13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

378 Chapter 16 <strong>Web</strong> Application Security<br />

// names <strong>and</strong> phone nums are separated by , char<br />

$namenum = split($lines, ',');<br />

echo "Name: {$namenum[0]}, Phone #: {$namenum[1]}\n";<br />

}<br />

?><br />

If you ever allow user input to the comm<strong>and</strong> placed in back quotes, you are opening<br />

yourselves to all sorts of security problems <strong>and</strong> will need to filter the input heavily to<br />

ensure the safety of your system. At the very least, the escapeshellcmd function should<br />

be used.To be certain, however, you might want to restrict the possible input even more.<br />

Even worse, given that we normally want to run our web server <strong>and</strong> <strong>PHP</strong> in a context<br />

with lower permissions (we will see more about this in following sections), we<br />

might find ourselves having to grant it more permissions to execute some of these comm<strong>and</strong>s,<br />

which could further compromise our security. Use of this operator in a production<br />

environment is something to be approached with a great amount of caution.<br />

The exec <strong>and</strong> system functions are very similar to the execution quotes operator,<br />

except that they execute the comm<strong>and</strong> directly instead of executing it within a shell<br />

environment <strong>and</strong> do not always return the full set of output that the execution quotes<br />

return.They do share many of the same security concerns, <strong>and</strong> thus also come with the<br />

same warnings.<br />

Securing Your <strong>Web</strong> Server <strong>and</strong> <strong>PHP</strong><br />

In addition to worrying about code security, the installation <strong>and</strong> configuration of our<br />

web server with <strong>PHP</strong> is also a large security concern. Much software that we install on<br />

our computers <strong>and</strong> servers comes with configuration files <strong>and</strong> default feature sets<br />

designed to show off the power <strong>and</strong> usefulness of the software. It assumes that we will<br />

work on disabling those portions that are not needed <strong>and</strong>/or that are less secure than<br />

may be needed.Tragically, many people do not think to do this, or do not take the time<br />

to do it properly.<br />

As part of our approach to dealing with security “holistically,” we want to be sure that<br />

our web servers <strong>and</strong> <strong>PHP</strong> are indeed properly configured. Although we cannot give a<br />

full presentation of how to secure each <strong>and</strong> every web server or extension in <strong>PHP</strong> you<br />

might use, we can at least provide some key points to investigate <strong>and</strong> point you in the<br />

correct direction for more advice <strong>and</strong> suggestions.<br />

Keep Software Up-to-Date<br />

One of the easiest ways to help the security of your system is to ensure that you are<br />

always running the latest <strong>and</strong> most secure version of the software you are using. For

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!