在一些测试项目上工作,我有这段代码,它运行得很好:
#include <windows.h>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
char shellcode[] = "..snip..\xa0\x4e\xbc\x0b\x45\xee\xb3\x1b\xf9..snip..";
void* exec = VirtualAlloc(0, sizeof shellcode, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
memcpy(exec, shellcode, sizeof shellcode);
((void(*)())exec)();
return 0;
}但是,我试图用shellcode代码传递动态大小的字节数组,这不会执行以下代码:
int main(int argc, char** argv) {
std::string(test) = "..snip..\xa0\x4e\xbc\x0b\x45\xee\xb3\x1b\xf9..snip..";
char* shellcode = new char[test.size()];
memcpy(shellcode, test.data(), test.size());
//std::copy(test.begin(), test.end(), shellcode);
//delete[] shellcode;
//std::cout << shellcode;
void* exec = VirtualAlloc(0, sizeof shellcode, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
memcpy(exec, shellcode, sizeof shellcode);
((void(*)())exec)();
//return 0;
}有人能指出问题在哪里吗?或者我该怎么改进呢?
发布于 2021-12-30 06:15:53
在第一个示例中,sizeof shellcode是数组本身的大小。在第二个示例中,sizeof shellcode是指针的大小。要么是4,要么是8。
将VirtualAlloc和随后的memcpy语句更改为:
void* exec = VirtualAlloc(0, test.size(), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
memcpy(exec, shellcode, test.size());https://stackoverflow.com/questions/70528043
复制相似问题