Skip to content
RCE Write-up Advanced

How I chained 4 bugs features into RCE on amazon

A path normalization inconsistency between Nuxeo's authentication filter and Tomcat allowed bypassing access controls to reach protected Seam servlets. Chaining Seam's actionMethod feature, double EL evaluation, and an EL blacklist bypass led to remote code execution.

Orange Tsai Follow

Published on blog.orange.tw

Hi! This is the case study in my Black Hat USA 2018 and DEFCON 26 talk, you can also check slides here:

Orange Tsai (@orange_8361), 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. 9 min read.

Context

This is the case study behind my Black Hat USA 2018 and DEFCON 26 talk, Breaking Parser Logic! Take Your Path Normalization Off and Pop 0days Out. The theme is inconsistency: the same idea as my earlier SSRF work on URL parser versus URL fetcher mismatches, applied this year to the path parser and path normalisation.

Writing a well-designed parser is hard. Every entity has its own standard and implementation, and to fix a bug without breaking business logic it is common to add a work-around or a filter rather than patch the bug directly. Whenever the filter and the method it protects disagree, the security mechanism can be bypassed.

While reading advisories I came across a feature called URL Path Parameter. Researchers had already noted that it can cause security issues, but usually only when the programming is already broken. With a little mind-mapping I found that this feature applies perfectly to multi-layered architectures, and is vulnerable by default without any coding failure. If you run a reverse proxy in front of a Java back end, you are under threat.

I first hit this attack surface in 2015 during a red teaming engagement, and later built a challenge around it for WCTF 2016. Nobody solved that challenge during the competition, which suggested the trick was not well known. I checked the scanners in DirBuster, wFuzz, DirB and DirSearch; at the time of writing only DirSearch had adopted the pattern, on 1 May 2017.

The target here is collaborate-corp.amazon.com, which appears to be a collaboration system for internal purposes. The copyright notice at the bottom shows it was built from the open source project Nuxeo, a very large Java project. I was looking to improve my Java auditing skill, so the story starts there.

preview
preview From the original on blog.orange.tw

Setup

The chain executes arbitrary EL without any authentication. The relevant versions named in the report are:

Component Version
Seam Framework 2.3.1.Final (latest at the time)
Nuxeo fix 8.10
Seam EL blacklist introduced 2.2.2.Final

Finding it

When I get Java source, the first thing I do is read pom.xml and look for outdated packages, because in the Java ecosystem most vulnerabilities come from known vulnerable components (OWASP Top 10 A9). Is there a Struts2, FastJSON, XStream or a component with a deserialisation bug? If yes, congratulations.

In Nuxeo most packages were up to date, but I found an old friend: Seam Framework, the JBoss/Red Hat web application framework that had been popular years earlier and still underpins many applications. I had reviewed Seam in 2016 and found numerous hacker-friendly features. It looked like the Seam part could not be accessed directly, so I noted it and kept going.

The authentication filter

