Advertisement
Guest User

Untitled

a guest
May 4th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include <wincrypt.h>
  5.  
  6. #include <strsafe.h>
  7.  
  8. #define SEED_CONSTANT 0xba0da71d
  9.  
  10. unsigned char secretKey[16]={ 0xa3,0x1e,0xf3,0x69,
  11. 0x07,0x62,0xd9,0x1f,
  12. 0x1e,0xe9,0x35,0x7d,
  13. 0x4f,0xd2,0x7d,0x48 };
  14.  
  15.  
  16. void ErrorExit(LPTSTR lpszFunction)
  17. {
  18. // Retrieve the system error message for the last-error code
  19.  
  20. LPVOID lpMsgBuf;
  21. LPVOID lpDisplayBuf;
  22. DWORD dw = GetLastError();
  23.  
  24. FormatMessage(
  25. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  26. FORMAT_MESSAGE_FROM_SYSTEM |
  27. FORMAT_MESSAGE_IGNORE_INSERTS,
  28. NULL,
  29. dw,
  30. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  31. (LPTSTR) &lpMsgBuf,
  32. 0, NULL );
  33.  
  34. // Display the error message and exit the process
  35.  
  36. lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
  37. (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR));
  38. StringCchPrintf((LPTSTR)lpDisplayBuf,
  39. LocalSize(lpDisplayBuf) / sizeof(TCHAR),
  40. TEXT("%s Error: %d: %s"),
  41. lpszFunction, dw, lpMsgBuf);
  42. MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
  43.  
  44. LocalFree(lpMsgBuf);
  45. LocalFree(lpDisplayBuf);
  46. ExitProcess(dw);
  47. }
  48.  
  49. int Decode(char output[], char passEntry[], DWORD entryLen)
  50. {
  51. int ret = -1;
  52. HANDLE hToken;
  53. char sid[512], name[512],domain[512];
  54. DWORD SidSize = 0, i, j;
  55. DWORD cchName,cchDomain;
  56. SID_NAME_USE peUse;
  57. TOKEN_USER *SidUser = (TOKEN_USER*)&sid;
  58.  
  59. unsigned char staticKey[16];
  60. unsigned int seed;
  61. unsigned char *a,*b;
  62.  
  63. memcpy(staticKey,secretKey,sizeof(staticKey));
  64.  
  65. if((OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken)))
  66. {
  67. if((GetTokenInformation(hToken,TokenUser,SidUser,sizeof(sid),&SidSize)))
  68. {
  69. cchName = cchDomain = sizeof(name);
  70.  
  71. if((LookupAccountSid(NULL,SidUser->User.Sid,
  72. (LPWSTR)name,&cchName,(LPWSTR)domain,&cchDomain,&peUse)))
  73. {
  74. seed = SEED_CONSTANT;
  75.  
  76. // mix username with key
  77.  
  78. for(i = 0;i < cchName;i++)
  79. {
  80. ((unsigned int*)staticKey)[ i % 4 ] ^= name[i] * seed;
  81. seed *= 48271;
  82. }
  83.  
  84. // mix domain name with key
  85.  
  86. for(j = 0;j < cchDomain;i++,j++)
  87. {
  88. ((unsigned int*)staticKey)[ i % 4 ] ^= domain[j] * seed;
  89. seed *= 48271;
  90. }
  91.  
  92. // decode string
  93.  
  94. seed = (((unsigned int*)staticKey)[0] | 1);
  95. a = (unsigned char*)&passEntry[4];
  96. b = (unsigned char*)&passEntry[5];
  97.  
  98. for(i = 0;i < entryLen;i += 2)
  99. {
  100. passEntry[ i / 2 ] = (((a[i]-1)*16) | (b[i]-33)) - (seed & 0xff);
  101. seed *= 69621;
  102. }
  103.  
  104. // use protected storage to decrypt data
  105.  
  106. DATA_BLOB DataIn, DataEntropy, DataOut;
  107.  
  108. DataEntropy.cbData = sizeof(staticKey);
  109. DataEntropy.pbData = (BYTE*)&staticKey;
  110.  
  111. DataIn.cbData = (i/2);
  112. DataIn.pbData = (BYTE*)passEntry;
  113.  
  114. //passEntry[(i/2)+4]=0;
  115.  
  116. if(CryptUnprotectData(&DataIn,
  117. NULL,
  118. &DataEntropy,
  119. NULL,
  120. NULL,
  121. 1,
  122. &DataOut)) {
  123. memcpy(output,DataOut.pbData,DataOut.cbData);
  124. output[DataOut.cbData] = 0;
  125. LocalFree(DataOut.pbData);
  126. ret = 0;
  127. }
  128. else{
  129. ErrorExit(TEXT("Pff:"));
  130. }
  131. }
  132. }
  133. CloseHandle(hToken);
  134. }
  135. return(ret);
  136. }
  137.  
  138. int main(void) {
  139. char pwd[1024],
  140. out[1024],
  141. *p;
  142.  
  143. printf(
  144. "paste your encrypted password here\n"
  145. "(\"pw\" from HKEY_CURRENT_USER\\Software\\Google\\Google Talk\\Accounts):\n");
  146. fgets(pwd, sizeof(pwd), stdin);
  147. for(p = pwd; *p && (*p != '\n') && (*p != '\r'); p++);
  148. *p = 0;
  149.  
  150. if(!Decode(out, pwd, strlen(pwd))) {
  151. printf("\nPASSWORD: %s\n", out);
  152. } else {
  153. printf("\nthe password cannot be decrypted on this account/machine\n");
  154. }
  155. printf("\npress return to quit\n");
  156. fgetc(stdin);
  157. return(0);
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement