Skip to content
RCE Write-up Intermediate

Failed Coding Assessment to Remote Code Execution - Part 1

The coding platform's online judge executed submitted code without sandboxing, allowing the author to run system commands. By using a system call to send test case inputs to an external server, the author exfiltrated hidden test data, and the text claims this was later escalated to remote code execution.

Akash Chhabra Follow

Published on hackingguy.medium.com

Hi there, Today I am going to explain how I found a vulnerability in a very famous coding platform let’s say REDACTED.com, and how I escalated the same to Remote Code Execution.

Akash Chhabra, on hackingguy.medium.com

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

Context

A very famous coding platform, referred to throughout the write-up as REDACTED.com, runs an online assessment feature: candidates solve programming problems in a browser IDE and the platform compiles and runs their submissions against hidden test cases. The author was sitting such an assessment, coding in C++ inside the platform's own IDE, when the hidden test cases became the object of interest rather than the problems themselves.

The write-up is the first part of a series. It covers how the author discovered that arbitrary system commands could be executed from submitted code and how the hidden test inputs were exfiltrated. The escalation to a root shell and to AWS and Firebase tokens is promised for a later part and is not described here.

From the original on hackingguy.medium.com

Setup

No accounts, roles or version numbers are given beyond the fact that the author was a candidate taking an online assessment on the platform. The tools used were:

  • The platform's in-browser IDE, with C++ as the chosen language.
  • system() calls from the submitted C++ program.
  • A TCP server started with netcat on a random port.
  • ngrok, described in the post as a temporary global domain name utility for a local port, to expose that local port to the internet.

The report does not describe the execution environment beyond the fact that submitted code ran and could call system().

From the original on hackingguy.medium.com

Finding it

The author had solved two problems and was stuck on the third: two test cases would not pass. After roughly 30 minutes without progress, with 40 minutes still left, the author stopped thinking about the algorithm and started thinking in terms of the test cases themselves: what are these test cases, and can they be found?

From the original on hackingguy.medium.com

Because the code ran in the platform's IDE, the first experiment was to see whether a command would run at all. The author submitted a simple instruction:

C++
system("ls")

This asks the C library to hand the string to the operating system's command interpreter, which lists the contents of the current working directory and writes them to standard output. The output came back in the IDE, listing all the files, but it contained only the input source code and its executable. No input test case file was present.

From the original on hackingguy.medium.com

That ruled out simply reading the test data off disk from the working directory. The next thought was to see the input the program receives while a test runs, but the input and output were hidden for these test cases, so printing them was not an option either.

From the original on hackingguy.medium.com

Exploitation

Step 1: confirm outbound connectivity from the execution environment

The idea was to send the input variable data as a payload to a server controlled by the author, from inside the executing code. The author started a TCP server with netcat on a random port and exposed it through ngrok, then changed the system command from ls to a ping against the ngrok hostname:

The string passed to system() was executed, and a request from the REDACTED.com server reached the author's TCP server, showing outbound connectivity. A request from the REDACTED.com server arrived at the author's basic TCP server, confirming both command execution and egress.

From the original on hackingguy.medium.com

Step 2: pass the hidden input into the command

Each test case had 4 inputs, so the author needed the program's own input variables to appear inside the command string. The write-up credits a StackOverflow answer for showing how to pass variable data into a system command; the exact code is not reproduced in the post. The result was that, on execution, the two failing input test cases arrived at the author's local server in a POST request.

That is the whole of the exploitation shown in this part: command execution from submitted code, outbound connectivity, and the hidden test inputs delivered to an attacker-controlled endpoint.

Root cause

The platform ran submitted code in an environment where system() commands executed and outbound connections were possible. Because the language runtime exposes system(), any submission could invoke the shell. The test case files were not in the working directory, and input and output were hidden for these test cases.

Impact

For a candidate, the immediate impact is reading the hidden test inputs of an assessment, which undermines the integrity of the test. In this case, submitted code ran commands on the executing server and could reach the network from it. The author states that the issue was escalated further, to a root shell on the server and complete access to AWS and Firebase tokens, but the details are left to a later part of the series and are not shown here.

Fix

The write-up does not say what the platform changed. What the design requires is to run untrusted submissions in an isolated sandbox with no outbound network access, so that a submitted program cannot invoke arbitrary host commands or send data to an external endpoint.

