You are currently viewing Exploiting XSS to perform CSRF

Exploiting XSS to perform CSRF

Introduction to Exploiting XSS to perform CSRF

In Exploiting XSS to perform CSRF, Cross-Site Scripting (XSS) is a web security attack where an attacker exploits vulnerabilities in web applications to steal user passwords. This occurs when a web application fails to validate or sanitize user input, allowing malicious scripts to be injected into the page. The attacker creates a malicious URL or input that includes the injected script, allowing the script to execute and intercept user passwords. To mitigate XSS attacks, web developers must implement strong input validation and output encoding practices. Users should be cautious when clicking suspicious links, use strong, unique passwords, enable multifactor authentication, and keep software and browser plugins up-to-date to minimize the risk of password capture through XSS attacks

Lab Solutions | Practical Work Time Exploiting XSS to perform CSRF

This lab contains a stored XSS vulnerability in the blog comments function. To solve the lab, exploit the vulnerability to perform a CSRF attack and change the email address of someone who views the blog post comments.You can log in to your own account using the following credentials: wiener:peter

Stepwise Solution of the lab:-

First of all, here we will click on ‘My account’.

Here we’ve to type the (username : password) that is given in the lab description. Following credentials wiener:peter .

Click on ‘Log in’ and see what will happen.

Now copy that email and paste it here. ( turn on the Intercept of Burp Suite )

After clicking on ‘Update email’, we got a prompt from Burp Suite to forward this request. Well, Have a look on csrf token. You may ask why we do that. Right? Will explain you later after solving this lab.

We again came back to the home and you can see there are lots of posts. (Scroll down a little bit)

Without further ado, click on “View post”. (You can select any post)

So after clicking on the post, I scrolled down until I came to this form or comment section whatever you say.

Now, fill up all the name and other section, after that paste the below payload I will tell you what will happen or a brief explanation of it.

var req = new XMLHttpRequest();
req.onload = handleResponse;'get','/my-account',true);
function handleResponse() {
    var token = this.responseText.match(/name="csrf" value="(\w+)"/)[1];
    var changeReq = new XMLHttpRequest();'post', '/my-account/change-email', true);

Simply click on ‘Post comment’ and see what will happen.

BOOM! We solved the lab successfully. Time to tell you what happened and what will impact performing this attack.

Well, This will make anyone who views the comment issue a POST request to change their email address to

I hope you had loved reading this article after you had completed this article we highly recommend you to study the next article: Reflected XSS into HTML context with most tags and attributes blocked, please don’t forget to leave a comment over here and share it with your friends as well, Good Luck!

Thank you for reading, if this article really helps you then do share it with your mates.
And follow @masaudsec on Twitter.


What is web security?

Website security refers to protecting a website or web application from cyberattacks, unauthorized access, or other security threats.

What is web application security?

Web application security means protecting a website from cyberattacks. These attacks may include vulnerabilities such as SQL injection, XSS, file inclusion, and others.

Which of the following is a good security practice for web browsing?

It is always a good practice to use an up-to-date browser with timely updates. Keep your browser plugins up-to-date, avoid malicious websites and links, and always enable 2-factor authentication while avoiding clickjacking.

How to find someone’s social security number on the dark web

Searching for someone’s social security number or credit card information on the dark web is illegal and unethical. It is important to always avoid such activities and protect yourself and others from cyber threats.

Leave a Reply