<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ComputerMedic (dotOrg) Web Servers &#187; iptables</title>
	<atom:link href="http://www.computermedic.org/?feed=rss2&#038;tag=iptables" rel="self" type="application/rss+xml" />
	<link>http://www.computermedic.org</link>
	<description>MLD Computers &#124; Computer Medic &#124; beagle host</description>
	<lastBuildDate>Fri, 22 Jul 2016 20:26:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.35</generator>
	<item>
		<title>Serious fail2ban!</title>
		<link>http://www.computermedic.org/?p=116</link>
		<comments>http://www.computermedic.org/?p=116#comments</comments>
		<pubDate>Tue, 13 Aug 2013 17:20:56 +0000</pubDate>
		<dc:creator><![CDATA[computermedicorg]]></dc:creator>
				<category><![CDATA[Networks]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Status]]></category>
		<category><![CDATA[already banned]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[conf]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[ddos]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[named]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[network security]]></category>
		<category><![CDATA[rate]]></category>
		<category><![CDATA[rate limit]]></category>
		<category><![CDATA[rsyslog]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[syslog]]></category>
		<category><![CDATA[system administration]]></category>
		<category><![CDATA[zombie]]></category>

		<guid isPermaLink="false">http://www.computermedic.org/?p=116</guid>
		<description><![CDATA[It reminds me of a level of Serious Sam &#8211; the one where 1,000s of those headless bomb-toting zombie-soldiers and screamers came pouring at you relentlessly, seemingly to infinity (and beyond). It was a backdraft. Or the eye of the Zombie-Nado-Cane. When the bad-bots got some air around August 5th &#8211; hak4umz.net DDoS or DNS Amplification [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-117" alt="Serious Sam Box Art" src="http://www.computermedic.org/wp-content/uploads/2013/08/SeriousSamBoxArt.jpg" width="300" height="339" />It reminds me of a level of <a title="Croteam - Serious Sam Games" href="http://croteam.com/" target="_blank">Serious Sam</a> &#8211; the one where 1,000s of those headless bomb-toting zombie-soldiers and screamers came pouring at you relentlessly, seemingly to infinity (and beyond).</p>
<p>It was a <a title="Backdraft Post" href="http://www.computermedic.org/?p=107">backdraft</a>. Or the eye of the Zombie-Nado-Cane. When the bad-bots got some air around August 5th &#8211; hak4umz.net DDoS or DNS Amplification &#8211; fail2ban (and the servers) got burned.</p>
<p>Even the &#8220;eye-dee-keff-kuh-may&#8221; (TammyBelle&#8217;s God Mode Code for DOOM][ ) cheat didn&#8217;t help.  fail2ban got clobbered&#8230; &#8216;already banned&#8217; every one second in the log and no more bans happening because 100s or 1000s of times per second from 100s or thousands of bots: bad requests.</p>
<p><span id="more-116"></span></p>
<p>Here is the <em><strong>Serious!</strong></em> problem when you put the fail2ban -vs- the entire globe death match together:</p>
<pre>2013-08-13 12:40:37,730 fail2ban.actions: INFO   [named-flood] &lt;ip&gt; already banned
2013-08-13 12:40:38,732 fail2ban.actions: INFO   [named-flood] &lt;ip&gt; already banned</pre>
<p>almost exactly one second apart, hundreds of times, and no new banning going on.<br />
Q: Why?<br />
A: fail2ban appears to have a &#8220;one second pulse/parse&#8221; clock built in to it.</p>
<p>Q: So?<br />
A: So, when 4,000 log entries appear in a log that fail2ban is reading within that one second, fail2ban &#8216;queues&#8217; (or spools or fifo&#8217;s) those 4,000 entries into an internal list and tries to de-queue them one-per-second.</p>
<p>Easier math: (&#8220;let&#8217;s say&#8221;) there are 10 &#8216;fail regex&#8217; entries pouring into your log per second. Trying to de-queue the messages from the first second takes fail2ban 9 seconds.  By the time it gets done, there are 90 more messages/fails waiting.  So every second that goes by (in this low number scenario) the problem gets 10-to-the-10th-power worse.  The problem being fail2ban over-run by those headless bomb-toting zombies.  The &#8220;real world&#8221; explanation: fail2ban lags out and becomes combat ineffective.  In cop-talk the radio call from Officer fail2ban would be: &#8220;Extended&#8221;</p>
<p>Now, a &#8220;server admin&#8221; must consider &#8211; besides &#8216;shutdown -h now&#8217; &#8211; is there a solution to the problem? First part of that: what &#8211; <em>exactly</em> &#8211; is the problem.  More Q/A (logic/reasoning):<br />
Q: Problem?<br />
A: fail2ban says &#8216;already banned&#8217; and is &#8216;lagged out'; can&#8217;t fight the good fight.</p>
<p>Q: Why?<br />
A: Too many log entries per second.  fail2ban reads logs and &#8216;actions&#8217; based on log entries.</p>
<p>Q: So, why don&#8217;t you server admins just limit the number of log entries? (Instead of trying to hyper-tune fail2ban, just give it less to do? Remember the old-old server used to say &#8216;&#8230;the previous message repeated ### times&#8230;&#8217;)<br />
A: Why didn&#8217;t I think of that.</p>
<p>The old-old server was a Gentoo box dragged across the millennium boundary by makes and make-installs.  It finally wore out (it still runs, it was just retired because it had done it&#8217;s duty) this year.  A little searching about &#8216;the previous message repeated&#8217; and was reminded that <em>that</em> is called: rate-limit-ing.  A modern Centos-6-x86_64 install (not a bunch of custom compiled stuff on a 32-bit Gentoo) uses an &#8216;out of the box&#8217; rsyslog and doesn&#8217;t say things like &#8216;&#8230;the previous message&#8230;&#8217;  The new stuff says:<br />
imuxsock begins to drop messages from pid 1228 due to rate-limiting</p>
<p>Very little more searching finds:<br />
<a href="http://www.rsyslog.com/tag/rate-limiting/">http://www.rsyslog.com/tag/rate-limiting/</a></p>
<p>The docs are a &#8216;little dated&#8217; (2010) but the essentials are there to solve the problem (problem being &#8216;too many log entries for poor old fail2ban&#8217;).</p>
<p><strong>vim /etc/rsyslog.conf</strong> (and add as the 2nd and 3rd uncommented lines):</p>
<pre>#### 8.12.13 - try to slow the message floods so fail2ban won't die so much ####
$SystemLogRateLimitInterval 1
$SystemLogRateLimitBurst 5</pre>
<p>[Esc]:wq (write and quit)</p>
<p>Now do a <strong>/etc/init.d/rsyslog restart</strong> or <strong>service rsyslog restart</strong> (<em>reload</em> does not work, I tried it) and&#8230;</p>
<p>Tah-dah!  fail2ban can keep up with the log.  Some of the abusers (firey screaming zombies with tater-bombs) get by for a few seconds until the rate-limit/fail2ban get Serious!; but, real-world they were getting by by the hundres-of-thousands before this fix (while poor old fail2ban was over-run or lag-back-buffered).</p>
<p>It may not be &#8216;iddqd&#8217; (god/degreelessness mode in &#8216;that other great fps&#8217;), but $SystemLogRateLimitInterval/$SystemLogRateLimitBurst is very close to TammyBelle&#8217;s &#8220;eye-dee-keff-kuh-may&#8221; (megaarmor, weapons and keys) for fail2ban.</p>
<p>Almost as good as Tangy-Bells for break-shishst.<br />
Very happy, ammo added.</p>
<p>*** A minor success/victory ***<br />
49 hours later&#8230; fail2ban chugging along ban/unban-ing, much smaller log files, no other services lagged out because of the packet attacks on port 53&#8230;.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.computermedic.org/?feed=rss2&#038;p=116</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Killin&#8217; Zombie Bots DNS Style</title>
		<link>http://www.computermedic.org/?p=62</link>
		<comments>http://www.computermedic.org/?p=62#comments</comments>
		<pubDate>Fri, 28 Jun 2013 12:27:50 +0000</pubDate>
		<dc:creator><![CDATA[computermedicorg]]></dc:creator>
				<category><![CDATA[Networks]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[ddos]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[named]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[network security]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[system administration]]></category>
		<category><![CDATA[zombie]]></category>

		<guid isPermaLink="false">http://www.computermedic.org/?p=62</guid>
		<description><![CDATA[The fun post title is the only thing fun about this. Unless you are in hosting, server admin, or run your own DNS servers this is going to be complicated, technical and boring. First [is first ~LK]: an apology to any &#8220;upstream&#8221; DNS servers that our pet zombie bots may have passed bad requests to.  Like [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>The fun post title is the only thing fun about this. Unless you are in hosting, server admin, or run your own DNS servers this is going to be complicated, technical and boring.</p>
<p><strong>First</strong> [is first ~LK]: an apology to any &#8220;upstream&#8221; DNS servers that our pet zombie bots may have passed bad requests to.  Like us, you probably didn&#8217;t know it was happening.</p>
<blockquote><p>&#8220;What&#8217;s happening?!&#8221;<br />
~ Dana (Dominique Dunne, <a title="Poltergeist at imdb.com" href="http://www.imdb.com/title/tt0084516/" target="_blank">Poltergeist</a>, 1982)</p></blockquote>
<p><del>Thousands Hundreds of thousands Millions</del> Hundreds of millions of bad DNS requests.<br />
<span id="more-62"></span></p>
<p>Let me start at the beginning.  All &#8220;new&#8221; servers at MLD (computermedic.org) &#8211; <a title="New-ish gear" href="http://www.computermedic.org/?p=9" target="_blank">weblogger here</a>.</p>
<p>Checking on things (scanning logs) on the new equipment to see how it was doing: a new message in /var/log/messages: named[1584]: clients-per-query decreased to 61 (as low as the 20s). Never heard of it (the old servers had bind/named logging disabled).  A little search finds: <strong># rndc querylog </strong>(turn on logging for bind).</p>
<p><strong># tail -f /var/log/messages</strong><br />
Boom.  Screens scrolling by too fast to see what&#8217;s going on.<br />
Jun 27 06:55:58 nineseven named[1584]: client 183.178.216.210#12673: query: 1rip IN A + (70.63.178.157)<br />
Jun 27 07:29:28 nineseven named[1584]: client 213.128.75.196#41712: query: 1rip.com IN ANY +E (70.63.178.157)<br />
&#8230;and a bunch of query: DDoS.asia (how inconspicuous)</p>
<p>The immediate problems (why these goofy old internet attacks work):<br />
1. Nobody watch-dogs their name servers (if they &#8211; or we &#8211; did, we would have known this was happening).  By default, bind/named do not log.  Most people running a name server are running secondary to a web, email or app server; it&#8217;s just part of the setup and quickly forgotten.<br />
2. Name Servers (mostly) pass queries &#8220;upstream&#8221; when they do not have an answer themselves. This is the big deal: Bot-&gt;to-&gt;ns1.computermedic.org &#8220;what is the ip address of 1rip?&#8221; ns1 does not know, tries to be overly helpful and &#8220;I&#8217;ll find out and get back to you&#8221; asks an upstream server &#8220;can you tell me the address of 1rip so I can tell bot?&#8221;; Well, what if upstream server doesn&#8217;t have an answer?  This continues (upstream processing / passing of queries) until either a timeout occurs or some server gives an answer &#8211; even if the answer is: 1rip doesn&#8217;t have any DNS, thank you.<br />
3. #2 thousands of times per second.  The only &#8216;symptom&#8217; on a new/modern server with a new/modern OS: <em>clients-per-query decreased</em></p>
<p>#4: How do &#8216;we&#8217; know #1 is true &#8211; we didn&#8217;t catch this for all these years &#8211; and our upstreams have never called or sent email to say &#8220;did you know that your servers are bombing ours with upstream queries?&#8221;  We are unwitting zombies in the zombie-internet-apocalypse.</p>
<p>The decided upon solution: Stop this madness. Call the internet police and have them write a ticket and issue a &#8220;strongest terms&#8221; warning to all of the other did-not-know-they-were-zombies-zombies.  They can just slap the old bracelets on those rogue bots, they need to be jailed anyway.</p>
<p>There is no such thing as internet police &#8211; call the server admins, work out what you can do with the tools that you have.  Solution: fail2ban, iptables firewall, spoof zones.</p>
<p>The problems with the solution (.plan): fail2ban, iptables, and bind (real zones, let alone spoofs) are extremely complicated to setup and use; and, equally frustrating in their levels of &#8220;should work, but doesn&#8217;t work.&#8221;  The &#8216;another&#8217; problem(s) with the solution (.plan): we use a &#8220;web interface server manager&#8221; that wants to control everything about the server and is prone to overwriting changes you make directly to the machine. The server manager has its own firewall rules and implements them using iptables.  That is &#8220;sort of&#8221; good, because iptables is already up and running and known to be working.</p>
<p style="text-align: center;"><strong>.plan in action part 1 &#8211; fail2ban</strong></p>
<p> See who, what, where, why and how about fail2ban here: <a title="fail2ban" href="http://www.fail2ban.org" target="_blank">http://www.fail2ban.org</a></p>
<p>Then search with your favorite flavor of search engine about fail2ban howto, and those evil-incarnate regexs (regex-&gt;py(thon) style-&gt;fail2ban interpreted). Then come back here for the step-by-step.</p>
<p>Our test this .plan server: 2-Core Intel processor (old), CentOS x86_64 6-point-something, bind and fail2ban installed with yum.  Will the steps work with your (other than CentOS 6 basically OOB)? Probably not, every OS distributor likes to move files around or change some trivial word (directories, folders, libraries?) to make their OS &#8220;better&#8221;.  The &#8216;paths&#8217; and &#8216;stuff&#8217; below are for our server, they &#8220;should be&#8221; nearly the same on yours.</p>
<p>First [is FIRST, Lilly Kate says], make sure bind/named are logging.  We turned it on &#8220;by hand&#8221; and have not yet configured the .conf ( /etc/named.conf or /etc/named.conf.local ) to do the logging on boot.</p>
<p><strong># rndc querylog </strong></p>
<p>Now, <strong>tail -f /var/log/messages</strong> and make sure you start to see some [named] entries.</p>
<p>If you do not see any bad guy messages or floods, stop, don&#8217;t sweat it, check your logs next month.</p>
<p>The first-worst zombie-bot-flood was/is queries for: 1rip.com<br />
After 2 hours of logging: #grep -c &#8216;1rip&#8217; /var/log/messages<br />
100025</p>
<p>Now, once you start to try to figure out fail2ban you&#8217;re going to find about a-million weblogger (moron) pages that tell you: RTFM.  The Linux nerds love that, translated from nix-nerd to English RTFM means &#8220;I don&#8217;t know either but I like writing that on boards and web pages.&#8221;</p>
<p>Here&#8217;s TFM for this particular problem and this particular fail2ban .plan (of course, with the particular setup/OS mentioned previously):</p>
<p><strong># vim /etc/fail2ban/filter.d/named-flood.conf</strong><br />
<em>(new file&#8230; press insert to get into insert mode)</em><br />
[Definition]<br />
failregex = .* named\[.*\]: client &lt;HOST&gt;\#.*: query: 1rip.com IN *<br />
ignoreregex =<br />
:wq</p>
<p>I spent better than 2 hours testing, trying, RTFM-ing, playing with, etc. that failregex and fail2ban-regex (their testing tool). If your log lines look any-at-all different than ours did (scroll way up) then this regex won&#8217;t work for you &#8211; you have to tweak it and test it.  Copy a few lines from your log to a file ( if you don&#8217;t know how to do that, you really should not be messing with servers and firewalls ); make sure you have some &#8216;good&#8217; DNS responses in the file.<br />
<strong># vim /tmp/testfail2regex.txt</strong> (new file, insert/paste some lines, :wq).<br />
<strong># fail2ban-regex /tmp/testfail2regex.txt /etc/fail2ban/filter.d/named-flood.conf</strong></p>
<p>OK, I&#8217;ll assume if you are still reading your test said: some number of hits / matches.</p>
<p><em>( add the following at the bottom of the file )<br />
( edit 7.1.13 &#8211; use the example at the bottom of this page )</em><br />
<strong># vim /etc/fail2ban/jail.conf</strong><br />
[named-flood]<br />
enabled = true<br />
filter = named-flood<br />
logpath = /var/log/messages<br />
action = iptables-allports[name=dnsflood]<br />
bantime = 600 ; start with 10 mins<br />
findtime = 1<br />
maxretry = 1<br />
( :wq to write and quit )</p>
<p>Do <strong>NOT</strong> miss or skip this step, fail2ban&#8217;s default iptables rules default to tcp &#8211; DNS is udp and if you don&#8217;t fix the action file fail2ban bans all tcp, DNS flood will continue.</p>
<p><strong># vim /etc/fail2ban/action.d/iptables-allports</strong><br />
#protocol = tcp (this # is not the nix command prompt, it&#8217;s a comment)<br />
protocol = all<br />
( :wq to write and quit )</p>
<p><strong># /etc/init.d/fail2ban restart</strong></p>
<p>That&#8217;s (almost) it. You should start seeing ( tail -f /var/log/fail2ban.log ) bans and unbans.</p>
<p>Why the 10-minute ( <strong>bantime = 600</strong> ) wall?  Why not forever, or a month? Because, reminder: our servers were sending these requests to upstream DNS resolvers for years.  We never got locked/blocked from anywhere.  Ten minutes is a &#8220;good/fair start&#8221; &#8211; hopefully if these are requests from real servers (not all zombie bots) they&#8217;ll end up fixed.  And, another &#8220;to remember&#8221; is that if <em>my</em> &#8220;upstream providers&#8221; ban <em>me</em> forever, on all ports, how am I going to get legitimate DNS requests resolved?  It&#8217;s a very complex problem/solution scenario (in the real world).</p>
<p>The last step of part 1 (fail2ban) is to fix a mis-configuration &#8220;out of the box&#8221; with fail2ban&#8217;s own logs.  The &#8220;default&#8221; conf (configuration file) has logging set to /var/log/fail2ban.log.  That&#8217;s AOK with us.  The default /etc/logrotate.d/fail2ban (installed by/with fail2ban) has a line that tells fail2ban to use SYSLOG (/var/log/messages) after rotation.  Don&#8217;t want that so:</p>
<p><strong># vim /etc/logrotate.d/fail2ban</strong><br />
(change the size from 30k to a bigger/better number &#8211; don&#8217;t want 100s of fail2ban-date.log files)<br />
size 500k<br />
(<del>delete [dd] these two lines</del> 6.29.13: correction-change the postrotate command)<br />
postrotate<br />
/usr/local/bin/fail2ban-client set logtarget /var/log/fail2ban.log 2&gt;/dev/null || true<br />
( :wq )</p>
<p><em>( edit 7.1.13 &#8211; use the example at the bottom of the page )</em><br />
Your finished <strong>/etc/logrotate.d/fail2ban</strong> file should be:<br />
/var/log/fail2ban.log {<br />
missingok<br />
notifempty<br />
size 500k<br />
create 0600 root root<br />
postrotate<br />
/usr/local/bin/fail2ban-client set logtarget /var/log/fail2ban.log 2&gt;/dev/null || true<br />
endscript<br />
}</p>
<p>&nbsp;</p>
<p style="text-align: center;"><strong>.plan part 2: spoofed zone &#8211; stop sending upstream</strong></p>
<p>The only &#8220;hitch&#8221; with the fail2ban solution (using fail2ban for anything) is that it is an &#8220;earn our dis-trust&#8221; practice.  Meaning: you let anyone and everyone in until they do something (accidentally or not) that gets them thrown out.  Running internet servers is a lot like running a bar &#8211; just more drunks.</p>
<p>At our &#8220;digital Cheers&#8221; we run a clicky-easy administration program.  Clicky-add a DNS Zone.  Here, again, problems.  Clicky-easy does spell checking and IP validation and all kinds of neat &#8220;don&#8217;t let someone make server-death mistakes&#8221; because they think clicking a mouse makes them an RTFM-posting Certified Server AdMInIsTraTOR.  If we write our own zone files or mod the .conf files of bind/named &#8211; Clicky-easy will overwrite our &#8220;mastery&#8221; the next time we make changes.</p>
<p>So.  Work around our own watch dogs.</p>
<p>Why, again?  Because we want our servers to answer the zombie-bots or &#8220;downstream&#8221; requests ( for 1rip.com in particular ) with &#8220;I know the answer to that!!!&#8221; (but it&#8217;s a CIA dis-information campaign) rather than becoming an in-stream zombie ourselves.  Let me try to rephrase that:<br />
Zombie-Bot asks us: 1rip.com?<br />
Right now, since fail2ban is up and only suffers a few seconds lag time:<br />
we (named) finds no local &#8216;zone file&#8217; (&#8220;I dunno&#8221;) so passes those few 1rip.com?s upstream.<br />
Right now, what &#8220;we&#8221; want to happen:<br />
we (named) finds a local &#8216;zone file&#8217; and answer the bad-zombie-bot (or less-informed-down-stream):<br />
1rip.com? I know them &#8211; look deep inside your self Clarisse! ( spoof the reply, 1rip.com = 127.0.0.1 )</p>
<p>So. Work around our own watch dogs: Clicky-easy will not let you enter (lo, loopback, localhost, 127.0.0.1) or any other &#8220;bad&#8221; stuff into a zone file.  Reformulate the .plan, write it out in advance (WTFM so you can RTFM), try it on a non-production server, then go at it, fast, because you&#8217;re messing with a production server now.</p>
<p>Take down the named, you don&#8217;t want to give &#8216;good answers&#8217; to those &#8216;bad requests&#8217;.<br />
<strong># /etc/init.d/named stop</strong></p>
<p>Clicky-Easy-Server-Admin-&gt;<br />
Add a Zone (Wizard), all real information to pass &#8216;muster&#8217; (spell check and validation)<br />
Save Zone, logout of Clicky-Easy, exit Clicky-Easy<br />
Wait for it&#8230; there it is&#8230;<br />
/var/named/1rip.com.zone<br />
*** <em>not the real file name, don&#8217;t want to give away too much</em></p>
<p><strong># vim /var/named/1rip.com.zone</strong> (use your real file name)<br />
$TTL        3600<br />
@       IN      SOA     ns1.1rip.com. null.1rip.com. (<br />
2013062706       ; serial, todays date + todays serial #<br />
7200              ; refresh, seconds<br />
540              ; retry, seconds<br />
604800              ; expire, seconds<br />
86400 )            ; minimum, seconds<br />
;<br />
1rip.com. 3600 A        127.0.0.1<br />
1rip.com. 3600      NS        ns1.1rip.com.<br />
ns1 3600 A        127.0.0.1<br />
( :wq to write and quit )</p>
<p><strong># /etc/init.d/named start</strong></p>
<p>Using a very different clicky-easy Data-Base admin program, go into the db for clicky-easy-server-admin and change/remove it&#8217;s version of the &#8216;bad zone&#8217; data.<br />
Note to self: <strong>DO NOT</strong> use clicky-easy to open/view/edit/save Spoofed-Zone Domains/DNS.</p>
<p style="text-align: center;"><strong>******** postrotate ********</strong></p>
<p> 6.28.13: The .plan in .effect is working.  Instead of ~100,000 1rips per hour (2 ns servers) it has fallen off to about ~100/hour at the primary.  Yes, there&#8217;s a lot of bloated log files (so what, 3TB drives are in the US$100 range right now); yes, there is some cpu overhead to fail2ban (0.0,0.1,0.0 last check); yes, the 10 minute kick is probably not enough (90 % of the bans in the fail2ban.log happen one second after that zombie-bot-ip was Unban-ed) &#8211; but, hay, 10% went away forever in one day.</p>
<p>The &#8220;way up side&#8221;: absolutely no more &#8220;passed upstream requests&#8221; for 1rip from us to our upstreams.  No more &#8220;our side&#8221; delays waiting for responses or timeouts from upstream.  Last night clients-per-query reduced to 99.</p>
<p>The &#8216;couple of other things&#8217; that need to be done (or could be), jail a couple more of the offensive requests (no need to spoof dns for DDoS.asia &#8211; only about 1000 attempts in the last 24 hours).</p>
<p>The simple-est solution is to copy/paste/edit the fail2ban rule file:<br />
<strong># vim /etc/fail2ban/filter.d/named-flood.conf</strong><br />
<em>(yy to yank the failregex line, p to paste a copy, change the badguy name)<br />
</em> [Definition]<br />
failregex = .* named\[.*\]: client &lt;HOST&gt;\#.*: query: <strong>1rip.com</strong> IN *<br />
.* named\[.*\]: client &lt;HOST&gt;\#.*: query: <strong>DDoS.asia</strong> IN *<br />
ignoreregex =<br />
:wq</p>
<p><strong># /etc/init.d/fail2ban restart</strong> -or- <strong># fail2ban-client restart</strong></p>
<p>There are ways to ignore case and macro-expand the regex&#8217;s &#8211; (?this|that) &#8211; not too vastly interested in it.  There are really not that many different variations coming in right now (absolutely zero ddos.asia; all DDoS.asia) [ grep -c &#8216;DDoS.asia&#8217; /var/log/messages = 1070 and grep -i -c &#8216;DDoS.asia&#8217; /var/log/messages = 1070 ].  If you want to &#8220;get all fancy&#8221; then see fail2bans apache-badbots.conf file.</p>
<p>&#8211; &#8211; &#8211; &#8211; &#8211; 6.28.13 Late Update &#8211; &#8211; &#8211; &#8211; &#8211;</p>
<p>A 2nd one appears today (been in the logs a couple of (hundred thousand) times): isc.org</p>
<p>Found: <a href="http://my.opera.com/jlouisbiz/blog/2013/05/14/blocking-amplified-dns-attack-by-the-ip-address-and-using-linux-firewall-softwar" target="_blank">http://my.opera.com/jlouisbiz/blog/2013/05/14/blocking-amplified-dns-attack-by-the-ip-address-and-using-linux-firewall-softwar</a></p>
<p><strong># vim /etc/fail2ban/filter.d/named-flood.conf<br />
</strong> <em>(yy to yank the failregex line, p to paste a copy, change the badguy name)<br />
</em> [Definition]<br />
failregex = .* named\[.*\]: client &lt;HOST&gt;\#.*: query: <strong>1rip.com</strong> IN *<br />
.* named\[.*\]: client &lt;HOST&gt;\#.*: query: <strong>DDoS.asia</strong> IN *<br />
.* named\[.*\]: client &lt;HOST&gt;\#.*: query: <strong>isc.org</strong> IN *<br />
ignoreregex =<br />
:wq</p>
<p><strong># /etc/init.d/fail2ban restart</strong> -or- <strong># fail2ban-client restart</strong></p>
<p>Stretched the ban time out to 20 minutes.</p>
<p>July 1, 2013: Some notes about how this has continued:<br />
&#8211; it has only gotten worse (another post coming)<br />
&#8211; had &#8216;timing&#8217; issues with fail2ban (blahblah already banned 1000s of times)<br />
&#8211; stretched the jail time out to 2 hours (sorry infected-good-guys id&#8217;d as zombie-bad-guys)<br />
&#8211; got errors trying to use apache-bad-bots style &#8216;expansion&#8217; so ended up with:</p>
<p>/etc/fail2ban/jail.conf</p>
<pre><span style="color: #666666; font-family: Consolas;"># DLW 6.27.13 - should use .local file? in a hurry to stop flood attack, sync/ddos
[named-flood]
enabled = true
filter  = named-flood
logpath = /var/log/messages
action  = iptables-allports[name=dnsflood]
bantime = 7200  ; start with 10 mins, bumped to 20, bumped to 2 hours 6.30
findtime = 2
maxretry = 1
</span></pre>
<p>The findtime of &#8220;2&#8221; stopped fail2ban from tripping over its own feet (stuck in an &#8220;&#8230;already banned&#8221; loop).</p>
<p>/etc/fail2ban/filter.d/named-flood.conf</p>
<pre>[Definition]
failregex = .* named\[.*\]: client &lt;HOST&gt;\#.*: query: (1rip\.com|isc\.org) IN *
ignoreregex =</pre>
<p>B-b-b-buh-but wait, there&#8217;s more! fail2ban&#8217;s default install and documentation have another &#8216;glitch':<br />
the logs don&#8217;t postrotate because <em>they</em> put the wrong path to the right file in <em>their</em> script.</p>
<pre><span style="color: #666666; font-family: Consolas;">[root@servername~]# /usr/local/bin/fail2ban-client set logtarget /var/log/fail2ban.log
-bash: /usr/local/bin/fail2ban-client: No such file or directory
[root@servername~]# /usr/bin/fail2ban-client set logtarget /var/log/fail2ban.log
Current logging target is:
`- /var/log/fail2ban.log
[root@servername ~]# tail -f /var/log/fail2ban.log
2013-07-01 23:19:28,262 fail2ban.server : INFO
------------&gt;   Changed logging target to /var/log/fail2ban.log for Fail2ban v0.8.8</span></pre>
<p>Notice the absence of /local/ in the path.  One more tidbit fixed.<br />
<strong>/etc/logrotate.d/fail2ban</strong></p>
<pre><span style="color: #666666; font-family: Consolas;">/var/log/fail2ban.log {
    missingok
    notifempty
    size 500k
    create 0600 root root
    postrotate
      /usr/bin/fail2ban-client set logtarget /var/log/fail2ban.log 2&gt;/dev/null || true
    endscript
}</span></pre>
<p>/etc/logrotate.conf <em>has the defaults for rotate and other settings</em></p>
<p>!!! Note: isc.org is a real deal &#8211; not some left over bad-bot junk.  They make bind (DNS Name Server) and all kinds of good stuff so that we can have these internets without typing IP addresses for everything.  Because they are &#8216;real&#8217; (unlike 1rip.com) we did not attempt to &#8216;spoof&#8217; their zone &#8211; the floods were amazing, now were passing up a few 1000 &#8216;snuck by fail2ban&#8217; requests.  But, sorry bad-zombie-bots &#8211; we don&#8217;t server your kind here (aka we don&#8217;t run a free-for-all DNS server, you zombies will have to flood someone else).</p>
<p>There is still another post coming about this madness, but it&#8217;s a different wopper all together.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.computermedic.org/?feed=rss2&#038;p=62</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
