首页 > 代码库 > iptables学习
iptables学习
droidwall.sh
#!/system/bin/shIPTABLES=iptablesBUSYBOX=busyboxGREP=grepECHO=echo# Try to find busyboxif /data/data/com.example.my_android_wall/app_bin/busybox_g1 --help >/dev/null 2>/dev/null ; then BUSYBOX=/data/data/com.example.my_android_wall/app_bin/busybox_g1 GREP="$BUSYBOX grep" ECHO="$BUSYBOX echo"elif busybox --help >/dev/null 2>/dev/null ; then BUSYBOX=busyboxelif /system/xbin/busybox --help >/dev/null 2>/dev/null ; then BUSYBOX=/system/xbin/busyboxelif /system/bin/busybox --help >/dev/null 2>/dev/null ; then BUSYBOX=/system/bin/busyboxfi# Try to find grepif ! $ECHO 1 | $GREP -q 1 >/dev/null 2>/dev/null ; then if $ECHO 1 | $BUSYBOX grep -q 1 >/dev/null 2>/dev/null ; then GREP="$BUSYBOX grep" fi # Grep is absolutely required if ! $ECHO 1 | $GREP -q 1 >/dev/null 2>/dev/null ; then $ECHO The grep command is required. DroidWall will not work. exit 1 fifi# Try to find iptables# Added if iptables binary already in system then use it, if not use implemented oneif ! command -v iptables &> /dev/null; thenif /data/data/com.example.my_android_wall/app_bin/iptables_armv5 --version >/dev/null 2>/dev/null ; then IPTABLES=/data/data/com.example.my_android_wall/app_bin/iptables_armv5fifi$IPTABLES --version || exit 1# Create the droidwall chains if necessary$IPTABLES -L droidwall >/dev/null 2>/dev/null || $IPTABLES --new droidwall || exit 2$IPTABLES -L droidwall-3g >/dev/null 2>/dev/null || $IPTABLES --new droidwall-3g || exit 3$IPTABLES -L droidwall-wifi >/dev/null 2>/dev/null || $IPTABLES --new droidwall-wifi || exit 4$IPTABLES -L droidwall-reject >/dev/null 2>/dev/null || $IPTABLES --new droidwall-reject || exit 5# Add droidwall chain to OUTPUT chain if necessary$IPTABLES -L OUTPUT | $GREP -q droidwall || $IPTABLES -A OUTPUT -j droidwall || exit 6# Flush existing rules$IPTABLES -F droidwall || exit 7$IPTABLES -F droidwall-3g || exit 8$IPTABLES -F droidwall-wifi || exit 9$IPTABLES -F droidwall-reject || exit 10# Create the reject rule (log disabled)$IPTABLES -A droidwall-reject -j REJECT || exit 11# Main rules (per interface)$IPTABLES -A droidwall -o rmnet+ -j droidwall-3g || exit$IPTABLES -A droidwall -o pdp+ -j droidwall-3g || exit$IPTABLES -A droidwall -o ppp+ -j droidwall-3g || exit$IPTABLES -A droidwall -o uwbr+ -j droidwall-3g || exit$IPTABLES -A droidwall -o wimax+ -j droidwall-3g || exit$IPTABLES -A droidwall -o vsnet+ -j droidwall-3g || exit$IPTABLES -A droidwall -o ccmni+ -j droidwall-3g || exit$IPTABLES -A droidwall -o usb+ -j droidwall-3g || exit$IPTABLES -A droidwall -o tiwlan+ -j droidwall-wifi || exit$IPTABLES -A droidwall -o wlan+ -j droidwall-wifi || exit$IPTABLES -A droidwall -o eth+ -j droidwall-wifi || exit$IPTABLES -A droidwall -o ra+ -j droidwall-wifi || exit# Filtering rules$IPTABLES -A droidwall-3g -m owner --uid-owner 10079 -j droidwall-reject || exit$IPTABLES -A droidwall-wifi -m owner --uid-owner 10079 -j droidwall-reject || exitexit
iptables -N[X] demo
iptables -A[D] demo -j REJECT -m owner --uid-owner u0_a74
iptables -A[D] OUTPUT -j demo
iptables学习
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。