Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


March 07, 2007

Secure PHP Configuration

RSS
Subscribe to Windows IT Pro | See More Security Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

A Month of PHP Bugs was launched March 1. If you missed last week's editorial about this initiative, you can read it on our Web site at the URL below. Be sure to also read the related news item "5 Vulnerabilities Kick Off Month of PHP Bugs," which you can link to from the Security News and Features section below.

http://www.windowsitpro.com/Article/ArticleID/95328

So far, Stefan Esser has posted several interesting vulnerabilities on his Month of PHP Bugs site, some of which you can avoid by specific practices. If you use PHP on your server, then you need to examine its configuration to make sure you're not overly exposing aspects of the engine, which could in turn expose your entire system and possibly other parts of your network.

If your Web system is closed (i.e., you don't allow others to upload or create any files), your potential security risks are more limited than if it's open. Either way, you need to take precautions to ensure that certain functions aren't usable unless you intend for them to be used.

One example is that PHP can allow the use of the exec and shell_exec functions, which essentially let you run OS commands and retrieve the output. I've used the shell-exec function to good advantage. I had an account with a Web hosting company, which had a server that would frequently slow to a crawl, making nearly all access impossible. I grew tired of the support staff's vague explanations and decided to investigate the problem myself.

With the help of the shell_exec function (and a few others), I could use PHP to look at a lot of the server's operational characteristics. I discovered the bottleneck, contacted support, and alluded to the problem. I figure the support team members scratched their heads for a couple months wondering how I knew what was happening before they finally wised up and disabled the shell_exec function.

In another example, I signed up for a blog at a popular site, which will remain unnamed here. I wanted specific blog functionality that wasn't available, so I went to work on a way around the limitations. I discovered that this site too allowed dangerous functions to operate. With a little work, I could navigate nearly the entire server disk subsystem at will, read configuration files, discover path information, and then manipulate my blog to gain the functionality I wanted by using the information I had gathered to enable my custom scripts to run. Eventually, the site staff figured out what was happening and disabled many dangerous functions.

In addition to exec and shell-exec, some dangerous PHP functions are suexec, passthru, proc_open, proc_close, proc_get-status, proc_nice, proc_terminate, system, popen, pclose, dl, ini_set, virtual, set_time_limit, apache_child_terminate, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid, posix_setuid, escapeshellcmd, and escapeshellarg. Go to this URL for other potentially dangerous functions:

http://www.phpbuilder.com/manual/features.safe-mode.functions.php

You can disable functions by adding (or editing) a line in your php.ini file like this:

disable_functions = "shell_exec, suexec, passthru"

More help for configuring PHP can be found at these URLs:

Ayman Hourieh's Blog

http://aymanh.com/checklist-for-securing-php-configuration

WEB-DOT-DEV--PHP Configuration

http://www.webdotdev.com/nvd/server-side/php/php-configuration.html

PHP Manual

http://us2.php.net/manual/en/security.php

PHP Security Consortium's PhpSecInfo

http://phpsec.org/projects/phpsecinfo/

Finally, a good resource with lots of other links (including books) is available at the PHP Security Consortium's Web site:

http://phpsec.org/library/

End of Article



Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Where is Microsoft NetMeeting in Windows XP?

...


Security Whitepapers Reducing the Costs and Risks of Branch Office Data Protection

Solving Desktop Management Challenges in Healthcare

Solving Desktop Management Challenges in Education

Related Events Oracle Developer Day Online - EUROPE

PowerShell 201 - eLearning Series with Paul Robichaux

Introduction to Identity Lifecycle Manager "2"

Check out our list of Free Email Newsletters!

Security eBooks Spam Fighting and Email Security for the 21st Century

Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

Related Security Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement