This blog includes company news, company statements, tutorials, guides and much more. So please add this blog to your RSS reader and let us help you to become better security professionals.
Disclaimer: The views of individual bloggers may not be the views of Aconiac as a whole.
Have you ever been on the road towards a meeting or a vacation, and then just suddenly stumbled upon an open network while waiting for a plane or drinking a cup of coffee? Most people probably have..
And have you even been a bit too tempted and logged onto this open network? Again, most probably have.
Now, have you then started working while on this network and directly sent corporate information or handled information on your corporate systems? Sadly, many have and if you’re one of them: Read on! Using open networks directly for sensitive data (like corporate data) is a big security no-no!
So why would this be a problem? Isn’t it just free internet for the masses? Well, yes and no. Yes it’s probably a network you are completely free to use. It might even be a network owned by the office building, hotel, airport or which ever company you’re at. But due to the way wifi-networks are designed, everything you send over this network is completely public. Every person, on the network or simply in the vicinity, can easily set up a simple network scanner like Wireshark or Kismet and directly save all the information you send over this network, including all e-mails, websites you visit, data you send to websites, data you receive – plain and simply everything! And you have no way of detecting this! None what so ever! There is absolutely no way to check for eavesdroppers on an open unencrypted network.
To add insult to injury, eavesdropping on a network is extremely easy to do and there are several easy to use tools out there that hordes of 15 year old script kiddies love to use to steal as much information as they possibly can – for no other reason than: They can!
So are we advocating not using public open wifi-networks? No, not at all – you just need to use them correctly!
You can look at it like this: A public open wifi-network gives you a gateway on which you can build a connection to your workplace and work from there. How do you do this? Well basically there are several solutions here:
So you can look at it like this: If you’re not doing any of the above, you have a problem and should take it up with your company in order to get a security policy on the matter and making it safe for the company to work from anywhere! Mobility is one of the top priorities in business these days, and you really want to use the opportunities laid before you well, without screwing yourself because of bad security.
So remember: Public open networks aren’t bad, but you need to keep your assets safe while using them!
As we’ve covered in an earlier blogpost (http://blog.aconiac.com/2009/07/29/ruby-on-rails-security-guide/) OWASP is an organization working to improve web application security in the entire world, by means of a whole bunch of different free projects for developers, security professionals and end users.
A few weeks ago, OWASP released a guide/article with the title “Secure Application Development on Facebook”, basically giving an outline of the security concerns involved in Facebook App development and how to make sure your application is sufficiently secure.
The guide/article can be found here: http://www.owasp.org/index.php/Facebook. The document is mainly designed for Facebook App developers, but can also be useful for decision makers wanting to understand the security architecture on Facebook (however certain sections should probably be skipped).
We highly recommend any company interested in Facebook Apps to read the guide from start to finish, and make it mandatory training for all Facebook related developers.
This is just one of many wonderful OWASP projects and in future blog posts we will look at some of the other great tools that are available to you, completely free of charge. If for some reason you don’t want to wait for these future blog posts, you can also just take a peak the the available projects straight away at: http://www.owasp.org/index.php/Category:OWASP_Project
If you’ve ever programmed anything in PHP before, you’ve probably had situations where you needed to be careful with your scripts to make sure they were secure. (and if you haven’t, you probably have but just haven’t noticed)
Making secure code is often times not as easy as you would hope, and while PHP does provide certain methods to help you in your task, it still lets much of the hassle be up to you as the programmer. This construction, combined with the amount of PHP sites out there, leads to the sad fact that many insecure websites are written in PHP. And while your own website may be totally secure, perhaps because you read guides like PHP Security Guide from PHP Security Consortium, there is absolutely no guarantee hosting users on your hosting server will do the same – so you need to protect yourself!
Protecting your server, and more importantly the users on it, is really a matter of several things. You need to make sure only the services you need are running, you need to secure access routes to the server (ssh, vnc, rdp etc.), you need to put in surveillance and detection systems (Nagios, Tripwire, Snort etc.), you need to make sure the data is backed up at all times, you need a proper firewall and tons of other things. Covering all these topics is way beyond this simple post however, so we’ll only focus on protecting yourself against badly coded PHP-scripts.
If a hosting user has a website on your server, say http://www.example.org/, and on this site he creates some PHP script that loads in a file and displays this in some way. Now this is obviously a stupid example, because when would you actually need this functionality? None the less, including files like this is sadly often times done indirectly, making it possible for an attacker to load in arbitrary files and gain full or partial access to the file content. In this example however we’ll simply look at a scheme like the following:
http://www.example.org/script.php?filename=test.txt
Where this script then loads in the content from test.txt.
This kind of setup is very problematic, because an attacker can easily take the request above and change it to load other files like:
http://www.example.org/script.php?filename=../../../../etc/passwd
http://www.example.org/script.php?filename=../../vhosts/someothersite.com/secretfile.php
Where the first one loads the password file on the server (it actually only includes usernames, passwords are in another file – but you get the point) and the second one could be perhaps a configuration file for another hosting user’s blog. This way the attacker could gain access to a complete list of users and some login information for another customer.
Both these situations are obviously unacceptable, and while you can’t protect your users from themselves (at least not easily), you can protect your good users from your more reckless users.
One way of doing this is by utilizing what’s called a chroot. Chrooting basically means taking an application and forcing it to do it’s work solely within a given directory, so that i.e. Apache was only allowed to function inside “/chroot/apache” and nowhere else. This prevents websites running on Apache from reading (and writing) files outside this chroot, so that an attacker can’t use the above attack to read the password file. Setting up such chroots aren’t always that easy, since everything Apache uses during runtime needs to be available in the chroot. One project has however attempted to make chrooting Apache much easier. This project is the Web Application Firewall Mod-Security, which can be found here. They use the so called SecChroot option to easily chroot your Apache.
Chrooting doesn’t however prevent a site in the chroot from reading data in another site stored in the same chroot. To prevent this kind of attack, you’d have to logically separate each running virtual host, by either setting up a dedicated Apache chroot for each virtual host (a bad solution) or use something called suPHP. By means of suPHP, which can be found here, we can make Apache run PHP scripts under the permissions of the owners of the scripts, instead of the normal Apache user which is shared between all virtual hosts. By doing this, we effectively make each virtual host able to only read/write files in its own directory and not spy on other virtual hosts data (assuming these have set correct permissions).
But what if we don’t trust this is enough? What if we want to be completely sure, that even if users set wrong permissions, a given user could still never read or write in another users virtual host? This can be accomplished by means of the php open_basedir option. The open_basedir option can be used to control in which directory the PHP scripts of a virtual host can work. This effectively means we’re actually chrooting the PHP scripts! The way you do this, is that you open up your virtual host configuration (which is probably stored somewhere like “/etc/apache2/vhosts/somevhostcom.conf”) and you then add the following within the <VirtualHost></VirtualHost> pair:
php_admin_value open_basedir /var/chroot/apache/vhosts/somevhost.com
Where “/var/chroot/apache/vhosts/somevhost.com” is the location of the virtual host directory. (be aware: If you’ve chrooted Apache, this path needs to be relative to the chroot and not the actual system).
Using open_basedir is not without it’s problems though. By making the PHP scripts run in what is effectively a chroot, they can’t i.e. write to the /tmp directory, which basically means file uploads won’t work. Be aware that chrooting in general can often lead to these types of issues, which is also why many server administrators just simply choose to take the risk and run Apache without chrooting.
Last but not least you can also use Mod-Security as what it was created as – a Web Application Firewall. A Web Application Firewall is a software firewall placed onto Apache, which then uses a complicated rule set to analyze traffic to the server and identify what kind of traffic is an attack and what is just normal use. These rules however have to be written, at least to some extent, manually and there are issues regarding making rules that catch illegal behavior but never stops legal requests – usually you have to accept some level of false-positives in attack detection if you want to be as secure as you can be.
That’s it! We hope you’ve become a bit more informed now and can get on with making your server secure against bad php scripts. Until next time – Keep safe!