Debian Codegraph @

src/functions/aslrcheck.sh

raw
1 #!/usr/bin/env bash
2 # shellcheck disable=SC2154
3 # these top lines are moved during build
4
5 # check for system-wide ASLR support
6 aslrcheck() {
7 # PaX ASLR support
8 if ! (grep -q 'Name:' /proc/1/status 2> /dev/null); then
9 echo_message '\033[33m insufficient privileges for PaX ASLR checks\033[m\n' '' '' ''
10 echo_message ' Fallback to standard Linux ASLR check' '' '' ''
11 fi
12
13 if grep -q 'PaX:' /proc/1/status 2> /dev/null; then
14 if grep -q 'PaX:' /proc/1/status 2> /dev/null | grep -q 'R'; then
15 echo_message '\033[32mPaX ASLR enabled\033[m\n\n' '' '' ''
16 else
17 echo_message '\033[31mPaX ASLR disabled\033[m\n\n' '' '' ''
18 fi
19 else
20 # standard Linux 'kernel.randomize_va_space' ASLR support
21 # (see the kernel file 'Documentation/sysctl/kernel.txt' for a detailed description)
22 echo_message " (kernel.randomize_va_space): " '' '' ''
23 if sysctl -a 2> /dev/null | grep -q 'kernel.randomize_va_space = 1'; then
24 echo_message '\033[33mPartial (Setting: 1)\033[m\n\n' '' '' ''
25 echo_message " Description - Make the addresses of mmap base, stack and VDSO page randomized.\n" '' '' ''
26 echo_message " This, among other things, implies that shared libraries will be loaded to \n" '' '' ''
27 echo_message " random addresses. Also for PIE-linked binaries, the location of code start\n" '' '' ''
28 echo_message " is randomized. Heap addresses are *not* randomized.\n\n" '' '' ''
29 elif sysctl -a 2> /dev/null | grep -q 'kernel.randomize_va_space = 2'; then
30 echo_message '\033[32mFull (Setting: 2)\033[m\n\n' '' '' ''
31 echo_message " Description - Make the addresses of mmap base, heap, stack and VDSO page randomized.\n" '' '' ''
32 echo_message " This, among other things, implies that shared libraries will be loaded to random \n" '' '' ''
33 echo_message " addresses. Also for PIE-linked binaries, the location of code start is randomized.\n\n" '' '' ''
34 elif sysctl -a 2> /dev/null | grep -q 'kernel.randomize_va_space = 0'; then
35 echo_message '\033[31mNone (Setting: 0)\033[m\n' '' '' ''
36 else
37 echo_message '\033[31mNot supported\033[m\n' '' '' ''
38 fi
39 echo_message " See the kernel file 'Documentation/sysctl/kernel.txt' for more details.\n\n" '' '' ''
40 fi
41 }