28.10.2014 Views

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Reviewing Code for <strong>SQL</strong> <strong>Injection</strong> • Chapter 3 103<br />

// $_POST − an associative array of variables passed via the POST method<br />

$variable = $_POST['name'];<br />

// $HTTP_POST_VARS − an associative array of variables passed via the POST<br />

// method, depreciated in PHP v4.1.0<br />

$variable = $HTTP_POST_VARS['name'];<br />

// $_REQUEST − an associative array that contains the contents of $_GET,<br />

// $_POST & $_COOKIE<br />

$variable = $_REQUEST['name'];<br />

// $_COOKIE − an associative array of variables passed via HTTP Cookies<br />

$variable = $_COOKIE['name'];<br />

// $_SERVER − server <strong>and</strong> execution environment information<br />

$variable = $_SERVER['name'];<br />

// $HTTP_SERVER_VARS − server <strong>and</strong> execution environment information,<br />

// depreciated in PHP v4.1.0.<br />

$variable = $HTTP_SERVER_VARS['name']<br />

PHP has a very well-known setting, register_globals, which you can configure from within<br />

PHP’s configuration file (php.ini) to register the EGPCS (Environment, GET, POST, Cookie,<br />

Server) variables as global variables. For example, if register_ globals is on, the URL “http://<br />

www.victim.com/process_input.php?foo=input” will declare $foo as a global variable with<br />

no code required (there are serious security issues with this setting, <strong>and</strong> as such it has been<br />

deprecated <strong>and</strong> should always be turned off ). If register_ globals is enabled, user input can be<br />

retrieved via the INPUT element <strong>and</strong> is referenced via the name attribute within an HTML<br />

form. For example:<br />

$variable = $foo;<br />

In Java, the process is fairly similar. You use the request object to get the value that the<br />

client passes to the Web server during an HTTP request. The request object takes the value<br />

from the client’s Web browser <strong>and</strong> passes it to the server via an HTTP request. The class or<br />

the interface name of the object request is HttpServletRequest. You write the object request as<br />

javax.servlet.http.HttpServletRequest. Numerous methods are available for the request object.<br />

We are interested in the following functions, which are used for processing user input:<br />

■■<br />

■■<br />

■■<br />

■■<br />

■■<br />

getParameter( ) Used to return the value of a requested given parameter<br />

getParameterValues( ) Used to return all the values of a given parameter’s<br />

request as an array<br />

getQueryString( ) Used to return the query string from the request<br />

getHeader( ) Used to return the value of the requested header<br />

getHeaders( ) Used to return the values of the requested header as an enumeration<br />

of string objects

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

Saved successfully!

Ooh no, something went wrong!