Skip to content

TibiAlex/XSS-POC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XSS POC

Abstract

Cross-Site Scripting (XSS) attacks are among the most prevalent and dangerous vulnerabilities in web applications, capable of compromising user data and site integrity. This paper explores the three primary types of XSS attacks: Reflective, Stored, and DOM-based. We analyze the encoding strategies attackers utilize to bypass browser security mechanisms and discuss effective mitigation techniques. Additionally, a detailed proof-of-concept implementation demonstrates the severity and practical implications of these vulnerabilities. The study concludes with the results of our experimentation and actionable insights to fortify web applications against XSS threats.

Introduction

XSS attacks exploit the trust that users place in a website by injecting malicious scripts that execute in the browser of an unsuspecting user. These scripts can steal sensitive information, hijack user sessions, or perform other malicious activities. The three main types of XSS attacks—Reflective, Stored, and DOM-based—leverage distinct mechanisms for script injection. Modern browsers employ various security measures, such as input sanitization and encoding, to mitigate these threats, but attackers continuously devise new methods to bypass these protections. This paper provides a comprehensive analysis of XSS attacks, highlighting their mechanisms, effects, and mitigation techniques.

Related Work

Numerous studies and frameworks have focused on XSS vulnerabilities and countermeasures. Notable works include OWASP’s XSS Prevention Cheat Sheet, which outlines best practices for developers, and academic studies that explore automated tools for XSS detection. Prior research has predominantly emphasized either theoretical analyses or specific case studies. Our work builds on this foundation by providing a holistic view of XSS, including practical proof-of-concept implementations and an examination of emerging encoding strategies used to evade security mechanisms.

Attack Description

  1. Reflective XSS Reflective XSS occurs when malicious scripts are embedded in a URL parameter and immediately executed when the victim accesses the crafted URL. For example:

    https://vulnerable-website.com/search?q=<script>alert('XSS')</script>
    

    The server reflects the malicious input back to the user’s browser without proper sanitization, leading to script execution.

  2. Stored XSS Stored XSS involves injecting malicious scripts into a website’s database. When a user accesses the affected page, the script executes. For instance, an attacker might insert the following payload into a comment field:

    <script>document.cookie="stolen="+document.cookie</script>

    Every user who views the comment section inadvertently executes the malicious code.

  3. DOM-based XSS DOM-based XSS arises when a web application manipulates the DOM using user-supplied data, resulting in script execution. An example is the improper handling of URL fragments:

    var input = location.hash.substring(1);
    document.body.innerHTML = input;

    Visiting a URL like https://example.com/#<script>alert('XSS')</script> leads to script execution.

Encoding Strategies to Bypass Browser Security

Attackers employ various encoding techniques to evade security mechanisms:

  1. HTML Encoding: Converting characters into their HTML entity equivalents (e.g., < to &lt;).

  2. URL Encoding: Encoding payloads using percent-encoded characters (e.g., <script> as %3Cscript%3E).

  3. Double Encoding: Applying multiple layers of encoding to obfuscate payloads (e.g., %253Cscript%253E).

  4. Base64 Encoding: Encoding scripts in Base64 and decoding them dynamically using JavaScript.

  5. Obfuscation via Comments: Injecting malicious code with obfuscated syntax, such as using comments to break detection patterns (e.g., <sc<!-- -->ript>).

Effects and Attack Mitigation

XSS attacks can result in identity theft, data breaches, and reputational damage for web applications. Effective mitigation strategies include:

  • Input Validation: Restricting allowed input formats using whitelists.
  • Output Encoding: Escaping special characters in user-supplied data before rendering.
  • Content Security Policy (CSP): Defining rules to restrict the execution of scripts from untrusted sources.
  • Secure JavaScript Practices: Avoiding direct DOM manipulation with user input.
  • Web Application Firewalls (WAFs): Detecting and blocking malicious payloads.

Proof-of-Concept Description and Implementation

A proof-of-concept attack was developed to demonstrate the impact of each XSS type:

  1. Reflective XSS: A crafted URL was used to execute a script that displayed an alert box.
  2. Stored XSS: A malicious payload was injected into a comment field, causing all viewers of the comment section to execute the script.
  3. DOM-based XSS: A URL fragment was manipulated to exploit a vulnerable client-side script, resulting in an alert box.

These attacks were executed in a controlled environment with intentionally vulnerable web applications to measure their feasibility and impact.

Results

Our proof-of-concept demonstrated the ease with which each type of XSS could compromise a vulnerable application. Encoding strategies significantly enhanced the ability of payloads to bypass basic security measures, underscoring the importance of robust defenses. CSPs and WAFs effectively mitigated Reflective and Stored XSS but required careful configuration to address DOM-based XSS.

About

A poc which presents the 3 types of cross-site scripting attacks (reflective, stored and DOM based) with examples

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors