Proxy Android App Communication via USB

Intructions to enable the access to the SSHd on a LineageOS:

1- Mount the / as rw (Android Device)

mount -o rw,remount,rw /

2- Generate a keypair that will allows to connect via SSH: (Android Device)

/system/bin/ssh-keygen

This will generate a keypair and save it in the defined location.

3- Generate host keys: (Android Device)

/system/bin/ssh-keygen -A

4- Add the public key to the sshd authorized_keys (Android Device)

cat /id_rsa.pub >> /data/ssh/authorized_keys

5- Confirm the existence of sshd_config in /data/ssh/sshd_config or create a new one with the following settings: (Android Device)

ListenAddress 127.0.0.1
Protocol 2
HostKey /data/ssh/ssh_host_rsa_key
LoginGraceTime 2m
PubkeyAuthentication yes
AuthorizedKeysFile /data/ssh/authorized_keys
PasswordAuthentication no
AllowAgentForwarding yes
AllowTcpForwarding yes
GatewayPorts yes
UsePrivilegeSeparation no

6- Start the SSHd (Android Device)

/system/bin/sshd &

7- Copy the private key to your device to use for connecting to SSHd (Host)

adb pull <previousSavedPath>/id_rsa device.priv

8- Ajust the private key permissions (Host)

chmod 600 device.priv

9- Forward the SSH port to the localhost and connect to SSH (Host)

adb forward tcp:2222 tcp:22 ssh localhost -p 2222 -i device.priv

With this setup now it’s easy to use SSH remote port forwarding to redirect a local port in the device to the port where your proxy is running. (Assuming device is connected via USB the same machine where proxy is running)

ssh 127.0.0.1 -p 2222 -i device.priv -R 8080:localhost:8080

Now all you need to do is set the Android device proxy to 127.0.0.1:8080 and all the communication is passed via USB.

comments powered by Disqus