Variants to test

  1. Submit a program that calls the shell (system(), Runtime.exec, subprocess, and equivalents) and see whether the output of a directory listing appears. A positive result is any host output returned in the IDE.
  2. Point a command at a listener you control, as with the ngrok hostname above. A positive result is an inbound connection from the platform's execution environment.
  3. Feed the program's own input variables into that command. A positive result is the hidden test data arriving at your endpoint.
  4. Try the same on other online judges and assessment platforms that compile and run code server-side, since the same trust boundary applies wherever submissions are executed without isolation.
From the original on hackingguy.medium.com

Stay curious.

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

What happened, in plain words

A coding platform, called REDACTED.com in the write-up, lets candidates solve programming problems in a browser-based editor. When you submit your answer, the platform runs your code on its own computers and checks the result against test cases that you are not allowed to see. The author was taking one of these online assessments, writing C++ in the platform's editor, and got stuck on the third problem: two test cases would not pass. Instead of continuing to fight the algorithm, the author started wondering what those hidden test cases actually are, and whether they could be found.

The author's submitted code was run as a real program, and it was able to run operating system commands. From there the author made the machine list its files, then made it send a network request to a server the author controlled, and finally made it send the hidden test inputs out over the internet. This first part of the series stops there. The author says a later part covers how this was pushed further, to a root shell on the server and to AWS and Firebase tokens, but none of that is shown here.

From the original on hackingguy.medium.com

The setup

The write-up does not give account details, roles or version numbers. All we know is that the author was a candidate sitting an online assessment on the platform. The pieces involved were:

  • The platform's in-browser editor, with C++ chosen as the language.
  • system() calls made from inside the submitted C++ program.
  • A TCP server started with netcat on a random port.
  • ngrok, described in the post as a temporary global domain name utility for a local port, used to expose that local port to the internet.

The report does not describe the execution environment beyond the fact that submitted code ran and could call system().

From the original on hackingguy.medium.com

How the problem was found

The author had solved two problems and was stuck on the third, where two test cases refused to pass. After about 30 minutes with no progress and 40 minutes still on the clock, the author stopped thinking about the algorithm and started thinking about the test cases themselves: what are they, and can they be found?

From the original on hackingguy.medium.com

Because the code ran inside the platform's editor, the first experiment was simply to check whether a command would run at all. The author submitted this instruction:

C++
system("ls")

Line by line:

  • system(...) is a C and C++ function that takes a piece of text and hands it to the operating system's command interpreter, the same program that runs commands when you type them into a terminal. Whatever the command prints is written to standard output, which is the normal stream of text a program produces.
  • "ls" is the text being handed over. ls is the standard command for listing the contents of the current folder, so the program asks the machine to show what files sit next to it.

The output came back inside the editor and listed all the files. But the listing contained only the input source code and its executable, meaning the compiled program. There was no file holding the input test cases.

From the original on hackingguy.medium.com

That ruled out the easy route of reading the test data straight off the disk. The next thought was to see the input the program receives while a test is running, but the input and output were hidden for these test cases, so printing them was not an option either.

From the original on hackingguy.medium.com

How it was exploited

Step 1: check whether the machine can reach the internet

The idea was to send the input data as a payload to a server the author controlled, from inside the running code. A payload here just means the data you want to deliver. The author started a TCP server with netcat on a random port and exposed it through ngrok, then changed the system command from ls to a ping against the ngrok hostname:

Line by line:

  • system(...) again hands the text to the operating system's command interpreter, so the machine runs it as a command rather than treating it as part of the calculation.
  • "ping https://<random>.ngrok.io" is the command text. ping is a standard utility that sends a small network message to a host and waits for a reply, which is a simple way to test whether a machine can reach somewhere else. The address is the ngrok hostname that pointed at the author's own listener.

The text passed to system() was executed, and a request from the REDACTED.com server reached the author's TCP server, showing outbound connectivity. A request from the REDACTED.com server arrived at the author's basic TCP server, which confirmed two things at once: commands really run, and the machine can talk to the outside world.

From the original on hackingguy.medium.com

Step 2: put the hidden input into the command

