<?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>Penguin on Rails &#187; Security</title>
	<atom:link href="http://www.cherpec.com/category/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cherpec.com</link>
	<description>linux + ruby on rails = love</description>
	<lastBuildDate>Thu, 17 Jun 2010 14:06:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Configure DenyHosts to ignore local networks</title>
		<link>http://www.cherpec.com/2009/10/configure-denyhosts-to-ignore-local-networks/</link>
		<comments>http://www.cherpec.com/2009/10/configure-denyhosts-to-ignore-local-networks/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 17:46:52 +0000</pubDate>
		<dc:creator>Vitalie Cherpec</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[DenyHosts]]></category>
		<category><![CDATA[hosts.allow]]></category>
		<category><![CDATA[hosts.deny]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.cherpec.com/?p=439</guid>
		<description><![CDATA[I would not talk about how important is to secure your ssh server. One of the tools that helps us to secure ssh server is DenyHosts. From the DenyHosts home page:

DenyHosts is a script intended to be run by Linux system administrators to help thwart SSH server attacks (also known as dictionary based attacks and [...]]]></description>
			<content:encoded><![CDATA[<p>I would not talk about how important is to secure your ssh server. One of the tools that helps us to secure ssh server is <a href="http://denyhosts.sourceforge.net">DenyHosts</a>. From the DenyHosts home page:</p>
<blockquote><p>
DenyHosts is a script intended to be run by Linux system administrators to help thwart SSH server attacks (also known as dictionary based attacks and brute force attacks).
</p></blockquote>
<p>Sending accidentally wrong password to server will block your access. You can avoid it by using public key authentication or when it&#8217;s not possible you can configure DenyHosts to ignore IP addresses from your network:</p>
<blockquote><p><strong>How can I prevent a legitimate IP address from being blocked by DenyHosts?</strong></p>
<p>Since it is quite possible for a user to mistype their password repeatedly it may be desirable to have DenyHosts prevent specific IP addresses from being added to /etc/hosts.deny. To address this issue, create a file named allowed-hosts in the WORK_DIR. Simply add an IP address, one per line. Any IP address that appears in this file will not be blocked.<br />
[...]</p>
<p><a href="http://denyhosts.sourceforge.net/faq.html#3_7">more</a>
</p></blockquote>
<p>I do prefer the TCP wrappers way, I&#8217;ll just bypass DenyHosts for local networks. </p>
<p>Configure DenyHosts to write blocked IPs to <em>/etc/denyhosts/blocked</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/denyhosts/denyhosts.cfg</span>
HOSTS_DENY = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>denyhosts<span style="color: #000000; font-weight: bold;">/</span>blocked
BLOCK_SERVICE  =</pre></div></div>

<p>Allow ssh connection if listed in <em>/etc/denyhosts/ignored</em>, and then the last rule is to allow ssh access unless listed in <em>/etc/denyhosts/blocked</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># hosts.allow   This file describes the names of the hosts which are</span>
<span style="color: #666666; font-style: italic;">#               allowed to use the local INET services, as decided</span>
<span style="color: #666666; font-style: italic;">#               by the '/usr/sbin/tcpd' server.</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ssh access</span>
sshd: <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>denyhosts<span style="color: #000000; font-weight: bold;">/</span>ignored : allow
sshd: ALL EXCEPT <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>denyhosts<span style="color: #000000; font-weight: bold;">/</span>blocked</pre></div></div>

<p>Add IPs/networks to ignore:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/denyhosts/ignored</span>
<span style="color: #666666; font-style: italic;"># hosts allowed to connect bypassing DenyHosts</span>
192.168.10.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0</pre></div></div>

<p>More on the file format:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">man</span> hosts.allow</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.cherpec.com/2009/10/configure-denyhosts-to-ignore-local-networks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>This site may harm your computer</title>
		<link>http://www.cherpec.com/2009/03/this-site-may-harm-your-computer/</link>
		<comments>http://www.cherpec.com/2009/03/this-site-may-harm-your-computer/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 12:40:00 +0000</pubDate>
		<dc:creator>Vitalie Cherpec</dc:creator>
				<category><![CDATA[Plesk]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[badware]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[geoip]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[malicious]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.cherpec.com/?p=172</guid>
		<description><![CDATA[  Today the website of one of the clients was blacklisted by Google by containing malicious software that downloads and installs without user&#8217;s consent. Google displayed &#8220;This site may harm your computer&#8221; under website in the results page.
Analyzing site&#8217;s sources we found obfuscated JavaScript code inserted near body, html tags in .html, .php, .tpl [...]]]></description>
			<content:encoded><![CDATA[<p>  Today the website of one of the clients was blacklisted by Google by containing malicious software that downloads and installs without user&#8217;s consent. Google displayed &#8220;This site may harm your computer&#8221; under website in the results page.</p>
<p>Analyzing site&#8217;s sources we found obfuscated JavaScript code inserted near <strong>body</strong>, <strong>html</strong> tags in <strong>.html</strong>, <strong>.php</strong>, <strong>.tpl</strong> files and a <strong>.htaccess</strong> file with following content:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">RewriteEngine On
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>HTTP_REFERER<span style="color: #7a0874; font-weight: bold;">&#125;</span> .<span style="color: #000000; font-weight: bold;">*</span>google.<span style="color: #000000; font-weight: bold;">*</span>$ <span style="color: #7a0874; font-weight: bold;">&#91;</span>NC,OR<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>HTTP_REFERER<span style="color: #7a0874; font-weight: bold;">&#125;</span> .<span style="color: #000000; font-weight: bold;">*</span>aol.<span style="color: #000000; font-weight: bold;">*</span>$ <span style="color: #7a0874; font-weight: bold;">&#91;</span>NC,OR<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>HTTP_REFERER<span style="color: #7a0874; font-weight: bold;">&#125;</span> .<span style="color: #000000; font-weight: bold;">*</span>msn.<span style="color: #000000; font-weight: bold;">*</span>$ <span style="color: #7a0874; font-weight: bold;">&#91;</span>NC,OR<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>HTTP_REFERER<span style="color: #7a0874; font-weight: bold;">&#125;</span> .<span style="color: #000000; font-weight: bold;">*</span>yahoo.<span style="color: #000000; font-weight: bold;">*</span>$ <span style="color: #7a0874; font-weight: bold;">&#91;</span>NC,OR<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>HTTP_REFERER<span style="color: #7a0874; font-weight: bold;">&#125;</span> .<span style="color: #000000; font-weight: bold;">*</span>yandex.<span style="color: #000000; font-weight: bold;">*</span>$ <span style="color: #7a0874; font-weight: bold;">&#91;</span>NC,OR<span style="color: #7a0874; font-weight: bold;">&#93;</span>^M
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>HTTP_REFERER<span style="color: #7a0874; font-weight: bold;">&#125;</span> .<span style="color: #000000; font-weight: bold;">*</span>rambler.<span style="color: #000000; font-weight: bold;">*</span>$ <span style="color: #7a0874; font-weight: bold;">&#91;</span>NC,OR<span style="color: #7a0874; font-weight: bold;">&#93;</span>^M
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>HTTP_REFERER<span style="color: #7a0874; font-weight: bold;">&#125;</span> .<span style="color: #000000; font-weight: bold;">*</span>ya.<span style="color: #000000; font-weight: bold;">*</span>$ <span style="color: #7a0874; font-weight: bold;">&#91;</span>NC<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule .<span style="color: #000000; font-weight: bold;">*</span> http:<span style="color: #000000; font-weight: bold;">//</span>real-antispyware.info<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span>go.php?<span style="color: #007800;">sid</span>=<span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>R,L<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Hmm, visitors from search engines were redirected to real-antispyware.info. This website is a scam that shows some JavaScript animation fulling the user with a message that his computer is infected and prompts him to download and install a fake AntiVirus.</p>
<p>Analyzing IP addresses from ftp logs we found connections from Russia and China that altered client&#8217;s website. Somehow they got user&#8217;s ftp password (it can be done in so many ways: weak password, traffic sniffing, virus, keylogger, trojan, &#8230;) and they altered website files.  </p>
<p>You can use this simple Ruby script to analyze your ftp logs. By default it is configured for a Plesk server, and it will show suspicious lines (change IGNORE variables to fit your needs). You may need to install <a href="http://www.cherpec.com/2008/07/install-rubygems-on-centos-4/">rubygems</a> and <a href="http://geoip.rubyforge.org/">geoip</a> gem.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'geoip'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'zlib'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># hide logs from these countries</span>
<span style="color:#008000; font-style:italic;"># Example: RO US</span>
IGNORE_COUNTRIES = <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>RO US<span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># free geoip database is not 100% accurate</span>
<span style="color:#008000; font-style:italic;"># we may need to ignore a few ip addresses</span>
IGNORE_IP = <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>127.0.0.1 127.0.0.2<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
files = <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;/usr/local/psa/var/log/xferlog*&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
geoip = GeoIP.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/var/lib/GeoIP/GeoIP.dat'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> ip2country<span style="color:#006600; font-weight:bold;">&#40;</span>geoip, ip<span style="color:#006600; font-weight:bold;">&#41;</span>
  country = geoip.<span style="color:#9900CC;">country</span><span style="color:#006600; font-weight:bold;">&#40;</span>ip<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
ip_list = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
files.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>filename<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Processing #{filename} ...&quot;</span>
&nbsp;
  <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>filename<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
    input = f
    input = <span style="color:#6666ff; font-weight:bold;">Zlib::GzipReader</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>f<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">extname</span><span style="color:#006600; font-weight:bold;">&#40;</span>filename<span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#996600;">&quot;.gz&quot;</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">while</span> line = input.<span style="color:#CC0066; font-weight:bold;">gets</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      ip = line.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>\s<span style="color:#006600; font-weight:bold;">+/</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">unless</span> ip_list.<span style="color:#9966CC; font-weight:bold;">include</span>? ip
        country = ip2country<span style="color:#006600; font-weight:bold;">&#40;</span>geoip, ip<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">unless</span> IGNORE_COUNTRIES.<span style="color:#9966CC; font-weight:bold;">include</span>? country.<span style="color:#9900CC;">upcase</span> <span style="color:#9966CC; font-weight:bold;">or</span> IGNORE_IP.<span style="color:#9966CC; font-weight:bold;">include</span>? ip
          <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot; [#{country} : #{ip}] =&gt; #{line}&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
        ip_list <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> ip
      <span style="color:#9966CC; font-weight:bold;">end</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Steps that needs to followed: </p>
<ol>
<li>Change FTP password</li>
<li>Upload a clean copy from the backups of the website</li>
<li>Submit the website in the <a href="http://www.google.com/webmasters/">Webmaster&#8217;s Tools</a> for reconsideration</li>
<li>Audit your company security: computers, firewalls, antiviruses, software, &#8230;</li>
</ol>
<p>You may find useful diagnose tool from the <a href="http://www.google.com">Google</a> (replace example.com with your domain):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">http:<span style="color: #000000; font-weight: bold;">//</span>www.google.com<span style="color: #000000; font-weight: bold;">/</span>safebrowsing<span style="color: #000000; font-weight: bold;">/</span>diagnostic?<span style="color: #007800;">site</span>=http:<span style="color: #000000; font-weight: bold;">//</span>example.com</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.cherpec.com/2009/03/this-site-may-harm-your-computer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
