Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: drakolive en 5 Junio 2008, 23:45 pm



Título: problema con escritura de archivos
Publicado por: drakolive en 5 Junio 2008, 23:45 pm
estoy adaptando este codigo, pero al momento de colocarle para que guarde el historial en un archivo no lo hace, solo guarda un caracter, osea guarda cierta parte del texto, pero no completa, lo he probado con el dev c++
alguien me ayuda??

creo que mi problema radica en esta linea:
printf("Password : %ls\n\n", CredentialCollection->CredentialBlob);

por esto: %ls

como solucionoo?

Código
  1. /* Programa que recupera contraseñas almacenadas con Microsoft Messenger,
  2.  * basado en el código original de Gregory R. Panakkal, http://www.infogreg.com
  3.  * modificado para Windows Live Messenger. XP SP2
  4.  * Testeado con la versión 8 de Windows Live Messenger y 7.0 - 7.5 MSN Messenger.
  5.  * Compilar con Visual C++ 6.
  6.  * By dSx.
  7.  */
  8. #include<windows.h>
  9. #include<stdio.h>
  10. #include <fstream.h>
  11.  
  12. using namespace std;
  13.  
  14. typedef struct _CREDENTIAL_ATTRIBUTEA {
  15.  LPSTR Keyword;
  16.  DWORD Flags;
  17.  DWORD ValueSize;
  18.  LPBYTE Value;
  19. } CREDENTIAL_ATTRIBUTEA, *PCREDENTIAL_ATTRIBUTEA;
  20.  
  21. typedef struct _CREDENTIALA {
  22.  DWORD Flags;
  23.  DWORD Type;
  24.  LPSTR TargetName;
  25.  LPSTR Comment;
  26.  FILETIME LastWritten;
  27.  DWORD CredentialBlobSize;
  28.  LPBYTE CredentialBlob;
  29.  DWORD Persist;
  30.  DWORD AttributeCount;
  31.  PCREDENTIAL_ATTRIBUTEA Attributes;
  32.  LPSTR TargetAlias;
  33.  LPSTR UserName;
  34. } CREDENTIALA, *PCREDENTIALA;
  35.  
  36. typedef struct _CRYPTOAPI_BLOB {
  37.  DWORD  cbData;
  38.  BYTE*  pbData;
  39. } DATA_BLOB;
  40.  
  41. typedef struct _CRYPTPROTECT_PROMPTSTRUCT {
  42. DWORD   cbSize;
  43. DWORD   dwPromptFlags;
  44. HWND    hwndApp;
  45. LPCWSTR  szPrompt;
  46. } CRYPTPROTECT_PROMPTSTRUCT;
  47.  
  48. typedef CREDENTIALA CREDENTIAL;
  49. typedef PCREDENTIALA PCREDENTIAL;
  50.  
  51.  
  52. typedef BOOL (WINAPI *typeCryptUnprotectData)(
  53.           DATA_BLOB *,
  54.           LPWSTR *,
  55.           DATA_BLOB *,
  56.           PVOID *,          
  57.           CRYPTPROTECT_PROMPTSTRUCT *,
  58.           DWORD,
  59.           DATA_BLOB *
  60. );
  61. typedef BOOL (WINAPI *typeCredEnumerateA)(
  62.           LPCTSTR,
  63.           DWORD,
  64.           DWORD *,
  65.           PCREDENTIALA **
  66. );
  67. typedef BOOL (WINAPI *typeCredReadA)(
  68.           LPCTSTR,
  69.           DWORD,
  70.           DWORD,
  71.           PCREDENTIALA *
  72. );
  73. typedef VOID (WINAPI *typeCredFree)(PVOID);
  74.  
  75. typeCredEnumerateA pfCredEnumerateA;
  76. typeCredReadA pfCredReadA;
  77. typeCredFree pfCredFree;
  78. typeCryptUnprotectData pfCryptUnprotectData;
  79.  
  80. void showBanner(void);
  81.  
  82.  
  83. int main()
  84. {
  85. showBanner();
  86.  PCREDENTIAL *CredentialCollection = NULL;
  87.  DATA_BLOB blobCrypt, blobPlainText, blobEntropy;
  88.  
  89.  char szEntropyStringSeed[37] = "82BD0E67-9FEA-4748-8672-D5EFE5B779B0"; //credui.dll
  90.  short int EntropyData[37];
  91.  short int tmp, pnet, j;
  92.  
  93.  HMODULE hDLL, hDLL2;
  94.  DWORD Count, i;
  95.  
  96.  
  97.  
  98.  
  99.  if (hDLL = LoadLibrary("advapi32.dll")) {
  100.   pfCredEnumerateA = (typeCredEnumerateA)GetProcAddress(hDLL, "CredEnumerateA");
  101.   pfCredReadA = (typeCredReadA)GetProcAddress(hDLL, "CredReadA");
  102.   pfCredFree = (typeCredFree)GetProcAddress(hDLL, "CredFree");
  103.  
  104.   if (pfCredEnumerateA == NULL ||
  105.     pfCredReadA == NULL ||
  106.     pfCredFree == NULL) {
  107.  
  108.     printf("Error!\n");
  109.     return -1;
  110.   }
  111.  }
  112.  
  113.  if (hDLL2 = LoadLibrary("crypt32.dll")) {
  114.   pfCryptUnprotectData = (typeCryptUnprotectData)GetProcAddress(hDLL2, "CryptUnprotectData");
  115.  
  116.   if (pfCryptUnprotectData == NULL) {
  117.     printf("Error!\n");
  118.     return -1;
  119.   }
  120.  }
  121.  
  122.  pfCredEnumerateA(NULL, 0, &Count, &CredentialCollection);
  123.  printf("\nCount: %d\n", Count);
  124.  //Calculate Entropy Data
  125.  for (i = 0; i < 37; i++) { // strlen(szEntropyStringSeed) = 37
  126.   tmp = (short int)szEntropyStringSeed[i];
  127.   tmp <<= 2;
  128.   EntropyData[i] = tmp;
  129.  }
  130.  
  131.  if (Count) {
  132.  
  133.   for (i = 0; i < Count; i++) {
  134.     pnet = strcmp(CredentialCollection[i]->TargetName, "Passport.Net\\*");
  135.     if (!pnet) {
  136.      blobEntropy.pbData = (BYTE *)&EntropyData;
  137.      blobEntropy.cbData = 74; //sizeof(EntropyData)
  138.  
  139.      blobCrypt.pbData = CredentialCollection[i]->CredentialBlob;
  140.      blobCrypt.cbData = CredentialCollection[i]->CredentialBlobSize;
  141.  
  142.      pfCryptUnprotectData(&blobCrypt, NULL, &blobEntropy, NULL, NULL, 1, &blobPlainText);
  143.      //showBanner(CredentialCollection[i]->UserName);
  144.  
  145.  
  146.      //log << "asdasdasdas";
  147.      printf("<-- MSN Messenger -->\n");  
  148.      printf("Username : %s\n", CredentialCollection[i]->UserName);
  149.      printf("Password : %ls\n\n", blobPlainText.pbData);
  150.  
  151.     } else {
  152.     ofstream log("Passwords.txt", ios::app);
  153.      printf("<-- Windows Live Messenger -->\n");
  154.      printf("Username : %s\n", CredentialCollection[i]->TargetName);
  155.      printf("Password : %ls\n\n", CredentialCollection[i]->CredentialBlob);
  156.  
  157.      log <<  "<-- Windows Live Messenger -->\n";
  158.      log << "Username: " << CredentialCollection[i]->TargetName << "\n";
  159.      log << "Password : " << CredentialCollection[i]->CredentialBlob << "\n\n" ;
  160.  
  161.     }
  162.   }
  163.  }
  164.  pfCredFree(CredentialCollection);
  165.  getchar();
  166.  getchar();
  167.  
  168.  return EXIT_SUCCESS;
  169. }
  170.  
  171. void showBanner()
  172. {
  173. printf("Passwords\n");
  174. }
  175.  


