How We Got Access To AWS Infrastructure Exploiting Foul Parser

How We Got Access To AWS Infrastructure Exploiting Foul Parser

Introduction

Server-Side JavaScript injection is the ability for a user to inject JavaScript code that will, in turn, be evaluated by the server, and therefore would allow an attacker to potentially execute JS code under the context of the server and interact with the filesystem.

Understanding the vulnerable feature

The target application allows users to send faxes. Users can also attach files of different formats with the fax. Once the fax is sent, the server processes the attached file and embeds its content into the fax, converting the fax into.TIFF format and send that to the recipient. The sent fax (with embedded file content) also appears in the Sent folder from where the sender can download the sent faxes as PDF. There were multiple supported file formats, but what caught our eye was that the HTML files were also supported. So If a user sends a fax with an attached HTML file with the below-mentioned code, it gets parsed and is embedded in the original fax.

How We Got Access To AWS Infrastructure Exploiting Foul Parser

Detecting the Vulnerability

HTML being processed is a feature for that application, not a vulnerability, but is there any way we can abuse this feature? Well, we started with basic checks. The very first test was to check if we are able to inject JavaScript. An HTML file with the below code was attached with the fax:

How We Got Access To AWS Infrastructure Exploiting Foul Parser

The TIFF file in the SENT folder had the “Ebryx” text in it. This proved that we can inject JS code. Next, we tried to find what protocol and path are being used by the server. A single line of JS code can show us that:

Server-Side JavaScript injection is the ability for a user to inject JavaScript code that will, in turn, be evaluated by the server, and therefore would allow an attacker to potentially execute JS code under the context of the server and interact with the filesystem.

When we looked at the generated .TIFF file, we could see file:// protocol being used by the server and internal path.

Exploitation

For exploitation, the team decided to read the AWS Cloud metadata. But during this process, we faced multiple issues that we needed to overcome to fully exploit this vulnerability.

Multiple IAM Roles

The first problem we faced was that each time we accessed the http://169.254.169.254/latest/meta-data/iam/security-credentials endpoint, there was a different role name in response.

We sent multiple requests to the /security-credentials endpoint and analyzed the role names in response. We found that there are actually three roles, each appearing in random order. So a very simple solution was to use three iframe tags in the same HTML file.

Server-Side JavaScript injection is the ability for a user to inject JavaScript code that will, in turn, be evaluated by the server, and therefore would allow an attacker to potentially execute JS code under the context of the server and interact with the filesystem.

Filtered out response text

After the multiple roles hurdle was passed, we had another problem. We used the iframe tag to get the secret keys, but the generated TIFF file had very few characters visible, and the majority of response text was filtered out.

Instead of getting a response in the generated TIFF file, we decided to exfiltrate the response. The solution seems very simple. At this stage, we knew that we can execute JS code at the server-side, so we can make XHR requests to get the AWS credentials, and send them to our server. We sent another fax with an attached
HTML file containing the following code:

Server-Side JavaScript injection is the ability for a user to inject JavaScript code that will, in turn, be evaluated by the server, and therefore would allow an attacker to potentially execute JS code under the context of the server and interact with the filesystem.

The above code should have sent the response text to our server, but we did not receive anything. Upon performing further tests, we found that the JS code inside onload function was not being executed. We checked the User-Agent header that we recieved and realized that the target server was using Internet Explorer 7. A quick search on caniuse showed that the onload function is not supported by IE-7. A simple solution here was to use synchronous requests instead of asynchronous.

Server-Side JavaScript injection is the ability for a user to inject JavaScript code that will, in turn, be evaluated by the server, and therefore would allow an attacker to potentially execute JS code under the context of the server and interact with the filesystem.

The above code worked and we got the keys in our server logs

Mitigation

To defend against such attacks, multiple fixes can be applied like whitelisting harmless elements, disabling the JS support on the target server, etc. Here is the summary of possible fixes: – A list of harmless HTML elements shall be maintained, and only those elements shall be parsed from the attached HTML file. – If possible, disable JS execution at the target server. Only HTML tags shall be allowed and JS code shall be filtered out. – Use Instance Metadata Service Version 2 (IMDSv2) instead of IMDSv1. More details here.

References

Share the article with your friends

Related Posts

Organized ATM Jackpotting
Blog
Ebryx forensic analysts identified an organized criminal group in the South-Asian region. The group utilized an ATM malware to dispense cash directly from the ATM tray.
May 22, 2023
3 Min Read
Cyberattacks on the Rise: 2022 Mid-Year Rport
Blog
Cyber attacks are on the rise in 2022. Despite increased cybersecurity awareness, businesses have not been able to defend themselves from the rapidly changing threat landscape. Compared with the same
May 22, 2023
3 Min Read
How To Land Your First Cybersecurity Job: 5 Tips
Blog
Cybersecurity jobs are growing at a staggering rate and have shown no signs of stopping. According to the New York Times, an estimated 3.5 million cybersecurity positions remain unfilled globally.
May 22, 2023
3 Min Read
Have questions?
Let's talk.
Ebryx experts are ready to answer
your questions.
Contact us