Douglas J. Partch, Jr. – Lead Nerd Protecting SQL Code Through DB2 LUW Obfuscation.

Slides:



Advertisements
Similar presentations
Oracle PL/SQL IV Exceptions Packages.
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.
SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 10 Oracle-Supplied Packages and SQL*Loader.
AppManager 7: Deep Technical Dive Tim Sedlack & Michi Schniebel Sr. Product Managers.
Chapter 9: Advanced SQL and PL/SQL Topics Guide to Oracle 10g.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Objectives Why PL-SQL ? Language features
Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.
Module 2: Using Transact-SQL Querying Tools. Overview SQL Query Analyzer Using the Object Browser Tool in SQL Query Analyzer Using Templates in SQL Query.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
6/1/2001 Supplementing Aleph Reports Using The Crystal Reports Web Component Server Presented by Bob Gerrity Head.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Module 1: Introduction to Microsoft SQL Server 7.0.
IMS 4212: Application Architecture and Intro to Stored Procedures 1 Dr. Lawrence West, Management Dept., University of Central Florida
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 11 Introduction to Dynamic SQL and Object Technology.
By Lecturer / Aisha Dawood 1.  You can control the number of dispatcher processes in the instance. Unlike the number of shared servers, the number of.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
June 6 th – 8 th 2005 Deployment Tool Set Synergy 2005.
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.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
ATG Environment Setup In this session you will learn – Setting Up ATG environment – Creating new ATG application – Configuring Data Source – Configuring.
ASP.NET.. ASP.NET Environment ASP.NET is Microsoft's programming framework that enables the development of Web applications and services. It is an easy.
B ASIC SQL P ROCEDURE S TRUCTURE. U NIT OBJECTIVES After completing this unit, you should be able to: Describe the structure of an SQL procedure Explain.
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
Copyright © Curt Hill Stored Procedures In Transact-SQL.
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
12 Copyright © 2004, Oracle. All rights reserved. Understanding and Influencing the PL/SQL Compiler.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
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.
Using Oracle-Supplied Packages. 2 home back first prev next last What Will I Learn? Describe two common uses for the DBMS_OUTPUT server-supplied package.
Intersession Communication Oracle Database PL/SQL 10g Programming
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.
Database Security Cmpe 226 Fall 2015 By Akanksha Jain Jerry Mengyuan Zheng.
55 Creating Data Dictionary Views and Standard Packages.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 10 Oracle-Supplied Packages, Dynamic SQL, and Hiding Source Code.
SQL.. AN OVERVIEW lecture3 1. Overview of SQL 2  Query: allow questions to be asked of the data and display only the information required. It can include.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Stored Procedures / Session 4/ 1 of 41 Session 4 Module 7: Introducing stored procedures Module 8: More about stored procedures.
Oracle10g Developer: PL/SQL Programming1 Objectives Named program units How to identify parameters The CREATE PROCEDURE statement Creating a procedure.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
SQL Introduction to database and SQL. Chapter 1: Databases and Database Users 6 Introduction to Databases Databases touch all aspects of our lives. Examples:
Lab 2 Writing PL/SQL Blocks CISB514 Advanced Database Systems.
Module 5: Managing Content. Overview Publishing Content Executing Reports Creating Cached Instances Creating Snapshots and Report History Creating Subscriptions.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
SQL Triggers, Functions & Stored Procedures Programming Operations.
1 Chapter 5: Advanced PL/SQL Programming. 2 Anonymous PL/SQL Programs Write code in text editor, execute it in SQL*Plus Code can be stored as text in.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
6 Copyright © 2009, Oracle. All rights reserved. Using Dynamic SQL.
D Copyright © 2009, Oracle. All rights reserved. Using SQL*Plus.
SQL Database Management
CS 3630 Database Design and Implementation
SQL and SQL*Plus Interaction
Using SQL*Plus.
Chapter 10 Oracle11g: PL/SQL Programming Oracle-Supplied Packages,
Introduction to PL/SQL
Using SQL*Plus.
PL/SQL Package Week 8.
ORACLE SQL Developer & SQLPLUS Statements
CS 440 Database Management Systems
PL/SQL week10.
SQL .. An overview lecture3.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Computer Science Projects Database Theory / Prototypes
Using SQL*Plus.
Procedures Oracle & MySQL
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Presentation transcript:

