Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More threading in f19 and r09 #102

Merged
merged 3 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/bin_version_strings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ libc:binary:"GNU\ C\ Library\ \(.*\)\ stable\ release\ version\ [0-9]\.[0-9]+$"
libcurl:binary:"CLIENT\ libcurl\ [0-9]\.[0-9]+\.[0-9]+"
libexpat:binary:"expat_[0-9]\.[0-9]+\.[0-9]+$"
libgcrypt::"[Ll]ibgcrypt\ [0-9]\.[0-9]+\.[0-9]+$"
libgcrypt::"[Ll]ibgcrypt\ [0-9]\.[0-9]+\.[0-9]+\ "
libgcrypt::"[Ll]ibgcrypt\ [0-9]\.[0-9]+\.[0-9]+-[a-z]+$"
liblzma::"liblzma\ [0-9]\.[0-9]+\.[0-9]+$"
libpcap:binary:"libpcap\ version\ [0-9]\.[0-9]+\.[0-9]+$"
Expand Down
10 changes: 7 additions & 3 deletions modules/F19_cve_aggregator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,12 @@ cve_db_lookup() {

{ echo ""
echo "[+] Statistics:$CVE_COUNTER_VERSION|$EXPLOIT_COUNTER_VERSION|$VERSION_SEARCH"
echo "[+] Statistics1:$HIGH_CVE_COUNTER|$MEDIUM_CVE_COUNTER|$LOW_CVE_COUNTER"
#echo "[+] Statistics1:$HIGH_CVE_COUNTER|$MEDIUM_CVE_COUNTER|$LOW_CVE_COUNTER"
} >> "$LOG_DIR"/aggregator/"$VERSION_PATH".txt
echo "$LOW_CVE_COUNTER" >> "$TMP_DIR"/LOW_CVE_COUNTER.tmp
echo "$MEDIUM_CVE_COUNTER" >> "$TMP_DIR"/MEDIUM_CVE_COUNTER.tmp
echo "$HIGH_CVE_COUNTER" >> "$TMP_DIR"/HIGH_CVE_COUNTER.tmp
echo "$EXPLOIT_COUNTER" >> "$TMP_DIR"/EXPLOIT_COUNTER.tmp

if [[ "$EXPLOIT_COUNTER_VERSION" -gt 0 ]]; then
print_output ""
Expand All @@ -678,7 +682,7 @@ generate_cve_details() {

for VERSION in "${VERSIONS_CLEANED[@]}"; do
# threading currently not working. This is work in progress
if [[ "$THREADED" -eq "X" ]]; then
if [[ "$THREADED" -eq 1 ]]; then
cve_db_lookup &
WAIT_PIDS_F19+=( "$!" )
max_pids_protection "${WAIT_PIDS_F19[@]}"
Expand All @@ -687,7 +691,7 @@ generate_cve_details() {
fi
done

if [[ "$THREADED" -eq "X" ]]; then
if [[ "$THREADED" -eq 1 ]]; then
wait_for_pid "${WAIT_PIDS_F19[@]}"
fi

Expand Down
23 changes: 23 additions & 0 deletions modules/F50_base_aggregator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,29 @@ get_data() {
export TOTAL_CWE_CNT
TOTAL_CWE_CNT=$(grep -a "\[\*\]\ Statistics:" "$LOG_DIR"/"$S120_LOG" | cut -d: -f2)
fi
if [[ -f "$TMP_DIR"/HIGH_CVE_COUNTER.tmp ]]; then
while read -r COUNTING; do
(( HIGH_CVE_COUNTER="$HIGH_CVE_COUNTER"+"$COUNTING" ))
done < "$TMP_DIR"/HIGH_CVE_COUNTER.tmp
(( CVE_COUNTER="$CVE_COUNTER"+"$HIGH_CVE_COUNTER" ))
fi
if [[ -f "$TMP_DIR"/MEDIUM_CVE_COUNTER.tmp ]]; then
while read -r COUNTING; do
(( MEDIUM_CVE_COUNTER="$MEDIUM_CVE_COUNTER"+"$COUNTING" ))
done < "$TMP_DIR"/MEDIUM_CVE_COUNTER.tmp
(( CVE_COUNTER="$CVE_COUNTER"+"$MEDIUM_CVE_COUNTER" ))
fi
if [[ -f "$TMP_DIR"/LOW_CVE_COUNTER.tmp ]]; then
while read -r COUNTING; do
(( LOW_CVE_COUNTER="$LOW_CVE_COUNTER"+"$COUNTING" ))
done < "$TMP_DIR"/LOW_CVE_COUNTER.tmp
(( CVE_COUNTER="$CVE_COUNTER"+"$LOW_CVE_COUNTER" ))
fi
if [[ -f "$TMP_DIR"/EXPLOIT_COUNTER.tmp ]]; then
while read -r COUNTING; do
(( EXPLOIT_COUNTER="$EXPLOIT_COUNTER"+"$COUNTING" ))
done < "$TMP_DIR"/EXPLOIT_COUNTER.tmp
fi
}

os_detector() {
Expand Down
74 changes: 42 additions & 32 deletions modules/R09_firmware_base_version_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@ R09_firmware_base_version_check() {
module_log_init "${FUNCNAME[0]}"
module_title "Binary firmware versions detection"

detect_binary_versions
}

detect_binary_versions() {
echo -e "\n"
print_output "[*] Initial version detection running on all firmware files ..." | tr -d "\n"

EXTRACTOR_LOG="$LOG_DIR"/p05_firmware_bin_extractor.txt
declare -a VERSIONS_DETECTED

while read -r VERSION_LINE; do
echo "." | tr -d "\n"
Expand All @@ -38,44 +33,59 @@ detect_binary_versions() {

# as we do not have a typical linux executable we can't use strict version details
if [[ $STRICT != "strict" ]]; then

#print_output "[*] $VERSION_LINE"
VERSION_IDENTIFIER="$(echo "$VERSION_LINE" | cut -d: -f3- | sed s/^\"// | sed s/\"$//)"
echo "." | tr -d "\n"

# currently we only have binwalk files but sometimes we can find kernel version information or something else in it
VERSION_FINDER=$(grep -o -a -E "$VERSION_IDENTIFIER" "$EXTRACTOR_LOG" 2>/dev/null | head -1 2>/dev/null)

if [[ -n $VERSION_FINDER ]]; then
echo ""
print_output "[+] Version information found ${RED}""$VERSION_FINDER""${NC}${GREEN} in extraction logs."
VERSIONS_DETECTED+=("$VERSION_FINDER")
if [[ "$THREADED" -eq 1 ]]; then
R09_bin_string_checker &
WAIT_PIDS_R09+=( "$!" )
else
R09_bin_string_checker
fi
fi

echo "." | tr -d "\n"
done < "$CONFIG_DIR"/bin_version_strings.cfg
echo "." | tr -d "\n"

if [[ -f $FIRMWARE_PATH ]]; then
VERSION_FINDER=$(find "$FIRMWARE_PATH" -type f -print0 2>/dev/null | xargs -0 strings | grep -o -a -E "$VERSION_IDENTIFIER" | head -1 2>/dev/null)
if [[ "$THREADED" -eq 1 ]]; then
wait_for_pid "${WAIT_PIDS_R09[@]}"
fi

if [[ -n $VERSION_FINDER ]]; then
echo ""
print_output "[+] Version information found ${RED}""$VERSION_FINDER""${NC}${GREEN} in original firmware file (static)."
VERSIONS_DETECTED+=("$VERSION_FINDER")
fi
echo "." | tr -d "\n"
fi
VERSIONS_DETECTED=$(grep -c "Version information found" "$( get_log_file )")

VERSION_FINDER=$(find "$OUTPUT_DIR" -type f -print0 2> /dev/null | xargs -0 strings | grep -o -a -E "$VERSION_IDENTIFIER" | head -1 2> /dev/null)
module_end_log "${FUNCNAME[0]}" "$VERSIONS_DETECTED"
}

if [[ -n $VERSION_FINDER ]]; then
echo ""
print_output "[+] Version information found ${RED}""$VERSION_FINDER""${NC}${GREEN} in extracted firmware files (static)."
VERSIONS_DETECTED+=("$VERSION_FINDER")
fi
echo "." | tr -d "\n"
fi
R09_bin_string_checker() {

# currently we only have binwalk files but sometimes we can find kernel version information or something else in it
VERSION_FINDER=$(grep -o -a -E "$VERSION_IDENTIFIER" "$EXTRACTOR_LOG" 2>/dev/null | head -1 2>/dev/null)

if [[ -n $VERSION_FINDER ]]; then
echo ""
print_output "[+] Version information found ${RED}""$VERSION_FINDER""${NC}${GREEN} in extraction logs."
fi

done < "$CONFIG_DIR"/bin_version_strings.cfg
echo "." | tr -d "\n"

module_end_log "${FUNCNAME[0]}" "${#VERSIONS_DETECTED[@]}"
if [[ -f $FIRMWARE_PATH ]]; then
VERSION_FINDER=$(find "$FIRMWARE_PATH" -type f -print0 2>/dev/null | xargs -0 strings | grep -o -a -E "$VERSION_IDENTIFIER" | head -1 2>/dev/null)

if [[ -n $VERSION_FINDER ]]; then
echo ""
print_output "[+] Version information found ${RED}""$VERSION_FINDER""${NC}${GREEN} in original firmware file (static)."
fi
echo "." | tr -d "\n"
fi

VERSION_FINDER=$(find "$OUTPUT_DIR" -type f -print0 2> /dev/null | xargs -0 strings | grep -o -a -E "$VERSION_IDENTIFIER" | head -1 2> /dev/null)

if [[ -n $VERSION_FINDER ]]; then
echo ""
print_output "[+] Version information found ${RED}""$VERSION_FINDER""${NC}${GREEN} in extracted firmware files (static)."
fi
echo "." | tr -d "\n"
}