Home > Linux, security > Enabling stack randomization in linux

Enabling stack randomization in linux


One way to make the process of exploiting buffer overflow vulnerabilities harder is to enable stack randomization feature.

In case of disabling stack randomization features, it’s so easy for the hacker to guess the address of the first instruction  in the shell code based on the offset from the beginning of the stack, so that to make the life  harder to the hacker (not good ones) we ‘ll enable this feature as shown below:

sysctl -w kernel.randomize_va_space=2

So, if we write a small c program to return with the address of the top of the stack,

#include <stdio.h>

unsigned long topOfStack(void){
__asm__(“movl %esp, %eax”);

int main(void){
printf(“%x\n”, topOfStack());
return 0;

and then run it more, the result ‘ll be as shown:


and so no.

Categories: Linux, security Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: