redballoonsecurity / ofrak

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

Minor: `/tmp/ofrak.log` probably shouldn't be hardcoded #311

Open ANogin opened 1 year ago

ANogin commented 1 year ago

What is the problem? (Here is where you provide a complete Traceback.)

We probably should not assume we can have exclusive use of /tmp/ofrak.log. It may be somewhat safe in a controlled docker environment where there is likely at most one instance of OFRAK running at a time, but not with pip install, or whatever weird things people might choose to do, resulting in:

    ofrak = OFRAK()
  File "/ofrak_core/ofrak/ofrak_context.py", line 125, in __init__
    logging.getLogger().addHandler(logging.FileHandler(DEFAULT_OFRAK_LOG_FILE))
  File "/usr/local/lib/python3.7/logging/__init__.py", line 1087, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/local/lib/python3.7/logging/__init__.py", line 1116, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: '/tmp/ofrak.log'

Please provide some information about your environment. At minimum we would like the following information on your platform and Python environment:

If you've discovered it, what is the root cause of the problem? DEFAULT_OFRAK_LOG_FILE = os.path.join(tempfile.gettempdir(), "ofrak.log") in ofrak_core/ofrak/ofrak_context.py seems to be hardcoded (as far as I can tell, the DEFAULT_ part is misleading).

How often does the issue happen?

What are the steps to reproduce the issue?

How would you implement this fix?

Are there any (reasonable) alternative approaches?

Are you interested in implementing it yourself?

whyitfor commented 1 year ago

Interesting. I've never run into this issue. What steps did you take to create this situation where you did not have permission for /tmp/ofrak.log?

ANogin commented 1 year ago

Interesting. I've never run into this issue. What steps did you take to create this situation where you did not have permission for /tmp/ofrak.log?

Invoked the default docker setup of having ofrak run the ghidra server as root, then tried docker exec -u aleksey ofrak-ghidra bash -l as I did not want the wrong ownership on the files mounted from host, and ran ofrak there.

But I would imagine multiple users running pip installed ofrak on a shared server would result in the same issue.

whyitfor commented 1 year ago

If seems like we might want to: