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 125<br />

lexical analyzers. Lexical analysis is necessary to reliably distinguish variables from functions<br />

<strong>and</strong> to identify function arguments.<br />

Some source code analyzers, such as those that operate as plug-ins to an IDE, often<br />

make use of an abstract syntax tree (AST). An AST is a tree representation of the simplified<br />

syntactic structure of source code. You can use an AST to perform a deeper analysis of the<br />

source elements to help track data flows <strong>and</strong> identify sinks <strong>and</strong> sink sources.<br />

Another method that some source code analyzers implement is data flow analysis,<br />

a process for collecting information about the use, definition, <strong>and</strong> dependencies of data in<br />

programs. The data flow analysis algorithm operates on a control flow graph (CFG) generated<br />

from the AST. You can use a CFG to determine the parts of a program to which a particular<br />

value assigned to a variable might propagate. A CFG is a representation, using graph notation,<br />

of all paths that might be traversed through a program during its execution.<br />

At the time of this writing, automated tools incorporate three distinct methods of<br />

analysis: string-based pattern matching, lexical token matching, <strong>and</strong> data flow analysis via<br />

an AST <strong>and</strong>/or a CFG. Automated static code analysis tools can be very useful in helping<br />

security consultants identify dangerous coding behaviors that incorporate security-sensitive<br />

functions or sinks, <strong>and</strong> make the task of identifying sink sources by tracing tainted data back<br />

to its origin (entry point) much simpler. However, you should not rely blindly on their<br />

results. Although in some ways they are an improvement over manual techniques, they should<br />

be used by security-conscientious developers or skilled <strong>and</strong> knowledgeable security consultants<br />

who can contextualize their findings <strong>and</strong> make an informed decision on their validity.<br />

I also recommend that you use any automated tool in conjunction with at least one other<br />

tool as well as a manual investigation of the code utilizing the techniques presented in this<br />

chapter. This combined approach will give you the highest level of confidence in your<br />

findings <strong>and</strong> allow you to eradicate the majority of false positives as well as help you identify<br />

false negatives. These tools don’t eliminate the need for a human reviewer; a certain level of<br />

security acumen is required to use the tools correctly. Web application programming languages<br />

are rich, expressive languages that you can use to build anything, <strong>and</strong> analyzing arbitrary<br />

code is a difficult job that requires a lot of context. These tools are more like spell checkers<br />

or grammar checkers; they don’t underst<strong>and</strong> the context of the code or the application <strong>and</strong><br />

can miss many important security issues.<br />

Yet Another Source<br />

Code Analyzer (YASCA)<br />

YASCA is an open source program which looks for security vulnerabilities <strong>and</strong> code-quality<br />

issues in program source code. It analyses PHP, Java, C/C++, <strong>and</strong> JavaScript (by default) for<br />

security <strong>and</strong> code-quality issues. YASCA is extensible via a plug-in-based architecture.<br />

It integrates other open source programs such as FindBugs (http://findbugs.sourceforge.net),<br />

PMD (http://pmd.sourceforge.net), <strong>and</strong> Jlint (http://artho.com/jlint). You can use the tool

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

Saved successfully!

Ooh no, something went wrong!