-
I've been using code-server for a couple of years now on my private server where I host some stuff for myself and friends/family. Yesterday, I noticed that I got hacked for the first time ever (I've been self-hosting stuff for ~12 years now), and the point of entry was code-server. Luckily, code-server was constrained to a docker container without root access, so the damage was somewhat contained, but I still have no answer to how the attacker actually gained access. So I'd like to share my insights and maybe we can figure out together what happened. the setup
I'm not using the built-in password authentication mechanism of code-server, since authelia already handles authentication. the incidentunexpected access to code-server on 2024-07-31 from an IP address in India.
full `remoteagent.log` from that day
the attacker then runs these commands on the vscode terminal inside the docker container
this installs a crypto miner that causes 100% load on all cpu cores and some kind of VPN that allows scammers to use your IP address to scam other people. point of entry
so, it seems like the attacker was able to completely avoid my authentication mechanism. They didn't even go through the webserver and still got access to code-server. How? 🤔 |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 12 replies
-
The only way I can come up with off the top of my head that would make this possible is if code-server was listening on some interface that is directly exposed to the internet, making it possible to bypass both Authelia and NGINX. Is Docker bound to 0.0.0.0 maybe? |
Beta Was this translation helpful? Give feedback.
-
I've decided to set up a honeypot: code-server will run on the same machine, with the same config except
the only way to access code-server now is from the inside, e.g. if an extension phones home and leaves a TCP connection open. let's see if someone will take the bait. |
Beta Was this translation helpful? Give feedback.
-
https://docs.docker.com/network/packet-filtering-firewalls/#docker-and-ufw I didn't know this. I've been using docker for so many years now, and all this time, my ufw rules were useless. This was the point of entry, code-server was exposed on port 8443 all along, I just never checked because I was so certain that I can rely on my ufw rules. For now, I've changed the port mapping to |
Beta Was this translation helpful? Give feedback.
-
Interesting article; similar topic: https://www.math.cmu.edu/~gautam/sj/blog/20191102-docker-sshguard.html |
Beta Was this translation helpful? Give feedback.
-
@klamann Can you share your configuration to bind authelia and code-server? I couldn't find the correct way to integrate authelia with code-server myself, and have tried a bunch of ways without a go. Thanks a lot! |
Beta Was this translation helpful? Give feedback.
-
Hello! I noticed that someone had also gained access to my server, through code-server, and had been mining. (I don't believe that they did something else than mining.) My setup was somewhat different:
However, port forwarding through subdomains was enabled without authentication. So in my head, even if someone managed to "create" a subdomain (in that period of time when my script was running):
However, I did not realise that:
I expected code-server to reject requests for subdomains that don't bind to any port, instead of loading the editor. However, it still makes sense to me that code-server should not accept requests to invalid subdomains. (This would improve security slightly, IMO) I hope by sharing this, others can avoid making similar mistakes :) |
Beta Was this translation helpful? Give feedback.
https://docs.docker.com/network/packet-filtering-firewalls/#docker-and-ufw
I didn't know this. I've been using docker for so many years now, and all this time, my ufw rules were useless. This was the point of entry, code-server was exposed on port 8443 all along, I just never checked because I was so certain that I can rely on my ufw rules.
For …