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.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
SQL Injection AttackOverview
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.
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.
CAST: Translates the HEX expression into a character string
EXEC: Executes this string
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.
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.
U = User table
35 = text
99 = ntext
167 = varchar
231 = nvarchar
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.
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.
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 90+0.
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.
<iframe width=1 height=1 border=0 frameborder=0 s
gAJys = parseInt(MhbtCwq*TMplSKEfAW)+parseInt(MhbtCwq);
gAJys = parseInt(gAJys)/Ffwx;
gHuP += String.fromCharCode(gAJys);
Splits the string at the commas
90*4 + 0 = 360
157*4 + 2 = 630
153*4 + 0 = 612
171*4 + 0 = 684
145*4 + 2 = 582
Splits the string at the plus
360/6 = 60
630/6 = 105
612/6 = 102
684/6 = 114
582/6 = 97
60 = <
105 = i
102 = f
114 = r
97 = a
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.
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.
inetnum: 184.108.40.206 - 220.127.116.11
descr: Digital United Inc.
descr: 7F,220,gangchi road
descr: Taipei Taiwan 114
status: ALLOCATED PORTABLE
notify: [email protected]
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.
changed: [email protected] 20061228
SQL Injection AttackOverview
Thank you for watching