redballoonsecurity / ofrak

OFRAK: unpack, modify, and repack binaries.
https://ofrak.com
Other
1.82k stars 128 forks source link

crashes when checking for missing dependencies #430

Open hikir1 opened 4 months ago

hikir1 commented 4 months ago

Ofrak crashes when invoked with -x and apktool is missing. It's method for checking for the existence of apktool involves calling it, which fails and leads to the error:

PermissionError: [Errno 13] Permission denied: 'apktool'

Solution: check if apktool is in PATH

To reproduce, run ofrak gui -x without apktool installed.

Stack trace:

  File "/home/hikir1/.local/bin/ofrak", line 33, in <module>
    sys.exit(load_entry_point('ofrak', 'console_scripts', 'ofrak')())
  File "/home/hikir1/ofrak/ofrak_core/ofrak/__main__.py", line 15, in main
    ofrak_cli.parse_and_run(sys.argv[1:])
  File "/home/hikir1/ofrak/ofrak_core/ofrak/cli/ofrak_cli.py", line 221, in parse_and_run
    parsed.run(parsed)
  File "/home/hikir1/ofrak/ofrak_core/ofrak/cli/ofrak_cli.py", line 182, in run
    ofrak.run(self.ofrak_func, args)
  File "/home/hikir1/ofrak/ofrak_core/ofrak/ofrak_context.py", line 197, in run
    asyncio.get_event_loop().run_until_complete(self.run_async(func, *args))
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/hikir1/ofrak/ofrak_core/ofrak/ofrak_context.py", line 187, in run_async
    ofrak_context = await self.create_ofrak_context()
  File "/home/hikir1/ofrak/ofrak_core/ofrak/ofrak_context.py", line 163, in create_ofrak_context
    components = await self._get_discovered_components()
  File "/home/hikir1/ofrak/ofrak_core/ofrak/ofrak_context.py", line 221, in _get_discovered_components
    await asyncio.gather(
  File "/home/hikir1/ofrak/ofrak_core/ofrak/model/component_model.py", line 61, in is_tool_installed
    proc = await asyncio.create_subprocess_exec(
  File "/usr/lib/python3.9/asyncio/subprocess.py", line 236, in create_subprocess_exec
    transport, protocol = await loop.subprocess_exec(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 1661, in subprocess_exec
    transport = await self._make_subprocess_transport(
  File "/usr/lib/python3.9/asyncio/unix_events.py", line 197, in _make_subprocess_transport
    transp = _UnixSubprocessTransport(self, protocol, args, shell,
  File "/usr/lib/python3.9/asyncio/base_subprocess.py", line 36, in __init__
    self._start(args=args, shell=shell, stdin=stdin, stdout=stdout,
  File "/usr/lib/python3.9/asyncio/unix_events.py", line 789, in _start
    self._proc = subprocess.Popen(
  File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
whyitfor commented 4 months ago

The error message you post -- PermissionError: [Errno 13] Permission denied: 'apktool' -- seems to indicate a permission error when running apktool, and not a problem with the command not existing.

Is it possible that what was encountered here was a permission error?

I just tried recreating with the python:3.7 docker image and am unable to -- it skips ApkUnpacker fine:

$ docker run -it python:3.7 bash
...
root@7217bfa0e56f:/# pip install ofrak
...
root@7217bfa0e56f:/# ofrak gui -x
[   ofrak_cli.py:  173] No disassembler backend specified, so no disassembly will be possible
[ofrak_context.py:  221] Skipped registering the following components due to missing dependencies: ApkPacker, ApkUnpacker, BinwalkAnalyzer, CpioPacker, CpioUnpacker, GzipPacker, GzipUnpacker, IhexAnalyzer, IhexPacker, IhexUnpacker, Jffs2Packer, Jffs2Unpacker, LzoPacker, LzoUnpacker, RarUnpacker, SevenZUnpacker, SevenzPacker, SquashfsPacker, SquashfsUnpacker, UbiAnalyzer, UbiIdentifier, UbiPacker, UbiUnpacker, UbifsAnalyzer, UbifsIdentifier, UbifsPacker, UbifsUnpacker, ZipPacker, ZstdPacker, ZstdUnpacker. Run `python3 -m ofrak deps --missing-only` for more details.
GUI is being served on http://127.0.0.1:8080/
hikir1 commented 4 months ago

It looks like their was a directory owned by another user on my PATH that I don't have access to. Perhaps ofrak could catch permission errors when searching for dependencies and output a warning?

whyitfor commented 2 months ago

@hikir1, is this issue addressed with #432 and #433? Is there any remaining work?

hikir1 commented 1 month ago

The test isn't working for some reason and I haven't had much time to figure out why.