<?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>Блог FreeBSD &#187; Безопасность</title>
	<atom:link href="http://bsd.irk38.ru/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://bsd.irk38.ru</link>
	<description>Ещё один блог сисадмина</description>
	<lastBuildDate>Wed, 18 Aug 2010 00:23:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Защита SSH от перебора паролей.</title>
		<link>http://bsd.irk38.ru/2009/12/zawita-ssh-ot-perebora-parolej/</link>
		<comments>http://bsd.irk38.ru/2009/12/zawita-ssh-ot-perebora-parolej/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 05:52:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Безопасность]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://bsd.irk38.ru/?p=78</guid>
		<description><![CDATA[Очень не приятно смотреть в логах, как идет методичный перебор имен и паролей к ssh с десятков ip&#8217;шников. В портах нашлось замечательное средство, bruteblock. Позволяет парсить лог, сверять записи с шаблоном, и добавлять злоумышленников в фаервол на определенное время.
Ставим

radio# whereis bruteblock
bruteblock: /usr/ports/security/bruteblock
radio# cd /usr/ports/security/bruteblock
radio# make install clean

по окончании установки получаем краткую инструкцию по установке

===&#62;  [...]]]></description>
			<content:encoded><![CDATA[<p>Очень не приятно смотреть в логах, как идет методичный перебор имен и паролей к ssh с десятков ip&#8217;шников. В портах нашлось замечательное средство, bruteblock. Позволяет парсить лог, сверять записи с шаблоном, и добавлять злоумышленников в фаервол на определенное время.</p>
<p><span id="more-78"></span>Ставим</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">radio<span style="color: #666666; font-style: italic;"># whereis bruteblock</span>
bruteblock: <span style="color: #eeeeee; font-weight: bold;">/</span>usr<span style="color: #eeeeee; font-weight: bold;">/</span>ports<span style="color: #eeeeee; font-weight: bold;">/</span>security<span style="color: #eeeeee; font-weight: bold;">/</span>bruteblock
radio<span style="color: #666666; font-style: italic;"># cd /usr/ports/security/bruteblock</span>
radio<span style="color: #666666; font-style: italic;"># make install clean</span></pre></div></div>

<p>по окончании установки получаем краткую инструкцию по установке</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">===<span style="color: #eeeeee; font-weight: bold;">&gt;</span>  CONFIGURATION NOTE:
&nbsp;
  Configuration of the bruteblock is <span style="color: #eeeeee; font-weight: bold;">done</span> via configuration files
  located at <span style="color: #eeeeee; font-weight: bold;">/</span>usr<span style="color: #eeeeee; font-weight: bold;">/</span>local<span style="color: #eeeeee; font-weight: bold;">/</span>etc<span style="color: #eeeeee; font-weight: bold;">/</span>bruteblock<span style="color: #eeeeee; font-weight: bold;">/</span>
&nbsp;
  To run the script, append following lines to <span style="color: #eeeeee; font-weight: bold;">/</span>etc<span style="color: #eeeeee; font-weight: bold;">/</span>syslog.conf:
&nbsp;
<span style="color: #eeeeee; font-weight: bold;">!*</span>
auth.info;authpriv.info                         <span style="color: #eeeeee; font-weight: bold;">|</span><span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #eeeeee; font-weight: bold;">/</span>usr<span style="color: #eeeeee; font-weight: bold;">/</span>local<span style="color: #eeeeee; font-weight: bold;">/</span>sbin<span style="color: #eeeeee; font-weight: bold;">/</span>bruteblock <span style="color: #660033;">-f</span> <span style="color: #eeeeee; font-weight: bold;">/</span>usr<span style="color: #eeeeee; font-weight: bold;">/</span>local<span style="color: #eeeeee; font-weight: bold;">/</span>etc<span style="color: #eeeeee; font-weight: bold;">/</span>bruteblock<span style="color: #eeeeee; font-weight: bold;">/</span>ssh.conf
&nbsp;
  and restart syslogd.
&nbsp;
  Also you should add ipfw2 table and the corresponding deny rule.
  For example,
&nbsp;
<span style="color: #666666; font-style: italic;"># ipfw add deny ip from table(1) to any  </span>
&nbsp;
  Next, you<span style="color: #ff0000;">'ll want to setup periodical cleanup of ipfw2 table.  Add following
  lines to /etc/rc.conf:
&nbsp;
     bruteblockd_enable=&quot;YES&quot;
     bruteblockd_table=&quot;1&quot;
     bruteblockd_flags=&quot;-s 5&quot;
&nbsp;
  and start bruteblockd: /usr/local/etc/rc.d/bruteblockd.sh start
&nbsp;
See bruteblock(8) for more detailts.</span></pre></div></div>

<p>будем следовать этой инструкции.</p>
<p>в файле, <strong>/etc/syslog.conf </strong>находим строчку</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">auth.info;authpriv.info                         <span style="color: #eeeeee; font-weight: bold;">/</span>var<span style="color: #eeeeee; font-weight: bold;">/</span>log<span style="color: #eeeeee; font-weight: bold;">/</span>auth.log</pre></div></div>

<p>и прямо под ней вставляем еще одну строку</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">auth.info;authpriv.info                         <span style="color: #eeeeee; font-weight: bold;">|</span><span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #eeeeee; font-weight: bold;">/</span>usr<span style="color: #eeeeee; font-weight: bold;">/</span>local<span style="color: #eeeeee; font-weight: bold;">/</span>sbin<span style="color: #eeeeee; font-weight: bold;">/</span>bruteblock <span style="color: #660033;">-f</span> <span style="color: #eeeeee; font-weight: bold;">/</span>usr<span style="color: #eeeeee; font-weight: bold;">/</span>local<span style="color: #eeeeee; font-weight: bold;">/</span>etc<span style="color: #eeeeee; font-weight: bold;">/</span>bruteblock<span style="color: #eeeeee; font-weight: bold;">/</span>ssh.conf</pre></div></div>

<p>Рестартуем syslogd</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">radio<span style="color: #666666; font-style: italic;"># /etc/rc.d/syslogd restart</span>
Stopping syslogd.
Starting syslogd.</pre></div></div>

<p>Настраиваем фаервол. Для начала его нужно включить, и создать свои правила.</p>
<p>создаем файл, <strong>/etc/rc.firewall.open</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #007800;">fwcmd</span>=<span style="color: #ff0000;">&quot;/sbin/ipfw&quot;</span>            <span style="color: #666666; font-style: italic;"># бинарник IPFW</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># сбрасываем все правила</span>
<span style="color: #800000;">${fwcmd}</span> <span style="color: #660033;">-f</span> flush
<span style="color: #666666; font-style: italic;"># сбрасываем все pipe</span>
<span style="color: #666666; font-style: italic;">#${fwcmd} -f pipe flush</span>
<span style="color: #666666; font-style: italic;"># сбрасываем очереди</span>
<span style="color: #666666; font-style: italic;">#${fwcmd} -f queue flush</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#берем адреса из таблицы table 1 и блокируем их</span>
<span style="color: #800000;">${fwcmd}</span> add <span style="color: #eeeeee;">100</span> deny ip from table\<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #eeeeee;">1</span>\<span style="color: #7a0874; font-weight: bold;">&#41;</span> to any
&nbsp;
<span style="color: #800000;">${fwcmd}</span> add <span style="color: #eeeeee;">200</span> pass all from any to any via lo0
<span style="color: #800000;">${fwcmd}</span> add <span style="color: #eeeeee;">300</span> deny all from any to 127.0.0.0<span style="color: #eeeeee; font-weight: bold;">/</span><span style="color: #eeeeee;">8</span>
<span style="color: #800000;">${fwcmd}</span> add <span style="color: #eeeeee;">400</span> deny ip from 127.0.0.0<span style="color: #eeeeee; font-weight: bold;">/</span><span style="color: #eeeeee;">8</span> to any
&nbsp;
<span style="color: #800000;">${fwcmd}</span> add <span style="color: #eeeeee;">65000</span> pass all from any to any</pre></div></div>

<p>в файл <strong>/etc/rc.conf </strong>добовляем</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">firewall_enable</span>=<span style="color: #ff0000;">&quot;YES&quot;</span>
<span style="color: #007800;">forewall_type</span>=<span style="color: #ff0000;">&quot;/etc/rc.firewall.open&quot;</span>
&nbsp;
<span style="color: #007800;">bruteblockd_enable</span>=<span style="color: #ff0000;">&quot;YES&quot;</span>
<span style="color: #007800;">bruteblockd_table</span>=<span style="color: #ff0000;">&quot;1&quot;</span>
<span style="color: #007800;">bruteblockd_flags</span>=<span style="color: #ff0000;">&quot;-s 5&quot;</span></pre></div></div>

<p>создаем файл <strong>/usr/local/etc/bruteblock/ssh.conf</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># шаблоны. при совпадении с которыми считается что пароль не правильный</span>
regexp          = sshd.<span style="color: #eeeeee; font-weight: bold;">*</span>Illegal user \S+ from <span style="color: #7a0874; font-weight: bold;">&#40;</span>\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
regexp1         = sshd.<span style="color: #eeeeee; font-weight: bold;">*</span>Failed password <span style="color: #eeeeee; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>?:illegal user <span style="color: #7a0874; font-weight: bold;">&#41;</span>?\S+ from <span style="color: #7a0874; font-weight: bold;">&#40;</span>\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
regexp2         = sshd.<span style="color: #eeeeee; font-weight: bold;">*</span>Failed keyboard-interactive\<span style="color: #eeeeee; font-weight: bold;">/</span>pam <span style="color: #eeeeee; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>?:invalid user <span style="color: #7a0874; font-weight: bold;">&#41;</span>?\S+ from <span style="color: #7a0874; font-weight: bold;">&#40;</span>\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Port \S+ ssh2
regexp3         = sshd.<span style="color: #eeeeee; font-weight: bold;">*</span>authentication error <span style="color: #eeeeee; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>?:illegal user <span style="color: #7a0874; font-weight: bold;">&#41;</span>?\S+ from <span style="color: #7a0874; font-weight: bold;">&#40;</span>\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
regexp4         = sshd.<span style="color: #eeeeee; font-weight: bold;">*</span>Invalid user \S+ from <span style="color: #7a0874; font-weight: bold;">&#40;</span>\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\.\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #eeeeee;">1</span>,<span style="color: #eeeeee;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># количество разрешенных попыток перед баном</span>
max_count       = <span style="color: #eeeeee;">4</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># в течении какого времени эти попытки можно делать</span>
within_time     = <span style="color: #eeeeee;">60</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># на какое время блочим</span>
reset_ip       = <span style="color: #eeeeee;">86400</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># IPFW номер таблицы</span>
ipfw2_table_no = <span style="color: #eeeeee;">1</span></pre></div></div>

<p>стартуем</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #eeeeee; font-weight: bold;">/</span>usr<span style="color: #eeeeee; font-weight: bold;">/</span>local<span style="color: #eeeeee; font-weight: bold;">/</span>etc<span style="color: #eeeeee; font-weight: bold;">/</span>rc.d<span style="color: #eeeeee; font-weight: bold;">/</span>bruteblockd start
Starting bruteblockd.
radio<span style="color: #666666; font-style: italic;"># /usr/local/etc/rc.d/bruteblockd status</span>
bruteblockd is running <span style="color: #c20cb9; font-weight: bold;">as</span> pid 3752.</pre></div></div>

<p>смотрим через некоторое время, таблицу фаервола</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">radio<span style="color: #666666; font-style: italic;"># ipfw table 1 list</span>
195.46.x.x<span style="color: #eeeeee; font-weight: bold;">/</span><span style="color: #eeeeee;">32</span> <span style="color: #eeeeee;">1260946935</span></pre></div></div>

<p>один попался <img src='http://bsd.irk38.ru/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.irk38.ru/2009/12/zawita-ssh-ot-perebora-parolej/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

