3.1 USB connection
3.1.1 Python Script Port Mapping

SSH [email protected] (SSH -p 22 [email protected]) SSH -p 12345 root@localhost As long as the local port 12345 is mapped to the USB port, the usb port is connected to the device to which the request is sent.

There is a python-client tool for mapping ports:

`

Python tcprelay.py -t Port to map: local port

`


python-client python tcprelay.py -t 22:12345

Forwarding local port 12345 to remote port 22

Copy the code

Map the local port 12345 to TCP port 22 on the device. This allows you to establish a connection locally through port 12345.

3.1.2 SSH Connection over USB

If you want to log in directly after mapping successfully:

You can also SSH -p 12345 [email protected] SSH -p 12345 root@localhostCopy the code

The important point here is that do not close the window after the port mapping is successful, otherwise there will be no mapping.

SSH connects to local 12345 and connects to port 22 of the opposite device through USB due to port mapping.

 SSH -p 12345 root@localhost The authenticity of host '[localhost]:12345 ([127.0.0.1]:12345)' can't be established. RSA  key fingerprint is SHA256:3vASLTEmYAr3ngQJ6b8MmLD82/LhxP0PuNHFQNPhBGl0. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '[localhost]:12345' (RSA) to the list of known hosts. zaizai:~ root#Copy the code

The RSA local record is re-executed (the IP address has been changed), and the secret free login is still valid. (IN order to test other convenience, I directly use 2222)

ps: ipChange is equivalent to logging in to a new server. So saversa.

3.1.3 Verifying a man-in-the-middle attack

At this time, SSH -p 12345 root@localhost login on another device will prompt the man in the middle attack, because the RSA corresponding to the local localhost does not match the hash value returned by the new phone. If only one mobile phone can be simulated by changing the RSA public key of localhost corresponding to know_hosts:

 SSH -p 12345 root @ localhost @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. The fingerprint for the RSA key sent by the remote host is SHA256:pIPlaWYd9wT2MfpRqvP/WOe1wVXfVVKiCKttyPHK3f0. Please contact your system administrator. Add correct host key in /Users/zaizai/.ssh/known_hosts to get rid of this message. Offending RSA key in /Users/zaizai/.ssh/known_hosts:4 RSA host key for [localhost]:12345 has changed and you have requested strict checking. Host key verification failed.Copy the code

So if you have two phones you can log in to via sh -p 12345 root@localhost and SSH -p 12345 [email protected], you can tell them apart.

3.2 Configuring USB Quick Login

In this case, the alias in config will not work because the port is mapped and the address is not a real address.

Create an iphonex. sh file in your script directory (it is best to configure environment variables for this directory) with the following script:

ssh -p 12345 root@localhost

The port mapping script usbconnect.sh is also required:

python /Users/zaizai/HPShell/python-client/tcprelay.py -t 22:12345

The port mapping script is separated from the connection script to facilitate switching between multiple devices, since the mapping is only required once.

Use:

// Map port  usbconnect. sh // link  iphonex. sh to connect to the phone.Copy the code

Requires two Windows to execute, mapping the end of the window that always exists.

Script directory files:

3.3 IproxyPort mapping

Iproxy is also a mapping tool.

  1. The installationlibimobiledevice

brew install libimobiledevice

Copy the code
  1. Port mapping

Iproxy local port to be mapped


iproxy 12345 22

Copy the code

This mapping is the reverse of the Python script. On the left are the local ports and on the right are the ports to be mapped. Other uses are the same.

Mapping terminal:


 iproxy 12345 22

Creating listening port 12345 for device port 22

waiting for connection

New connection for 12345->22, fd = 5

waiting for connection

Requesting connecion to USB device handle 3 (serial: 5d38c0a07ffa912050c2cbc05da5436e10a2d5d7), port 22

Copy the code

Connection terminal:

 iPhoneX. Sh iPhoneX: ~ root#Copy the code

End