How To Xss Without Html Tags

Cross-Site Scripting (XSS) is a common web vulnerability that allows attackers to inject malicious scripts into
a website, potentially compromising the integrity and security of the site and its users. While most XSS attacks
involve the use of HTML tags to inject these scripts, it is possible to perform an XSS attack without using any
HTML tags at all. In this blog post, we’ll discuss how to carry out an XSS attack without the use of HTML tags,
and some tips on how to protect your website from these types of attacks.

Method 1: Using JavaScript String.fromCharCode()

One way to achieve an XSS attack without using HTML tags is by utilizing JavaScript’s String.fromCharCode() method. This method allows you to create a string from a sequence of Unicode values, effectively allowing you to bypass any filters that may be in place to restrict the use of HTML tags.

For example, let’s say you want to inject the following script into a vulnerable site:
<script>alert('XSS')</script>

Instead of using the HTML tags, you can use the String.fromCharCode() method to create the same script:

        String.fromCharCode(60, 115, 99, 114, 105, 112, 116, 62, 97, 108, 101, 114, 116, 40, 39, 88, 83, 83, 39, 41, 60, 47, 115, 99, 114, 105, 112, 116, 62)
    

This will generate the same script as before, but without using any HTML tags, making it harder for filters to detect and block the attack.

Method 2: Using JavaScript encodeURI()

Another method to perform XSS without using HTML tags is by using JavaScript’s encodeURI() function. This function is used to encode a URI by replacing special characters with their corresponding UTF-8 escape sequences. By doing this, you can effectively bypass any filters that rely on simple pattern matching to block malicious scripts.

For example, let’s say you want to inject the following script into a vulnerable site:
<script>alert('XSS')</script>

Instead of using the HTML tags, you can use the encodeURI() function to create a URI-encoded version of the script:

        %3Cscript%3Ealert('XSS')%3C%2Fscript%3E
    

This will generate the same script as before, but in a URI-encoded format, which may bypass filters designed to block HTML tags.

Protecting Your Website from XSS Attacks

To protect your website from XSS attacks, it is critical to implement proper input validation and filtering techniques, such as allowing only a whitelist of safe HTML tags and attributes, and making use of Content Security Policy (CSP) headers. Additionally, ensure that your website’s code is up-to-date and follows best practices for secure coding to minimize vulnerabilities.

In conclusion, while most XSS attacks involve the use of HTML tags, it is possible to execute an XSS attack without them. As a web developer or site owner, it’s essential to be aware of these alternative methods and take the necessary precautions to protect your site and its users from such attacks.