uBuntu Nginx/Apache DDOS Fail2Ban 攻擊防范

最近服務(wù)器被DDOS惡意攻擊,對于此類攻擊,筆者基本思路是使用IP地址過濾,因為這里的攻擊者采用的是不同的IP輪流攻擊恬惯,這里采用FAIL2BAN+IPTABLE來記錄重復(fù)請求并將IP地址記錄黑名單的方式實現(xiàn), 日志如下:

139.208.55.108 - - [19/Jun/2017:16:47:49 +0800] "POST /sys/zh/wininhr/home/index?a=sendSMSy HTTP/1.1" 200 478 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)"
139.208.55.108 - - [19/Jun/2017:16:47:49 +0800] "POST /sys/zh/wininhr/home/index?a=sendSMSy HTTP/1.1" 200 478 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)"
139.208.55.108 - - [19/Jun/2017:16:47:49 +0800] "POST /sys/zh/wininhr/home/index?a=sendSMSy HTTP/1.1" 200 478 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)"
139.208.55.108 - - [19/Jun/2017:16:47:49 +0800] "POST /sys/zh/wininhr/home/index?a=sendSMSy HTTP/1.1" 200 478 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)"
139.208.55.108 - - [19/Jun/2017:16:47:49 +0800] "POST /sys/zh/wininhr/home/index?a=sendSMSy HTTP/1.1" 200 478 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)"
139.208.55.108 - - [19/Jun/2017:16:47:49 +0800] "POST /sys/zh/wininhr/home/index?a=sendSMSy HTTP/1.1" 200 478 "-" "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11"
183.157.18.57 - - [19/Jun/2017:16:47:50 +0800] "POST /sys/zh/wininhr/home/index?a=sendSMSy HTTP/1.1" 200 478 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)"
112.51.51.91 - - [19/Jun/2017:16:47:51 +0800] "POST /sys/zh/wininhr/home/index?a=sendSMSy HTTP/1.1" 200 478 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)"
125.84.177.240 - - [19/Jun/2017:16:47:51 +0800] "POST /sys/zh/wininhr/home/index?a=sendSMSy HTTP/1.1" 200 478 "-" "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11"
218.77.94.240 - - [19/Jun/2017:16:47:52 +0800] "POST /sys/zh/wininhr/home/index?a=sendSMSy HTTP/1.1" 200 478 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)"
175.167.236.138 - - [19/Jun/2017:16:47:54 +0800] "POST /sys/zh/wininhr/home/index?a=sendSMSy HTTP/1.1" 200 478 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)"

安裝fail2ban

apt-get install fail2ban

配置基本屬性:vi /etc/fail2ban/jail.conf

[nginx-get-sms-limit]
enabled=true
filter=nginx-get-sms-limit
action=iptables[name=nppl, port=http, protocol=tcp]
logpath=/var/log/apache2/other_vhosts_access.log  #NGinx: /var/log/nginx/access.log
findtime=60
bantime=7200
maxretry=3

配置攔截規(guī)則:vi /etc/fail2ban/filter.d/nginx-get-sms-limit.conf

[Definition]
failregex=<HOST>.*GET.*sms\?phone.*

調(diào)試匹配項

fail2ban-regex /var/log/apache2/other_vhosts_access.log /etc/fail2ban/filter.d/nginx-get-sms-limit.conf
fail2ban-client status nginx-get-sms-limit

查看被禁用IP地址

iptables -nL
REJECT     all  --  175.8.29.85          0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  114.232.99.86        0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  59.58.7.225          0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  117.81.205.54        0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  27.154.70.171        0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  123.82.184.185       0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  182.37.56.89         0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  60.175.17.23         0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  183.9.84.178         0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  111.122.177.36       0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  1.60.213.68          0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  115.218.227.113      0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  182.41.105.209       0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  125.109.17.39        0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  140.237.98.68        0.0.0.0/0            reject-with icmp-port-unreachable

PS: 這里注意一下 IPTABLES 里面有3中類型:ACCEPT, REJECT, DROP, 默認(rèn)為REJECT, REJECT與DROP的區(qū)別:打一個比方你收到一個詐騙電話, DROP就是直接掛機(jī)亚茬,REJECT就是你跟他說我不需要酪耳。
這里我們改成DROP,不記錄日志直接拒絕:

  • ACCEPT:允許數(shù)據(jù)包通過才写。
  • DROP:直接丟棄數(shù)據(jù)包葡兑。
  • REJECT:丟棄數(shù)據(jù)包,同時發(fā)送響應(yīng)報文通知發(fā)送方赞草。

增加配置項到: vi /etc/fail2ban/action.d/iptables-blocktype.local

[Init]
blocktype = DROP

查看屏蔽日志: /var/log/fail2ban.log

