| 1 |
#!/usr/bin/env bash |
| 2 |
# shellcheck disable=SC2154 |
| 3 |
# these top lines are moved during build |
| 4 |
|
| 5 |
# check process(es) |
| 6 |
proccheck() { |
| 7 |
# check for RELRO support |
| 8 |
if ${readelf} -l "${1}/exe" 2> /dev/null | grep -q 'Program Headers'; then |
| 9 |
if ${readelf} -l "${1}/exe" 2> /dev/null | grep -q 'GNU_RELRO'; then |
| 10 |
if ${readelf} -d "${1}/exe" 2> /dev/null | grep -q 'BIND_NOW'; then |
| 11 |
echo_message '\033[32mFull RELRO \033[m ' 'Full RELRO,' ' relro="full"' '"relro":"full",' |
| 12 |
else |
| 13 |
echo_message '\033[33mPartial RELRO\033[m ' 'Partial RELRO,' ' relro="partial"' '"relro":"partial",' |
| 14 |
fi |
| 15 |
else |
| 16 |
echo_message '\033[31mNo RELRO \033[m ' 'No RELRO,' ' relro="no"' '"relro":"no",' |
| 17 |
fi |
| 18 |
else |
| 19 |
echo -n -e '\033[31mPermission denied (please run as root)\033[m\n' |
| 20 |
exit 1 |
| 21 |
fi |
| 22 |
|
| 23 |
# check for stack canary support |
| 24 |
if ${readelf} -s "${1}/exe" 2> /dev/null | grep -q 'Symbol table'; then |
| 25 |
if ${readelf} -s "${1}/exe" 2> /dev/null | grep -Eq '__stack_chk_fail|__stack_chk_guard|__intel_security_cookie'; then |
| 26 |
echo_message '\033[32mCanary found \033[m ' 'Canary found,' ' canary="yes"' '"canary":"yes",' |
| 27 |
else |
| 28 |
echo_message '\033[31mNo canary found \033[m ' 'No Canary found,' ' canary="no"' '"canary":"no",' |
| 29 |
fi |
| 30 |
else |
| 31 |
if [[ "${1}" == "1" ]]; then |
| 32 |
echo_message '\033[33mPermission denied \033[m ' 'Permission denied,' ' canary="Permission denied"' '"canary":"Permission denied",' |
| 33 |
else |
| 34 |
echo_message '\033[33mNo symbol table found \033[m ' 'No symbol table found,' ' canary="No symbol table found"' '"canary":"No symbol table found",' |
| 35 |
fi |
| 36 |
fi |
| 37 |
|
| 38 |
if ${extended_checks}; then |
| 39 |
# check if compiled with Clang CFI |
| 40 |
$debug && echo -e "\n***function proccheck->clangcfi" |
| 41 |
#if $readelf -s "$1" 2>/dev/null | grep -Eq '\.cfi'; then |
| 42 |
read -r -a cfifunc <<< "$($readelf -s "$1/exe" 2> /dev/null | grep .cfi | awk '{ print $8 }')" |
| 43 |
func=${cfifunc/.cfi/} |
| 44 |
# TODO: fix this check properly, need more clang CFI files to be able to test properly |
| 45 |
# shellcheck disable=SC2128 |
| 46 |
if [ -n "$cfifunc" ] && $readelf -s "$1/exe" 2> /dev/null | grep -q "$func$"; then |
| 47 |
echo_message '\033[32mClang CFI found \033[m ' 'with CFI,' ' clangcfi="yes"' '"clangcfi":"yes",' |
| 48 |
else |
| 49 |
echo_message '\033[31mNo Clang CFI found\033[m ' 'without CFI,' ' clangcfi="no"' '"clangcfi":"no",' |
| 50 |
fi |
| 51 |
|
| 52 |
# check if compiled with Clang SafeStack |
| 53 |
$debug && echo -e "\n***function proccheck->safestack" |
| 54 |
if $readelf -s "$1/exe" 2> /dev/null | grep -Eq '__safestack_init'; then |
| 55 |
echo_message '\033[32mSafeStack found \033[m ' 'with SafeStack,' ' safestack="yes"' '"safestack":"yes",' |
| 56 |
else |
| 57 |
echo_message '\033[31mNo SafeStack found\033[m ' 'without SafeStack,' ' safestack="no"' '"safestack":"no",' |
| 58 |
fi |
| 59 |
fi |
| 60 |
|
| 61 |
# check for Seccomp mode |
| 62 |
seccomp=$(grep 'Seccomp:' "${1}/status" 2> /dev/null | cut -b10) |
| 63 |
if [[ "${seccomp}" == "1" ]]; then |
| 64 |
echo_message '\033[32mSeccomp strict\033[m ' 'Seccomp strict,' ' seccomp="strict"' '"seccomp":"strict",' |
| 65 |
elif [[ "${seccomp}" == "2" ]]; then |
| 66 |
echo_message '\033[32mSeccomp-bpf \033[m ' 'Seccomp-bpf,' ' seccomp="bpf"' '"seccomp":"bpf",' |
| 67 |
else |
| 68 |
echo_message '\033[31mNo Seccomp \033[m ' 'No Seccomp,' ' seccomp="no"' '"seccomp":"no",' |
| 69 |
fi |
| 70 |
|
| 71 |
# first check for PaX support |
| 72 |
if grep -q 'PaX:' "${1}/status" 2> /dev/null; then |
| 73 |
pageexec=$(grep 'PaX:' "${1}/status" 2> /dev/null | cut -b6) |
| 74 |
segmexec=$(grep 'PaX:' "${1}/status" 2> /dev/null | cut -b10) |
| 75 |
mprotect=$(grep 'PaX:' "${1}/status" 2> /dev/null | cut -b8) |
| 76 |
randmmap=$(grep 'PaX:' "${1}/status" 2> /dev/null | cut -b9) |
| 77 |
if [[ "${pageexec}" = "P" || "${segmexec}" = "S" ]] && [[ "${mprotect}" = "M" && "${randmmap}" = "R" ]]; then |
| 78 |
echo_message '\033[32mPaX enabled\033[m ' 'Pax enabled,' ' pax="yes"' '"pax":"yes",' |
| 79 |
elif [[ "${pageexec}" = "p" && "${segmexec}" = "s" && "${randmmap}" = "R" ]]; then |
| 80 |
echo_message '\033[33mPaX ASLR only\033[m ' 'Pax ASLR only,' ' pax="aslr_only"' '"pax":"aslr_only",' |
| 81 |
elif [[ "${pageexec}" = "P" || "${segmexec}" = "S" ]] && [[ "${mprotect}" = "m" && "${randmmap}" = "R" ]]; then |
| 82 |
echo_message '\033[33mPaX mprot off \033[m' 'Pax mprot off,' ' pax="mprot_off"' '"pax":"mprot_off",' |
| 83 |
elif [[ "${pageexec}" = "P" || "${segmexec}" = "S" ]] && [[ "${mprotect}" = "M" && "${randmmap}" = "r" ]]; then |
| 84 |
echo_message '\033[33mPaX ASLR off\033[m ' 'Pax ASLR off,' ' pax="aslr_off"' '"pax":"aslr_off",' |
| 85 |
elif [[ "${pageexec}" = "P" || "${segmexec}" = "S" ]] && [[ "${mprotect}" = "m" && "${randmmap}" = "r" ]]; then |
| 86 |
echo_message '\033[33mPaX NX only\033[m ' 'Pax NX only,' ' pax="nx_only"' '"pax":"nx_only",' |
| 87 |
else |
| 88 |
echo_message '\033[31mPaX disabled\033[m ' 'Pax disabled,' ' pax="no"' '"pax":"no",' |
| 89 |
fi |
| 90 |
# fallback check for NX support |
| 91 |
elif ${readelf} -l "${1}/exe" 2> /dev/null | grep 'GNU_STACK' | grep -q 'RWE'; then |
| 92 |
echo_message '\033[31mNX disabled\033[m ' 'NX disabled,' ' nx="no"' '"nx":"no",' |
| 93 |
else |
| 94 |
echo_message '\033[32mNX enabled \033[m ' 'NX enabled,' ' pax="yes"' '"nx":"yes",' |
| 95 |
fi |
| 96 |
|
| 97 |
# check for PIE support |
| 98 |
if ${readelf} -h "${1}/exe" 2> /dev/null | grep -q 'Type:[[:space:]]*EXEC'; then |
| 99 |
echo_message '\033[31mNo PIE \033[m ' 'No PIE,' ' pie="no"' '"pie":"no",' |
| 100 |
elif ${readelf} -h "${1}/exe" 2> /dev/null | grep -q 'Type:[[:space:]]*DYN'; then |
| 101 |
if ${readelf} -d "${1}/exe" 2> /dev/null | grep -q 'DEBUG'; then |
| 102 |
echo_message '\033[32mPIE enabled \033[m ' 'PIE enabled,' ' pie="yes"' '"pie":"yes",' |
| 103 |
else |
| 104 |
echo_message '\033[33mDynamic Shared Object\033[m ' 'Dynamic Shared Object,' ' pie="dso"' '"pie":"dso",' |
| 105 |
fi |
| 106 |
else |
| 107 |
echo_message '\033[33mNot an ELF file \033[m ' 'Not an ELF file,' ' pie="not_elf"' '"pie":"not_elf",' |
| 108 |
fi |
| 109 |
|
| 110 |
if ${extended_checks}; then |
| 111 |
# check for selfrando support |
| 112 |
if ${readelf} -S "${1}/exe" 2> /dev/null | grep -c txtrp | grep -q '1'; then |
| 113 |
echo_message '\033[32mSelfrando enabled \033[m ' |
| 114 |
else |
| 115 |
echo_message '\033[31mNo Selfrando \033[m ' |
| 116 |
fi |
| 117 |
fi |
| 118 |
|
| 119 |
#check for forifty source support |
| 120 |
Proc_FS_functions="$(${readelf} -s "${1}/exe" 2> /dev/null | awk '{ print $8 }' | sed 's/_*//' | sed -e 's/@.*//')" |
| 121 |
if grep -q '_chk$' <<< "$Proc_FS_functions"; then |
| 122 |
echo_message '\033[32mYes\033[m' 'Yes' " fortify_source='yes'>" '"fortify_source":"yes" }' |
| 123 |
else |
| 124 |
echo_message "\033[31mNo\033[m" "No" " fortify_source='no'>" '"fortify_source":"no" }' |
| 125 |
fi |
| 126 |
} |