ReFirmLabs / binwalk

Firmware Analysis Tool
MIT License
10.75k stars 1.54k forks source link

files are extracted in the wrong directory #635

Closed viavi-ab closed 1 week ago

viavi-ab commented 1 year ago

According to the documentation, binwalk defaults to extracting files in the current directory.

This is not always the case, however, and I think this is a regression; I was previously using version 2.1.1 (from ubuntu 18) and it behaved correctly. version 2.2.0 (shipped with ubuntu 20) and later seem to behave incorrectly.

Consider the following script:

#! /bin/sh

mkdir cd
cp /boot/vmlinuz cd/
mkisofs -o cd.iso cd
rm -rf cd

mkdir /a
mkdir /a/iso
mount -o ro,loop cd.iso /a/iso
cd /a
binwalk -e /a/iso/vmlinuz --run-as=root

When binwalk runs, the current directory is /a; however binwalk will attempt to extract files into /a/iso, causing this exception:

  File "/usr/local/lib/python3.8/dist-packages/binwalk-2.3.3-py3.8.egg/binwalk/modules/extractor.py", line 571, in build_output_directory
    os.mkdir(output_directory)
OSError: [Errno 30] Read-only file system: '/a/iso/_vmlinuz.extracted'

None of these work either:

binwalk -e iso/vmlinuz --run-as=root
binwalk -e /a/iso/vmlinuz --run-as=root -C .
binwalk -e /a/iso/vmlinuz --run-as=root -C /a