<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://rgaucher.info/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>deep inside | security &amp; tools - PHP, variable variables, oh my!  - Comments</title>
  <link>http://rgaucher.info/</link>
  <description>This is a technical blog around the web security and hopefully lots of technologies. There will be at least: Python, C++, Web, AJAX, CSS and JavaScript. I'd like to talk more about data-mining, operational research stuff, maybe more intelligent algorithm also...</description>
  <language>en</language>
  <pubDate>Fri, 04 May 2012 15:43:23 -0400</pubDate>
  <copyright>All the content of this blog has been written by Romain Gaucher. Please add my blog URL if you quote me</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
    
    <item>
    <title>PHP, variable variables, oh my! - Romain</title>
    <link>http://rgaucher.info/post/2011/09/20/PHP-variable-variables-oh-my#c2871</link>
    <guid isPermaLink="false">urn:md5:74879c501efc1fc7c7a85943ae856a7d</guid>
    <pubDate>Thu, 22 Sep 2011 18:54:57 -0400</pubDate>
    <dc:creator>Romain</dc:creator>
    
    <description>&lt;p&gt;To me, the main problem is not the ability to write arrays in a var vars.
The PHP docs claim that super globals cannot be overwritten (which is
eventually true), but we see that we can temporarily modify them.&lt;/p&gt;
&lt;p&gt;The problem is mostly about the access to the super globals through var
vars. I'll file a bug report soon.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;</description>
  </item>
      
    
    <item>
    <title>PHP, variable variables, oh my! - Toya Kyte</title>
    <link>http://rgaucher.info/post/2011/09/20/PHP-variable-variables-oh-my#c2870</link>
    <guid isPermaLink="false">urn:md5:baf7c39772213b12b19a57ece12a2722</guid>
    <pubDate>Thu, 22 Sep 2011 17:04:31 -0400</pubDate>
    <dc:creator>Toya Kyte</dc:creator>
    
    <description>&lt;p&gt;Correction: you set the session var to 0, overwriting it in the session (if
set), so it doesn't persist. I wasn't careful. But arrays shouldn't work in var
vars, so I believe a bug should be filed so we can see what comes out of
it.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;</description>
  </item>
      
    
    <item>
    <title>PHP, variable variables, oh my! - Toya Kyte</title>
    <link>http://rgaucher.info/post/2011/09/20/PHP-variable-variables-oh-my#c2869</link>
    <guid isPermaLink="false">urn:md5:c9af7c335c6b51709391eb361e74b03c</guid>
    <pubDate>Thu, 22 Sep 2011 09:54:04 -0400</pubDate>
    <dc:creator>Toya Kyte</dc:creator>
    
    <description>&lt;p&gt;Hi, Romain.&lt;/p&gt;
&lt;p&gt;You know what, wow.&lt;/p&gt;
&lt;p&gt;You're right. This has to be a bug. Writing to the SESSION should persist,
or not work at all. Can you please file this code example with the details on
bugs.php.net?&lt;/p&gt;
&lt;p&gt;Then please give us here the bug ID (or link) so we can vote it up.&lt;/p&gt;</description>
  </item>
      
    
    <item>
    <title>PHP, variable variables, oh my! - MaXe</title>
    <link>http://rgaucher.info/post/2011/09/20/PHP-variable-variables-oh-my#c2868</link>
    <guid isPermaLink="false">urn:md5:8e05e80fb4950086fab0ba3cc7eeea30</guid>
    <pubDate>Wed, 21 Sep 2011 16:01:26 -0400</pubDate>
    <dc:creator>MaXe</dc:creator>
    
    <description>&lt;p&gt;Thanks Romain, your reply was very useful as I needed a proper code example
to fully understand how this applies.&lt;/p&gt;</description>
  </item>
      
    
    <item>
    <title>PHP, variable variables, oh my! - Romain</title>
    <link>http://rgaucher.info/post/2011/09/20/PHP-variable-variables-oh-my#c2867</link>
    <guid isPermaLink="false">urn:md5:caa98e5e6354c0af2fee220f88ce6243</guid>
    <pubDate>Wed, 21 Sep 2011 11:45:12 -0400</pubDate>
    <dc:creator>Romain</dc:creator>
    
    <description>&lt;p&gt;@Tokya Kite, @Trikisatan,&lt;br /&gt;
