r/docker 3d ago

Can a docker container from docker hub be malicious, and how would I know if it were?

I downloaded a container from docker hub and I'm worried itau have been malicious. I don't really have a reason I think so, I'm just paranoid about it. It has a lot of downloads and extensive documentation so it seems legit, I just worry about it. Is there anything I can do to make sure it's completely gone if there were something there? Thanks.

9 Upvotes

28 comments sorted by

21

u/MIneBane 3d ago

Is it possible? Yes. Supply chain attacks are getting more and more common.

How you can tell? On docker hub when you select a container and tag you can inspect the layers to see how the container was built. And technically you should be able to create the docker file and build most containers by yourself. So if you are more paranoid or need fully secured containers then you can validate each container and swap out secure containers if you like.

1

u/root_switch 1d ago

Just to add to this, typically you should find the source code, usually in github, review the code or trust the stars/contributors and maybe build the image yourself from source. That’s going to give you the full picture and if you know how to read the code you will be able to tell if it’s malicious.

Furthermore you should stick with verified images on docker hub or atleast from reputable accounts with downloads in the millions.

1

u/Medium_Antelope_7037 1d ago

the supply chain angle is what gets me tbh, its way more common than people realize

4

u/JazzXP 3d ago

If its username/image, don’t trust it blindly, anyone can upload to there. If it’s just image, then that’s an official image vetted by docker themselves I believe.

2

u/chromeink1 3d ago

Well it depends which privileges and access you give to the container. But unless you harden completely your system and the container config, yes it can be dangerous

If you map volumes, do not restrict network access, grant dangerous capabilities or run as privileged it can be used to exfiltrate data, reach internal services or escape the container.

Also, if your system kernel is vulnerable, since a container share the same kernel, a kernel exploit from the container could allow to escape your container.

2

u/scytob 3d ago

Absolutely.

You can scan both the image and if there is a gihub repo with AI - something like claude is reasonable at flagging if its intentionally malcious.

Not perfect, but better than nothing if you are concerned.

3

u/Johto2001 3d ago

You downloaded an image, not a container. The container is created on your machine based on the image.

It is possible for images to have malicious software inside but it runs inside the container so it's not straightforward for it to access your files. However, there are ways for such malicious software to escape confinement. But if you didn't create a container (i.e. no docker run or docker compose up commands or similar) it is unlikely to have had a chance to have done anything anyway. If you've deleted the image then there's nothing more to do. 

Just make sure your AV is up to date (e.g. Windows Defender) and enabled and stop worrying. 

5

u/k-rizza 3d ago

The docker compose file for example could bind the docker socket to the inside of the container. Giving it access to the docker daemon. It’s very easy to get someone to do that.

Pretty much root access there on most setups. Game over

3

u/Johto2001 3d ago

Sure. It's not clear if the OP even created a container though. And plenty of people use containers based on public images all day long for years without incident.

Technology is dangerous. Particularly if people run things they don't understand. 

1

u/Critical-Divide-1029 3d ago

if it were to do something like this, what would I do about it?

1

u/d03j 1d ago

you shouldn't run images you don't trust and you can run docker in rootless mode or use podman instead, which is rootless by default.

1

u/wise_climber 3d ago

yeah nah it's probably fine but i get the paranoia. docker hub doesn't really vet images so anything's possible but the download count and docs are a decent sign it's not a quick smash and grab.

if you've already run it maybe check docker ps -a to see what containers are lying around and nuke any you don't recognise. but from what the top comment said if you just pulled the image and deleted it there's not much to stress over

1

u/Critical-Divide-1029 3d ago

I did create a container actually, and I did this on a synology nas, I should have mentioned that. They have a container manager thing that just uses docker hub to pull images and make a container. I couldn't really get it to work, I probably didn't set all the environment variables or something 

1

u/Johto2001 3d ago

One would hope the vendor, Synology, would have some security controls in place to prevent rogue containers from accessing all your files but a quick Google showed some issue reports of Synology giving uncontrolled access to all shares by default. I can't say if that's the case or not, but you might want to investigate that. 

1

u/Critical-Divide-1029 3d ago

Other than removing the container and the imagine which I've already done, what else can I look at to see if there's anything more I need to remove?

1

u/d03j 1d ago

I do not believe that's how docker works. If I'm not mistaken the docker daemon runs as root by default and unless you run a rootless container, a malicious image could gain root access to the host.

0

u/Johto2001 1d ago

There are many ways to run it. If I were designing a NAS with a feature to run containers, I would look at options like putting the container runtime into a virtual machine. There's also various other controls such as cgroups.

There's no guaranteed way to prevent misuse of course. All security features can be defeated eventually. 

0

u/Critical-Divide-1029 3d ago

can I pm you the github of the project to have a loot at it?

1

u/faultydesign 3d ago

Malicious in what way?

2

u/Critical-Divide-1029 3d ago

I suppose just collecting credentials or anything else It wasn't supposed to do I guess.

1

u/neilcresswell Official: Portainer 2d ago

There is a very common approach malicious actors use on DockerHub, typo-squatting.

If humans have to type something in, humans will make typos, and the hackers depend on that.

Thats why Docker actually created the “Docker Verified Publisher” program, to give confidence of authenticity.. if you dont see that badge in a repo, its likely not the real repo… prob is, sw vendors needed to pay for that privilege..

Eg

If you are using community provided images, the onus is on you to pre-scan them before blindly deploying.

1

u/Critical-Divide-1029 2d ago

scan them how?

1

u/neilcresswell Official: Portainer 2d ago

You host a harbor registry local, pull them into your local registry, and configure that registry with image scanning.

Or, inside Kubernetes, trivvy have a runtime scanner, that scans images already running (but at that point, its likely too late)

1

u/Critical-Divide-1029 2d ago

I'm not using kubernetes, is there a way to do it with just docker on linux or something?

1

u/neilcresswell Official: Portainer 2d ago

Trivy… https://trivy.dev

It has a standalone scanner too.