Skip to content
Path traversal Write-up Intermediate

Security Advisory: Remote Command Execution in binwalk

A path traversal vulnerability in binwalk's PFS extractor allowed writing files outside the extraction directory. An attacker could craft a malicious PFS file that, when extracted, writes a plugin to binwalk's plugin directory, leading to arbitrary code execution.

onekey.com

Published on onekey.com

Example H2

The author, on onekey.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code used os.path.join to build a path and then checked if it started with the output directory, but os.path.join does not resolve '..' sequences, so the check never triggered.

Impact

An attacker could execute arbitrary code on the victim's machine, but the victim must open a malicious file with binwalk in extract mode.

What the attacker needed

Victim runs binwalk with -e on malicious file

The fix

The fix adds a call to os.path.abspath to fully resolve the path before the check, but at the time of publication the vulnerability had not been patched in the official repository.

How it was found

  1. Craft a valid PFS filesystem with filenames containing '../' sequences.
  2. Run binwalk with extract mode (-e) on the malicious file.
  3. The path traversal writes a malicious plugin to binwalk's plugin directory.
  4. Binwalk loads and executes the plugin during the scan.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Binwalk is a tool that extracts files from firmware images. A path traversal bug lets a malicious file trick the tool into writing files to unintended locations, like your home directory. The attacker can then place a plugin that binwalk automatically runs, giving them control of your computer.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.