Skip to content

Instantly share code, notes, and snippets.

@samsayen
Forked from CHEF-KOCH/redirecttoproxy.sh
Created March 6, 2020 02:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsayen/ae567f03a7c87c0062a2933f0ca4403d to your computer and use it in GitHub Desktop.
Save samsayen/ae567f03a7c87c0062a2933f0ca4403d to your computer and use it in GitHub Desktop.
redirect to proxy
#!/bin/sh
# 2016
echo "Loading Firewall ..."
####################
# Disable IPv6 #
####################
adb shell "echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6"
adb shell "echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6"
adb shell "echo 1 > /proc/sys/net/ipv6/conf/wlan0/disable_ipv6"
####################
# Purge/Flush #
####################
# Clear all rules
adb shell "iptables -F"
adb shell "iptables -t nat -F"
adb shell "iptables -t mangle -F"
adb shell "ip6tables -F"
adb shell "ip6tables -t nat -F"
adb shell "ip6tables -t mangle -F"
# Clear all chains
adb shell "iptables -X"
adb shell "iptables -t nat -X"
adb shell "iptables -t mangle -X"
adb shell "ip6tables -X"
adb shell "ip6tables -t nat -X"
adb shell "ip6tables -t mangle -X"
####################
# Defaults #
####################
# IPv4 connections
adb shell "iptables -P INPUT ACCEPT"
adb shell "iptables -P FORWARD ACCEPT"
adb shell "iptables -P OUTPUT ACCEPT"
# IPv6 connections
adb shell "ip6tables -P INPUT DROP"
adb shell "ip6tables -P FORWARD DROP"
adb shell "ip6tables -P OUTPUT DROP"
#####################
# Redirect Traffic #
#####################
# Redirect HTTP traffic to Burp
adb shell "iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination 192.168.1.100:8080"
# Redirect HTTPS traffic to Burp
adb shell "iptables -t nat -A OUTPUT -p tcp --dport 443 -j DNAT --to-destination 192.168.1.100:8080"
# Activate Masquerading
adb shell "iptables -t nat -A POSTROUTING -p tcp --dport 80 -j MASQUERADE"
adb shell "iptables -t nat -A POSTROUTING -p tcp --dport 443 -j MASQUERADE"
# Disable netd / Force DNS over Router
adb shell "iptables -t nat -I OUTPUT -p tcp --dport 53 -j DNAT --to-destination 192.168.1.1:53"
adb shell "iptables -t nat -I OUTPUT -p udp --dport 53 -j DNAT --to-destination 192.168.1.1:53"
echo "Yo!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment