In the past two weeks I set up a new VPS, and I run a small experiment. I share the results for those who are curious.
Consider that this is a backup server only, meaning that there is no outgoing traffic unless a backup is actually to be recovered, or as we will see, because of sshd.
I initially left the standard “port 22 open to the world” for 4-5 days, I then moved sshd to a different port (still open to the whole world), and finally I closed everything and turned on tailscale. You find a visualization of the resulting egress traffic in the image. Different colors are different areas of the world. Ignore the orange spikes which were my own ssh connections to set up stuff.
Main points:
-
there were about 10 Mb of egress per day due just to sshd answering to scanners. Not to mention the cluttering of access logs.
-
moving to a non standard port is reasonably sufficient to avoid traffic and log cluttering even without IP restrictions
-
Tailscale causes a bit of traffic, negligible of course, but continuous.
Public key auth, and fail2ban on an extremely strict mode with scaling bantime works well enough for me to leave 22 open.
Fail2ban will ban people for even checking if the port is open.
Honest question, is there a good default config available somewhere or is what
apt install fail2ban
does good to go? All the tutorials I’ve found have left it to the reader to configure their own rules.Honestly the default config is good enough to prevent brute force attacks on ssh. Just installing it and forgetting about it is a definite option.
I think the default block time is 10 minutes after 5 failed login attempts in 10 minutes. Not enough to ever be in your way but enough to fustrate any automated attacks. And it’s got default config for a ton of services by default. Check your /etc/fail2ban/jail.conf for an overview.
I see that a recidive filter that bans repeat offenders for a week after 10 fail2ban bans in one day is also default now. So I’d say that the results are perfect unless you have some exotic or own service you need fail2ban for.
Yeah fail2ban has worked great for me
If Fail2Ban is so important, why the h*** does it not come installed and enabled as standard?!
Security is the number-1 priority for any OS, and yet stock SSHD apparently does not have Fail2Ban-level security built in. My conclusion is that Fail2Ban cannot therefore be that vital.
You really shouldn’t have something kike SSHD open to the world, that’s just an unnecessary atrack surface. Instead, run a VPN on the server (or even one for a network if you have several servers on one subnet), connect to that then ssh to your server. The advantage is that a well setup VPN simply won’t respond to an invalid connection, and to an attacker, looks just like the firewall dropping the packet. Wireguard is good for this, and easy to configure. OpenVPN is pretty solid too.
You say this and are downvoted.
While we are coming off the tail of Def Con where there where a plethora or small talks and live examples of taking advantage and abusing just this.
Just trying to parse your comment, I assume your first “this” and second “this” are referring to different things, right?
I usually just run a ZeroTier client on my Pi connected to a private P2P network to solve this issue, and then have ProtonVPN over Wireguard for all internet traffic in and out of the Pi.
Or, you know, just use key auth only and fail2ban. Putting sshd behind another port only buys you a little time.
Yeah but the majority of bots out there are going after easy prey. Honestly, if you use public key authentication with ssh you should be fine, even if it is on port 22. But it does of course clog up access logs.
The majority of bots out there are stopped by just using a hard to guess password. It’s not them that you should be worried about.
who should we be worried about?
I opened a raw text channel on the Telnet port for a personal game engine project and someone tried to enable commands and do some shady stuff. Unfortunately for them, that’s not a valid chess move.
Just do it properly and configure sshd securely. When you have a machine exposed to the internet, you should expect it to be attacked. If you really want to give the finger to bots, run endlessh on port 22 and keep sshd on a non-standard port. Stay safe.
endlessh
Lmao thanks for this
I’d favour own VPN instead of relying on an additional third party
Right? PiVPN is easy AF and uses WireGuard. No reason not to set up something yourself if you’re already selfhosting.
Mine is quick enough to run remote desktop over
Same, I use Moonlight/Sunshine to stream my main gaming PC. I can even use wake on lan, so the big chungus isn’t drawing power unless I’m using it.
Oh, something new to try, thanks
Do you have any tutorial that explains what you did? I’d love to try to better understand your setup
Well for PiVPN I just followed the docs to get it setup: https://docs.pivpn.io/
Then I port forwarded the port I use for Wireguard to that same port on my Pi with PiVPN on it.
For Sunshine: https://docs.lizardbyte.dev/projects/sunshine/en/latest/about/installation.html
So now when I want to remotely access my gaming PC, I use Wireguard on my phone, use the configured PiVPN setup on there which points to the domain name that I have setup with my DDNS, then I use a Wake On Lan app setup with my gaming PC’s MAC address to wake it, then I just log into it with Moonlight like normal
Do you use Linux if so, are you on Wayland ?
I use Linux Mint, so no Wayland, but Sunshine/Moonlight works on both X11 and Wayland, generally speaking.
Isn’t port forwarding dangerous?
10mb is pretty much nothing. May as well just use Fail2Ban.
I get what you say, and you’re definitely not wrong to do it. But as I see it, you only saved ~80Kib of ingress and a few lines of logs in the end. From my monitoring I get ~5000 failed auth per day, which account for less than 1Mbps average bandwidth for the day.
It’s not like it’s consuming my 1Gbps bandwidth or threatening me as I enforce ssh key login. I like to keep things simple, and ssh on port 22 over internet makes it easy to access my boxes from anywhere.
ssh -p 12345 would leave your boxes accessible from anywhere too. Other blocks of IPs receive 10 times or more requests, as scanners can focus on blocks of ips from major providers.
Yeah I know, I just don’t really care about that traffic to bother changing it :) Also, I’m talking about a server hosted on Hetzner, so I feel like it’s scanned a lot.
If you do want to open 22, and there are plenty of good reasons to want to, just implement something called port knocking and you can do it safely.
Note with this you still need good authentication. That means no passwords, key based auth only.
I have read elsewhere that port knocking is just security through obscurity and isn’t worth considering. I found it when searching for ways to set it up and that put me off.
It is and it isn’t. It prevents random scans from opening 22 and attempting to authenticate, that’s basically the entire purpose. You still need good authentication after because you’re right, it’s not a security measure, it’s just a way to keep your logs useful and to keep botnets from beating the hell out of 22.
By “good authentication” I mean a key pair based authentication. That is impossible to brute force. If you use a password on 22 you shouldn’t open it at all and you should rethink allowing any remote access.
Put another way: You’re the doorman at a speak easy. You can answer the little window with “what’s the password?” to every jack ass that approaches, and you’d be asking all the time. But if they don’t know they have to knock “shave and a haircut” first, your job gets a lot easier and you’re dealing with a lot fewer nuisance password promptings.
You can also use it to blacklist. If someone tries to hit 22 without knocking you can blacklist that IP entirely because you know it’s nuisance.
When you put it that way, it sounds beneficial and like something I’d like to use. Thank you!
The article may have been dissing it as a sole strategy.
It’s not uncommon for people to try using it as their sole authentication so that wouldn’t be a surprise. But for it’s purpose, it’s perfect.
But if they don’t know they have to knock “shave and a haircut” first, your job gets a lot easier and you’re dealing with a lot fewer nuisance password promptings.
Very good explanation. And the benefits are even greater: because there is absolutely no response until the entire secret knock is correctly used, the random guy trying to get in doesn’t even know if there’s anyone at that address. (In fact, set up correctly, they won’t even know if there’s really a door there or not)
Security through obscurity is a very valid way to secure something. It shouldn’t be the only way of securing something, but it can be a valid additional layer.
The knock sequence is a secret, just like a password. It may not be a particularly strong secret, but is is strong enough to keep out casual attackers. You’ll still need additional security, but sshd is well equipped to provide that.
If you want to go down that path, a password is only security by obscurity.
Port knocking is an extra layer of security, and one that can stop attackers from ever knowing your private server even exists. A random scanner won’t even see any open ports.
Always bear in mind that any random guy advising people not to use port knocking may be doing it with malicious intent. I’m sure there’s someone out there advising that random passwords are a waste of time, and everyone should just use monkey123.
I wish I still had the link, but you make a good point. I’ll look into setting it up again. I have certs set up and working. I just need to disable password.
ITT: People who don’t understand Tailscale or are allergic to it for ‘reasons’
As others have already said, set up a VPN like wireguard, connect to the VPN and then SSH to the server. No need to open ports for SSH.
I do have port 22 open on my network, but it’s forwarded to an SSH tarpit: https://github.com/skeeto/endlessh
But Tailscale is Wireguard under the hood.
I have wireguard for other purposes but I also have ssh open on a different port. I don’t much understand the argument of exchanging ssh for wireguard. In the end, we’re just trading an attack vector for another.
My ssh only allows connections from my user. If I’m using password auth, I also request a 2FA.
Tail scale is also a good idea but I don’t like having my control plane under someone else’s control.
There is quite a significant difference. An ssh server - even when running on a non-default port - is easily detectable by scanning for it. With a properly configured Wireguard setup this is not the case. As someone scanning from the outside, it is impossible to tell if there is Wireguard listening or not, since it simply won’t send any reply to you if you don’t have the correct key. Since it uses UDP it isn’t even possible to tell if there is any service running on a given UDP port.
So just run headscale then.
Or nebula
The reason a VPN is better to expose than SSH, is the feedback.
If someone tries connecting to your SSH with the wrong key or password, they get a nice and clear permission denied. They now know that you have SSH, and which version. Which might allow them to find a vulnerability.
If someone connects to your wireguard with the wrong key, they get zero response. Exactly as if the port had not been open in the first place. They have no additional information, and they don’t even know that the port was even open.
Try running your public IP through shodan.io, and see what ports and services are discovered.
If someone finds a 0day in your SSH server and goes on drive-by attacking the whole internet you’re toast.
Already moving off port 22 reduces much of the risk, essentially reducing the attack surface for drive-by attacks to zero while still being susceptible to targeted attacks – that is, still susceptible to attackers bothering to scan the whole range. Anything that makes you unscannable (VPN, portknockd, doesn’t matter) mitigates that. Even state-level actors would have to be quite determined to get through that one.
Yes it’s security through obscurity. Yes it’s a good idea: There’s a difference between hiding your unlocked front door and hiding your military-grade front door lock, one of them is silly the other isn’t.
For management ports, I set up a firewall on the VPS to only respond to connections from known IPs.
Throw CrowdSec on there to stop the bots before they can do anything
The best reason is reducing attack surface. It’s such an easy thing to do. I don’t know why people still expose services they don’t need to.
Moving the port doesn’t reduce attack surface. It’s the same amount of surface.
Tailscale is a bit controversial because it requires a 3rd party to validate connections, a 3rd party that is a large target for threat actors, and is reliant on profitability to stay online.
I would recommend a client VPN like wireguard, or SSH being validated using signed keys against a certificate authority your control, with fail2ban.
You can run headscale to do your own validation.
It reduces the probability that a drive by scanner is going to detect a vulnerable service. Camouflage isn’t a guarantee that you aren’t going to be sighted on a battlefield, but it’s still a good idea to reduce the probability of becoming a target in whatever ways you can.
And yet it is more likely that tailscale get owned since the reward is much higher. I take my chances with my secured openssh server at port 22 vs a 3rd party company who controlls the access.
Just setup a wireguard system that’s pretty bulletproof
So is SSH
Wireguard doesn’t respond but I agree open-ssh is pretty solid. Can’t speak for any of the other ssh implementations. It can also be poorly configured. Like you could use a password
The benefit of Wireguard is that if you screw it up, it just won’t work. It basically enforces security.
Well, unless you tried to use the original PFSense module.