Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[!] Exception: An error occurred and it was not possible to restore it (3 attempts failed) and [!] [Errno 54] Connection reset by peer #265

Closed
humanUnit opened this issue Oct 10, 2018 · 6 comments
Labels

Comments

@humanUnit
Copy link

humanUnit commented Oct 10, 2018

Issue

Hi Marco, could you please help me? This issue happens when I connect to needle, I restart my workstation and then connect. All use actions don't run, I always catch same issue. Needle Agent is running.

Steps to reproduce

  1. Start needle > sudo python needle.py
  2. Enter password.

needle error logs

[needle] > set AGENT_PORT 4444
AGENT_PORT => 4444
[needle] > set DEBUG True
DEBUG => True
[needle] > set HIDE_SYSTEM_APPS False
HIDE_SYSTEM_APPS => False
[needle] > set IP 127.0.0.1
IP => 127.0.0.1
[needle] > set PORT 2222
PORT => 2222
[needle] > set OUTPUT_FOLDER /Users/mehadhe_sameer/needle/needle/output
OUTPUT_FOLDER => /Users/mehadhe_sameer/needle/needle/output
[D] Output folder changed, reloading modules
[needle] > set PASSWORD 
PASSWORD => ********
[needle] > set SKIP_OUTPUT_FOLDER_CHECK True
SKIP_OUTPUT_FOLDER_CHECK => True
[needle] > set USERNAME root
USERNAME => root
[needle] > set VERBOSE True
VERBOSE => True
[needle][pasteboard] > use storage/caching/screenshot
[+] Resource file successfully loaded
[needle][screenshot] > run
[*] Checking connection with device...
[+] Already connected to: 127.0.0.1
[D] Creating temp folder: /var/root/needle/
[D] [REMOTE CMD] Remote Command: if [ -d /var/root/needle/ ]; then echo "yes"; else echo "no" ; fi
[+] Target app: com.apple.AppStore
[*] Retrieving app's metadata...
[D] Copying the plist to temp: /Applications/AppStore.app/Info.plist -> /Users/ekaterinak/.needle/tmp/plist
[*] Pulling: /Applications/AppStore.app/Info.plist -> /Users/ekaterinak/.needle/tmp/plist
[D] Downloading: "/Applications/AppStore.app/Info.plist" -> /Users/ekaterinak/.needle/tmp/plist
[D] [LOCAL CMD] Local Command: sshpass -p "MadApp12345" scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P 2222 root@127.0.0.1:"/Applications/AppStore.app/Info.plist" /Users/ekaterinak/.needle/tmp/plist
[D] [REMOTE CMD] Remote Command: lipo -info /Applications/AppStore.app/AppStore
[!] sh: lipo: command not found

