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

Create successful ePaper yourself

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

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

˛˛ To perform an effective source code review <strong>and</strong> identify all potential <strong>SQL</strong> injection<br />

vulnerabilities, you need to be able to recognize dangerous coding behaviors,<br />

identify security-sensitive functions, locate all potential methods for h<strong>and</strong>ling<br />

user-controlled input, <strong>and</strong> trace tainted data back to its origin via its execution<br />

path or data flow.<br />

˛˛ Armed with a comprehensive list of search strings, the simplest <strong>and</strong> most<br />

straightforward approach to conducting a manual source code review is to use<br />

the UNIX utility grep (also available for Windows systems).<br />

Automated Source Code Review<br />

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

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

analysis via an abstract syntax tree (AST) <strong>and</strong>/or a control flow graph (CFG).<br />

˛˛ Some automated tools use regular expression string matching to identify sinks that<br />

pass tainted data as a parameter, as well as sink sources (points in the application<br />

where untrusted data originates).<br />

˛˛ Lexical analysis is the process of taking an input string of characters <strong>and</strong> producing<br />

a sequence of symbols called lexical tokens. Some tools preprocess <strong>and</strong> tokenize<br />

source files <strong>and</strong> then match the lexical tokens against a library of sinks.<br />

˛˛ An AST is a tree representation of the simplified syntactic structure of source<br />

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

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

˛˛ Data flow analysis is a process for collecting information about the use, definition,<br />

<strong>and</strong> dependencies of data in programs. The data flow analysis algorithm operates<br />

on a CFG generated from an AST.<br />

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

graph notation, of all paths that might be traversed through a program during<br />

its execution.

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

Saved successfully!

Ooh no, something went wrong!