Hackers can take full control of online compilers through a RCE exploit (2018)
Several online C/C++ compilers ran user-submitted code without a sandbox, so the standard C functions for running shell commands and reading environment variables let an attacker run arbitrary commands on the host. An attacker could then read files, open an interactive shell, crash the machine or run a cryptocurrency miner.
serhack.me
Published on serhack.me
Online compilers are a handy tool to save time and resources for coders, and are freely available for a variety of programming languages. They are useful for learning a new language and developing simple programs, such as the ubiquitous “Hello World” exercise.
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.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the compilers executed user code directly on the host without a sandbox and without removing or restricting dangerous library functions such as system() and execl().
Impact
An attacker could gain shell access to the compiler host, read protected files, crash it through resource exhaustion, or mine cryptocurrency on it; the author notes some compilers were sandboxed and blocked these attacks.
What the attacker needed
Access to the online compiler; no sandbox on the host
The fix
The compilers should run user code in a resource-limited, self-rebooting sandbox, or the libraries should be recompiled without the exploitable functions; the author says the two unsandboxed compilers he reported were fixed within a week.
How it was found
- Submit C code that calls system() to learn the username and operating system version.
- Use system() to run further commands and read files such as logs and website files.
- Replace the running process with a shell using execl() so commands can be sent through the browser without recompiling.
- Optionally loop fork() to exhaust memory, or inject a cryptocurrency miner.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
An online compiler is a website that takes the code you type and runs it on the company's own computer. If that computer is not locked away in a sandbox (an isolated box with limited access), your code can do anything a normal program can, including asking the operating system to run other commands. Here the site ran the code directly, so a visitor could read files or take over the machine.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.