0

Hi im trying to write a C Program that decrypts the Key that Chrome uses to encrypt saved Passwords. The Key is encrypted with CryptProtectData and then encoded with Base64, i have sucessfully decoded the Key and now i want to decrypt it with CryptUnprotectData but when i try to use this function my Program just crashes, i had a similar Problem once when I got the size of the byte* holding the encrypted data wrong. Does anyone know what i did wrong?

#include <stdio.h>
#include <base64.h>
#include <wincrypt.h>

void main()
{    
  //RFBBUEk = DPAPI    
  char B64[] = "BAAAA0Iyd3wEV0RGMegDAT8KX6wEAAAAYUduGi5FwQr1+XlafMqBZAAAAAAIAAAAAABBmAAAAAQAAIAAAALIvW98pXJMaQ0aJPpr40c12oSSRDg59tr+zaF+podlvAAAAAA6AAAAAAgAAIAAAAD2z5W4nMDHLOxthH8nXyxl+1hpRdY2BGHStxaDvgjSiMAAAAIKrcLbXw5WZCPjqyPtO/3QahMa0yMRC/CoMS/OoDw5j7fcZ8N31sIildXpN82egDEAAAAAvzHS7+Zf2IR05cggu1XHfNGknq3TKRHW37CVEktIHHu6yo1K0Q0r5YevYDUUNdhzlpJ+ynQUTBAS2Fa3PRR4V";
  int len = sizeof(B64);
  int * flen;
  char * ergebnis;
  ergebnis = unbase64(B64,len,flen);
  DATA_BLOB Input,Output;
  Input.pbData = (byte*)ergebnis;
  Input.cbData = *flen;
  CryptUnprotectData(&Input,NULL,NULL,NULL,NULL,0,&Output);
  printf("%s",(char*)Output.pbData);
  getchar();  
}


Ðаn
  • 10,934
  • 11
  • 59
  • 95

1 Answers1

1
  printf("%s",(char*)Output.pbData);

First, you don't check if CryptUnprotectData succeeds. If it fails, you're passing a pointer to garbage to printf.

Second, how are you expecting printf to know how many bytes to print? You need to do something with Output.cbData.

Lastly, flen is never assigned a value. You pass whatever nonsense, uninitialized value it has to unbase64 and then try to use that value.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278