Douglas J. Partch, Jr. – Lead Nerd Protecting SQL Code Through DB2 LUW Obfuscation

“Is it possible to protect SQL Code in a database?” 2 Frequent question asked by manufactures of software applications containing databases. For DB2 the simple answers was always, “NO”, up until release of DB2 LUW 9.7 Fix Pack 2 IBM added support for Oracle’s DBMS_DDL.WRAP Function DBMS_DDL.CREATE_WRAPPED Stored Procedure,

What can be protected 3 DB2 LUW supports the following objects. ObjectPL/SQLSQL PL Create ProcedureYes Create FunctionYes Create PackageYesNo Create Package BodyYesNo Create TriggersYes Create ViewYes Alter Module Add FunctionYes Alter Module Publish FunctionYes Alter Module Add ProcedureYes Alter Module Publish ProcedureYes

How do we do it. 4 Step 1. Enable Oracle Compatibility if DB2 version lower than 10.5 First the requirement: The database must be enabled for Oracle compatibility, even if this is the only feature you want to use. First the requirement: The database must be enabled for Oracle compatibility, even if this is the only feature you want to use. 1. db2set DB2_COMPATIBILITY_VECTOR=ORA 2. db2stop 3. db2start 4. db2set DB2_COMPATIBILITY_VECTOR 5. create db PROTECT 6. connect to PROTECT Can not be added to an existing database

Build Initial object 5 Step 2. Create Database object to be protected CREATE OR REPLACE xray.SQUARE_SP CREATE OR REPLACE PROCEDURE xray.SQUARE_SP (IN var_IN SMALLINT, OUT var_OUT INTEGER) (IN var_IN SMALLINT, OUT var_OUT INTEGER) LANGUAGE SQL LANGUAGE SQL READS SQL DATA READS SQL DATA NOT DETERMINISTIC NOT DETERMINISTIC SPECIFIC TEST_SP SPECIFIC TEST_SP P1: BEGIN P1: BEGIN -- Square the input variable -- Square the input variable SET var_OUT = var_IN * var_IN; SET var_OUT = var_IN * var_IN;

Encrypt Object (Method 1) 6 Step 3a. Encrypted object using SELECT SELECT DBMS_DDL.WRAP(TEXT) FROM SYSCAT.ROUTINES FROM SYSCAT.ROUTINES WHERE ROUTINESCHEMA = 'XRAY' WHERE ROUTINESCHEMA = 'XRAY' AND ROUTINENAME = ' SQUARE_SP ' AND ROUTINENAME = ' SQUARE_SP ' --output-- string type of CLOB(2M) CREATE OR REPLACE PROCEDURE xray.SQUARE_SP ( IN var_IN SMALLINT, OUT var_OUT INTEGER ) ( IN var_IN SMALLINT, OUT var_OUT INTEGER ) WRAPPED SQL10054 ablGWmdiWmtuTmduTmJGTmtmUmZKUmJeUmdCWmdaWidaWmdaWmdaXnJf orcaGicaGFhf_D5GCMrs4t8HyTuxOEoCaQtY0ipPT_ac_lcdzK1ya_D0 zvnMzxacCYXfj0OjchzVbt93WJGUnTC1cY:YoyP_53tBa6O07YSQTA:H gLp29aD2ZSaV9K5aR0l6WEkhl0qRe67fq5DlypPwNRb7JXT53GQsYeO_ UKJkVJRV912dnNku:GSNXh7:PH37nTS4W7zZUrNDyH8y5y4RmguppGL1 dZ4ia WRAPPED SQL10054 ablGWmdiWmtuTmduTmJGTmtmUmZKUmJeUmdCWmdaWidaWmdaWmdaXnJf orcaGicaGFhf_D5GCMrs4t8HyTuxOEoCaQtY0ipPT_ac_lcdzK1ya_D0 zvnMzxacCYXfj0OjchzVbt93WJGUnTC1cY:YoyP_53tBa6O07YSQTA:H gLp29aD2ZSaV9K5aR0l6WEkhl0qRe67fq5DlypPwNRb7JXT53GQsYeO_ UKJkVJRV912dnNku:GSNXh7:PH37nTS4W7zZUrNDyH8y5y4RmguppGL1 dZ4ia Make sure you save a copy of the Original SQL code first

