Skip to content
RCE Write-up Advanced

Yahoo Bug Bounty - *.login.yahoo.com Remote Code Execution

Two Yahoo login subdomains ran a Struts2 version vulnerable to S2-016, where the redirect and redirectAction prefixes evaluated OGNL expressions. An attacker could run Java code and system commands on the server, though a filter blocked the public exploit and had to be bypassed.

Orange Tsai Follow

Published on blog.orange.tw

出問題的原因在於這� �個網站撰寫時是使用了 Struts2 這個 Java Framework,今年七月中的時,Struts2 爆發一個嚴重的 Remote Code Execution 等級的漏洞,這個漏洞被官方編號為 s2-016(基本上 Struts2 可以出� 的地方都出過一遍了之後再出事應該也不意外…),大致是說在 Struts2 中支援一些 Prefix 讓程式開發人員可以方便導向如 action, redirect, redirectAction 等,但在處理這些方法時並沒有做好過濾,造成在這之中的� �容可以用 ${ognlexp} 的形式來執行 OGNL 如:

Orange Tsai, on blog.orange.tw

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

Context

This is the second part of a two-part write-up on Yahoo's bug bounty programme. The first part covered an arbitrary file download in a Yahoo blog. This part covers a remote code execution (RCE) issue found on two hosts:

Text
b.login.yahoo.com
apt.login.yahoo.com

The apt host appears to be Yahoo's online advertising management system. The author could not tell what b is for.

From the original on blog.orange.tw

Both sites were built on the Struts2 Java framework. In mid-July of that year, Struts2 had a serious remote code execution vulnerability, officially numbered s2-016. The author's summary of s2-016: Struts2 supports prefixes that let developers redirect requests, such as action, redirect and redirectAction. When handling these methods it did not filter properly, so content inside them could be executed as OGNL in the form ${ognl_exp}.

Setup

The report does not describe any accounts, roles or tooling beyond the payloads shown. The testing was black box: the author could not see the server-side code and had to infer behaviour from responses. The author confirmed OGNL evaluation on the target with the arithmetic test below.

Finding it

The author first checked whether the vulnerability was present at all. The test payload was:

Text
redirectAction: ${123*123}

The site redirected to /15129.action. Since 123*123 is 15129, the server had evaluated the OGNL expression, which confirmed the vulnerability.

A detail the author highlights: when the vulnerability was published, the official advisory also released an attack PoC. Attackers therefore did not need to work out the details of the flaw; they could take the PoC and start modifying it. During that period many sites had not patched in time and were affected. The Chinese vulnerability reporting site 烏雲 (WooYun) had many people using the weakness to farm rank.

From the original on blog.orange.tw

Exploitation

Step 1: confirm OGNL evaluation

The arithmetic test above (redirectAction: ${123*123} redirecting to /15129.action) established that OGNL was being evaluated on the server. This is the same check described under Finding it and is the entry point for everything that follows.

Step 2: try the public exploit and watch it fail

With the vulnerability confirmed on Yahoo, the next step was to run the public attack code to execute commands. The public exploit did not work directly. The author notes this is expected, since otherwise the target would already have been exploited by many people. Working out why it failed became the research part of the exercise.

The author's general point: many script kiddies only use ready-made tools from the internet. Without understanding the underlying principle, it is common to have a real vulnerability that the tool cannot exploit. One example is a different library path. Public tools hard-code paths such as:

Text
com.opensymphony.xwork2

If the path is not in its default location, the tool fails.

Step 3: leak the environment with #request

When the location cannot be determined, the #request variable can be used to see the path and some sensitive information. The payload used here was:

