有谁知道为什么我得到 SIGSEGV,执行 0x90 导致分段错误
Do anyone konow why I get SIGSEGV, segmentation fault by execution 0x90
我执行 0x90 时遇到分段错误,为什么会发生这种情况??
这是我的 C 代码:
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdint.h>
char * buffer;
int64_t * startPtr;
int64_t * endPtr;
int64_t * exploitAddress;
int test()
{
printf("test\n");
return 0;
}
void main(int argc, char ** argv)
{
char buffer[512];
startPtr = (int64_t *) &test;
printf("funcPtr : \n %p\n", startPtr);
printf("bufferPtr : \n %p\n", buffer);
strcpy(buffer, argv[1]);
printf("string : \n%s\n", buffer);
}
这就是我在 gdb 中所做的:
(gdb) run `python -c 'print "\x90" * (256+8) + "\x90"*(256) + "\x30\xd8\xff\xff\xff\x7f\x00\x00"'`
Starting program: /home/nikolaij/Schreibtisch/BufferOverflow/OpenGL `python -c 'print "\x90" * (256+8) + "\x90"*(256) + "\x30\xd8\xff\xff\xff\x7f\x00\x00"'`
funcPtr :
0x4005b6
bufferPtr :
0x7fffffffd800
string :
����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������0����
Program received signal SIGSEGV, Segmentation fault.
0x00007fffffffd830 in ?? ()
(gdb) info reg
rax 0x219 537
rbx 0x0 0
rcx 0x7ffffde7 2147483111
rdx 0x7ffff7dd3780 140737351858048
rsi 0x1 1
rdi 0x1 1
rbp 0x9090909090909090 0x9090909090909090
rsp 0x7fffffffda10 0x7fffffffda10
r8 0x0 0
r9 0x219 537
r10 0x20e 526
r11 0x246 582
r12 0x4004c0 4195520
r13 0x7fffffffdae0 140737488345824
r14 0x0 0
r15 0x0 0
rip 0x7fffffffd830 0x7fffffffd830
eflags 0x10206 [ PF IF RF ]
cs 0x33 51
---Type <return> to continue, or q <return> to quit---
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
(gdb) x /64xb 0x00007fffffffd830
0x7fffffffd830: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd838: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd840: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd848: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd850: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd858: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd860: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd868: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
(gdb)
通知:
0x7fffffffd830: 0x90
rip 0x7fffffffd830 0x7fffffffd830
编译:
gcc test.c -fno-stack-protector -o OpenGL
程序名"OpenGL"与程序无关。它只是来自一个较旧的程序。
感谢您的帮助。
您需要使用 -Wl,-z,execstack
进行构建。
大多数现代系统都会防止将可执行代码放入堆栈,以防止您尝试实施的堆栈溢出攻击。
我执行 0x90 时遇到分段错误,为什么会发生这种情况??
这是我的 C 代码:
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdint.h>
char * buffer;
int64_t * startPtr;
int64_t * endPtr;
int64_t * exploitAddress;
int test()
{
printf("test\n");
return 0;
}
void main(int argc, char ** argv)
{
char buffer[512];
startPtr = (int64_t *) &test;
printf("funcPtr : \n %p\n", startPtr);
printf("bufferPtr : \n %p\n", buffer);
strcpy(buffer, argv[1]);
printf("string : \n%s\n", buffer);
}
这就是我在 gdb 中所做的:
(gdb) run `python -c 'print "\x90" * (256+8) + "\x90"*(256) + "\x30\xd8\xff\xff\xff\x7f\x00\x00"'`
Starting program: /home/nikolaij/Schreibtisch/BufferOverflow/OpenGL `python -c 'print "\x90" * (256+8) + "\x90"*(256) + "\x30\xd8\xff\xff\xff\x7f\x00\x00"'`
funcPtr :
0x4005b6
bufferPtr :
0x7fffffffd800
string :
����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������0����
Program received signal SIGSEGV, Segmentation fault.
0x00007fffffffd830 in ?? ()
(gdb) info reg
rax 0x219 537
rbx 0x0 0
rcx 0x7ffffde7 2147483111
rdx 0x7ffff7dd3780 140737351858048
rsi 0x1 1
rdi 0x1 1
rbp 0x9090909090909090 0x9090909090909090
rsp 0x7fffffffda10 0x7fffffffda10
r8 0x0 0
r9 0x219 537
r10 0x20e 526
r11 0x246 582
r12 0x4004c0 4195520
r13 0x7fffffffdae0 140737488345824
r14 0x0 0
r15 0x0 0
rip 0x7fffffffd830 0x7fffffffd830
eflags 0x10206 [ PF IF RF ]
cs 0x33 51
---Type <return> to continue, or q <return> to quit---
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
(gdb) x /64xb 0x00007fffffffd830
0x7fffffffd830: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd838: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd840: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd848: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd850: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd858: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd860: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
0x7fffffffd868: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90
(gdb)
通知:
0x7fffffffd830: 0x90
rip 0x7fffffffd830 0x7fffffffd830
编译:
gcc test.c -fno-stack-protector -o OpenGL
程序名"OpenGL"与程序无关。它只是来自一个较旧的程序。
感谢您的帮助。
您需要使用 -Wl,-z,execstack
进行构建。
大多数现代系统都会防止将可执行代码放入堆栈,以防止您尝试实施的堆栈溢出攻击。