<?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>blog.poucet.org &#187; Uncategorized</title>
	<atom:link href="http://blog.poucet.org/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.poucet.org</link>
	<description>Blogging about technology, functional programming, linux and life in general.</description>
	<lastBuildDate>Tue, 17 Nov 2009 23:01:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setting up iptables to throttle incoming ssh</title>
		<link>http://blog.poucet.org/2009/11/setting-up-iptables-to-throttle-incoming-ssh/</link>
		<comments>http://blog.poucet.org/2009/11/setting-up-iptables-to-throttle-incoming-ssh/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 22:56:13 +0000</pubDate>
		<dc:creator>poucet</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.poucet.org/?p=132</guid>
		<description><![CDATA[So I decided today, since I seem to be getting a lot of ssh attempts to my firewall at home to set up some iptable rules.
It took me quite a while to figure it out, since I needed to set up some modprobe options.
First, I set that I can count up to 250 (I think [...]]]></description>
			<content:encoded><![CDATA[<p>So I decided today, since I seem to be getting a lot of ssh attempts to my firewall at home to set up some iptable rules.</p>
<p>It took me quite a while to figure it out, since I needed to set up some modprobe options.</p>
<p>First, I set that I can count up to 250 (I think the maximum is 256) recent ip hits.</p>
<p><code>cat /etc/modprobe.d/options<br />
options ipt_recent ip_pkt_list_tot=250</code></p>
<p>Then I created a firewall script:</p>
<p><code>cat firewall.sh</code></p>
<pre><code>#!/bin/sh
ipt=/sbin/iptables

set -x

if [ -z $1 ] ; then
echo "$0 &lt;public device&gt;"
exit
fi

# Clear rules
$ipt -D INPUT -i $1 -p TCP --dport ssh -m state --state NEW -j "$1"-SSH 2&gt;/dev/null

# Set up an ssh and blacklist chain.
$ipt -F "$1"-SSH 2&gt;/dev/null
$ipt -F "$1"-BLACKLIST 2&gt;/dev/null
$ipt -X "$1"-SSH 2&gt;/dev/null
$ipt -X "$1"-BLACKLIST 2&gt;/dev/null

$ipt -N "$1"-SSH
$ipt -N "$1"-BLACKLIST

# Make sure that we update the recency of the packet, and then drop them.  The timing is controlled by the ssh chain.
$ipt -A "$1"-BLACKLIST -m recent --name BLACKLIST --set
$ipt -A "$1"-BLACKLIST -j DROP

# In the ssh chain, incoming connections from BLACKLIST hosts are dropped.  The timer is restarted everytime we get a packet within 600 s.
$ipt -A "$1"-SSH -m recent --update --name BLACKLIST --seconds 600 --hitcount 1 -j DROP

# Create several counting buckets.
$ipt -A "$1"-SSH -m recent --set --name "$1"-BUCKET1
$ipt -A "$1"-SSH -m recent --set --name "$1"-BUCKET2
$ipt -A "$1"-SSH -m recent --set --name "$1"-BUCKET3
$ipt -A "$1"-SSH -m recent --set --name "$1"-BUCKET4

# Blacklist if:
#   More than 2 connections in 10 seconds
#   More than 14 connections in 120 seconds
#   More than 79 connections in 600 seconds
#   More than 250 connections in 1800 seconds
$ipt -A "$1"-SSH -m recent --update --name "$1"-BUCKET1 --seconds   10 --hitcount   3 -j "$1"-BLACKLIST
$ipt -A "$1"-SSH -m recent --update --name "$1"-BUCKET2 --seconds  120 --hitcount  15 -j "$1"-BLACKLIST
$ipt -A "$1"-SSH -m recent --update --name "$1"-BUCKET3 --seconds  600 --hitcount  80 -j "$1"-BLACKLIST
$ipt -A "$1"-SSH -m recent --update --name "$1"-BUCKET4 --seconds 1800 --hitcount 250 -j "$1"-BLACKLIST

# All other ssh access is allowed.
$ipt -A "$1"-SSH -j ACCEPT

# Allow packets that belong to existing connections.
$ipt -D INPUT -i $1 -m state --state RELATED,ESTABLISHED -j ACCEPT 2&gt;/dev/null
$ipt -A INPUT -i $1 -m state --state RELATED,ESTABLISHED -j ACCEPT

# Allow all packets from loopback device.
$ipt -D INPUT -i lo -j ACCEPT 2&gt;/dev/null
$ipt -A INPUT -i lo -j ACCEPT

# Redirect all incoming ssh connections to the chain of the same name.
$ipt -A INPUT -i $1 -p TCP --dport ssh -m state --state NEW -j "$1"-SSH

# What remains has no right to continue.
$ipt -D INPUT -i $1 -j DROP 2&gt;/dev/null
$ipt -A INPUT -i $1 -j DROP</code></pre>
<p>Finally, I set it up in my /etc/network/interfaces, that this should be called for my main interface (my public one):<br />
<code>auto eth0<br />
iface eth0 inet dhcp<br />
up firewall.sh eth0</code><br />
I hope this helps anyone.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.poucet.org/2009/11/setting-up-iptables-to-throttle-incoming-ssh/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>To my family and friends</title>
		<link>http://blog.poucet.org/2009/08/to-my-family-and-friends/</link>
		<comments>http://blog.poucet.org/2009/08/to-my-family-and-friends/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 15:39:49 +0000</pubDate>
		<dc:creator>poucet</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.poucet.org/?p=127</guid>
		<description><![CDATA[I think this is probably one of the best XKCD comics.  I wish I had had this in the past when people or family would ask me questions about computers (usually windows, being an avid Linux user).

]]></description>
			<content:encoded><![CDATA[<p>I think this is probably one of the best <a href="http://www.xkcd.com">XKCD</a> comics.  I wish I had had this in the past when people or family would ask me questions about computers (usually windows, being an avid Linux user).</p>
<p><a href="http://xkcd.com/627/"><img class="alignnone" title="How geeks perform tech support." src="http://imgs.xkcd.com/comics/tech_support_cheat_sheet.png" alt="" width="732" height="823" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.poucet.org/2009/08/to-my-family-and-friends/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
