我工作的一个项目,我需要一个简单的exe
文件加载到一个缓冲区,然后从RAM中调用exe
文件的入口点运行的编译功能。C:从RAM
我知道我无法加载并运行一个非常复杂的exe文件,但缓冲区有很多依赖关系,但我认为它有可能调用exe (PE)
文件的独立函数(如空主)。我必须找到exe文件的入口点地址(它的偏移量),然后将该地址(现在加载到缓冲区中)转换为指向函数的指针,然后调用它,它可能会调用在RAM中加载的函数,但我不知道如何找到地址。
这是我迄今所做的:
int main(){
void (* function)();
unsigned char* buffer;
FILE* fp;
size_t size;
char* path = "address of the file";
fp = fopen(path, "rb");
fseek(fp, 0, SEEK_END);
size = ftell(fp); /*calc the size needed*/
fseek(fp, 0, SEEK_SET);
buffer = (unsigned char *) malloc(size);
fclose(fp);
/*problem : i have to sum the buffer address with that offset here*/
function = (void (*)())(buffer);
function();
return 0;
}
我认为这是非常清楚的代码什么即时尝试做。
这里是试图做同样的事情meterpreter
(的想法是一样的)链接:
https://github.com/rsmudge/metasploit-loader/blob/master/src/main.c
我会很感激的任何帮助。
谢谢
见http://stackoverflow.com/questions/8723039/c-how-to-run-an -exe-file-which-contents-are-stored-in-a-char-array以及本文https://www.blackhat.com/presentations/bh-usa-07/Harbour/Whitepaper/bh-usa -07-harbor-WP.pdf以及http://stackoverflow.com/questions/3553875/load-an-exe-file-and-run-it-from-memory –
@RichardChambers - 这两个SO答案都是对于C#不是C –