在example2.cpp中解密后,我很难弄清楚为什么有效负载不能工作,当使用命令'example2.exe > out.txt‘执行编译后的exe时,我得到的外壳代码是有效的,不会在example.cpp中造成任何问题,因为我可以看到输出是hello world (至少在我的例子中是这样)
example.cpp
unsigned char out[] = "\x00\x00...";
int main()
{
void *exec = VirtualAlloc(0, sizeof(out), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
memcpy(exec, out, sizeof(out));
((void(*)())exec)();
}example2.cpp
void decrypt_run(){
std::vector<unsigned char> decrypted(encrypted.size());
// the encrypted cipher get decrypted and the vector decrypted is filled with unsigned chars
unsigned char buf[decrypted.size()];
// converting the vector to an unsigned char buffer to be passed to memcopy
std::copy(decrypted.begin(), decrypted.end(), buf);
size_t shellcodesize = sizeof(buf);
cout << buf << endl; // prints the shellcode to the screen
//void *exec = VirtualAlloc(0, shellcodesize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
//memcpy(exec, buf, shellcodesize);
//((void(*)())exec)();
}
int main()
{
decrypt_run();
return 0;
}当取消对decrypt_run()中最后三行的注释时,程序完成时,除了self代码本身之外,没有任何输出。
同样,out.txt中相同的外壳代码也与example.cpp一起使用,它运行得完美无缺,但对example2.cpp却没有。
发布于 2022-01-22 00:24:40
在第一种情况下,您将在固定内存缓冲区中对外壳代码进行硬编码,然后将这些字节复制到分配的可执行内存中。这很好。
但是在第二个例子中,您有一个充满(解密)外壳代码字节的动态vector,然后分配一个动态数组,将外壳代码复制到该数组中,然后将外壳代码从该数组复制到可执行内存中。这个中间数组完全没有必要,应该删除,您可以将外壳代码字节直接从vector复制到可执行内存中,例如:
void decrypt_run(){
std::vector<unsigned char> decrypted(encrypted.size());
// the encrypted cipher get decrypted and the vector decrypted is filled with unsigned chars
// passing the vector to memcopy
unsigned char *buf = decrypted.data();
size_t shellcodesize = decrypted.size();
cout << buf << endl; // prints the shellcode to the screen
void *exec = VirtualAlloc(0, shellcodesize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
memcpy(exec, buf, shellcodesize);
((void(*)())exec)();
}https://stackoverflow.com/questions/70807364
复制相似问题