0

This is the code that i am using and the string i am trying to base64 decode is below which is a from the chrome localstate file,DPAPI key.

RFBBUEkBAAAA0Iyd3wEV0RGMegDAT8KX6wEAAADi+GGk7DWzQpfcOpvrA5QBAAAAAAIAAAAAABBmAAAAAQAAIAAAAB71Yux67n+/BdPaKkGQcjERQXhrLPqH+5oIpE0adTRXAAAAAA6AAAAAAgAAIAAAADw0+h5r3BV2XvQ5Dxou4g8lLEs+r7rMr4urasiaUVbLMAAAAIvSN/H/Q04j/4gknX3tPi/jPFo5zqEqsNFOqq3iMvVoAK5ZpYWdc5WBxzR+gXb+7UAAAAC6hU4zxFN3wWaxxwk1YVIB+ePgEFoe9SYynAXhkUIlxSheodOTXxCFij2DPCvxH8eAze6qw6lxHNC4NVHt7Yvu

/* A BASE-64 ENCODER AND DECODER USING OPENSSL */

#include <openssl/pem.h>
#include <string.h> //Only needed for strlen().


unsigned char *base64decode (const void *b64_decode_this, int decode_this_many_bytes){
    BIO *b64_bio, *mem_bio;      //Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
    unsigned char *base64_decoded = calloc( (decode_this_many_bytes*3)/4+1, sizeof(char) ); //+1 = null.
    b64_bio = BIO_new(BIO_f_base64());                      //Initialize our base64 filter BIO.
    mem_bio = BIO_new(BIO_s_mem());                         //Initialize our memory source BIO.
    BIO_write(mem_bio, b64_decode_this, decode_this_many_bytes); //Base64 data saved in source.
    BIO_push(b64_bio, mem_bio);          //Link the BIOs by creating a filter-source BIO chain.
    BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL);          //Don't require trailing newlines.
    int decoded_byte_index = 0;   //Index where the next base64_decoded byte should be written.
    while ( 0 < BIO_read(b64_bio, base64_decoded+decoded_byte_index, 1) ){ //Read byte-by-byte.
        decoded_byte_index++; //Increment the index until read of BIO decoded data is complete.
    } //Once we're done reading decoded data, BIO_read returns -1 even though there's no error.
    BIO_free_all(b64_bio);  //Destroys all BIOs in chain, starting with b64 (i.e. the 1st one).
    return base64_decoded;        //Returns base-64 decoded data with trailing null terminator.
}


int main(void){

    char data_to_decode[]="RFBBUEkBAAAA0Iyd3wEV0RGMegDAT8KX6wEAAADi+GGk7DWzQpfcOpvrA5QBAAAAAAIAAAAAABBmAAAAAQAAIAAAAB71Yux67n+/BdPaKkGQcjERQXhrLPqH+5oIpE0adTRXAAAAAA6AAAAAAgAAIAAAADw0+h5r3BV2XvQ5Dxou4g8lLEs+r7rMr4urasiaUVbLMAAAAIvSN/H/Q04j/4gknX3tPi/jPFo5zqEqsNFOqq3iMvVoAK5ZpYWdc5WBxzR+gXb+7UAAAAC6hU4zxFN3wWaxxwk1YVIB+ePgEFoe9SYynAXhkUIlxSheodOTXxCFij2DPCvxH8eAze6qw6lxHNC4NVHt7Yvu";
    int bytes_to_decode = strlen(data_to_decode); //Number of bytes in string to base64 decode.
    unsigned char *base64_decoded = base64decode(data_to_decode, bytes_to_decode);   //Base-64 decoding.


    printf("Base-64 decoded string is: %s\n", base64_decoded);  //Prints base64 decoded string.
    printf("LENGHT:%d",strlen(base64_decoded));
    int i=0;
    while(base64_decoded[i]!='\0')
    {
        printf("\n%i",i);
        i++;
    }

}

This is the string returned when i run it through gdb

yeah_well
  • 130
  • 1
  • 6

1 Answers1

1

I was able to solve it by viewing the memory contents by gdb x /bx command and not p(print) since the print wont work because it is binary data and a null terminator would terminate the string when printing,thanks to commenter.

yeah_well
  • 130
  • 1
  • 6