<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Reviewing Practical PHP Exploitation Techniques</title>
	<atom:link href="http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/</link>
	<description>Cutting-edge Think tank &#124; Ethical Hacker Outfit</description>
	<pubDate>Fri, 04 Jul 2008 17:20:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Viz</title>
		<link>http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118853</link>
		<dc:creator>Viz</dc:creator>
		<pubDate>Tue, 15 Apr 2008 22:54:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118853</guid>
		<description>There is an issue on slide 12 with 

&lt;blockquote&gt;POST http&#58;//192.168.1.4/t/xoops-2.0.14/htdocs/install/index.php HTTP/1.1
lang=../../../../../../../../etc/passwd%00&#38;op=start&#38;submit=Next
NOTE: This attack will not work if MAGIC QUOTES are enabled. MAGIC
QUOTES escapes null characters to . This feature is often forgotten about.&lt;/blockquote&gt;

magic quotes is deprecated and will be going completely away with php 6. Advising people to use it is setting them up for trouble.

per the manual:http://www.php.net/manual/en/security.magicquotes.php

&lt;blockquote&gt;Warning

This feature has been DEPRECATED and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.&lt;/blockquote&gt;

As well it's inconsistent and doesn't always work. They are removing it because they've realized you can't create defensive coding with a language option that only works half the time. It simply doesn't work. A far better solution to the include problem is to compare the input variable and switch on it:

&lt;pre&gt;&lt;code&gt;$var=$_GET['language'];
switch($var)
{
  case "english":
    $include='english.php';
    break;
  case "spanish":
    $include='spanish.php';
    break;
  default:
    $include='genericerror.php';
    //or even 'english.php'
}&lt;/code&gt;&lt;/pre&gt;

