CPTS labs - 18 Cross-Site Scripting XSS
Cross-Site Scripting (XSS)
XSS Basics
Stored XSS
To get the flag, use the same payload we used above, but change its JavaScript code to show the cookie instead of showing the url.
Results: HTB{570r3d_f0r_3v3ry0n3_70_533}
Reflected XSS
To get the flag, use the same payload we used above, but change its JavaScript code to show the cookie instead of showing the url.
Results: HTB{r3fl3c73d_b4ck_2_m3}
DOM XSS
To get the flag, use the same payload we used above, but change its JavaScript code to show the cookie instead of showing the url.
Results:
XSS Discovery
Utilize some of the techniques mentioned in this section to identify the vulnerable input parameter found in the above server. What is the name of the vulnerable parameter?
Results: email
What type of XSS was found on the above server? "name only"
Results: Reflected
XSS Attacks
Phishing
Try to find a working XSS payload for the Image URL form found at '/phishing' in the above server, and then use what you learned in this section to prepare a malicious URL that injects a malicious login form. Then visit '/phishing/send.php' to send the URL to the victim, and they will log into the malicious login form. If you did everything correctly, you should receive the victim's login credentials, which you can use to login to '/phishing/login.php' and obtain the flag.
Creating a valid payload in http://10.129.148.221/phishing/index.php?url= This would be the payload:
This would be the link generated:
Starting a netcat listener:
Visiting http://10.129.148.221/phishing/send.php and entering the link generated.
In the netcat listener we obtain:
We use the creds for accessing to /phishing/login.php and grabbing the flag
Results: HTB{r3f13c73d_cr3d5_84ck_2_m3}
Session Hijacking
Try to repeat what you learned in this section to identify the vulnerable input field and find a working XSS payload, and then use the 'Session Hijacking' scripts to grab the Admin's cookie and use it in 'login.php' to get the flag.
Create a file index.php in the attacker machine:
Have a php server listening:
Enter $ip/hijacking and enter this payload in every field. Use the field name (username, name, surname...) as <custom.name>
when different payloads:
If successful, you will see a connection in your php server like this:
Then, profile
would be the vulnerable input (parameter imgurl
). The URL:
Beside the index.php, have a lala.js in your php server:
Run your php server:
Now, we can change the URL in the XSS payload we found earlier to use lala.js
. For instance:
You will log the following activity in your php server:
Results: HTB{4lw4y5_53cur3_y0ur_c00k135}
XSS Prevention
Skills Assessment
What is the value of the 'flag' cookie?
Enter payload in all form fields. The vulnerable one is website
with the payload
I have a php server running, with this index.php:
I know that it is the parameter webserver
because of this:
Now, I have also this file lala.js in my server:
And in my php server:
Results: HTB{cr055_5173_5cr1p71n6_n1nj4}
Last update: 2025-01-26 Created: January 26, 2025 19:15:53