sensepost / objection

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

[bug] A Frida agent exception has occurred cannot read property 'address' of undefined #361

Closed OsamaMahmood closed 4 years ago

OsamaMahmood commented 4 years ago

Describe the bug When i try to watch any method of a class i ran into this error after that i updated my Frida and objection framework to see if the issue gets resolved but still getting the same error.

WARNING: Ignoring this template and not completing the fields could result in your issue simply being closed.

To Reproduce Steps to reproduce the behavior:

  1. Run command 'ios hooking set return_value "-[FIRGetAccountInfoResponseUser emailVerified:]" true'

  2. ios hooking watch method "-[FIRSecureTokenRequest APIKey:]" --dump-args

Both Commands result into same error. Expected behavior A clear and concise description of what you expected to happen.

Evidence / Logs / Screenshots Any output from objection, such as stack traces or errors that occurred. Be sure to run objection with the --debug flag so that errors from the agent are verbose enough to debug. For example: Getting this error when trying to dump arguments of a method call

A Frida agent exception has occurred.
TypeError: cannot read property 'address' of undefined
at [anon] (../../../frida-gum/bindings/gumjs/duktape.c:56618)
at /script1.js:10272
at frida/runtime/message-dispatcher.js:15
at o (frida/runtime/message-dispatcher.js:25)