Text
redirect: ${#request}
From the original on blog.orange.tw

The redirect location contained the contents of the #request variable. The author describes the satisfaction of seeing a mass of data come back. From this output the library path could be seen to be the default one, and some sensitive information was noted for possible later use.

Step 4: map the filter with blind testing

During testing, certain patterns made the exploit fail. The author suspected a filter or other server-side configuration was responsible, so those patterns had to be found and bypassed.

The redirect variant of the s2-016 flaw leaks information through the redirect, which lets the tester judge whether Java code executed successfully. Even though the test was black box, it could therefore be done blind.

Blind testing showed the patterns were roughly, though not completely, as follows:

  1. No method after a comma.
  2. No double quotes.
  3. Certain specific keywords are not allowed.

Bypassing these restrictions was enough to execute Java code.

Step 5: rewrite the exploit and run commands

The final approach was to rewrite the s2-016 exploit to bypass these patterns and to use OGNL static methods to execute commands. The final PoC is shown in the screenshot:

From the original on blog.orange.tw

It made the server sleep for ten seconds; the Total Duration column shows more than 10000 ms.

Step 6: execute a system command and exfiltrate the result

Next came running system commands. It was three or four in the morning by then, and the author did not want to spend time finessing it, so the command output was sent straight back to the author's own server to prove the system command had executed. The command run was uname -a, with the result sent back to the author's server:

From the original on blog.orange.tw

That closed the case.

Root cause

The mistake is in Struts2's handling of the action, redirect and redirectAction prefixes. Content inside these methods was not filtered properly, so ${ognl_exp} was evaluated as OGNL on the server. That is the s2-016 flaw as the author describes it.

On Yahoo's hosts, the public exploit still failed. The author's blind testing suggests a filter or similar server-side configuration was blocking certain patterns: no method after a comma, no double quotes, and some specific keywords. The report does not identify the filter or its configuration. The bypass combined a rewritten s2-016 exploit with OGNL static methods.

Impact

An attacker who could reach the vulnerable endpoints could execute Java code and then system commands on the server. The author demonstrated this with a ten-second sleep and with uname -a whose output was sent back to the author's server. The author notes Yahoo paid a generous bounty, though the payment process was cumbersome.

Fix

The report does not say what Yahoo changed.

Variants to test

  1. Send redirectAction: ${123*123} to a Struts2 endpoint. A redirect to /15129.action means OGNL is being evaluated.
  2. Send redirect: ${#request} and inspect the redirect location. Seeing request attributes, including library paths, means the environment can be leaked.
  3. Take a public s2-016 exploit and send it unchanged. If it fails while the arithmetic test succeeds, a filter may be present.
  4. Probe blind with the redirect leak: try a method after a comma, double quotes, and common keywords, watching whether the redirect reflects the evaluated result.
  5. Rewrite the exploit to avoid the blocked patterns and use OGNL static methods. A positive result is a measurable side effect, such as a delay of more than 10000 ms in the response time.
  6. The author ran uname -a with the output sent to his own server, which confirmed system command execution.

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

What happened, in plain words

This is the second part of a two-part story about reporting bugs to Yahoo and getting paid for it (a bug bounty). The first part was about a Yahoo blog that let you download files it should not have. This part is about something more serious: a way to make Yahoo's servers run code that the attacker chooses. Security people call that remote code execution, or RCE for short.

To understand why that matters, think of a website as a restaurant. Normally you order from the menu and the kitchen cooks what you asked for. Remote code execution is like being able to walk into the kitchen and tell the cooks to make anything you like, including dishes that are not on the menu. On a computer, the "dishes" are commands, and the kitchen is the server that runs the website.

The author found this on two Yahoo websites:

Text
b.login.yahoo.com
apt.login.yahoo.com

apt looks like Yahoo's online advertising management system, a place where advertisers manage their ads. The author could not work out what b is for.

From the original on blog.orange.tw

Both sites were built with a piece of software called Struts2. Struts2 is a Java framework: a collection of ready-made building blocks that programmers use to build web applications faster, the way a furniture kit gives you pre-cut parts instead of raw timber. In mid-July of that year, Struts2 had a serious security hole, officially numbered s2-016.

The author's explanation of s2-016 is this. Struts2 lets developers send a visitor to another page using special prefixes, words placed at the start of a value such as action, redirect and redirectAction. When Struts2 handled these, it did not check the content properly. As a result, anything written in the form ${ognl_exp} inside them was treated as a small program and run on the server.

OGNL is a mini language used inside Java applications to read values and do simple calculations. The ${...} wrapper means "work out what is inside and use the result". So if the inside is arithmetic, the server does the arithmetic. If the inside is something more powerful, the server runs that too. That is the whole problem in one sentence.

Finding it

The author first wanted to know whether the hole existed at all, before spending time on anything else. The test was:

Text
redirectAction: ${123*123}

Line by line: redirectAction: is the Struts2 prefix that tells the application to send the visitor onward to another page. ${123*123} is the part the server is supposed to treat as text. If the server is vulnerable, it does not treat it as text: it calculates 123 times 123, which is 15129, and then uses that number in the redirect.

The site redirected to /15129.action. That number is the proof. The server did the multiplication, which means it ran the content of ${...} as a program.

Why start here? Because it is cheap and harmless. A multiplication cannot damage anything, but it tells you whether the dangerous behaviour is present. It is like knocking on a door before trying the handle.

The author also points out something about how the flaw became so widespread. When the vulnerability was published, the official advisory also released attack code, a proof of concept (PoC). A PoC is a small demonstration that shows a flaw is real, and it can be reused and modified. So attackers did not need to understand the details; they could take the PoC and start changing it. Many sites had not patched in time and were hit. The Chinese vulnerability reporting site 烏雲 (WooYun) had many people using the weakness to farm rank, meaning to climb the site's reputation leaderboard by reporting or exploiting it.

From the original on blog.orange.tw

Trying the public exploit, and watching it fail

With the hole confirmed on Yahoo, the next step was to run the public attack code to execute commands. It did not work directly. The author says this is expected: if the public exploit worked everywhere, the target would already have been taken over by many people. Finding out why it failed became the research part of the exercise.

Here the author makes a general point worth remembering. Many script kiddies, people who use ready-made attack tools without understanding them, only run tools downloaded from the internet. Without understanding the underlying principle, it is common to have a real vulnerability that the tool simply cannot exploit. One example is a different library path. Public tools hard-code paths such as:

Text
com.opensymphony.xwork2

A path here is the address of a folder or package inside the application, the way a street address locates a building. com.opensymphony.xwork2 is the default location of part of Struts2. Attack code often needs to point at a class inside that package to do its work. If the application keeps that code somewhere else, the hard-coded address is wrong and the tool fails, even though the hole is still there.

Leaking the environment with #request

When you cannot tell where things live, the author suggests a trick: use the #request variable to see the path and some sensitive information. In OGNL, #request refers to the request object, the bundle of data the browser sent to the server plus what the server attached to it. The payload was:

Text
redirect: ${#request}

Line by line: redirect: is the Struts2 prefix for sending the visitor to another page. ${#request} asks the server to work out the value of the request object. On a vulnerable server, that value ends up in the redirect location, the address the browser is told to go to next.

From the original on blog.orange.tw

The redirect location contained the contents of the #request variable. The author describes the satisfaction of seeing a mass of data come back. From that output the library path could be seen to be the default one, and some sensitive information was noted for possible later use.

Why does this matter? Because it turns a blind attack into an informed one. Instead of guessing where the application's internals live, you read the address from the server's own answer. It is like asking a building's reception desk for the floor plan instead of trying every door.

Mapping the filter with blind testing

During testing, certain patterns made the exploit fail. A pattern here means a particular combination of characters, such as a comma followed by a word. The author suspected a filter, a piece of software that inspects incoming data and blocks anything matching a rule, or some other server-side configuration was responsible. So those patterns had to be found and bypassed.

Why could the author still learn anything? Because the redirect variant of the s2-016 flaw leaks information through the redirect. If the Java code runs, the result shows up in the redirect location; if it is blocked, it does not. So even though the test was black box, meaning the author could not see the server-side code and had to infer behaviour from responses, it could be done blind. Blind testing means you cannot see the result directly, so you send a probe and watch for an indirect sign, such as a change in the response.

Blind testing showed the patterns were roughly, though not completely, as follows:

  1. No method after a comma.
  2. No double quotes.
  3. Certain specific keywords are not allowed.

In plain terms: the filter seemed to reject input where a comma was followed by a method call, input containing double quote characters, and input containing some particular words. Bypassing these restrictions was enough to execute Java code.

Once you know which characters and words are blocked, you can rewrite the same attack using other characters and other ways of writing the same instruction.

Rewriting the exploit and running commands

The final approach was to rewrite the s2-016 exploit to bypass these patterns and to use OGNL static methods to execute commands. A static method is a function that belongs to a class itself rather than to one particular object made from it; in OGNL, calling one is a way to reach Java's built-in machinery, including the machinery that starts system commands. The final PoC is shown in the screenshot:

From the original on blog.orange.tw

It made the server sleep for ten seconds; the Total Duration column shows more than 10000 ms. A sleep is a deliberate pause. The Total Duration column is the response time shown by the testing tool.

Executing a system command and sending the result back

Next came running system commands. It was three or four in the morning by then, and the author did not want to spend time finessing it, so the command output was sent straight back to the author's own server to prove the system command had executed. The command run was uname -a, with the result sent back to the author's server:

From the original on blog.orange.tw

uname -a is a standard command that prints information about the operating system and kernel, the core of the system. Sending the output back to a server you control is called exfiltration: moving data out of the target to a place you can read it. It proves the command really ran, because the output could only come from the target machine.

That closed the case.

Why it worked, and what it means

The mistake is in Struts2's handling of the action, redirect and redirectAction prefixes. Content inside these methods was not filtered properly, so ${ognl_exp} was evaluated as OGNL on the server. That is the s2-016 flaw as the author describes it.

On Yahoo's hosts, the public exploit still failed. The author's blind testing suggests a filter or similar server-side configuration was blocking certain patterns: no method after a comma, no double quotes, and some specific keywords. The report does not identify the filter or its configuration. The bypass combined a rewritten s2-016 exploit with OGNL static methods.

What was the impact? An attacker who could reach the vulnerable endpoints could execute Java code and then system commands on the server. The author demonstrated this with a ten-second sleep and with uname -a whose output was sent back to the author's server. The author notes Yahoo paid a generous bounty, though the payment process was cumbersome.

What was the fix? The report does not say what Yahoo changed.

How you would test this yourself

These are the same steps in the same order, written so you can follow the reasoning:

  1. Send redirectAction: ${123*123} to a Struts2 endpoint. A redirect to /15129.action means OGNL is being evaluated.
  2. Send redirect: ${#request} and inspect the redirect location. Seeing request attributes, including library paths, means the environment can be leaked.
  3. Take a public s2-016 exploit and send it unchanged. If it fails while the arithmetic test succeeds, a filter may be present.
  4. Probe blind with the redirect leak: try a method after a comma, double quotes, and common keywords, watching whether the redirect reflects the evaluated result.
  5. Rewrite the exploit to avoid the blocked patterns and use OGNL static methods. A positive result is a measurable side effect, such as a delay of more than 10000 ms in the response time.
  6. The author ran uname -a with the output sent to his own server, which confirmed system command execution.

Glossary

  • Bug bounty: a programme where a company pays people for reporting security problems in its systems.
  • Remote code execution (RCE): a flaw that lets an attacker make a remote server run code the attacker chooses.
  • Server: the computer that stores a website and answers requests from browsers.
  • Framework: a collection of ready-made building blocks programmers use to build software faster.
  • Struts2: a Java framework for building web applications.
  • Java: a programming language and runtime commonly used for server-side applications.
  • s2-016: the official number of a Struts2 vulnerability that allowed OGNL expressions in certain prefixes to be evaluated.
  • Prefix: a word placed at the start of a value that tells the framework what to do with it, such as redirect.
  • OGNL: a small expression language used inside Java applications to read values and do calculations.
  • Expression: a piece of code that produces a value, such as 123*123.
  • ${...}: a wrapper meaning "work out what is inside and use the result".
  • Redirect: an instruction from a server telling the browser to go to a different address.
  • Proof of concept (PoC): a small demonstration showing that a vulnerability is real and can be triggered.
  • Script kiddie: someone who uses ready-made attack tools without understanding how they work.
  • Library path: the address of a folder or package inside an application, used to locate code.
  • com.opensymphony.xwork2: the default package path of part of Struts2.
  • #request: an OGNL variable referring to the request object, the data sent by the browser plus what the server attached.
  • Filter: software that inspects incoming data and blocks anything matching a rule.
  • Pattern: a particular combination of characters that a filter looks for.
  • Black box: testing where you cannot see the server-side code and must infer behaviour from responses.
  • Blind testing: sending a probe and watching for an indirect sign of success, because the result is not shown directly.
  • Bypass: getting around a restriction without removing it.
  • Static method: a function that belongs to a class itself rather than to one object made from it.
  • Sleep: a deliberate pause in a program, often used to prove code execution by measuring response time.
  • Total Duration: the response time shown by the testing tool.
  • uname -a: a standard command that prints information about the operating system and kernel.
  • Kernel: the core part of an operating system.
  • Exfiltration: moving data out of a target system to a place the attacker can read it.
  • Endpoint: a specific address on a server that accepts requests.
  • Patch: a software update that fixes a security problem.
  • Advisory: an official announcement describing a vulnerability and how to fix it.

More by Orange Tsai

View all

2 more disclosed reports, best first.

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.