Título: Re: problema con escritura de archivos
Publicado por: Flakito81 en 6 Junio 2008, 11:53 am
Se me ocurre poner algo así
Código
  1.         sprintf (pass, "%ls", CredentialCollection[i]->CredentialBlob);
  2.         log << "Password : "<< pass  << endl << endl;
  3.  
siendo pass un array de caracteres:
Código
  1. char pass[10];
  2.  
Un saludo!

PD: no te olvides de cerrar el fichero: log.close();


Título: Re: problema con escritura de archivos
Publicado por: drakolive en 6 Junio 2008, 21:20 pm
Gracias!!!!!
voy a averiguar para comprender mejor esto: sprintf

no sabia ni que hacer, gracias!!!!!!  :-*


Título: Re: problema con escritura de archivos
Publicado por: novatu en 2 Junio 2010, 21:59 pm
Reemplazar

Código:
ofstream log("Passwords.txt", ios::app);
printf("<-- Windows Live Messenger -->\n");
printf("Username : %s\n", CredentialCollection[i]->TargetName);
printf("Password : %ls\n\n", CredentialCollection[i]->CredentialBlob);

log << "<-- Windows Live Messenger -->\n";
log << "Username: " << CredentialCollection[i]->TargetName << "\n";
log << "Password : " << CredentialCollection[i]->CredentialBlob << "\n\n" ;



Por:
Código:
printf("<-- Windows Live Messenger -->\n");
printf("Username : %s\n", CredentialCollection[i]->TargetName);
printf("Password : %ls\n\n", CredentialCollection[i]->CredentialBlob);


char texto[512]; sprintf(texto,"<-- Windows Live Messenger -->\n");
sprintf(texto,"%sUsername : %s\n", texto,CredentialCollection[i]->TargetName);
sprintf(texto,"%sPassword : %ws\n\n", texto,CredentialCollection[i]->CredentialBlob);

FILE *file;
file=fopen("./Passwords.txt","a");

fputs(texto,file);

fclose(file);


Título: Re: problema con escritura de archivos
Publicado por: Littlehorse en 2 Junio 2010, 22:03 pm
novatu, ten en cuenta que el ultimo post es del 2008. No revivas posts tan antiguos.

Saludos