Reputation: 753
I'm working on a binary-based Capture The Flag exercise, the first one in a series. I had the idea of writing code to the stack and executing it. To test this out, I ran the executable with a special input, so that it would jump to the code in the stack. To test this, I used gdb
, and it worked!
However, when I tried to run this outside of gdb
, I received the dreaded Segmentation Fault
. I think this is because Ubuntu 16.04 does not allow code to be executed on the stack, but I'm not sure.
If this is the case, how come I could execute in gdb
?
Also also, I tried using execstack -s
on the exercise binary, it didn't do anything, so I'm starting to suspect that I may be having different issues. But, if I'm having different issues, how do I debug those issues without resorting to gdb
, wherein the process works perfectly?
Upvotes: 1
Views: 1037
Reputation: 753
Thanks to Mark Plotnick for helping me with this answer!
It turns out that I could execute from stack, in GDB and outside GDB. The issue was, indeed, ASLR. I finagled the stack pointer's "actual value" so that the program would "return to stack" where I injected the program. This is as opposed to writing the stack pointer's memory address as an immediate, which worked in GDB, but wouldn't work outside it because, as Mark Plotnick says, "GDB turns off ASLR" which randomizes the stack pointer's base address.
Upvotes: 1