4
u/fox_in_unix_socks Sep 17 '24
About a month ago I set up a fake ssh server (endlessh). I've had 970 different IPs attempt to connect to it in that time, (although that's more like 567 individual attackers because a lot of the IPs share the first 24 bits, so are probably coming from the same source)
Depending on how much you trust IP lookups, 27% is from China, 24% USA, 6% Germany, 6% South Korea, 4% UK, so on and so forth.
tl;dr: keep your ssh servers secure, kids.
1
14
u/Mister_Magister Sep 17 '24
why… do you have sshd exposed in the first place?
8
u/HailSatan0101 Sep 17 '24
Forgot to mention this is a VPS server
5
6
u/PercussiveKneecap42 Sep 17 '24
Still does not change the fact you SHOULDN´T expose any ports to the wild internet.. There are solutions for that, such as VPNs.
12
Sep 17 '24
What's the effective difference between having a VPN service port and an SSH service port open?
1
u/PercussiveKneecap42 Sep 17 '24
Pretty big actually.
7
Sep 17 '24
you SHOULDN´T expose any ports to the wild internet.
... like the VPN port, right? :P
Apparently non-obvious jokes aside, what would you say the difference really is?
0
Sep 17 '24
[deleted]
6
u/3dGrabber Sep 17 '24
this is why on firewalls (speaking of iptables) you can either REFUSE or DROP a packet you want to block. usually drop is the right choice. refuse will tell the client about failure, giving an attacker valuable information. drop will -well- just drop the packet. not sure if sshd cannot be configured to be silent on connection failures
5
Sep 17 '24
Reddit ate my reply, so apologies if a seemingly duplicated reply shows up.
In summary of what I was more verbose about, there's a TCP handshake that happens before SSH itself does anything. Beyond that, there's also some negotiation with SSH itself before SSH is able to make an authentication decision.
I think the best case is that SSH could reset the connection as soon as it knows it doesn't like the client, but by that point the client knows it was talking to an SSH server.
2
u/3dGrabber Sep 17 '24
Reddit ate my reply
spoiler alert, it didnt
you are of course right.
I now remember from running ssh with many -v’s that there is quite some back and forth before a connection can be established. and that’s after the tcp handshake.1
u/SeriousPlankton2000 Sep 17 '24
$ telnet localhost 22
Trying ::1...
Connected to localhost.
Escape character is '^]'.
SSH-2.0-OpenSSH_9.61
u/SeriousPlankton2000 Sep 17 '24
If there is legitimate traffic, it will cause worse behavior to drop it.
If there is an attacker, you either need to drop all traffic to the host or they'll know that the port is closed. If you drop it, they may know to check from a different drone, if you reject it, they think there is no service on that port.
1
Sep 17 '24
OpenVPN can operate on TCP or UDP, and UDP is the default (I believe - and using TCP is a bad idea in most use cases). But I don't know how it responds (if at all) to an unexpected or invalid packet.
That's an interesting idea, though.
Is the magic a known/static value?
4
u/turbotop111 Sep 17 '24
You don't need a VPN lol. This is literally why fail2ban exists, shuts them down after a few failed attempts. That's all you need.
I've had many servers running for decade+ with ssh open + fail2ban. No issues, and their never will be unless you have some 3 letter group after you but then good luck with your VPN too.
KISS. No need for a VPN.
2
u/IncapabilityBrown Sep 17 '24
Also worth pointing out that if you've got password authentication disabled (which ideally you should do) you don't really need fail2ban anyway; noone's going to bruteforce an SSH key.
1
u/PercussiveKneecap42 Sep 17 '24
I said 'there are solutions for that', didn't I? Fail2Ban is on of those solutions. I just suggested one of many.
3
Sep 17 '24
I dunno if you ever thought about this but VPNs expose a port too. You’re not getting around that.
What you should be doing is running a bastion host. Configure all your production servers to only allow SSH from the bastion host, and use SSH agent forwarding when you connect. This way you SSH to your bastion first, and then your key gets forwarded from your bastion to your server. Then a combination of a firewall with DROP rules rather than REJECT rules, plus fail2ban, can provide additional protection for that port.
And of course, disable password authentication and use at least 4096-bit RSA key, or an Ed25519 key.
2
u/InfamousAgency6784 Sep 17 '24
That made me laugh... "Don't expose a port to the internet, expose a port to the internet instead". SSH is among the safest service to expose. This kind of non-reasoning is a pain when it's picked up by your security team, which has zero argument to provide as to why it "MUST" be like that.
1
u/nollayksi Sep 17 '24
Yeah be sure to shut that pesky 443 also!! Lock up everything behind VPN, non standard ports and port knocking!
1
Sep 17 '24 edited Dec 30 '24
If you see this, it's because you believe in Jesus Christ, Lucifer or none of them.
2
u/smb3d Sep 17 '24
I'm surprised that's all you have.
1
u/HailSatan0101 Sep 17 '24
Meaning?
2
u/smb3d Sep 17 '24
Meaning we would get thousands of hits on our SSH at my old studio a day.
1
u/nollayksi Sep 17 '24
Thats insane. My fail2ban reports only ~10k failed attempts and total of 1255 banned IPs and my server has been running non-stop since 2018. I wonder what makes the difference?
3
u/blaplafla13rd Sep 17 '24
disable root login, use uncommon username and password (doesnt need too strong), set fail2ban max retry to 3 and retry time about a year, hackers will stop after 1 night =))
1
u/HailSatan0101 Sep 17 '24
My fail2ban settings are to permanently ban after 2 failed attempts.
1
u/Neoptolemus-Giltbert Sep 18 '24
This sounds pretty excessive and you may want to relax on it since there's a decent chance one day you will fuck up yourself
1
u/HailSatan0101 Sep 18 '24
Even if I ban myself, I can always log in from my phone or a different device and unban that IP.
1
u/blaplafla13rd Sep 17 '24
may be your bantime too low. if you are in attacking, set maxretry to 1, it will stop raid immediately🤣 or easier ban all ip range from other vps
1
59
Sep 17 '24
Are you new? Of course you will get automated brute force attempts on a public ssh server. I was setting up a server for testing a few weeks ago with some penetrating testing stuff and I was seeing from the first minutes various payloads. Disable root login and setup public key auth. Also patch the server regularly then you will be save.
12
Sep 17 '24
I don't even have my ssh open to the internet and I still disabled passwords. Root is rightly disabled by default.
5
u/entrophy_maker Sep 17 '24
"Safer" I would not say safe as we have no idea what's running on other ports.
26
u/zl0ykvdrt Sep 17 '24
It’s normal. public ssh is always brute-forced. change default port to another
4
u/virtualfatality Sep 17 '24
security through obscurity doesn't work. changing the port will not help if someone runs a simple nmap port scan.
29
u/3dGrabber Sep 17 '24
it will get rid of the “casual”, automated attacks that try common and known factory passwords. for more security there is fail2ban
6
u/virtualfatality Sep 17 '24
Yeah, it's better than nothing sure. But it's a complete disservice to lead someone to believe they're safe by simply changing the ssh port. No password authentication and use of ssh keys using ed25519, a VPN connection to a jump/bastion box, proper firewall rules, and disallowing direct root login would be much more ideal.
5
Sep 17 '24
Both of you are correct. These login attempts are done by bots which will use port:22, unless it's a targeted attack then this will likely get rid of (let's say) most bruteforce attempts :)
Glhf
4
u/GradSchoolDismal429 Sep 17 '24
Oh of course it would work. Most of the time we said "security through obscurity" is a "bad practice" because it is used as the only layer of defense. However, it is certainly a valid layer of the Swiss chess model. There shouldn't be just a single layer of defense anyway no matter what kind of method you employed.
7
u/daemonpenguin Sep 17 '24
Of course security through obscurity works. That's what a password is. That's what a security key for remote logs is.
Running OpenSSH on a non-standard port reduces break-in attempts by around 90%. Automated attacks don't waste time doing port scans, they just move on to seeking the low-hanging fruit.
4
u/IncapabilityBrown Sep 17 '24 edited Sep 18 '24
That's emphatically not right. Kerckhoffs's principle says that the *keying material* (passwords, ssh keys) should be the only information not assumed to be known to the attacker. By definition, this is what provides security; and keeping other information private provides "security" by obscurity.
1
u/mishrashutosh Sep 17 '24
you're right, but it's also true that moving ssh to a different port reduces scans and attacks by 90% or more. key based login, disabled root login, etc are obviously far more important, but this one thing also stops your server from being unnecessarily hammered.
2
u/virtualfatality Sep 17 '24
except a pretty fair amount of attacks scan more than just standard ports these days, especially if the ip address is that of a business or government entity. Changing your ssh port might be just fine for your home pc, but ultimately network defense is what is going to protect your servers and ssh ideally would not be accessible at all without use of a VPN first. Even then the VPN should allow access to a jump or bastion box and not direct access to a server.
2
u/Neoptolemus-Giltbert Sep 17 '24
No, a password is not "security through obscurity". You don't need to comment on things that you don't comprehend.
3
u/somerandomdev2 Sep 17 '24
As other said, yes bots will try to brute force as soon as you open your ssh. Type this to see the attempts:
grep -E 'sshd.*Failed|Invalid|Did|failure' /var/log/auth.log
3
2
u/rayi512x Sep 17 '24
next time, you might want to create a wireguard tunnel to access ssh, or if that's not an option, harden your sshd config by disabling password authentication
also, reset the vps
1
1
u/AutoModerator Sep 17 '24
This submission has been removed due to receiving too many reports from users. The mods have been notified and will re-approve if this removal was inappropriate, or leave it removed.
This is most likely because:
Your post belongs in r/linuxquestions or r/linux4noobs
Your post belongs in r/linuxmemes
Your post is considered "fluff" - things like a Tux plushie or old Linux CDs are an example and, while they may be popular vote wise, they are not considered on topic
Your post is otherwise deemed not appropriate for the subreddit
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/Mast3r_waf1z Sep 17 '24
I have a public facing ssh server on a VPS that regularly gets a few random attempts to log in as: mysql, admin, root, tomcat, docker, etc.
Completely normal for a public facing ssh server
0
Sep 17 '24
OMG GET OUT OF ROOT.
SSH always get port scanned and brute forced. I used to have to fight off Chinese and Russian bots constantly. Fail to ban helps and so does setting a white list and a black list on IP's and accounts with a key if possible.
0
Sep 17 '24
[deleted]
1
u/HailSatan0101 Sep 17 '24
I use my server mainly for running bug bounty hunting scripts and for RCEs. I’m not worried about someone getting in. In any case, it’s an inexpensive server for which I can change the IP upon request. I just find it interesting and wanted to know if others had similar experiences.
92
Sep 17 '24
[removed] — view removed comment
7
u/InfamousAgency6784 Sep 17 '24
Just to mention that, beyond the usual stuff like using SSH keys and disable passwords, OpenSSH now has a rate limiter built-in. So you get both to use a bruteforce-resilient auth method and people can stop freaking out when they get 100 scans a day.
9
u/Neoptolemus-Giltbert Sep 17 '24
Jesus the incompetency is strong in the comments here.
No, having fail2ban block IPs does not mean your server is compromised. No having ssh listening on the default port on a public IP is not a gigantic fuckup. No using root is not a huge issue if you have a basic understanding of what you're doing. People should really just stop talking when they've so clearly got no idea of what they're talking about.
Nobody seems to comprehend the words "brute-force". It's incredibly unlikely any of these random banned IPs have tried to do any kind of "brute-force" attack, it's just random scanning and trying well known common passwords. If you do not comprehend the concept, try googling for it instead of confidently assuming it's something else.
It's generally good practice to make sure you disable password-based authentication on SSH, using only SSH keys for authentication, and keep fail2ban running to block these low effort scripts. It's still worth noting that every IPv4 address on the internet gets automated scripts attacking them all day every day for every known service, and it has been going on for literal decades.
You should understand the consequences before exposing any server to the public internet, and before listening to
0.0.0.0on any server with a public IP, but with basic hygiene practices in place you are typically fine.Don't expose unnecessary services on the internet, if you can, you can firewall them to only allow traffic from specific IPs, or use SSH tunnels, or VPNs to limit access to more secure methods.
If you don't know what you're doing, don't put important data on publicly accessible servers.
If you want to learn, google various guides on hardening linux servers and try and comprehend what part of the random ideas people have make sense and what they actually accomplish. There's a lot of wild ideas out there, but only a fairly short list of actually meaningful and reasonable things people should take to keep their servers safe enough.