Skip to content
RCE Write-up Advanced

Bypass firewall to get RCE

The application ran a vulnerable Apache Struts2 version that allowed remote command execution through a redirect parameter, but a web application firewall blocked the initial exploit. By prepending a legitimate redirect URL to the malicious expression, the attacker bypassed the firewall, executed commands, obtained a reverse SSH shell, and then escalated to root using a kernel exploit.

Avinash Jain Follow

Published on medium.com

#### Avinash Jain (@logicbomb1)

Avinash Jain (@logicbomb_1), 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. 7 min read.

Context

This write-up covers a chain built on Apache Struts 2, specifically CVE-2013-2251, at the time the vulnerability was widely exploited because it led to remote command execution. The researcher describes it as a vulnerability introduced by manipulating parameters prefixed with action:/redirect:/redirectAction:, allowing remote command execution in a Java web application using Struts earlier than 2.3.15 as its framework.

The target was a travel booking website. The researcher does not name the site or describe the booking feature itself; the only thing established about the application is that it ran a vulnerable Struts version and sat behind an application firewall.

When the flaw went viral, major application firewall vendors updated their rule engines and detection techniques to block it. The researcher's point is that this particular deployment was still bypassable, and that the command execution was only the first stage: from a server shell the chain continued to a root account through a kernel exploit.

Setup

No accounts, roles or credentials are described. The work was done from an attacker-controlled server, which the researcher needed in order to place an SSH public key and to receive a reverse tunnel. The steps involve firing Struts requests, SSH for the tunnel, and a public exploit for the kernel, taken from GitHub.

Preconditions for the chain as described:

  1. A Struts 2 application older than 2.3.15, reachable through the firewall.
  2. The firewall blocking the plain OGNL payload but not the redirection form.
  3. SSH reachable in a way that permits the reverse tunnel and public key authentication.
  4. A kernel version with a known local privilege escalation exploit.

Finding it

To find whether an application runs a vulnerable Struts version, check for the parameters action, redirect and redirectAction. To build the OGNL expression for the payload, the researcher used the OpenSecurityResearch article on attacking Struts with CVE-2013-2251.

The first payload runs ifconfig:

