<?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>Erics Tech Blog &#187; ddos</title>
	<atom:link href="http://eric.lubow.org/tag/ddos/feed/" rel="self" type="application/rss+xml" />
	<link>http://eric.lubow.org</link>
	<description>Thoughts, musings, and other idealistic (sometimes useful) systems and development hoopla.</description>
	<lastBuildDate>Fri, 18 Nov 2011 14:56:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Checking For A DoS</title>
		<link>http://eric.lubow.org/2008/linux-security/checking-for-a-dos/</link>
		<comments>http://eric.lubow.org/2008/linux-security/checking-for-a-dos/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 14:00:58 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Linux Security]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[ddos]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/blog/?p=50</guid>
		<description><![CDATA[Working on groups of web servers, especially ones that are highly susceptible to attack, it is a good idea to have a string of commands that will allow you to check what is going on. Check for DDos: netstat -n &#124; grep EST &#124; awk '{ print $5 }' &#124; cut -d: -f1 &#124; sort [...]]]></description>
			<content:encoded><![CDATA[<p>Working on groups of web servers, especially ones that are highly susceptible to attack, it is a good idea to have a string of commands that will allow you to check what is going on.</p>
<p>Check for DDos:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">netstat -n | grep EST | awk '{ print $5 }' | cut -d: -f1 | sort | uniq -c | sort -nr | perl -an -e 'use Socket; ($hostname, @trash) = gethostbyaddr(inet_aton($F[1]), AF_INET); print &quot;$F[0]\t$F[1]\t$hostname\n&quot;;'</div></div>
<p>Using this command will produce a list of hostnames that have a connect to the machine in an ESTABLISHED state.  This is handy for creating a firewall rule either on the host (iptables, ipfw) or a little further away from the machine (at the edge router).</p>
<p>Check for web attacks:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cat eric.lubow.org-access_log.20081015 | awk '{print $1 }' | sort | uniq -c | sort -nr | head | perl -an -e 'use Socket; ($hostname, @trash) = gethostbyaddr(inet_aton($F[1]), AF_INET); print &quot;$F[0]\t$F[1]\t$hostname\n&quot;;'</div></div>
<p>By using this command, you will get a hostname lookup on the IP sorted by total hit count descending.  As when checking for DDos attacks, you can use this information to write firewall rules.</p>
<p>More web attack checks:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">for i in `ls *.20081015 | grep -v error`; do echo &quot;##### $i ######&quot;; tail -n 10000 $i| awk '{print $1};' | sort -n | uniq -c | sort -nr | head -2; done</div></div>
<p>The difference between this check and the previous check is that this time, you may have a lot more logfiles to go through.  I am also assuming that they are stored by <sitename>.<date>.  They will print out which file its scanning and the top 2 issues from that file.</p>
<p>Referrer Check:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">for file in `ls -lrS *access*20080525* | tail -n20`; do echo &quot;==========&quot; $file; gawk --re-interval -F'&quot;' '{ split($4, myrt, &quot;/&quot;); &nbsp;split($0, myct); split(myct[3], myc, &quot; &quot;); if (length(myrt[3])==0) { myrt[3]=&quot;none&quot;}; if (myrt[3] ~ /([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}/) { referrers[myrt[3]&quot;/&quot;myc[1]]++; } else { t=split(myrt[3], myrt2, &quot;.&quot;); myref=&quot;*.&quot;myrt2[t-1]&quot;.&quot;myrt2[t]; referrers[myref&quot;/&quot;myc[1]]++; } } END { for (referrer in referrers) { print referrers[referrer], referrer } }' $file | grep -v none | sort -n; done</div></div>
<p>This last check will get the referrer for a page from the logs and count up the number of times that exact referrer drives traffic to your page.  Although this may initially appear to be only tangentially useful, if you are getting DDos, it may be hard to track down.  Let&#8217;s say that you have some static content like a funny image and want to know why everyone is going to that image.  Maybe your getting <a href="http://digg.com/">Dugg</a> or <a href="http://slashdot.org">./</a> and this will help you tell (and find out what your page is so you can Digg yourself if you&#8217;re into that sort of thing).</date></sitename></p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2007/perl/syshostname/' rel='bookmark' title='Sys::Hostname'>Sys::Hostname</a></li>
<li><a href='http://eric.lubow.org/2009/perl/cleaning-up-long-conditionals-with-grep/' rel='bookmark' title='Cleaning Up Long Conditionals With Grep'>Cleaning Up Long Conditionals With Grep</a></li>
<li><a href='http://eric.lubow.org/2009/ruby/rails/checking-roles-in-views-using-rolerequirement/' rel='bookmark' title='Checking Roles in Views Using RoleRequirement'>Checking Roles in Views Using RoleRequirement</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2008/linux-security/checking-for-a-dos/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