[V] [SSH] Disconnecting...
[V] [AGENT] Disconnecting from agent...
[D] Stopping USB port forwarding
[D] [LOCAL CMD] Stopping Local Subprocess Command [pid: 3010]
[D] [AGENT] Stopping port forwarding
[?] Resetting connection to device...
[D] Setting up USB port forwarding on port 2222
[D] [LOCAL CMD] Local Subprocess Command: /Users/ekaterinak/needle/needle/libs/usbmuxd/tcprelay.py -t 22:2222
[D] [AGENT] Setting up port forwarding on port 4444
[V] [AGENT] Connecting to agent (127.0.0.1:4444)...
[+] [AGENT] Successfully connected to agent (127.0.0.1:4444)...
[D] [AGENT] Executing command: os_version
2018-10-10 16:48:05,700| ERROR   | Secsh channel 0 open FAILED: Connection refused: Connect failed
2018-10-10 16:48:05,705| ERROR   | Could not establish connection from ('127.0.0.1', 4444) to remote side of the tunnel
[!] [Errno 54] Connection reset by peer
[V] [SSH] Disconnecting...
[V] [AGENT] Disconnecting from agent...
[D] Stopping USB port forwarding
[D] [LOCAL CMD] Stopping Local Subprocess Command [pid: 3015]
[D] [AGENT] Stopping port forwarding
[?] Resetting connection to device...
[D] Setting up USB port forwarding on port 2222
[D] [LOCAL CMD] Local Subprocess Command: /Users/ekaterinak/needle/needle/libs/usbmuxd/tcprelay.py -t 22:2222
[D] [AGENT] Setting up port forwarding on port 4444
[V] [AGENT] Connecting to agent (127.0.0.1:4444)...
[+] [AGENT] Successfully connected to agent (127.0.0.1:4444)...
[D] [AGENT] Executing command: os_version
2018-10-10 16:48:07,949| ERROR   | Secsh channel 0 open FAILED: Connection refused: Connect failed
2018-10-10 16:48:07,949| ERROR   | Could not establish connection from ('127.0.0.1', 4444) to remote side of the tunnel
[!] [Errno 54] Connection reset by peer
[V] [SSH] Disconnecting...
[V] [AGENT] Disconnecting from agent...
[D] Stopping USB port forwarding
[D] [LOCAL CMD] Stopping Local Subprocess Command [pid: 3016]
[D] [AGENT] Stopping port forwarding
[?] Resetting connection to device...
[D] Setting up USB port forwarding on port 2222
[D] [LOCAL CMD] Local Subprocess Command: /Users/ekaterinak/needle/needle/libs/usbmuxd/tcprelay.py -t 22:2222
[D] [AGENT] Setting up port forwarding on port 4444
[V] [AGENT] Connecting to agent (127.0.0.1:4444)...
[+] [AGENT] Successfully connected to agent (127.0.0.1:4444)...
[D] [AGENT] Executing command: os_version
2018-10-10 16:48:10,202| ERROR   | Secsh channel 0 open FAILED: Connection refused: Connect failed
2018-10-10 16:48:10,207| ERROR   | Could not establish connection from ('127.0.0.1', 4444) to remote side of the tunnel
[!] [Errno 54] Connection reset by peer
[V] [SSH] Disconnecting...
[V] [AGENT] Disconnecting from agent...
[D] Stopping USB port forwarding
[D] [LOCAL CMD] Stopping Local Subprocess Command [pid: 3017]
[D] [AGENT] Stopping port forwarding
[?] Resetting connection to device...
[D] Setting up USB port forwarding on port 2222
[D] [LOCAL CMD] Local Subprocess Command: /Users/ekaterinak/needle/needle/libs/usbmuxd/tcprelay.py -t 22:2222
[D] [AGENT] Setting up port forwarding on port 4444
[V] [AGENT] Connecting to agent (127.0.0.1:4444)...
[+] [AGENT] Successfully connected to agent (127.0.0.1:4444)...
------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/ekaterinak/needle/needle/core/framework/module.py", line 111, in do_run
    pre = self.module_pre()
  File "/Users/ekaterinak/needle/needle/core/framework/module.py", line 147, in module_pre
    if self.app_check() is None: return None
  File "/Users/ekaterinak/needle/needle/core/framework/framework.py", line 693, in app_check
    self.APP_METADATA = Framework.APP_METADATA = self.device.app.get_metadata(app)
  File "/Users/ekaterinak/needle/needle/core/device/app.py", line 17, in get_metadata
    return self._retrieve_metadata()
  File "/Users/ekaterinak/needle/needle/core/device/app.py", line 35, in _retrieve_metadata
    architectures = self.__detect_architectures(binary_path)
  File "/Users/ekaterinak/needle/needle/core/device/app.py", line 117, in __detect_architectures
    out = self._device.remote_op.command_blocking(cmd, internal=True)
  File "/Users/ekaterinak/needle/needle/core/device/remote_operations.py", line 94, in command_blocking
    out, err = self._device._exec_command_ssh(cmd, internal)
  File "/Users/ekaterinak/needle/needle/core/utils/utils.py", line 207, in wrapper
    device.connect()
  File "/Users/ekaterinak/needle/needle/core/device/device.py", line 218, in connect
    self._connect_agent()
  File "/Users/ekaterinak/needle/needle/core/device/device.py", line 160, in _connect_agent
    self.agent.exec_command_agent(Constants.AGENT_CMD_OS_VERSION)
  File "/Users/ekaterinak/needle/needle/core/utils/utils.py", line 207, in wrapper
    device.connect()
  File "/Users/ekaterinak/needle/needle/core/device/device.py", line 218, in connect
    self._connect_agent()
  File "/Users/ekaterinak/needle/needle/core/device/device.py", line 160, in _connect_agent
    self.agent.exec_command_agent(Constants.AGENT_CMD_OS_VERSION)
  File "/Users/ekaterinak/needle/needle/core/utils/utils.py", line 207, in wrapper
    device.connect()
  File "/Users/ekaterinak/needle/needle/core/device/device.py", line 218, in connect
    self._connect_agent()
  File "/Users/ekaterinak/needle/needle/core/device/device.py", line 160, in _connect_agent
    self.agent.exec_command_agent(Constants.AGENT_CMD_OS_VERSION)
  File "/Users/ekaterinak/needle/needle/core/utils/utils.py", line 207, in wrapper
    device.connect()
  File "/Users/ekaterinak/needle/needle/core/device/device.py", line 218, in connect
    self._connect_agent()
  File "/Users/ekaterinak/needle/needle/core/device/device.py", line 160, in _connect_agent
    self.agent.exec_command_agent(Constants.AGENT_CMD_OS_VERSION)
  File "/Users/ekaterinak/needle/needle/core/utils/utils.py", line 211, in wrapper
    raise Exception("An error occurred and it was not possible to restore it ({} attempts failed)".format(self.tries))
