2

So i recently hooked PR_Write in Mozilla and was able to log results( all of the connection literally ) to a log file, there's however one problem, i was assuming that after hooking PR_Write, i would be able to capture HTTPS data but when i log in to an HTTPS server, it doesn't capture the unencrypted POST data, i tried using localhost and making a fake POST and it captures the localhost post considering it's not encrypted. Is the point of hooking PR_Write not to capture all kinds of data?

This is the prototype of the PR_Write that i'm using and the variable:

typedef int (*Custom_Write)(PVOID, LPVOID, INT);
Custom_Write c_write=NULL;

PR_Write definition by Mozilla

and in the detour function, i call the original PR_Write by getting the address which is stored in c_write using GetProcAddress. Below is how it's called:

// detour function
int detour_pr_write(int fd, LPVOID buf, int bytes)
{
    // ... code for virtual protect
    int retaddr=c_write(fd, buf, bytes);
    // file functions
    fwrite(buf, sizeof(char), strlen(buf), fileHandle);
    // ... code for virtual protect
    return retaddr;    // go to original function
}

The logging and other stuff works fine but when it comes down to writing encrypted POST data, it fails. It ends up writing gibberish.

demogorgon
  • 49
  • 1
  • 9

1 Answers1

1

'write(buf, sizeof(char), strlen(buf), fileHandle);' - the strlen() call is both inappropriate and unnecessary. Not only does it not work reliably with void pointers that may, or may not, point at null-terminated char arrays, it is redundant because you already know how many bytes/chars to write - it's passed in as the 'int bytes' parameter.

Get rid of the strlen() call;

fwrite(buf, 1,bytes, fileHandle);

strlen() is not required and cannot work reliably with binary data that may contain embedded nulls.

With network code, strlen() is a disaster 99.9% of the time.

Martin James
  • 24,453
  • 3
  • 36
  • 60