I've been writing Heap-based buffer overflow exploits for a deliberately vulnerable (that I wrote). To hijack control flow, I overwrite the function's return address on stack.
These exploits depend on the stack being at a particular (hardcoded) location.
I assumed this OK because I disabled ASLR (I'm running Ubuntu 14.04, x86_64):
I disabled ASLR by adding kernel.randomize_va_space = 0
to my /etc/sysctl.conf
and rebooting the machine.
I've confirmed ASLR has been disabled through the following command:
$ cat /proc/sys/kernel/randomize_va_space
0
But the address of the stack when main begins clearly changes. To test this, I loaded the program in gdb and broke on the first asm instruction and did the following:
(gdb) p $rsp
$1 = (void *) 0x7fffffffe538
Then I rebooted and I did the same
(gdb) p $rsp
$1 = (void *) 0x7fffffffe558
Is this behavior expected? Can I disable it so that a particular binary will always have the same stack address? If not do real exploits need to leak the stack's address to do this? Is there a common technique for this?