<?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; lamp</title>
	<atom:link href="http://fernandoipar.com/tag/lamp/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>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>
	</channel>
</rss>