Encrypt Object (Method 2) 7 Step 3b. Encrypt all database objects using DB2LOOK. db2look –d PROTECT –e -wrap DDL Statements for Stored Procedures SET NLS_STRING_UNITS = 'SYSTEM'; SET CURRENT SCHEMA = "PARD04 "; SET CURRENT PATH = "SYSIBM","SYSFUN","SYSPROC","SYSIBMADM","PARD04"; CREATE PROCEDURE xray.SQUARE_SP (IN var_IN SMALLINT, OUT var_OUT INTEGER) WRAPPED SQL10054 ablGWmdiWmtuTmduTmJGTmtqUmdiUmtaUmJy2mdaXidaWmdaWmdaXntDqmsaGicaG6Cx52seVPY9 FpzJavr24KHbC:mfGh1SAawXPorMsrLd3rjWvSWhiuofmGr5qp6QVtnyQpogB38C3zAeQfZhKEun UTYMsNs7YJPW6WVBC4Zi:mms:hX3PN0XSNp58e3KuuDLL9oPeia_mKf9Y5Fe9hOd7ht5bTPZ3vLU Qwae5q0Lgx5Pvmd7OcNLWYccYdvkKTrbYF8WuJQ_uk7:GPsU:4aaa; COMMIT WORK;

Encrypt Object (Method 3) 8 Step 3c. Encrypted object using SP CALL and create it in one step. CALL DBMS_DDL.CREATE_WRAPPED (DBMS_DDL.WRAP('CREATE OR REPLACE PROCEDURE xray.SQUARE_SP (IN var_IN SMALLINT, OUT var_OUT INTEGER) LANGUAGE SQL READS SQL DATA NOT DETERMINISTIC SPECIFIC SQUARE_SP P1: BEGIN SET var_OUT = var_IN * var_IN; END P1' )) --output-- DB20000I The SQL command completed successfully. CALL DBMS_DDL.CREATE_WRAPPED(DBMS_DDL.WRAP('CREATE OR REPLACE PROCEDURE xray.SQUARE_SP ( IN var_IN SMALLINT, OUT var_OUT INTEGER) LANGUAGE SQL READS SQL DATA NOT DETERMINISTIC SPECIF IC SQUARE_SP P1: BEGIN SET var_OUT = var_IN * var_IN; END' )) Return Status = 0

How do we do it. 9 Decoding Wrapped WRAPPED pppvvrrm ppp identifies the product as DB2 LUW using the letters SQL vv is a two-digit version identifier, such as ‘10' rr is a two-digit release identifier, such as '05' m is a one-character modification level identifier, such as ‘4'. WRAPPED SQL WRAPPED SQL ablGWmdiWmtuTmduTmJGTmtqUmdiUmtaUmJy2mdaXidaWmdaWmdaXntDqmsaGicaG6Cx52s eVPY9FpzJavr24KHbC:mfGh1SAawXPorMsrLd3rjWvSWhiuofmGr5qp6QVtnyQpogB38C3z AeQfZhKEunUTYMsNs7YJPW6WVBC4Zi:mms:hX3PN0XSNp58e3KuuDLL9oPeia_mKf9Y5Fe9 hOd7ht5bTPZ3vLUQwae5q0Lgx5Pvmd7OcNLWYccYdvkKTrbYF8WuJQ_uk7:GPsU:4aaa; Any time wrap is called it will create unique encrypted data

