Trustwave SpiderLabs Security Advisory TWSL2016-017: SQL Injection Vulnerability in SAP Adaptive Server Enterprise Published: 09/16/2016 Version: 1.0 Vendor: SAP (www.sap.com) Product: Adaptive Server Enterprise (ASE) Version affected: 16.0 SP02 PL03 Product description: Relational database management system for UNIX, Linux, and Windows platforms. Finding 1: dbcc import_sproc SQL injection Credit: Martin Rakhmanov of Trustwave CVE: CVE-2016-7402 SAP ASE 16.0 SP02 PL03 introduced a new DBCC command: dbcc import_sproc Example invocation: dbcc import_sproc('loopback', 'SourceDB', 'TargetDB') Any database owner can run this DBCC statement by default. Suppose a malicious user owns databases SourceDB and TargetDB on some server running ASE 16.0 SP02 PL03. In that case he or she can elevate privileges to sa (system administrator) in a few simple steps: In TargetDB create some dummy stored procedure via the CREATE PROCEDURE statement: create procedure usp_demo as return Replace the stored procedure body in syscomments with malicious T-SQL: update syscomments set text = 'grant role sa_role to james--' where id = object_id('usp_demo') Note that this requires ad-hoc updates to system catalog to be enabled which is not the default setting. But it can be easily bypassed by dumping the database, restoring the dump on another attacker-controlled server where ad-hoc updates are on, doing the update and then dumping and restoring back to the server being attacked. Run dbcc import_sproc('loopback', 'TargetDB', 'SourceDB') while in SourceDB or TargetDB context which will execute T-SQL of attacker's choice with the highest privileges possible. Examine roles via sp_displayroles for role granted via the malicious T-SQL. Remediation Steps: Apply the SAP ASE 16.0 SP02 PL04 HF1 vendor supplied patch. Please refer to SAP Security Note 2353243 for additional information. Revision History: 06/02/2016 - Vulnerability disclosed to vendor 09/13/2016 - Patch released by vendor 09/16/2016 - Advisory published About Trustwave: Trustwave helps businesses fight cybercrime, protect data and reduce security risk. With cloud and managed security services, integrated technologies and a team of security experts, ethical hackers and researchers, Trustwave enables businesses to transform the way they manage their information security and compliance programs. More than three million businesses are enrolled in the Trustwave TrustKeeper cloud platform, through which Trustwave delivers automated, efficient and cost-effective threat, vulnerability and compliance management. Trustwave is headquartered in Chicago, with customers in 96 countries. For more information about Trustwave, visit https://www.trustwave.com. About Trustwave SpiderLabs: SpiderLabs(R) is the advanced security team at Trustwave focused on application security, incident response, penetration testing, physical security and security research. The team has performed over a thousand incident investigations, thousands of penetration tests and hundreds of application security tests globally. In addition, the SpiderLabs Research team provides intelligence through bleeding-edge research and proof of concept tool development to enhance Trustwave's products and services. https://www.trustwave.com/spiderlabs Disclaimer: The information provided in this advisory is provided "as is" without warranty of any kind. Trustwave disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Trustwave or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Trustwave or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.