sensepost / objection

📱 objection - runtime mobile exploration
GNU General Public License v3.0
7.54k stars 855 forks source link

Exception due to agent.js missing #240

Closed dkasak closed 5 years ago

dkasak commented 5 years ago

I installed objection into a virtualenv using pip as described in the wiki. However, upon running objection -g SOME_APP explore, the following exception is thrown:

Using USB device `Samsung GT-I9300`
Traceback (most recent call last):
  File "/home/dkasak/code/projects/objection/venv/bin/objection", line 10, in <module>
    sys.exit(cli())
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/objection/console/cli.py", line 114, in explore
    agent.inject()
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/objection/utils/agent.py", line 196, in inject
    self.script = session.create_script(source=self._get_agent_source())
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/objection/utils/agent.py", line 175, in _get_agent_source
    'information on building the agent.'.format(location=self.agent_path))
Exception: Unable to locate Objection agent sources at: /home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/objection/agent.js. If this is a development install, check the wiki for more information on building the agent.

The same command also sometimes throws the following (it seems non-deterministic which exception will be thrown):

Using USB device `Samsung GT-I9300`
Traceback (most recent call last):
  File "/home/dkasak/code/projects/objection/venv/bin/objection", line 10, in <module>
    sys.exit(cli())
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/objection/console/cli.py", line 114, in explore
    agent.inject()
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/objection/utils/agent.py", line 195, in inject
    session = self.get_session()
  File "/home/dkasak/code/projects/objection/venv/lib/python3.7/site-packages/objection/utils/agent.py", line 145, in get_session
    self.session = self.device.attach(state_connection.gadget_name)
TypeError: an integer is required (got type str)

Environment (please complete the following information):

Additional context From a cursory look, it seems that the npm module frida-compile might be required to generate agent.js and since I don't have it, the file never gets produced. Is this a likely explanation? I haven't seen it mentioned in the documentation, though.

dkasak commented 5 years ago

Update: I tried installing frida-compile manually using npm and this makes it work.

leonjza commented 5 years ago

Thanks for the report! It appears as though I have a packaging problem, and am super confused how this is only picked up now.

$ tar tvf <(curl -sL https://github.com/sensepost/objection/archive/1.6.4.tar.gz) '*agent.js'
tar: *agent.js: Not found in archive
tar: Error exit delayed from previous errors.

Debugging this now!

leonjza commented 5 years ago

Actually, I am confused. I spun up a new virtual environment and ran pip3 install objection, and seem to have it:

venv3-temp/lib/python3.7/site-packages/objection » ls agent.js
agent.js

I also just realised you mention that you are running from master. In this case, you need to build the agent yourself. Some instructions are here: https://github.com/sensepost/objection/wiki/Agent-Development-Environment

dkasak commented 5 years ago

Oh, I missed that page, sorry (or rather failed to recognize it as relevant). I guess I expected that running pip3 install . from the git repository would be equivalent to running pip3 install objection, except for the commit used.

I tried following the instructions on the page you linked and it indeed works, so I guess there's nothing to be done here, except perhaps adding a paragraph to the installation page? Something along the lines of

These instructions are for installing released versions of objection. To install objection from its git repository, you additionally need to build the objection agent yourself. For instructions on how to do this, see the Agent Development Environment page.

leonjza commented 5 years ago

No problem. Yeah, I think I need to create a dedicated "development install" guide to help link the pieces together here.

aph3rson commented 5 years ago

@leonjza instead of the manual build process for (re)building the agent, would it be possible to do a check when Objection launches if an agent rebuild is needed, and rebuild automatically?

This could be augmented with some command-line options, such as --build-agent/--no-build-agent, to prevent automatic processing if need be.

leonjza commented 5 years ago

I am not sure. That would mean we need to build code for and maintain another external env for node, npm and all that; something I feel does not warrant the effort.

A missing agent should really only be a problem when you are busy developing and should never happen in standard pip installs from pypi. I am writing the development installation wiki doc as we speak though.

leonjza commented 5 years ago

Remember, when developing the agent, running the npm run watch command gives you live recompilation as well, so your agent updates automatically as your code progresses. This is already works pretty nicely in the node world imo :)

leonjza commented 5 years ago

Added Development Environment Installation.