Firmware Analysis & Scripting

report GitHub

Overview

This was a group project for my Ethical Hacking course. My group of three was tasked with analyzing three embedded device firmwares and then creating a repeatable script to scan for our findings.

While all members contributed to the analysis & report, I focused more on the script and my teammates did more on the OSINT and analysis.

A high-level overview follows, see the report for more details.

The Brief

The manufactured ThanosTech LLC requested a static firmware security assessment of three firmware images used in their communication relay devices.

The engagement was scoped to offline static analysis and repeatable automation only, meaning no live exploitation or network testing was permitted. Our goal was to identify security risks in the firmware such as hard-coded credentials, outdated dependencies, and embedded secrets.

From these findings we were to produce a mitigation report, as well as a lightweight script written in bash or python for use in triage.

Script

Design

The script was written in bash with support for versions as low as 3.2.57 (the version shipped with macOS), to provide maximum portability.

Since this script is intended for triage use, it was designed in a modular fashion allowing for future expansions targeting new systems and vulnerabilities.

To achieve this goal, functionality was split into component files which each performed a specific analysis and reported their logs and findings. These components were executed by an orchestration script which determines the target type and acts accordingly.

Capabilities

Dependencies

ToolUsageDesc
filerecondetermine data formats and architectures, used to guide tool usage
binwalkextractorextract binaries and compressed data, setting up for further tools
readelfextractorinspect ELF metadata to guide tool usage and analysis
objdumpextractorproduce human and tool readable content from assembly objects
ripgrepscannerprimary scanning tool used to identify common secret patterns
stringsscannerextract human readable text for analysis, focusing on version information and tags

Findings

Hard-Coded Root Passwords

Affected: TP-Link, D-Link

Vulnerability A startup script writes clear-text credentials to /var/passwd & /etc/shadow. This allows anyone with the ability to read the firmware root access to the device during operation.

Mitigation on Avoid hard-coded passwords. Replace with randomized generation, secure provisioning, or public/private encryption.

Embedded Private Keys & Credentials

Affected: Bare-Metal ELF, D-Link

Vulnerability

Private Keys, AWS Credentials, and GitHub auth tokens stored insecurely in firmware. This provides an attacker access to services beyond the vulnerable device, allowing breach of or exfiltration from cloud services.

Mitigation

Store secrets in a secure hardware device (e.g. TPM). Provision unique device keys with scoped access and lifetimes instead of static credentials.

Outdated BusyBox

Affected: D-Link, TP-Link

Vulnerability An outdated BusyBox version with known and reported exploits in use on both devices.

Mitigations

Insecure Boot Chain

Affected: D-Link

Vulnerability: Outdated U-boot version with known vulnerabilities, allowing execution of unsigned code. Network boot protocol that potentially allows for remote execution of these exploits.

Mitigations Upgrade U-boot version, disable network boot protocols. Enforce firmware signatures.