semgrep-rules icon indicating copy to clipboard operation
semgrep-rules copied to clipboard

Upload dockerd socket mount detection rule and test file

Open r0075h3ll opened this issue 1 year ago • 6 comments

This PR adds a new rule, along with a test file, for dockerd unix socket file i.e. docker.sock mount detection.

Description

Docker works in client-server architecture. In a normal setup, docker command issued in the CLI interacts with the docker server(dockerd) using a Remote API or Unix Socket File(docker.sock) - the latter is often encountered. However, in a scenario where an attacker breaks into the container that has /var/run/docker.sock mounted, it can be leveraged to execute arbitrary commands on the host machine i.e. to talk back to the host machine thereby providing a way for escaping the container.

Example

Here's a dummy Dockerfile that mounts docker.sock file:

FROM docker:latest

WORKDIR /app

VOLUME /var/run/docker.sock:/var/run/docker.sock

CMD ["docker", "images"]

Upon running Semgrep with the provided rule, this is how the output looks like: image

Thanks.

r0075h3ll avatar Apr 19 '24 18:04 r0075h3ll

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 19 '24 18:04 CLAassistant

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Apr 19 '24 18:04 CLAassistant

thanks for the contribution! can you add a positive and negative test case annotation to the code? cf https://semgrep.dev/docs/writing-rules/testing-rules/

ievans avatar Apr 23 '24 16:04 ievans

@ievans

Done :)

r0075h3ll avatar Apr 24 '24 13:04 r0075h3ll

This looks good to me, thanks for the contribution!

0xDC0DE avatar Jul 08 '24 12:07 0xDC0DE

Hey @0xDC0DE, can we merge?

r0075h3ll avatar Jul 10 '24 04:07 r0075h3ll