<?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>Climens&#039; Codelog &#187; Seguridad</title>
	<atom:link href="http://codelog.climens.net/category/seguridad/feed/" rel="self" type="application/rss+xml" />
	<link>http://codelog.climens.net</link>
	<description>Development, productivity, blogging, technology, life in the trenches...</description>
	<lastBuildDate>Tue, 20 Dec 2011 22:41:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using fail2ban with nginx in Debian</title>
		<link>http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/</link>
		<comments>http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 13:03:16 +0000</pubDate>
		<dc:creator>climens</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Seguridad]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://codelog.climens.net/?p=336</guid>
		<description><![CDATA[Taking a look at the logwatch mails I see a common pattern of attacks, coming from China and trying to find details of my server configuration, which is something I dont like. Looking around I found fail2ban which is a tool that does som regex matches on the server logs (sshd, httpd, authd, &#8230;) and [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><g:plusone size="tall" href="http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/"></g:plusone></div><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/" data-text="Using fail2ban with nginx in Debian" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/&amp;layout=box_count&amp;show_faces=true&amp;width=80&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:80px !important; height:65px;" allowTransparency="true"></iframe></div></div><p>Taking a look at the logwatch mails I see a common pattern of attacks, coming from China and trying to find details of my server configuration, which is something I dont like.</p>
<p>Looking around I found <a href="http://www.fail2ban.org/">fail2ban</a> which is a tool that does som regex matches on the server logs (sshd, httpd, authd, &#8230;) and takes proper actions, like banning the offending IP.</p>
<p>I then installed fail2ban in my Debian box:</p>
<pre class="brush: plain; title: ; notranslate">
&gt; apt-get install fail2ban
</pre>
<p>Then, I took a look at /etc/fail2ban/jail.conf and found some entries for Apache but none for <a href="http://nginx.org/">nginx</a>, my server of choice, so I decided to create a <strong>jail.local</strong> to add some nginx stuff (this is recommended in Debian to allow hassle-free upgrades).</p>
<p>I started copying the Apache sections of the default fail2ban as the log files in my case use the same format that allows me to use Awstats easily. Then, I modified my log routes to point to the nginx ones and using Apache rules, if they don&#8217;t work I&#8217;ll tune them later.</p>
<pre class="brush: plain; title: ; notranslate">
[nginx]

enabled = true
port    = http,https
filter  = apache-auth
logpath = /var/log/nginx*/*error.log
maxretry = 6

[nginx-noscript]

enabled = false
port    = http,https
filter  = apache-noscript
logpath = /var/log/nginx*/*error.log
maxretry = 6

[nginx-overflows]

enabled = false
port    = http,https
filter  = apache-overflows
logpath = /var/log/nginx*/*error.log
maxretry = 2
</pre>
<p>Although this is ok, the bots I see don&#8217;t leave a trace in error.log but in access.log so I took a look at the filter.d folder where an interesting apache-badbots.conf was present. Then, I found the default fail2ban documentation in /usr/share/doc/fail2ban where there&#8217;s an usage example of the badbots script. I added I to my jail.local:</p>
<pre class="brush: plain; title: ; notranslate">
[apache-badbots]

enabled  = true
port    = http,http
filter   = apache-badbots
logpath  = /var/log/nginx*/*access.log
bantime  = 172800
maxretry = 1
</pre>
<p>Finally, I added this to the top of the file, to send mails to myself when a rule matches and a host is banned.</p>
<pre class="brush: plain; title: ; notranslate">
[DEFAULT]

action = %(action_mwl)s
</pre>
<p>Finally, restart the service and start receiving mails:</p>
<pre class="brush: plain; title: ; notranslate">
&gt; sudo /etc/init.d/fail2ban restart
</pre>
<p>I&#8217;m sure this will need further adjustments, but it&#8217;s a beginning in my bot fighting war. I&#8217;ll make some updates as I find interesting results.</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

