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.

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

IF ora_server_error(n) in ('900','906','907','911','917','920','923','933','970',<br />

'1031','1476','1719','1722','1742','1756','1789','1790','24247','29257','29540')<br />

THEN<br />

-- insert the attempt including the <strong>SQL</strong> statement into a table<br />

INSERT INTO system.oraerror VALUES (id, sysdate, ora_login_user, ora_client_<br />

ip_address, ora_server_error(n), ora_server_error_msg(n), v_stmt);<br />

-- send the information via email to the DBA<br />

-- <br />

COMMIT;<br />

END IF;<br />

END LOOP;<br />

--<br />

END after_error;<br />

/<br />

Locking Down the Database Server<br />

Once the application data has been secured, you still need to take a few additional steps<br />

to harden the database server itself. In a nutshell, you want to make sure the systemwide<br />

configuration is secured in a manner that is consistent with the security principle of least<br />

privilege <strong>and</strong> that the database server software is up to date <strong>and</strong> patched. If you comply with<br />

these two key directives, it will be very difficult for an attacker to access anything outside the<br />

scope of the intended application data. Let’s take a closer look at some specific<br />

recommendations.<br />

Additional Lockdown of System Objects<br />

Besides revoking public role permissions on system objects, consider taking additional steps<br />

to further lock down access to privileged objects, such as those used for system administration,<br />

executing operating system comm<strong>and</strong>s, <strong>and</strong> making network connections. Although these<br />

features are useful to database administrators, they are also just as useful (if not more so)<br />

to an attacker who has gained direct access to the database. Consider restricting by ensuring<br />

that superfluous permissions are not granted to application roles, disabling access to privileged<br />

objects systemwide via server configuration, or dropping from the server completely<br />

(to avoid reenabling should privilege escalation occur).<br />

On Oracle, you should restrict the ability to run operating system comm<strong>and</strong>s <strong>and</strong> to<br />

access files on the operating system level from the database. To ensure that (PL/)<strong>SQL</strong> injection<br />

problems cannot be used to run operating system comm<strong>and</strong>s or access files, do not grant the<br />

following privileges to the Web application user: CREATE ANY LIBRARY, CREATE<br />

ANY DIRECTORY, ALTER SYSTEM, or CREATE JOB. Also, you should remove the<br />

PUBLIC grant at least from the following packages if it is not needed: UTL_FILE, UTL_<br />

TCP, UTL_MAIL, UTL_SMTP, UTL_INADDR, DBMS_ADVISOR, DBMS_<strong>SQL</strong>, <strong>and</strong>

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

Saved successfully!

Ooh no, something went wrong!