<?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>Michele Manzotti &#187; ssh</title>
	<atom:link href="http://manzotti.eu/tag/ssh/feed" rel="self" type="application/rss+xml" />
	<link>http://manzotti.eu</link>
	<description></description>
	<lastBuildDate>Mon, 12 Jul 2010 23:53:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SSH anonimo via TOR</title>
		<link>http://manzotti.eu/ssh-anonimo-via-tor</link>
		<comments>http://manzotti.eu/ssh-anonimo-via-tor#comments</comments>
		<pubDate>Fri, 04 Sep 2009 23:52:05 +0000</pubDate>
		<dc:creator>manzotti</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[anonima]]></category>
		<category><![CDATA[BackTrack]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tor]]></category>

		<guid isPermaLink="false">http://manzotti.eu/?p=1459</guid>
		<description><![CDATA[Dopo aver installato il Tor in BT4, vediamo come poterlo utilizzare per effettuare connessioni ssh anonime.
La suite del pacchetto mette a disposizione l&#8217;utility torify che come vedete ci permette di effettuare connessioni TCP via tor:

$ apropos torify
torify (1)           - wrapper for tsocks and tor

&#8230;.e per [...]]]></description>
			<content:encoded><![CDATA[<p>Dopo aver installato il <a href="http://manzotti.eu/installare-tor-su-backtrack-4">Tor in BT4</a>, vediamo come poterlo utilizzare per effettuare connessioni ssh anonime.<br />
La suite del pacchetto mette a disposizione l&#8217;utility <strong>torify</strong> che come vedete ci permette di effettuare connessioni TCP via tor:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ apropos torify
torify (1)           - wrapper for tsocks and tor</pre></div></div>

<p>&#8230;.e per non farci mancare proprio nulla:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ apropos tor-resolve
tor-resolve (1)      - resolve a hostname to an IP address via tor</pre></div></div>

<p>Bè credo che sia chiaro&#8230;. quindi digitando semplicemente:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ torify ssh root@a.b.c.d</pre></div></div>

<p>&#8230; avremo la nostra bella shell anonima <img src='http://manzotti.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Una via speculare potrebbe essere quella del programma connect, disponibile su ubuntu e debian come <strong>connect-proxy</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ ssh -o ProxyCommand=&quot;/usr/bin/connect -S 127.0.0.1:9050 %h %p&quot; root@a.b.c.d</pre></div></div>

<p>Ulteriori riferimenti: <a href="http://psylocibe.noblogs.org/post/2008/07/15/come-aprire-una-connessione-anonima-verso-un-server-con-ssh-e-tor">qui</a><br />
<br />
Alla prossima <img src='http://manzotti.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://manzotti.eu/ssh-anonimo-via-tor/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ssh brute force bloccato con pf e regole di filtering su OpenBSD</title>
		<link>http://manzotti.eu/ssh-brute-force-bloccato-con-pf-e-regole-di-filtering</link>
		<comments>http://manzotti.eu/ssh-brute-force-bloccato-con-pf-e-regole-di-filtering#comments</comments>
		<pubDate>Sat, 10 Jan 2009 14:21:38 +0000</pubDate>
		<dc:creator>manzotti</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[brute]]></category>
		<category><![CDATA[force]]></category>
		<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[pf]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://manzotti.eu/?p=98</guid>
		<description><![CDATA[Poco tempo fa stavo stavo dando un occhiata ai miei log e mi sono subito accorto di un attacco brute force sulla porta ssh.
#tail /var/log/authlog

Dec 26 19:22:31 maxbsd sshd&#91;12620&#93;: Failed password for root from 218.23.105.25 port 45219 ssh2
Dec 26 19:22:31 maxbsd sshd&#91;13293&#93;: Received disconnect from 218.23.105.25: 11: Bye Bye
Dec 26 19:22:35 maxbsd sshd&#91;6301&#93;: reverse mapping [...]]]></description>
			<content:encoded><![CDATA[<p>Poco tempo fa stavo stavo dando un occhiata ai miei log e mi sono subito accorto di un attacco brute force sulla porta ssh.</p>
<p>#tail /var/log/authlog</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">Dec <span style="color: #cc66cc;">26</span> <span style="color: #cc66cc;">19</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">22</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">31</span> maxbsd sshd<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">12620</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span> Failed password <span style="color: #b1b100;">for</span> root from 218<span style="color: #339933;">.</span>23<span style="color: #339933;">.</span>105<span style="color: #339933;">.</span>25 port <span style="color: #cc66cc;">45219</span> ssh2
Dec <span style="color: #cc66cc;">26</span> <span style="color: #cc66cc;">19</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">22</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">31</span> maxbsd sshd<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">13293</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span> Received disconnect from 218<span style="color: #339933;">.</span>23<span style="color: #339933;">.</span>105<span style="color: #339933;">.</span>25<span style="color: #339933;">:</span> <span style="color: #cc66cc;">11</span><span style="color: #339933;">:</span> Bye Bye
Dec <span style="color: #cc66cc;">26</span> <span style="color: #cc66cc;">19</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">22</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">35</span> maxbsd sshd<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6301</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #000066;">reverse</span> mapping checking getaddrinfo <span style="color: #b1b100;">for</span> 25<span style="color: #339933;">.</span>105<span style="color: #339933;">.</span>23<span style="color: #339933;">.</span>218<span style="color: #339933;">.</span>broad<span style="color: #339933;">.</span>static<span style="color: #339933;">.</span>hf<span style="color: #339933;">.</span>ah<span style="color: #339933;">.</span>cndata<span style="color: #339933;">.</span>com <span style="color: #009900;">&#91;</span>218<span style="color: #339933;">.</span>23<span style="color: #339933;">.</span>105<span style="color: #339933;">.</span>25<span style="color: #009900;">&#93;</span> failed <span style="color: #339933;">-</span> POSSIBLE BREAK<span style="color: #339933;">-</span>IN ATTEMPT<span style="color: #339933;">!</span>
Dec <span style="color: #cc66cc;">26</span> <span style="color: #cc66cc;">19</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">22</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">35</span> maxbsd sshd<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6301</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span> Failed password <span style="color: #b1b100;">for</span> root from 218<span style="color: #339933;">.</span>23<span style="color: #339933;">.</span>105<span style="color: #339933;">.</span>25 port <span style="color: #cc66cc;">45474</span> ssh2
Dec <span style="color: #cc66cc;">26</span> <span style="color: #cc66cc;">19</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">22</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">35</span> maxbsd sshd<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2351</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span> Received disconnect from 218<span style="color: #339933;">.</span>23<span style="color: #339933;">.</span>105<span style="color: #339933;">.</span>25<span style="color: #339933;">:</span> <span style="color: #cc66cc;">11</span><span style="color: #339933;">:</span> Bye Bye
Dec <span style="color: #cc66cc;">26</span> <span style="color: #cc66cc;">19</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">22</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">39</span> maxbsd sshd<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3801</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #000066;">reverse</span> mapping checking getaddrinfo <span style="color: #b1b100;">for</span> 25<span style="color: #339933;">.</span>105<span style="color: #339933;">.</span>23<span style="color: #339933;">.</span>218<span style="color: #339933;">.</span>bro</pre></div></div>

<p>Per eliminare questo genere di attacchi possiamo:</p>
<ul>
<li>Abilitare ssh in modo che dopo 3 tentativi sbagliati cada la connessione</li>
<li>Inserire una regola in pf in modo che non accetti più di 3 connessioni contemporaneamente dallo stesso Ip, per poi bannarlo in una blacklist</li>
<li>Creare uno script in modo che legga l&#8217;ip dell&#8217;attaccante dai log e lo inserisca nella blacklist.</li>
</ul>
<p>Per risolvere il primo punto è sufficiente modificare il file di configurazione di ssh, sshd_config, decommentando l&#8217;opzione:</p>
<p># nano /etc/ssh/sshd_config</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">MaxAuthTries <span style="color: #cc66cc;">3</span></pre></div></div>

<p>Per il secondo punto è necessario definire una tabella che contenga gli ip bloccati (la nostra blacklist). Dunque editiamo il file di configurazione di pf che si trova in /etc/pf.conf:</p>
<p>#nano /etc/pf.conf</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">table  persist file <span style="color: #ff0000;">&quot;/etc/spammers&quot;</span></pre></div></div>

<p>Ora invece scriviamo la regola in modo che non accetti più di 3 connessioni contemporaneamente dallo stesso Ip e lo inserisca nella blacklist:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000066;">int</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;fxp0&quot;</span>
ssh_limit<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;(max-src-conn-rate 3/30, overload  flush global)&quot;</span>
pass in <span style="color: #000066;">log</span> quick on <span style="color: #0000ff;">$int</span> inet proto tcp from any to <span style="color: #0000ff;">$int</span> port ssh flags S<span style="color: #339933;">/</span>SA keep state <span style="color: #0000ff;">$ssh_limit</span></pre></div></div>

<p>Infine per il terzo punto è sufficiente creare uno script, ssh_block_attack, come il seguente, in modo che legga il file di log e metta in blacklist l&#8217;indirizzo ip che ha sbagliato la password o l&#8217;username:</p>
<p># nano /root/ssh_block_attack</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #000066;">read</span> mm dd hms localhostname sshd word1 word2 word3 word4 host1 host2 rest<span style="color: #339933;">;</span>
<span style="color: #b1b100;">do</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#91;</span> <span style="color: #ff0000;">&quot;$word1 $word2 $word4&quot;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Invalid user from&quot;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">then</span>
data<span style="color: #339933;">=</span><span style="color: #ff0000;">`date`</span>
pfctl <span style="color: #339933;">-</span>t spammers <span style="color: #339933;">-</span>T add <span style="color: #0000ff;">$host1</span>
echo <span style="color: #ff0000;">&quot;Aggiunto $host1 a spammers il $data&quot;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #339933;">/</span>root<span style="color: #339933;">/</span>ssh_log
&nbsp;
elif <span style="color: #009900;">&#91;</span> <span style="color: #ff0000;">&quot;$word1 $word2 $word3 $host1&quot;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Failed password for from&quot;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">then</span>
pfctl <span style="color: #339933;">-</span>t spammers <span style="color: #339933;">-</span>T add <span style="color: #0000ff;">$host2</span>
echo <span style="color: #ff0000;">&quot;Aggiunto $host2 a spammers il $data&quot;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #339933;">/</span>root<span style="color: #339933;">/</span>ssh_log
fi
done</pre></div></div>

<p>Per lanciarlo avvio dandogli in pasto il log da monitorare aggiungiamo questa riga in /etc/rc.local .</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">tail <span style="color: #339933;">-</span>f <span style="color: #339933;">/</span>var<span style="color: #339933;">/</span><span style="color: #000066;">log</span><span style="color: #339933;">/</span>authlog <span style="color: #339933;">|</span> sh ssh_block_attack <span style="color: #339933;">&amp;</span></pre></div></div>

<p>Infine se vogliamo vedere la tabella degli ip bloccati è necessario utilizzare questo comando</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">pfctl <span style="color: #339933;">-</span>t spammers <span style="color: #339933;">-</span>T show</pre></div></div>

<p>Ovviamente per non saturare la nostra macchina ogni tanto andrebbe svuotata:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">pfctl <span style="color: #339933;">-</span>t spammers <span style="color: #339933;">-</span>T <span style="color: #000066;">delete</span> indirizzo_ip</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://manzotti.eu/ssh-brute-force-bloccato-con-pf-e-regole-di-filtering/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
