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

F19 and S115 updates, cleanups, certificate details #112

Merged
merged 12 commits into from
May 27, 2021
23 changes: 16 additions & 7 deletions emba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ main()
# afterwards do a default emba scan
export PYTHON_CHECK=1
export QEMULATION=0
# to get rid of all the running stuff we are going to kill it after RUNTIME
export QRUNTIME="20s"

export SHELLCHECK=1
export SHORT_PATH=0 # short paths in cli output
export THREADED=0 # 0 -> single thread
Expand Down Expand Up @@ -435,8 +438,8 @@ main()
if [[ $D_RETURN -eq 0 ]] ; then
if [[ $ONLY_DEP -eq 0 ]] ; then
print_output "[*] Emba finished analysis in docker container.\\n" "no_log"
print_output "[*] Firmware tested: $ORANGE$FIRMWARE_PATH" "no_log"
print_output "[*] Log directory: $ORANGE$LOG_DIR" "no_log"
print_output "[*] Firmware tested: $ORANGE$FIRMWARE_PATH$NC" "no_log"
print_output "[*] Log directory: $ORANGE$LOG_DIR$NC" "no_log"
exit
fi
else
Expand Down Expand Up @@ -500,6 +503,10 @@ main()

print_output "\n=================================================================\n" "no_log"

check_firmware
prepare_binary_arr
prepare_file_arr

if [[ $KERNEL -eq 0 ]] ; then
architecture_check
architecture_dep_check
Expand All @@ -516,9 +523,9 @@ main()
detect_root_dir_helper "$FIRMWARE_PATH" "main"
fi

check_firmware
prepare_binary_arr
prepare_file_arr
#check_firmware
#prepare_binary_arr
#prepare_file_arr
set_etc_paths
echo

Expand Down Expand Up @@ -559,11 +566,13 @@ main()

run_modules "F" "0" "$HTML"

update_index
if [[ "$HTML" -eq 1 ]]; then
update_index
fi

if [[ "$TESTING_DONE" -eq 1 ]]; then
if [[ -f "$HTML_PATH"/index.html ]]; then
print_output "[*] Web report created HTML report in ""$LOG_DIR""html-report\\n" "main"
print_output "[*] Web report created HTML report in $LOG_DIR/html-report\\n" "main"
fi
echo
if [[ -d "$LOG_DIR" ]]; then
Expand Down
9 changes: 9 additions & 0 deletions helpers/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ wait_for_pid() {
while [[ -e /proc/"$PID" ]]; do
#print_output "[*] wait pid protection - running pid: $PID"
echo "." | tr -d "\n"
# if S115 is running we have to kill old qemu processes
if [[ $(grep -c S115_ "$LOG_DIR"/"$MAIN_LOG_FILE") -eq 1 && -n "$QRUNTIME" ]]; then
killall -9 --quiet --older-than "$QRUNTIME" -r .*qemu.*sta.*
fi
done
done
}
Expand All @@ -61,6 +65,11 @@ max_pids_protection() {
TEMP_PIDS+=( "$PID" )
fi
done
# if S115 is running we have to kill old qemu processes
if [[ $(grep -c S115_ "$LOG_DIR"/"$MAIN_LOG_FILE") -eq 1 && -n "$QRUNTIME" ]]; then
killall -9 --quiet --older-than "$QRUNTIME" -r .*qemu.*sta.*
fi

#print_output "[!] really running pids: ${#TEMP_PIDS[@]}"

# recreate the arry with the current running PIDS
Expand Down
15 changes: 10 additions & 5 deletions helpers/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,25 @@ architecture_check()
{
if [[ $ARCH_CHECK -eq 1 ]] ; then
print_output "[*] Architecture auto detection (could take some time)\\n" "no_log"
local DETECT_ARCH ARCH_MIPS=0 ARCH_ARM=0 ARCH_X64=0 ARCH_X86=0 ARCH_PPC=0
# do not use -executable here. Not all firmware updates have exec permissions set
IFS=" " read -r -a DETECT_ARCH < <( find "$FIRMWARE_PATH" "${EXCL_FIND[@]}" -type f -xdev -exec file {} \; 2>/dev/null | grep ELF | tr '\r\n' ' ' | tr -d '\n' 2>/dev/null)
for D_ARCH in "${DETECT_ARCH[@]}" ; do
local ARCH_MIPS=0 ARCH_ARM=0 ARCH_X64=0 ARCH_X86=0 ARCH_PPC=0
# we use the binaries array which is already unique
for D_ARCH in "${BINARIES[@]}" ; do
D_ARCH=$(file "$D_ARCH")
if [[ "$D_ARCH" == *"MIPS"* ]] ; then
ARCH_MIPS=$((ARCH_MIPS+1))
continue
elif [[ "$D_ARCH" == *"ARM"* ]] ; then
ARCH_ARM=$((ARCH_ARM+1))
continue
elif [[ "$D_ARCH" == *"x86-64"* ]] ; then
ARCH_X64=$((ARCH_X64+1))
continue
elif [[ "$D_ARCH" == *"80386"* ]] ; then
ARCH_X86=$((ARCH_X86+1))
continue
elif [[ "$D_ARCH" == *"PowerPC"* ]] ; then
ARCH_PPC=$((ARCH_PPC+1))
continue
fi
done

Expand All @@ -134,7 +139,7 @@ architecture_check()
elif [[ $ARCH_PPC -gt $ARCH_MIPS ]] && [[ $ARCH_PPC -gt $ARCH_ARM ]] && [[ $ARCH_PPC -gt $ARCH_X64 ]] && [[ $ARCH_PPC -gt $ARCH_X86 ]] ; then
D_ARCH="PPC"
fi
echo
print_output ""
print_output "$(indent "Detected architecture of the firmware: ""$ORANGE""$D_ARCH""$NC")""\\n" "no_log"
if [[ -n "$ARCH" ]] ; then
if [[ "$ARCH" != "$D_ARCH" ]] ; then
Expand Down
Loading