Exception: An error occurred and it was not possible to restore it (3 attempts failed)
------------------------------------------------------------
[!] Exception: An error occurred and it was not possible to restore it (3 attempts failed)
[needle][screenshot] > 2018-10-10 16:48:12,479| ERROR   | Secsh channel 0 open FAILED: Connection refused: Connect failed
2018-10-10 16:48:12,484| ERROR   | Could not establish connection from ('127.0.0.1', 4444) to remote side of the tunnel

Needle Version

Needle v1.3.2 [mwr.to/needle]

  • Framework (on your machine):
  • Agent (on your device): Cydia

Workstation Operating System

macOS Mojave 10.14

Python Version

2.7, but 3.2 doesn't work at all.

Python Packages (pip freeze)

asn1crypto==0.24.0
bcrypt==3.1.4
biplist==1.0.3
cffi==1.11.5
cryptography==2.3.1
enum34==1.1.6
frida==12.2.11
gnureadline==6.3.8
idna==2.7
ipaddress==1.0.22
paramiko==2.4.2
pyasn1==0.4.4
pycparser==2.19
PyNaCl==1.3.0
six==1.11.0
sshtunnel==0.1.4

Device iOS Version

Iphone 5 IOS 10.3.3

@marco-lancini
Copy link
Contributor

Hi @humanUnit, from the log above you can see that:

[D] [REMOTE CMD] Remote Command: lipo -info /Applications/AppStore.app/AppStore
[!] sh: lipo: command not found

This means lipo is not installed on your device. Please install it and feel free to reopen this issue if the problem still persists

@humanUnit
Copy link
Author

@marco-lancini but as I understand lipo is for arm64 devices, if I have arm32 device like iPhone5, then I can't use needle?

@humanUnit
Copy link
Author

humanUnit commented Oct 10, 2018

Also I started get this issue, I am not sure what happened. After I run sudo python needle.py. Before needle started without any issues.

  File "needle.py", line 57, in <module>
    main()
  File "needle.py", line 54, in main
    launch_ui(args)
  File "needle.py", line 31, in launch_ui
    x = cli.CLI(cli.Mode.CONSOLE)
  File "/Users/ekaterinak/needle/needle/core/framework/cli.py", line 47, in __init__
    self._history_load()
  File "/Users/ekaterinak/needle/needle/core/framework/framework.py", line 158, in _history_load
    readline.read_history_file(history_path)
IOError: [Errno 2] No such file or directory ```

@marco-lancini
Copy link
Contributor

@marco-lancini but as I understand lipo is for arm64 devices, if I have arm32 device like iPhone5, then I can't use needle?

I'm afraid not.

Also I started get this issue, I am not sure what happened. After I run sudo python needle.py. Before needle started without any issues.

  File "needle.py", line 57, in <module>
    main()
  File "needle.py", line 54, in main
    launch_ui(args)
  File "needle.py", line 31, in launch_ui
    x = cli.CLI(cli.Mode.CONSOLE)
  File "/Users/ekaterinak/needle/needle/core/framework/cli.py", line 47, in __init__
    self._history_load()
  File "/Users/ekaterinak/needle/needle/core/framework/framework.py", line 158, in _history_load
    readline.read_history_file(history_path)
IOError: [Errno 2] No such file or directory ```

You shouldn't run needle with sudo

@Yogehi
Copy link
Collaborator

Yogehi commented Oct 10, 2018

@humanUnit try the solution here: #172 (comment)

@humanUnit
Copy link
Author

@marco-lancini but if run it without sudo, then I have error IOError: [Errno 13] Permission denied.


             __   _ _______ _______ ______         _______
             | \  | |______ |______ |     \ |      |______
             |  \_| |______ |______ |_____/ |_____ |______
        
                   Needle v1.3.2 [mwr.to/needle]                  
  [MWR InfoSecurity (@MWRLabs) - Marco Lancini (@LanciniMarco)]   

Traceback (most recent call last):
  File "needle.py", line 57, in <module>
    main()
  File "needle.py", line 54, in main
    launch_ui(args)
  File "needle.py", line 31, in launch_ui
    x = cli.CLI(cli.Mode.CONSOLE)
  File "/Users/ekaterinak/needle/needle/core/framework/cli.py", line 47, in __init__
    self._history_load()
  File "/Users/ekaterinak/needle/needle/core/framework/framework.py", line 158, in _history_load
    readline.read_history_file(history_path)
IOError: [Errno 13] Permission denied

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants