<?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>Fernando Ipar &#187; security</title>
	<atom:link href="http://fernandoipar.com/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://fernandoipar.com</link>
	<description>I love mankind! Its people I can&#039;t stand!</description>
	<lastBuildDate>Wed, 07 Jul 2010 04:10:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>iptables trick to limit concurrent tcp connections</title>
		<link>http://fernandoipar.com/2009/06/17/iptables-trick-to-limit-concurrent-tcp-connections/</link>
		<comments>http://fernandoipar.com/2009/06/17/iptables-trick-to-limit-concurrent-tcp-connections/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 11:58:10 +0000</pubDate>
		<dc:creator>fernando</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://fernandoipar.com/?p=173</guid>
		<description><![CDATA[This is sort of a self-documenting post, and a self-support group about ill-behaved tomcat apps. Sometimes, you have multiple nodes accesing your MySQL server (or any kind of server, for that matter) concurrently. Eventually, software in one or more of these nodes might do nasty things (you know who you are buddy:)) MySQL provides a [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>This is sort of a self-documenting post, and a self-support group about ill-behaved tomcat apps.</p>
<p>Sometimes, you have multiple nodes accesing your MySQL server (or any kind of server, for that matter) concurrently. Eventually, software in one or more of these nodes might do nasty things (you know who you are buddy:))</p>
<p>MySQL provides a built in mechanism to limit concurrent connections, but this can only be set for the whole server, or on a per user basis. Unfortunatly, most of these setups use the same database user for all their nodes, so this feature can&#8217;t be used to confine any possible damage.</p>
<p>Enter your good friend iptables.</p>
<p>This isn&#8217;t perfect, but this little trick might help you while programmers take care of their business:</p>
<pre>iptables -A INPUT -p tcp -m recent --rcheck --seconds 60 -j REJECT
iptables -A INPUT -p tcp --dport 3306 -m connlimit --connlimit-above 2 -m recent --set -j REJECT</pre>
<p>(The number of seconds and the concurrency limit here are examples for testing only, set them to proper values if you use them in your servers!)</p>
<p>This two rules create a recent &#8216;bad guy&#8217; list, and send any source that exceeds two concurent connections on tcp pot 3306 to this list for 60 seconds.</p>
<p>If used smartly with a proper timeout value for MySQL connections, this could be useful for situations such as the one I described.</p>
<p>Hope it helps you!</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://fernandoipar.com/2009/06/17/iptables-trick-to-limit-concurrent-tcp-connections/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Generating random salts from bash</title>
		<link>http://fernandoipar.com/2009/02/04/generating-random-salts-from-bash/</link>
		<comments>http://fernandoipar.com/2009/02/04/generating-random-salts-from-bash/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 23:19:57 +0000</pubDate>
		<dc:creator>fernando</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://fernandoipar.com/?p=86</guid>
		<description><![CDATA[From the &#8216;just because it can be done&#8217; column, here comes a handy shell script to generate random salts. So, without further ado,  here it goes: #!/bin/bash [ $# -eq 0 ] &#38;&#38; { echo "usage: salt &#60;length&#62;"&#62;&#38;2 exit } strings &#60;/dev/urandom &#124; while read line; do echo $line &#124; tr '\n\t ' $RANDOM:0:1 &#62;&#62; [...]


Related posts:<ol><li><a href='http://fernandoipar.com/2009/08/14/generating-data-with-dbmonster/' rel='bookmark' title='Permanent Link: Generating data with dbmonster'>Generating data with dbmonster</a> <small> In my last post I included some sample data...</small></li><li><a href='http://fernandoipar.com/2009/01/12/running-commands-from-the-shell-with-a-timeout-pt-2/' rel='bookmark' title='Permanent Link: Running commands from the shell with a timeout (pt 2)'>Running commands from the shell with a timeout (pt 2)</a> <small>Here&#8217;s an improved version of the safecmd script. This one...</small></li><li><a href='http://fernandoipar.com/2009/01/10/running-commands-from-the-shell-with-a-timeout/' rel='bookmark' title='Permanent Link: Running commands from the shell with a timeout'>Running commands from the shell with a timeout</a> <small>Sometimes, in a shell script, you need to run a...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>From the &#8216;just because it can be done&#8217; column, here comes a handy shell script to generate random <a title="Cryptographic Salt (Wikipedia)" href="http://en.wikipedia.org/wiki/Salt_(cryptography)">salts</a>.</p>
<p>So, without further ado,  here it goes:</p>
<pre>#!/bin/bash 

[ $# -eq 0 ] &amp;&amp; {
        echo "usage: salt &lt;length&gt;"&gt;&amp;2
        exit
}
strings &lt;/dev/urandom | while read line; do
        echo $line | tr '\n\t ' $RANDOM:0:1 &gt;&gt; /tmp/.salt.$$
        salt=$(cat /tmp/.salt.$$)
        [ ${#salt} -ge $1 ] &amp;&amp; salt=${salt:0:$1} &amp;&amp; echo $salt &amp;&amp; break
done
rm -f /tmp/.salt.$$</pre>
<p>I had to use $1 and not a var, and echo the salt right from inside the while, because the &#8216;|&#8217; creates another shell, so I can&#8217;t pass variables to or from the while in this case.</p>
<p>If you want to keep things simple, you can go perl and just do</p>
<pre>
#!/usr/bin/perl
use Crypt::Salt;
my $length = shift;
print salt($length);
</pre>
<p>But if you ever find yourself in a server with no cpan, the first option might prove useful <img src='http://fernandoipar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>


<p>Related posts:<ol><li><a href='http://fernandoipar.com/2009/08/14/generating-data-with-dbmonster/' rel='bookmark' title='Permanent Link: Generating data with dbmonster'>Generating data with dbmonster</a> <small> In my last post I included some sample data...</small></li><li><a href='http://fernandoipar.com/2009/01/12/running-commands-from-the-shell-with-a-timeout-pt-2/' rel='bookmark' title='Permanent Link: Running commands from the shell with a timeout (pt 2)'>Running commands from the shell with a timeout (pt 2)</a> <small>Here&#8217;s an improved version of the safecmd script. This one...</small></li><li><a href='http://fernandoipar.com/2009/01/10/running-commands-from-the-shell-with-a-timeout/' rel='bookmark' title='Permanent Link: Running commands from the shell with a timeout'>Running commands from the shell with a timeout</a> <small>Sometimes, in a shell script, you need to run a...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://fernandoipar.com/2009/02/04/generating-random-salts-from-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intrusion detection at the application level, for PHP</title>
		<link>http://fernandoipar.com/2009/01/19/intrusion-detection-at-the-application-level-for-php/</link>
		<comments>http://fernandoipar.com/2009/01/19/intrusion-detection-at-the-application-level-for-php/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 01:19:54 +0000</pubDate>
		<dc:creator>fernando</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://fernandoipar.com/?p=52</guid>
		<description><![CDATA[Here&#8217;s phpids, an Intrusion Detection System for PHP. According to the site, it aims to counter XSS, SQL Injection, header injection, directory traversal, RFE/LFI, DoS and LDAP attacks, and unknown attack patterns,  through it&#8217;s Centrifuge component. Installation is simple. Just download it, copy the lib directory to a directory in your project structure, or add [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s <a title="Intrusion Detection System for PHP" href="http://php-ids.org/" target="_self">phpids</a>, an Intrusion Detection System for PHP.</p>
<p>According to the site, it aims to counter XSS, SQL Injection, header injection, directory traversal, RFE/LFI, DoS and LDAP attacks, and unknown attack patterns,  through it&#8217;s Centrifuge component.</p>
<p>Installation is simple. Just download it, copy the lib directory to a directory in your project structure, or add it to your <code>include_path</code>.</p>
<p>I actually chose a mix of both ways, so it&#8217;s automatically included when I distribute my applications.</p>
<p>Here&#8217;s how to use it:</p>
<p><code><br />
ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.PRIVATE_ROOT.DIRECTORY_SEPARATOR.'phpids'.DIRECTORY_SEPARATOR.'lib');<br />
</code><br />
Here we&#8217;re just modifying the include path in order to add phpids.<br />
PRIVATE_ROOT is a constant that I&#8217;ve defined in my app, which defines the root of the application. This is not accessible from the web server (following the recommendation of the <a href="http://phpsec.org/projects/guide/1.html#1.4.1">Dispatch</a> method, from the <a href="http://phpsec.org">PHP Security Consortium</a>. However, this is a particular case, in most situations, I&#8217;d recommend using a framework that already takes a similar pattern into account, like <a href="http://cakephp.org/">CakePHP</a>).<br />
phpids is where I&#8217;ve copied this IDS. The downloaded package has a similar root directory name, like phpids-x.y.n, depending on the version number.</p>
<p><code><br />
require_once 'IDS/Init.php';<br />
</code></p>
<p>Require the Init.php file</p>
<p>Then, whenever you need to access the request variables (in my case, this was just in one point in my application so I just had to modify one function), add something like this:</p>
<p><code><br />
$request = array(<br />
'REQUEST' =&gt; $_REQUEST,<br />
'GET' =&gt; $_GET,<br />
'POST' =&gt; $_POST,<br />
'COOKIE' =&gt; $_COOKIE<br />
);<br />
$init = IDS_Init::init(PRIVATE_ROOT. DIRECTORY_SEPARATOR .'phpids'.DIRECTORY_SEPARATOR.'lib/IDS/Config/Config.ini');</code></p>
<p>$ids = new IDS_Monitor($request, $init);<br />
$result = $ids-&gt;run();</p>
<p>if (!$result-&gt;isEmpty()) {<br />
trigger_error($result);<br />
}</p>
<p>If the $result object is not empty, the IDS detected an attack attempt and therefore you should stop processing the request.</p>
<p>And now the fun part.</p>
<p>In order to test this, I set up a very simple, very insecure test page.<br />
Here&#8217;s the php code:</p>
<pre>error_reporting(E_ALL);
ini_set('include_path',ini_get('include_path').':'.'../src/phpids/lib');
require 'IDS/Init.php';
function checkIds()
{
   $request = array(
     'REQUEST' =&gt; $_REQUEST,
     'GET' =&gt; $_GET,
     'POST' =&gt; $_POST,
     'COOKIE' =&gt; $_COOKIE
);

$init = IDS_Init::init('/home/fipar/workspace/at-intranet/src/phpids/lib/IDS/Config/Config.ini');
$ids = new IDS_Monitor($request,$init);
$result = $ids-&gt;run();
if (!$result-&gt;isEmpty()) {
     trigger_error($result);
}
}

if (isset($_REQUEST['sql'])) {
     checkIds();
     $sql = $_REQUEST['sql'];
     print 'Form says '.$sql.'
';
}</pre>
<p>The html page has just an input type text with the name &#8216;sql&#8217;, and a submit button.</p>
<p>I tried the following inputs:</p>
<ul>
<li>Hello, which goes by ok</li>
<li>&#8216; and 1, which generates errors for the REQUEST and POST variables, stating<br />
<blockquote><p>Detects classic SQL injection probings 1/2 | Tags: sqli, id, lfi | ID: 42</p></blockquote>
</li>
<li>&lt;a href=&#8221;http://www.google.com&#8221;&gt;www.google.com&lt;/a&gt;, which generates errors for the REQUEST and POST variables, stating<br />
<blockquote>
<ul>
<li>finds html breaking injections including whitespace attacks | Tags: xss, csrf | ID: 1</li>
<li>Detects JavaScript object properties and methods | Tags: xss, csrf, id, rfe | ID: 17</li>
<li>Detects basic SQL authentication bypass attempts 2/3 | Tags: sqli, id, lfi | ID: 45</li>
</ul>
</blockquote>
</li>
</ul>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://fernandoipar.com/2009/01/19/intrusion-detection-at-the-application-level-for-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top 25 most dangerous programming errors</title>
		<link>http://fernandoipar.com/2009/01/13/top-25-most-dangerous-programming-errors/</link>
		<comments>http://fernandoipar.com/2009/01/13/top-25-most-dangerous-programming-errors/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 15:51:32 +0000</pubDate>
		<dc:creator>fernando</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://fernandoipar.com/?p=36</guid>
		<description><![CDATA[Most people make at least 8 or 9 of these in a new project, and this alone is a good reason to use a programming framework, unless you know what you&#8217;re doing. The problem is, sometimes, people who skip on frameworks, don&#8217;t know what they&#8217;re doing. Or, as the Tao of Programming says: There once [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Most people make at least 8 or 9 of these in a new project, and this alone is a good reason to use a programming framework, unless you know what you&#8217;re doing. </p>
<p>The problem is, sometimes, people who skip on frameworks, don&#8217;t know what they&#8217;re doing.<br />
Or, as the <a href="http://www.amazon.com/Tao-Programming-Geoffrey-James/dp/0931137071">Tao of Programming</a> says: </p>
<blockquote><p>
There once was a master programmer who wrote unstructured programs. A novice programmer, seeking to imitate him, also began to write unstructured programs. When the novice asked the master to evaluate his progress, the master criticized him for writing unstructured programs, saying, &#8220;What is appropriate for the master is not appropriate for the novice. You must understand the Tao before transcending structure.&#8221;
</p></blockquote>
<p>Anyway, for novices and masters alike, <a href="http://cwe.mitre.org/top25/">here&#8217;s</a> a great resource of common programming errors one should avoid while working on a project. Some are web oriented, but most are applicable in any environment. </p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://fernandoipar.com/2009/01/13/top-25-most-dangerous-programming-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