Each test case had 4 inputs, so the author needed the program's own input variables to appear inside the command text. The write-up credits a StackOverflow answer for showing how to pass variable data into a system command; the exact code is not reproduced in the post. The result was that, on execution, the two failing input test cases arrived at the author's local server in a POST request. A POST request is the way a browser or program sends data to a server, as opposed to simply asking for a page.

That is all the exploitation shown in this part: commands run from submitted code, the machine can reach the internet, and the hidden test inputs are delivered to an endpoint the attacker controls.

Why it worked

The platform ran submitted code in an environment where system() commands executed and outbound connections were possible. A sandbox is an isolated box that a program runs inside so that it cannot touch anything outside. Because the language runtime exposes system(), any submission could invoke the shell. The test case files were not in the working folder, and input and output were hidden for these test cases.

What the impact was

For a candidate, the immediate impact is reading the hidden test inputs of an assessment, which undermines the integrity of the test. In this case, submitted code ran commands on the executing server and could reach the network from it. The author states that the issue was escalated further, to a root shell on the server and complete access to AWS and Firebase tokens, but the details are left to a later part of the series and are not shown here.

How it should be fixed

What the design requires is to run untrusted submissions in an isolated sandbox with no outbound network access, so that a submitted program cannot invoke arbitrary host commands or send data to an external endpoint.

Things to try on other platforms

  1. Submit a program that calls the shell (system(), Runtime.exec, subprocess, and equivalents) and see whether the output of a directory listing appears. A positive result is any host output returned in the editor.
  2. Point a command at a listener you control, as with the ngrok hostname above. A positive result is an inbound connection from the platform's execution environment.
  3. Feed the program's own input variables into that command. A positive result is the hidden test data arriving at your endpoint.
  4. Try the same on other online judges and assessment platforms that compile and run code server-side, since the same trust boundary applies wherever submissions are executed without isolation.
From the original on hackingguy.medium.com

Stay curious.

Glossary

  • API: a defined way for one program to ask another program to do something, like a service counter where you make a request and get a response.
  • AWS: Amazon Web Services, a cloud provider that rents out computers and storage over the internet.
  • C++: a programming language often used in coding tests and in software that needs to be fast.
  • Command interpreter (shell): the program that reads text commands and runs them on the operating system.
  • Compile: turn source code written by a person into an executable program the machine can run.
  • Cookie: a small piece of data a website stores in your browser so it can recognise you on later requests.
  • Egress: network traffic going out from a machine to somewhere else.
  • Endpoint: a specific address on a server that a request is sent to.
  • Executable: a file that the machine can run as a program.
  • Exfiltration: secretly sending data out of a system to somewhere the owner did not intend.
  • Firebase: a Google service for building apps, which can hold tokens and data for an app.
  • Host: the physical or virtual machine that a program actually runs on.
  • IDE: integrated development environment, an editor with tools for writing and running code, here inside a browser.
  • Input test cases: the hidden data a platform feeds to your program to check whether it produces the right answers.
  • netcat: a small networking utility for reading and writing network connections, often used to start a simple listener.
  • ngrok: a service that gives a temporary public address for a port on your own machine, so the internet can reach it.
  • OS command injection: a vulnerability where untrusted text ends up being run as an operating system command.
  • Outbound network access: the ability of a machine to make connections out to other machines.
  • Payload: the data you want to deliver to a target.
  • ping: a utility that sends a small network message to a host to test whether it can be reached.
  • POST request: a way for a program or browser to send data to a server.
  • Remote Code Execution (RCE): a vulnerability where an attacker can make a remote system run code of their choosing.
  • Root shell: a command prompt with the highest level of permission on a machine, able to do anything.
  • Sandbox: an isolated environment a program runs inside so it cannot affect anything outside.
  • Standard output: the normal stream of text a program prints.
  • system(): a C and C++ function that hands a piece of text to the operating system's command interpreter.
  • TCP server: a program that listens on a network port and accepts connections, here used to catch requests.
  • Test case: one set of input data and the expected output used to check a program.
  • Token: a piece of text that acts like a key, proving to a service that a program is allowed to use it.
  • Trust boundary: the line between code you trust and code you do not, which should be enforced by isolation.
  • Working directory: the folder a running program is currently sitting in.

More from HackerEarth

View all

The newest disclosed reports for this program.

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.