How do we do it. 10 Step 4. Place the Encrypted object in the database. Execute Code create from Step 3a or 3b (). Execute Code create from Step 3a or 3b (3c has already created the object). CREATE OR REPLACE PROCEDURE xray.SQUARE_SP ( IN var_IN SMALLINT, OUT var_OUT INTEGER ) WRAPPED SQL09075 ablGWmdiWmtiTmdiTmJCTmJiUnteUndKUndm3mdaWidaWmdaWmdaYmJDUzcaGicaGTXFNDXk1azDZkg2zEqHnY ZXjczGCgLJuXEgyaYDDWrYjsP40Zq:kCz9cGZ:weDD2uB91ArD5GvaF5aMVp7bm:gVVh6XHZZkbgDD9jgtzscl odJIB7J8YU74ocjV8s0:sjbB:_0M13Fb8ZLefoE4snbMTr2zk4Hvg2Rqq4DCYRA8WCCFbDJ6vY1ytUoT2m5I4n 3FSX7TtPnza_62EsNoWbHBKyLwE9FBK2978tbWVLCOsB0DzXN4u0DAYwHnuoK7GeYu0aN2xp9rpMeUCuGaxc4b tNWeitGDz_Cvn_DO_lOdtL1bOr Update the existing object in database Update the existing object in databaseBEGIN DECLARE txt CLOB(2M); DECLARE txt CLOB(2M); SET txt = (SELECT DBMS_DDL.WRAP(TEXT) SET txt = (SELECT DBMS_DDL.WRAP(TEXT) FROM SYSCAT.ROUTINES FROM SYSCAT.ROUTINES WHERE ROUTINESCHEMA = 'XRAY' WHERE ROUTINESCHEMA = 'XRAY' AND ROUTINENAME = ‘SQUARE_SP'); AND ROUTINENAME = ‘SQUARE_SP'); EXECUTE IMMEDIATE txt; EXECUTE IMMEDIATE txt;END

How do we do it. 11 Step 5. Test Encrypted object. call xray.SQUARE_SP(10,?) --Output-- Value of output parameters Parameter Name : VAR_OUT Parameter Value : 100 Return Status = 0

Other Built in Modules. 12 DBMS_ALERT module The DBMS_ALERT module provides a set of procedures for registering for alerts, sending alerts, and receiving alerts. DBMS_ALERT module DBMS_JOB module The DBMS_JOB module provides procedures for the creation, scheduling, and managing of jobs. DBMS_JOB module DBMS_LOB module The DBMS_LOB module provides the capability to operate on large objects. DBMS_LOB module DBMS_OUTPUT module The DBMS_OUTPUT module provides a set of procedures for putting messages (lines of text) in a message buffer and getting messages from the message buffer. These procedures are useful during application debugging when you need to write messages to standard output. DBMS_OUTPUT module DBMS_PIPE module The DBMS_PIPE module provides a set of routines for sending messages through a pipe within or between sessions that are connected to databases within the same DB2 instance. DBMS_PIPE module DBMS_SQL module The DBMS_SQL module provides a set of procedures for executing dynamic SQL, and therefore supports various data manipulation language (DML) or data definition language (DDL) statement. DBMS_SQL module

Other Built in Modules. 13 DBMS_UTILITY module The DBMS_UTILITY module provides various utility programs. DBMS_UTILITY module MONREPORT module The MONREPORT module provides a set of procedures for retrieving a variety of monitoring data and generating text reports. MONREPORT module UTL_DIR module The UTL_DIR module provides a set of routines for maintaining directory aliases that are used with the UTL_FILE module. UTL_DIR module UTL_FILE module The UTL_FILE module provides a set of routines for reading from and writing to files on the database server's file system. UTL_FILE module UTL_MAIL module The UTL_MAIL module provides the capability to send . UTL_MAIL module UTL_SMTP module The UTL_SMTP module provides the capability to send over the Simple Mail Transfer Protocol (SMTP). UTL_SMTP module

Example of using DBMS_OUTPUT 14 CREATE PROCEDURE xray.proc1(IN_PARM VARCHAR(10) ) BEGIN CALL DBMS_OUTPUT.PUT( 'INPUT = ' ); CALL DBMS_OUTPUT.PUT_LINE(IN_PARM ); SET SERVEROUTPUT CALL xray.proc1( '10' SET SERVEROUTPUT CALL xray.proc1( '20' CALL proc1( '10' ) Return Status = 0 INPUT = 10 SET SERVEROUTPUT OFF DB20000I The SET SERVEROUTPUT command completed successfully. CALL proc1( '20' ) Return Status = 0

That’s all folks 15