1/7
Looks like no tags are added yet.
Cross-Site Scripting
A common web application vulnerability where attackers inject malicious scripts into trusted websites.
The term "XSS" was used to avoid confusion with CSS (Cascading Style Sheets), which already used the abbreviation
Takes advantage of security flaws in browsers, allowing information from one site to be shared with another, potentially exposing sensitive data.
Exploits the trust a user has for a website by injecting malicious JavaScript code. Since JavaScript is widely supported in most browsers, these attacks can be highly effective.
How Cross-Site Scripting (XSS) Works
The victim is typically a user interacting with a trusted website
The attacker exploits the vulnerability by sending a specially crafted link containing malicious script code.
The victim clicks the link, which directs them to a legitimate, trusted website. However, hidden within this link is malicious JavaScript that runs silently when the user accesses the site
The script can steal sensitive information such as:
Cookies
Session details
Private data from the website
This information is then sent directly to the attacker, allowing them to hijack the user's session, impersonate the user, or access sensitive data.
Non-Persistent (Reflected) XSS Attack
The vulnerability arises when websites allow user inputs (such as in a search box) to be processed without proper validation or sanitization, allowing attackers to inject JavaScript code.
Attacker can craft a malicious link that includes harmful JavaScript embedded within the URL. When the victim clicks on the link, the script is reflected off the server and executed in the victim’s browser.
The attacker typically sends this link through email, social media, or another platform, tricking the victim into visiting the compromised link.
The key point of this attack is that the attacker is sending the malicious code, but the victim unknowingly executes it in their browser against a trusted third-party website. This makes it very difficult to detect, as the attack is carried out through seemingly legitimate interactions with the website.
Non-Persistent (Reflected) XSS Attack ELI5:
Imagine Alice and Bob are two people on the Internet. Bob owns a website where Alice can log in and store her personal information.
Bob’s website also has a search feature, and if you search for something that doesn’t exist, it shows "X not found," where X is whatever Alice typed in the search box.
Now, there’s a bad actor, Mallory, who notices this feature. Mallory knows that Bob’s website doesn’t check what’s entered into the search box carefully. So, Mallory creates a malicious script and wraps it in a special link that, when clicked, sends the script through the search feature.
When Alice clicks this link, Bob’s website sees Alice’s search term as usual, but this time, the script that Mallory crafted is included. Bob’s website doesn’t realize it’s malicious, so it runs the script, thinking it’s just normal behavior.
The script that Mallory injected steals Alice's authorization cookie, which is what tells Bob’s website that Alice is logged in. Now, Mallory can pretend to be Alice and access her information.
Vulnerable XSS Website Example
Imagine a shopping website with a credit card number field that doesn’t properly check for scripts.
The attacker injects a malicious script into the credit card number field.
When the user clicks the "Purchase" button, the website processes the form as usual. However, instead of just confirming the purchase, the injected script runs as well.
A message appears on the screen showing session information, including the session ID—a unique identifier for the user’s session.
While the victim sees the session ID pop up on their screen, the malicious script doesn’t show anything to the attacker. Instead, the session ID is secretly sent to the attacker in the background.
Persistent (Stored) XSS Attack:
The attacker posts a message on a social media site or another platform that includes a malicious script
The attacker creates a post or message that contains a malicious payload (script) and submits it to the site.
The malicious script gets stored in the website’s database.
Everyone who views the page will unknowingly execute the script, as the script is now a part of the page's content.
Since it's on a social networking site, the attacker may include additional code that makes it easy for other users to share the malicious post.
As more people share it, the malicious script continues to spread.
Hacking a Subaru
In June 2017, Aaron Guzman, a security researcher, discovered a critical Cross-Site Scripting (XSS) vulnerability on Subaru's website.
When users logged into their Subaru account, they received a token to authenticate their session. However, the token never expired, which is a major security flaw.
An attacker could send a link with malicious code to a victim. When the victim clicked the link, the script would run, and the attacker could steal the authentication token from the victim’s session.
Once the attacker obtained the token, they could use it to make requests and manage the victim's vehicle services. Since the token did not expire, the attacker could use it indefinitely.
The attacker could also add their email address to another Subaru account with the token, gaining full access to that account and potentially the victim's vehicle management features.
Protecting Against XSS
Never blindly click on links in emails, messages, or on websites you don't trust. Malicious links may contain embedded scripts designed to exploit XSS vulnerabilities.
Disabling JavaScript or controlling its execution with browser extensions can offer some protection against XSS. However, this may limit the functionality of some websites, as many rely on JavaScript for legitimate purposes.
Regularly update your browser and other applications to patch vulnerabilities.
If you're building a website or web application, ensure all user inputs are properly validated and sanitized