Practicing buffer overflow attack in Ubuntu

2019-04-01 02:44发布

问题:

I am trying to learn to use buffer overflow attack in Ubuntu. Unfortunately, I cannot turn off Address Space Layout Randomization (ASLR) feature in this OS, which is turned on by default. I have tried some work around found in some fedora books:

echo "0" > /proc/sys/kernel/randomize_va_space 

but for some reason the protection's still there. Please give me some suggestions. Thanks.

[edit]Actually the above command was not successful, it said "Permission Denied", even with sudo. How can I fix that?

[adding] I kept on getting segmetation fault error when it shows an address in stack. Is it related to non-executable stack in ubuntu :(?

回答1:

You will need root perms before attempting it, and if I'm not mistaken, to restart once you've done it.

 sudo -i
 echo "0" > /proc/sys/kernel/randomize_va_space


回答2:

found it myself

you have to compile this way:

gcc -fno-stack-protector -z execstack -o OUTPUT INPUT.c



回答3:

to echo to files with root acces using sudo you can use the following code:

echo "0" | sudo tee /proc/sys/kernel/randomize_va_space


回答4:

gcc compile with -fno-stack-protector



回答5:

You can turn off ASLR for a particular process by launching with setarch

For 32 bit programs:

setarch i386 -R yourProgram

For 64 bit programs:

setarch x86_64 -R yourProgram