19.09.2017 Views

the-web-application-hackers-handbook

Create successful ePaper yourself

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

734 Chapter 19 n Finding Vulnerabilities in Source Code<br />

NOTE Not all dangerous functions are restricted by safe mode, and some<br />

restrictions are affected by o<strong>the</strong>r configuration options. Fur<strong>the</strong>rmore, <strong>the</strong>re<br />

are various ways to bypass some safe mode restrictions. Safe mode should<br />

not be considered a panacea to security issues within PHP <strong>application</strong>s. Safe<br />

mode has been removed from PHP version 6.<br />

Magic Quotes<br />

If <strong>the</strong> magic_quotes_gpc directive is enabled, any single quote, double quote,<br />

backslash, and NULL characters contained within request parameters are automatically<br />

escaped using a backslash. If <strong>the</strong> magic_quotes_sybase directive is<br />

enabled, single quotes are instead escaped using a single quote. This option is<br />

designed to protect vulnerable code containing unsafe database calls from being<br />

exploitable via malicious user input. When reviewing <strong>the</strong> <strong>application</strong> codebase to<br />

identify any SQL injection flaws, you should be aware of whe<strong>the</strong>r magic quotes<br />

are enabled, because this affects <strong>the</strong> <strong>application</strong>’s handling of input.<br />

Using magic quotes does not prevent all SQL injection attacks. As described<br />

in Chapter 9, an attack that injects into a numeric field does not need to use<br />

single quotation marks. Fur<strong>the</strong>rmore, data whose quotes have been escaped<br />

may still be used in a second-order attack when it is subsequently read back<br />

from <strong>the</strong> database.<br />

The magic quotes option may result in undesirable modification of user input,<br />

when data is being processed in a context that does not require any escaping.<br />

This can result in <strong>the</strong> addition of slashes that need to be removed using <strong>the</strong><br />

stripslashes function.<br />

Some <strong>application</strong>s perform <strong>the</strong>ir own escaping of relevant input by passing<br />

individual parameters through <strong>the</strong> addslashes function only when required.<br />

If magic quotes are enabled in <strong>the</strong> PHP configuration, this approach results in<br />

double-escaped characters. Doubled-up slashes are interpreted as literal backslashes,<br />

leaving <strong>the</strong> potentially malicious character unescaped.<br />

Because of <strong>the</strong> limitations and anomalies of <strong>the</strong> magic quotes option, it is<br />

recommended that prepared statements be used for safe database access and<br />

that <strong>the</strong> magic quotes option be disabled.<br />

NOTE The magic quotes option has been removed from PHP version 6.<br />

Miscellaneous<br />

Table 19-10 lists some miscellaneous configuration options that can affect <strong>the</strong><br />

security of PHP <strong>application</strong>s.

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

Saved successfully!

Ooh no, something went wrong!