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

check braces for modules scripts #861

Merged
merged 3 commits into from
Nov 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions modules/D02_firmware_diffing_bin_details.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ D02_firmware_diffing_bin_details() {
module_title "Firmware differ - binary details"
local NEG_LOG=0

if ! [[ -f "$FIRMWARE_PATH" ]]; then
if ! [[ -f "${FIRMWARE_PATH}" ]]; then
print_output "[-] No 1st file for diffing provided"
return
fi
if ! [[ -f "$FIRMWARE_PATH1" ]]; then
if ! [[ -f "${FIRMWARE_PATH1}" ]]; then
print_output "[-] No 2nd file for diffing provided"
return
fi
Expand All @@ -53,8 +53,8 @@ D02_firmware_diffing_bin_details() {
print_fw_file_details "${FIRMWARE_PATH}"
# generate_pixde "${FIRMWARE_PATH}"
fw_bin_detector "${FIRMWARE_PATH}"
if [[ -f "$LOG_DIR"/firmware_entropy.png ]]; then
mv "$LOG_DIR"/firmware_entropy.png "${LOG_PATH_MODULE}"/firmware1_entropy.png
if [[ -f "${LOG_DIR}"/firmware_entropy.png ]]; then
mv "${LOG_DIR}"/firmware_entropy.png "${LOG_PATH_MODULE}"/firmware1_entropy.png
write_link "${LOG_PATH_MODULE}"/firmware1_entropy.png
fi

Expand All @@ -64,10 +64,10 @@ D02_firmware_diffing_bin_details() {
print_fw_file_details "${FIRMWARE_PATH1}"
# generate_pixde "${FIRMWARE_PATH1}"
fw_bin_detector "${FIRMWARE_PATH1}"
if [[ -f "$LOG_DIR"/firmware_entropy.png ]]; then
mv "$LOG_DIR"/firmware_entropy.png "${LOG_PATH_MODULE}"/firmware2_entropy.png
if [[ -f "${LOG_DIR}"/firmware_entropy.png ]]; then
mv "${LOG_DIR}"/firmware_entropy.png "${LOG_PATH_MODULE}"/firmware2_entropy.png
write_link "${LOG_PATH_MODULE}"/firmware2_entropy.png
fi

module_end_log "${FUNCNAME[0]}" "$NEG_LOG"
module_end_log "${FUNCNAME[0]}" "${NEG_LOG}"
}
38 changes: 19 additions & 19 deletions modules/D05_firmware_diffing_extractor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,49 @@ D05_firmware_diffing_extractor() {
OUTPUT_DIR_UNBLOB1="${LOG_PATH_MODULE}"/extractor_"$(basename "${FIRMWARE_PATH}")"
unblobber "${FIRMWARE_PATH}" "${OUTPUT_DIR_UNBLOB1}" 0

if [[ -d "$OUTPUT_DIR_UNBLOB1" ]]; then
if [[ -d "${OUTPUT_DIR_UNBLOB1}" ]]; then
NEG_LOG=1
linux_basic_identification_unblobber "${OUTPUT_DIR_UNBLOB1}"
FILES_EXT_UB=$(find "$OUTPUT_DIR_UNBLOB1" -xdev -type f | wc -l )
UNIQUE_FILES_UB=$(find "$OUTPUT_DIR_UNBLOB1" -xdev -type f -exec md5sum {} \; 2>/dev/null | sort -u -k1,1 | cut -d\ -f3 | wc -l )
DIRS_EXT_UB=$(find "$OUTPUT_DIR_UNBLOB1" -xdev -type d | wc -l )
tree -Csh "$OUTPUT_DIR_UNBLOB1" > "${LOG_PATH_MODULE}"/firmware_image1.txt
FILES_EXT_UB=$(find "${OUTPUT_DIR_UNBLOB1}" -xdev -type f | wc -l )
UNIQUE_FILES_UB=$(find "${OUTPUT_DIR_UNBLOB1}" -xdev -type f -exec md5sum {} \; 2>/dev/null | sort -u -k1,1 | cut -d\ -f3 | wc -l )
DIRS_EXT_UB=$(find "${OUTPUT_DIR_UNBLOB1}" -xdev -type d | wc -l )
tree -Csh "${OUTPUT_DIR_UNBLOB1}" > "${LOG_PATH_MODULE}"/firmware_image1.txt

print_ln
print_output "[*] ${ORANGE}Unblob$NC results:"
print_output "[*] Found $ORANGE$FILES_EXT_UB$NC files ($ORANGE$UNIQUE_FILES_UB$NC unique files) and $ORANGE$DIRS_EXT_UB$NC directories at all."
print_output "[*] ${ORANGE}Unblob${NC} results:"
print_output "[*] Found ${ORANGE}${FILES_EXT_UB}${NC} files (${ORANGE}${UNIQUE_FILES_UB}${NC} unique files) and ${ORANGE}${DIRS_EXT_UB}${NC} directories at all."
if [[ -f "${LOG_PATH_MODULE}"/firmware_image1.txt ]]; then
write_link "${LOG_PATH_MODULE}"/firmware_image1.txt
fi
print_output "[*] Additionally the Linux path counter is $ORANGE$LINUX_PATH_COUNTER_UNBLOB$NC."
print_output "[*] Additionally the Linux path counter is ${ORANGE}${LINUX_PATH_COUNTER_UNBLOB}${NC}."
prepare_binary_arr "${OUTPUT_DIR_UNBLOB1}"
architecture_check
detect_root_dir_helper "$OUTPUT_DIR_UNBLOB1"
detect_root_dir_helper "${OUTPUT_DIR_UNBLOB1}"
print_ln
fi

sub_module_title "Firmware extraction - firmware image 2"
OUTPUT_DIR_UNBLOB2="${LOG_PATH_MODULE}"/extractor_"$(basename "${FIRMWARE_PATH1}")"
unblobber "${FIRMWARE_PATH1}" "${OUTPUT_DIR_UNBLOB2}" 0

if [[ -d "$OUTPUT_DIR_UNBLOB2" ]]; then
if [[ -d "${OUTPUT_DIR_UNBLOB2}" ]]; then
NEG_LOG=1
linux_basic_identification_unblobber "${OUTPUT_DIR_UNBLOB2}"
FILES_EXT_UB=$(find "$OUTPUT_DIR_UNBLOB2" -xdev -type f | wc -l )
UNIQUE_FILES_UB=$(find "$OUTPUT_DIR_UNBLOB2" -xdev -type f -exec md5sum {} \; 2>/dev/null | sort -u -k1,1 | cut -d\ -f3 | wc -l )
DIRS_EXT_UB=$(find "$OUTPUT_DIR_UNBLOB2" -xdev -type d | wc -l )
tree -Csh "$OUTPUT_DIR_UNBLOB2" > "${LOG_PATH_MODULE}"/firmware_image2.txt
FILES_EXT_UB=$(find "${OUTPUT_DIR_UNBLOB2}" -xdev -type f | wc -l )
UNIQUE_FILES_UB=$(find "${OUTPUT_DIR_UNBLOB2}" -xdev -type f -exec md5sum {} \; 2>/dev/null | sort -u -k1,1 | cut -d\ -f3 | wc -l )
DIRS_EXT_UB=$(find "${OUTPUT_DIR_UNBLOB2}" -xdev -type d | wc -l )
tree -Csh "${OUTPUT_DIR_UNBLOB2}" > "${LOG_PATH_MODULE}"/firmware_image2.txt

print_ln
print_output "[*] ${ORANGE}Unblob$NC results:"
print_output "[*] Found $ORANGE$FILES_EXT_UB$NC files ($ORANGE$UNIQUE_FILES_UB$NC unique files) and $ORANGE$DIRS_EXT_UB$NC directories at all."
print_output "[*] ${ORANGE}Unblob${NC} results:"
print_output "[*] Found ${ORANGE}${FILES_EXT_UB}${NC} files (${ORANGE}${UNIQUE_FILES_UB}${NC} unique files) and ${ORANGE}${DIRS_EXT_UB}${NC} directories at all."
if [[ -f "${LOG_PATH_MODULE}"/firmware_image2.txt ]]; then
write_link "${LOG_PATH_MODULE}"/firmware_image2.txt
fi
print_output "[*] Additionally the Linux path counter is $ORANGE$LINUX_PATH_COUNTER_UNBLOB$NC."
print_output "[*] Additionally the Linux path counter is ${ORANGE}${LINUX_PATH_COUNTER_UNBLOB}${NC}."
prepare_binary_arr "${OUTPUT_DIR_UNBLOB2}"
architecture_check
detect_root_dir_helper "$OUTPUT_DIR_UNBLOB2"
detect_root_dir_helper "${OUTPUT_DIR_UNBLOB2}"

# detect_root_dir_helper includes a link to a module that is usually not executed in diff mode
# let's remove this link now:
Expand All @@ -96,6 +96,6 @@ D05_firmware_diffing_extractor() {
print_ln
fi

module_end_log "${FUNCNAME[0]}" "$NEG_LOG"
module_end_log "${FUNCNAME[0]}" "${NEG_LOG}"
}

2 changes: 1 addition & 1 deletion modules/D10_firmware_diffing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ D10_firmware_diffing() {

check_for_new_files

module_end_log "${FUNCNAME[0]}" "$NEG_LOG"
module_end_log "${FUNCNAME[0]}" "${NEG_LOG}"
}

check_for_new_files() {
Expand Down
30 changes: 15 additions & 15 deletions modules/F10_license_summary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ F10_license_summary() {
local LICENSE=""
local TYPE=""

mapfile -t LICENSE_DETECTION_STATIC < <(grep -v "version_rule" "$CSV_DIR"/s09_*.csv 2>/dev/null | cut -d\; -f1,4,5 | sort -u || true)
mapfile -t LICENSE_DETECTION_DYN < <(grep -v "version_rule" "$CSV_DIR"/s116_*.csv 2>/dev/null | cut -d\; -f1,4,5 |sort -u || true)
mapfile -t LICENSE_DETECTION_STATIC < <(grep -v "version_rule" "${CSV_DIR}"/s09_*.csv 2>/dev/null | cut -d\; -f1,4,5 | sort -u || true)
mapfile -t LICENSE_DETECTION_DYN < <(grep -v "version_rule" "${CSV_DIR}"/s116_*.csv 2>/dev/null | cut -d\; -f1,4,5 |sort -u || true)
# TODO: Currently the final kernel details from s25 are missing

write_csv_log "binary/file" "version_rule" "version_detected" "csv_rule" "license" "static/emulation"
Expand All @@ -44,16 +44,16 @@ F10_license_summary() {
if [[ "${#LICENSE_DETECTION_STATIC[@]}" -gt 0 ]]; then
TYPE="static"
for ENTRY in "${LICENSE_DETECTION_STATIC[@]}"; do
if [[ -z "$ENTRY" ]]; then
if [[ -z "${ENTRY}" ]]; then
continue
fi

BINARY="$(safe_echo "$ENTRY" | cut -d\; -f1)"
VERSION="$(safe_echo "$ENTRY" | cut -d\; -f2 | cut -d: -f2-)"
LICENSE="$(safe_echo "$ENTRY" | cut -d\; -f3)"
BINARY="$(safe_echo "${ENTRY}" | cut -d\; -f1)"
VERSION="$(safe_echo "${ENTRY}" | cut -d\; -f2 | cut -d: -f2-)"
LICENSE="$(safe_echo "${ENTRY}" | cut -d\; -f3)"

print_output "[+] Binary: $ORANGE$(basename "$BINARY" | cut -d\ -f1)$GREEN / Version: $ORANGE$VERSION$GREEN / License: $ORANGE$LICENSE$NC"
write_csv_log "$BINARY" "$VERSION_RULE" "$VERSION" "$CSV_RULE" "$LICENSE" "$TYPE"
print_output "[+] Binary: ${ORANGE}$(basename "${BINARY}" | cut -d\ -f1)${GREEN} / Version: ${ORANGE}${VERSION}${GREEN} / License: ${ORANGE}${LICENSE}${NC}"
write_csv_log "${BINARY}" "${VERSION_RULE}" "${VERSION}" "${CSV_RULE}" "${LICENSE}" "${TYPE}"
((COUNT_LIC+=1))
done
fi
Expand All @@ -62,19 +62,19 @@ F10_license_summary() {
if [[ "${#LICENSE_DETECTION_DYN[@]}" -gt 0 ]]; then
TYPE="emulation"
for ENTRY in "${LICENSE_DETECTION_DYN[@]}"; do
if [[ -z "$ENTRY" ]]; then
if [[ -z "${ENTRY}" ]]; then
continue
fi

BINARY="$(safe_echo "$ENTRY" | cut -d\; -f1)"
VERSION="$(safe_echo "$ENTRY" | cut -d\; -f2 | cut -d: -f2-)"
LICENSE="$(safe_echo "$ENTRY" | cut -d\; -f3)"
BINARY="$(safe_echo "${ENTRY}" | cut -d\; -f1)"
VERSION="$(safe_echo "${ENTRY}" | cut -d\; -f2 | cut -d: -f2-)"
LICENSE="$(safe_echo "${ENTRY}" | cut -d\; -f3)"

print_output "[+] Binary: $ORANGE$(basename "$BINARY")$GREEN / Version: $ORANGE$VERSION$GREEN / License: $ORANGE$LICENSE$NC"
write_csv_log "$BINARY" "$VERSION_RULE" "$VERSION" "$CSV_RULE" "$LICENSE" "$TYPE"
print_output "[+] Binary: ${ORANGE}$(basename "${BINARY}")${GREEN} / Version: ${ORANGE}${VERSION}${GREEN} / License: ${ORANGE}${LICENSE}${NC}"
write_csv_log "${BINARY}" "${VERSION_RULE}" "${VERSION}" "${CSV_RULE}" "${LICENSE}" "${TYPE}"
((COUNT_LIC+=1))
done
fi

module_end_log "${FUNCNAME[0]}" "$COUNT_LIC"
module_end_log "${FUNCNAME[0]}" "${COUNT_LIC}"
}