Dutch PHP Conference: The Slides

June 16th, 2009 by Stefan Esser


At this years Dutch PHP Conference I presented a PHP Security Crash Course for beginners and a session about secure programming with the Zend Framework. You can download all the slides from here.

PHP Security Crash Course for beginners

Secure Programming with the Zend Framework

Enjoy the slides and shoot any questions or improvement ideas my way…

Speaking at Blackhat Briefings 2009 in Las Vegas

June 7th, 2009 by Stefan Esser

Three weeks after I present my research about advanced post exploitation in hardened PHP environments at SyScan in Singapore and Taipei, I will present a similar session at this year’s Blackhat Briefings 2009 in Las Vegas. The session will be a little bit different from the one at SyScan because I will have a few more minutes to present. If you want to see some PHP memory corruption voodoo in action and cannot attent SyScan you should come to Las Vegas.

Session: State of the Art Post Exploitation in Hardened PHP Environments

When an attacker manages to execute arbitrary PHP code in a web application he nowadays often ends up in hardened PHP environments that not only make use of PHP’s internal protections like safemode, openbasedir or disable_functions but also make use of Suhosin and operating system, filesystem or libc level security mechanisms like ASLR, NX, hardened memory managers or unix file permissions.

In such a situation taking over the server becomes a challenge and requires PHP shellcode that is able to use local PHP exploits to get around these protections. This talk will show the problems arising from the different protection mechanisms for PHP shellcode, will give an insight into the internal memory structures of PHP that are required to write stable local exploits and will demonstrate how a special class of vulnerabilities in PHP that also exists in standard functions enables PHP shellcode to get around most of these protections.

See you in Las Vegas between 29rd and 30rd.

European Parliament Election 2009

June 7th, 2009 by Stefan Esser

Today there is the european parliament election 2009 in germany and around 11:55 I went to the St. Nikolaus elementary school here in cologne to vote. For me it was the first time to vote in this district and therefore I was happy that several other people were heading in the same direction, which allowed me to just follow them.

Once in the building there were lots of signs directing you to the room. And then something happened that makes you really wonder about the strength of our system. I gave the letter that contains the invitation to vote (Wahlbenachrichtigung) to the girl sitting behind the desk and she started looking me up in their book.

After she found me I was allowed to vote. They did not check my id or my passport.

So in my district you can obviously vote for others just by stealing their letter of invitation…

Speaking at SyScan 2009 Singapore and Taipei

April 28th, 2009 by Stefan Esser

I will present a session at this year’s SyScan 2009 in Singapore and also in Taipei. The session is about my research into advanced post exploitation in hardened PHP environments. If you want to see some PHP memory corruption voodoo you should see it.

Session: State of the Art Post Exploitation in Hardened PHP Environments

When an attacker manages to execute arbitrary PHP code in a web application he nowadays often ends up in hardened PHP environments that not only make use of PHP’s internal protections like safemode, openbasedir or disable_functions but also make use of Suhosin and operating system, filesystem or libc level security mechanisms like ASLR, NX, hardened memory managers or unix file permissions.

In such a situation taking over the server becomes a challenge and requires PHP shellcode that is able to use local PHP exploits to get around these protections. This talk will show the problems arising from the different protection mechanisms for PHP shellcode, will give an insight into the internal memory structures of PHP that are required to write stable local exploits and will demonstrate how a special class of vulnerabilities in PHP that also exists in standard functions enables PHP shellcode to get around most of these protections.

See you in Singapore between 2nd and 3rd July and in Tapei between 7th and 8th July.

Speaking at Dutch PHP Conference 2009

April 28th, 2009 by Stefan Esser

I will present a session and a workshop at this year’s Dutch PHP Conference 2009 in Amsterdam. The session is about writing secure PHP applications with the Zend Framework and the workshop is a PHP security crash course for beginners. Don’t expect any magic. If you want to see PHP voodoo you need to attend SyScan Singapore 2009.

Workshop: PHP Security Crash Course

This workshop is meant for PHP programmers that know the basics of PHP but have no or only a bit insight into the security problems they have to deal with when developing web applications. During the workshop the most important subjects of web application security will be introduced, which are:

  • Input filtering
  • Cross Site Scripting (XSS)
  • Cross Site Request Forgery (CSRF)
  • SQL Injection
  • Session Managament
  • PHP Code Inclusion and Evaluation

Every subject will be introduced from the attacker’s and the programmer’s point of view, because for an effective defense it is vital to understand the tricks of the offense.

Session: Secure Programming with the Zend Framework

More and more PHP developers are using the Zend Framework when developing new applications. Because of guidelines and features of the framework the process to develop secure PHP applications changes.

This session will introduce which features of ZF help to develop secure applications, how they are used and what security problems you still have to solve on your own.

See you in Amsterdam between 11th and 13th June.

Speaking at International PHP Conference 2009 Spring Edition

April 28th, 2009 by Stefan Esser

I will present two sessions at this year’s International PHP Conference 2009 - Spring Edition in Berlin about Bytekit and writing secure PHP applications with the Zend Framework.

Session: Bytekit - An open source toolset to work with PHP bytecode

Bytekit is a PHP extension that allows PHP applications to directly read the PHP Bytecode. It comes with a bytecode disassembler and also provides control flow information that allows drawing control flow graphs.

In this session all of Bytekits features will be introduced and several smaller examples will be presented that show how some security problems can be detected with it in source code.

