How To Harden PHP5 With Suhosin On CentOS 5.0

Version 1.0
Author: Falko Timme

This tutorial shows how to harden PHP5 with Suhosin on a CentOS 5.0 server. From the Suhosin project page: "Suhosin is an advanced protection system for PHP installations that was designed to protect servers and users from known and unknown flaws in PHP applications and the PHP core. Suhosin comes in two independent parts, that can be used separately or in combination. The first part is a small patch against the PHP core, that implements a few low-level protections against bufferoverflows or format string vulnerabilities and the second part is a powerful PHP extension that implements all the other protections."

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I have tested this on a CentOS 5.0 server with the IP address 192.168.0.100.

I will install both Suhosin parts in this tutorial, the Suhosin patch (for which we need to recompile PHP5) and the Suhosin PHP extension. To see what Suhosin can do, please refer to http://www.hardened-php.net/suhosin/a_feature_list.html. The features of the Suhosin patch are listed under Engine Protection (only with patch); all the other features come with the Suhosin extension.

 

2 Installing Apache2 And PHP5 (Optional)

(This chapter is optional if you already have Apache2 and PHP5 installed - please skip to the next chapter.)

If you don't have Apache2 and PHP5 installed on your server, install it now:

yum install httpd php php-devel

Then create the system startup links for Apache2 and start Apache2:

chkconfig --levels 235 httpd on
/etc/init.d/httpd start

You now have a PHP5 with basic functionality on your server; if you need special PHP5 modules, you can search for them like this:

yum search php

From the output, pick the modules you need, install them like this and restart Apache2:

yum install php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc
/etc/init.d/httpd restart

 

3 Getting Details About Your PHP5 Installation

Unless you have already created virtual hosts in your Apache installation, the document root of the default web site is /var/www/html. We will now create a small PHP file (info.php) in that directory (if you have created virtual hosts, place it in any of the virtual hosts that has PHP enabled) and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /var/www/html/info.php
<?php
phpinfo();
?>

Now we call that file in a browser (e.g. http://192.168.0.100/info.php):

As you see, our PHP version is 5.1.6, and Suhosin is not mentioned anywhere on that page which means it is not installed.

Share this page:

0 Comment(s)