Skip to Main Content
Linux Server Security, Second Edition
book

Linux Server Security, Second Edition

by Michael D. Bauer
January 2005
Intermediate to advanced content levelIntermediate to advanced
544 pages
23h 44m
English
O'Reilly Media, Inc.
Content preview from Linux Server Security, Second Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
342
|
Chapter 10: Securing Web Servers
Executing Programs
Most scripting languages let you run external programs. This is a golden opportu-
nity for nasty tricks. Check the pathname of the external program and remove any
metacharacters that would allow multiple commands. Avoid passing commands
through a shell interpreter.
PHP
Escape any possible attempts to slip in extra commands with this PHP function:
$safer_input = escapeshellarg($input);
system("some_command $safer_input");
or:
system(escapeshellcmd("some_command $input"));
These PHP functions invoke the shell and are vulnerable to misuse of shell metachar-
acters:
system, passthru, exec, popen, preg_replace (with the /e option), and the
backtick (
`command`) operator.
If
safe_mode is set, only programs within safe_mode_exec_dir can be executed, and
only files owned by the owner of the PHP script can be accessed.
The PHP function
eval($arg) executes its argument $arg as PHP code. There’s no
equivalent to
safe_mode for this, although the disable_functions option lets you turn
off selected functions. Don’t execute any command with embedded user data.
Perl
Taint mode will not let you pass unaltered user input to the functions system, exec,
eval, or the backtick (`command`) operator. Untaint them before executing, as
described earlier.
Uploading Files ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux: Powerful Server Administration

Linux: Powerful Server Administration

Uday Sawant, Oliver Pelz, Jonathan Hobson, William Leemans
Linux Server Hacks

Linux Server Hacks

Rob Flickenger
Linux Server Hacks, Volume Two

Linux Server Hacks, Volume Two

William von Hagen, Brian K. Jones

Publisher Resources

ISBN: 0596006705Supplemental ContentCatalog PageErrata