# Proxy

![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-8c5d6ef24ae54759175052b237351dccf0432770%2Fmapt.png?alt=media)

All the following solutions are implemented in [HacknDroid](https://github.com/RaffaDNDM/HacknDroid).

## System Proxy

* Set the system proxy

  ```bash
  adb shell settings get global http_proxy <proxy_ip>:<port>
  ```
* Get current system proxy

  ```bash
  adb shell settings get global http_proxy
  ```
* Reset the system proxy

  ```bash
  adb shell settings put global http_proxy :0
  ```

## Invisible proxy (iptables)

* Set the proxy on ports 80 and 443

  ```bash
  adb shell
  su root
  iptables -t nat -A OUTPUT -p tcp --dport 443 -j DNAT --to-destination <proxy_ip>:443
  iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination <proxy_ip>:80
  iptables -t nat -A POSTROUTING -p tcp --dport 443 -j MASQUERADE
  iptables -t nat -A POSTROUTING -p tcp --dport 80 -j MASQUERADE
  ```
* Set the proxy on port 80 and 443 only for the application with a specific owner UID

  ```bash
  adb shell
  su root
  iptables -t nat -A OUTPUT -m owner --uid-owner <owner_uid> -p tcp --dport 443 -j DNAT --to-destination <proxy_ip>:443
  iptables -t nat -A OUTPUT -m owner --uid-owner <owner_uid> -p tcp --dport 80 -j DNAT --to-destination <proxy_ip>:80
  iptables -t nat -A POSTROUTING -m owner --uid-owner <owner_uid> -p tcp --dport 443 -j MASQUERADE
  iptables -t nat -A POSTROUTING -m owner --uid-owner <owner_uid> -p tcp --dport 80 -j MASQUERADE
  ```
* Get current system proxy

  ```bash
  adb shell
  su root
  iptables -t nat -L OUTPUT -v -n | grep 'DNAT'
  ```
* Reset the system proxy

  ```bash
  adb shell
  su root
  iptables -t nat -F
  ```

## Invisible Proxy (via DNS spoofing)

1. Launch [dnschef](https://github.com/iphelix/dnschef):

   ```bash
   sudo python3 dnschef/dnschef.py --fakeip <proxy_ip> --interface <dns_ip> --log-file /tmp/dnschef.log
   ```
2. Open the Wifi settings and set the IP address specified in `--interface` related to dnschef execution

   ```bash
   adb shell am start -a android.settings.WIFI_SETTINGS
   ```
