使用Buffer-Overflow执行一些简单的说明失败 - (Segfaults)

发布于 2025-01-23 03:59:48 字数 1697 浏览 2 评论 0原文

我正在尝试缓冲溢出并使使系统执行mmap分配的地址,这将是某些简单说明的函数,即

mov $0x1, %rax
ret

opCode数组的\ x48 \ xc7 \ xc7 \ xc0 \ x01 \ x00 \ x00 \ x00 \ xc3

我编写的以下代码

char shellcode[] = "\x48\xc7\xc0\x01\x00\x00\x00\xc3";
int main() {
#define page 400
    char buff[page];
    
    void* m = mmap(NULL, 
            sizeof(shellcode),
            PROT_WRITE | PROT_EXEC,
            MAP_ANONYMOUS | MAP_PRIVATE,
            -1,
            0);

    for(int i=0;i<page;i++) strcat(buff, "\x90");
    strcat(buff, shellcode);
    strcpy(m,buff);
    int(*f)() = m;
    return f();
}

(我的实际代码更长,所以这是关于在那里正在执行的操作的摘要),

但是当我运行它时,我会得到segfault

->  0x7ffff7ffa193: addl   %eax, (%rax)
    0x7ffff7ffa195: addb   %al, (%rax)
    0x7ffff7ffa197: addb   %al, (%rax)
    0x7ffff7ffa199: addb   %al, (%rax)
    0x7ffff7ffa19b: addb   %al, (%rax)
    0x7ffff7ffa19d: addb   %al, (%rax)
    0x7ffff7ffa19f: addb   %al, (%rax)
    0x7ffff7ffa1a1: addb   %al, (%rax)
    0x7ffff7ffa1a3: addb   %al, (%rax)
    0x7ffff7ffa1a5: addb   %al, (%rax)
    0x7ffff7ffa1a7: addb   %al, (%rax)
    0x7ffff7ffa1a9: addb   %al, (%rax)
    0x7ffff7ffa1ab: addb   %al, (%rax)
    0x7ffff7ffa1ad: addb   %al, (%rax)
    0x7ffff7ffa1af: addb   %al, (%rax)
    0x7ffff7ffa1b1: addb   %al, (%rax)

,但是如果我执行follwing shellCode,“ \ x32 \ xc0 \ xc0 \ x48 \ x48 \ x48 \ xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\x2b\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05\ x05“

它可以按预期工作。

请帮助我如何制作“ \ x48 \ xc7 \ xc0 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ xc3” exeute。

I'm trying to buffer overflow and make the make the system execute mmap allocated address which would be a function of some simple instructions, namely

mov $0x1, %rax
ret

the opcode array for this is \x48\xc7\xc0\x01\x00\x00\x00\xc3.

The following code I wrote

char shellcode[] = "\x48\xc7\xc0\x01\x00\x00\x00\xc3";
int main() {
#define page 400
    char buff[page];
    
    void* m = mmap(NULL, 
            sizeof(shellcode),
            PROT_WRITE | PROT_EXEC,
            MAP_ANONYMOUS | MAP_PRIVATE,
            -1,
            0);

    for(int i=0;i<page;i++) strcat(buff, "\x90");
    strcat(buff, shellcode);
    strcpy(m,buff);
    int(*f)() = m;
    return f();
}

(my actual code is longer, so this is summary of what's being done there)

but when I run it, I get segfault

->  0x7ffff7ffa193: addl   %eax, (%rax)
    0x7ffff7ffa195: addb   %al, (%rax)
    0x7ffff7ffa197: addb   %al, (%rax)
    0x7ffff7ffa199: addb   %al, (%rax)
    0x7ffff7ffa19b: addb   %al, (%rax)
    0x7ffff7ffa19d: addb   %al, (%rax)
    0x7ffff7ffa19f: addb   %al, (%rax)
    0x7ffff7ffa1a1: addb   %al, (%rax)
    0x7ffff7ffa1a3: addb   %al, (%rax)
    0x7ffff7ffa1a5: addb   %al, (%rax)
    0x7ffff7ffa1a7: addb   %al, (%rax)
    0x7ffff7ffa1a9: addb   %al, (%rax)
    0x7ffff7ffa1ab: addb   %al, (%rax)
    0x7ffff7ffa1ad: addb   %al, (%rax)
    0x7ffff7ffa1af: addb   %al, (%rax)
    0x7ffff7ffa1b1: addb   %al, (%rax)

but if I execute the follwing shellcode, "\x32\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\x2b\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05\x05"

it works as expected.

Please help me with how to make "\x48\xc7\xc0\x01\x00\x00\x00\xc3" exeute.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文