2017-06-19 16:51:12,252 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 60.180.1.255
2017-06-19 16:51:24,273 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 117.89.101.27
2017-06-19 16:51:24,281 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 183.253.143.67
2017-06-19 16:51:25,288 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 36.22.177.154
2017-06-19 16:51:41,315 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 115.202.100.52
2017-06-19 16:51:46,330 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 49.73.108.251
2017-06-19 16:51:49,341 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 116.10.160.6
2017-06-19 16:52:02,364 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 115.210.142.15
2017-06-19 16:52:06,378 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 183.30.139.203
2017-06-19 16:52:24,410 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 223.73.193.42
2017-06-19 16:52:25,421 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 124.238.145.101
2017-06-19 16:52:28,432 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 113.222.233.141
2017-06-19 16:52:28,440 fail2ban.actions: INFO   [nginx-get-sms-limit] 113.222.233.141 already banned
2017-06-19 16:52:29,442 fail2ban.actions: INFO   [nginx-get-sms-limit] 113.222.233.141 already banned
2017-06-19 16:52:30,444 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 113.5.228.58
2017-06-19 16:52:30,452 fail2ban.actions: INFO   [nginx-get-sms-limit] 113.5.228.58 already banned
2017-06-19 16:52:31,454 fail2ban.actions: INFO   [nginx-get-sms-limit] 113.5.228.58 already banned
2017-06-19 16:52:32,456 fail2ban.actions: INFO   [nginx-get-sms-limit] 113.5.228.58 already banned
2017-06-19 16:52:33,457 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 125.118.140.47
2017-06-19 16:52:37,471 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 117.179.227.224
2017-06-19 16:52:38,478 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 27.18.63.44
2017-06-19 16:52:38,486 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 110.81.60.177
2017-06-19 16:52:39,497 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 115.229.49.104
2017-06-19 16:52:48,517 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 117.82.174.234
2017-06-19 16:52:52,529 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 121.34.167.236
2017-06-19 16:52:53,538 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 106.226.56.52
2017-06-19 16:52:54,546 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 60.181.11.55
2017-06-19 16:53:00,561 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 27.151.192.86
2017-06-19 16:53:01,570 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 113.88.251.191
2017-06-19 16:53:03,580 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 211.162.109.118
2017-06-19 16:53:07,593 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 1.204.205.221
2017-06-19 16:53:12,608 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 114.218.251.125
2017-06-19 16:53:13,619 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 101.207.134.2
2017-06-19 16:53:16,633 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 27.151.202.76
2017-06-19 16:53:20,647 fail2ban.actions: WARNING [nginx-get-sms-limit] Ban 49.222.181.56
...

更多查看:

@see http://www.361way.com/fail2ban-nginx/1825.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末讹堤,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子厨疙,更是在濱河造成了極大的恐慌洲守,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,311評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件沾凄,死亡現(xiàn)場離奇詭異梗醇,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)撒蟀,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,339評論 2 382
  • 文/潘曉璐 我一進(jìn)店門叙谨,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人保屯,你說我怎么就攤上這事手负。” “怎么了姑尺?”我有些...
    開封第一講書人閱讀 152,671評論 0 342
  • 文/不壞的土叔 我叫張陵竟终,是天一觀的道長。 經(jīng)常有香客問我切蟋,道長统捶,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,252評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮喘鸟,結(jié)果婚禮上匆绣,老公的妹妹穿的比我還像新娘。我一直安慰自己迷守,他們只是感情好犬绒,可當(dāng)我...
    茶點故事閱讀 64,253評論 5 371
  • 文/花漫 我一把揭開白布旺入。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪瓤逼。 梳的紋絲不亂的頭發(fā)上勺馆,一...
    開封第一講書人閱讀 49,031評論 1 285
  • 那天,我揣著相機(jī)與錄音拗秘,去河邊找鬼圣絮。 笑死,一個胖子當(dāng)著我的面吹牛雕旨,可吹牛的內(nèi)容都是我干的扮匠。 我是一名探鬼主播,決...
    沈念sama閱讀 38,340評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼凡涩,長吁一口氣:“原來是場噩夢啊……” “哼棒搜!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起活箕,我...
    開封第一講書人閱讀 36,973評論 0 259
  • 序言:老撾萬榮一對情侶失蹤力麸,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后育韩,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體克蚂,經(jīng)...
    沈念sama閱讀 43,466評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 35,937評論 2 323
  • 正文 我和宋清朗相戀三年筋讨,在試婚紗的時候發(fā)現(xiàn)自己被綠了埃叭。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,039評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡悉罕,死狀恐怖赤屋,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情蛮粮,我是刑警寧澤益缎,帶...
    沈念sama閱讀 33,701評論 4 323
  • 正文 年R本政府宣布,位于F島的核電站然想,受9級特大地震影響莺奔,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,254評論 3 307
  • 文/蒙蒙 一令哟、第九天 我趴在偏房一處隱蔽的房頂上張望恼琼。 院中可真熱鬧,春花似錦屏富、人聲如沸晴竞。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,259評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽噩死。三九已至,卻和暖如春神年,著一層夾襖步出監(jiān)牢的瞬間已维,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評論 1 262
  • 我被黑心中介騙來泰國打工已日, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留垛耳,地道東北人。 一個月前我還...
    沈念sama閱讀 45,497評論 2 354
  • 正文 我出身青樓飘千,卻偏偏與公主長得像堂鲜,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子护奈,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 42,786評論 2 345

推薦閱讀更多精彩內(nèi)容