| 1 |
#!/usr/bin/env bash |
| 2 |
set -ou pipefail |
| 3 |
if [[ -f /bin/bash ]]; then |
| 4 |
test_file="/bin/bash" |
| 5 |
elif [[ -f /bin/sh ]]; then |
| 6 |
test_file="/bin/sh" |
| 7 |
elif [[ -f /bin/ls ]]; then |
| 8 |
test_file="/bin/ls" |
| 9 |
else |
| 10 |
echo "could not find valid file to test" |
| 11 |
exit 255 |
| 12 |
fi |
| 13 |
|
| 14 |
DIR=$( |
| 15 |
cd "$(dirname "$0")" |
| 16 |
pwd |
| 17 |
) |
| 18 |
PARENT=$( |
| 19 |
cd "$(dirname "$0")/.." |
| 20 |
pwd |
| 21 |
) |
| 22 |
|
| 23 |
#check xml for proc-all |
| 24 |
echo "starting proc-all check - xml" |
| 25 |
"${PARENT}"/checksec --format=xml --proc-all > "${DIR}/output.xml" |
| 26 |
xmllint --noout "${DIR}/output.xml" |
| 27 |
RET=$? |
| 28 |
if [ ${RET} != 0 ]; then |
| 29 |
cat "${DIR}/output.xml" |
| 30 |
echo "proc-all xml validation failed" |
| 31 |
exit 1 |
| 32 |
fi |
| 33 |
|
| 34 |
#check xml for proc-all |
| 35 |
echo "starting extended proc-all check - xml" |
| 36 |
"${PARENT}"/checksec --format=xml --proc-all --extended > "${DIR}/output.xml" |
| 37 |
xmllint --noout "${DIR}/output.xml" |
| 38 |
RET=$? |
| 39 |
if [ ${RET} != 0 ]; then |
| 40 |
cat "${DIR}/output.xml" |
| 41 |
echo "proc-all xml validation failed" |
| 42 |
exit 1 |
| 43 |
fi |
| 44 |
|
| 45 |
#check xml for kernel |
| 46 |
echo "starting kernel check - xml" |
| 47 |
"${PARENT}"/checksec --format=xml --kernel > "${DIR}/output.xml" |
| 48 |
xmllint --noout "${DIR}/output.xml" |
| 49 |
RET=$? |
| 50 |
if [ ${RET} != 0 ]; then |
| 51 |
cat "${DIR}/output.xml" |
| 52 |
echo "kernel xml validation failed" |
| 53 |
exit 1 |
| 54 |
fi |
| 55 |
|
| 56 |
echo "starting custom kernel check for file kernel.config - json" |
| 57 |
"${PARENT}"/checksec --format=xml --kernel=kernel.config > "${DIR}"/output.xml |
| 58 |
xmllint --noout "${DIR}/output.xml" |
| 59 |
RET=$? |
| 60 |
if [ ${RET} != 0 ]; then |
| 61 |
cat "${DIR}/output.xml" |
| 62 |
echo "custom kernel json validation failed" |
| 63 |
exit 1 |
| 64 |
fi |
| 65 |
|
| 66 |
while read -r file; do |
| 67 |
#check xml against custom kernel config to trigger all checks |
| 68 |
echo "starting custom kernel check for file ${file} - xml" |
| 69 |
"${PARENT}"/checksec --format=xml --kernel="${file}" > "${DIR}/output.xml" |
| 70 |
xmllint --noout "${DIR}/output.xml" |
| 71 |
RET=$? |
| 72 |
if [ ${RET} != 0 ]; then |
| 73 |
cat "${DIR}/output.xml" |
| 74 |
echo "custom kernel xml validation failed" |
| 75 |
exit 1 |
| 76 |
fi |
| 77 |
done < <(find "${PARENT}"/kernel_configs/configs/ -type f -iname "config-*") |
| 78 |
|
| 79 |
#check xml for file |
| 80 |
echo "starting file check - xml" |
| 81 |
"${PARENT}"/checksec --format=xml --file="${test_file}" > "${DIR}/output.xml" |
| 82 |
xmllint --noout "${DIR}/output.xml" |
| 83 |
RET=$? |
| 84 |
if [ ${RET} != 0 ]; then |
| 85 |
cat "${DIR}/output.xml" |
| 86 |
echo "file xml validation failed" |
| 87 |
exit 1 |
| 88 |
fi |
| 89 |
|
| 90 |
#check xml for file |
| 91 |
echo "starting extended file check - xml" |
| 92 |
"${PARENT}"/checksec --format=xml --file="${test_file}" --extended > "${DIR}/output.xml" |
| 93 |
xmllint --noout "${DIR}/output.xml" |
| 94 |
RET=$? |
| 95 |
if [ ${RET} != 0 ]; then |
| 96 |
cat "${DIR}/output.xml" |
| 97 |
echo "file xml validation failed" |
| 98 |
exit 1 |
| 99 |
fi |
| 100 |
|
| 101 |
#check xml for fortify file |
| 102 |
echo "starting fortify-file check - xml" |
| 103 |
"${PARENT}"/checksec --format=xml --fortify-file="${test_file}" > "${DIR}/output.xml" |
| 104 |
xmllint --noout "${DIR}/output.xml" |
| 105 |
RET=$? |
| 106 |
if [ ${RET} != 0 ]; then |
| 107 |
cat "${DIR}/output.xml" |
| 108 |
echo "fortify-file xml validation failed" |
| 109 |
exit 1 |
| 110 |
fi |
| 111 |
|
| 112 |
#check xml for fortify file |
| 113 |
echo "starting extended fortify-file check - xml" |
| 114 |
"${PARENT}"/checksec --format=xml --fortify-file="${test_file}" --extended > "${DIR}/output.xml" |
| 115 |
xmllint --noout "${DIR}/output.xml" |
| 116 |
RET=$? |
| 117 |
if [ ${RET} != 0 ]; then |
| 118 |
cat "${DIR}/output.xml" |
| 119 |
echo "fortify-file xml validation failed" |
| 120 |
exit 1 |
| 121 |
fi |
| 122 |
|
| 123 |
#check xml for fortify proc |
| 124 |
echo "starting fortify-proc check - xml" |
| 125 |
"${PARENT}"/checksec --format=xml --fortify-proc=1 > "${DIR}/output.xml" |
| 126 |
xmllint --noout "${DIR}/output.xml" |
| 127 |
RET=$? |
| 128 |
if [ ${RET} != 0 ]; then |
| 129 |
cat "${DIR}/output.xml" |
| 130 |
echo "fortify-proc xml validation failed" |
| 131 |
exit 1 |
| 132 |
fi |
| 133 |
|
| 134 |
#check xml for fortify proc |
| 135 |
echo "starting extended fortify-proc check - xml" |
| 136 |
"${PARENT}"/checksec --format=xml --fortify-proc=1 --extended > "${DIR}/output.xml" |
| 137 |
xmllint --noout "${DIR}/output.xml" |
| 138 |
RET=$? |
| 139 |
if [ ${RET} != 0 ]; then |
| 140 |
cat "${DIR}/output.xml" |
| 141 |
echo "fortify-proc xml validation failed" |
| 142 |
exit 1 |
| 143 |
fi |
| 144 |
|
| 145 |
#check xml for dir |
| 146 |
echo "starting dir check - xml" |
| 147 |
"${PARENT}"/checksec --format=xml --dir=/sbin > "${DIR}/output.xml" |
| 148 |
xmllint --noout "${DIR}/output.xml" |
| 149 |
RET=$? |
| 150 |
if [ ${RET} != 0 ]; then |
| 151 |
cat "${DIR}/output.xml" |
| 152 |
echo "dir xml validation failed" |
| 153 |
exit 1 |
| 154 |
fi |
| 155 |
|
| 156 |
echo "All XML validation tests passed xmllint" |
| 157 |
rm -f "${DIR}/output.xml" |