推出全新OEM分銷體系
具有殺傷力的價(jià)格,超大利潤
Linux服務(wù)器 屏蔽國外IP訪問及簡單的防CC攻擊攔截屏蔽國外IP訪問 通過ssh遠(yuǎn)程登錄服務(wù)器內(nèi),運(yùn)行如下命令語句獲取國內(nèi)IP網(wǎng)段,會(huì)保存為/root/china_ssr.txt wget -q --timeout=60 -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F\| '/CN\|ipv4/ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /root/china_ssr.txt 將下面腳本保存為/root/allcn.sh ,并設(shè)置可執(zhí)行權(quán)限( 命令: chmod +x allcn.sh) mmode=$1 CNIP="/root/china_ssr.txt" gen_iplist() { cat <<-EOF $(cat ${CNIP:=/dev/null} 2>/dev/null) EOF } flush_r() { iptables -F ALLCNRULE 2>/dev/null iptables -D INPUT -p tcp -j ALLCNRULE 2>/dev/null iptables -X ALLCNRULE 2>/dev/null ipset -X allcn 2>/dev/null } mstart() { ipset create allcn hash:net 2>/dev/null ipset -! -R <<-EOF $(gen_iplist | sed -e "s/^/add allcn /") EOF iptables -N ALLCNRULE iptables -I INPUT -p tcp -j ALLCNRULE iptables -A ALLCNRULE -s 127.0.0.0/8 -j RETURN iptables -A ALLCNRULE -s 169.254.0.0/16 -j RETURN iptables -A ALLCNRULE -s 224.0.0.0/4 -j RETURN iptables -A ALLCNRULE -s 255.255.255.255 -j RETURN iptables -A ALLCNRULE -m set --match-set allcn src -j RETURN iptables -A ALLCNRULE -p tcp -j DROP } if [ "$mmode" == "stop" ] ;then flush_r exit 0 fi flush_r sleep 1 mstart 執(zhí)行如下命令將開始攔截 /root/allcn.sh 執(zhí)行如下命令即可停止攔截 /root/allcn.sh stop CC攻擊攔截 方式1:通過netstat -an命令統(tǒng)計(jì)出當(dāng)前請(qǐng)求并發(fā)大于100的IP,然后將不在白名單的IP自動(dòng)加入DROP規(guī)則 首先運(yùn)行 vi deny_1.sh 添加以下命令語句 #!/bin/bash if [[ -z $1 ]];then num=100 else num=$1 fi cd $(cd $(dirname $BASH_SOURCE) && pwd) iplist=`netstat -an |grep ^tcp.*:80|egrep -v 'LISTEN|127.0.0.1'|awk -F"[ ]+|[:]" '{print $6}'|sort|uniq -c|sort -rn|awk -v str=$num '{if ($1>str){print $2} fi}'` if [[ ! -z $iplist ]]; then for black_ip in $iplist do ip_section=`echo $black_ip | awk -F"." '{print $1"."$2"."$3}'` grep -q $ip_section ./white_ip.txt if [[ $? -eq 0 ]];then echo $black_ip >>./recheck_ip.txt else iptables -nL | grep $black_ip || iptables -I INPUT -s $black_ip -j DROP echo $black_ip >>./black_ip.txt fi done fi 保存后執(zhí)行以下語句: chmod +x deny_1.sh sh deny_1.sh 攔截的IP會(huì)記錄到black_ip.txt中,如果有要排除的白名單IP,可將這些IP加入到white_ip.txt,一行一個(gè)。 方式2:通過web網(wǎng)站日志中攻擊者訪問特征,根據(jù)這些特征過濾出攻擊的ip,利用iptables來阻止(排除本機(jī)IP:127.0.0.1)。 首先運(yùn)行 vi deny_2.sh 添加以下命令語句: #!/bin/bash OLD_IFS=$IFS IFS=$'\n' for status in `cat 網(wǎng)站訪問日志路徑 | grep '特征字符' | grep -v '127.0.0.1' | awk '{print $1}' |sort -n | uniq -c | sort -n -r | head -20` do IFS=$OLD_IFS NUM=`echo $status | awk '{print $1}'` IP=`echo $status | awk '{print $2}'` if [ -z "`iptables -nvL | grep "dpt:80" | awk '{print $8}' | grep "$IP"`" ];then if [ $NUM -gt 250 ];then /sbin/iptables -I INPUT -p tcp -s $IP --dport 80 -j DROP fi fi done 保存后執(zhí)行以下語句: chmod +x deny_2.sh sh deny_2.sh 最后使用crontab -e 添加到任務(wù)計(jì)劃,每20分鐘執(zhí)行一次: */20 * * * * /root/deny_ip1.sh >dev/null 2>&1 注意:
|
|||||
>> 相關(guān)文章 | |||||
關(guān)注我們
最新動(dòng)態(tài)
新浪微博
交流互動(dòng)
關(guān)于我們
|
聯(lián)系我們
|
付款方式
|
人才招聘
|
友情鏈接
|
域名資訊
|
提交工單
|
我要評(píng)價(jià)
|
投訴建議
|
域名投訴
|
網(wǎng)站備案
|
百科知識(shí)
|
手機(jī)站
《中華人民共和國增值電信業(yè)務(wù)經(jīng)營許可證》編號(hào):B1-20172600 川B1-20080058 蜀ICP備12028237號(hào)
《中華人民共和國互聯(lián)網(wǎng)域名服務(wù)許可證》編號(hào):川 D3-20220002
電話總機(jī):028-62778877(20線) 400電話:400-028-5800
400-028-5800
028-62778877
您好,非正常上班時(shí)間若有緊急技術(shù)問題,請(qǐng)撥總機(jī)后按7號(hào)鍵, 其他問題請(qǐng)?zhí)峤还位蛟谏习鄷r(shí)間聯(lián)系,謝謝支持!