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.

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

context, such as dropping tables or executing operating system comm<strong>and</strong>s. It’s important to<br />

remember that even with this mitigating control the attacker may still be able to circumvent<br />

business rules <strong>and</strong> view the portfolio data of another user.<br />

To determine the permissions assigned to a database login, find its role membership <strong>and</strong><br />

remove any unnecessary or privileged roles, such as the public or database administrator role.<br />

Ideally, the login should be a member of one (or possibly more) custom application roles.<br />

A follow-up step is to audit permissions assigned to custom application roles to ensure that<br />

they are locked down appropriately. During a database audit, it is very common to find<br />

unnecessary UPDATE or INSERT permissions assigned to custom application roles<br />

intended for read-only access. These audit <strong>and</strong> subsequent cleanup steps can be performed<br />

with graphical management tools that often accompany the database server platform or with<br />

<strong>SQL</strong> via the query console.<br />

Revoke PUBLIC Permissions<br />

Every database server platform has a default role to which every login belongs, usually called<br />

the public role, which has a default set of permissions that includes access to system objects.<br />

Attackers use this default access to query system catalogs to map out database schema <strong>and</strong><br />

target the juiciest tables for subsequent querying, such as those storing application login<br />

credentials. The public role is also assigned permission to execute built-in system stored<br />

procedures, packages, <strong>and</strong> functions used for administrative purposes.<br />

Usually you cannot drop the public role; however, it is recommended that you not grant<br />

additional permissions to the public role, because each database user inherits the permissions<br />

of this role. You should revoke public role permissions from as many system objects as possible.<br />

Additionally, you must revoke superfluous permissions granted to the public role on custom<br />

database objects (such as application tables <strong>and</strong> stored procedures) unless a justifiable reason<br />

for the permissions exists. If necessary, you should assign database permissions to a custom<br />

role that you can use to grant a default level of access to specific users <strong>and</strong> groups.<br />

Use Stored Procedures<br />

From a security perspective, you should encapsulate application <strong>SQL</strong> queries within stored<br />

procedures <strong>and</strong> grant only EXEC permissions on those objects. All other permissions,<br />

such as SELECT, INSERT, <strong>and</strong> so on, on the underlying objects can be revoked. In the<br />

event of <strong>SQL</strong> injection, a least-privileged database login that has only EXECUTE<br />

permissions on application stored procedures makes it more difficult to return arbitrary result<br />

sets to the browser. This does not guarantee safety from <strong>SQL</strong> injection, as the insecure code<br />

could not lie within the stored procedure itself. Additionally, it may be possible to obtain<br />

result sets via other means, such as with blind <strong>SQL</strong> injection techniques.

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

Saved successfully!

Ooh no, something went wrong!