所以我最近在 Mozilla 中挂接了 PR_Write 并且能够将结果(所有连接字面意思)记录到日志文件中,但是有一个问题,我假设在挂接 PR_Write 之后,我将能够捕获 HTTPS 数据但是当我登录到 HTTPS 服务器时,它没有捕获未加密的 POST 数据,我尝试使用 localhost 并制作一个假的 POST 并且考虑到它未加密,它捕获了 localhost post。 hook PR_Write 的目的不是为了抓取各种数据吗?
这是我正在使用的 PR_Write 的原型(prototype)和变量:
typedef int (*Custom_Write)(PVOID, LPVOID, INT);
Custom_Write c_write=NULL;
PR_Write definition by Mozilla
在绕行函数中,我通过使用 GetProcAddress 获取存储在 c_write
中的地址来调用原始 PR_Write。下面是它的调用方式:
// 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
}
日志记录和其他东西工作正常,但是当涉及到写入加密的 POST 数据时,它失败了。它最终会写出乱码。
最佳答案
'write(buf, sizeof(char), strlen(buf), fileHandle);' - strlen() 调用既不合适又不必要。它不仅不能可靠地使用可能指向或不指向以 null 终止的 char 数组的 void 指针,而且它是多余的,因为您已经知道要写入多少字节/字符 - 它作为“int bytes”参数传入.
去掉 strlen() 调用;
fwrite(buf, 1,bytes, fileHandle);
strlen() 不是必需的,并且不能可靠地处理可能包含嵌入空值的二进制数据。
对于网络代码,strlen() 在 99.9% 的情况下都是一场灾难。
关于c - PR_Write Hook 后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37236228/