Python stack trace: Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/objection/console/repl.py", line 371, in start_repl
self.run_command(document)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/objection/console/repl.py", line 185, in run_command
exec_method(arguments)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/objection/commands/ios/hooking.py", line 234, in watch_class_method
api.ios_hooking_watch_method(selector,
File "/Users/osamamahmood/Library/Python/3.8/lib/python/site-packages/frida/core.py", line 401, in method
return script._rpc_request('call', js_name, args, **kwargs)
File "/Users/osamamahmood/Library/Python/3.8/lib/python/site-packages/frida/core.py", line 26, in wrapper
return f(*args, **kwargs)
File "/Users/osamamahmood/Library/Python/3.8/lib/python/site-packages/frida/core.py", line 333, in _rpc_request
raise result[2]
frida.core.RPCException: TypeError: cannot read property 'address' of undefined
at [anon] (../../../frida-gum/bindings/gumjs/duktape.c:56618)
at /script1.js:10272
at frida/runtime/message-dispatcher.js:15
at o (frida/runtime/message-dispatcher.js:25)

Environment (please complete the following information):

leonjza commented 4 years ago

Please run objection with the --debug flag and paste that stack trace.

OsamaMahmood commented 4 years ago
objection --debug explore                 
[debug] Agent path is: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/objection/agent.js
[debug] Injecting agent...
Using USB device `iPhone`
[debug] Attempting to attach to process: `Gadget`
[debug] Unable to find process: `Gadget`, attempting spawn
Unable to connect to the frida server: unable to launch iOS app: The operation couldn’t be completed. Application "Gadget" is unknown to FrontBoard.
Exception ignored in: <function Pool.__del__ at 0x105b85dc0>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/pool.py", line 268, in __del__
    self._change_notifier.put(None)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/queues.py", line 368, in put
    self._writer.send_bytes(obj)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/connection.py", line 200, in send_bytes
    self._send_bytes(m[offset:offset + size])
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/connection.py", line 411, in _send_bytes
    self._send(header + buf)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/connection.py", line 368, in _send
    n = write(self._handle, buf)
OSError: [Errno 9] Bad file descriptor
leonjza commented 4 years ago

And then run your commands after that please.

OsamaMahmood commented 4 years ago

When i run objection with --debug flag it closes after giving this stack trace.

OsamaMahmood commented 4 years ago

Even when I run objection version it gives this stack trace after printing out the version.

objection version                           
objection: 1.9.1
Exception ignored in: <function Pool.__del__ at 0x112b11dc0>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/pool.py", line 268, in __del__
    self._change_notifier.put(None)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/queues.py", line 368, in put
    self._writer.send_bytes(obj)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/connection.py", line 200, in send_bytes
    self._send_bytes(m[offset:offset + size])
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/connection.py", line 411, in _send_bytes
    self._send(header + buf)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/connection.py", line 368, in _send
    n = write(self._handle, buf)
OSError: [Errno 9] Bad file descriptor
leonjza commented 4 years ago

[debug] Unable to find process: Gadget, attempting spawn

The error says it cant find the gadget. Is the app running?

OsamaMahmood commented 4 years ago

here is the stack trace in debug mode:

app.app on (iPhone: 13.4) [usb] # ios hooking watch method "-[FIRSecureTokenRequest APIKey:]" --dump-args
A Frida agent exception has occurred.
TypeError: cannot read property 'address' of undefined
    at [anon] (../../../frida-gum/bindings/gumjs/duktape.c:56618)
    at src/ios/hooking.ts:54
    at frida/runtime/message-dispatcher.js:15
    at o (frida/runtime/message-dispatcher.js:25)

Python stack trace: Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/objection/console/repl.py", line 371, in start_repl
    self.run_command(document)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/objection/console/repl.py", line 185, in run_command
    exec_method(arguments)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/objection/commands/ios/hooking.py", line 234, in watch_class_method
    api.ios_hooking_watch_method(selector,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/frida/core.py", line 401, in method
    return script._rpc_request('call', js_name, args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/frida/core.py", line 26, in wrapper
    return f(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/frida/core.py", line 333, in _rpc_request
    raise result[2]
frida.core.RPCException: TypeError: cannot read property 'address' of undefined
    at [anon] (../../../frida-gum/bindings/gumjs/duktape.c:56618)
    at src/ios/hooking.ts:54
    at frida/runtime/message-dispatcher.js:15
    at o (frida/runtime/message-dispatcher.js:25)
OsamaMahmood commented 4 years ago

@leonjza any update on this?

leonjza commented 4 years ago

Just tested this, I can only replicate it when I try and watch a selector which the ApiResolver could not find. Are you sure you have the selector right there?

I am going to add better error reporting for this case shortly.

OsamaMahmood commented 4 years ago

Yes the selector is there, that will be great to better understand what is causing this error.

leonjza commented 4 years ago

It could be that you are trying to watch an instance method when in fact you are after a class method. Try swapping out the - for a +.

hax0rgb commented 4 years ago

Even I'm facing the same issue when running objection on Mac osx :/

leonjza commented 4 years ago

The command invokes this logic to find your method. Maybe write a small Frida script to replicate that for your target to help you debug the name?

MarshalX commented 4 years ago
Exception ignored in: <function Pool.__del__ at 0x7f51b61b11f0>
Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 268, in __del__
    self._change_notifier.put(None)
  File "/usr/lib/python3.8/multiprocessing/queues.py", line 368, in put
    self._writer.send_bytes(obj)
  File "/usr/lib/python3.8/multiprocessing/connection.py", line 200, in send_bytes
    self._send_bytes(m[offset:offset + size])
  File "/usr/lib/python3.8/multiprocessing/connection.py", line 411, in _send_bytes
    self._send(header + buf)
  File "/usr/lib/python3.8/multiprocessing/connection.py", line 368, in _send
    n = write(self._handle, buf)
OSError: [Errno 9] Bad file descriptor

After installing and executing the command "objection". It displays usage, arguments, but at the end an exception. Accordingly, with other cmds, too

pip3 ver pip 20.0.2 from /usr/lib/python3.8/site-packages/pip (python 3.8)

python ver Python 3.8.2

objection ver objection: 1.9.4

leonjza commented 4 years ago

@MarshalX that is unrelated to this ticket. I will reference a new issue for it as this is related to the update checker.

MarshalX commented 4 years ago

@MarshalX that is unrelated to this ticket. I will reference a new issue for it as this is related to the update checker.

the same exception https://github.com/sensepost/objection/issues/361#issuecomment-613439775 in this ticket

leonjza commented 4 years ago

the same exception #361 (comment) in this ticket

Which can be discussed in #381 now.