Understand Reflected XSS
In this step, we will learn about Reflected XSS vulnerabilities and how to exploit them.
First, let's initialize the lab environment by running the following command in the terminal:
curl 'https://labfile.oss.aliyuncs.com/courses/3471/init_xss_1_1.sh' > ~/init_xss_1_1.sh;chmod +x ~/init_xss_1_1.sh;sudo ./init_xss_1_1.sh
This command will create two PHP files in the /var/www/html/xss/
directory:
xss_reflect.php
xss_storage.php
Access xss_reflect.php
in your web browser using the following URL:
http://127.0.0.1/xss/xss_reflect.php
This is a simple search functionality where the system will output the input string directly to the webpage.
Try entering hello World
in the input field, and you will see hello World
printed on the page.
Now, try entering a JavaScript code like <script>alert('xss')</script>
:
<script>
alert("xss");
</script>
You should see an alert box pop up on the page, executing the JavaScript code.
Note that the "alert" is not the goal of an XSS attack; it is just a test to determine if the JavaScript code can be executed. In an actual XSS exploit, you would replace the alert()
function with other malicious JavaScript code.
Check the page source code, and you'll see that your input has been inserted into the HTML source, allowing the code to execute.
However, this XSS attack is non-persistent (reflected). If you refresh the page or access the URL again, the XSS attack will not be triggered because the JavaScript code has been cleared.
This is the principle of a Reflected XSS attack. Let's move on to understand Stored XSS in the next step.