4

I am trying to recreate a buffer overflow attack in my machine using Ubuntu 16.04. But no matter what I try I always get the error 'Segmentation fault(core dumped)'

I already disabled memory randomization by using:

sysctl kernel.randomize_va_space=0

And I have also tried these flags when compiling my program:

-fno-stack-protector 
-z execstack
-D_FORTIFY_SOURCE=0

Adding all these flags I end up compiling the following:

gcc -z execstack -g -fno-stack-protector -mpreferred-stack-boundary=2 -D_FORTIFY_SOURCE=0 -o code code.c

But nothing seems to work. Is there any other protection I need to disable in order to recreate my buffer overflow successfully?

1
  • Try wrapping the fuse in the mains plug with alu foil. Commented Sep 8, 2016 at 17:49

1 Answer 1

6

I think that you did the possible and something that is not strictly required. During the computer security course we just compiled the source with the following flags: -O0 -mpreferred-stack-boundary=2 -g -m32 fno-stack-protector In this way you disable code optimizations, align the stack pointer at 4 bytes, disable canaries and enable gdb (it is better to start using the debugger). Remember that with m32 the code is compiled for 32 bits system. If you're learning buffer overflow from zero it is better to start with this (It's easier to handle registers).

Remember that if you're trying to make am exploit with buffer overflow and you get segmentation fault you're probably overwriting the saved frame pointer (but you should know it, it's stack smashing: http://insecure.org/stf/smashstack.html ).

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your answer! It was really helpful! I got it to work by compiling as a 32bit program like you recommended.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.