Cross-site scripting (XSS) is a web vulnerability that allows attackers to inject malicious scripts into web pages, which then execute in the browsers of unsuspecting visitors. It is cataloged under CWE-79 in the Common Weakness Enumeration database.
Cross-Site Scripting (XSS)
Just remember that this is for educational and ethical hacking purposes only. Never use this knowledge for illegal, malicious or unethical activity.
I'm at the common weakness enumeration website, and this is the database of all the weaknesses that are being tracked. What I'm going to do is expand all on these weaknesses. I'm going to do a find, and we're going to look for XSS.
So we see here there's a whole section here. This is the improper neutralization of input during web page generation, or cross-site scripting. It's associated with cross-site scripting number CWE-79. And as we can see, there's lots of variations underneath this. So one of the variations is basic XSS, and then we have a couple other XSS, but these are all variations of this top layer one, cross-site scripting.
Let's go ahead and open up this cross-site scripting and see what this looks like. It gives us a little visual of what cross-site scripting is.
So here we have an adversary. An adversary is getting into a website and leaving a message. The message is some sort of script that they're adding to this website. And now when somebody goes and visits this website, this script is going to get played for them, and so therefore their computer gets infected, or their computer gets compromised, or something about this connection gets compromised. So the adversary creates some sort of code and then inserts that on the website, and then when users visit that website, they activate that code, or they run that code.
One of the easiest ways to do this is visit a website that has some sort of comments box in it. Now, the comments box has to have this weakness, but then what happens is that the adversary inserts their code directly into this message box. As you can see, it's very easy to carry out this cross-site scripting. It's as simple as copying and pasting code into a comment box.
So now an unsuspecting victim visits the website. What happens is that this web page gets sent over to the browser on this user's computer, and it'll interpret everything that's on this page. Well, what's on this page? One of the things is some malicious code. So now the malicious code gets run inside that browser.
Let's take a look at an example of this. Here I've got just a simple web form. It's just one input, name, and then I can hit submit. So I'm going to type in Andrew and hit submit here. What happens is this Andrew goes into this message here and it says hello Andrew.
But what happens when I submit some sort of code, some sort of data that needs to be run? In this case right here, we're doing a script alert and it says you've been hacked. This is just representative of maybe some sort of malicious code that we have. So I'm going to copy this script right here. I'm going to paste it into this input. And when I hit submit, it's actually going to reput this up and run it, in which case then I get this alert that gets popped up and it says you've been hacked. So I'll click on OK. That's just an example of this script that's running now on this site here that I have.
So why would an adversary want to do this? Well, for one, maybe they just want to attack the integrity of the website. Maybe they want to put up some of their own code, or maybe they're trying to hijack a user session, or inject malware, or do some sort of redirection.
Website integrity is maybe they're inserting this just to display things on the website and attack the integrity of that website, so therefore when a user goes and views this website, it just looks different, or something is off on the website.
Maybe the adversary is looking to do a session hijack. That is, the user visits this website, logs into this website, and then this code gets presented, and then this session goes to the adversary. Now the adversary can start manipulating and changing things as if they were this user.
Perhaps the adversary wants to infect the computer with some sort of malware. So if they put malicious code in here, then maybe it then gets installed on this user's machine.
Or an adversary could be setting up some sort of redirection. That is, the user visits the website, this malicious code then redirects them to a whole other website. So this could be maybe a competitor: a competitor wants to take business from their competition, and so they'll do a redirect, so now users are buying from this other website.
Here's the attack card on that. We've got cross-site scripting, or XSS, and this is when an attacker injects scripts into a web page to be viewed by other users. And so it's associated with CWE-79.
TechKnowSurge builds IT and cybersecurity professionals through hands-on, concept-first training built around real understanding — not memorization. Free interactive tools, structured programs, and 25+ years of real-world experience, all in one place.
Explore free tools and programs →