Text
redirect:${#a=(new java.lang.ProcessBuilder(new java.lang.String[]{' ifconfig'})).start(),#b=#a.getInputStream(),#c=new java.io.InputStreamReader(#b),#d=new java.io.BufferedReader(#c),#e=new char[50000],#d.read(#e),#matt=#context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse'),#matt.getWriter().println(#e),#matt.getWriter().flush(),#matt.getWriter().close()}

The expression starts a ProcessBuilder for ifconfig, wraps its input stream in a reader and a buffered reader, reads into a 50000-character buffer, and writes the buffer to the HttpServletResponse obtained from the Struts context, flushing and closing it. The redirect: prefix is what routes the value into the vulnerable parameter handling.

The screenshot shows the OGNL expression used to run the command.

This request was blocked by the application firewall, which redirected the researcher to a bots page.

Image for post
Blocked by Application Firewall- Redirected to Bots page From the original on medium.com

The bots page returned in place of the command output.

At this point the researcher went back to basics: the redirect parameter was known to be vulnerable, so a plain redirection was tried:

Text
redirect:http://www.goal.com

The response was a 302 redirect to http://www.goal.com. That contrast is the finding: the ifconfig payload was blocked, but the redirection through the same parameter was not. The ifconfig payload was blocked, but the redirection through the same parameter was not.

Exploitation

Step 1: bypass the firewall by combining redirection with the OGNL payload

The researcher combined the two working pieces, putting the external URL first and the OGNL expression after it in the same redirect: value:

Text
redirect:http://www.goal.com/${#a=(new java.lang.ProcessBuilder(new java.lang.String[]{' ifconfig'})).start(),#b=#a.getInputStream(),#c=new java.io.InputStreamReader(#b),#d=new java.io.BufferedReader(#c),#e=new char[50000],#d.read(#e),#matt=#context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse'),#matt.getWriter().println(#e),#matt.getWriter().flush(),#matt.getWriter().close()}

The request was fired and the firewall did not block it.

Image for post
Image for post From the original on medium.com

The response to the combined payload.

The ifconfig output came back through the response writer, confirming command execution.

Image for post
ifconfig command output From the original on medium.com

The screenshot shows the ifconfig command output.

Step 2: obtain a remote shell with reverse SSH tunnelling and public key authentication

The next objective was a remote shell on the server. The researcher used reverse SSH tunnelling together with public key authentication, which lets SSH users log in without entering passwords. To do that, the attacker server's SSH public key had to be placed in the victim server's ~/.ssh/authorized_keys, and because the tunnel was reverse, the victim's own id_rsa.pub also had to be added.

The researcher summarises the two concepts as follows: id_rsa.pub is a public key that you add to other hosts' authorized_keys files to allow you to log in as that user, and authorized_keys is a list of public keys that are allowed to log into that specific account on that specific server.

The steps were:

  1. Read the id_rsa.pub file of the victim server using the RCE.
  2. Copy the authorized_keys from the victim server to the attacker server.
  3. Copy the modified authorized_keys back from the attacker server to the victim, including the key obtained by reading id_rsa.pub.

The id_rsa.pub file read from the victim.

Image for post
Copy the authorized_keys from victim server to attacker server From the original on medium.com

Copying authorized_keys from the victim server to the attacker server.

Image for post
Copy back the modified authorized_keys from attacker server to victim From the original on medium.com

Copying the modified authorized_keys back to the victim.

Step 3: connect over the reverse tunnel

The final step was to SSH using the reverse tunnel from the attacker machine.

Image for post
SSH using reverse tunnel From the original on medium.com

The SSH connection over the reverse tunnel.

This reached a remote shell on the server, but not as root, so rights and access to files and commands were limited.

Step 4: escalate to root with a kernel exploit

To escalate, the researcher first checked the kernel version running on the victim machine.

The kernel version on the victim.

The version was 2.6.32. Searching for open CVEs against it showed it was vulnerable to privilege escalation, with an exploit available on GitHub at https://github.com/realtalk/cve-2013-2094. The researcher ran the exploit.

Running the privilege escalation exploit.

That produced privilege escalation to the root user, completing the chain from the Struts vulnerability to a root shell.

Root cause

The initial weakness is the Struts 2 parameter handling described at the top: parameters prefixed with action:/redirect:/redirectAction: can be manipulated to execute remote commands in applications using Struts earlier than 2.3.15. The application passed user-controlled values into that handling, so the OGNL expression was evaluated server-side.

The firewall failure is the interesting part. It blocked the payload when the value began with the OGNL expression, but allowed the same expression when it followed a legitimate-looking redirect:http://www.goal.com/ prefix. The report does not explain why the firewall allowed the expression when it followed a redirection target.

The later stages are not application flaws in the same sense: the shell was reachable because SSH public key authentication was available and the account's authorized_keys could be written through the RCE, and root was reachable because the host ran kernel 2.6.32, which the researcher found to be vulnerable to privilege escalation.

Impact

Under the conditions described, an attacker could execute commands on the server despite the application firewall, then obtain an interactive shell as the web user, and from there escalate to root. The chain depends on all of the preconditions above holding: a vulnerable Struts version, a firewall that can be bypassed this way, SSH access suitable for the tunnel, and the vulnerable kernel.

Fix

The measures implied by the chain are: upgrade Struts past the affected versions so the action:/redirect:/redirectAction: parameters are no longer exploitable, and patch or upgrade the kernel so CVE-2013-2094 no longer applies. On the firewall side, detection should not be satisfied by a benign-looking prefix in front of an expression; the rule needs to inspect the whole parameter value for evaluated content.

Variants to test

  1. Try the plain OGNL payload first on any Struts candidate, checking action, redirect and redirectAction. A positive result is command output reflected in the response.
  2. If it is blocked, send a bare redirect:http://www.goal.com and look for a 302 to that location. A positive result shows the parameter is processed and the firewall is not blocking redirection itself.
  3. Combine the two, as here, with the URL first and the expression after it. A positive result is command output in the response instead of a block page.
  4. Vary the benign prefix (different external hosts, paths, schemes) to see whether the firewall rule is tied to a specific string. A positive result is any prefix that still lets the expression through.
  5. On a host where a shell is obtained, check the kernel version and look for known local privilege escalation exploits matching it. A positive result is a working exploit that yields root.
  6. Where SSH is exposed, test whether public key authentication and tunnelling are permitted and whether authorized_keys is writable by the web user. A positive result is a successful login over the tunnel with the injected key.

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.

What happened, in plain words

A security researcher found a way to run commands on a travel booking website even though a firewall was supposed to stop that kind of attack. The website used an old version of a piece of software called Apache Struts 2, which had a known flaw (CVE-2013-2251) that let attackers run commands on the server. The firewall blocked the first attempt, but the researcher got around it by making the malicious request look like a harmless redirect to another website. Once commands could run, the researcher used them to set up a secret login (an SSH key) and connect to the server's command line. From there, the researcher noticed the server's operating system kernel was old (version 2.6.32) and used a public exploit to become the all-powerful root user. This post explains each step in simple terms.

Background: what is Apache Struts and CVE-2013-2251?

Apache Struts is a framework for building Java web applications. Many websites use it to handle forms and actions. A serious bug was found: manipulating parameters prefixed with action:, redirect:, or redirectAction: allowed remote command execution on the server. This is called remote code execution (RCE). The bug is catalogued as CVE-2013-2251. It affects Struts versions before 2.3.15.

When this bug became widely known, firewall vendors updated their products to block attacks that used it. A web application firewall (WAF) sits in front of a website and inspects incoming requests, blocking ones that look malicious. The researcher's point is that even with an updated firewall, this particular site could still be exploited.

The target and the first attempt

The researcher was testing a travel booking website. The site's name is not given. The only things we know are that it ran a vulnerable Struts version and had a firewall in front of it.

To find out if a site is vulnerable, the researcher checked for the three parameter names: action, redirect, and redirectAction. These are the parameters that the bug abuses. To build the actual attack code (called an OGNL expression), the researcher used a public article by OpenSecurityResearch.

The first payload tries to run the command ifconfig, which shows the network configuration of the server. Here is the payload exactly as used:

Text
redirect:${#a=(new java.lang.ProcessBuilder(new java.lang.String[]{' ifconfig'})).start(),#b=#a.getInputStream(),#c=new java.io.InputStreamReader(#b),#d=new java.io.BufferedReader(#c),#e=new char[50000],#d.read(#e),#matt=#context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse'),#matt.getWriter().println(#e),#matt.getWriter().flush(),#matt.getWriter().close()}

Let's break this down piece by piece:

  • redirect: tells Struts that this parameter is a redirect. That is the part that triggers the vulnerable code path.
  • ${ ... } is an OGNL expression. OGNL is a language that lets you access Java objects. Struts evaluates it, which is the heart of the bug.
  • #a=(new java.lang.ProcessBuilder(new java.lang.String[]{' ifconfig'})).start() creates a new process (like opening a terminal) that runs the command ifconfig. The result is stored in a variable #a.
  • #b=#a.getInputStream() gets the output of that command as a stream.
  • #c=new java.io.InputStreamReader(#b) wraps the stream in a reader that turns bytes into characters.
  • #d=new java.io.BufferedReader(#c) adds buffering so reading is efficient.
  • #e=new char[50000] creates a character array big enough to hold the output.
  • #d.read(#e) reads the command output into that array.
  • #matt=#context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse') gets the HTTP response object from Struts, so the output can be sent back to the attacker.
  • #matt.getWriter().println(#e) writes the output to the response.
  • #matt.getWriter().flush() and #matt.getWriter().close() flush and close the writer, making sure the output is sent.

The screenshot shows the OGNL expression used to run the command.

This request was blocked by the firewall, which redirected the researcher to a bots page (a page that says you are a bot).

Image for post
Blocked by Application Firewall- Redirected to Bots page From the original on medium.com

The bots page returned in place of the command output.

Going back to basics: testing a simple redirect

When something like this happens, the researcher goes back to basics. The redirect parameter was known to be vulnerable, so the researcher tried a harmless redirect to an external site:

Text
redirect:http://www.goal.com

The server responded with a 302 redirect to http://www.goal.com. A 302 is a standard HTTP status code that means "temporary redirect": the server tells the browser to go to another URL. This showed that the redirect parameter was still being processed and that the firewall did not block a simple redirect. The firewall was likely looking for the command-execution pattern, not for the word redirect itself.

Bypassing the firewall by combining redirect and command

The researcher then combined the two: put the external URL first, then the OGNL expression after it, all in the same redirect: value:

Text
redirect:http://www.goal.com/${#a=(new java.lang.ProcessBuilder(new java.lang.String[]{' ifconfig'})).start(),#b=#a.getInputStream(),#c=new java.io.InputStreamReader(#b),#d=new java.io.BufferedReader(#c),#e=new char[50000],#d.read(#e),#matt=#context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse'),#matt.getWriter().println(#e),#matt.getWriter().flush(),#matt.getWriter().close()}

This is the same OGNL expression as before, but now it is preceded by http://www.goal.com/. The idea is that the firewall sees a legitimate-looking redirect and lets it through, while Struts still evaluates the expression after the URL.

The request was sent, and the firewall did not block it.

Image for post
Image for post From the original on medium.com

The response to the combined payload.

The output of ifconfig came back in the response, proving that the command had run.

Image for post
ifconfig command output From the original on medium.com

The screenshot shows the ifconfig command output.

Getting a remote shell with SSH keys

Now the researcher wanted an interactive shell on the server, not just single commands. The method chosen was reverse SSH tunnelling with public key authentication. Let's explain these terms:

  • SSH (Secure Shell) is a protocol for logging into another computer securely. It is commonly used by administrators.
  • Public key authentication is a way to log in without a password. You have a pair of keys: a private key (kept secret) and a public key (shared). If the server has your public key in a special file, it will let you in.
  • authorized_keys is that special file, located at ~/.ssh/authorized_keys in the user's home directory. It lists the public keys that are allowed to log in as that user.
  • id_rsa.pub is the public key file. The corresponding private key is id_rsa.
  • A reverse SSH tunnel is a way to connect from the server back to the attacker's machine, often used to bypass network restrictions.

To set this up, the attacker's public key must be added to the victim's authorized_keys. Also, because the tunnel is reverse, the victim's own public key (id_rsa.pub) had to be added as well.

The researcher summarises: id_rsa.pub is a public key that you add to other hosts' authorized_keys files to allow you to log in as that user. authorized_keys is a list of public keys that are allowed to log into that specific account on that specific server.

The steps were:

  1. Read the victim's id_rsa.pub using the RCE.
  2. Copy the victim's authorized_keys file to the attacker's server.
  3. Copy the modified authorized_keys back from the attacker server to the victim, including the key obtained by reading id_rsa.pub.

The id_rsa.pub file read from the victim.

Image for post
Copy the authorized_keys from victim server to attacker server From the original on medium.com

Copying authorized_keys from the victim server to the attacker server.

Image for post
Copy back the modified authorized_keys from attacker server to victim From the original on medium.com

Copying the modified authorized_keys back to the victim.

Connecting over the reverse tunnel

The final step was to SSH from the attacker machine using the reverse tunnel.

Image for post
SSH using reverse tunnel From the original on medium.com

The SSH connection over the reverse tunnel.

This gave a remote shell on the server, but not as root. The user had limited rights.

Escalating to root with a kernel exploit

To become root, the researcher first checked the kernel version.

The kernel version on the victim.

The version was 2.6.32. Searching for known vulnerabilities in that version showed it was vulnerable to privilege escalation, with an exploit on GitHub. An exploit was available on GitHub at https://github.com/realtalk/cve-2013-2094. The researcher ran it.

Running the privilege escalation exploit.

That gave root access, completing the chain.

Why it worked

The initial weakness is in Struts: it evaluates OGNL expressions in parameters that start with action:, redirect:, or redirectAction:. The application passed user input into that evaluation, so the expression ran on the server.

The firewall bypass worked because the firewall blocked the payload when it started with the OGNL expression, but allowed it when a legitimate-looking URL came first. The report does not explain why the firewall allowed the expression when a redirect target came first.

The later stages are not application bugs: the shell was possible because SSH public key authentication was enabled and the authorized_keys file was writable via the RCE. Root was possible because the kernel was old and vulnerable to CVE-2013-2094.

Impact

An attacker could run commands on the server despite the firewall, get an interactive shell as the web user, and then escalate to root. The researcher does not say what data or systems were reachable beyond the server, and no bounty or severity rating is given. The chain depends on all the preconditions: a vulnerable Struts version, a bypassable firewall, SSH access suitable for the tunnel, and the vulnerable kernel.

Fix

The measures implied are: upgrade Struts to a version after 2.3.15, patch or upgrade the kernel to fix CVE-2013-2094, and improve firewall rules to inspect the entire parameter value for expressions, not just the beginning.

Variants to test

  1. Try the plain OGNL payload on any Struts candidate, checking action, redirect, and redirectAction. A positive result is command output in the response.
  2. If blocked, send a bare redirect:http://www.goal.com and look for a 302. A positive result shows the parameter is processed and the firewall is not blocking redirection.
  3. Combine the two, with the URL first and the expression after. A positive result is command output instead of a block page.
  4. Vary the benign prefix (different hosts, paths, schemes) to see if the firewall rule is tied to a specific string. A positive result is any prefix that still lets the expression through.
  5. On a host where you get a shell, check the kernel version and look for known local privilege escalation exploits. A positive result is a working exploit that yields root.
  6. Where SSH is exposed, test whether public key authentication and tunnelling are allowed and whether authorized_keys is writable by the web user. A positive result is a successful login over the tunnel with the injected key.

Glossary

  • Apache Struts: A framework for building Java web applications.
  • CVE: Common Vulnerabilities and Exposures, a unique identifier for a known security flaw.
  • Remote Code Execution (RCE): A vulnerability that lets an attacker run commands on a remote server.
  • OGNL: Object-Graph Navigation Language, an expression language used by Struts to access Java objects.
  • Web Application Firewall (WAF): A security device that inspects HTTP requests and blocks malicious ones.
  • 302 redirect: An HTTP status code meaning the requested resource has temporarily moved to another URL.
  • SSH: Secure Shell, a protocol for secure remote login.
  • Public key authentication: A method of logging in using a key pair instead of a password.
  • authorized_keys: A file listing public keys that are allowed to log in as a user.
  • id_rsa.pub: The public key file in an SSH key pair.
  • Reverse SSH tunnel: A connection initiated from the server back to the attacker, often to bypass firewalls.
  • Kernel: The core of an operating system that manages hardware and system resources.
  • Privilege escalation: Gaining higher-level permissions, such as becoming root.
  • Root: The superuser account on Unix-like systems with full control.
  • CVE-2013-2251: The Struts 2 vulnerability that allows RCE via parameters prefixed with action:, redirect:, or redirectAction:.
  • CVE-2013-2094: A Linux kernel vulnerability that allows local privilege escalation.

More by Avinash Jain

View all

29 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.