diff --git a/checksec b/checksec index a5ec78a..9d5a7ae 100755 --- a/checksec +++ b/checksec @@ -823,18 +823,29 @@ filecheck() { fi search_libc - + libc_found="false" + if [[ -n $(ldd ${1} 2> /dev/null | grep 'libc\.so' | cut -d' ' -f3) ]]; then + libc_found="true" + fi FS_filechk_func_libc="$(${readelf} -s "${use_dynamic}" "${FS_libc}" 2> /dev/null | sed -ne 's/.*__\(.*_chk\)@@.*/\1/p')" FS_func_libc="${FS_filechk_func_libc//_chk/}" FS_func="$(${readelf} -s "${use_dynamic}" "${1}" 2> /dev/null | awk '{ print $8 }' | sed -e 's/_*//' -e 's/@.*//' -e '/^$/d')" - FS_cnt_checked=$(grep -cFxf <(sort <<< "${FS_filechk_func_libc}") <(sort <<< "${FS_func}")) - FS_cnt_unchecked=$(grep -cFxf <(sort <<< "${FS_func_libc}") <(sort <<< "${FS_func}")) + FS_cnt_checked=$(grep -cFxf <(sort -u <<< "${FS_filechk_func_libc}") <(sort -u <<< "${FS_func}")) + FS_cnt_unchecked=$(grep -cFxf <(sort -u <<< "${FS_func_libc}") <(sort -u <<< "${FS_func}")) FS_cnt_total=$((FS_cnt_unchecked + FS_cnt_checked)) - if [[ $FS_cnt_checked -eq $FS_cnt_total ]]; then - echo_message '\033[32mYes\033[m' 'Yes,' ' fortify_source="yes" ' '"fortify_source":"yes",' + if [[ "${libc_found}" == "true" ]] || [[ "${FS_cnt_total}" == "0" ]]; then + echo_message "\033[32mN/A\033[m" "N/A," ' fortify_source="n/a" ' '"fortify_source":"n/a",' else - echo_message "\033[31mNo\033[m" "No," ' fortify_source="no" ' '"fortify_source":"no",' + if [[ $FS_cnt_checked -eq $FS_cnt_total ]]; then + echo_message '\033[32mYes\033[m' 'Yes,' ' fortify_source="yes" ' '"fortify_source":"yes",' + else + if [[ "${FS_cnt_checked}" == "0" ]]; then + echo_message "\033[31mNo\033[m" "No," ' fortify_source="no" ' '"fortify_source":"no",' + else + echo_message "\033[33mPartial\033[m" "Partial," ' fortify_source="partial" ' '"fortify_source":"partial",' + fi + fi fi echo_message "\t${FS_cnt_checked}\t" "${FS_cnt_checked}", "fortified=\"${FS_cnt_checked}\" " "\"fortified\":\"${FS_cnt_checked}\"," echo_message "\t${FS_cnt_total}\t\t" "${FS_cnt_total}" "fortify-able=\"${FS_cnt_total}\"" "\"fortify-able\":\"${FS_cnt_total}\"" diff --git a/src/functions/filecheck.sh b/src/functions/filecheck.sh index 197e285..150b802 100644 --- a/src/functions/filecheck.sh +++ b/src/functions/filecheck.sh @@ -130,15 +130,18 @@ filecheck() { fi search_libc - + libc_found="false" + if [[ -n $(ldd ${1} 2> /dev/null | grep 'libc\.so' | cut -d' ' -f3) ]]; then + libc_found="true" + fi FS_filechk_func_libc="$(${readelf} -s "${use_dynamic}" "${FS_libc}" 2> /dev/null | sed -ne 's/.*__\(.*_chk\)@@.*/\1/p')" FS_func_libc="${FS_filechk_func_libc//_chk/}" FS_func="$(${readelf} -s "${use_dynamic}" "${1}" 2> /dev/null | awk '{ print $8 }' | sed -e 's/_*//' -e 's/@.*//' -e '/^$/d')" - FS_cnt_checked=$(grep -cFxf <(sort <<< "${FS_filechk_func_libc}") <(sort <<< "${FS_func}")) - FS_cnt_unchecked=$(grep -cFxf <(sort <<< "${FS_func_libc}") <(sort <<< "${FS_func}")) + FS_cnt_checked=$(grep -cFxf <(sort -u <<< "${FS_filechk_func_libc}") <(sort -u <<< "${FS_func}")) + FS_cnt_unchecked=$(grep -cFxf <(sort -u <<< "${FS_func_libc}") <(sort -u <<< "${FS_func}")) FS_cnt_total=$((FS_cnt_unchecked + FS_cnt_checked)) - if [[ "${FS_cnt_total}" == "0" ]]; then + if [[ "${libc_found}" == "true" ]] || [[ "${FS_cnt_total}" == "0" ]]; then echo_message "\033[32mN/A\033[m" "N/A," ' fortify_source="n/a" ' '"fortify_source":"n/a",' else if [[ $FS_cnt_checked -eq $FS_cnt_total ]]; then