I've read that stack usually starts in same address so the attacker may guess the starting point of the buffer to overflow. This is necessary to know this address to make the malicious code run. I made a program with a few lines of code to get the stack pointer address each time it starts and print it on the screen:
int * get_stack_pointer(){
__asm__("mov %esp,%eax");
}
void main(){
printf("Address: %p\n",get_stack_pointer());
}
And this is disassembly of the program:
<get_stack_pointer>:
push %rbp
mov %rsp,%rbp
mov %esp,%eax
pop %rbp
retq
<main>:
push %rbp
mov %rsp,%rbp
mov $0x0,%eax
callq 40050c <get_stack_pointer>
mov %rax,%rsi
mov $0x4005ec,%edi
mov $0x0,%eax
callq 4003e0 <printf@plt>
pop %rbp
retq
But each time I start the program I get different addresses. Some of these are as following:
Address: 0xc31b2c80
Address: 0x2e041e0
Address: 0x7b003190
Address: 0xb3fd1350
So in this case how is it possible for the attacker to run his code on the vulnerable program? (my OS is Linux 64bit)
EDIT: I made another program in assembly which includes a few simple lines. I just check the value of RSP every time it starts with debugger and I see always RSP has the same value but not the program written in c.