Interesting, I just read this part actually that it was not supposed to
overwrite the session. However, my quick testing shows this is actually
possible to change the values inside the session, those do not get persisted
though. That means that the changes are only available for the remaining of the
script.&lt;/p&gt;
&lt;p&gt;Here is the script (rw.php) I use:&lt;br /&gt;&lt;/p&gt;
&lt;pre&gt;
&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;$_SESSION['admin'] = 0;&lt;br /&gt;print &amp;quot;Before: Admin? - &amp;quot; . $_SESSION['admin'] . '&amp;lt;br /&amp;gt;';&lt;br /&gt;while(list($name, $value) = each($_GET)) {&lt;br /&gt;$$name = $value;&lt;br /&gt;}&lt;br /&gt;print &amp;quot;After: Admin? - &amp;quot; . $_SESSION['admin'] . '&amp;lt;br /&amp;gt;';&lt;br /&gt;?&amp;gt;
&lt;/pre&gt;
&lt;p&gt;When you use something like:&lt;br /&gt;
&lt;a href=&quot;http://example.com/rw.php?_SESSION[admin]=1&quot; title=&quot;http://example.com/rw.php?_SESSION[admin]=1&quot;&gt;http://example.com/rw.php?_SESSION[admin]=1&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The trace will show:&lt;br /&gt;
Before: Admin? - 0&lt;br /&gt;
After: Admin? - 1&lt;/p&gt;
&lt;p&gt;However, the value isadmin=1 is not persisted in the session itself. It's
only dynamically set during the context of the running script.&lt;/p&gt;</description>
  </item>
      
    
    <item>
    <title>PHP, variable variables, oh my! - briedis</title>
    <link>http://rgaucher.info/post/2011/09/20/PHP-variable-variables-oh-my#c2866</link>
    <guid isPermaLink="false">urn:md5:c27ccc3f7505849b196e3fef3a6fca12</guid>
    <pubDate>Wed, 21 Sep 2011 10:33:11 -0400</pubDate>
    <dc:creator>briedis</dc:creator>
    
    <description>&lt;p&gt;If approching as a black box - not so vulnerable... But still, variable
variables never should have been born :)&lt;/p&gt;</description>
  </item>
      
    
    <item>
    <title>PHP, variable variables, oh my! - Trikisatan</title>
    <link>http://rgaucher.info/post/2011/09/20/PHP-variable-variables-oh-my#c2865</link>
    <guid isPermaLink="false">urn:md5:b1360b773daf6e20b067066e9e6f1f54</guid>
    <pubDate>Wed, 21 Sep 2011 10:25:44 -0400</pubDate>
    <dc:creator>Trikisatan</dc:creator>
    
    <description>&lt;p&gt;So, you are saying that php.net is bullshitting?&lt;br /&gt;
&lt;a href=&quot;http://php.net/manual/en/language.variables.variable.php&quot; title=&quot;http://php.net/manual/en/language.variables.variable.php&quot;&gt;http://php.net/manual/en/language.v...&lt;/a&gt;&lt;br /&gt;

More exactly:&lt;br /&gt;
Warning&lt;/p&gt;
&lt;p&gt;Please note that variable variables cannot be used with PHP's Superglobal
arrays within functions or class methods. The variable $this is also a special
variable that cannot be referenced dynamically.&lt;/p&gt;
&lt;p&gt;Superglobals:&lt;br /&gt;
&lt;a href=&quot;http://www.php.net/manual/en/language.variables.superglobals.php&quot; title=&quot;http://www.php.net/manual/en/language.variables.superglobals.php&quot;&gt;http://www.php.net/manual/en/langua...&lt;/a&gt;&lt;/p&gt;</description>
  </item>
      
    
    <item>
    <title>PHP, variable variables, oh my! - Haris</title>
    <link>http://rgaucher.info/post/2011/09/20/PHP-variable-variables-oh-my#c2864</link>
    <guid isPermaLink="false">urn:md5:1daf5c960bedf265be174e92192d6825</guid>
    <pubDate>Wed, 21 Sep 2011 10:17:55 -0400</pubDate>
    <dc:creator>Haris</dc:creator>
    
    <description>&lt;p&gt;Once I encountered a similar bug on a PHP application. The way I exploited
