Install mitmproxy
- Install
mitmproxy
with your package manager
Generate self signed certificate
- Run
mitmproxy
& exit (creates ~/.mitmproxy with certificate valid for 10 years)
Install certificate on Manjaro Linux
openssl x509 -in ~/.mitmproxy/mitmproxy-ca.pem -inform PEM -out ca.crt
sudo trust anchor ca.crt
rm ca.crt
Remove certificate after usage:
trust list
sudo trust anchor --remove "pkcs11:id=%AA%BB%CC%DD%EE;type=cert"
HTTPS Sniffing with mitmproxy in reverse mode
mitmproxy --mode reverse:https://login.nestbank.pl/ -p 4433
Connect to “https://localhost:4433”
Source:
https://unix.stackexchange.com/questions/103037/what-tool-can-i-use-to-sniff-http-https-traffic
https://gist.github.com/franciscocpg/a4f52afcc00d472a9d7c407db16a92ee
Sniff traffic from Android phone
Install certificate on the phone
Copy ~/.mitmproxy/mitmproxy-ca-cert.cer to the phone
Go to Settings, Security / … / “Install from device storage”
Select certificate file and click “OK”
Set name & keep used for: “VPN and apps”
Now click on “Trusted credentials” and select the “User” tab. The certificate should now appear in the list.
Starting from Android 24 (7.0) the certificate must be installed in the system trust store. To do it:
Move certificate file found in
/data/misc/user/0/cacerts-added/
folder to/system/etc/security/cacerts
Reboot the phone
Firefox does not use system certificates and the certificate must be imported to Firefox.
Option 1 - regular proxy
Regular proxy works with most apps, but not with not all of them (TCP stream and/or Mono apps). But it’s easy to enable.
On the phone:
Go to the wifi settings
Go to the network’s settings
Put computer’s IP and port (8080)
Run mitmproxy as regular proxy:
mitmproxy
Option 2 - transparent proxy
On the phone:
Got to the wifi settings, static IP
Put your PC’s IP address as the default gateway
On PC - these settings will not be persistent after reset:
Enable IP forwarding and disable ICMP redirects:
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv6.conf.all.forwarding=1
sudo sysctl -w net.ipv4.conf.all.send_redirects=0
Redirect the desired traffic to mitmproxy:
sudo iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 1:65535 -j REDIRECT --to-port 8080
sudo ip6tables -t nat -A PREROUTING -i eno1 -p tcp --dport 1:65535 -j REDIRECT --to-port 8080
where eno1
is the interface name (may be different for you, verify with ifconfig
) and 1:65535
is port range (you may alternatively provide single port like 443
and 80
)
- Run mitmproxy with transparent mode:
mitmproxy --mode transparent --showhost