Skip to content
RCE Write-up Intermediate

How I got 5500 from yahoo for RCE

A Yahoo-hosted Apache Struts2 application was vulnerable to CVE-2017-5638, allowing remote code execution via a crafted Content-Type header. The author demonstrated the vulnerability by injecting an expression that multiplied two numbers and added a response header, confirming code execution.

th3g3nt3lman Follow

Published on medium.com

Bounty$5,500 View original

I always believed that sharing is caring, and i have been learning from multiple security researchers in the bug bounty field, so i decided to share my few findings with you as it might help others who started in the Bug Bounty journey.

Th3G3nt3lman, on medium.com

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.

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. 4 min read.

Context

A few months before this write-up, a critical vulnerability was discovered in Apache Struts2, tracked as CVE-2017-5638, which leads to remote code execution. An easy exploit for it was published, and a lot of web applications were being exploited in a massive way.

During reconnaissance, roughly three weeks after the Struts2 exploit was published, the researcher came across this link:

Text
https://svdevems01.direct.gq1.yahoo.com/sm/login.jsp

It is a login page for the Selligent Messages studio solution used by Yahoo.

From the original on medium.com

The login page itself did not yield anything. The interesting part came from an endpoint discovered later:

Text
https://svdevems01.direct.gq1.yahoo.com/sm/login/loginpagecontentgrabber.do

As the researcher notes, endpoints ending in .action, .do or .go indicate that the web application is running Struts2. That made this endpoint a candidate for the published CVE-2017-5638 exploit.

Setup

No accounts, roles or special tooling are described. The work was done during ordinary reconnaissance against the public login page and the endpoint above. The only precondition that matters is that the target runs Struts2, which the .do extension on the endpoint suggests.

Finding it

The researcher tried to find vulnerabilities on the login page and failed, until the loginpagecontentgrabber.do endpoint turned up. Because of the .do suffix, the application was identified as Struts2, and therefore a candidate for CVE-2017-5638.

The published exploit was easy to use, but it did not work against this target, even though the target was confirmed to be vulnerable. The researcher's conclusion was that a WAF or something similar was blocking the attacks.

Stopping there was not an option: the target was vulnerable, and a valid proof of concept was needed to report it. After some searching, the researcher found a Twitter post with a payload that can bypass a WAF to exploit this vulnerability.

Exploitation

The detection method found makes use of the Content-Type HTTP header to send a specially crafted packet. The header is shown below:

