<?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; Security</title>
	<atom:link href="http://www.computermedic.org/?cat=19&#038;feed=rss2" 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>Windows Ten Remote Desktop Notes</title>
		<link>http://www.computermedic.org/?p=239</link>
		<comments>http://www.computermedic.org/?p=239#comments</comments>
		<pubDate>Sun, 16 Aug 2015 04:40:18 +0000</pubDate>
		<dc:creator><![CDATA[computermedicorg]]></dc:creator>
				<category><![CDATA[Networks]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Windows Computers]]></category>
		<category><![CDATA[10]]></category>
		<category><![CDATA[desktop]]></category>
		<category><![CDATA[RDC]]></category>
		<category><![CDATA[RDP]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[ten]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[x]]></category>

		<guid isPermaLink="false">http://www.computermedic.org/?p=239</guid>
		<description><![CDATA[In a test environment we came up with an odd behavior between Remote Desktop Client Apps/Programs and Windows X.  All of the boring details after a short version of what happened and how we fixed it. What happened: clients could not connect.  It would start to, prompt for credentials, show the welcome screen, then a [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>In a test environment we came up with an odd behavior between Remote Desktop Client Apps/Programs and Windows X.  All of the boring details after a short version of what happened and how we fixed it.</p>
<p><span id="more-239"></span>What happened: clients could not connect.  It would start to, prompt for credentials, show the welcome screen, then a disconnect with a message:</p>
<blockquote><p>Your Remote Desktop session has ended.</p>
<p>Another user connected to the remote computer, so your connection was lost. Try connecting again, or contact your network administrator or technical support group.</p></blockquote>
<p>The only way around it was to physically &#8220;Sign out&#8221; at the hardware.</p>
<p><a href="http://www.computermedic.org/wp-content/uploads/2015/08/2015_0815_WinX_RDP_1.jpg"><img class="aligncenter size-medium wp-image-240" src="http://www.computermedic.org/wp-content/uploads/2015/08/2015_0815_WinX_RDP_1-263x300.jpg" alt="2015_0815_WinX_RDP_1" width="263" height="300" /></a>The fix: add a password to the account (see the notes below) and enable the &#8220;Allow only&#8230;NLA&#8221; (picture) option in the remote desktop settings.</p>
<p style="text-align: center;"><strong>How this all happened&#8230;</strong></p>
<p>First: not a very well used Windows 8 &#8220;test&#8221; computer.  When we set it up originally we didn&#8217;t put a password on it.  We must have had some old Macs or XP boxes that we tried to connect RDP clients from, so had un-checked the &#8220;Allow connections only&#8230;&#8221; option in the Remote tab.</p>
<p>2nd: No &#8220;pre-release&#8221; Windows X stuff.  On July 29, 2015 we had to update this computer to 8.1 before upgrading to X.  The 8.1 and the X (Ten/10) installers did not mention exactly how important a password is to these newest systems.  A little online searching tells us that it&#8217;s not Microsoft&#8217;s fault, not too many people seem to have this exact series of mistakes/user errors.</p>
<p>Finally: we ended up with a Windows X (Pro) computer with RDC (the new name for RDP) enabled, old un-secure clients allowed, and no &#8220;only user&#8221; account password.</p>
<p style="text-align: center;"><strong>How this all got fixed&#8230;</strong></p>
<p>First: After reading too many online posts and pages about RDP (RDC) in general we saw &#8220;a couple&#8221; of mentions about that &#8220;Allow connections only&#8230;&#8221; checkbox.  Went to see what was up: un-checked.  Put a check-mark in there and tried again&#8230;</p>
<p>Second: Secure connections require minimally secure computers (user account needs a password).  When we tried to connect this time we got a &#8220;Cannot connect&#8221; error stating that &#8220;&#8230;the password is expired&#8230; &#8230;or&#8230;&#8221; (about 3 total possibilities that we didn&#8217;t screenshot).  We knew there was no password so it wasn&#8217;t &#8220;expired.&#8221;  Back to the hardware, set a password on the user account, Sign out, Sign in&#8230;</p>
<p>Finally:  Add the new password to the RDP (RDC) client connection dialogue and everything works fine.  RD Client connected, console user was Signed out.</p>
<p>This was a very &#8220;anomalous behavior incident&#8221; but if we could do it someone else probably could as well.  So, now it&#8217;s documented.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.computermedic.org/?feed=rss2&#038;p=239</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>That&#8217;s a fine server, Anthony, a fine, fine server!</title>
		<link>http://www.computermedic.org/?p=161</link>
		<comments>http://www.computermedic.org/?p=161#comments</comments>
		<pubDate>Sun, 06 Jul 2014 23:58:21 +0000</pubDate>
		<dc:creator><![CDATA[computermedicorg]]></dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Equipment]]></category>
		<category><![CDATA[Networks]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Status]]></category>

		<guid isPermaLink="false">http://www.computermedic.org/?p=161</guid>
		<description><![CDATA[July, 2014.  The internet is a secluded village, all controlled and terrorized by one boy&#8230; Meet Anthony, from the &#8216;It&#8217;s a Good Life&#8217; episode of The Twilight Zone (Nov. 1961).  Details over at imdb, or watch the whole episode (with modernized commercial/ad inserts) at hulu. We&#8217;ve hired Anthony, now in his 50s to do away [&#8230;]]]></description>
				<content:encoded><![CDATA[<div id="attachment_162" style="width: 210px" class="wp-caption alignright"><img class="wp-image-162 size-full" src="http://www.computermedic.org/wp-content/uploads/2014/07/tz_anthony_badman.jpg" alt="Twighlight Zone Good Life Anthony" width="200" height="161" /><p class="wp-caption-text">You&#8217;re a bad bot. I&#8217;m tired of playing with you. I&#8217;m going to make you dead now.</p></div>
<p>July, 2014.  The internet is a secluded village, all controlled and terrorized by one boy&#8230;</p>
<p>Meet Anthony, from the &#8216;It&#8217;s a Good Life&#8217; episode of The Twilight Zone (Nov. 1961).  Details over at <a title="TZ Ep 61 at IMDB" href="http://www.imdb.com/title/tt0734580/" target="_blank">imdb</a>, or watch the whole episode (with modernized commercial/ad inserts) at <a title="TZ Ep 61 at hulu" href="http://www.hulu.com/watch/440799" target="_blank">hulu</a>.</p>
<p>We&#8217;ve hired Anthony, now in his 50s to do away with spam, Zombie DNS DDoS Bots, and other such pests buzzing around and annoying or destroying everything and everyone in the internet play ground.  We should have thought of it earlier&#8230; Just <em>making bad things dead</em> or <em>wishing them into the cornfield</em>.</p>
<p>OK, not quite that easy, here&#8217;s what&#8217;s up in the fight against Spam-Nados and Zombie Bots&#8230;</p>
<p><span id="more-161"></span></p>
<p>[Thermal] Inversion Layers.  In the undersea world of submariners these separations between temperatures of water mask objects from sonar and/or, of course, thermal imaging.  What does that have to do with servers and DDoS attacks? Nothing.  Except the association is how we remember:</p>
<p>Inverse Tactics.  At some point around the Happy Holiday Season 2013-2014 (aka Christmas to normal people) a server manager woke from a horrible holiday dream &#8211; a dream of fail2ban memory leaks, dead sockets, out of memory errors and massive log files &#8211; with a vision of a less nightmarish future.  Simplicity was unmasked.  The fortune-cookie like note that comes from the bobble-head-devil fortune machine in that other episode of Twilight Zone:</p>
<p style="text-align: center;"><strong>Invert your tactics.</strong></p>
<p>Instead of trying to use fail2ban (perl/python/loosely interpreted regexs) to sift through everything and lock out the bad guys after they had been bad, and possibly then wrong because UDP sources are easily spoofed; use the &#8216;firewall&#8217; (compiled, close to the kernel, strict iptables) as a firewall.  Seems simple, use the firewall as the firewall. But that&#8217;s hind-sight.</p>
<p>So, simple, use the firewall, invert the tactics.  What does that mean?</p>
<p>It means: allow only certain things along the &#8216;port 53 chain&#8217; ~ only the domains that we truly are the authoritative host for.  And, since our little web-server is also a recursive-caching DNS server for itself and others; only do this filtration on the &#8216;net-facing&#8217; (public) adapter.  Confused? Good. Welcome to the Twilight Zone.</p>
<p>Inverted logic:<br />
&#8211; Old way: allow everything, find anything &#8216;known bad&#8217; and block that; ever growing list of &#8216;known bad&#8217; (because the bad-bot guys change what they query you to death with)<br />
&#8211; New way: allow only the domains we NS host to be allowed passed iptables to get to bind/named and furthermore to fail2ban; drop all other (not known good) DNS queries.  Yep; drop; no tarpit, no &#8216;channel[s] closed&#8217;, no loopback, no reply, no nothing, DEEeee-ROP. (Wish bad queries into the corn field.)</p>
<p>Simple. Smart. Effective.  Can&#8217;t find the notes to give credit to some very helpful websites/pages that helped us through this &#8220;seems simple (everything computer is supposed to be simple)&#8221; but was very, very complicated set of iptables rules. TODO for later: find the notes, give the credit.</p>
<p>Here&#8217;s the summary:<br />
&#8211; iptables does string matching (the * here is that iptables string matching on UDP sockets is very complicated, based on hex conversions of the strings, very strict, but very fast)<br />
&#8211; set up a new &#8216;table (chain)&#8217; and set of &#8216;RETURN&#8217; rules based on the domains we actually want to give answers to DNS queries for<br />
&#8211; set up the new &#8216;table (chain)&#8217; to default to DROP (not reject, not return) all others</p>
<p>Here&#8217;s the implementation, using the plain text matching of iptables instead of the complete domain.tld (the dots don&#8217;t translate so you have to use hex to match domain(special)tld):</p>
<pre>#!/bin/sh
#
# create the chain to drop everything we don't specifically know
if ! iptables -L netdnswash -n  &gt;/dev/null 2&gt;&amp;1 ; then
        #echo "debugging make the chain netdnswash"
        iptables -N netdnswash
fi
# flush it either way
iptables -F netdnswash
# default rule = DROP.  This is to stop trying to block badbots, only allow good stuff.
# This should also drop the '.' (single dot) query
iptables -A netdnswash -j DROP
### during build/testing return everything, watch the counters on the one-two test domains
### iptables -A netdnswash -j RETURN
# put the most common ones up top (e.g. computermedic.org since that's the name server, then down to the least busy)
# reverse order because inserts stack on top
iptables -I netdnswash -i eth1 -p udp -m udp --dport 53 -m string --algo bm --icase --to 255 --string 'mldragon' -m comment --comment "mldragon.com" -j RETURN
iptables -I netdnswash -i eth1 -p udp -m udp --dport 53 -m string --algo bm --icase --to 255 --string 'computermedic' -m comment --comment "computermedic.org always first" -j RETURN
# make sure this is first in the INPUT chain - returns to INPUT will allow fail2ban to catch crap.gooddomain.tld
# make sure that fail2ban (actions) build their rules at/after 2. More manual thinking for fail2ban (admins) but way less work
# make sure it doesn't already exists
if ! iptables -L INPUT -n | grep 'netdnswash' -c 2&gt;&amp;1 ; then
        #echo "debugging make the rule in INPUT"
        iptables -I INPUT 1 -i eth1 -p udp -m udp --dport 53 -j netdnswash
fi

</pre>
<p>Note 1: all chain creation prior to adding it to the INPUT chain rules.<br />
Note 2: only traffic on the &#8216;net-facing/public&#8217; adapter goes through here (at the bottom, &#8230;eth1&#8230;)<br />
Note 3: used inserts ( -I ) so what you want first you have to put last in the script (invert again)<br />
Note 4: once fully tested and put into operation: iptables-save &gt;/path/to/conf_file so that if the server restart iptables doesn&#8217;t have to be &#8216;re-made&#8217;.<br />
Note 5: change the fail2ban jail create/destroy commands to insert at 2, so fail2ban can be restarted without messing up the new iptables stuff.</p>
<p>Now, important, the lack of the complete domain.tld business.  If we had hundreds or thousands of Ns in our NS we would go through the trouble to use &#8216;hex string matching&#8217; to get the whole computermedic.org thing in there.  But the &#8220;less than hundreds&#8221; number of domains on this server lets us deal with the occasional bad bot playing computermedic.tld [other than org] games.  How do we deal with that?</p>
<p>fail2ban of course.  Now, much relaxed and under-loaded because no more rolling/spoofed-source DNS/DDoS querries.  Again, don&#8217;t want to tell the bad-guys how to defeat our newly created defensive systems, but suffice it to say: if you run 3 or more ddosasia.computermedic.org or www999, www998, www997 (the rolling ones we encountered) queries against the server fail2ban is going to shut you down (1st time for 2 hours, 2nd time for&#8230; drumroll&#8230; Evuh!).  First the cornfield for a reasonable timeout, then fail2bAnthony makes you dead.</p>
<p><strong>Less Spammy Inboxes version 14.7 (year.month versioning because there have been way too many versions)</strong></p>
<div id="attachment_175" style="width: 310px" class="wp-caption alignleft"><img class="size-medium wp-image-175" src="http://www.computermedic.org/wp-content/uploads/2014/07/tz_anthony_badman2-300x225.jpg" alt="TZ Anthony 2" width="300" height="225" /><p class="wp-caption-text">I hate anybody that doesn&#8217;t like me!</p></div>
<p>Now that fail2bAnthony has less DNS problems on his hands, lots of free memory and CPU cycles, has not gone to swap in at least 3 months it&#8217;s time to put fail2bAnthony on task of wishing spambots into the cornfield, and those dreaded three-headed-gophers (the guess your password bots that then use your email to send spam everywhere &#8216;authenticated&#8217;): Dead.</p>
<p>fail2ban was already working the &#8216;mail servers logfiles&#8217; to identify bad auth attempts and ban bad guys there.  However! We utilize an &#8216;Anti-Spam Relay/Filter Server&#8217; (or several) and a great many of the bad auth attempts were going to those.  A couple of new fail2ban filters and actions, done.  Send legit email if you want copies of the fail2ban files, not publishing those (x-th time: don&#8217;t give the bad-guys a &#8216;how we defend ourselves&#8217; map).  We&#8217;ll suffice it to say in this regard: had to get a few users new passwords, but &#8216;rejects&#8217;, bad server reputation points, and dictionary/rolling login attempts, junk in the mailq, against all mail systems are significantly decreased.  Will be even more decreased as time goes by because after certain re-bans, ips and whole ranges are banned for 1 year (all ports).  Cornfield, cornfield, dead.</p>
<p>A little over a year ago we said &#8216;Finally&#8230;&#8217; ( <a title="New Server" href="http://www.computermedic.org/?p=9">http://www.computermedic.org/?p=9</a> ).  Doing all of this iptables, fail2ban, named (forgot to mention above, no more spoofed/loop-back entries in named conf files because no more bad domains/tlds allowed through), mail/spam server tuning revealed a major problem in the spam filter/relay setup: SenderBase did not install last year.  &#8216;Hypothetically speaking&#8217; we could pretend that we use a certain Anti-Spam SMTP Proxy ( <a title="ASSP Sourceforge" href="http://sourceforge.net/projects/assp/" target="_blank">ASSP</a> ) and we &#8216;hypothetically&#8217; used their install/update scripts to get the thing moving.  Well, in those 12-18 days of extreme server configs and installs and the months of Zombie-Bot and DDoS-Nado wars after, the one little message in a log file seldom read about Net::SenderBase not being available was missed. Then there is the fact that ASSP &#8216;hypothetically&#8217; does not log (even if debug level logging is selected) anything about SenderBase if it was not available at startup.  Where the problem lies: in some nix distros the install/update scripts, and the howto pages, that say use MCPAN to <strong>install Net::SenderBase</strong> don&#8217;t warn you to watch the output carefully to make sure there wasn&#8217;t any error[s].  Here&#8217;s the deal, and a warning: Watch the output of install Net::SenderBase carefully!!  If there are errors (any error means no SenderBase, no filters, regex matching, country matching, scoring, based on SenderBase in ASSP, and nothing to let you know): <strong>force install Net::SenderBase</strong>.</p>
<p>Bam. Done, had to go back an re-tweak/un-tweak about 12,000 ASSP (hypothetically) settings, logs, regex-es, etc., that had been tweaked trying to figure out why so much wasn&#8217;t working, gave ASSP a full stop (/etc/init.d/assp stop), let it rest a minute, fired it back up (replace stop with start) and wah-lah! 79% blocked instead of 45-51%.  Less spammy inboxes.</p>
<p><strong>Updated wordpress to 3.9.1 today.</strong><br />
Not important but it works *great* in IE11.  Makes links correctly, which it did not.  Looks a little better.  Good job wordpress.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.computermedic.org/?feed=rss2&#038;p=161</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Zombie Bot Back-Draft?</title>
		<link>http://www.computermedic.org/?p=107</link>
		<comments>http://www.computermedic.org/?p=107#comments</comments>
		<pubDate>Thu, 01 Aug 2013 06:22:35 +0000</pubDate>
		<dc:creator><![CDATA[computermedicorg]]></dc:creator>
				<category><![CDATA[Networks]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Status]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[ddos]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[zombie]]></category>

		<guid isPermaLink="false">http://www.computermedic.org/?p=107</guid>
		<description><![CDATA[Starting on about the 27th of July, sema.cz became the dns query flood from all around the world in huge numbers (@350,000 requests per hour; hundreds of sources). Suddenly, in sync with Aug 1 (00:00:00) rolling in around the globe (asia, Europe, etc): It stopped. All of the &#8216;watch words&#8217; we&#8217;ve been jamming in fail2ban [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Starting on about the 27th of July, sema.cz became the dns query flood from all around the world in huge numbers (@350,000 requests per hour; hundreds of sources).</p>
<p>Suddenly, in sync with Aug 1 (00:00:00) rolling in around the globe (asia, Europe, etc):<br />
<strong>It stopped.</strong></p>
<p><span id="more-107"></span></p>
<p>All of the &#8216;watch words&#8217; we&#8217;ve been jamming in fail2ban vanished.  By 00:00:00 Eastern US: 1 ip in the 2 hour block box.  At 12:00:00 (pm) July 31: 1000+.</p>
<p>Whatever time-bomb went off and killed all the zombie bots &#8211; hoozah.</p>
<p>There is something very creepy about it, though.</p>
<p>When (in the zombie apocalypse wars) you get a &#8216;tides have gone out&#8217; moment: fortify defenses.</p>
<p>Updated fail2ban from 8.8 to 8.10.  Lots of features and fixes noted at their site &#8211; hope so, have had some trouble with fail2ban 8.8 and this recent assault.</p>
<p>In the last 2 weeks we have put some smarter rules in effect: empty zones with &#8216;deny&#8217; default in /etc/named.conf</p>
<pre>// sema.cz 7.29.13 - 7.30.13 100s
zone "sema.cz" {
        type master;
        allow-query { none; };
        allow-transfer { none; };
        file "named.empty";
};</pre>
<p>This, of course, adds some bloat to the logs ( /IN/ANY denied line ). But it doesn&#8217;t go upstream.</p>
<p>More later, if the DNS ddos returns, or if time permits.</p>
<p>******** 8.1.13 (later in the day) update *********</p>
<p>Still too quiet after 100s-of-millions of attempts over the last 2 months.</p>
<p>The couple that have appeared reveal that the updated fail2ban tries to be nicey-nice ( reject ) instead of dumping zombies into the pit of oblivion (drop).</p>
<p>The new fail2ban default is:<br />
blocktype = REJECT &#8211;reject-with icmp-port-unreachable</p>
<p>So, I am trying in the jail.conf file:</p>
<pre>action  = iptables-allports[name=dnsflood, blocktype=DROP]</pre>
<p>Took about 1 minute for the last of the zombie-hee-cans to get DROP-ped.  Something went right today.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.computermedic.org/?feed=rss2&#038;p=107</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ZombieBots Part 2 or&#8230;</title>
		<link>http://www.computermedic.org/?p=89</link>
		<comments>http://www.computermedic.org/?p=89#comments</comments>
		<pubDate>Sat, 13 Jul 2013 21:46:57 +0000</pubDate>
		<dc:creator><![CDATA[computermedicorg]]></dc:creator>
				<category><![CDATA[Equipment]]></category>
		<category><![CDATA[Networks]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Status]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[sharknado]]></category>
		<category><![CDATA[zombie]]></category>

		<guid isPermaLink="false">http://www.computermedic.org/?p=89</guid>
		<description><![CDATA[Sharknado!  Equally exciting, terrifying, low-budget and prone to sequels. So bad it&#8217;s good movie lovers, click the link above and see if you can survive that whirlwind of bites. Server admins, stay right here and get ready for DNS-Zombie-Bots Two: More Tech-Talk and .configs Than You Can Stand!  (Or, &#8220;Bored To Death!&#8221; Or, &#8220;You can have the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a title="SHARKNADO at the imdb" href="http://www.imdb.com/title/tt2724064/" target="_blank">Sharknado!</a> <img class="alignright size-full wp-image-92" alt="sharknado" src="http://www.computermedic.org/wp-content/uploads/2013/07/sharknado.jpg" width="175" height="116" /></p>
<p>Equally exciting, terrifying, low-budget and prone to sequels.</p>
<p><em>So bad it&#8217;s good</em> movie lovers, click the link above and see if you can survive that whirlwind of bites.</p>
<p>Server admins, stay right here and get ready for DNS-Zombie-Bots Two: More Tech-Talk and .configs Than You Can Stand!  (Or, &#8220;Bored To Death!&#8221; Or, &#8220;You can have the whole seat, but you only need the edge!&#8221;)<span id="more-89"></span></p>
<p>Or, I had to document it so I can take it from server to server without trusting my memory, so I thought I would share.</p>
<p>It started with a &#8216;Hay Bay-Bay&#8217; &#8211; or a &#8216;clients-per-query&#8217; message.</p>
<p>Lots of tweaks, tunes, service this restart, /etc/init.d/that restart later: &#8216;clients-per-query&#8217; (increased/decreased) messages, lots of them.  (Somehow, sync&#8217;d between servers, trying to figure that BIND9 magic out would be like trying to reach into the mouth of one of those sharknado sharks and pull its heart out.  It is because it is, do the fixes you can do and worry about enigmatic synchronicity later.)</p>
<p>Here&#8217;s the setup again so when you try these things on a server with a point-zero-zero-one version difference you&#8217;ll know why it doesn&#8217;t work:<br />
~ <a href="http://www.centos.org/" target="_blank">CentOS</a> x86_64 6.4 (Installed, updated [yum update] June, 2013)<br />
~ <a href="http://www.isc.org/downloads/bind/" target="_blank">bind / named</a><br />
* <em># rndc status</em>: version: 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.4<br />
* <em># yum list bind</em>: bind.x86_64 32:9.8.2-0.17.rc1.el6_4.4<br />
~ <a href="http://www.fail2ban.org" target="_blank">fail2ban</a><br />
* <em># yum list fail2ban</em>: fail2ban.noarch 0.8.8-3.el6 ( 0.8.10-1.el6 <em>available</em> )</p>
<p>Since last I wrote about it ( <a href="http://www.computermedic.org/?p=62" target="_blank">Killin Zombie Bots</a> ) some seemingly minor, but very important changes mainly to the bind/named and related conf files.<br />
<strong>/etc/resolv.conf: nameserver 127.0.0.1</strong><br />
~ all &#8216;in-server&#8217; services should ask &#8216;self&#8217; for DNS, when self doesn&#8217;t know it &#8220;recurses&#8221; (goes upstream) and caches so that for a time (cache TTLs and expirys) &#8216;self&#8217; does know the answer.<br />
<strong>/etc/named.conf</strong> (in the <em>options { }</em> block): <strong>querylog yes;</strong><br />
~ log at boot (that semi-colon &#8216;;&#8217; is very-necessary)<br />
<strong>/etc/fail2ban/jail.conf: ignoreip = 127.0.0.1/8</strong><br />
~ &#8216;confirmed&#8217; (it is the default in the [default] section) &#8211; <em>Self: don&#8217;t ban we</em>.</p>
<p style="text-align: center;"><strong><em>clients-per-query</em> groans the almost healed zombie server</strong></p>
<p>Ask the modern zombie-to-English interpreter ( <a href="http://www.google.com" target="_blank">google</a> ) what that means and the interpreter says:<br />
About 2,440,000 results  (0.33 seconds)</p>
<p>Go on an Injun vision quest and consult the shaman: <strong>add more RAM</strong>.</p>
<p>Don&#8217;t run down that 2.44-Million results rabbit hole.  Smack your head and think I should have thought of that when the light bulb turns on in there behind the sign that reads:</p>
<p>The cache of a caching DNS server on a moderate-to-heavy-load server can get quite large.</p>
<p>That&#8217;s RAM bay-bays, nothing else.  Don&#8217;t believe yourself, <strong># free</strong>. <em>@125MB of 2GB</em> left and look lower: <em>@105648[k] used Swap:</em>.  This is on the &#8216;dedicated&#8217; DNS server.  Pop-Nerd-Quiz: Going swap happens when?  Right, when &#8216;real memory&#8217; (RAM) is full.</p>
<p>Jump over to the we-have-it-no-matter-what-it-is-and-cheap shop of the new millennium ( <a href="http://www.ebay.com" target="_blank">eBay</a> ) and [Buy It Now] on 8GB of the wrong RAM for your server.  Smack your head again because everything is &#8216;the hard way&#8217; (like being the only seal in a Sharknado), put the wrong RAM up for sale and [Buy It Now-Now] on 8GB of hopefully the right RAM for your server.  When it shows up (it will be right this time!) hope that 8GBs is enough for a caching DNS server.</p>
<p>Summary: <strong>clients-per-query = add more RAM</strong>.</p>
<p>There is a nightmare-nado of other things you can try to tweak or tune or limit and shutdown -r now&#8230; or you can RAM-up and see all those Zombie-Language /var/log/ messages in your logs vanish.  If you are &#8216;flush with GB&#8217; and nothing in swap: <em>it&#8217;s 2.44 million curtains for you, tough guy (in 0.33 seconds)!</em></p>
<p style="text-align: center;"><strong>Z0mb13 t4Lk (or ID-10-T bot-writer cOdEs) and fail2ban</strong></p>
<p> 1rip, 1Rip, 1rIP, and so-on.  case-insensitive, or ignore-case. Sounds so easy.  So you try a little (?i) and a little \/\.IhateRegEx (interpreted through .py and other things depending on revision or build number) and pretty soon you are standing in the eye of a shark-icane with your <a href="http://www.imdb.com/title/tt0058331/" target="_blank">Mary Poppins </a>umbrella waiting for the winds to take you to a hopefully quick and not too painful shark-shutdown (in the air).</p>
<p>begin here (/etc/fail2ban/filter.d dir):<br />
[root@server filter.d]# cp named-flood.conf named-ignoretest.conf<br />
[root@server filter.d]# vim named-ignoretest.conf</p>
<p>It has now (sorry for the wordpress word-wrap):</p>
<pre>failregex = .* named\[.*\]: client &lt;HOST&gt;\#.*: query: (1rip\.com|isc\.org|\.) (IN|ANY) *</pre>
<p>Based on the only search result that made sense ( <a href="https://github.com/fail2ban/fail2ban/issues/48" target="_blank">https://github.com/fail2ban/fail2ban/issues/48</a> ) and ( <a href="http://www.tutorialspoint.com/python/python_reg_expressions.htm">http://www.tutorialspoint.com/python/python_reg_expressions.htm</a> ) [and about 100 trial-with-error failures] change it to:</p>
<pre> failregex = .* named\[.*\]: client &lt;HOST&gt;\#.*: query: ((?i)1rip|1rip\.com|isc\.org|\.) (IN|ANY) *</pre>
<p>The important thing here (besides this is not tested against any other versions): <strong>((?i)[pipe separated list])</strong>.  The &#8216;ignore-case&#8217; <strong>(?i)</strong> toggle is working on all of the entries in the <strong>[pipe separated list]</strong>.  Another thing: I didn&#8217;t test and don&#8217;t care if the case-insensitive compare carries over to the <strong>(IN|ANY)</strong>.</p>
<p>Because the only &#8216;spoof&#8217; in there is 1rip.com (now case does not matter) some of those isc.org queries are still getting answered, and the (space)1rip(space) [1rip without a domain extension] are still doing <em>something</em> (as yet unknown) to the cache and the upstream.  What is known about those is that they are now successfully triggering fail2ban to shut those servers/ips down after a couple of hits and send the rest of their millions of attempts to &gt;dev/null.</p>
<p>Doing packet/byte count watches ( <strong>#iptables -n -L -v &#8211;line-numbers</strong> ) reveals that once &#8216;dumped&#8217; into the &#8216;fail2ban filter table&#8217; the bad-zombie-bots (flooding w/requrests) are &#8216;dropping&#8217; many hundreds of thousands of requests (packets) and GBs of data per hour.</p>
<pre>2    3000K  864M fail2ban-dnsflood    all  -- *  *   0.0.0.0/0   0.0.0.0/0
3    1829K  792M fail2ban-maillogins  all  -- *  *   0.0.0.0/0   0.0.0.0/0</pre>
<p>&#8220;It&#8217;s only&#8221; 72MB (@10% by bytes), but fully 39% of all packet-traffic being killed by this fail2ban zombie-net &#8211; <em>on this one particular server</em>.  Not sure how to &#8216;math it out&#8217; but it is also a server-unload because that many (1171K = 1.2-Million) queries/requests are not being cache-pulled or sent upstream &#8211; <em>on this one particular server</em>.  (iptables numbers above were reset 60 minutes previous)</p>
<p style="text-align: center;"><strong>Slowly I turned, step by step, inch by inch</strong><br />
<strong>(shark by shark twisting in the wind)</strong></p>
<p>I ran off on a statistics tangent and never completed the fail2ban new-regex howto.</p>
<p>The new-est /etc/fail2ban/filter.d/named-flood.conf needs to be up-to-dated:<br />
<strong># vim /etc/fail2ban/filter.d/named-flood.conf</strong></p>
<pre>[Definition]
failregex = .* named\[.*\]: client &lt;HOST&gt;\#.*: query: ((?i)1rip|1rip\.com|isc\.org|\.) (IN|ANY) *
ignoreregex =</pre>
<p><strong>:wq</strong> (write and quit)</p>
<p>Make a test file:<br />
<strong>#vim /tmp/testfile.txt (press insert when it &#8216;loads: New File&#8217;)</strong></p>
<pre>Jul 11 05:40:22 server named[1301]: client 1.1.1.1#1: query: 1rip IN ANY +E ([ip of server])
Jul 11 05:40:22 server named[1301]: client 2.2.2.2#2: query: 1rip IN ANY +E ([ip of server])
Jul 11 05:40:23 server named[1301]: client 3.3.3.3#3: query: 1Rip IN ANY +E ([ip of server])
Jul 11 05:40:23 server named[1301]: client 4.4.4.4#4: query: 1rIp IN ANY +E ([ip of server])
Jul 11 05:40:24 server named[1301]: client 5.5.5.5#5: query: 1riP IN ANY +E ([ip of server])
Jul 11 05:40:24 server named[1301]: client 6.6.6.6#6: query: 1rip IN ANY +E ([ip of server])
Jul 11 05:40:24 server named[1301]: client 7.7.7.7#7: query: 1rip.com IN ANY +E ([ip of server])
Jul 11 05:40:24 server named[1301]: client 8.8.8.8#8: query: 1rIp.com IN ANY +E ([ip of server])
Jul 11 05:40:24 server named[1301]: client 9.9.9.9#9: query: linenine.com IN ANY +E ([ip of server])</pre>
<p><strong>:wq</strong> (write and quit)</p>
<p><strong>[root@server filter.d]# fail2ban-regex /tmp/testfile.txt named-flood.conf</strong></p>
<p>Should get 8 &#8220;number of match&#8221;</p>
<p>Compare to grep-ing (note the spaces and escaped .s inside the single quotes)<br />
grep -c -i &#8216; 1rip &#8216; /tmp/testfile.txt : 6<br />
grep -c -i &#8216; 1rip\.com &#8216;  /tmp/testfile.txt : 2<br />
grep -c -i &#8216; \. &#8216;  /tmp/testfile.txt : 0<br />
grep -c -i &#8216; isc\.org &#8216;  /tmp/testfile.txt : 0</p>
<p>Test and compare against the real thing:</p>
<p>Make a working copy:<strong><br />
[root@server filter.d]# cp /var/log/messages /tmp/x.txt</strong></p>
<p><strong>[root@server filter.d]# fail2ban-regex /tmp/x.txt named-flood.conf<br />
</strong>Takes a while on this server, then:<br />
<strong>Success, the total number of match is 106225</strong></p>
<p>Compare to grep-ing (note the spaces and escaped .s inside the single quotes)<br />
grep -c -i &#8216; 1rip &#8216; /tmp/x.txt : 81034<br />
grep -c -i &#8216; 1rip\.com &#8216;  /tmp/x.txt : 2977<br />
grep -c -i &#8216; \. &#8216;  /tmp/x.txt : 15917<br />
grep -c -i &#8216; isc\.org &#8216;  /tmp/x.txt : 6297<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; <strong>106225</strong> all added together</p>
<p>Sure looks like this is working, rm all those test files in /tmp/, then:</p>
<p># /etc/init.d/fail2ban restart</p>
<p>Because of the amount of sharks in this nado, you might (we have to) manually block some ip&#8217;s while fail2ban gets back in the race.  Once fail2ban is all caught up and ready to go up against the whirlwind of feeding-frenzied zombie-shark-bots, manually release those and let fail2ban do its thing.</p>
<p>One last piece of housekeeping in this bad movie: reset the counters.<br />
<strong>#iptables -Z</strong></p>
<p>About one minute later, late one Saturday afternoon:</p>
<pre><span style="color: #666666; font-family: Consolas;">num   pkts   bytes    target (rest snipped)
</span>1     2059    175K    fail2ban-dnsflood
2      352   66583    fail2ban-maillogins</pre>
<p>A whopping 17% of packet-traffic is NOT a DNS-DDoS-Flood packet.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.computermedic.org/?feed=rss2&#038;p=89</wfw:commentRss>
		<slash:comments>0</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>