Bytekit will become open source during the conference.

Session: Secure Programming with the Zend Framework

More and more PHP developers are using the Zend Framework when developing new applications. Because of guidelines and features of the framework the process to develop secure PHP applications changes.

This session will introduce which features of ZF help to develop secure applications, how they are used and what security problems you still have to solve on your own.

See you in Berlin between 25th and 27th May.

CGNSec - Fifth Meeting in Cologne

April 27th, 2009 by Stefan Esser

I just wanted to announce that this wednesday (29th of April 2009) at 19:30 there will be the fifth CGNSec meetup in Cologne/Germany. With Eurocrypt 2009 in town we hope that some of the security researchers from there will join us.

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. To find us, just ask for the tables reserved for CGNSec.

The Month of Java Bugs

April 1st, 2009 by Stefan Esser

I just wanted to announce that two years after the Month of PHP Bugs the same crew is back to organise the Month of Java Bugs in May 2009. In days were more and more researchers join the nomorefreebugs campaign this initiative will provide Java security bugs for free, day by day throughout a whole month.

Enjoy a very dark coffee in May 2009…

UPDATE: Sorry the Month of Java Bugs was only an April Fool’s Day joke :P

Some facts about the PHPList vulnerability and the phpbb.com hack

February 6th, 2009 by Stefan Esser

A few days ago phpbb.com was hacked through a super-globals-overwrite vulnerability in PHPList that was used by an attacker for a local file inclusion exploit. Details about the whole attack, written down by someone who claims to be the attacker, can be read here. From the explanation it seems that the PHP installation on phpbb.com was more or less a default one that was not hardened against attacks at all, but I will get into this later.

First I want to shed some light on the super-globals-overwrite vulnerability in PHPList that was wrongly attributed a local file inclusion vulnerability in so many places (including the PHPList announcement). Responsible for the attack is the following code in admin/index.php:

if (!ini_get("register_globals") 
          || ini_get("register_globals") == "off") {
   # fix register globals, for now, should be phased out gradually
   # sure, this gets around the entire reason that register globals
   # should be off, but going through three years of code takes a long time....
   foreach ($_REQUEST as $key => $val) {
      $$key = $val;
   }
}
...
if (isset($_SERVER["ConfigFile"]) && is_file($_SERVER["ConfigFile"])) {
   print '<!-- using '.$_SERVER["ConfigFile"].'-->'."\n";
   include $_SERVER["ConfigFile"];
}

This code will detect if register_globals is turned off (which is the default since PHP 4.2) and in that case emulate register_globals by globalising everything within the _REQUEST array. Code similar to this is used by many projects to emulate register_globals=on. Usually this is done as a quick hack to make software work when register_globals=off. The comment proves that this is also the case for PHPList.

The problem here is that the foreach loop above does not contain any kind of sanity check which allows attackers to overwrite all the super-global-variables (like GLOBALS, _SERVER, _ENV, …) by supplying new values for them through either the URL, the POST data or through the COOKIE. For the code above this also means an attacker can also overwrite the value of $_SERVER['ConfigFile'] from the outside. This gives the attacker full control over an include statement, which allows him to include arbitrary files.

Unfortunately the original exploit author, the PHPList team and many other people still believe that using is_file() or file_exists() around the file to include is enough to ensure that it is a local file. Therefore the original exploit and also the PHPList security announcement wrongly assume this is a local file inclusion problem. In reality however is_file() and file_exists() also work on PHP’s URL wrappers if the wrapper implements the stat() call. PHP’s HTTP(S)/DATA/PHP://INPUT URL wrappers do not support this. But since PHP 5.0 the FTP URL wrapper does support this and therefore _SERVER['ConfigFile'] allows a normal remote file inclusion through the FTP protocol.

More importantly neither the original exploit writer, nor the PHPList team or anyone else reporting about it have realised that the problem is bigger than _SERVER['ConfigFile'] and therefore it is not suprinsing that the fix by PHPList is just a hack that fixes a single exploit but not the problem.

if (isset($_REQUEST['_SERVER'])) { exit; }

This code does obviously protect the _SERVER variables only. All the other super-global-variables are still unprotected. Because of this it is still possible to perform LFI/RFI and SQL-Injection attacks against the latest PHPList release by just overwriting other super-globals.

Protection

This attack was only possible because the PHP installation of phpbb.com was not configured securely. Multiple applications on the same server should be isolated from each other. Activating open_basedir*, which is a simple PHP configuration option, would have been good enough to stop PHPList from including avatar files uploaded to the PHPBB installation. Additionally disabling allow_url_fopen/allow_url_include in combination with the is_file() check would have stopped a possible remote file inclusion attack. However SQL-Injection attacks would through the super-globals-overwrite would still be possible.

On the other hand there is a simple way to protect a server against super-globals-overwrite vulnerabilities: Just install the Suhosin PHP security extension. It will detect, log and stop this kind of super-globals-overwrite. If you ask me any admin installing a vanilla PHP without Suhosin patch and extension is careless anyway.

Attention

*open_basedir - don’t get me wrong - open_basedir is not secure when it comes to protect a server against a malicious users/PHP scripts, but it makes exploiting local file inclusion attacks a lot harder.

CGNSec - Third Meeting in Cologne

December 31st, 2008 by Stefan Esser

I just wanted to announce that next wednesday (7th of January 2009) at 19:30 there will be the third 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. To find us, just ask for the tables reserved for CGNSec.