I would like to disable address space layout randomization (ASLR) on my system (Ubuntu Gnu/Linux 2.6.32-41-server), but, if I use
sysctl -w kernel.randomize_
The best way to disable locally the ASLR on a Linux-based system is to use processes personality flags. The command to manipulate personality flags is setarch with
-R,--addr-no-randomizeDisables randomization of the virtual address space (turns on ADDR_NO_RANDOMIZE).
Here is how to proceed:
$> setarch $(uname -m) -R /bin/bash
This command runs a shell in which the ASLR has been disabled. All descendants of this process will inherit of the personality flags of the father and thus have a disabled ASLR. The only way to break the inheritance of the flags would be to call a setuid program (it would be a security breach to support such feature).
Note that the uname -m is here to not hard-code the architecture of your platform and make this command portable.