You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disable Execution Protection (not needed for Ubuntu18)
Linux NX
[ 0.000000] NX (Execute Disable) protection: active
Boot and interrupt the GRUB menu
Edit the boot configuration, changing the "linux" line by adding these two parameters to the end of the line:
noexec=off noexec32=off
Then boot by pressing Ctrl+x.
After booting, you can check to see if DEP/NX is turned off by running:
dmesg | grep NX
When DEP/NX is turned off you should see something similar to this output:
# dmesg | grep NX
[ 0.000000] NX (Execute Disable) protection: disabled by kernel command line option
ASLR
Address space layout randomization (ASLR) is a computer security technique involved in preventing exploitation of memory corruption vulnerabilities. In order to prevent an attacker from reliably jumping to, for example, a particular exploited function in memory, ASLR randomly arranges the address space positions of key data areas of a process, including the base of the executable and the positions of the stack, heap and libraries.
# disable in current session
echo 0 | tee /proc/sys/kernel/randomize_va_space
# make change permanent (across reboots)
echo "kernel.randomize_va_space = 0" > /etc/sysctl.d/01-disable-aslr.conf
Buffer Overflow Protection
Buffer overflow protection is any of various techniques used during software development to enhance the security of executable programs by detecting buffer overflows on stack-allocated variables, and preventing them from causing program misbehavior or from becoming serious security vulnerabilities. A stack buffer overflow occurs when a program writes to a memory address on the program's call stack outside of the intended data structure, which is usually a fixed-length buffer. Stack buffer overflow bugs are caused when a program writes more data to a buffer located on the stack than what is actually allocated for that buffer. This almost always results in corruption of adjacent data on the stack, which could lead to program crashes, incorrect operation, or security issues.
https://en.wikipedia.org/wiki/Buffer_overflow_protection#Canaries
# Compile with -fno-stack-protector -z execstack
gcc stack.c -fno-stack-protector -z execstack -o stack
Considerations
Global Offset Table (GOT) - Stores a map of the global variables
Procedure Linkage Table (PLT) - Stores a map for the ASLR
Disassemble the main function to find the ret(32)/retq(64 aka return quad) instruction
(gdb) disassemble main
Create a break point when the main function returns
(gdb) break *0x0...
Define a hook-stop macro
(gdb) define hook-stop
Setup the hook
# Display the current instruction which will be executed next $eip (32) / $rip (64)
> x/1i $eip
> x/1i $rip
# Examine 8 words as hex from the stack $esp(32)/$rsp(64) and x/8wx(32)/x8gx(64)
> x/8wx $esp
> x/8gx $rsp
# Close the hook stop
> end
Execute it
(gdb) r
The code should break at out breakpoint so let's step into the return
(gdb) si
Run the code with the exploit
(gdb) r < exploit
Step into what should be a segmentation fault
(gdb) si
Inspect the stack register $esp(32)/$rsp(64)
(gdb) x/s $esp
(gdb) x/s $rsp
Run it again
(gdb) r
Step into our return
(gdb) si
Inspect the registers
(gdb) info registers
Update the script with a INT3 and then run
(gdb) r < exploit
Continue the code which should show us telling the instructor to jump to the stack, hitting an int3 and if all worked you will have a SIGTRAP instead of a SIGSEGV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters