<?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"
	>

<channel>
	<title>Suspekt... &#187; Security</title>
	<atom:link href="http://www.suspekt.org/category/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.suspekt.org</link>
	<description>A Blog About Code, Information Security, PHP And More</description>
	<pubDate>Fri, 05 Mar 2010 08:26:52 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Suhosin-Patch 0.9.9.1</title>
		<link>http://www.suspekt.org/2010/03/05/suhosin-patch-0991/</link>
		<comments>http://www.suspekt.org/2010/03/05/suhosin-patch-0991/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 08:26:52 +0000</pubDate>
		<dc:creator>Stefan Esser</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[suhosin]]></category>

		<guid isPermaLink="false">http://www.suspekt.org/?p=341</guid>
		<description><![CDATA[Together with the release of PHP 5.3.2 by the PHP team I have released Suhosin-Patch 0.9.9.1 which comes with bugfixes and new features. The changes are:




fixed some crashbugs for IA64 architecture


check return value of mprotect() to ensure that memory is read only - credits: PAX Team


fixed mprotect() call - encrypted pointer was used in revoked [...]]]></description>
			<content:encoded><![CDATA[<p>Together with the release of <a href="http://www.php.net">PHP 5.3.2</a> by the PHP team I have released <a href="http://www.suhosin.org/">Suhosin-Patch 0.9.9.1</a> which comes with bugfixes and new features. The changes are:</p>
<div class="level3">
<div class="level3">
<ul>
<li class="level1">
<div class="li">fixed some crashbugs for IA64 architecture</div>
</li>
<li class="level1">
<div class="li">check return value of mprotect() to ensure that memory is read only - credits: PAX Team</div>
</li>
<li class="level1">
<div class="li">fixed mprotect() call - encrypted pointer was used in revoked 0.9.9 - credits: PAX Team</div>
</li>
<li class="level1">
<div class="li">added additional hardening to destructor protection</div>
</li>
<li class="level1">
<div class="li">added pointer obfuscation to memory manager</div>
</li>
</ul>
</div>
<div class="level3">The most important new feature is the pointer obfuscation inside the PHP memory manager. This mitigation makes it much harder to exploit lots of memory corruptions correctly. Pointer obfuscation is also used to protect the pointer to the read only configuration inside Suhosin-Patch that allows it to be configured by environment variables.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.suspekt.org/2010/03/05/suhosin-patch-0991/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Month of PHP Security - Blog Post Drawing</title>
		<link>http://www.suspekt.org/2010/03/05/month-of-php-security-blog-post-drawing/</link>
		<comments>http://www.suspekt.org/2010/03/05/month-of-php-security-blog-post-drawing/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 08:06:30 +0000</pubDate>
		<dc:creator>Stefan Esser</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[amazon]]></category>

		<category><![CDATA[coupon]]></category>

		<category><![CDATA[drawing]]></category>

		<category><![CDATA[MOPS]]></category>

		<category><![CDATA[php security]]></category>

		<category><![CDATA[win]]></category>

		<guid isPermaLink="false">http://www.suspekt.org/?p=338</guid>
		<description><![CDATA[While going through the HTTP_REFERER log of the Month of PHP Security website I realised that there are more incoming refers from various blog posts about it than there are submissions to drawing@php-security.org. Like I previously announced we will honor 10 blog postings with 25 EUR amazon coupons. The winners will be selected by random, [...]]]></description>
			<content:encoded><![CDATA[<p>While going through the HTTP_REFERER log of the <a href="http://php-security.org">Month of PHP Security</a> website I realised that there are more incoming refers from various blog posts about it than there are submissions to <a href="mailto:drawing@php-security.org">drawing@php-security.org</a>. Like I <a href="http://www.suspekt.org/2010/02/27/month-of-php-security-2010-call-for-papers/">previously announced</a> we will honor 10 blog postings with 25 EUR amazon coupons. The winners will be selected by random, however only among those we will select that announce their blogpost to us via the email address provided above.</p>
<p>The reasons for this rule is very simple. Without the announcement we would have to look at every new HTTP_REFERER and manually check if it is just spam, an old link to the Month of PHP Bugs, someone who just copied the blog of another person or other nonsense. In addition to that we have to find a contact address of the person who originally has written the entry and ask him/her if he/she wants to take part in the drawing. This would be too much work. Therefore announce your blog posting to <a href="mailto:drawing@php-security.org">drawing@php-security.org</a> or you have no chance of winning one of the coupons.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suspekt.org/2010/03/05/month-of-php-security-blog-post-drawing/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Patch breaks Suhosin Security Feature in Debian Unstable/Testing</title>
		<link>http://www.suspekt.org/2010/02/27/debian-breaks-suhosin-security-feature/</link>
		<comments>http://www.suspekt.org/2010/02/27/debian-breaks-suhosin-security-feature/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 18:52:46 +0000</pubDate>
		<dc:creator>Stefan Esser</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[broken]]></category>

		<category><![CDATA[debian security fail]]></category>

		<category><![CDATA[fail]]></category>

		<category><![CDATA[patch]]></category>

		<category><![CDATA[php security]]></category>

		<category><![CDATA[suhosin]]></category>

		<guid isPermaLink="false">http://www.suspekt.org/?p=325</guid>
		<description><![CDATA[Two days ago I installed a mail client on my reinstalled desktop system that was not doing anything for 2 month and checked mails of the hardened-php account that were not checked for 2 months. Usually noone uses this email account to contact me, but the Suhosin bug reports sometimes end up there. While killing [...]]]></description>
			<content:encoded><![CDATA[<p>Two days ago I installed a mail client on my reinstalled desktop system that was not doing anything for 2 month and checked mails of the hardened-php account that were not checked for 2 months. Usually noone uses this email account to contact me, but the Suhosin bug reports sometimes end up there. While killing thousands of SPAM messages I also found a message from the Debian PHP maintainers, dating back to the 10th February 2010, telling me about a crash problem inside the Suhosin patch. The email also contained their solution to the problem: a patch for the suhosin patch. You can view this patch <a href="http://git.debian.org/?p=pkg-php/php.git;a=blob;f=debian/patches/suhosin_page_size_fixes.patch">here</a>. However you should not commit this patch to your PHP because it does not solve the problem correctly.</p>
<p>I previously blogged about one of the <a href="http://www.suspekt.org/2009/08/13/suhosin-patch-098-for-php-530-beta-please-test/">new features</a> in Suhosin Patch for PHP 5.3.x. It is now possible to adjust several internal features by setting certain environment variables on startup. This includes the memory manager canary protection, the sanitization of free memory blocks, the protection of linked lists and hashtables. When a Suhosin patched PHP starts the environment variables are evaluated and the suhosin config is written into a variable called suhosin_config.</p>
<p>It should be obvious that this kind of feature comes with a little problem. Certain bytes in memory now control if Suhosin&#8217;s internal memory protections are activated or not. This means that a memory corruption vulnerability in PHP could be used by an attacker to overwrite the config variable and disable the security. Because of this Suhosin Patch tries to align the suhosin_config variable to a page boundary and then set it to read only.</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #808080; font-style: italic;">/* hack that needs to be fixed */</span>
<span style="color: #339933;">#ifndef PAGE_SIZE</span>
<span style="color: #339933;">#define PAGE_SIZE 4096</span>
<span style="color: #339933;">#endif</span>
&nbsp;
<span style="color: #339933;">#ifdef ZEND_WIN32</span>
__declspec<span style="color: #009900;">&#40;</span>align<span style="color: #009900;">&#40;</span>PAGE_SIZE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">#endif</span>
<span style="color: #993333;">char</span> suhosin_config<span style="color: #009900;">&#91;</span>PAGE_SIZE<span style="color: #009900;">&#93;</span>
<span style="color: #339933;">#if defined(__GNUC__)</span>
__attribute__ <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>aligned<span style="color: #009900;">&#40;</span>PAGE_SIZE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">#endif</span>
;
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> suhosin_write_protect_configuration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #339933;">#if defined(__GNUC__)</span>
   mprotect<span style="color: #009900;">&#40;</span>suhosin_config, PAGE_SIZE, PROT_READ<span style="color: #009900;">&#41;</span>;
<span style="color: #339933;">#endif</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The implementation has some problems. First of all it only works in case of a GNU C compiler. The second and more serious problem is that it assumes that the PAGE_SIZE is smaller than or equal to 4096. Otherwise mprotect() will not correctly work. On systems where the PAGE_SIZE is bigger than 4096 the mprotect() will either fail or set too many bytes to read only. In case of a write access after the suhosin_config variable this can lead to a crash.</p>
<p>The Debian people saw this crash on some architectures and reacted with a patch. However they did misunderstand the security idea behind it and therefore their patch looks like this.</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>suhosin_config <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> suhosin_write_protect_configuration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #339933;">#if defined(__GNUC__)</span>
   mprotect<span style="color: #009900;">&#40;</span>suhosin_config, sysconf<span style="color: #009900;">&#40;</span>_SC_PAGESIZE<span style="color: #009900;">&#41;</span>, PROT_READ<span style="color: #009900;">&#41;</span>;
<span style="color: #339933;">#endif</span>
<span style="color: #009900;">&#125;</span>
...
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>suhosin_config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   suhosin_config <span style="color: #339933;">=</span> mmap<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">NULL</span>, sysconf<span style="color: #009900;">&#40;</span>_SC_PAGESIZE<span style="color: #009900;">&#41;</span>, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, <span style="color: #cc66cc;">-1</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>;
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>suhosin_config <span style="color: #339933;">==</span> MAP_FAILED<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;suhosin&quot;</span><span style="color: #009900;">&#41;</span>;
      _exit<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>;
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The Debian maintainers tried to fix the problem by replacing the aligned suhosin_config variable with a pointer. They then allocate a single memory mapped page and set it to read only. While this fixes the possible crash it shows that the Debian PHP maintainers did not fully understand the idea behind that code. The patch ensures that the suhosin configuration is set to read only, but now a memory corruption exploit can just overwrite the suhosin_config pointer and let it point to a memory area that contains a new configuration.</p>
<p><del datetime="2010-02-28T18:44:06+00:00">A correct fix would be to check if the dynamic page size is indeed bigger than 4096 and in this case just warn the user that he should recompile PHP with a bigger PAGE_SIZE definition and do not set the variable to read only in this case. But this might arise the next problem that the PAGE_SIZE might exceed the maximum alignment that the compiler supports.</del></p>
<p><strong>UPDATE:</strong> I rewrote several parts of this blog entry to make it less critic and sound less aggressive. I spent the day discussing possible fixes and other problems with the current solution. The current solution is also not safe in all cases (all OS/architectures/compilers) because of intermediate pointers introduced by the compiler that are invisible at the C level. The solution to this is that the runtime configurability of Suhosin will become optional and can be selected at compile time. If the runtime configurability is selected the sysconf() method will be used to determine the correct page size. The pointer however will be protected by pointer obfuscation/encryption and maybe checksums.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suspekt.org/2010/02/27/debian-breaks-suhosin-security-feature/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Month of PHP Security 2010 - CALL FOR PAPERS</title>
		<link>http://www.suspekt.org/2010/02/27/month-of-php-security-2010-call-for-papers/</link>
		<comments>http://www.suspekt.org/2010/02/27/month-of-php-security-2010-call-for-papers/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 12:57:10 +0000</pubDate>
		<dc:creator>Stefan Esser</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[MOPS]]></category>

		<category><![CDATA[php security]]></category>

		<guid isPermaLink="false">http://www.suspekt.org/?p=319</guid>
		<description><![CDATA[I previously blogged a sneak preview of the Month of PHP Security which is a new initiative to improve security in the PHP ecosystem. Today the call for papers was released. Everyone from the PHP and security community is invited to produce quality articles/advisories about PHP security topics/bugs and submit them to the CFP committee.
The [...]]]></description>
			<content:encoded><![CDATA[<p>I previously blogged a <a href="http://www.suspekt.org/2010/02/19/sneak-preview-month-of-php-security-2010/">sneak preview</a> of the <a href="http://php-security.org">Month of PHP Security</a> which is a new initiative to improve security in the PHP ecosystem. Today the <a href="http://php-security.org">call for papers</a> was released. Everyone from the PHP and security community is invited to produce quality articles/advisories about PHP security topics/bugs and submit them to the CFP committee.</p>
<p>The event is generously sponsored by <a href="http://syscan.org">Syscan</a>, <a href="http://www.sektioneins.com">SektionEins</a> and <a href="http://www.codescan.com">CodeScan</a>. And the best submissions can win a number of attractive prizes. The first prize consists of 1000 EUR, a free Syscan ticket and a free CodeScan PHP License. For a full list of the submissions accepted and prizes available check out the website.</p>
<p>In case you are not a PHP security expert you can still help to improve the event. Spread the word about the Month of PHP Security in your blog, link to it and announce your blog posting at drawing@php-security.org and win one of ten 25 EUR amazon coupons.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suspekt.org/2010/02/27/month-of-php-security-2010-call-for-papers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sneak Preview: Month of PHP Security 2010</title>
		<link>http://www.suspekt.org/2010/02/19/sneak-preview-month-of-php-security-2010/</link>
		<comments>http://www.suspekt.org/2010/02/19/sneak-preview-month-of-php-security-2010/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 13:53:39 +0000</pubDate>
		<dc:creator>Stefan Esser</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[month of]]></category>

		<category><![CDATA[mopb]]></category>

		<category><![CDATA[php security]]></category>

		<guid isPermaLink="false">http://www.suspekt.org/?p=314</guid>
		<description><![CDATA[Three years ago the Hardened-PHP project organized the Month of PHP Bugs. During one month I disclosed more than 40 vulnerabilities in the PHP interpreter in order to improve the overall security of PHP. In the history of PHP this event has been one of a kind. But now, three years later, my company SektionEins [...]]]></description>
			<content:encoded><![CDATA[<p>Three years ago the <a href="http://www.hardened-php.net">Hardened-PHP</a> project organized the <a href="http://php-security.org">Month of PHP Bugs</a>. During one month I disclosed more than 40 vulnerabilities in the PHP interpreter in order to improve the overall security of PHP. In the history of PHP this event has been one of a kind. But now, three years later, my company <a href="http://www.sektioneins.com">SektionEins GmbH</a> will continue in the same spirit and organize the <a href="http://php-security.org">Month of PHP Security</a>. Our preparations are not finished yet, but here is a sneak preview of what it will be.</p>
<p>The <a href="http://php-security.org">Month of PHP Security</a> will take place in May 2010 and will be very different from all the previous &#8220;Month of Bugs&#8221; or &#8220;Week of Bugs&#8221; events. You can think of the Month of PHP Security as a conference without a conference. This means around the 1st of March we will send out a call for papers in order to collect the best advisories, the best research and the best articles about PHP security. We invite everyone from the PHP and from the security community to take part in this event.</p>
<p>The basic idea will be that during May we are planning to release (at least) one advisory or one research paper or one article about PHP security topics that were submitted to the public. And in the end of May our jury will select the best X submissions and give out prizes. We are still in the process of selecting good prizes and would be happy about more sponsors. <em>Therefore: If you consider this event to be a good idea to improve the security of PHP and want to sponsor prizes, do not hesitate to contact us at </em><strong>info@sektioneins.de</strong>.</p>
<p>The accepted topics will be:</p>
<ul>
<li>Advisory/Article about new vulnerability in PHP (with or without exploits) (no simple safe_mode, open_basedir bypass vulnerabilities)</li>
<li>Advisory/Article about vulnerability in PHP related software (popular 3rd party PHP extensions/patches, like Suhosin or Zend tools)</li>
<li>Detailed article about a single topic of PHP application security</li>
<li>Article about a complicated vulnerability in/attack against a widespread PHP application</li>
<li>Article about a complicated topic of attacking PHP (e.g. explain how to exploit heap overflows in PHP&#8217;s heap implementation)</li>
<li>Article about how to attack encrypted PHP applications</li>
<li>Release of a new PHP security tools</li>
<li>Other topics related to PHP (application) security</li>
</ul>
<p>Of course we will accept multiple submissions by the same person/team and there will most probably also be articles/advisories by ourself. (But of course we cannot win the prizes)</p>
<p>We at <a href="http://www.sektioneins.com">SektionEins</a> are already very excited about the event and hope it will be a success and once again improve the security of the PHP ecosystem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suspekt.org/2010/02/19/sneak-preview-month-of-php-security-2010/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Advisory 03/2009: Piwik Cookie unserialize() Vulnerability</title>
		<link>http://www.suspekt.org/2009/12/09/advisory-032009-piwik-cookie-unserialize-vulnerability/</link>
		<comments>http://www.suspekt.org/2009/12/09/advisory-032009-piwik-cookie-unserialize-vulnerability/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 12:50:13 +0000</pubDate>
		<dc:creator>Stefan Esser</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[analytics]]></category>

		<category><![CDATA[code exec]]></category>

		<category><![CDATA[exploit]]></category>

		<category><![CDATA[piwik]]></category>

		<category><![CDATA[tracking]]></category>

		<category><![CDATA[unserialize]]></category>

		<guid isPermaLink="false">http://www.suspekt.org/?p=304</guid>
		<description><![CDATA[I released an important advisory about a remotely exploitable unserialize() vulnerability in Piwik today.
                         SektionEins GmbH
                [...]]]></description>
			<content:encoded><![CDATA[<p>I released an important advisory about a remotely exploitable unserialize() vulnerability in Piwik today.</p>
<pre>                         SektionEins GmbH
                        www.sektioneins.de

                     -= Security  Advisory =-

     Advisory: Piwik Cookie Unserialize() Vulnerability
 Release Date: 2009/12/09
Last Modified: 2009/12/09
       Author: Stefan Esser [stefan.esser[at]sektioneins.de]

  Application: Piwik &lt;= 0.4.5
     Severity: Piwik unserializes() user input which allows an attacker
               to send a carefully crafted cookie that when unserialized
               utilizes Piwik's classes to upload arbitrary files or
               execute arbitrary PHP code
         Risk: Critical
Vendor Status: Piwik 0.5.0 was released which fixes this vulnerability
    Reference: <a href="http://www.sektioneins.de/en/advisories/advisory-032009-piwik-cookie-unserialize-vulnerability/">advisory-032009-piwik-cookie-unserialize-vulnerability</a>
               <a href="http://www.suspekt.org/downloads/RSS09-WebApplicationFirewallBypassesAndPHPExploits.pdf">RSS09-WebApplicationFirewallBypassesAndPHPExploits.pdf</a>
               <a href="http://www.suspekt.org/downloads/POC2009-ShockingNewsInPHPExploitation.pdf">POC2009-ShockingNewsInPHPExploitation.pdf</a>           

Overview:

  Quote from http://www.piwik.org
  "Piwik is a downloadable, open source (GPL licensed) web analytics
   software program. It provides you with detailed real time reports
   on your website visitors: the search engines and keywords they
   used, the language they speak, your popular pages… and so much more.

   Piwik aims to be an open source alternative to Google Analytics."

  Piwik recently became sourceforge project of the month and won the
  Infoworld Bossie Award for best open source enterprise software which
  made it quite popular. Therefore Piwik is nowadays installed on many
  high profile websites like: banking websites, political party websites,
  gaming websites, blogs and even security company websites.

  During our research in unserialize() vulnerabilities it was discovered
  that Piwik unserializes data from the user supplied cookie. By
  unserializing some of Piwik's objects it is possible to write
  arbitrary files to writable locations on the webserver which
  can be used to upload e.g. PHP files to writable directories
  within the webserver's document root which usually exist in a
  standard Piwik installation. In newer versions of Piwik it is
  also possible to execute arbitrary PHP code directly.

  Combined with the interruption vulnerability exploits demonstrated
  by SektionEins at Syscan and Blackhat it is possible to disable
  all internal PHP security protections and execute arbitrary code
  e.g. local kernel exploits to become root.

Details:

  SektionEins recently demonstrated how it is sometimes possible
  to execute arbitrary PHP code in an application using unserialize()
  on user supplied data. In detail various exploits were shown that
  work against all Zend Framework based applications that unserialize()
  user input. Part of this research was to find popular PHP open
  source applications that are vulnerable to this.

  During our search it was discovered that Piwik does unserialize()
  data from the cookie and uses parts of the Zend Framework:

  protected function loadContentFromCookie()
  {
    $cookieStr = $_COOKIE[$this-&gt;name];
    $values = explode( self::VALUE_SEPARATOR, $cookieStr);
    foreach($values as $nameValue)
    {
      $equalPos = strpos($nameValue, '=');
      $varName = substr($nameValue,0,$equalPos);
      $varValue = substr($nameValue,$equalPos+1);

      // no numeric value are base64 encoded so we need to decode them
      if(!is_numeric($varValue))
      {
        $varValue = base64_decode($varValue);

        // some of the values may be serialized array so we try to...
        if( ($arrayValue = @unserialize($varValue)) !== false
            // we set the unserialized version only for arrays...
            &amp;&amp; is_array($arrayValue)
            )
        {
          $varValue = $arrayValue;
        }
      }
      $this-&gt;set($varName, $varValue);
    }
  }

  While this allows to unserialize() user input the previously
  demonstrated exploits will not work on Piwik because only parts of
  the Zend Framework are shipped with the Piwik source code. Because
  of this we had to evaluate if Piwik's own classes can be utilized
  in exploits.

  When trying to exploit an unserialize() vulnerability in a PHP
  application the first step is to enumerate the objects that contain
  __wakeup() or __destruct() methods and read their code to analyze if
  these methods are doing something interesting.

  When looking at the Piwik source code one particular class can be
  found that allows writing arbitrary configuration files to the
  webserver. This class is called Piwik_Config and contains the
  following code.

  function __destruct()
  {
    if($this-&gt;configFileUpdated === true
        &amp;&amp; $this-&gt;doWriteFileWhenUpdated === true)
    {
      $configFile = "; &lt;?php exit; ?&gt; DO NOT REMOVE THIS LINE\n";
      $configFile .= "; file automatically generated or modified by "
                     "Piwik; you can manually override the default "
                     "values in global.ini.php by redefining them "
                     "in this file.\n";

      foreach($this-&gt;userConfig as $section =&gt; $arraySection)
      {
        $arraySection = $arraySection-&gt;toArray();
        $configFile .= "[$section]\n";
        foreach($arraySection as $name =&gt; $value)
        {
          ...
          $configFile .= $name.' = '.$value."\n";
          ...
        }
        $configFile .= "\n";
      }
      chdir($this-&gt;correctCwd);
      file_put_contents($this-&gt;pathIniFileUserConfig, $configFile );
    }
  }

  It should be obvious that when unserializing a Piwik_Config object
  it is possible to write arbitrary configurations to arbitrary
  locations by just setting the properties of the object correctly.
  However it should also be obvious that executing arbitrary PHP code
  is not that simple because the authors of Piwik add a show stopper
  to the beginning of every configuration file "; &lt;?php exit; ...".
  Because of this it is not possible to just write PHP code into a
  file and execute it.

  There is however a lesser known and nearly never used feature of PHP5
  that allows exploiting this situation. By using the PHP5 filter
  stream wrapper through the php://filter URI scheme it is possible to
  write arbitrary files to the server. By crafting a configuration
  filename like
  php://filter/write=convert.base64-decode/resource=/var/www/x.php it
  is possible to channel all writes to the file through a base64
  decoder. Because PHP does ignore invalid characters during base64
  decoding it is possible to destroy the show stopper by a single
  base64 decoding. By calculating how many base64 compatible characters
  are contained in the show stopper it is possible to find out how
  many padding bytes are necessary so that base64 injected PHP payload
  ends up correctly decoded in the written configuration file.

  Because the filter wrapper can be stacked several times before data
  is written to the actual file it is possible to construct payloads
  that do not only destroy the show stopper but also get rid of all the
  bytes. In current Piwik versions 5 times base64 decode is required
  for this. In earlier versions of Piwik there have been 3 different
  show stoppers strings. Therefore in order to exploit older Piwik
  versions different exploits are required.

  In order to execute arbitrary code it is possible to overwrite one
  of Piwik cache files and triggering a tracking event. Alternatively
  it is possible to first write a .htaccess file to one of the
  directories within Piwik's tmp directory that allows accessing its
  content and then dropping a PHP file in there.

  In the most recent Piwik version the Zend Framework components were
  upgraded which allows executing arbitrary PHP code directly. To
  achieve this the Zend_Log destructor is utilized.

  public function __destruct()
  {
    foreach($this-&gt;_writers as $writer) {
      $writer-&gt;shutdown();
    }
  }

  The Zend_Log destructor iterates through an array which it expects
  inside the _writers property. Each element of this array is then
  expected to have a method called shutdown() which is then executed.
  The next step in creating an exploit is to find classes that contain
  a shutdown() method. The best fitting class is Zend_Log_Writer_Mail.
  It is the same class that is also utilized in the generic Zend
  Framework exploit.

  public function shutdown()
  {
    // If there are events to mail, use them as message body.  Otherwise,
    // there is no mail to be sent.
    if (empty($this-&gt;_eventsToMail)) {
      return;
    }

    if ($this-&gt;_subjectPrependText !== null) {
      // Tack on the summary of entries per-priority to the subject
      // line and set it on the Zend_Mail object.
      $numEntries = $this-&gt;_getFormattedNumEntriesPerPriority();
      $this-&gt;_mail-&gt;setSubject(
      "{$this-&gt;_subjectPrependText} ({$numEntries})");
    }

    // Always provide events to mail as plaintext.
    $this-&gt;_mail-&gt;setBodyText(implode('', $this-&gt;_eventsToMail));

    // If a Zend_Layout instance is being used, set its "events"
    // value to the lines formatted for use with the layout.
    if ($this-&gt;_layout) {
      // Set the required "messages" value for the layout.  Here we
      // are assuming that the layout is for use with HTML.
      $this-&gt;_layout-&gt;events = implode('', $this-&gt;_layoutEventsToMail);

      // If an exception occurs during rendering, convert it to a notice
      // so we can avoid an exception thrown without a stack frame.
      try {
        $this-&gt;_mail-&gt;setBodyHtml($this-&gt;_layout-&gt;render());
      } catch (Exception $e) {
        ...
      }

      // Finally, send the mail.  If an exception occurs, convert ...
      // warning-level message so we can avoid an exception thrown ...
      // stack frame.
      try {
          $this-&gt;_mail-&gt;send();
      } catch (Exception $e) {
          ...
      }
  }

  This shutdown method will check if there are events not yet mailed
  and if there are, it will mail them to the address specified in the
  Zend_Mail object which has to be within the _mail property. This
  allows anyone to send out arbitrary spam to arbitrary mail addresses.
  However there is a more interesting exploiting path hidden here that
  once again utilizes the HTML rendering. Therefore an attacker has to
  find a class that contains a render method. The most promising class
  in case of Piwik is Piwik_View. Its render method will do a lot of
  things that can be ignored and finally call smarty to render the
  template.

  public function render()
  {
    try {
      ...
    } catch(Exception $e) {
      // can fail, for example at installation (no plugin loaded yet)
    }

    ...

    @header('Content-Type: text/html; charset=utf-8');
    @header("Pragma: ");
    @header("Cache-Control: no-store, must-revalidate");

    return $this-&gt;smarty-&gt;fetch($this-&gt;template);
  }

  Because most of the code in the render method is within a try and
  catch block it can be ignored. The only interesting part of the
  method is the fetch method called on the smarty property. Because
  smarty templates can execute PHP code the smarty class is the first
  one should look at and indeed smarty can be used to execute PHP
  code.

  function fetch($resource_name, $cache_id = null, ...)
  {
    ...
    if ($display &amp;&amp; !$this-&gt;caching &amp;&amp; count($this-&gt;_plugins['outputfilter']) == 0) {
      if ($this-&gt;_is_compiled($resource_name, $_smarty_compile_path)
          || $this-&gt;_compile_resource($resource_name, $_smarty_compile_path))
      {
        include($_smarty_compile_path);
      }
    } else {
    ...

  The supplied template name is then given to the _compile_resource
  method to compile the resource.

  function _compile_resource($resource_name, $compile_path)
  {

    $_params = array('resource_name' =&gt; $resource_name);
    if (!$this-&gt;_fetch_resource_info($_params)) {
      return false;
    }
    ...

  Before the resource is being compiled the _fetch_resource_info
  method is called to determine more information about the resource.

  function _fetch_resource_info(&amp;$params)
  {
    ...
    $_params = array('resource_name' =&gt; $params['resource_name']) ;
    ...

    if ($this-&gt;_parse_resource_name($_params)) {
      $_resource_type = $_params['resource_type'];
      $_resource_name = $_params['resource_name'];
      switch ($_resource_type) {
        case 'file':
          ...
          break;

        default:
          // call resource functions to fetch the template source and timestamp
          if ($params['get_source']) {
            $_source_return = isset($this-&gt;_plugins['resource'][$_resource_type]) &amp;&amp;
            call_user_func_array($this-&gt;_plugins['resource'][$_resource_type][0][0],
             array($_resource_name, &amp;$params['source_content'], &amp;$this));
          } else {
            $_source_return = true;
          }
          ...
        }

  The _fetch_resource_info method first calls _parse_resource_name to
  determine the type and name of resource. The expected format is
  resource_type:resource_name. For non file resources a function will
  be determined by a lookup in the _plugins[resource] lookup table
  that will be called to retrieve the resource data. Because all
  properties are attacker supplied an exploit can freely choose what
  function should be called.

  Because the called function is called with three parameters and only
  the first one is user supplied it gets a bit tricky to execute
  arbitrary PHP code. Calling eval() is not possible because it is a
  language construct and not a function and calling assert() instead
  will also fail, because it only accepts one parameter. The trick
  here is to use one of the methods inside the smarty class which is
  a wrapper around eval().

  function _eval($code, $params=null)
  {
    return eval($code);
  }

  While this function does only define two parameters in its signature
  it is possible to call this function with more than two parameters.
  The reason for this is that unlike internal functions that usually
  bail out when too many parameters are supplied internal functions
  will not do this because otherwise it would not be possible to have
  functions with an arbitrary number of parameters.

  So to summarize the attack: By carefully crafting a user supplied
  cookie it is possible to utilize Piwik's own objects and execute
  arbitrary PHP code by supplying the argument to an eval() statement.

Proof of Concept:

  SektionEins GmbH is not going to release a proof of concept
  exploit for this vulnerability.

Disclosure Timeline:

  28. November 2009 - Notified hello@piwik.org
  09. December 2009 - Piwik developers released Piwik 0.5.0
  09. December 2009 - Public Disclosure

Recommendation:

  It is recommended to upgrade to the latest version of Piwik.

  Grab your copy at:
  http://piwik.org/latest.zip

CVE Information:

  The Common Vulnerabilities and Exposures project (cve.mitre.org) has
  not assigned a name to this vulnerability.

GPG-Key:

  pub  1024D/15ABDA78 2004-10-17 Stefan Esser
  Key fingerprint = 7806 58C8 CFA8 CE4A 1C2C  57DD 4AE1 795E 15AB DA78

Copyright 2009 SektionEins GmbH. All rights reserved.</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.suspekt.org/2009/12/09/advisory-032009-piwik-cookie-unserialize-vulnerability/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SektionEins PHP Security Poster</title>
		<link>http://www.suspekt.org/2009/11/28/sektioneins-php-security-poster/</link>
		<comments>http://www.suspekt.org/2009/11/28/sektioneins-php-security-poster/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 18:44:13 +0000</pubDate>
		<dc:creator>Stefan Esser</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[free]]></category>

		<category><![CDATA[php security]]></category>

		<category><![CDATA[php security poster]]></category>

		<category><![CDATA[poster]]></category>

		<category><![CDATA[security audits]]></category>

		<category><![CDATA[security consulting]]></category>

		<category><![CDATA[security training]]></category>

		<guid isPermaLink="false">http://www.suspekt.org/?p=301</guid>
		<description><![CDATA[My company SektionEins that is specialised in web application security audits, consulting and trainings has finished the english translation of the PHP Security Poster. This poster is send out for free to interested PHP programmers (until out of stock). The poster is of DIN A0 size and details the most important aspects of configuring PHP [...]]]></description>
			<content:encoded><![CDATA[<p>My company <a href="http://www.sektioneins.com/">SektionEins</a> that is specialised in web application <a href="http://www.sektioneins.de/en/services/security-audits/index.html">security audits</a>, <a href="http://www.sektioneins.de/en/services/consulting/index.html">consulting</a> and <a href="http://www.sektioneins.de/en/services/training/index.html">trainings</a> has finished the english translation of the PHP Security Poster. This poster is send out for free to interested PHP programmers (until out of stock). The poster is of DIN A0 size and details the most important aspects of configuring PHP securely and writing secure PHP code.</p>
<div class="wp-caption aligncenter" style="width: 410px"><a href="http://www.sektioneins.de/en/php-security-poster-english/index.html"><img style="border:0" border="0" title="s1poster" src="http://www.sektioneins.de/gfx/s1poster.png" alt="SektionEins PHP Security Poster" width="400" height="357" /></a><p class="wp-caption-text">SektionEins PHP Security Poster</p></div>
<p>The poster contains the following topics:</p>
<p>* Vulnerabilities &amp; Concepts<br />
* Security Related PHP Funktionen<br />
* Secure Programming<br />
* Hardening the PHP Configuration<br />
* Server Protection with Suhosin</p>
<p>The order form for the poster is available <a href="http://www.sektioneins.de/en/php-security-poster-english/index.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suspekt.org/2009/11/28/sektioneins-php-security-poster/feed/</wfw:commentRss>
		</item>
		<item>
		<title>RSS09: Web Application Firewall Bypasses and PHP Exploits</title>
		<link>http://www.suspekt.org/2009/11/28/rss09-web-application-firewall-bypasses-and-php-exploits/</link>
		<comments>http://www.suspekt.org/2009/11/28/rss09-web-application-firewall-bypasses-and-php-exploits/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 17:52:51 +0000</pubDate>
		<dc:creator>Stefan Esser</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[bigip]]></category>

		<category><![CDATA[exploits]]></category>

		<category><![CDATA[modsecurity]]></category>

		<category><![CDATA[unserialize]]></category>

		<category><![CDATA[user input]]></category>

		<category><![CDATA[waf]]></category>

		<category><![CDATA[wafs]]></category>

		<category><![CDATA[web application firewalls]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.suspekt.org/?p=299</guid>
		<description><![CDATA[At yesterday&#8217;s RSS09 conference I gave a slightly different version of my &#8220;Shocking News in PHP Exploitation&#8221; talk. This time I disclosed for the first time how unserializing user input in Zend Framework based applications can result in direct remote PHP code execution.
The topics of my talk were

easy ways to bypass modsecurity and f5 big [...]]]></description>
			<content:encoded><![CDATA[<p>At yesterday&#8217;s RSS09 conference I gave a slightly different version of my &#8220;Shocking News in PHP Exploitation&#8221; talk. This time I disclosed for the first time how unserializing user input in Zend Framework based applications can result in direct remote PHP code execution.</p>
<p>The topics of my talk were</p>
<ul>
<li>easy ways to bypass modsecurity and f5 big ip</li>
<li>executing PHP code on Zend Framework based applications that unerialize user input</li>
<li>how to still exploit PHP interruption vulnerabilities after recent fixes in PHP</li>
</ul>
<p>You can grab my new slides <a href="http://www.suspekt.org/downloads/RSS09-WebApplicationFirewallBypassesAndPHPExploits.pdf">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suspekt.org/2009/11/28/rss09-web-application-firewall-bypasses-and-php-exploits/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Shocking News in PHP Exploitation</title>
		<link>http://www.suspekt.org/2009/11/28/shocking-news-in-php-exploitation/</link>
		<comments>http://www.suspekt.org/2009/11/28/shocking-news-in-php-exploitation/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 17:43:54 +0000</pubDate>
		<dc:creator>Stefan Esser</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[korea]]></category>

		<category><![CDATA[exploits]]></category>

		<category><![CDATA[poc2009]]></category>

		<category><![CDATA[unserialize]]></category>

		<guid isPermaLink="false">http://www.suspekt.org/?p=294</guid>
		<description><![CDATA[On 5th of November I gave a talk titled &#8220;Shocking News in PHP Exploitation&#8221; at the Powerofcommunity hacking/security conference in Seoul, South Korea. Afterwards I uploaded my slides to this server but only distributed the link through twitter. I totally forgot about announcing the slides in my blog.
The topics of my talk were

easy ways to [...]]]></description>
			<content:encoded><![CDATA[<p>On 5th of November I gave a talk titled &#8220;Shocking News in PHP Exploitation&#8221; at the Powerofcommunity hacking/security conference in Seoul, South Korea. Afterwards I uploaded my slides to this server but only distributed the link through twitter. I totally forgot about announcing the slides in my blog.</p>
<p>The topics of my talk were</p>
<ul>
<li>easy ways to bypass modsecurity and f5 big ip asm</li>
<li>exploiting unserialize vulnerabilities in Zend Framework applications</li>
<li>exploiting PHP interruption vulnerabilities after recent fixes in PHP</li>
</ul>
<p>The slides are available <a href="http://www.suspekt.org/downloads/POC2009-ShockingNewsInPHPExploitation.pdf">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suspekt.org/2009/11/28/shocking-news-in-php-exploitation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CGNSec October 2009</title>
		<link>http://www.suspekt.org/2009/10/07/cgnsec-october-2009/</link>
		<comments>http://www.suspekt.org/2009/10/07/cgnsec-october-2009/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 20:11:52 +0000</pubDate>
		<dc:creator>Stefan Esser</dc:creator>
		
		<category><![CDATA[CGNSec]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[fun]]></category>

		<category><![CDATA[it-security]]></category>

		<category><![CDATA[meeting]]></category>

		<guid isPermaLink="false">http://www.suspekt.org/?p=292</guid>
		<description><![CDATA[I am pleased to announce that Thursday 22th of October 2009 at 19:30 there will be the 10th CGNSec meetup in Cologne/Germany. The meeting takes place at Hallmackenreuther, Brüsseler Platz 9, 50674 Köln (Google Maps).
Everyone working in the field of information security is invited to attend. If you are attending the first time it is [...]]]></description>
			<content:encoded><![CDATA[<p>I am pleased to announce that Thursday 22th of October 2009 at 19:30 there will be the 10th <a href="http://www.cgnsec.de">CGNSec</a> meetup in Cologne/Germany. The meeting takes place at Hallmackenreuther, Brüsseler Platz 9, 50674 Köln (<a href="http://www.google.com/maps?q=Hallmackenreuther%2c%20Br%c3%bcsseler%20Platz%209,50674,K%c3%b6ln,Germany">Google Maps</a>).</p>
<p>Everyone working in the field of information security is invited to attend. If you are attending the first time it is best to send me an email beforehand to ensure that you find us. Otherwise search for the table that has the most fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suspekt.org/2009/10/07/cgnsec-october-2009/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
