Closed gskip17 closed 1 year ago
Ok, so the problem is that during unpacking, when there is a file with an absolute path, the OS will (correctly) realize it should not try and overwrite that specific file (eg /dev/console
), and throw an error to stderr for that specific file.
If you prevent the script from checking the return code, it will successfully run cpio -id
to completion.
(ofrak/core/cpio.py 103-104)
if proc.returncode:
raise CalledProcessError(returncode=proc.returncode, cmd=cmd)
The issue remains that we would still want to unpack the /dev/console
file and other absolutes. Therefore the proper fix is to probably just use the 7z
utility to unpack cpio filesystems.
I will experiment with this to determine what, if any, limitations arise when doing it this way.
Made a pull request for a possible solution to use 7z
instead of cpio
in the CpioUnpacker
.
https://github.com/redballoonsecurity/ofrak/pull/276
If there is a better way to do this (eg, use the existing SevenZip
component), ill leave that to reviewers.
The fix should be simple enough.
Addressed by #276.
Seems like this patch was reverted with #290 . I'm running into this issue now on pretty much the same setup as the original post but on the latest version (3.2.0.post0).
What is the problem? (Here is where you provide a complete Traceback.)
OFRAK relies on the
cpio
utility to unpack CPIO filesystems. The utility is called with-id
flags. When unpacking the filesystem, if there are any absolute filepaths, the utility will crash because it should (rightly) not try and overwrite a user's system files.Please provide some information about your environment. At minimum we would like the following information on your platform and Python environment:
python3 -m pip freeze
. pypi, local,ofrak==2.2.1.post1
If you've discovered it, what is the root cause of the problem?
See above.
How often does the issue happen?
Every time a CPIO filesystem unpacks, on Linux.
What are the steps to reproduce the issue?
Unpack a CPIO filesystem on a Linux distro. It will work in the ofrak docker container (supposedly?).
Ideally, give us a short script that reproduces the issue.
Open a DTB or something similar containing a CPIO filesystem, and unpack it recursively.
await resource.unpack_recursively()
Here is one you can try out. image.zip
How would you implement this fix?
A possible solution is to include the
--no-absolute-filenames
flag, however this will mean you will potentially lose files during repacking.A better solution is to probably just use the
7z
utility to unpack the filesystem. This is what theunblob
project appears to do and I tested it on my machine and it seems like a decent solution. Using7z
is also a bit safer in this scenario.Are there any (reasonable) alternative approaches?
Are you interested in implementing it yourself?
Yes. Working on a fix.