Information
Address space layout randomization (ASLR) is an exploit mitigation technique which randomly arranges the address space of key data areas of a process.
Randomly placing virtual memory regions will make it difficult to write memory page exploits as the memory placement will be consistently shifting.
Solution
- Review all files ending in .conf in the /etc/sysctl.d directory and comment out or remove all kernel.randomize_va_space lines that are not kernel.randomize_va_spacee=2.
Example script:
#!/usr/bin/env bash
{
l_option="kernel.randomize_va_space" l_grep="${l_option//./\\.}" l_value="2"
while IFS= read -r -d $'\0' l_file; do
grep -Poi '\h*'"$l_option"'\h*=\h*\H+\b' "$l_file" \
| grep -Pivq '^\h*'"$l_grep"'\h*=\h*'"$l_value"'\b' && \
sed -ri '/^\s*kernel.yama.ptrace_scope\s*=/s/^/# /' "$l_file"
done < <(find /etc/sysctl.d/ -type f -name '*.conf' -print0)
}
- Create or edit a file in the /etc/sysctl.d/ directory ending in .conf and edit or add the following line:
kernel.randomize_va_space = 2
Example:
# [ ! -d "/etc/sysctl.d/" ] && mkdir -p /etc/sysctl.d/
# printf '%s\n' "" "kernel.randomize_va_space = 2" >> /etc/sysctl.d/60-kernel_sysctl.conf
- Run the following command to load all system configuration filles:
# sysctl --system