Linux+DDoS deflate 预防DDoS
使用DDoS腳本防止DDoS
?
使用DDoS腳本防止DDoS:
DDoS概述:
分布式拒絕服務(wù)(DDoS:Distributed Denial of Service),指借助于客戶/服務(wù)器技術(shù),將多個計算機聯(lián)合起來作為attack平臺,對一個或多個目標(biāo)發(fā)動DDoS,從而成倍地提高拒絕服務(wù)的威力。
如何查看是否受到DDoS?
通過netstat? 查看網(wǎng)絡(luò)連接數(shù)。如果一個IP地址對服務(wù)器建立很多連接數(shù)(比如一分鐘產(chǎn)生了100個連接),就認(rèn)為發(fā)生了DDoS
[root@web?~]#?vim??ddos_test.sh???#寫入以下內(nèi)容 #!/bin/bash netstat?-ntu?|?awk?'{print?$5}'?|?cut?-d:?-f1?|?uniq?-c?|?sort?-n 查看tcp和udp連接情況|截取外網(wǎng)IP和端口|截取外網(wǎng)IP|去重|排序并統(tǒng)計模擬DDOS
[root@web?~]#?systemctl?start?httpd #?使用ab命令模擬DDoS?訪問一個頁面?,?頁面越大?,消耗服務(wù)器帶寬就越大 [root@DDoS?~]#?ab?-n?1000?-c?10?http://192.168.94.11/index.html #?-n?要產(chǎn)生的鏈接數(shù)總和???-c?同時打開的客戶端數(shù)量#?回到web服務(wù)器查看 [root@web?~]#?netstat?-ntu?|?awk?'{print?$5}'?|?cut?-d:?-f1?|?uniq?-c?|?sort?-n??????1?192.168.94.2541?Address??????1?servers)???1000?192.168.94.111#?如果發(fā)現(xiàn)某個IP連接數(shù)據(jù)有上百的鏈接,說明就有DDOS解決辦法
使用DDoS deflate?解決服務(wù)器被DDOS的問題
DDoS deflate是用來防御和減輕DDoS的腳本 它通過netstat監(jiān)測跟蹤創(chuàng)建大量網(wǎng)絡(luò)連接的IP地址,在檢測到某個結(jié)點超過預(yù)設(shè)的限制時,該程序會通過APF或IPTABLES禁止或阻擋這些IP
下面開始安裝DDos deflate
[root@web?~]#?wget?? [root@web?~]#?chmod?+x?install.sh? [root@web?~]#?./install.sh?#需要機器能上網(wǎng) Installing?DOS-Deflate?0.6Downloading?source?files.........doneCreating?cron?to?run?script?every?minute.....(Default?setting).....doneInstallation?has?completed. Config?file?is?at?/usr/local/ddos/ddos.conf Please?send?in?your?comments?and/or?suggestions?to?zaf@vsnl.com?#下面內(nèi)容省略?輸入q退出 [root@web?~]#?cd?/usr/local/ddos/ [root@web?ddos]#?ls ddos.conf??ddos.sh??ignore.ip.list??LICENSE????#?安裝目錄下面有配置文件、腳本和IP白名單配置DDoS deflate配置文件
#####?Paths?of?the?script?and?other?files?????????????????????????????????????????????2?PROGDIR="/usr/local/ddos"3?PROG="/usr/local/ddos/ddos.sh"????#要執(zhí)行的DDoS腳本??4?IGNORE_IP_LIST="/usr/local/ddos/ignore.ip.list"????#?IP白名單?,?名單中的IP不受限制??5?CRON="/etc/cron.d/ddos.cron"????#?周期任務(wù)??6?APF="/etc/apf/apf"7?IPT="/sbin/iptables"8?9?#####?frequency?in?minutes?for?running?the?script?10?#####?Caution:?Every?time?this?setting?is?changed,?run?the?script?with?--cron?11?#####??????????option?so?that?the?new?frequency?takes?effect?12?FREQ=1????#?檢查DDoS×××間隔?,?默認(rèn)一分鐘?13?14?#####?How?many?connections?define?a?bad?IP??Indicate?that?below.?15?NO_OF_CONNECTIONS=150????#?最大連接數(shù),超過這個數(shù)IP就會被屏蔽,一般默認(rèn)即可?16?17?#####?APF_BAN=1?(Make?sure?your?APF?version?is?atleast?0.96)?18?#####?APF_BAN=0?(Uses?iptables?for?banning?ips?instead?of?APF)?19?APF_BAN=1????#?使用APF還是iptables。推薦使用iptables,將APF_BAN的值改為0即可?20?21?#####?KILL=0?(Bad?IPs?are'nt?banned,?good?for?interactive?execution?of?script)22?#####?KILL=1?(Recommended?setting)?23?KILL=1????#??是否屏蔽IP,默認(rèn)即可?24?25?#####?An?email?is?sent?to?the?following?address?when?an?IP?is?banned.?26?#####?Blank?would?suppress?sending?of?mails?27?EMAIL_TO="root"????#?當(dāng)IP被屏蔽時給指定郵箱發(fā)送郵件報警,換成自己的郵箱即可?28?29?#####?Number?of?seconds?the?banned?ip?should?remain?in?blacklist.?30?BAN_PERIOD=600????#?禁用IP時間,默認(rèn)600秒,可根據(jù)情況調(diào)整查看周期任務(wù)
[root@web?ddos]#?cat?/etc/cron.d/ddos.cron?#?系統(tǒng)級別的計劃任務(wù)? SHELL=/bin/sh0-59/1?*?*?*?*?root?/usr/local/ddos/ddos.sh?>/dev/null?2>&1#?每分鐘查看一下,是不是有DDoS,如果發(fā)現(xiàn)就開始拒絕測試
#?查看web服務(wù)器iptables策略 [root@web?ddos]#?iptables?-nL Chain?INPUT?(policy?ACCEPT) target?????prot?opt?source???????????????destination?????????Chain?FORWARD?(policy?ACCEPT) target?????prot?opt?source???????????????destination?????????Chain?OUTPUT?(policy?ACCEPT) target?????prot?opt?source???????????????destination????????#使用ab命令模擬DDoS [root@DDoS?~]#?ab?-n?1000?-c?10?http://192.168.94.11/index.html?#?等一分鐘查看web服務(wù)器查看iptables策略 [root@web?ddos]#?iptables?-nL Chain?INPUT?(policy?ACCEPT) target?????prot?opt?source???????????????destination????????? DROP???????all??--??192.168.94.111???????0.0.0.0/0???????????Chain?FORWARD?(policy?ACCEPT) target?????prot?opt?source???????????????destination?????????Chain?OUTPUT?(policy?ACCEPT) target?????prot?opt?source???????????????destination????????? [root@web?ddos]#若果不想使用DDoS deflate怎么辦呢?
很簡單
一鍵卸載 :
[root@web?ddos]#?wget?? [root@web?ddos]#?chmod?+x?uninstall.ddos? [root@web?ddos]#?./uninstall.ddos?Uninstalling?DOS-DeflateDeleting?script?files.........doneDeleting?cron?job.......doneUninstall?Complete雖然說DDoS deflate的計劃任務(wù)是系統(tǒng)級別的
hacker一樣有辦法去篡改一個系統(tǒng)級別的計劃任務(wù)
可能我們也看不出動了什么手腳 ,? 定期檢查的時候看著還是跟往常一樣
忽然某一天被DDoS還不知道怎么回事
所以 , 我們還是先下手為強
[root@web?~]#?find?/etc/cron*?-type?f?-exec?md5sum?{}?\;?>?/usr/share/cronfile_md5 #?可以使用md5加密?,?因為md5加密算法是不可逆的?,?文件只要被改動過就能看得出來 [root@web?share]#?cat?cronfile_md5? 1638f7fe39f7f52c412e1705a0bc52d1??/etc/cron.d/0hourly 367636170f3ac44df6a117e3cbf7e4ba??/etc/cron.d/raid-check a51a35325c37a1cc0ed00f8638a06b96??/etc/cron.d/ddos.cron 6e10e35911b4ba4e2dff44613b56676f??/etc/cron.daily/logrotate 16e73be8fe46a83f7525b59f921e9bab??/etc/cron.daily/man-db.cron d41d8cd98f00b204e9800998ecf8427e??/etc/cron.deny 8675eb4a3dba8e20bd6b82c626304556??/etc/cron.hourly/0anacron c39252b11aad842fcb75e05c6a27eef8??/etc/crontab [root@web?share]#?md5sum?-c?cronfile_md5????? #?校驗文件信息/etc/cron.d/0hourly:?確定 /etc/cron.d/raid-check:?確定 /etc/cron.d/ddos.cron:?確定 /etc/cron.daily/logrotate:?確定 /etc/cron.daily/man-db.cron:?確定 /etc/cron.deny:?確定 /etc/cron.hourly/0anacron:?確定 /etc/crontab:?確定 [root@web?share]#?echo?"?"?>>?/etc/cron.d/ddos.cron?????#?加一個空格進去 [root@web?share]#?md5sum?-c?cronfile_md5? /etc/cron.d/0hourly:?確定 /etc/cron.d/raid-check:?確定 /etc/cron.d/ddos.cron:?失敗????#?驗證失敗 /etc/cron.daily/logrotate:?確定 /etc/cron.daily/man-db.cron:?確定 /etc/cron.deny:?確定 /etc/cron.hourly/0anacron:?確定 /etc/crontab:?確定 md5sum:?警告:1?個校驗和不匹配這樣定期檢查的時候就可以發(fā)現(xiàn)系統(tǒng)級別的計劃任務(wù)是否被篡改
?
轉(zhuǎn)載于:https://blog.51cto.com/13848248/2177394
總結(jié)
以上是生活随笔為你收集整理的Linux+DDoS deflate 预防DDoS的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux下安装navicat并生成桌面
- 下一篇: day5 笔记