⏳
Ichyaboy
  • 👋Ichyaboy
  • Hackthebox Related
    • 🎰Machines
      • Linux based Machines
        • Talkative
        • Encoding
      • Windows based machines
        • Silo
    • 🕹️Challenges (coming soon)
  • Portswigger Related
    • 🔧Server-side topics
      • Business logic flaws
        • Excessive trust in client-side controls
        • 2FA Broken Logic
        • High-level logic vulnerability
        • Inconsistent handling of exceptional input
        • Inconsistent security controls
        • Weak isolation on dual-use endpoint
        • Low-level logic flaw
        • Infinite money logic flaw
      • Information Disclosure
        • Information disclosure in error messages
        • Information disclosure on debug page
        • Source code disclosure via backup files
        • Authentication bypass via information disclosure
        • Information disclosure in version control history
      • Access Control
        • Unprotected admin functionality
        • Unprotected admin functionality with unpredictable URL
        • User role controlled by request parameter
        • User role can be modified in user profile
        • User ID controlled by request parameter
        • User ID controlled by request parameter, with unpredictable user IDs
        • User ID controlled by request parameter with data leakage in redirect
        • User ID controlled by request parameter with password disclosure
        • Insecure direct object references
        • URL-based access control can be circumvented
        • Method-based access control can be circumvented
        • Multi-step process with no access control on one step
        • Referer-based access control
      • File Upload
        • Remote code execution via web shell upload
        • Web shell upload via Content-Type restriction bypass
        • Web shell upload via path traversal
        • Web shell upload via extension blacklist bypass
        • Web shell upload via obfuscated file extension
        • Remote code execution via polyglot web shell upload
        • Web shell upload via race condition
      • Race Conditions
        • Limit overrun race conditions
        • Bypassing rate limits via race conditions
        • Multi endpoint race conditions
        • Single endpoint race conditions
        • Time sensitive vulnerabilities
        • Partial construction race conditions
      • SSRF
        • Basic SSRF against the local server
        • Basic SSRF against another back end system
        • Blind SSRF with out of band detection
        • SSRF with blacklist based input filter
        • SSRF with filter bypass via open redirection vulnerability
        • Blind SSRF with Shellshock exploitation
        • SSRF with whitelist based input filter
      • XXE Injection
        • Exploiting XXE using external entities to retrieve files
        • Exploiting XXE to perform SSRF attacks
        • Blind XXE with out of band interaction
        • Blind XXE with out of band interaction via XML parameter entities
        • Exploiting blind XXE to exfiltrate data using a malicious external DTD
        • Exploiting blind XXE to retrieve data via error messages
        • Exploiting XInclude to retrieve files
        • Exploiting XXE via image file upload
        • Exploiting XXE to retrieve data by repurposing a local DTD
      • Nosql Injection
        • Detecting NoSQL injection
        • Exploiting NoSQL operator injection to bypass authentication
        • Exploiting NoSQL injection to extract data
        • Exploiting NoSQL operator injection to extract unknown fields
      • Api Testing
        • Exploiting an API endpoint using documentation
        • Exploiting server side parameter pollution in a query string
        • Finding and exploiting an unused API endpoint
        • Exploiting a mass assignment vulnerability
        • Exploiting server side parameter pollution in a REST URL
    • 🎯Client-side topics
      • Cross-site scripting (XSS)
        • Stored XSS
          • Stored XSS into HTML context with nothing encoded
          • Stored XSS into anchor href attribute with double quotes HTML encoded
          • Stored XSS into onclick event with angle brackets and double quotes HTML encoded and single quotes and backslash escaped
        • Reflected XSS
          • Reflected XSS into HTML context with nothing encoded
          • Reflected XSS into attribute with angle brackets HTML encoded
          • Reflected XSS into a JavaScript string with angle brackets HTML encoded
          • Reflected XSS into HTML context with most tags and attributes blocked
          • Reflected XSS into HTML context with all tags blocked except custom ones
          • Reflected XSS with some SVG markup allowed
          • Reflected XSS in canonical link tag
          • Reflected XSS into a JavaScript string with single quote and backslash escaped
          • Reflected XSS into a JavaScript string with angle brackets and double quotes HTML encoded and single quotes escaped
          • Reflected XSS into a template literal with angle brackets, single, double quotes, backslash and backticks Unicode escaped
          • Reflected XSS with event handlers and href attributes blocked
          • Reflected XSS in a JavaScript URL with some characters blocked
        • DOM-based XSS
          • DOM XSS in document.write sink using source location.search
          • DOM XSS in innerHTML sink using source location.search
          • DOM XSS in jQuery anchor href attribute sink using location.search source
          • DOM XSS in jQuery selector sink using a hashchange event
          • DOM XSS in document.write sink using source location.search inside a select element
          • DOM XSS in AngularJS expression with angle brackets and double quotes HTML encoded
          • Reflected DOM XSS
          • Stored DOM XSS
        • CSP Bypass
          • Reflected XSS protected by CSP, with CSP bypass
          • Reflected XSS protected by very strict CSP, with dangling markup attack
        • Client-side template injection
          • Reflected XSS with AngularJS sandbox escape without strings
          • Reflected XSS with AngularJS sandbox escape and CSP
        • Common XSS Attacks
          • Exploiting cross site scripting to steal cookies
          • Exploiting cross site scripting to capture passwords
          • Exploiting XSS to perform CSRF
      • WebSockets
        • Manipulating WebSocket messages to exploit vulnerabilities
        • Cross site WebSocket hijacking
        • Manipulating the WebSocket handshake to exploit vulnerabilities
      • Cross-site Request forgery (CSRF)
        • CSRF vulnerability with no defenses
        • CSRF where token validation depends on request method
        • CSRF where token validation depends on token being present
        • CSRF where token is not tied to user session
        • CSRF where token is tied to non session cookie
        • CSRF where token is duplicated in cookie
        • SameSite Lax bypass via method override
        • SameSite Strict bypass via client side redirect
        • SameSite Strict bypass via sibling domain
        • SameSite Lax bypass via cookie refresh
        • CSRF where Referer validation depends on header being present
        • CSRF with broken Referer validation
      • Cross-origin resource sharing
        • CORS vulnerability with basic origin reflection
        • CORS vulnerability with trusted null origin
        • CORS vulnerability with trusted insecure protocols
      • Clickjacking
        • Basic clickjacking with CSRF token protection
        • Clickjacking with form input data prefilled from a URL parameter
        • Clickjacking with a frame buster script
        • Exploiting clickjacking vulnerability to trigger DOM based XSS
        • Multistep clickjacking
      • DOM-based vulnerabilities
        • DOM XSS using web messages
        • DOM XSS using web messages and a JavaScript URL
        • DOM XSS using web messages and JSON.parse
        • DOM based open redirection
        • DOM based cookie manipulation
        • Exploiting DOM clobbering to enable XSS
        • Clobbering DOM attributes to bypass HTML filters
  • Resources
    • 🏳️Cheatsheets
      • Basic Tools
      • Footprinting
      • Web Inofrmation Gathering
      • Nmap
      • File Transfer
      • Passwords Attacks
      • USING THE METASPLOIT FRAMEWORK
      • Shells & Payloads
      • Attacking Common Services
      • Pivoting, Tunneling, and Port Forwarding
    • 🏴Useful Scripts
      • NoSQL REGEX Password Length
      • NoSQL REGEX Password
      • Creds BruteForce CSRF Handling