You could also set up an associative array of include directories and do an array reference using $var as the index to locate a path or something. If the value at that index is empty (unexpected/malicious input) use the safety include. Using input directly, no matter how it's filtered, to build a path is very very bad form. Always has been. I've lost track (I'm sure you have too 8) of the number of vulnerabilities caused by this type of stupidity. As well, you can use a whitelist filter on your input to remove things like null. eg:

&lt;pre&gt;&lt;code&gt;$inputvar=$_GET['inputvar'];
$inputvar=preg_replace("/^[\w\.\@]/","",$inputvar);
(remove all but a-z,A-Z,0-9, . and @)&lt;/code&gt;&lt;/pre&gt;

Trying to filter all the bad stuff out is a losing proposition, much better to *only allow the good stuff*. It's future proof.

Great article!!!

-Viz</description>
		<content:encoded><![CDATA[<p>There is an issue on slide 12 with </p>
<blockquote><p>POST http&#58;//192.168.1.4/t/xoops-2.0.14/htdocs/install/index.php HTTP/1.1<br />
lang=../../../../../../../../etc/passwd%00&amp;op=start&amp;submit=Next<br />
NOTE: This attack will not work if MAGIC QUOTES are enabled. MAGIC<br />
QUOTES escapes null characters to . This feature is often forgotten about.</p></blockquote>
<p>magic quotes is deprecated and will be going completely away with php 6. Advising people to use it is setting them up for trouble.</p>
<p>per the manual:http://www.php.net/manual/en/security.magicquotes.php</p>
<blockquote><p>Warning</p>
<p>This feature has been DEPRECATED and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.</p></blockquote>
<p>As well it&#8217;s inconsistent and doesn&#8217;t always work. They are removing it because they&#8217;ve realized you can&#8217;t create defensive coding with a language option that only works half the time. It simply doesn&#8217;t work. A far better solution to the include problem is to compare the input variable and switch on it:</p>
<pre><code>$var=$_GET['language'];
switch($var)
{
  case &#8220;english&#8221;:
    $include=&#8217;english.php&#8217;;
    break;
  case &#8220;spanish&#8221;:
    $include=&#8217;spanish.php&#8217;;
    break;
  default:
    $include=&#8217;genericerror.php&#8217;;
    //or even &#8216;english.php&#8217;
}</code></pre>
<p>You could also set up an associative array of include directories and do an array reference using $var as the index to locate a path or something. If the value at that index is empty (unexpected/malicious input) use the safety include. Using input directly, no matter how it&#8217;s filtered, to build a path is very very bad form. Always has been. I&#8217;ve lost track (I&#8217;m sure you have too 8) of the number of vulnerabilities caused by this type of stupidity. As well, you can use a whitelist filter on your input to remove things like null. eg:</p>
<pre><code>$inputvar=$_GET['inputvar'];
$inputvar=preg_replace(&#8221;/^[\w\.\@]/&#8221;,&#8221;",$inputvar);
(remove all but a-z,A-Z,0-9, . and @)</code></pre>
<p>Trying to filter all the bad stuff out is a losing proposition, much better to *only allow the good stuff*. It&#8217;s future proof.</p>
<p>Great article!!!</p>
<p>-Viz</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Kierznowski</title>
		<link>http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118790</link>
		<dc:creator>David Kierznowski</dc:creator>
		<pubDate>Mon, 14 Apr 2008 10:34:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118790</guid>
		<description>Awesome AnDrEw, as far as I know, I think this is one way to handle NULL bytes.

hadaka, I could probably do a seperate presentation on that topic. See Awesome AnDrEw's comment.

mike, cool stuff man. Keep up the good work.</description>
		<content:encoded><![CDATA[<p>Awesome AnDrEw, as far as I know, I think this is one way to handle NULL bytes.</p>
<p>hadaka, I could probably do a seperate presentation on that topic. See Awesome AnDrEw&#8217;s comment.</p>
<p>mike, cool stuff man. Keep up the good work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mike</title>
		<link>http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118460</link>
		<dc:creator>mike</dc:creator>
		<pubDate>Tue, 08 Apr 2008 23:34:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118460</guid>
		<description>Wow,  its cool to see some CVE's instead of just theory.   I am not saying that I don't enjoy theory. 

urldecode() isn't the only way to bypass filtering.  I used base64_decode() here to bypass magic_quotes_gpc to hit some nifty SQL injection.  The SQL payload I used is a bit different from the norm. http://milw0rm.com/exploits/4733

Also EVERY file function in php suffers from a null byte issue because they are all calling the same C file handling function,  go ahead look at the stack trace in GDB.   To be honest as a C programmer I'm horrified some functions will read past the null byte. 

Peace</description>
		<content:encoded><![CDATA[<p>Wow,  its cool to see some CVE&#8217;s instead of just theory.   I am not saying that I don&#8217;t enjoy theory. </p>
<p>urldecode() isn&#8217;t the only way to bypass filtering.  I used base64_decode() here to bypass magic_quotes_gpc to hit some nifty SQL injection.  The SQL payload I used is a bit different from the norm. <a href="http://milw0rm.com/exploits/4733" rel="nofollow">http://milw0rm.com/exploits/4733</a></p>
<p>Also EVERY file function in php suffers from a null byte issue because they are all calling the same C file handling function,  go ahead look at the stack trace in GDB.   To be honest as a C programmer I&#8217;m horrified some functions will read past the null byte. </p>
<p>Peace</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hadaka-sarutobi</title>
		<link>http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118333</link>
		<dc:creator>hadaka-sarutobi</dc:creator>
		<pubDate>Tue, 08 Apr 2008 01:36:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118333</guid>
		<description>Can you elaborate more on multi-byte encoding attacks and how one attacks/defends them?</description>
		<content:encoded><![CDATA[<p>Can you elaborate more on multi-byte encoding attacks and how one attacks/defends them?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joey</title>
		<link>http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118101</link>
		<dc:creator>Joey</dc:creator>
		<pubDate>Sun, 06 Apr 2008 02:20:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118101</guid>
		<description>Thanks for publishing your presentation David. 

Always good to have more documented vulnerabilities (and their solutions) to keep newly built applications on top of them.</description>
		<content:encoded><![CDATA[<p>Thanks for publishing your presentation David. </p>
<p>Always good to have more documented vulnerabilities (and their solutions) to keep newly built applications on top of them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gustavo Cardial</title>
		<link>http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118086</link>
		<dc:creator>Gustavo Cardial</dc:creator>
		<pubDate>Sun, 06 Apr 2008 00:09:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-118086</guid>
		<description>Very nice, I'll check it out! Also, if you know where to find the php sockets presentation, please, let me know</description>
		<content:encoded><![CDATA[<p>Very nice, I&#8217;ll check it out! Also, if you know where to find the php sockets presentation, please, let me know</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Awesome AnDrEw</title>
		<link>http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-117992</link>
		<dc:creator>Awesome AnDrEw</dc:creator>
		<pubDate>Sat, 05 Apr 2008 05:21:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-117992</guid>
		<description>Correct me if I'm wrong, David, since I am in no way an expert in PHP, but nullbytes can easily be detected with preg_match and preg_match_all assuming they are in a Hex-encoded string, right? I've experimented with it a bit in the past, and always found it work in my test cases.</description>
		<content:encoded><![CDATA[<p>Correct me if I&#8217;m wrong, David, since I am in no way an expert in PHP, but nullbytes can easily be detected with preg_match and preg_match_all assuming they are in a Hex-encoded string, right? I&#8217;ve experimented with it a bit in the past, and always found it work in my test cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Kierznowski</title>
		<link>http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-117961</link>
		<dc:creator>David Kierznowski</dc:creator>
		<pubDate>Sat, 05 Apr 2008 00:15:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.gnucitizen.org/blog/reviewing-practical-php-exploitation-techniques/#comment-117961</guid>
		<description>Hugo sent me an interesting point regarding the urldecode() attack. I mentioned that urldecode would change %2527 to % + 27.

&lt;blockquote&gt;
Hugo: The Webserver will change %25 to %, and then urldecode() will change %27 to "'".
&lt;/blockquote&gt;

Lets try this out:
&lt;pre&gt;&lt;code&gt;$a = $_GET['t'];

    echo $a; // before urldecode
    $b = urldecode($a);
    echo $b; // after urldecode

We get from t=%25 &#124; t=%:
    $a = %
    $b = % // no change&lt;/code&gt;&lt;/pre&gt;

Thanks for the observation Hugo. 

While we are on the subject of urldecode(). urldecode() is also vulnerable to NULL byte injection. So there is certainly potential for other vulnerabilities such as File Include bugs (%2500).</description>
		<content:encoded><![CDATA[<p>Hugo sent me an interesting point regarding the urldecode() attack. I mentioned that urldecode would change %2527 to % + 27.</p>
<blockquote><p>
Hugo: The Webserver will change %25 to %, and then urldecode() will change %27 to &#8220;&#8216;&#8221;.
</p></blockquote>
<p>Lets try this out:</p>
<pre><code>$a = $_GET['t'];

    echo $a; // before urldecode
    $b = urldecode($a);
    echo $b; // after urldecode

We get from t=%25 | t=%:
    $a = %
    $b = % // no change</code></pre>
<p>Thanks for the observation Hugo. </p>
<p>While we are on the subject of urldecode(). urldecode() is also vulnerable to NULL byte injection. So there is certainly potential for other vulnerabilities such as File Include bugs (%2500).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
