sensepost / objection

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

Error on connecting to server running on emulator #53

Closed mabdi closed 6 years ago

mabdi commented 6 years ago

I have used following command to connect to the server running inside an emulator, but an error occurs:

$ adb forward tcp:27042 tcp:27042
$ objection -N explore
Error: unable to connect to remote frida-server: Error receiving data: An existing connection was forcibly closed by the remote host.

maybe useful:

$ objection  device_type
Traceback (most recent call last):
  File "c:\python3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python3\Scripts\objection.exe\__main__.py", line 9, in <module>
  File "c:\python3\lib\site-packages\click\core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "c:\python3\lib\site-packages\click\core.py", line 697, in main
    rv = self.invoke(ctx)
  File "c:\python3\lib\site-packages\click\core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\python3\lib\site-packages\click\core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\python3\lib\site-packages\click\core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "c:\python3\lib\site-packages\objection\console\cli.py", line 164, in device_type
    device_name, system_name, model, system_version = get_device_info()
  File "c:\python3\lib\site-packages\objection\commands\device.py", line 20, in get_device_info
    runner.run(hook=hook)
  File "c:\python3\lib\site-packages\objection\utils\frida_transport.py", line 346, in run
    session = self.get_session()
  File "c:\python3\lib\site-packages\objection\utils\frida_transport.py", line 281, in get_session
    return frida.get_usb_device(5).attach(state_connection.gadget_name)
  File "c:\python3\lib\site-packages\frida\core.py", line 97, in attach
    return Session(self._impl.attach(self._pid_of(target)))
  File "c:\python3\lib\site-packages\frida\core.py", line 115, in _pid_of
    return self.get_process(target).pid
  File "c:\python3\lib\site-packages\frida\core.py", line 67, in get_process
    matching = [process for process in self._impl.enumerate_processes() if fnmatch.fnmatchcase(process.name.lower(), process_name_lc)]
frida.ServerNotRunningError: unable to connect to remote frida-server: closed

and I'm using windows 7

leonjza commented 6 years ago

Does connecting using Frida tools work? For example using: frida-ps -Ria.

burrowingsec commented 6 years ago

Hi @leonjza,

I'm having the same issue here. I can see the original poster didn't reply to your question but in my case I'm not able to connect with the Frida tools nor objection. It looks like the Frida Gadget is either not starting or not opening the socket properly. I ran netstat to check this and didn't see the open port.

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
udp        0      0 :::5353                 :::*
udp        0      0 :::5353                 :::*
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State           I-Node Path
unix  2      [ ACC ]     STREAM     LISTENING         4107 /dev/socket/logd
unix  2      [ ACC ]     SEQPACKET  LISTENING         4112 /dev/socket/logdr
unix  2      [ ACC ]     STREAM     LISTENING         4124 /dev/socket/vold
unix  2      [ ACC ]     STREAM     LISTENING         4129 /dev/socket/cryptd
unix  2      [ ACC ]     STREAM     LISTENING         5526 @jdwp-control
unix  2      [ ACC ]     SEQPACKET  LISTENING         4143 /dev/socket/lmkd
unix  2      [ ACC ]     STREAM     LISTENING         5163 /dev/socket/property_service
unix  2      [ ACC ]     STREAM     LISTENING         6233 /dev/socket/installd
unix  2      [ ACC ]     STREAM     LISTENING         4185 /dev/socket/adbd
unix  2      [ ACC ]     STREAM     LISTENING         6244 /dev/socket/netd
unix  2      [ ACC ]     STREAM     LISTENING         6249 /dev/socket/dnsproxyd
unix  2      [ ACC ]     STREAM     LISTENING         6252 /dev/socket/mdns
unix  2      [ ACC ]     STREAM     LISTENING         6255 /dev/socket/fwmarkd
unix  2      [ ACC ]     STREAM     LISTENING         6268 /dev/socket/rild
unix  2      [ ACC ]     STREAM     LISTENING         6276 /dev/socket/rild-debug
unix  2      [ ACC ]     STREAM     LISTENING         3273 @android:debuggerd
unix  2      [ ACC ]     STREAM     LISTENING         4264 /dev/socket/zygote
unix  2      [ ACC ]     STREAM     LISTENING         9252 /data/system/ndebugsocket

I also tried to connect to the port directly through netcat and just got "Connection Refused" errors.

I suppose the issue with troubleshooting this is whether this is an issue with Objection or an issue with the Frida Gadget. Any help you could provide would be great though.

burrowingsec commented 6 years ago

So there's an issue with the latest releases of the Frida Gadget and not with Objection itself. I have gone and manually patched my APKs with the Frida Gadget 10.6.32 release. I've not worked out the latest working version, but if you're stuck then I recommend using this version and manually patching your binaries.

leonjza commented 6 years ago

Thanks for the updates @burrowingsec ! I am going to add a --version flag to the patcher soon to help with this. Could you tell me if adb logcat has anything of interest with the latest gadgets?

leonjza commented 6 years ago

I have added the --gadget-version flag to the patchers in objection v1.2.4. Could you try an older gadget like 10.6.20 and see if that works?

Thanks!

leonjza commented 6 years ago

After some testing, it seems like the 10.6.33 gadget is the last one that is working as expected. Will debug this further.

burrowingsec commented 6 years ago

I've been doing some other work today so haven't had a chance to grab the logcat output. Do you still need it or did you grab your own output during testing?

Also, thanks for the quick push of the --gadget-version flag. I've had success with that whilst patching an IPA. objection is a brilliant tool.

leonjza commented 6 years ago

I grabbed quite a bit during testing and have concluded that 10.6.33 is the latest version that still works as expected for Android. I have poked @oleavr on Telegram for some ideas and will debug this further.

Thanks.

leonjza commented 6 years ago

The latest gadgets have been fixed since https://github.com/frida/frida-core/commit/b46081304f904773882f6efac4507c627a38fcdb (tagged in Frida 10.6.55) and should work as expected again.