Wednesday, December 5, 2007

PHP Installation as an Apache module

When PHP is used as an Apache module it inherits Apache's user permissions (typically those of the "nobody" user). This has several impacts on security and authorization. For example, if you are using PHP to access a database, unless that database has built-in access control, you will have to make the database accessible to the "nobody" user. This means a malicious script could access and modify the database, even without a username and password. It's entirely possible that a web spider could stumble across a database administrator's web page, and drop all of your databases. You can protect against this with Apache authorization, or you can design your own access model using LDAP, .htaccess files, etc. and include that code as part of your PHP scripts.

Often, once security is established to the point where the PHP user (in this case, the apache user) has very little risk attached to it, it is discovered that PHP is now prevented from writing any files to user directories. Or perhaps it has been prevented from accessing or changing databases. It has equally been secured from writing good and bad files, or entering good and bad database transactions.

A frequent security mistake made at this point is to allow apache root permissions, or to escalate apache's abilities in some other way.

Escalating the Apache user's permissions to root is extremely dangerous and may compromise the entire system, so sudo'ing, chroot'ing, or otherwise running as root should not be considered by those who are not security professionals.

There are some simpler solutions. By using open_basedir you can control and restrict what directories are allowed to be used for PHP. You can also set up apache-only areas, to restrict all web based activity to non-user, or non-system, files.

Saturday, December 1, 2007

How to Array / Class in PHP

Following three (3) listed functions return all related information of an object that may be an ARRAY in PHP.
function print_vars($obj)
{
 foreach (get_object_vars($obj) as $prop => $val) {
   echo "\t$prop = $val\n";
 }
}

function print_methods($obj)
{
   $arr = get_class_methods(get_class($obj));
   foreach ($arr as $method) {
       echo "\tfunction $method()\n";
   }
}

function class_parentage($obj, $class)
{
 if (is_subclass_of($GLOBALS[$obj], $class)) {
   echo "Object $obj belongs to class " . get_class($$obj);
   echo " a subclass of $class\n";
 }
 else {
   echo "Object $obj does not belong to a
  subclass of $class\n";
 }
}

Friday, November 30, 2007

What is WAMP?

The acronym WAMP refers to a set of open source applications (Apache, MySQL and one or more of Perl, PHP and Python), combined with Microsoft Windows, which are commonly used in Web server environments. The WAMP stack provides developers with the four key elements of a Web server: an operating system (Windows), database (MySQL), Web server (Apache) and Web scripting software (PHP, Perl, Python). The combined usage of these programs is called a server stack. In this stack, Microsoft Windows is the operating system (OS), Apache is the Web server, MySQL handles the database components, while PHP (is an object-oriented web scripting language), Python (is a powerful, general-purpose, object-oriented scripting language), or PERL (is yet another powerful, general-purpose, object-oriented scripting language) represents the dynamic scripting languages.