it though was different.&lt;/p&gt;
&lt;p&gt;The location of the variable overwriting code was at the top of the file and
only few variables could get overwritten. Among them was mysql_host and
mysql_user/pass.&lt;/p&gt;
&lt;p&gt;The rest of the code didn't have any authentication and all the other
variables were properly initialized so one couldn't exploit an SQL injection or
change the code flow to get admin access. I spend a couple days trying to
figure out how to exploit this vulnerability...&lt;/p&gt;
&lt;p&gt;I did an nmap and found that the server had the mysql server bound on
0.0.0.0 and without any host restrictions. So I overwrote the mysql_host
variable and made it connect to my computer. On my computer I was running mysql
proxy and had it setup to connect to the remote server.&lt;/p&gt;
&lt;p&gt;Tada! I had complete MySQL access... without knowing the database
credentials (the PHP client did the authentication for me). I wrote a few LUA
scripts (this is what MySQL proxy uses) and was able to access the whole
DB.&lt;/p&gt;
&lt;p&gt;These vulnerabilities can be very tricky to exploit some times and are hard
to detect with SAST. During a manual code review though one could do a grep for
'$$' to find any dynamic variable assignments.&lt;/p&gt;
&lt;p&gt;Overall great post and a great idea for some PHP challenges :)&lt;/p&gt;</description>
  </item>
      
    
    <item>
    <title>PHP, variable variables, oh my! - PingPong</title>
    <link>http://rgaucher.info/post/2011/09/20/PHP-variable-variables-oh-my#c2863</link>
    <guid isPermaLink="false">urn:md5:3fe9d8c96cd894e04428bc86bad9e3b7</guid>
    <pubDate>Wed, 21 Sep 2011 10:13:20 -0400</pubDate>
    <dc:creator>PingPong</dc:creator>
    
    <description>&lt;p&gt;Wouldn't exploiting the first example require very intimate knowledge of the
executed code? First you'd need to know variable variables are being used, and
then somehow you'd have to know to overwrite $declareSQLArray.&lt;/p&gt;</description>
  </item>
      
    
    <item>
    <title>PHP, variable variables, oh my! - Toya Kyte</title>
    <link>http://rgaucher.info/post/2011/09/20/PHP-variable-variables-oh-my#c2862</link>
    <guid isPermaLink="false">urn:md5:fb0bd449ac92cf084a24f1de9c2e0496</guid>
    <pubDate>Wed, 21 Sep 2011 09:29:11 -0400</pubDate>
    <dc:creator>Toya Kyte</dc:creator>
    
    <description>&lt;p&gt;You're right the code example shows a vulnerability, but what you're not
right about is that it's not immediately visible to anyone experienced with
PHP. Additionally you're incorrect about PHP interpreting arrays in variable
variables as in your $_SESSION example. Try to make it work. You won't be able
to.&lt;/p&gt;
&lt;p&gt;Of course, you can always fail if you demand to, say
$_SESSION[$_POST['something']] but that's blatantly obviously bad.&lt;/p&gt;</description>
  </item>
      
    
    <item>
    <title>PHP, variable variables, oh my! - Will</title>
    <link>http://rgaucher.info/post/2011/09/20/PHP-variable-variables-oh-my#c2861</link>
    <guid isPermaLink="false">urn:md5:8be5fb01315c1cb0597a5bb3ba162aa7</guid>
    <pubDate>Tue, 20 Sep 2011 19:21:46 -0400</pubDate>
    <dc:creator>Will</dc:creator>
    
    <description>&lt;p&gt;All that besides the quite ugly DOS. Egads - I've always hated PHP but this
is off the charts nauseating.&lt;/p&gt;</description>
  </item>
      
</channel>
</rss>
