Cre Loaded Template
( 19476 ) May 31, 2008
By Jordan Dimov
PHP has achieved a stable and solid presence on the Web in the last several years, and its popularity as a server-side scripting language is only increasing. Its primary use is for providing dynamically generated interfaces between Web users and the host. As such, PHP scripts fall a natural prey to many Internet attacks. Despite the fact that the language is designed with security in mind, a familiarity with its more dangerous aspects and conformance to common secure programming guidelines is essential to minimizing the possibility of security compromises. The aim of this document is to provide an overview of various security issues with PHP and to offer advice on secure PHP programming practices.
Introduction
PHP (PHP Hypertext Preprocessor) is a server-side scripting language that facilitates the creation of dynamic Web pages by embedding PHP-coded logic in HTML documents. It combines many of the finest features of Perl, C, and Java, and adds its own elements to the concoction to give Web programmers great flexibility and power in designing and implementing dynamic, content-oriented Web pages. As with any powerful tool however, there are certain risks and dangers associated with the use of PHP. This article aims to alert the reader of such subtle details of the language. By being aware of the risks and observing some simple secure programming rules, it is possible to significantly lower the risk of security compromises.
In the following sections, we will identify a number of causes that commonly lead to violations of the security of PHP scripts and ultimately the systems on which these scripts are executing. We will then develop some guidelines for strengthening the security of PHP and for writing secure code. Web developers and system administrators should keep in mind, however, that these guidelines only identify some practices that can reduce the risk of security compromises. There isn't a definite omnipotent solution to all security problems, and in fact, the very concept of a system that is in a fully secure state is rather ethereal. Instead, security should be viewed as an evolving process, requiring constant supervision. This article provides a basis for understanding the security issues related to PHP and gives a broad overview of the topic.
Sources of Security Breaches
PHP can be run as either a CGI application or as an integrated Web server module. Regardless of its mode of execution, the PHP interpreter has the potential to access virtually every part of the host -- the file system, network interfaces, IPC, etc. Consequently, it has the potential to do (or be forced to do) a lot of damage. To prevent attacks from adversaries, the programmer needs to be aware of everything that can go wrong at any time during the program execution. This is a formidable task. Software gets very complicated very fast. Nevertheless, knowledge of the weaknesses of a system and the common modes of attack can go a long way toward increasing its security. This applies to PHP just as much as it applies to any other piece of software. Therefore, in this section we will examine various sources of potential security vulnerabilities in PHP scripts and will draw some generalized conclusions. We will use this information in a later section to develop a set of guidelines for secure PHP programming.
Trusting User Input
The most common and most severe security vulnerabilities in PHP scripts, and indeed in any Web application, are due to poorly validated user input. Many scripts use information that the user has provided in a Web form and process this information in various ways. If this user input is trusted blindly, the user has the potential to force unwanted behavior in the script and the hosting platform.
To make things worse, PHP registers all kinds of external variables in the global namespace. Environment variables for example are simply accessible by their name from anywhere within a script. So you can just peek at $HOSTNAME and $PATH for such pieces of information. Field tag names submitted from GET or POST forms are also accessible in the same manner. There are several problems with this. First, there is really no way to ensure that those external variables contain authentic data that can be trusted. (The next section discusses this in greater detail.) Second, due to the habit of PHP to make everything globally available, no variable can be trusted anymore, whether external or internal. Indeed, imagine the following scenario:
$tempfile = "12345.tmp";
...
# do something with $tempfile here
# and some form processing
...
unlink ($tempfile);
Even if you handle $tempfile safely before unlinking it, the last statement is still very dangerous. An attacker can craft his or her own form containing a field similar to:
<input type=hidden name="tempfile"
value="../../../etc/passwd">
function Send($sendmail = "/usr/sbin/sendmail") {
if ($this->form == "") {
$fp = popen ($sendmail."-i".$this->to, "w");
}
else {
$fp = popen ($sendmail."-i -f".
$this->from." ".$this->to, "w");
}
}
Ecommerce Applications
E-Commerce Development with customization facility in PHP programmer. We provide professional web site development & Web site design india and ecommerce solutions php shopping cart development, payment gateway integration etc. Today ecommerce is essential for eBusiness i.e. B2B & B2C sites
Customise Solutions
Softagz is formed with a vision to provide solutions for web development and Software development of international standards as per user choice. Team Eexpertise in Languages : PHP, XML, HTML, SQL providing Web as well as Software solution with quality and integrity. By which we have thousands of...
Joomla Development
Joomla! is one of the most powerful Open Source Content Management Systems on the planet. It is used all over the world for everything from simple websites to complex corporate applications. Joomla! is easy to install, simple to manage, and reliable.
More
Oscommerce Development
osCommerce has attracted a large growing e-commerce community that consists of over 174,400 store owners and developers who support each other and extend osCommerce Online Merchant with add-ons being contributed on a daily basis.
More
After working with Softagz and his highly skilled team of developers I am confident in recommending his services. The company always delivers on time and within budget.
-John Taylor
I had a very good experience dealing with Softagz. They are very cooperative and have a well-experienced staff. I personally recommend them to you, and hope you too will find the same.
-Brian McMillan
JOOMLA: Building Websites with Joomla! v1.0
OSCOMMERCE: Deep Inside osCommerce: The Cookbook
CSS: The Definitive Guide, Third Edition
DREAMWEAVER: Training from the Source
JAVASCRIPT: The Good Parts [ILLUSTRATED] (Paperback)
WEB STYLE GUIDE: Basic Design Principles.
DATABASE APPLICATION: Applications with PHP & MySQL
PHP/MYSQL: Programming for the Absolute Beginner
AJAX: Building Responsive Web Applications
PHP 5: Learning PHP 5 [ILLUSTRATED] (Paperback)