Remote Command Execution in binwalk
The PFS extractor in binwalk joined archive entry names onto the output directory without fully resolving the resulting path, so a crafted PFS image with traversal sequences in filenames could write files outside the extraction directory. By writing a plugin into binwalk's plugin directory, an attacker could get arbitrary commands executed when the victim scans the malicious file with extract mode.
Published on onekey.com
Example H2
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 extractor checked the joined path with a string prefix test but never resolved '..' segments, so the safety check could never trigger.
Impact
An attacker could execute arbitrary code on the machine running binwalk, though the victim must open the malicious file in extract mode.
What the attacker needed
Victim runs binwalk -e on the file; attacker supplies a crafted PFS image
The fix
The fix resolves the joined path with os.path.abspath before the prefix check; the text says the vulnerability had not been patched at publication time.
How it was found
- Craft a valid PFS filesystem whose entry filenames contain traversal sequences.
- Have the victim run binwalk in extract mode on the crafted file.
- The extractor writes the entry outside the output directory, into binwalk's plugin directory.
- binwalk loads the dropped plugin during the same scan and executes it.
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 unpacks firmware images, and it trusts the file names stored inside those images. A file name containing '..' means 'go up one folder', so the tool could be tricked into saving a file somewhere it should not, such as a folder binwalk loads code from. That let the researcher run their own commands on the victim's machine when the victim unpacked the file.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.