<?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>tom's blog &#187; iptables</title>
	<atom:link href="http://tom.knaupp.com/tag/iptables/feed/" rel="self" type="application/rss+xml" />
	<link>http://tom.knaupp.com</link>
	<description>free software, security and a bunch of my strange thoughts</description>
	<lastBuildDate>Fri, 21 Jan 2011 00:13:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Prevent SSH Brute Force attacks</title>
		<link>http://tom.knaupp.com/2009/02/28/prevent-ssh-brute-force-attacks/</link>
		<comments>http://tom.knaupp.com/2009/02/28/prevent-ssh-brute-force-attacks/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 14:48:00 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://tom.knaupp.com/?p=208</guid>
		<description><![CDATA[When checking logfiles, I often can see brute force attacks &#8211; especially against the ssh daemon. Of course, best way would be to block all ssh traffic except from your office/home ip. If this is not possible for various reasons, you can make life a little harder for &#8220;intruders&#8221; using iptables. &#160; Aim: If there [...]]]></description>
			<content:encoded><![CDATA[<p>When checking logfiles, I often can see brute force attacks &#8211; especially against the ssh daemon.<br />
Of course, best way would be to block all ssh traffic except from your office/home ip.<br />
If this is not possible for various reasons, you can make life a little harder for &#8220;intruders&#8221; using iptables.<br />
&nbsp;<br />
Aim: <br />
If there are more than three connection attemps within 120 seconds,<br />
all traffic from potential attacker to ssh port (tcp, 22) shall be blocked temporarily.<br />
&nbsp;<br />
<code><br />
#!/bin/bash<br />
#<br />
IPTABLES=`which iptables`<br />
#<br />
### if more than three new connections in 120 sec -> log<br />
$IPTABLES -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent \<br />
--rcheck --seconds 120 --hitcount 3 --rttl --name SSH -j LOG --log-level 7 \<br />
--log-prefix "Possible SSH breakin attemp: "<br />
#<br />
### if more than three new connections in 120 sec -> drop requests<br />
$IPTABLES -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent \<br />
--update --seconds 120 --hitcount 3 --rttl --name SSH -j DROP<br />
#<br />
### remember new, established connections<br />
$IPTABLES -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent \<br />
--set --name SSH -j ACCEPT<br />
#<br />
### generally allow ssh connections<br />
$IPTABLES -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT<br />
#<br />
# ---<br />
# -I INPUT .. -> iptables chain<br />
# -i eth0 ... -> interface to apply rule to<br />
# -p tcp .... -> use tcp port<br />
# --dport ... -> destination port 22 (SSH)<br />
# -m recent . -> matching state<br />
# --state ... -> can be NEW, ESTABLISHED, RELATED or INVALID<br />
# -rcheck ... -> will check if the source address of the packet is currently in the list<br />
# ---<br />
</code><br />
&nbsp;<br />
&nbsp;<br />
If it works, you should see entries like this in your firewall log<br />
(i.e. in /var/log/firewall [ openSuSE ]):<br />
&nbsp;<br />
<code><br />
Feb 28 15:14:20 cypher kernel: Possible SSH breakin attemp: IN=eth0 OUT= MAC=00:0c:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx SRC=123.xxx.xxx.xxx DST=223.xxx.xxx.xxx LEN=60 TOS=0x00 PREC=0x00 TTL=59 ID=52858 DF PROTO=TCP SPT=38220 DPT=22 WINDOW=5840 RES=0x00 SYN URGP=0<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://tom.knaupp.com/2009/02/28/prevent-ssh-brute-force-attacks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

