時(shí)間:2023-04-18 18:20:01 | 來源:網(wǎng)站運(yùn)營
時(shí)間:2023-04-18 18:20:01 來源:網(wǎng)站運(yùn)營
網(wǎng)站防刷方案:網(wǎng)站防刷方案User -> Browse -> CDN/Proxy Cache -> Web Server -> App Server / fastcgi pool -> Cache -> Database
大部分網(wǎng)站都是這樣的結(jié)構(gòu):用戶,瀏覽器,CDN或反向代理,Web服務(wù)器,應(yīng)用服務(wù)器,緩存,數(shù)據(jù)庫PC -> ADSL/Cable/Ethernet -> Route -> ... -> Route -> Firewall -> Load Balance -> Switch -> Server
我們看看從那些環(huán)節(jié)可以截獲用戶的刷新行為$("form").submit(function(){ $(":submit",this).attr("disabled","disabled");});
在上面的例子基礎(chǔ)上可以改良,增加計(jì)時(shí)器,限制一定時(shí)間內(nèi)不可重復(fù)提交。訪問第一個(gè)頁面 login.example.com/form.ext 的時(shí)候設(shè)置一個(gè) cookie 變量訪問第二個(gè)頁面 login.example.com/auth.ext 的時(shí)候判斷上一個(gè)頁面設(shè)置的 cookie 是否有效,如果無效拒絕訪問。
可以進(jìn)一步增加難度,例如用戶注冊(cè)分為很多步驟,每一個(gè)步驟都會(huì)設(shè)置一個(gè)標(biāo)記,如果用戶行為不是按照順序訪問,直接在最后一個(gè)頁面提交,明顯可以判斷是非法行為。iptables -A INPUT -p icmp -m limit --limit 3/s -j LOG --log-level INFO --log-prefix "ICMP packet IN: "iptables -N syn-floodiptables -A INPUT -p tcp --syn -j syn-floodiptables -I syn-flood -p tcp -m limit --limit 3/s --limit-burst 6 -j RETURNiptables -A syn-flood -j REJECT
限制源IP的訪問數(shù)量-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 --tcp-flags FIN,SYN,RST,ACK SYN -m connlimit --connlimit-above 50 --connlimit-mask 32 -j REJECT --reject-with icmp-port-unreachable-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 --tcp-flags FIN,SYN,RST,ACK SYN -m connlimit --connlimit-above 50 --connlimit-mask 32 -j REJECT --reject-with icmp-port-unreachable
關(guān)鍵字,字符串過略iptables -A INPUT -p tcp --dport 80 -m string --algo bm --string "XXDD0S" -j DROP
以上所講都是被動(dòng)方法,需要系統(tǒng)管理一條一條添加規(guī)則。#!/bin/bash######################################### Homepage: http://netkiller.github.io# Author: neo <netkiller@msn.com>########################################PIPE=/tmp/pipepidfile=/tmp/firewall.pidACCCESS_LOG=/tmp/access.logTIMEPOINT='24/May/2012'BLACKLIST=/var/tmp/black.lstWHITELIST=/var/tmp/white.lst########################################if [ -z "$( egrep "CentOS|Redhat" /etc/issue)" ]; then echo 'Only for Redhat or CentOS' exitfiif [ ! -f ${BLACKLIST} ]; then touch ${BLACKLIST}fiif [ ! -f ${WHITELIST} ]; then touch ${WHITELIST}fifor deny in $(grep ${TIMEPOINT} ${ACCCESS_LOG} | awk '{print $1}' | awk -F'.' '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -r -n | head -n 30| awk '{print $2}')do if [ $(grep -c $deny ${WHITELIST}) -ne 0 ]; then echo 'Allow IP:' $deny iptables -D INPUT -p tcp --dport 443 -s $deny -j DROP iptables -D INPUT -p tcp --dport 80 -s $deny -j DROP continue fi if [ $(grep -c $deny ${BLACKLIST}) -eq 0 ] ; then echo 'Deny IP:' $deny echo $deny >> ${BLACKLIST} iptables -I INPUT -p tcp --dport 443 -s $deny -j DROP iptables -I INPUT -p tcp --dport 80 -s $deny -j DROP fidone
相比前面腳本,這個(gè)腳本更高級(jí),實(shí)現(xiàn)關(guān)鍵字過濾,管道實(shí)時(shí)處理,這樣不回因?yàn)槿罩境叽缱兇?,影響到腳本的處理性能。#!/bin/bash######################################### Homepage: http://netkiller.github.io# Author: neo <netkiller@msn.com>########################################ACCESSLOG=/www/logs/www.example.com/access.$(date +'%Y-%m-%d').logTIMEPOINT='24/May/2012'KEYWORD=send.phpBLACKLIST=/var/tmp/black.lstWHITELIST=/var/tmp/white.lstPIPE=/var/tmp/pipepidfile=/var/tmp/firewall.pidlogfile=/var/tmp/firewall.log########################################if [ -z "$( egrep "CentOS|Redhat" /etc/issue)" ]; then echo 'Only for Redhat or CentOS' exitfiif [ -z $1 ]; then echo "$0 clear|fw|collect|process|close"fiif [ "$1" == "clear" ]; then rm -rf $BLACKLIST rm -rf $PIPE echo "Clear OK!!!"fiif [ "$1" == "close" ]; then killall tail kill `cat $pidfile` echo > $pidfilefiif [ ! -e $PIPE ]; then mkfifo $PIPEfiif [ "$1" == 'fw' ]; then iptables -A OUTPUT -p tcp --dport 2049 -j REJECT iptables -A OUTPUT -p tcp -m multiport --dports 22,21 -j REJECT for ipaddr in ${WHITELIST} do if [ $(grep -c $ipaddr ${WHITELIST}) -ne 0 ]; then iptables -A INPUT -p tcp --dport 443 -s $ipaddr -j ACCEPT iptables -A INPUT -p tcp --dport 80 -s $ipaddr -j ACCEPT echo 'Allow IP:' $ipaddr >> $logfile fi if [ $(grep -c $ipaddr ${BLACKLIST}) -eq 0 ] ; then iptables -D INPUT -p tcp --dport 443 -s $ipaddr -j DROP iptables -D INPUT -p tcp --dport 80 -s $ipaddr -j DROP echo 'Deny IP:' $ipaddr fi donefiif [ "$1" == "collect" ]; then killall tail for (( ; ; )) do tail -f $ACCESSLOG | grep $KEYWORD | cut -d ' ' -f1 > $PIPE done & echo $! > $pidfilefiif [ "$1" == "process" ]; then if [ ! -f $BLACKLIST ]; then touch $BLACKLIST fi if [ ! -f ${WHITELIST} ]; then touch ${WHITELIST} fi for (( ; ; )) do while read ipaddr do if [ $(grep -c $ipaddr ${WHITELIST}) -ne 0 ]; then echo 'Allow IP:' $ipaddr >> $logfile continue fi grep $ipaddr ${BLACKLIST} if [ $? -eq 1 ] ; then echo $ipaddr >> ${BLACKLIST} iptables -I INPUT -p tcp --dport 80 -s $ipaddr -j DROP echo "Deny IP: $ipaddr" >> $logfile fi done < $PIPE done & echo $! >> $pidfilefi
5.2. WEB 服務(wù)器部分valid_referers none blocked *.example.com example.com;if ($invalid_referer) { #rewrite ^(.*)$ http://www.example.com/cn/$1; return 403;} if ($http_user_agent = "") { return 403; }
6. 通過程序控制訪問行為www.example.com (此時(shí) http_referer 為空,或者其他,這不重要) -> login.example.com (http_referer: www.example.com)-> login.example.com/auth.ext (http_referer: login.example.com) -> login.example.com/secussed.ext (http_referer: login.example.com/auth.ext)
看明白了嗎 http_referer 每次都是上一個(gè)頁面,我們程序中判斷,如果上一個(gè)頁面不是我們所指定的,或者不再允許列表內(nèi),就拒絕訪問www.example.com (GET) -> login.example.com (GET)-> login.example.com/auth.ext (POST) -> login.example.com/secussed.ext (GET)
同理,在不允許的頁面POST操作,將立即拒絕www.example.com (cookie 1) -> login.example.com (cookie 2)-> login.example.com/auth.ext (cookie 3) -> login.example.com/secussed.ext (cookie 4)
沒有按照指定流程訪問,cookie 值不會(huì)變化,屬于異常行為 關(guān)鍵詞:方案
客戶&案例
營銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。