Powered by GitBook
On this page
  • Description
  • Approach
  1. Portswigger Related
  2. Client-side topics
  3. Cross-site scripting (XSS)
  4. Reflected XSS

Reflected XSS in a JavaScript URL with some characters blocked

PreviousReflected XSS with event handlers and href attributes blockedNextDOM-based XSS

Description

This lab reflects your input in a JavaScript URL, but all is not as it seems. This initially seems like a trivial challenge; however, the application is blocking some characters in an attempt to prevent XSS attacks.

To solve the lab, perform a attack that calls the alert function with the string 1337 contained somewhere in the alert message.

Approach

After accessing the lab, I enabled the FoxyProxy extension to proxy all requests through Burp Suite and then started navigating the site. One request caught my attention:

GET /post?postId=1

Its response contained an interesting canonical link tag inside a div responsible for returning to previous pages:

<div class="is-linkback">
	<a href="javascript:fetch('/analytics', {method:'post',body:'/post%3fpostId%3d1'}).finally(_ => window.location = '/')">Back to Blog</a>
</div>

Clicking this link runs the fetch function with the given arguments, and notably, the postId parameter is part of the fetch function's configuration object. If I can escape this argument declaration and add my own, I can successfully exploit this XSS vulnerability.

The question is, why am I considering adding multiple arguments to the fetch function, and will that break its functionality? In JavaScript, the number of additional arguments doesn’t matter as long as the required ones are present. For example, here it accepts two arguments:

  • /analytics: the URL the fetch function will access.

  • {method:'post',body:'/post%3fpostId%3d1'}: the configuration object of the fetch function.

Since these objects are well-declared, adding more arguments is acceptable as long as the syntax is correct.

To build the payload, I need to inject at the body level of the configuration argument. I will start by providing a & symbol to add a parameter in the query string of the URL, preventing the URL from breaking:

/post?postId=1&

Next, I need to escape the configuration object {method:'post',body:'/post?postId=1'} by adding a } to close it properly:

/post?postId=1&'}

At this stage, the payload looks like this in the canonical tag:

{method:'post',body:'/post?postId=1&'}'}

I successfully escaped the object and can now add arguments using the , character. For example:

{method:'post',body:'/post?postId=1&'},ARG1,ARG2,ARG3'}

However, the characters }' at the end will break the payload. I need to include them as part of an argument. Instead of '}', I use {x:''} by adding a , to count as an argument, then adding {x:''} to build the object at that argument:

{method:'post',body:'/post?postId=1&'},ARG1,ARG2,ARG3,{x:''}

Next, I'll build the rest of the payload to trigger the alert function. For the first argument, I will use an arrow function:

x = (x) => {
throw onerror=alert,1337
}

This function uses the throw statement with provided values. The onerror=alert sets an event handler that triggers an alert on error. The throw statement outputs an error message, triggering the alert with the message 1337.

To bypass blocked characters like (), ;, and spaces, I modify the payload:

x=x=>{throw/**/onerror=alert,1337}

I removed blocked characters and replaced spaces with comments to spoof the space character.

Next, I call this function in the payload as the next argument. I redefine the toString function to point to my function and trigger it with a simple instruction. When JavaScript parses it, my instruction will use the predefined toString function to run my function instead.

toString=x

Now, when toString is called, it runs as my function x. To trigger it:

window+''

Since window is not a string, JavaScript uses the toString function to convert it, thus running my function x.

The final payload, incorporating all parts as arguments to the fetch function, looks like this:

/post?postId=1&'},x=x=>{throw/**/onerror=alert,1337},toString=x,window+'',{x:'

When I copy and paste this payload into the URL in the browser, the lab is solved, though the alert popup doesn’t appear immediately because the canonical link tag is a back link. By scrolling down the page and clicking on Back to Blog, the alert is triggered, and an alert box pops up.

🎯
cross-site scripting