iptables学习

系统 2589 0

droidwall.sh

      
        #
      
      
        !/system/bin/sh
      
      

IPTABLES=
      
        iptables

BUSYBOX
      
      =
      
        busybox

GREP
      
      =
      
        grep

ECHO
      
      =
      
        echo


      
      
        #
      
      
         Try to find busybox
      
      
        if
      
       /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
      
      =
      
        busybox


      
      
        elif
      
       /system/xbin/busybox --help >/dev/null 2>/dev/
      
        null ; then

    BUSYBOX
      
      =/system/xbin/
      
        busybox


      
      
        elif
      
       /system/bin/busybox --help >/dev/null 2>/dev/
      
        null ; then

    BUSYBOX
      
      =/system/bin/
      
        busybox

fi


      
      
        #
      
      
         Try to find grep
      
      
        if
      
       ! $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
      
        

    fi

fi


      
      
        #
      
      
         Try to find iptables
      
      
        

#
      
      
         Added if iptables binary already in system then use it, if not use implemented one
      
      
        if
      
       ! command -v iptables &> /dev/
      
        null; then


      
      
        if
      
       /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_armv5

fi

fi

$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 ||
      
         exit

exit
      
    

iptables -N[X] demo

iptables -A[D] demo -j REJECT -m owner --uid-owner u0_a74

iptables -A[D] OUTPUT -j demo

 

iptables学习


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论