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.

Use Strong Cryptography<br />

to Protect Stored Sensitive Data<br />

Platform-Level <strong>Defense</strong>s • Chapter 9 397<br />

A key mitigating control against unauthorized viewing of sensitive data in the database is<br />

the use of strong cryptography. The options include storing a mathematical hash of the data<br />

(rather than the data itself) or storing the data encrypted with a symmetric algorithm. In both<br />

cases, you should use only public algorithms deemed cryptographically strong. You should<br />

avoid homegrown cryptographic solutions at all costs.<br />

If the data itself does not require storage, consider an appropriately derived mathematical<br />

hash instead. An example of this is data used for challenging the identity of a user, such as<br />

passwords or security question answers. If an attacker is able to view the table storing this<br />

data, only password hashes will be returned. The attacker must go through the time-consuming<br />

exercise of cracking password hashes to obtain the actual credentials. Another clear benefit to<br />

hashing is that it eliminates the key management issues associated with encryption. To stay<br />

consistent with security best practices, ensure that the hashing algorithm of choice has not<br />

been determined mathematically susceptible to collisions, such as MD5 <strong>and</strong> SHA-1. Consult<br />

resources such as NIST (http://csrc.nist.gov/groups/ST/hash/policy.html) to find out the<br />

current set of hashing algorithms deemed acceptable for use by federal agencies.<br />

If you must store sensitive data, protect it with a strong symmetric encryption algorithm<br />

such as Advanced Encryption St<strong>and</strong>ard (AES) or Triple DES (Data Encryption St<strong>and</strong>ard).<br />

The primary challenge to encrypting sensitive data is storing the key in a location that the<br />

attacker cannot access easily. You should never store encryption keys client-side, <strong>and</strong> the best<br />

server-side solution for key storage usually depends on the application architecture. If the<br />

key can be provided at runtime, this is ideal as it will only reside in memory on the server<br />

(<strong>and</strong> depending on the application framework it can be possible to protect it while in<br />

memory). However, on-the-fly key generation is usually not feasible or practical in most<br />

enterprise application environments. One possible solution is to store the key in a protected<br />

location on the application server so that the attacker needs to compromise both the database<br />

server <strong>and</strong> the application server to decrypt it. In a Windows environment, you can use the<br />

Data Protection API (DPAPI) to encrypt application data <strong>and</strong> leverage the operating system<br />

to securely store the key. Another Windows-specific option is storing the key in the<br />

Windows Registry, which is a more complex storage format than a flat text file <strong>and</strong> therefore<br />

could be more challenging to view depending on the level of unauthorized access gained by<br />

the attacker. When operating system specific storage options are not available (such as with<br />

a Linux server), you should store the key (or secret used to derive it) on a protected area of<br />

the file system with strict file system ACLs applied. It’s also worth noting that as of Microsoft<br />

<strong>SQL</strong> Server 2005 <strong>and</strong> Oracle Database 10g Release 2, both support column-level encryption<br />

natively. However, these nice built-in features do not provide much additional protection<br />

against <strong>SQL</strong> injection, as this information will usually be transparently decrypted for the<br />

application.

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

Saved successfully!

Ooh no, something went wrong!