News for hackers. Stuff that matters.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by benjojo12 on Sunday May 29, 2016 @09:19AM (#11796254)
Hi, 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.

Re:Changes sshd port every 30 seconds, using Two Factor Auth... by niccaluim on Sunday May 29, 2016 @11:02AM (#11796581)
> a joke for all of the people who say "Changing your port is security by obscurity"

This always tickled me. I don't do it for security; I do it because (on public-facing servers) it keeps the constant stream of doorknob-rattling out of the logs!

Re:Changes sshd port every 30 seconds, using Two Factor Auth... by ultramancool on Sunday May 29, 2016 @03:06PM (#11797743)
Failed auths are generally boring and rarely worth looking at. Look at the successes instead.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by mancerayder on Sunday May 29, 2016 @05:24PM (#11798307)
I just use DenyHosts. A few rattling attempts, and the IP won't be able to make another auth attempt again.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by niccaluim on Sunday May 29, 2016 @07:31PM (#11798727)
It's very very very rarely the same IP.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by e12e on Sunday May 29, 2016 @04:36PM (#11798082)
Fun project. With my more serious hat on, I think what most people are missing about all these port-knocking schemes -- is that they all boil down to poor key based authentication.

In the case of TOTP, the key is stored in plain text two places: the server and the TOTP client (or similarly, for other port knocking schemes, on the server to calculate the next port, and on the client to do the same).

Contrast this with disabling password login, and using only key-based authentication: Now the secret key is only stored in one place: on the client (although, to be fair, there's a secret key you can steal on the server too, in order to compromise the system).

The way to improve security beyond simply requiring key-based auth, is to move away from trust-on-first-use to using ssh certificates. To improve on that, require certificates and TOTP. It's still somewhat hard to see how the latter really improves on security - perhaps with some kind of dedicated TOTP hw token. I would guess that compromising the TOTP-key stored on a smartphone is probably one of the easiest attack vectors, so it's unclear how much more secure it is, beyond simply using ssh certificates.

Re:Changes sshd port every 30 seconds, using Two Factor Auth... by andersonmvd on Sunday May 29, 2016 @04:54PM (#11798165)
Just an observation: 30 seconds should be enough to brute force all ports. It's possible to split the range of the ports by using multiple hosts to perform the scan in case 30 seconds don't be enough.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by e12e on Monday May 30, 2016 @01:02AM (#11799650)
The obvious next step is ipv6 address hopping in a /64 dedicated to the machine in question I guess...
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by venomsnake on Sunday May 29, 2016 @12:49PM (#11797026)
Couple of enhancements - there should be port map for ports which not to connect to. Also - you will have a hell of a time with synchronization, timezone etc.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by camperman on Sunday May 29, 2016 @09:40AM (#11796317)
Aren't you worried that systemd won't silently kill the background process? :)
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by danieldk on Sunday May 29, 2016 @10:18AM (#11796443)
I know that you are probably joking, but you'd launch such a thing from a unit file. Hence, no silent killing.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by akshatpradhan on Sunday May 29, 2016 @10:19AM (#11796448)
How would that even be possible?
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by morb on Sunday May 29, 2016 @11:44AM (#11796732)
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by TheCoreh on Sunday May 29, 2016 @11:27AM (#11796669)
A new change in systemd made it so that nohup'd processes are killed by systemd after you log out.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by milankragujevic on Sunday May 29, 2016 @01:40PM (#11797289)
I'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.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by stordoff on Sunday May 29, 2016 @02:04PM (#11797445)
Does that mean that something like "wget URL &" would be killed if I log out of SSH?
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by MereInterest on Sunday May 29, 2016 @04:14PM (#11797997)
Why would they change that? Isn't that exactly why you would ever nohup a process?
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by evook on Sunday May 29, 2016 @09:54AM (#11796370)
> as a joke for all of the people who say "Changing your port is security by obscurity"

That's simply not true. Changing the sshd safes you a lot of trouble in risky environments. You prevent services which rely on ssh from failing during automated dos/bf attempts.

Re:Changes sshd port every 30 seconds, using Two Factor Auth... by frutiger on Sunday May 29, 2016 @11:09AM (#11796599)
It's weird that you trust randomizing the port over a range of [0, 65536) over the trust you have for the cryptographic strength of a 4096-bit RSA key (or equivalent).
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by jlmorton on Sunday May 29, 2016 @06:21PM (#11798503)
While making the port number based on a TOTP token is clearly just for fun, it's not unusual to not entirely trust public key authentication. This is an additional security step.

Once public key authentication is allowed, the mechanism is only as secure as the private key. There is no way to require a password on private keys, and in any event it could be captured with a keylogger. The concern is not the cryptographic strength of the key, it's end-user security.

While randomizing the port is not security, no one would say 2FA is not required because we can trust RSA.

Re:Changes sshd port every 30 seconds, using Two Factor Auth... by curried_haskell on Sunday May 29, 2016 @11:25AM (#11796663)
I trust two countermeasures over just one.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by ryanlol on Sunday May 29, 2016 @01:02PM (#11797088)
If someone could break 4096 bit ssh keys they could scan every single TCP port on the internet in seconds.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by jjnoakes on Sunday May 29, 2016 @02:05PM (#11797452)
What?
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by mitchty on Sunday May 29, 2016 @02:46PM (#11797643)
http://blog.erratasec.com/2013/09/masscan-entire-internet-in...

180 seconds is still seconds. Randomizing ports really doesn't buy much.

Re:Changes sshd port every 30 seconds, using Two Factor Auth... by ryanlol on Sunday May 29, 2016 @04:06PM (#11797975)
If they can break SSH keys like that, they'll easily compromise thousands of servers they can use to scale up their attack.
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by krastanov on Sunday May 29, 2016 @11:24AM (#11796657)
But is it not true that a random port helps specifically against DoS attacks?
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by jsmthrowaway on Sunday May 29, 2016 @03:15PM (#11797783)
What on earth does a port have to do with a denial of service? Let's play this out, Mr. Spock:

- I have some kind of SSH-specific DoS and will simply enumerate ports until I find SSH, which readily identifies itself right off the bat by nature of the protocol. (No config for that.) Result: DoS successful.

- You deploy fail2ban because someone told you to do so because it makes you "safer." Now I can DoS you in three ways since I know (a) there's a Python regex running on your log and (b) naughty addresses will add a netfilter rule, gradually slowing down each packet as it traverses INPUT. What's that, Lassie? A /16 fell down the SSH port while I inundated fail2ban with failures? (Why do you think fail2ban doesn't have IPv6 support yet? I'm just waiting for [0] since solving the problem is intractable, despite what is common consensus in that community. Oh, you're flattening prefixes? How cute. Watch me find the corner cases in your flattening algorithm since I have several googols of v6 addresses to play with.) Result: DoS successful.

- I grow bored of your mildly annoying countermeasures and simply fire up a reflection attack that targets you with several gigabit/sec of traffic behind the aft nacelle, not caring where your SSH lives. Result: Vastly more probable DoS super successful once your hosting provider null routes you. Add cron to watch for your return. Repeat. Follow you to the new IP when you try that because I will invariably find it (probably when you get back on IRC). Walk over your cold server's corpse while you panic and email CloudFlare who can't help, and you can't afford who can. The end.

Now, shall we begin?

There is a lot of shitty shaman wisdom, some making an appearance in this thread, around the SSH port and logging and yadda yadda that actually makes things less safe for a lot of people who don't know better. Most people move SSH from 22 to something like 2200, forgetting that <1024 requires root so now they're one sshd listener crash or restart race away from a local user intercepting SSH with a malicious binary. Oops.

Correct, and only correct, answer: leave sshd on 22 and get your squishy services off the public Internet or rotate the logs faster. You are a sysadmin with grep and awk. Deal with failures in your log. They are there for a reason, especially if you are exposing sshd to the Internet, and pulling netfilter in or moving ports around is silly TSA-level security theater.

This is all promulgated by those "do these ten things first when you install Ubuntu" guides which capitalize on folks not knowing any better to identify (often faulty) opinion. If you followed one lately it's probably steered you wrong, much like those Learn Sushi Preparation in 24 Hours books. Take the time to understand the problem if you're going to operate services on the Internet and get away from guides. (And yes, I am indicting you for writing one, iff yours includes anything discussed in this comment. Sorry.)

Knocking is the only truly plausible, though still silly, security idea here but even that betrays itself in an nmap by nature of TCP. Also, hope you don't forget your knock when your machine is on fire. (You will.)

It's too bad I'm on the right side of ethical these days or I'd patch all the common SSH scanners to try every port so people will stop doing stuff like this. Some already do.

[0]: https://github.com/fail2ban/fail2ban/pull/1410

Re:Changes sshd port every 30 seconds, using Two Factor Auth... by teddyh on Sunday May 29, 2016 @04:16PM (#11798006)
Thank you for saving at least me from having to argue this viewpoint again, as I have done in the past:

https://news.ycombinator.com/item?id=6617312

https://news.ycombinator.com/item?id=6482192

You did it even better than I did, I think.

Re:Changes sshd port every 30 seconds, using Two Factor Auth... by jsmthrowaway on Sunday May 29, 2016 @04:29PM (#11798053)
It's weird that even right-thinking engineers will vehemently argue against just being a lemming on any number of issues, but all it takes is a few "move SSH port to clean up your logs and install fail2ban" guides and here we are.

This really hits people who dabble in operations with a personal server or something. It's probably a failure of operations folks like me to properly reach developers and other groups who simply toy with our dark arts in the pursuit of getting something done. Operating on the Internet is capital H Hazardous, and simply buying a guide wholesale without understanding it even more so.

I am identifying a need.

Re:Changes sshd port every 30 seconds, using Two Factor Auth... by teddyh on Sunday May 29, 2016 @04:47PM (#11798133)
The problem is that people get unnerved by the log entries showing unsuccessful logins. They get a knee-jerk reaction and the first thing they think of (which will work) is to change the SSH port. What should have stopped them is the feeling that they are now disobeying the internet standards, and the standardized ports are probably standardized for a reason. It’s the same reason anyone should feel a mental pain when considering any quick-and-dirty method of fixing a problem – it is dirty, and will have repercussions.

(The same phenomenon, knee-jerk reactions, could be seen starting in the mid-90s when everybody and their dog had a Solution™ to the e-mail spam problem, leading to canned rebuttals like this: http://craphound.com/spamsolutions.txt)

The proper solution for SSH is probably for the OpenSSH authors to change OpenSSH to no longer log unsuccessful logins (at least by default). If there’s a successful login, the log entry might add how many previous unsuccesful logins there had been within the previous few minutes, but I see no reason at all to log unsuccessful login attempts anymore. The current logging defaults were normal for its time when the code was written, when the internet was very different, but today they are simply scaring people for no reason.

Re:Changes sshd port every 30 seconds, using Two Factor Auth... by danesparza on Sunday May 29, 2016 @10:31AM (#11796476)
Hmmm ... wouldn't it be possible to use a distrubuted portscanner to find the current port? Or simply DDOS the switch that the box is attached to? Or the router? Or another downstream connection point?

While I love the ingenuity of the OP's software, I'd have to agree with their own assessment on the Github page "Beware, currently I would not really recommend running this software, it was only written as a joke."

Re:Changes sshd port every 30 seconds, using Two Factor Auth... by djrogers on Sunday May 29, 2016 @11:16AM (#11796619)
Needing distributed port scanner adds a huge barrier to entry over that needed for a simple ssh brute force script. Not to mention that once you find the port you have at most 30s to brute force it before it moves again...
Re:Changes sshd port every 30 seconds, using Two Factor Auth... by falcolas on Sunday May 29, 2016 @11:49AM (#11796752)
Not so huge.

    nc -z <host ip> 0-65535
This runs pretty quickly, and if you're co-located with your attacker (i.e. aws), you're not going to be in great shape.

So ultimately, this offers about the same protection against a dedicated attacker that just hosting it on a non-standard port does, with the disadvantage of any clock drift making it much harder to access your own machine.