16 ms·
Changes sshd port every 30 seconds, using Two Factor Auth to login
- taspeotis 10y agoPrevious discussion: https://news.ycombinator.com/item?id=11750003 https://news.ycombinator.com/item?id=11750003
- e40 10y agoI don't understand why this is seen as acceptable, yet port knocking is derided every time it's brought up. Since installing fwknopd more than a year ago, we have had not a single attempt at sshd. Not one. We had a lot before, and it was annoying as hell.
- benjojo12 10y agoUnfortunately people have taken this a little too seriously, I wrote this as a joke/PoC of silly "Security by obscurity" methods, and yet people are for some reason viewing this as a serious solution...
- mclemme 10y agoIt does seem a little silly, the readme does also mention it was written as a joke. Was looking at ways to decrease logspam from ssh login bots some years ago, port knocking seemed like the most elegant solution. I ended up simply moving ssh away from port 22, the logspam disappeared. I've used fail2ban in other setups, it also has the advantage of being easy to integrate with other systems such as wordpress, sftp/ftps, nginx, apache.
- noonespecial 10y agoPeople get their wires crossed about port knocking because it doesn't add much security when I'm trying to find a way to hack you. It does add something when I'm trying randomly to find you to hack. They make the valid criticism of the first case while you argue the second and somehow the arguments miss in the middle.
- nisa 10y agoHow does that not add security? If you use a secret token or some authenticated website for opening the port how can an attacker easily circumvent this?
- developer2 10y agoIf you do not have the ability to eavesdrop on the network between my client and my server, then port knocking is essentially unhackable. Port knocking only fails when the malicious party can monitor the network traffic. This is a valid concern, and I would never say that port knocking by itself is all the security one needs. It does however completely block all regular "outsiders" from ever being able to even open a connection to sshd. If I require 5 ports to be hit in sequence, and blacklist IPs that hit unknown ports, it is extremely unlikely you will ever connect. Now if someone on my local network, at my ISP, or at my hosting provider sniffs my traffic to determine a static knocking sequence... good for them. They're the one unauthorized person who can connect to sshd, without a valid ssh key to authenticate with. It's a reality that most businesses are not going to invest in setting up a network that cannot be accessed from the internet at large. For such setups, a little bit of obscurity via something like port knocking to prevent every single port scanner in existence from discovering your sshd server must be better than nothing at all.
- munin 10y ago> blacklist IPs that hit unknown ports so what happens when someone hits an unknown port on your system from every IP on the internet?
- developer2 10y agoYou reject all packets from "bad IPs" for a period of time. 5 minutes, 30 minutes, whatever. If you're in a position to spoof IPs and you manage to spoof one I need to connect from (or I make a mistake and get myself blacklisted), it's a temporary inconvenience. That, and having out-of-band access to the server always helps. ;)
- georgeam 10y agoI recognize that this is a joke, in the words of the OP. However I think SPA-type port knocking is completely legitimate, and I second the use of fwknopd. I depend on fwknopd a lot, so if that is not secure idea, I would like someone to point that out to me. NOTE that fwknopd does not depend on expecting a client to connect to a short sequence of different port numbers. That is not what fwknopd does, at least not the latest fwknopd. Instead, fwknopd listens for an encrypted packet on a specified port, which it will not acknowledge. The firewall does not allow the packet through, technically speaking. But fwknopd recognizes the arrival of the packet by scanning logs when the firewall drops the packet and logs the dropped packet. etc. etc. If you know this type of fwknopd deployment and don't think it is a good idea, please comment. Again, I am not taking the OP seriously, but I do take seriously that people either don't know about fwknopd, or maybe, don't think that is good security (in which case I want to hear from you).
- belorn 10y agoCorrect me if I am wrong here, but would the following changes to SSH give you the same result: Change protocol from TCP to UPD and port from 22 to 62201. Remove greeting. If first message is not the correct password, do not send a reply. If everyone used this, do you think SSH would become more secure and eliminate password scanners? Personally I think that if ssh took in a fwknopd patch and used that as default, any benefit you see now would disappear. I also suspect that logging every UDP package to 62201 would be a bad idea, probably worse than logging every failed attempt on TCP port 22.
- oneru 10y agoSsh does a fingerprint verification and establishes a secure channel before it does the password exchange. Avoiding replay attacks can be a challeng as well. Putting strong authentication in a single packet is deceptively nontrivial. It can be done, but at that point you'd be reimplementing Fwknopd. Additionally, Fwknop can protect more than just ssh, and do fancy things like providing access to a machine without a public IP address. Disclaimer: I'm one of the Fwknop devs. =)
- rsync 10y ago"I don't understand why this is seen as acceptable, yet port knocking is derided every time it's brought up." I have been in this business for a long time and I still look very fondly at port-knocking as a thing that genuinely makes things better. Almost zero complexity added, super stable knockd daemon, and does a single, simple thing very, very well. I love port knocking, I love using it, I love the idea of it, and I wouldn't build a server without hiding sshd (and others) behind a knock. All criticism of port knocking (weirdly) assumes that you also disable all other forms of security and that you rely solely on port knocking, which of course is false. It is true that port knocking adds just a marginal additional amount of security, but it's still additive and it's still a high return on the (very low) complexity and maintenance.
- belorn 10y agoIf you chain two sshd and have a certificate on the first and password on the second, the second sshd will have the exact same number of attempts as your current setup.
- benjojo12 10y agoHi, Author of this here! The title "Changes sshd port every 30 seconds, using Two Factor Auth to login" This isn't what the project is about, It was mainly done as a joke for all of the people who say "Changing your port is security by obscurity", and thus the idea came to make a even more insane/silly version of it. It's using "two factor" to generate the port to connect, not to login, there are loads of ways to authenticate SSH with TOTP tokens, but this is not that.
- camperman 10y agoAren't you worried that systemd won't silently kill the background process? :)
- danieldk 10y agoI know that you are probably joking, but you'd launch such a thing from a unit file. Hence, no silent killing.
- akshatpradhan 10y agoHow would that even be possible?
- TheCoreh 10y agoA new change in systemd made it so that nohup'd processes are killed by systemd after you log out.
- milankragujevic 10y agoI'm not really linux-savvy, but if it's true and it does what I think it does, it's really stupid. A lot of my scripts rely on nohup to send something to background, and I often logout after running the script, so this would break my whole workflow.
- stordoff 10y agoDoes that mean that something like "wget URL &" would be killed if I log out of SSH?
- geocar 10y agoThis is a very bad idea. If I suspect you're doing this, I can definitely probe 30k ports silently within a second. How many tries do you think I need to break the last two digits?
- MichaelBurge 10y agoThe very description of the project says "Take security by obscurity to the next level (You must be insane to run this)", so I'm not sure why you're trying to convince the author here.
- developer2 10y agoa) It's not explicitly said that the ssh password is the last digits from the code. That's the intuition I got as well, but that would be pure craziness. I assume only the port is affected, and you're using your normal authentication scheme (key or password) to login. b) Straight from the GitHub's README, which was not edited after submission to HN: >> Beware, currently I would not really recommend running this software, it was only written as a joke.
- dexterdog 10y agoI didn't think he meant getting the password which won't do you any good without the private key. I thought he meant getting the last 2 digits so you could start recording a pattern and eventually determine the 2FA key.
- dexterdog 10y agoCan't a scan like that be detected by a simple firewall?
- brudgers 10y agoTwo men walking in the woods enter grizzly country. One stops and swaps his hiking boots for running shoes. The other says, that's stupid, you'll never out run a grizzly bear. The technical concerns fall under the category of security. The business concerns fall under risk mitigation. These concerns converge as the value of an enterprise's assets rises. Banks and blogs are toward different ends of the spectrum. At the lower end, this sort of measure probably keeps a wordpress site in the middle of the herd when wolves invite themselves to dinner.
- daraosn 10y agoIs there a service that wraps/proxies a port with a different or custom protocol? (kind of like SSL for HTTP) Idea: instead of ssh'ing a server, you would run your custom command which communicates to port XXXX, communicate with a custom protocol and then if validation succeeds, would proxy to SSH (or any other internal port/protocol). Why? Because as others suggested you could scan all ports very quickly to break this, but if you scan a port and just receive garbage or something only you can understand when opening it, then you could hide it from the outside.. (Just curious)
- xg15 10y agoSeems possible (though very time-consuming) if you just use it to protect your hobby/toy machines. As soon as your protocol becomes important enough that it attracts the attention of human hackers and not just bots they can easily reverse-engeneer it. By the way, I think you could view encrypted connections as a sort of automation of that practice: A crypto algorithm could be seen as a machine that generates "custom protocols" given a key...
- daraosn 10y agoThat's a interesting idea, to make encryption dynamic using something like the 2FA described here.
- frutiger 10y agoEncryption in most commonly used protocols are dynamic - each session generates a brand new session key that are negotiated such that only the holders of the private keys can discern.
- deleted 10y ago[deleted]
- mjec 10y agoThere is an existing solution to give you this protection, it's called port knocking.
- 10y ago
- mschuster91 10y agoNice idea, but tbh I'd prefer if someone rewrote it in (ba)sh scripts. Not everyone likes to install dozens of different language interpreters/runtimes on his systems - Ruby for puppet, perl is these days mainly used by apt-get, Go, NodeJS, some people use PHP, then Java, the Python version hell with people using either 2.7 or 3.x, Mono, bash, zsh, C, C++... As much as I like flexibility and "the right tool for the right job", we have ended with ridiculously huge install bases - a minimal Debian may very well end up with hundreds of megabytes, it's ridiculous. Mandatory xkcd: https://xkcd.com/927/ https://xkcd.com/927/
- Nullabillity 10y agoI dislike Go as well, but it does compile to a static binary, so you shouldn't need to install any runtime at all.
- patrickg_zill 10y agoI would install it, but there is not the usual "wget https:// https:// ... | bash" setup...
- benkulbertis 10y agoHere you go! "wget -O - https://pastebin.com/raw/beiNBca5 https://pastebin.com/raw/beiNBca5 | sudo bash"
- jftuga 10y agoThis is also an interesting idea: http://serverfault.com/a/217066/46738 http://serverfault.com/a/217066/46738 (accepted answer is pasted below) Rate limiting login attempts is an easy way to prevent some of the high speed password guessing attacks. However, it's hard to limit distributed attacks and many run at a low pace over weeks or months. I personally prefer to avoid using automated response tools like fail2ban. And this is for two reasons: 1) Legitimate users sometimes forget their passwords. I don't want to ban legitimate users from my server, forcing me to manually enable their accounts again (or worse, try to figure out which of the 100/1000 banned IP addresses is theirs). 2) An IP address is not a good identifier for a user. If you have multiple users behind a single IP (for example, a school that runs NAT on 500 student machines) a single user making a few bad guesses can land you in a world of pain. At the same time the majority of the password guessing attempts I see are distributed. Therefore I don't consider fail2ban (and similar automated response tools) a very good approach to securing a server against brute force attacks. A simple IPTables rules set to cut down on the log spam (which I have on most of my linux servers) is something like this: iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 -j DROP It prevents more than 4 connection attempts from a single IP to ssh in any 60 second period. The rest can be handled by ensuring passwords are reasonably strong. On high security servers forcing the users to use public key authentication is another way to stop guessing. ---- (end of answer) for Ubuntu admins... http://manpages.ubuntu.com/manpages/xenial/man8/ufw.8.html http://manpages.ubuntu.com/manpages/xenial/man8/ufw.8.html (Uncomplicated Firewall) ufw supports connection rate limiting, which is useful for protecting against brute-force login attacks. When a limit rule is used, ufw will normally allow the connection but will deny connections if an IP address attempts to initiate 6 or more connections within 30 seconds. See http://www.debian-administration.org/articles/187 http://www.debian-administration.org/articles/187 for details. Typical usage is: ufw limit ssh/tcp
- joelhaasnoot 10y ago> On high security servers forcing the users to use public key authentication is another way to stop guessing. Public key and IP limiting is standard practice, eliminating passwords should be top priority for anyone running SSH servers.
- cel1ne 10y agoI just set the port to something > 10000 and configure it to use public key authentication only.
- agrafix 10y agoYeah, me too! I would not call this security by obscurity because it actually helps making the auth logfile more readable ;-)
- sschueller 10y agoIsn't it safer to keep the ssh port below 1024 so that another user other than root can't start a listener on that port?
- noinsight 10y agoThey can only do that if the ssh daemon isn't already listening on the port, i.e. it has crashed or is not running.
- cperciva 10y agoA far more secure approach: http://www.daemonology.net/blog/2012-08-30-protecting-sshd-using-spiped.html http://www.daemonology.net/blog/2012-08-30-protecting-sshd-u...
- geggam 10y agoAll of these port knocking folks who talk about logs getting full.... quit logging the rejected connections. Log the accepted connections. Reminds me of Butch Cassidy movie where the old man told them they were silly for worrying about getting robbed before they had the money. If people cant get in they cant do bad things(tm) BTW... is there an ansible playbook for portnocking with config management ?
- Animats 10y agoReminds me of "port knocking", a similar form of security through obscurity. Still, this stuff is useful just to thin out all the crap coming in from botnets.
- dohqu8Zi 10y agoSo, this is http://shimmer.sourceforge.net/ http://shimmer.sourceforge.net/ rewritten in go?