Looking at access control in WEB-INF/web.xml, Nuxeo uses a custom authentication filter, NuxeoAuthenticationFilter, mapped to /*. Most pages require authentication, but a whitelist allows a few entry points such as login.jsp. All of this is implemented in a method called bypassAuth.

bypassAuth retrieves the current requested page and compares it with unAuthenticatedURLPrefix. The way it retrieves that page is where the first problem appears: Nuxeo writes a method that extracts the requested page from HttpServletRequest.RequestURI, and to handle URL path parameters it truncates everything after a semicolon.

The behaviour of URL path parameters varies between web servers, each with its own implementation. Nuxeo's truncation may be safe in containers like WildFly, JBoss and WebLogic, but the target runs on Tomcat. The difference between getRequestedPage and the servlet container's own parsing is the security problem.

Exploitation

Step 1: Path normalisation bug leads to ACL bypass

Because Nuxeo truncates at the semicolon while Tomcat does not, we can forge a request that matches the whitelist in the ACL but reaches an unauthorised area in the servlet. I chose login.jsp as the prefix. The bypass looks like this:

With this, the redirection to authentication is bypassed, but most pages still return a 500 error, because the servlet logic cannot obtain a valid user principal and throws a Java NullPointerException. Even so, it gives us a chance to knock on the door. There is a quicker way to open it, but the first attempt is worth writing down.

Step 2: Code reuse feature leads to partial EL invocation

The next step is to chain the first bug to reach the unauthorised Seam servlet. Seam has a series of HTTP parameters that control where the browser is redirected, and actionOutcome is one of them; in 2013 @meder found remote code execution through it (CVE-2010-1871). Here I use a different one: actionMethod.

actionMethod is a special parameter that can invoke specific JBoss EL (Expression Language) from the query string. That sounds dangerous, but there are preconditions, implemented in the method callAction. To invoke the EL, all of the following must hold:

  1. The value of actionMethod must be a pair that looks like FILENAME:EL_CODE.
  2. The FILENAME part must be a real file under the context root.
  3. The file FILENAME must contain the content "#{EL_CODE}" (the double quotes are required).

For example, if there is a file named login.xhtml under the context root, you can invoke the EL user.username by URL:

On its own this is not enough: you cannot control any file under the context root, so you cannot invoke arbitrary EL on a remote server.

Step 3: Double evaluation leads to EL injection

There is one more crazy feature. If the previous invocation returns a string, and that string looks like an EL expression, Seam invokes it again.

From the original on blog.orange.tw

The detailed call stack is:

  1. callAction(Pages.java)
  2. handleOutcome(Pages.java)
  3. handleNavigation(SeamNavigationHandler.java)
  4. interpolateAndRedirect(FacesManager.java)
  5. interpolate(Interpolator.java)
  6. interpolateExpressions(Interpolator.java)
  7. createValueExpression(Expressions.java)

With this feature we can execute arbitrary EL if we control the returned value. It is very similar to ROP in binary exploitation, so we need a good gadget. I chose the one in widgets/suggest_add_new_directory_entry_iframe.xhtml, because request.getParameter there returns a string we control from the query string. The whole tag is meant to assign a variable, but we can abuse its semantics.

We put the second stage payload in the directoryNameForPopup parameter. Combined with the first bug, this executes arbitrary EL without any authentication. The PoC:

That is not the end. Although we can execute arbitrary EL, we still fail to pop a shell, which leads to the next section.

Step 4: EL blacklist bypass leads to RCE

Seam knows EL is dangerous. Since Seam 2.2.2.Final there is an EL blacklist that blocks dangerous invocations, and Nuxeo uses the latest Seam (2.3.1.Final), so the blacklist must be bypassed. It lives in resources/org/jboss/seam/blacklist.properties.

After a little study, the blacklist turned out to be simple string matching, and a blacklist is always a bad idea. The first time I saw it I recalled the bypass for Struts2 S2-020: the idea is the same, use array-like operators to avoid the blacklist patterns. Just change:

to:

That is all it takes.

The last thing is to write the shellcode in JBoss EL. We use the Java reflection API to get the java.lang.Runtime object and list all its methods. Index 7 is the method getRuntime(), which returns a Runtime instance, and index 15 is exec(String), which executes our command.

The full chain

  1. Path normalisation bug leads to ACL bypass.
  2. Bypass the whitelist to access the unauthorised Seam servlet.
  3. Use the Seam feature actionMethod to invoke gadgets in the file suggest_add_new_directory_entry_iframe.xhtml.
  4. Prepare the second stage payload in the HTTP parameter directoryNameForPopup.
  5. Use array-like operators to bypass the EL blacklist.
  6. Write the shellcode with the Java reflection API.
  7. Wait for the shell back.

Here is the whole exploit:

From the original on blog.orange.tw

Running the Perl script gave us the shell:

From the original on blog.orange.tw

Root cause

The first bug is a parser inconsistency. Nuxeo's method extracts the requested page from HttpServletRequest.RequestURI and truncates at the semicolon to handle URL path parameters, while Tomcat's own handling of the same URI differs. The filter therefore sees a path that matches the unAuthenticatedURLPrefix whitelist, and the servlet sees a different, unauthorised path. The Nuxeo approach may be safe in WildFly, JBoss or WebLogic, but not in Tomcat.

The rest of the chain relies on Seam features. actionMethod lets a query string invoke EL from a file under the context root, and the double evaluation means a returned string that looks like EL is invoked again, so a gadget that reflects a request parameter gives arbitrary EL. The EL blacklist added in Seam 2.2.2.Final is plain string matching, so wrapping the expression in array-like operators avoids the patterns.

Impact

On this target the chain led to remote code execution on the Amazon collaboration system. More broadly, the path parameter attack surface can leak information, bypass ACLs (as in my Uber OneLogin bypass case) and lead to RCE in several bug bounty programs. The ACL bypass alone only got past the authentication redirect, with most pages returning a 500 error.

Fix

There are three sides to the fix.

JBoss. I reported the Seam features to [redacted] in September 2016. Their reply was that Seam was only included in EAP 5, not 6 or 7; EAP was near the end of maintenance support, ending in November 2016; the upstream version I tested was released over three years earlier; during maintenance support EAP 5 only receives patches for important or critical issues; and while RCE is possible, it requires the attacker to first upload a file, which reduces the impact to moderate. They said they would not fix these issues at this stage of the Seam project lifecycle. Because of the EOL there is no official patch for these features, so if you use Seam I recommend mitigating with Nuxeo's fix.

Amazon. The security team isolated the server with a rapid investigation, discussed with me how to mitigate, and listed every step they had taken in detail.

Nuxeo. After notification from Amazon, Nuxeo quickly released a patch in version 8.10. The patch overrides the method callAction() to fix the crazy feature. If you need the patch for your own Seam application, refer to the Nuxeo commit.

Timeline

  • 10 March 2018 01:13 GMT+8: report to the Amazon security team via [redacted]
  • 10 March 2018 01:38 GMT+8: acknowledgement that they are investigating
  • 10 March 2018 03:12 GMT+8: ask to join the conference call with the security team
  • 10 March 2018 05:30 GMT+8: conference call with Amazon, get status and the steps taken
  • 10 March 2018 16:05 GMT+8: ask whether public disclosure at my Black Hat talk is possible
  • 15 March 2018 04:58 GMT+8: Nuxeo releases version 8.10 patching the RCE vulnerability
  • 15 March 2018 23:00 GMT+8: conference call with Amazon, discuss public disclosure details
  • 05 April 2018 05:40 GMT+8: receive the award from Amazon

Variants to test

  • Semicolon truncation against other containers. Send a whitelisted prefix followed by ;/..;/ segments to a Java back end behind a reverse proxy. A positive result is that the filter's view of the path matches the whitelist while the servlet reaches a page that should require authentication.
  • Other Seam HTTP parameters. Test parameters in the same family as actionOutcome and actionMethod that control redirection or navigation. A positive result is EL evaluation triggered from the query string.
  • Gadget files under the context root. Look for files whose content includes #{...} around a request parameter, as in suggest_add_new_directory_entry_iframe.xhtml. A positive result is that a parameter you control is returned and then evaluated a second time.
  • EL blacklist bypass. Where a Seam blacklist blocks a pattern, wrap the expression in array-like operators as with S2-020. A positive result is that the blocked invocation executes.
  • Scanner coverage. Check whether your directory brute-force tool sends path parameter patterns; at the time of writing only DirSearch had adopted the pattern, on 1 May 2017.

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

What happened, in plain words

A security researcher found a way to take full control of a server belonging to Amazon. The server ran a collaboration system, a website where people inside a company share documents and work together. The researcher did not have a password or an account. He got in anyway, and in the end he could run any command he wanted on the machine. That is called remote code execution, or RCE for short: from your own computer, over the internet, you make someone else's computer do what you tell it.

The interesting part is how he did it. He did not find one giant hole. He found four smaller weaknesses and joined them together, like climbing a staircase where each step is only useful because the previous one lifted you higher. Security people call this chaining. The talk this story comes from is called Breaking Parser Logic! Take Your Path Normalization Off and Pop 0days Out, given at Black Hat USA 2018 and DEFCON 26, two large security conferences.

The theme of the talk is inconsistency. A parser is the part of a program that reads text and decides what it means. When two different programs read the same text and disagree about what it says, you can sometimes slip something past one of them. The researcher had used the same idea before, on the part of a program that reads web addresses (URLs), and this time he applied it to the part that reads file paths.

Writing a parser that gets everything right is genuinely hard. Every product has its own standard and its own implementation. And when a bug is found, the usual fix is not to rewrite the parser properly, because that might break the product for everyone. Instead someone adds a work-around or a filter: a small check that catches the bad case. Whenever the filter and the thing it is protecting disagree about what the text means, the protection can be walked around.

While reading security advisories, the researcher noticed a feature called URL Path Parameter. Other researchers had already pointed out that it can cause security problems, but usually only when the code is already badly written. With a bit of thinking, he realised the feature fits perfectly against systems built in layers, and that such systems are vulnerable by default, without anyone making a coding mistake. If you put a reverse proxy in front of a Java back end, you are exposed. A reverse proxy is a server that sits in front of your real application and forwards requests to it, a bit like a receptionist who decides which visitor goes to which office.

He first came across this attack surface in 2015, during a red teaming engagement. Red teaming means being paid to attack your own organisation, on purpose, to find the holes before criminals do. He later built a challenge around the trick for WCTF 2016, a competition where top teams from around the world each design challenges for the others. Nobody solved his challenge during the competition, which suggested the trick was not well known. He also checked the popular tools people use to guess file and folder names on a website (DirBuster, wFuzz, DirB and DirSearch). At the time of writing, only DirSearch had adopted the pattern, on 1 May 2017.

The target was collaborate-corp.amazon.com, which looks like a collaboration system meant for internal use. The copyright notice at the bottom of the page showed it was built from an open source project called Nuxeo, a very large piece of software written in the Java programming language. Open source means the source code is public, so anyone can read it. The researcher wanted to get better at reading Java code, so that is where the story starts.

preview
preview From the original on blog.orange.tw

The setup

The chain executes arbitrary EL without any authentication. Perl is an older programming language often used for quick scripts.

The versions named in the report are:

Component Version
Seam Framework 2.3.1.Final (the latest at the time)
Nuxeo fix 8.10
Seam EL blacklist introduced 2.2.2.Final

The context root is the folder on the server that the website is served from, the equivalent of the public folder of a site.

Finding it

When the researcher gets hold of Java source code, the first thing he does is open a file called pom.xml. That file lists the libraries the project depends on, a bit like the ingredients list on a food packet. He looks for outdated packages, because in the Java world most vulnerabilities come from known vulnerable components. This is item A9 on the OWASP Top 10, a well-known list of the most common security mistakes. Is there an old Struts2, FastJSON or XStream, or some component with a known bug in how it reads data back in (deserialisation)? If yes, congratulations, you probably have an easy way in.

In Nuxeo most packages were up to date. But he found an old friend: Seam Framework, a web application framework made by JBoss, a division of Red Hat. A framework is a ready-made set of building blocks that developers use to build an application faster. Seam had been popular years earlier and still underpins many applications. The researcher had reviewed Seam in 2016 and found many features that are friendly to an attacker. It looked like the Seam part of this site could not be reached directly, so he made a note and kept going.

The authentication filter

He then looked at how access control was set up in a file called WEB-INF/web.xml. That file is the configuration that tells the Java server which piece of code handles which address. Nuxeo uses a custom authentication filter called NuxeoAuthenticationFilter, and it is mapped to /*, meaning it sees every single request that arrives. A filter is a checkpoint that inspects a request before it reaches the actual page, like a bouncer at a door.

Most pages require you to be logged in, but a whitelist allows a few entry points, such as login.jsp. A whitelist is a list of things that are allowed; everything not on the list is refused. All of this is implemented in a method called bypassAuth. A method is a named block of code that does one job.

bypassAuth works out which page the visitor is asking for, and compares it with a list called unAuthenticatedURLPrefix, the prefixes that are allowed without logging in. The way it works out the page is where the first problem appears. Nuxeo wrote its own method that takes the requested address from HttpServletRequest.RequestURI (the raw address the browser asked for) and, to handle URL path parameters, cuts off everything after a semicolon.

A URL path parameter is a small piece of extra information stuck onto a web address after a semicolon, like a sticky note on a parcel. The behaviour of these parameters varies between web servers, because each one implements them its own way. Nuxeo's cut-off approach may be safe in containers like WildFly, JBoss and WebLogic, but this target runs on Tomcat. The difference between what getRequestedPage decides and what the servlet container decides is the security problem.

Exploitation

Step 1: a path normalisation bug leads to an ACL bypass

ACL stands for access control list: the rules about who may see what. Because Nuxeo cuts the address at the semicolon while Tomcat does not, you can craft a request that matches the whitelist as far as the filter is concerned, but reaches a page that should require a login as far as the servlet is concerned. He chose login.jsp as the prefix, because that is on the whitelist. The bypass looks like this:

Line by line, in plain words:

  • /login.jsp is the allowed page. The filter sees this at the start and is satisfied.
  • ; is the semicolon. Nuxeo treats everything after it as a path parameter and throws it away, so from Nuxeo's point of view the request is just for login.jsp.
  • /.. means go up one folder. In a normal address, .. lets you climb out of the current folder into its parent. Here it is used to climb back out of the allowed area.
  • /.. again climbs up once more.
  • /some-unauthorized-page is the page the attacker actually wants, which should have required a login.

Tomcat does not throw away the part after the semicolon, so it reads the whole address and ends up at the unauthorised page. The filter and the server disagree about what the address means, and that disagreement is the whole bug.

With this, the redirect to the login page is bypassed. But most pages still return a 500 error, which is the server saying something went wrong on its side. The reason is that the page's code tries to find out who the logged-in user is, finds nobody, and crashes with a Java NullPointerException, which is what happens when a program tries to use something that is not there. Even so, it gives us a chance to knock on the door. There is a quicker way to open it, but the first attempt is worth writing down.

Step 2: a code reuse feature leads to partial EL invocation

The next step is to use the first bug to reach the Seam part of the application, which should not be reachable without logging in. Seam has a set of HTTP parameters that control where the browser is sent next. A parameter is a named value attached to a request, the part after the ? in an address. actionOutcome is one of them, and in 2013 a researcher called @meder found remote code execution through it, tracked as CVE-2010-1871. A CVE is a public catalogue number given to a known vulnerability so people can refer to it unambiguously. Here the researcher uses a different parameter: actionMethod.

actionMethod is a special parameter that can make Seam run a piece of JBoss EL taken from the query string. EL stands for Expression Language: a small language that lets a page ask for a value, such as the current user's name, and have the framework work it out. A query string is the part of an address after the question mark. Being able to run EL from a parameter sounds dangerous, but there are conditions, implemented in a method called callAction. To invoke the EL, all of the following must be true:

  1. The value of actionMethod must be a pair that looks like FILENAME:EL_CODE, a file name, a colon, then the expression.
  2. The FILENAME part must be a real file under the context root.
  3. The file FILENAME must contain the content "#{EL_CODE}", and the double quotes are required.

For example, if there is a file named login.xhtml under the context root, you can invoke the EL user.username by URL:

Line by line:

  • /login.seam is the Seam page being requested.
  • ? starts the query string, the list of parameters.
  • actionMethod= names the parameter Seam looks for.
  • login.xhtml:user.username is the pair: the file login.xhtml, a colon, then the expression user.username, which asks for the username of the current user.

On its own this is not enough. You cannot control any file under the context root, so you cannot make the server run an expression of your choosing. The feature is limited by the files that already exist.

Step 3: double evaluation leads to EL injection

There is one more feature, and it is a strange one. If the previous invocation returns a string, and that string itself looks like an EL expression, Seam runs it again. In other words, the answer to the first question becomes the second question. Imagine asking a librarian for a book title, and the title she gives you turns out to be another request, which she then carries out.

From the original on blog.orange.tw

The detailed call stack is:

  1. callAction(Pages.java)
  2. handleOutcome(Pages.java)
  3. handleNavigation(SeamNavigationHandler.java)
  4. interpolateAndRedirect(FacesManager.java)
  5. interpolate(Interpolator.java)
  6. interpolateExpressions(Interpolator.java)
  7. createValueExpression(Expressions.java)

A call stack is simply the list of steps the program went through, one calling the next, like a chain of people passing a message along. Reading it from top to bottom shows how the first expression's result is handed down until it is turned into a new expression and evaluated.

With this feature, we can run arbitrary EL if we control the value that comes back. It is very similar to ROP in binary exploitation. ROP, return-oriented programming, is a technique where an attacker does not inject new code but instead strings together small pieces of code that already exist in the program, called gadgets. Here we need a good gadget too: an existing piece of the application that will hand back a value we control.

He chose the gadget in widgets/suggest_add_new_directory_entry_iframe.xhtml. Why this one? Because request.getParameter there returns a string that we control from the query string. request.getParameter is the standard way a Java web page reads a value the visitor sent. The whole tag is only meant to assign a variable, but we can abuse what it means.

We put the second stage payload in the directoryNameForPopup parameter. Combined with the first bug, this runs arbitrary EL without any authentication. The proof of concept:

Line by line:

  • /login.jsp;/..;/..;/ is the same trick as step 1: the filter sees the allowed login.jsp, Tomcat climbs out of it.
  • nuxeo.war/widgets/suggest_add_new_directory_entry_iframe.xhtml is the gadget file we want to reach.
  • ?actionMethod= tells Seam to invoke EL from a file.
  • suggest_add_new_directory_entry_iframe.xhtml:directoryNameForPopup is the required pair: the file name, a colon, then the expression. The expression here is just the name of a parameter, so Seam will look up that parameter and return its value.
  • & separates one parameter from the next.
  • directoryNameForPopup=#{...} is the value we control. The #{...} is EL syntax; the ... stands for whatever expression we want. Because the gadget returns this string and it looks like EL, Seam evaluates it a second time.

That is not the end. Although we can run arbitrary EL, we still cannot get a shell. A shell is a command prompt on the remote machine, the thing that lets you type commands and see the output. The reason we cannot get one yet is the next section.

Step 4: bypassing the EL blacklist leads to RCE

Seam knows that EL is dangerous. Since Seam 2.2.2.Final there has been an EL blacklist that blocks dangerous invocations. A blacklist is the opposite of a whitelist: a list of forbidden things, with everything else allowed. Nuxeo uses the latest Seam, 2.3.1.Final, so the blacklist has to be bypassed. It lives in resources/org/jboss/seam/blacklist.properties.

After a little study, the blacklist turned out to be simple string matching: it looks for particular text and refuses anything containing it. A blacklist is always a bad idea, because there is usually another way to write the same thing. The first time he saw it, he remembered the bypass for Struts2 S2-020, another Java framework vulnerability. The idea is the same: use array-like operators to avoid the blacklist patterns. Just change:

to:

Line by line:

  • #{...} is the normal way to write an EL expression. The blacklist is looking for this shape.
  • #{[...]} wraps the expression in square brackets. In EL, square brackets are an array-like way of writing the same thing, so the meaning is unchanged, but the text no longer matches the pattern the blacklist searches for.

That is all it takes.

The last thing is to write the shellcode in JBoss EL. Shellcode here means the expression that will run our command. We use the Java reflection API to get the java.lang.Runtime object and list all its methods. An API is a set of functions one program offers to another; reflection is Java's ability to inspect and use its own classes at runtime, by name, rather than in advance. java.lang.Runtime is the Java class that represents the running program and can start other programs. Index 7 is the method getRuntime(), which returns a Runtime instance, and index 15 is exec(String), which runs our command. Index here means the position in the list of methods that reflection returned.

The full chain

  1. The path normalisation bug leads to an ACL bypass.
  2. Bypass the whitelist to reach the unauthorised Seam servlet.
  3. Use the Seam feature actionMethod to invoke gadgets in the file suggest_add_new_directory_entry_iframe.xhtml.
  4. Prepare the second stage payload in the HTTP parameter directoryNameForPopup.
  5. Use array-like operators to bypass the EL blacklist.
  6. Write the shellcode with the Java reflection API.
  7. Wait for the shell to come back.

Here is the whole exploit:

From the original on blog.orange.tw

Running the Perl script gave us the shell:

From the original on blog.orange.tw

Root cause

The first bug is a parser inconsistency. Nuxeo's method works out the requested page from HttpServletRequest.RequestURI and cuts at the semicolon to handle URL path parameters, while Tomcat's own handling of the same address differs. The filter therefore sees a path that matches the unAuthenticatedURLPrefix whitelist, and the servlet sees a different, unauthorised path. The Nuxeo approach may be safe in WildFly, JBoss or WebLogic, but not in Tomcat.

The rest of the chain relies on Seam features. actionMethod lets a query string invoke EL from a file under the context root, and the double evaluation means a returned string that looks like EL is run again, so a gadget that reflects a request parameter gives arbitrary EL. The EL blacklist added in Seam 2.2.2.Final is plain string matching, so wrapping the expression in array-like operators avoids the patterns.

Impact

On this target the chain led to remote code execution on the Amazon collaboration system. More broadly, the path parameter attack surface can leak information, bypass ACLs (as in the researcher's Uber OneLogin bypass case) and lead to RCE in several bug bounty programs. A bug bounty program is a scheme where a company pays researchers for reporting security holes. The ACL bypass alone only got past the authentication redirect, with most pages returning a 500 error.

The fix

There are three sides to the fix.

JBoss. The researcher reported the Seam features to [redacted] in September 2016. Their reply was that Seam was only included in EAP 5, not 6 or 7; EAP was near the end of maintenance support, ending in November 2016; the upstream version he tested was released over three years earlier; during maintenance support EAP 5 only receives patches for important or critical issues; and while RCE is possible, it requires the attacker to first upload a file, which reduces the impact to moderate. They said they would not fix these issues at this stage of the Seam project lifecycle. Because of the end of life there is no official patch for these features, so if you use Seam, mitigate with Nuxeo's fix.

Amazon. The security team isolated the server with a rapid investigation, discussed with the researcher how to mitigate, and listed every step they had taken in detail.

Nuxeo. After notification from Amazon, Nuxeo quickly released a patch in version 8.10. The patch overrides the method callAction() to fix the crazy feature. If you need the patch for your own Seam application, refer to the Nuxeo commit.

Timeline

  • 10 March 2018 01:13 GMT+8: report to the Amazon security team via [redacted]
  • 10 March 2018 01:38 GMT+8: acknowledgement that they are investigating
  • 10 March 2018 03:12 GMT+8: ask to join the conference call with the security team
  • 10 March 2018 05:30 GMT+8: conference call with Amazon, get status and the steps taken
  • 10 March 2018 16:05 GMT+8: ask whether public disclosure at the Black Hat talk is possible
  • 15 March 2018 04:58 GMT+8: Nuxeo releases version 8.10 patching the RCE vulnerability
  • 15 March 2018 23:00 GMT+8: conference call with Amazon, discuss public disclosure details
  • 05 April 2018 05:40 GMT+8: receive the award from Amazon

Variants to test

  • Semicolon truncation against other containers. Send a whitelisted prefix followed by ;/..;/ segments to a Java back end behind a reverse proxy. A positive result is that the filter's view of the path matches the whitelist while the servlet reaches a page that should require authentication.
  • Other Seam HTTP parameters. Test parameters in the same family as actionOutcome and actionMethod that control redirection or navigation. A positive result is EL evaluation triggered from the query string.
  • Gadget files under the context root. Look for files whose content includes #{...} around a request parameter, as in suggest_add_new_directory_entry_iframe.xhtml. A positive result is that a parameter you control is returned and then evaluated a second time.
  • EL blacklist bypass. Where a Seam blacklist blocks a pattern, wrap the expression in array-like operators as with S2-020. A positive result is that the blocked invocation executes.
  • Scanner coverage. Check whether your directory brute-force tool sends path parameter patterns; at the time of writing only DirSearch had adopted the pattern, on 1 May 2017.

Glossary

  • ACL (access control list): the rules that say who is allowed to see or do what.
  • API: a set of functions one program offers to another so they can talk to each other.
  • Authentication: proving who you are, usually with a password or a token.
  • Blacklist: a list of forbidden things; anything not on the list is allowed.
  • Bug bounty program: a scheme where a company pays researchers for reporting security holes.
  • Call stack: the list of steps a program went through, one calling the next.
  • Chaining: joining several smaller weaknesses so that each one makes the next possible.
  • Context root: the folder on the server that the website is served from.
  • CVE: a public catalogue number given to a known vulnerability.
  • Deserialisation: turning stored or transmitted data back into objects in memory; a common source of bugs.
  • EL (Expression Language): a small language that lets a page ask for a value and have the framework work it out.
  • End of life (EOL): the point at which a product stops receiving support and fixes.
  • Filter: a checkpoint that inspects a request before it reaches the actual page.
  • Framework: a ready-made set of building blocks developers use to build an application faster.
  • Gadget: an existing piece of code that an attacker reuses to do something it was not meant to do.
  • HTTP parameter: a named value attached to a request, the part after the ? in an address.
  • Java: a widely used programming language, especially for large server applications.
  • Method: a named block of code that does one job.
  • NullPointerException: a Java error that happens when a program tries to use something that is not there.
  • Open source: software whose source code is public and can be read by anyone.
  • OWASP Top 10: a well-known list of the most common security mistakes in web applications.
  • Parameter: see HTTP parameter.
  • Parser: the part of a program that reads text and decides what it means.
  • Path normalisation: turning a written file path into the single, standard form the system will actually use.
  • Payload: the part of an attack that actually does the damage.
  • Perl: an older programming language often used for quick scripts.
  • Proof of concept (PoC): a small demonstration that a vulnerability really works.
  • Query string: the part of a web address after the question mark, holding the parameters.
  • RCE (remote code execution): making someone else's computer run commands you choose, over the network.
  • Red teaming: being paid to attack your own organisation on purpose, to find holes before criminals do.
  • Reflection: Java's ability to inspect and use its own classes at runtime, by name.
  • Reverse proxy: a server that sits in front of your real application and forwards requests to it.
  • ROP (return-oriented programming): stringing together small pieces of existing code instead of injecting new code.
  • Seam Framework: a Java web application framework made by JBoss, a division of Red Hat.
  • Servlet: a Java program that handles web requests.
  • Servlet container: the program that runs Java web applications and hands them incoming requests, such as Tomcat.
  • Shell: a command prompt on a machine, where you type commands and see the output.
  • Shellcode: here, the expression that runs the attacker's command.
  • Tomcat: a widely used Java servlet container.
  • URL: a web address.
  • URL path parameter: a small piece of extra information stuck onto a web address after a semicolon.
  • Whitelist: a list of things that are allowed; everything not on the list is refused.
  • XSS: not used in this report.
  • 0day: a vulnerability that is not yet known to the vendor and has no fix.

More by Orange Tsai

View all

5 more disclosed reports, best first.

More from Amazon

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.