ovrwngtvity
ovrwngtvity

Reputation: 4419

How to exit with SIGSEGV instead of SIGABRT?

I am learning how to cause Buffer Overflows with this code. Then I am running this with GDB and when I input bad data that causes the smashing of the Stack I exit with Program received signal SIGABRT, Aborted. 0x00007ffff7a4af79 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory. but the the both guide I am reading exits with SIGSEGV or EXC_BAD_ACCESS with the reason (in the last case) KERN_INVALID_ADDRESS and the address that actually are the bad input.

How do I exit with those Signals? Is it my system that is configured to work that way?

I am running on Ubuntu 14.04 LTS Trusty

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int test(char *test) {
    char buf[10];
    strcpy(buf, test);

    return 0;
}

int main(int argc, char *argv[]) {
    test(argv[1]);
    printf("After test: %s\n", argv[1]);

    return 0;
}

Upvotes: 1

Views: 1099

Answers (2)

Jet_C
Jet_C

Reputation: 662

You need to disable the -fstack-protector when compiling your c file.

Compile like so:

gcc yourFileName.c -o yourFileName -fno-stack-protector

In your case it would be gcc raise.c -o raise -fno-stack-protector then run with GDB using gdb ./raise. You can then overflow the buffer right after by running something like

run $(python –c “print(‘F’*32)”) 

which will overflow your char buf[10]; by placing 32 'F' characters into buf[10]. This will cause the SIGSEGV, Segmentation fault to display.

Upvotes: 0

Arjun Sreedharan
Arjun Sreedharan

Reputation: 11453

Your compiler seems to implement stack smashing protection to protect from buffer overflow. Compile with -fno-stack-protector flag.

Upvotes: 2

Related Questions