gpt4 book ai didi

c++ - 在cpp中运行shellcode

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:41:52 46 4
gpt4 key购买 nike

我正在尝试在 cpp 中运行 shellcode(shellcode 来自用户,因此程序应该是动态的)当我尝试运行我的程序时,我遇到了一个异常,我认为它告诉我无法从数据部分运行代码。之后我尝试创建一个新的可执行部分并将我的数据放在那里但是它没有用

#pragma section(".shell",read,execute)                                                                                                                        
__declspec(allocate(".shell"))
unsigned char code[] =
"\xB8\x04\x00\x00\x00";

// Function pointer points to the address of function.
int(*shell)(); //Function pointer
// Initializing a function pointer with the address of a shellcode
shell = ((int(*)())&code);
// Execute shellcode
int a = shell();

有人可以向我解释我做错了什么吗?

最佳答案

你写的都是正确的。异常被引发只是因为你的 shellcode 只包含 mov eax, 4。 Windows 分配器将您的部分与页面大小对齐并用零填充它,但是 0x00add byte ptr [rax], al 的操作码。现在你的 shellcode 中不仅有 mov eax, 4,还有:

mov eax, 4
add byte ptr [rax],al
add byte ptr [rax],al
....

在您的 mov 之后,您尝试在 eax 地址 0x00000004 处获取值,Windows 页面保护程序所在的位置。现在你有 0xC0000005: Access violation on write "0x0000000000000004"

ret 添加到您的 shellcode 中:

unsigned char code[] = ""\xB8\x04\x00\x00\x00\xC3"

并且您不会执行未使用的命令并成功退出。

关于c++ - 在cpp中运行shellcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48279069/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com