[{"data":1,"prerenderedAt":1182},["ShallowReactive",2],{"article-20210915-fail2ban-apache-dos":3},{"article":4,"surround":1171},{"id":5,"title":6,"authorKey":7,"body":8,"codeLinks":1131,"createdAt":1135,"description":1136,"excerpt":1137,"extension":1157,"image":1158,"meta":1159,"navigation":320,"path":1160,"published":1161,"readingTime":218,"revisedAt":1162,"seo":1163,"stem":1164,"tags":1165,"__hash__":1170},"articles\u002Farticles\u002F20210915-fail2ban-apache-dos.md","Fail2ban jail to mitigate DoS attacks against Apache","philip",{"type":9,"value":10,"toc":1125},"minimark",[11,42,49,52,70,75,78,92,103,145,166,170,177,261,305,435,451,455,461,657,663,764,768,771,839,842,1041,1048,1118,1121],[12,13,14,15,22,23,28,29,33,34,37,38,41],"p",{},"Recently, one of our shared hosting webservers at ",[16,17,21],"a",{"href":18,"rel":19},"https:\u002F\u002Fwww.onlime.ch\u002F",[20],"nofollow","Onlime GmbH"," got hit by a DoS attack. The attacker started a larger vulnerability scan against common Wordpress security issues. We already had common brute-force attack patterns on Wordpress covered by a custom ",[16,24,27],{"href":25,"rel":26},"https:\u002F\u002Fwww.fail2ban.org",[20],"Fail2Ban"," jail, which mainly trapped ",[30,31,32],"code",{},"POST"," requests to ",[30,35,36],{},"xmlrpc.php"," or ",[30,39,40],{},"wp-login.php"," (the usual dumb WP brute-force attacks...). But this DoS attack had hundreds of customer sites as target and did not get trapped by our existing rules.",[12,43,44,45,48],{},"After having blocked the attacker's IP (glad this was no large-scale DDoS!), I wrote an extra Fail2Ban jail which traps such simple DoS attacks. It's a very basic Fail2Ban jail that should cover common attacks and should not cause any false positives as it is only getting triggered by a large amount of failed ",[30,46,47],{},"GET"," requests.",[12,50,51],{},"There are other good articles about setting up such Fail2Ban jails to block simple DoS, but they didn't quite fit our needs:",[53,54,55,63],"ul",{},[56,57,58],"li",{},[16,59,62],{"href":60,"rel":61},"https:\u002F\u002Fsamnicholls.net\u002F2016\u002F06\u002F06\u002Ffail2ban-apache-dos\u002F",[20],"Using fail2ban to mitigate simple DOS attacks against apache (or why I am a terrible sysop)",[56,64,65],{},[16,66,69],{"href":67,"rel":68},"https:\u002F\u002Fwww.garron.me\u002Fen\u002Fgo2linux\u002Ffail2ban-protect-web-server-http-dos-attack.html",[20],"Install fail2ban to protect your site from DOS attacks",[71,72,74],"h2",{"id":73},"requirements","Requirements",[12,76,77],{},"What we would like to accomplish:",[53,79,80,83,89],{},[56,81,82],{},"Scanning of all Apache access logs",[56,84,85,86,88],{},"Ban the attackers IP if there are more than 300 ",[30,87,47],{}," requests during a time span of 5 mins resulting in HTTP non-200 (OK) status codes: 401, 403, 404, 503",[56,90,91],{},"Ban the attacker for 1 hour",[12,93,94,95,98,99,102],{},"We're going to scan all customer Apache ",[30,96,97],{},"access.log"," logfiles which are in a slightly tuned (non-standard) ",[30,100,101],{},"combined"," log format:",[104,105,110],"pre",{"className":106,"code":107,"language":108,"meta":109,"style":109},"language-apache shiki shiki-themes github-light-default github-light-default github-dark-default","#LogFormat \"%h %l %u %t \\\"%r\\\" %>s %O \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\"\" combined\nLogFormat \"%h %l %u %t %I %O \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\" %V %p\" combined\n","apache","",[30,111,112,121],{"__ignoreMap":109},[113,114,117],"span",{"class":115,"line":116},"line",1,[113,118,120],{"class":119},"s9BHP","#LogFormat \"%h %l %u %t \\\"%r\\\" %>s %O \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\"\" combined\n",[113,122,124,128,132,136,139,142],{"class":115,"line":123},2,[113,125,127],{"class":126},"s5nWI","LogFormat",[113,129,131],{"class":130},"s_bOF"," \"%h %l %u %t %I %O \\\"%r\\\" %>s %b \\\"%{",[113,133,135],{"class":134},"sQJ0q","Referer",[113,137,138],{"class":130},"}i\\\" \\\"%{",[113,140,141],{"class":134},"User-Agent",[113,143,144],{"class":130},"}i\\\" %V %p\" combined\n",[12,146,147,148,151,152,37,155,158,159,165],{},"Below ",[30,149,150],{},"failregex"," also works for default ",[30,153,154],{},"extended\u002Fcombined",[30,156,157],{},"common"," Apache ",[16,160,163],{"href":161,"rel":162},"https:\u002F\u002Fhttpd.apache.org\u002Fdocs\u002F2.4\u002Fmod\u002Fmod_log_config.html#logformat",[20],[30,164,127],{},".",[71,167,169],{"id":168},"setup-fail2ban-jail","Setup Fail2Ban jail",[12,171,172,173,176],{},"Let's call the new Fail2Ban jail ",[30,174,175],{},"apache-get-dos"," and create the following two files:",[104,178,183],{"className":179,"code":180,"filename":181,"language":182,"meta":109,"style":109},"language-ini shiki shiki-themes github-light-default github-light-default github-dark-default","[apache-get-dos]\nenabled  = true\nport     = http,https\nfilter   = apache-get-dos\nlogpath  = \u002Fvar\u002Fwww\u002F*\u002Flogs\u002Faccess.log\ndatepattern = %%d\u002F%%b\u002F%%Y:%%H:%%M:%%S %%z\nmaxretry = 300\nfindtime = 5m\nbantime  = 1h\n","jail.d\u002Fapache-get-dos.conf","ini",[30,184,185,190,198,207,216,225,234,243,252],{"__ignoreMap":109},[113,186,187],{"class":115,"line":116},[113,188,189],{"class":134},"[apache-get-dos]\n",[113,191,192,195],{"class":115,"line":123},[113,193,194],{"class":126},"enabled",[113,196,197],{"class":130},"  = true\n",[113,199,201,204],{"class":115,"line":200},3,[113,202,203],{"class":126},"port",[113,205,206],{"class":130},"     = http,https\n",[113,208,210,213],{"class":115,"line":209},4,[113,211,212],{"class":126},"filter",[113,214,215],{"class":130},"   = apache-get-dos\n",[113,217,219,222],{"class":115,"line":218},5,[113,220,221],{"class":126},"logpath",[113,223,224],{"class":130},"  = \u002Fvar\u002Fwww\u002F*\u002Flogs\u002Faccess.log\n",[113,226,228,231],{"class":115,"line":227},6,[113,229,230],{"class":126},"datepattern",[113,232,233],{"class":130}," = %%d\u002F%%b\u002F%%Y:%%H:%%M:%%S %%z\n",[113,235,237,240],{"class":115,"line":236},7,[113,238,239],{"class":126},"maxretry",[113,241,242],{"class":130}," = 300\n",[113,244,246,249],{"class":115,"line":245},8,[113,247,248],{"class":126},"findtime",[113,250,251],{"class":130}," = 5m\n",[113,253,255,258],{"class":115,"line":254},9,[113,256,257],{"class":126},"bantime",[113,259,260],{"class":130},"  = 1h\n",[262,263,264,275],"blockquote",{},[12,265,266,267,270,271,274],{},"In above jail, we didn't specify a ",[30,268,269],{},"banaction",", as we're using the global default. You might want to put the following in ",[30,272,273],{},"jail.d\u002Fcustom.conf",":",[104,276,278],{"className":179,"code":277,"filename":273,"language":182,"meta":109,"style":109},"[DEFAULT]\nbantime  = 300\nfindtime = 300\nbanaction = iptables-allports\n",[30,279,280,285,292,298],{"__ignoreMap":109},[113,281,282],{"class":115,"line":116},[113,283,284],{"class":134},"[DEFAULT]\n",[113,286,287,289],{"class":115,"line":123},[113,288,257],{"class":126},[113,290,291],{"class":130},"  = 300\n",[113,293,294,296],{"class":115,"line":200},[113,295,248],{"class":126},[113,297,242],{"class":130},[113,299,300,302],{"class":115,"line":209},[113,301,269],{"class":126},[113,303,304],{"class":130}," = iptables-allports\n",[104,306,309],{"className":179,"code":307,"filename":308,"language":182,"meta":109,"style":109},"# Fail2Ban filter to scan Apache access.log for DoS attacks\n\n[INCLUDES]\nbefore = common.conf\n\n[Definition]\n# Option:  failregex\n# Notes.:  regex to match GET requests in the logfile resulting in one of the\n#          following status codes: 401, 403, 404, 503.\n#          The host must be matched by a group named \"host\". The tag \"\u003CHOST>\" \n#          can be used for standard IP\u002Fhostname matching and is only an alias for\n#          (?:::f{4,6}:)?(?P\u003Chost>[\\w\\-.^_]+)\n# Values:  TEXT\nfailregex = ^\u003CHOST> .*\"GET (?!\\\u002Frobots\\.txt).*\" (401|403|404|503)\\s\n\n# Option:  ignoreregex\n# Notes.:  regex to ignore. If this regex matches, the line is ignored.\n# Values:  TEXT\n#\nignoreregex =\n","filter.d\u002Fapache-get-dos.conf",[30,310,311,316,322,327,335,339,344,349,354,359,365,371,377,383,398,403,409,415,420,426],{"__ignoreMap":109},[113,312,313],{"class":115,"line":116},[113,314,315],{"class":119},"# Fail2Ban filter to scan Apache access.log for DoS attacks\n",[113,317,318],{"class":115,"line":123},[113,319,321],{"emptyLinePlaceholder":320},true,"\n",[113,323,324],{"class":115,"line":200},[113,325,326],{"class":134},"[INCLUDES]\n",[113,328,329,332],{"class":115,"line":209},[113,330,331],{"class":126},"before",[113,333,334],{"class":130}," = common.conf\n",[113,336,337],{"class":115,"line":218},[113,338,321],{"emptyLinePlaceholder":320},[113,340,341],{"class":115,"line":227},[113,342,343],{"class":134},"[Definition]\n",[113,345,346],{"class":115,"line":236},[113,347,348],{"class":119},"# Option:  failregex\n",[113,350,351],{"class":115,"line":245},[113,352,353],{"class":119},"# Notes.:  regex to match GET requests in the logfile resulting in one of the\n",[113,355,356],{"class":115,"line":254},[113,357,358],{"class":119},"#          following status codes: 401, 403, 404, 503.\n",[113,360,362],{"class":115,"line":361},10,[113,363,364],{"class":119},"#          The host must be matched by a group named \"host\". The tag \"\u003CHOST>\" \n",[113,366,368],{"class":115,"line":367},11,[113,369,370],{"class":119},"#          can be used for standard IP\u002Fhostname matching and is only an alias for\n",[113,372,374],{"class":115,"line":373},12,[113,375,376],{"class":119},"#          (?:::f{4,6}:)?(?P\u003Chost>[\\w\\-.^_]+)\n",[113,378,380],{"class":115,"line":379},13,[113,381,382],{"class":119},"# Values:  TEXT\n",[113,384,386,388,391,395],{"class":115,"line":385},14,[113,387,150],{"class":126},[113,389,390],{"class":130}," = ^\u003CHOST> .*",[113,392,394],{"class":393},"s-BGO","\"GET (?!\\\u002Frobots\\.txt).*\"",[113,396,397],{"class":130}," (401|403|404|503)\\s\n",[113,399,401],{"class":115,"line":400},15,[113,402,321],{"emptyLinePlaceholder":320},[113,404,406],{"class":115,"line":405},16,[113,407,408],{"class":119},"# Option:  ignoreregex\n",[113,410,412],{"class":115,"line":411},17,[113,413,414],{"class":119},"# Notes.:  regex to ignore. If this regex matches, the line is ignored.\n",[113,416,418],{"class":115,"line":417},18,[113,419,382],{"class":119},[113,421,423],{"class":115,"line":422},19,[113,424,425],{"class":119},"#\n",[113,427,429,432],{"class":115,"line":428},20,[113,430,431],{"class":126},"ignoreregex",[113,433,434],{"class":130}," =\n",[12,436,437,438,440,441,446,447,450],{},"You might want to tune the ",[30,439,150],{}," to your needs. For our use case, I have created a ",[16,442,445],{"href":443,"rel":444},"https:\u002F\u002Fregex101.com\u002Fr\u002FF1Z9VO\u002F1",[20],"regex101"," with some sample log lines which you can play around with. It will ignore any failing ",[30,448,449],{},"GET \u002Frobots.txt"," requests (as most bots request this) and it will not care about \"sane\" HTTP status codes like 200 (OK), 301 (Moved Permanently), 302 (Found). So, please be aware, that this jail only protects you from some kind of DoS attack that targets a large amount of non-existing URLs\u002Fpathes, which is mostly the case for malicious vulnerability scans.",[71,452,454],{"id":453},"monitoring-jail","Monitoring jail",[12,456,457,458,460],{},"After having restarted Fail2Ban, you might want to monitor the new ",[30,459,175],{}," jail:",[104,462,466],{"className":463,"code":464,"language":465,"meta":109,"style":109},"language-bash shiki shiki-themes github-light-default github-light-default github-dark-default","# list status of apache-get-dos jail with monitored Apache logs\n$ fail2ban-client status apache-get-dos\nStatus for the jail: apache-get-dos\n|- Filter\n|  |- Currently failed: 80\n|  |- Total failed: 290517\n|  `- File list:    \u002Fvar\u002Fwww\u002F\u003Cuser>\u002Flogs\u002Faccess.log ...\n`- Actions\n   |- Currently banned: 0\n   |- Total banned: 5\n   `- Banned IP list:   \n\n# review banning in fail2ban.log\n$ grep -Pi 'apache-get-dos\\] (un)?ban' \u002Fvar\u002Flog\u002Ffail2ban.log\n2021-09-14 17:45:47,285 fail2ban.actions        [107006]: NOTICE  [apache-get-dos] Ban 1.2.3.4\n2021-09-14 18:45:45,503 fail2ban.actions        [107006]: NOTICE  [apache-get-dos] Unban 1.2.3.4\n","bash",[30,467,468,473,487,502,513,532,548,572,582,597,610,620,624,629,642,650],{"__ignoreMap":109},[113,469,470],{"class":115,"line":116},[113,471,472],{"class":119},"# list status of apache-get-dos jail with monitored Apache logs\n",[113,474,475,478,481,484],{"class":115,"line":123},[113,476,477],{"class":134},"$",[113,479,480],{"class":393}," fail2ban-client",[113,482,483],{"class":393}," status",[113,485,486],{"class":393}," apache-get-dos\n",[113,488,489,492,495,498,500],{"class":115,"line":200},[113,490,491],{"class":134},"Status",[113,493,494],{"class":393}," for",[113,496,497],{"class":393}," the",[113,499,460],{"class":393},[113,501,486],{"class":393},[113,503,504,507,510],{"class":115,"line":209},[113,505,506],{"class":126},"|",[113,508,509],{"class":134},"-",[113,511,512],{"class":393}," Filter\n",[113,514,515,517,520,522,525,528],{"class":115,"line":218},[113,516,506],{"class":126},[113,518,519],{"class":126},"  |",[113,521,509],{"class":134},[113,523,524],{"class":393}," Currently",[113,526,527],{"class":393}," failed:",[113,529,531],{"class":530},"sDkKp"," 80\n",[113,533,534,536,538,540,543,545],{"class":115,"line":227},[113,535,506],{"class":126},[113,537,519],{"class":126},[113,539,509],{"class":134},[113,541,542],{"class":393}," Total",[113,544,527],{"class":393},[113,546,547],{"class":530}," 290517\n",[113,549,550,552,555,557,560,563,566,569],{"class":115,"line":236},[113,551,506],{"class":126},[113,553,554],{"class":393},"  `",[113,556,509],{"class":134},[113,558,559],{"class":393}," File list:    \u002Fvar\u002Fwww\u002F",[113,561,562],{"class":126},"\u003C",[113,564,565],{"class":393},"user",[113,567,568],{"class":126},">",[113,570,571],{"class":393},"\u002Flogs\u002Faccess.log ...\n",[113,573,574,577,579],{"class":115,"line":245},[113,575,576],{"class":393},"`",[113,578,509],{"class":134},[113,580,581],{"class":393}," Actions\n",[113,583,584,587,589,591,594],{"class":115,"line":254},[113,585,586],{"class":126},"   |",[113,588,509],{"class":134},[113,590,524],{"class":393},[113,592,593],{"class":393}," banned:",[113,595,596],{"class":530}," 0\n",[113,598,599,601,603,605,607],{"class":115,"line":361},[113,600,586],{"class":126},[113,602,509],{"class":134},[113,604,542],{"class":393},[113,606,593],{"class":393},[113,608,609],{"class":530}," 5\n",[113,611,612,615,617],{"class":115,"line":367},[113,613,614],{"class":393},"   `",[113,616,509],{"class":134},[113,618,619],{"class":393}," Banned IP list:   \n",[113,621,622],{"class":115,"line":373},[113,623,321],{"emptyLinePlaceholder":320},[113,625,626],{"class":115,"line":379},[113,627,628],{"class":119},"# review banning in fail2ban.log\n",[113,630,631,633,636,639],{"class":115,"line":385},[113,632,477],{"class":134},[113,634,635],{"class":393}," grep ",[113,637,638],{"class":530},"-Pi",[113,640,641],{"class":393}," 'apache-get-dos\\] (un)?ban' \u002Fvar\u002Flog\u002Ffail2ban.log\n",[113,643,644,647],{"class":115,"line":400},[113,645,646],{"class":134},"2021-09-14",[113,648,649],{"class":393}," 17:45:47,285 fail2ban.actions        [107006]: NOTICE  [apache-get-dos] Ban 1.2.3.4\n",[113,651,652,654],{"class":115,"line":405},[113,653,646],{"class":134},[113,655,656],{"class":393}," 18:45:45,503 fail2ban.actions        [107006]: NOTICE  [apache-get-dos] Unban 1.2.3.4\n",[12,658,659,660,662],{},"In case you have designed your ",[30,661,150],{}," too aggressively and have banned too many IPs, remember those commands:",[104,664,666],{"className":463,"code":665,"language":465,"meta":109,"style":109},"# unban an IP from a specific jail\n$ fail2ban-client set \u003CJAIL> unbanip \u003CIP>\n\n# unban an IP (or several) from all jails\n$ fail2ban-client unban \u003CIP> ... \u003CIP>\n\n# unbans all IP addresses (in all jails and database)\n$ fail2ban-client unban --all\n",[30,667,668,673,707,711,716,744,748,753],{"__ignoreMap":109},[113,669,670],{"class":115,"line":116},[113,671,672],{"class":119},"# unban an IP from a specific jail\n",[113,674,675,677,679,682,685,688,691,693,696,698,701,704],{"class":115,"line":123},[113,676,477],{"class":134},[113,678,480],{"class":393},[113,680,681],{"class":393}," set",[113,683,684],{"class":126}," \u003C",[113,686,687],{"class":393},"JAI",[113,689,690],{"class":130},"L",[113,692,568],{"class":126},[113,694,695],{"class":393}," unbanip",[113,697,684],{"class":126},[113,699,700],{"class":393},"I",[113,702,703],{"class":130},"P",[113,705,706],{"class":126},">\n",[113,708,709],{"class":115,"line":200},[113,710,321],{"emptyLinePlaceholder":320},[113,712,713],{"class":115,"line":209},[113,714,715],{"class":119},"# unban an IP (or several) from all jails\n",[113,717,718,720,722,725,727,729,731,733,736,738,740,742],{"class":115,"line":218},[113,719,477],{"class":134},[113,721,480],{"class":393},[113,723,724],{"class":393}," unban",[113,726,684],{"class":126},[113,728,700],{"class":393},[113,730,703],{"class":130},[113,732,568],{"class":126},[113,734,735],{"class":393}," ...",[113,737,684],{"class":126},[113,739,700],{"class":393},[113,741,703],{"class":130},[113,743,706],{"class":126},[113,745,746],{"class":115,"line":227},[113,747,321],{"emptyLinePlaceholder":320},[113,749,750],{"class":115,"line":236},[113,751,752],{"class":119},"# unbans all IP addresses (in all jails and database)\n",[113,754,755,757,759,761],{"class":115,"line":245},[113,756,477],{"class":134},[113,758,480],{"class":393},[113,760,724],{"class":393},[113,762,763],{"class":530}," --all\n",[71,765,767],{"id":766},"bonus-commands","Bonus Commands",[12,769,770],{},"I'll provide you with some bonus commands to further investigate such DoS attacks:",[104,772,774],{"className":463,"code":773,"language":465,"meta":109,"style":109},"# Top 20 list of IPs with a large amount of connections to the server\n$ netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head -n20\n",[30,775,776,781],{"__ignoreMap":109},[113,777,778],{"class":115,"line":116},[113,779,780],{"class":119},"# Top 20 list of IPs with a large amount of connections to the server\n",[113,782,783,785,788,791,794,797,800,802,805,808,811,813,816,818,821,824,826,828,831,833,836],{"class":115,"line":123},[113,784,477],{"class":134},[113,786,787],{"class":393}," netstat",[113,789,790],{"class":530}," -ntu",[113,792,793],{"class":126}," |",[113,795,796],{"class":134}," awk",[113,798,799],{"class":393}," '{print $5}'",[113,801,793],{"class":126},[113,803,804],{"class":134}," cut",[113,806,807],{"class":530}," -d:",[113,809,810],{"class":530}," -f1",[113,812,793],{"class":126},[113,814,815],{"class":134}," sort",[113,817,793],{"class":126},[113,819,820],{"class":134}," uniq",[113,822,823],{"class":530}," -c",[113,825,793],{"class":126},[113,827,815],{"class":134},[113,829,830],{"class":530}," -nr",[113,832,793],{"class":126},[113,834,835],{"class":134}," head",[113,837,838],{"class":530}," -n20\n",[12,840,841],{},"You may also want to scan all Apache access logs for the IPs with most requests:",[104,843,845],{"className":463,"code":844,"language":465,"meta":109,"style":109},"# Top 10 IP list for ALL sites for previous hour\n$ grep -h \"\\[$(date -d -1hour +'%d\u002F%b\u002F%Y:%H:')\" \u002Fvar\u002Fwww\u002F*\u002Flogs\u002Faccess.log | cut -d' ' -f1 | sort | uniq -c | sort -nr | head -n10\n\n# Top 10 IP list for ALL sites for current hour\n$ grep -h \"\\[$(date +'%d\u002F%b\u002F%Y:%H:')\" \u002Fvar\u002Fwww\u002F*\u002Flogs\u002Faccess.log | cut -d' ' -f1 | sort | uniq -c | sort -nr | head -n10\n \n# Top 10 IP list for ALL sites with filename\n$ grep \"\\[$(date +'%d\u002F%b\u002F%Y:%H:')\" \u002Fvar\u002Fwww\u002F*\u002Flogs\u002Faccess.log | cut -d' ' -f1 | sort | uniq -c | sort -nr | head -n10\n",[30,846,847,852,920,924,929,981,986,991],{"__ignoreMap":109},[113,848,849],{"class":115,"line":116},[113,850,851],{"class":119},"# Top 10 IP list for ALL sites for previous hour\n",[113,853,854,856,859,862,865,868,871,874,877,880,883,886,888,890,892,895,897,899,901,903,905,907,909,911,913,915,917],{"class":115,"line":123},[113,855,477],{"class":134},[113,857,858],{"class":393}," grep",[113,860,861],{"class":530}," -h",[113,863,864],{"class":393}," \"\\[$(",[113,866,867],{"class":134},"date",[113,869,870],{"class":530}," -d",[113,872,873],{"class":530}," -1hour",[113,875,876],{"class":393}," +'%d\u002F%b\u002F%Y:%H:')\"",[113,878,879],{"class":393}," \u002Fvar\u002Fwww\u002F",[113,881,882],{"class":530},"*",[113,884,885],{"class":393},"\u002Flogs\u002Faccess.log",[113,887,793],{"class":126},[113,889,804],{"class":134},[113,891,870],{"class":530},[113,893,894],{"class":393},"' '",[113,896,810],{"class":530},[113,898,793],{"class":126},[113,900,815],{"class":134},[113,902,793],{"class":126},[113,904,820],{"class":134},[113,906,823],{"class":530},[113,908,793],{"class":126},[113,910,815],{"class":134},[113,912,830],{"class":530},[113,914,793],{"class":126},[113,916,835],{"class":134},[113,918,919],{"class":530}," -n10\n",[113,921,922],{"class":115,"line":200},[113,923,321],{"emptyLinePlaceholder":320},[113,925,926],{"class":115,"line":209},[113,927,928],{"class":119},"# Top 10 IP list for ALL sites for current hour\n",[113,930,931,933,935,937,939,941,943,945,947,949,951,953,955,957,959,961,963,965,967,969,971,973,975,977,979],{"class":115,"line":218},[113,932,477],{"class":134},[113,934,858],{"class":393},[113,936,861],{"class":530},[113,938,864],{"class":393},[113,940,867],{"class":134},[113,942,876],{"class":393},[113,944,879],{"class":393},[113,946,882],{"class":530},[113,948,885],{"class":393},[113,950,793],{"class":126},[113,952,804],{"class":134},[113,954,870],{"class":530},[113,956,894],{"class":393},[113,958,810],{"class":530},[113,960,793],{"class":126},[113,962,815],{"class":134},[113,964,793],{"class":126},[113,966,820],{"class":134},[113,968,823],{"class":530},[113,970,793],{"class":126},[113,972,815],{"class":134},[113,974,830],{"class":530},[113,976,793],{"class":126},[113,978,835],{"class":134},[113,980,919],{"class":530},[113,982,983],{"class":115,"line":227},[113,984,985],{"class":130}," \n",[113,987,988],{"class":115,"line":236},[113,989,990],{"class":119},"# Top 10 IP list for ALL sites with filename\n",[113,992,993,995,997,999,1001,1003,1005,1007,1009,1011,1013,1015,1017,1019,1021,1023,1025,1027,1029,1031,1033,1035,1037,1039],{"class":115,"line":245},[113,994,477],{"class":134},[113,996,858],{"class":393},[113,998,864],{"class":393},[113,1000,867],{"class":134},[113,1002,876],{"class":393},[113,1004,879],{"class":393},[113,1006,882],{"class":530},[113,1008,885],{"class":393},[113,1010,793],{"class":126},[113,1012,804],{"class":134},[113,1014,870],{"class":530},[113,1016,894],{"class":393},[113,1018,810],{"class":530},[113,1020,793],{"class":126},[113,1022,815],{"class":134},[113,1024,793],{"class":126},[113,1026,820],{"class":134},[113,1028,823],{"class":530},[113,1030,793],{"class":126},[113,1032,815],{"class":134},[113,1034,830],{"class":530},[113,1036,793],{"class":126},[113,1038,835],{"class":134},[113,1040,919],{"class":530},[12,1042,1043,1044,1047],{},"I recommend you block such IPs directly on your front-end firewall. But in case you can't, use ",[30,1045,1046],{},"iptables"," to quickly block a single IP:",[104,1049,1051],{"className":463,"code":1050,"language":465,"meta":109,"style":109},"# Block a single IP\n$ iptables -A INPUT -s \u003CIP> -j DROP\n# Unblock it\n$ iptables -D INPUT -s \u003CIP> -j DROP\n",[30,1052,1053,1058,1088,1093],{"__ignoreMap":109},[113,1054,1055],{"class":115,"line":116},[113,1056,1057],{"class":119},"# Block a single IP\n",[113,1059,1060,1062,1065,1068,1071,1074,1076,1078,1080,1082,1085],{"class":115,"line":123},[113,1061,477],{"class":134},[113,1063,1064],{"class":393}," iptables",[113,1066,1067],{"class":530}," -A",[113,1069,1070],{"class":393}," INPUT",[113,1072,1073],{"class":530}," -s",[113,1075,684],{"class":126},[113,1077,700],{"class":393},[113,1079,703],{"class":130},[113,1081,568],{"class":126},[113,1083,1084],{"class":530}," -j",[113,1086,1087],{"class":393}," DROP\n",[113,1089,1090],{"class":115,"line":200},[113,1091,1092],{"class":119},"# Unblock it\n",[113,1094,1095,1097,1099,1102,1104,1106,1108,1110,1112,1114,1116],{"class":115,"line":209},[113,1096,477],{"class":134},[113,1098,1064],{"class":393},[113,1100,1101],{"class":530}," -D",[113,1103,1070],{"class":393},[113,1105,1073],{"class":530},[113,1107,684],{"class":126},[113,1109,700],{"class":393},[113,1111,703],{"class":130},[113,1113,568],{"class":126},[113,1115,1084],{"class":530},[113,1117,1087],{"class":393},[12,1119,1120],{},"And now, cross fingers you won't get hit by a brutal DDoS. I plan to cover DDoS attack mitigation in a future article.",[1122,1123,1124],"style",{},"html pre.shiki code .s9BHP, html code.shiki .s9BHP{--shiki-light:#6E7781;--shiki-default:#6E7781;--shiki-dark:#8B949E}html pre.shiki code .s5nWI, html code.shiki .s5nWI{--shiki-light:#CF222E;--shiki-default:#CF222E;--shiki-dark:#FF7B72}html pre.shiki code .s_bOF, html code.shiki .s_bOF{--shiki-light:#1F2328;--shiki-default:#1F2328;--shiki-dark:#E6EDF3}html pre.shiki code .sQJ0q, html code.shiki .sQJ0q{--shiki-light:#953800;--shiki-default:#953800;--shiki-dark:#FFA657}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s-BGO, html code.shiki .s-BGO{--shiki-light:#0A3069;--shiki-default:#0A3069;--shiki-dark:#A5D6FF}html pre.shiki code .sDkKp, html code.shiki .sDkKp{--shiki-light:#0550AE;--shiki-default:#0550AE;--shiki-dark:#79C0FF}",{"title":109,"searchDepth":123,"depth":200,"links":1126},[1127,1128,1129,1130],{"id":73,"depth":123,"text":74},{"id":168,"depth":123,"text":169},{"id":453,"depth":123,"text":454},{"id":766,"depth":123,"text":767},[1132],{"link":1133,"desc":1134},"https:\u002F\u002Fgist.github.com\u002Fonlime\u002Ff5108c23e9f4dfbb88fba2c9386cd219","Gist","2021-09-15","Using a Fail2ban jail to mitigate simple DoS attacks against Apache.",{"type":9,"value":1138},[1139,1153],[12,1140,14,1141,22,1144,28,1147,33,1149,37,1151,41],{},[16,1142,21],{"href":18,"rel":1143},[20],[16,1145,27],{"href":25,"rel":1146},[20],[30,1148,32],{},[30,1150,36],{},[30,1152,40],{},[12,1154,44,1155,48],{},[30,1156,47],{},"md","\u002Fimages\u002Fcovers\u002Ffail2ban-apache-dos.jpg",{},"\u002Farticles\u002F20210915-fail2ban-apache-dos",false,null,{"title":6,"description":1136},"articles\u002F20210915-fail2ban-apache-dos",[1166,1167,1168,1169],"sysadmin","linux","security","fail2ban","gXZQeuM3cOEZIDgGn29SJfXz8UrR61KJozdu3lI3B8g",[1172,1177],{"title":1173,"path":1174,"stem":1175,"createdAt":1176,"children":-1},"GitLab PostgreSQL Data Recovery","\u002Farticles\u002F20210901-gitlab-postgresql-recovery","articles\u002F20210901-gitlab-postgresql-recovery","2021-09-01",{"title":1178,"path":1179,"stem":1180,"createdAt":1181,"children":-1},"Log emails as *.eml in Laravel Mailer","\u002Farticles\u002F20211203-laravel-mailer-log-eml","articles\u002F20211203-laravel-mailer-log-eml","2021-12-03",1794817240032]