HTTP
Content-Type: %{#context[‘com.opensymphony.xwork2.dispatcher.HttpServletResponse’].addHeader(‘X-Ack-Th3g3nt3lman-POC’,4*4)}.multipart/form-data

Step 1: Send the crafted Content-Type header

The value is an OGNL expression wrapped in %{...} and placed in front of .multipart/form-data. Struts2 evaluates the expression, and the expression calls addHeader on the HttpServletResponse object obtained from the OGNL context, adding a response header named X-Ack-Th3g3nt3lman-POC whose value is the result of 4*4.

Step 2: Read the result

The new request asks the web server to multiply two numbers, and the same mechanism can be used to ask the web server to perform any other operation. In this example the two numbers are 4 and 4, and the answer from the web server was 16, which concluded that the server is vulnerable.

The response, as per the picture below, contains the new header X-Ack-Th3g3nt3lman-POC: 16.

From the original on medium.com

That was enough to report the bug to Yahoo through HackerOne. Yahoo triaged the report within 30 minutes, took the application offline to fix the issue, and the researcher confirmed the fix afterwards. Within a week the researcher was awarded 5500 USD for this finding.

Root cause

The application runs Apache Struts2 and processes the Content-Type header through OGNL. When the header value contains an OGNL expression, Struts2 evaluates it, which is the flaw behind CVE-2017-5638. Struts2 evaluates the OGNL expression in the header, which is the flaw behind CVE-2017-5638.

The published exploit did not work against this target, which the researcher attributes to a WAF or something similar blocking the attacks. The bypass delivers the expression inside the Content-Type header, which the researcher found in a Twitter post after the published exploit was blocked. The report does not describe the WAF rules themselves, so the exact reason the original payload was blocked is not stated.

Impact

The proof of concept only multiplies two numbers and reflects the result in a response header, but the same mechanism can be used to ask the web server to perform any other operation. The same mechanism can be used to ask the web server to perform any other operation, which is what the CVE-2017-5638 classification implies. The report does not enumerate what was reachable from that host.

Fix

Yahoo took the application offline to fix the issue, and the researcher confirmed the fix afterwards. The report does not describe the specific change made.

Variants to test

  1. Look for endpoints ending in .action, .do or .go on in-scope hosts. A positive result is an endpoint that responds like a Struts2 action rather than a static file.
  2. Send the Content-Type header above with a harmless arithmetic expression such as 4*4. A positive result is a response containing the header X-Ack-Th3g3nt3lman-POC: 16.
  3. If the straightforward payload is blocked, try delivering the OGNL expression through the Content-Type header instead of the body or parameters, as done here. A positive result is the same reflected header.
  4. Change the header name and the expression to confirm evaluation rather than a cached or reflected value. A positive result is a header whose value matches the computed expression.

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. 10 min read.

What happened, in plain words

A security researcher found a way to make a Yahoo web server run a small calculation of his choosing, and prove it by having the server send back the answer. The server was running a piece of software called Apache Struts2, which had a serious, publicly known flaw. The researcher used a trick that slipped past whatever filter was protecting the site, showed the server answering 4*4 with 16, reported it through HackerOne, and was paid 5500 USD. Yahoo triaged the report within 30 minutes and took the application offline to fix it.

This article walks through the same steps for someone who has never done security testing before. You only need to understand how a browser talks to a website.

Background: what Struts2 is and why it mattered

When you open a web page, your browser sends a request to a server, and the server sends back a response. Many websites are built with frameworks: collections of ready-made code that handle common jobs such as reading a form, checking a login, or producing a page. Apache Struts2 is one such framework, written in Java and widely used for building web applications.

A few months before this write-up, a critical vulnerability was discovered in Apache Struts2. It is tracked as CVE-2017-5638. A CVE is a public catalogue number for a known security flaw, so people can refer to the same bug unambiguously. This particular flaw leads to remote code execution, usually shortened to RCE: an attacker can make the server run commands of their choosing, from a distance, without logging in. An easy exploit for it was published, and a lot of web applications were being exploited in a massive way.

An exploit here means a ready-made request that triggers the flaw. Once one is public, anyone can copy it, which is why so many sites were hit.

Reconnaissance: finding the login page

Reconnaissance (recon) is the information-gathering phase: looking at what a company exposes on the internet before trying anything. Roughly three weeks after the Struts2 exploit was published, during recon, the researcher came across this link:

Text
https://svdevems01.direct.gq1.yahoo.com/sm/login.jsp

Reading the URL from left to right: https:// means the connection is encrypted; svdevems01.direct.gq1.yahoo.com is the name of the server; /sm/login.jsp is the path to a particular page on it. The page is a login page for the Selligent Messages studio solution used by Yahoo. In other words, it is the sign-in screen of a marketing or messaging product that Yahoo runs.

From the original on medium.com

The picture shows that login page as the researcher found it.

A login page is interesting to a tester because it is a door into an application, but it is also usually well guarded. The researcher tried to find vulnerabilities on the login page itself and failed. That is normal: the front door is often the most carefully built part.

The endpoint that changed things

The interesting part came from an endpoint discovered later:

Text
https://svdevems01.direct.gq1.yahoo.com/sm/login/loginpagecontentgrabber.do

An endpoint is a specific address on a server that does a specific job, rather than showing a normal page. Think of a restaurant: the dining room is the website you see, and the kitchen door is the endpoint where orders are actually processed. This one is called loginpagecontentgrabber.do, which suggests it grabs content for the login page.

The important detail is the ending: .do. As the researcher notes, endpoints ending in .action, .do or .go indicate that the web application is running Struts2. It is a fingerprint, like recognising a car brand from its badge. That made this endpoint a candidate for the published CVE-2017-5638 exploit.

Setup: what was needed

No accounts, roles or special tooling are described. The work was done during ordinary reconnaissance against the public login page and the endpoint above. The only precondition that matters is that the target runs Struts2, which the .do extension on the endpoint suggests. You do not need to be logged in to reach these addresses; they are on the public internet.

Finding it: the exploit was blocked

The published exploit was easy to use, but it did not work against this target, even though the target was confirmed to be vulnerable. The researcher's conclusion was that a WAF or something similar was blocking the attacks.

A WAF, or web application firewall, is a filter that sits in front of a website and inspects incoming requests. If a request looks like a known attack, the WAF refuses it before the website ever sees it. The everyday comparison is a bouncer at a club door who has a list of troublemakers: the club itself never meets them. The published exploit was on that list, so it was turned away.

Stopping there was not an option: the target was vulnerable, and a valid proof of concept was needed to report it. A proof of concept, or PoC, is a small, safe demonstration that a flaw is real, something a defender can reproduce. Without one, a report is just a claim. After some searching, the researcher found a Twitter post with a payload that can bypass a WAF to exploit this vulnerability. A payload is the part of a request that carries the attack.

Exploitation: sending the crafted header

The detection method found makes use of the Content-Type HTTP header to send a specially crafted packet. The header is shown below:

HTTP
Content-Type: %{#context[‘com.opensymphony.xwork2.dispatcher.HttpServletResponse’].addHeader(‘X-Ack-Th3g3nt3lman-POC’,4*4)}.multipart/form-data

Before explaining it, two ideas from everyday web traffic.

Headers are the labelled lines that travel with every request and response, like the address and handling notes on an envelope. They tell the server what kind of data is being sent, who is asking, and so on. Content-Type is the header that says what format the body of the request is in. multipart/form-data is the format browsers use when you upload a file or submit a form with attachments.

OGNL is an expression language used inside Struts2. An expression is a small instruction that produces a value, such as 4*4. The %{...} wrapper tells Struts2: treat what is inside as an expression and evaluate it.

Now the header, piece by piece:

  1. Content-Type: is the name of the header being set.
  2. %{ opens an OGNL expression, so Struts2 will evaluate what follows instead of treating it as plain text.
  3. #context[‘com.opensymphony.xwork2.dispatcher.HttpServletResponse’] reaches into Struts2's internal context and picks out the object that represents the response the server is about to send back. The context is the framework's shared workspace for the current request.
  4. .addHeader(‘X-Ack-Th3g3nt3lman-POC’,4*4) calls a method on that object which adds a header to the response. The header is named X-Ack-Th3g3nt3lman-POC, and its value is the result of 4*4. The X- prefix is a common convention for custom, non-standard headers.
  5. } closes the expression, and .multipart/form-data is appended so the header still looks like a normal content type to a casual filter.

In short: the value is an OGNL expression wrapped in %{...} and placed in front of .multipart/form-data. Struts2 evaluates the expression, and the expression calls addHeader on the HttpServletResponse object obtained from the OGNL context, adding a response header named X-Ack-Th3g3nt3lman-POC whose value is the result of 4*4.

Step 1: Send the crafted Content-Type header

You send a request to the endpoint with this header in place of the ordinary content type. The expression is delivered inside the Content-Type header, which is the bypass the researcher found in a Twitter post.

Step 2: Read the result

The new request asks the web server to multiply two numbers, and the same mechanism can be used to ask the web server to perform any other operation. In this example the two numbers are 4 and 4, and the answer from the web server was 16, which concluded that the server is vulnerable.

Why arithmetic? Because it is harmless and unambiguous. If the server replies with a header containing 16, the server clearly computed something the researcher asked for. That is the proof of concept: no damage, no data touched, just the server showing it follows instructions.

The response, as per the picture below, contains the new header X-Ack-Th3g3nt3lman-POC: 16.

From the original on medium.com

The picture shows the response with that header and its value, which is the evidence the researcher needed.

That was enough to report the bug to Yahoo through HackerOne. HackerOne is a platform where researchers submit vulnerability reports to companies and companies pay rewards, called bounties. Yahoo triaged the report within 30 minutes: triage is the first check where the company confirms the report is real and worth acting on. It took the application offline to fix the issue, and the researcher confirmed the fix afterwards. Within a week the researcher was awarded 5500 USD for this finding.

Root cause: why this worked

The application runs Apache Struts2 and processes the Content-Type header through OGNL. When the header value contains an OGNL expression, Struts2 evaluates it, which is the flaw behind CVE-2017-5638. Struts2 evaluates the OGNL expression in the header, which is the flaw behind CVE-2017-5638.

The published exploit did not work against this target, which the researcher attributes to a WAF or something similar blocking the attacks. The bypass works because the expression is delivered inside the Content-Type header rather than in the request body or parameters that the published exploit used, so the filtering in place did not catch it. The report does not describe the WAF rules themselves, so the exact reason the original payload was blocked is not stated.

Impact: how bad it could have been

The proof of concept only multiplies two numbers and reflects the result in a response header, but the same mechanism can be used to ask the web server to perform any other operation. The same mechanism can be used to ask the web server to perform any other operation, which is what the CVE-2017-5638 classification implies. Unauthenticated means without any login or account. The report does not enumerate what was reachable from that host.

Fix: what happened next

Yahoo took the application offline to fix the issue, and the researcher confirmed the fix afterwards. The report does not describe the specific change made.

Variants to test

If you want to practise the same thinking on systems you are allowed to test:

  1. Look for endpoints ending in .action, .do or .go on in-scope hosts. A positive result is an endpoint that responds like a Struts2 action rather than a static file.
  2. Send the Content-Type header above with a harmless arithmetic expression such as 4*4. A positive result is a response containing the header X-Ack-Th3g3nt3lman-POC: 16.
  3. If the straightforward payload is blocked, try delivering the OGNL expression through the Content-Type header instead of the body or parameters, as done here. A positive result is the same reflected header.
  4. Change the header name and the expression to confirm evaluation rather than a cached or reflected value. A positive result is a header whose value matches the computed expression.

Glossary

  • Apache Struts2: a Java framework for building web applications, used by many large sites.
  • CVE: a public catalogue number for a known security vulnerability, so everyone can refer to the same bug.
  • CVE-2017-5638: the identifier for the Struts2 flaw exploited here, which allows remote code execution.
  • Remote code execution (RCE): a flaw that lets an attacker make a server run commands of their choosing from a distance, without logging in.
  • Exploit: a request or piece of code that triggers a vulnerability.
  • Payload: the part of a request that carries the attack.
  • Reconnaissance (recon): the information-gathering phase of security testing, looking at what a company exposes publicly.
  • Endpoint: a specific address on a server that performs a particular job, rather than showing a normal page.
  • HTTP header: a labelled line sent with every web request and response, carrying information such as the data format or the identity of the requester.
  • Content-Type: the header that states the format of the data being sent, for example multipart/form-data.
  • multipart/form-data: the format browsers use when submitting forms with file uploads.
  • OGNL: an expression language used inside Struts2 to compute values.
  • Expression: a small instruction that produces a value, such as 4*4.
  • Context: the framework's shared workspace of objects for the current request.
  • HttpServletResponse: the object in Struts2 that represents the response being sent back to the browser.
  • addHeader: a method that adds a header to a response.
  • WAF (web application firewall): a filter in front of a website that inspects requests and blocks ones that look like attacks.
  • Bypass: getting past a protection such as a WAF without triggering it.
  • Proof of concept (PoC): a small, safe demonstration that a vulnerability is real and reproducible.
  • HackerOne: a platform where researchers report vulnerabilities to companies and receive bounty payments.
  • Triage: the company's first review of a report, confirming it is real and worth acting on.
  • Bounty: a reward paid by a company for a valid vulnerability report.
  • Unauthenticated: without any login or account.

More by th3g3nt3lman

View all

3 more disclosed reports, best first.

More from Yahoo! / Verizon Media

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.