• Adrian Bool

    I agree wholeheartedly; it’s just another level of protection as part of defence in depth – although I’d use port 48351, or similar, rather than port 24!

    This action would only be security through obscurity if you had no password or private key on the accounts – the non-standard port was your only protection. I’m sure that that is not the case!

    A further protection is, on your firewall, to only permit connections with a source port less than 1024, then use the ‘UsePrivilegedPort yes’ in your ~/.ssh/config file to tell ssh to use source ports < 1024. My quick checks with nmap showed that nmap used source ports over 1024 – so even a hit on the right destination port would not result in an ‘open’.

    Were you monitoring the traffic to your ssh ports, if yes, were most of the source ports < 1024??

  • Adrian Bool

    I agree wholeheartedly; it’s just another level of protection as part of defence in depth – although I’d use port 48351, or similar, rather than port 24!

    This action would only be security through obscurity if you had no password or private key on the accounts – the non-standard port was your only protection. I’m sure that that is not the case!

    A further protection is, on your firewall, to only permit connections with a source port less than 1024, then use the ‘UsePrivilegedPort yes’ in your ~/.ssh/config file to tell ssh to use source ports < 1024. My quick checks with nmap showed that nmap used source ports over 1024 – so even a hit on the right destination port would not result in an ‘open’.

    Were you monitoring the traffic to your ssh ports, if yes, were most of the source ports < 1024??

  • http://www.seanmcollins.com/ Sean

    The problem with changing ports that services listen on is the loss of trust. Services that listen on ports lower than 1024 are considered “trusted” because they require root privileges. So if SSH is enabled on a very high port, I’d be worried about my personal security when I connect to that system.

    Also, using service detection with tools like NMAP will quickly remove negate any extra security that is provided by running on non-standard ports.

    The only upside to running on non-standard ports is that automated attacks won’t occur, but honestly a good firewall ruleset or a something like deny_hosts really solves the problem while retaining the “trust” factor.

  • http://www.seanmcollins.com Sean

    The problem with changing ports that services listen on is the loss of trust. Services that listen on ports lower than 1024 are considered “trusted” because they require root privileges. So if SSH is enabled on a very high port, I’d be worried about my personal security when I connect to that system.

    Also, using service detection with tools like NMAP will quickly remove negate any extra security that is provided by running on non-standard ports.

    The only upside to running on non-standard ports is that automated attacks won’t occur, but honestly a good firewall ruleset or a something like deny_hosts really solves the problem while retaining the “trust” factor.

  • Pingback: Disable SSH Password Authentication with OS X 10.5 Leopard « Anthony Vance

  • Samir

    plz can you tell me how to change the port of the ssh on fedora 8 because ive 2 servers on the same router when so i cant login to one of them because the servers ssh have the same port plz help me , thx

  • Samir

    plz can you tell me how to change the port of the ssh on fedora 8 because ive 2 servers on the same router when so i cant login to one of them because the servers ssh have the same port plz help me , thx

  • http://www.blahedo.org/blog blahedo

    What you’re advocating here is not so much security improvement through obscurity, but security improvement through irregularity. You could proclaim from the mountaintops that you serve ssh on port 24—in fact, you just did—and it would still have improved your security. Heck, you could respond to attempts on 22 with a message redirecting them two ports higher, and it would improve your security, because it would still filter out all the wardialer-style scripts. It wouldn’t work if everyone did the same thing, but by decreasing regularity, you make it much harder for the scripts to account for your case. None of these stop someone determined to get into your system in particular, of course, but that’s why you’re not relying on them.

    • Bob

      I don’t think this is really the case. If you follow good security practice then your risk of getting owned by an automated attempt is near zero even if a new OpenSSH vulnerability is found and – somehow – makes its way into automated scripts quickly enough for you to be hit without warning. These automated attempts are not a security risk for most people, at least I would hope not most people reading this. Moving port does precisely nothing to mitigate the genuine risk of a determined attacker except the thin argument that it reduces noise in logs, and there are other equally valid solutions there.

      • Bob

        I think that sometimes people spend far too much time faffing around creating novel solutions to minor risks rather than putting the effort into following good practice – which will mitigate the trivial stuff anyway – and saving their creativity for the real worries.

      • http://danielmiessler.com/ Daniel Miessler

        If your tank armor is good enough then getting owned by a bullet is small. So why use camo?

        More importantly: Why not?

        • Bob

          It really isn’t that simple.

          A better analogy would be to say we could install a magical camouflage on our tanks that reduced the chance of getting hit by 1% but actually made it break down 1% more as well. Should we do it? Well, we could, but in the end it doesn’t make any difference.

          So changing the ssh port reduces my exposure to automated ssh attacks. I already have adequate protection against these through other policies (which I would require anyway), they are very very low risk.

          However, by doing this I have at least:

          • Made an additional configuration change. In other words, added complexity, no matter how minor. And we know about complexity and security.

          • Added to user and admin WTF factor. Oh, here’s that complexity again.

          • Admin time taken away from dealing with real threats.

          • Changed to a less-tested code path through ssh. In this case a very very minor one, but once you start making this sort tweak they all add up.

          These are maybe a bit of a stretch but so is the idea of a different port stopping some new ssh 0-day.

          • Justin DeMaris

            I have to say I was of the same mentality that the port changes were a stupid change that added complexity, but the point that really hit home for me was the zero-day one. We take for granted that SSH itself is secure. And if you want to buy yourself a bit of extra time from automated attacks when a zero-day gets exposed, running on a different port will most CERTAINLY buy you some time.

            With regards to the added complexity part… any good administrator is inside the sshd_config file for any server deployment anyway, so changing the port number is very minimal risk. If you keep it consistent across your company, then anyone who has a legitimate reason to be using SSH anyway shouldn’t have a problem with it after initial training. Anybody who is comfortable enough with SSH to be given server access should be fine at changing the port number to connect with. Anybody who isn’t comfortable with that has no business having shell access to your server.

          • Bob

            I agree that only good administrators should have access and the risk of a screw-up is low, but it is a risk – and that’s what this is all about. Is the risk of an admin making a mistake (and even good ones do) higher than the risk of getting hit by an ssh 0-day and saved by a different port? In most cases I don’t believe it is.

            I would note that although changing the port should be an easy change, ssh is critical and a mistake made when configuring it can lead to a high security risk or leave you unable to fix a genuine security problem elsewhere. This is always the case but is surely an argument for reducing the time spent in sshd_config unnecessarily.

  • http://www.blahedo.org/blog blahedo

    What you’re advocating here is not so much security improvement through obscurity, but security improvement through irregularity. You could proclaim from the mountaintops that you serve ssh on port 24—in fact, you just did—and it would still have improved your security. Heck, you could respond to attempts on 22 with a message redirecting them two ports higher, and it would improve your security, because it would still filter out all the wardialer-style scripts. It wouldn’t work if everyone did the same thing, but by decreasing regularity, you make it much harder for the scripts to account for your case. None of these stop someone determined to get into your system in particular, of course, but that’s why you’re not relying on them.

  • Pingback: 2 SSH Brute-Force Countermeastures | dmiessler.com

  • http://clichereality.blogspot.com/ Mike

    I just run SSH on a non-standard port >1024 to keep down the size of my log files.

  • http://clichereality.blogspot.com/ Mike

    I just run SSH on a non-standard port >1024 to keep down the size of my log files.

  • http://www.acooke.org/ andrew cooke

    i used to do this, but switched to using knockd instead.

    one reason i switched is that it wasn’t always easy to persuade other software to use the new port. even sftp requires quite an ugly syntax to pass the parameter down to the ssh layer.

    the other reason was that my isp started “traffic shaping”. that means that data transfer using non-standard ports had limited bandwidth.

    neither of those is a very powerful argument (and i’ve since changed providers – from vtr to telefonica chile – to avoid the traffic shaping) and knockd is itself a bit frustrating to use if you don’t have the client handy (you can trigger it using telnet, but it’s hit and miss).

    even so, you might consider it… http://www.portknocking.org/

    ps also, of course, it can protect other protocols too.

  • http://www.acooke.org andrew cooke

    i used to do this, but switched to using knockd instead.

    one reason i switched is that it wasn’t always easy to persuade other software to use the new port. even sftp requires quite an ugly syntax to pass the parameter down to the ssh layer.

    the other reason was that my isp started “traffic shaping”. that means that data transfer using non-standard ports had limited bandwidth.

    neither of those is a very powerful argument (and i’ve since changed providers – from vtr to telefonica chile – to avoid the traffic shaping) and knockd is itself a bit frustrating to use if you don’t have the client handy (you can trigger it using telnet, but it’s hit and miss).

    even so, you might consider it… http://www.portknocking.org/

    ps also, of course, it can protect other protocols too.

  • Drew

    I do this too. A while back I got really annoyed by the number of brute force attempts on my servers.

    I have a HIDS system in place which alerts me to brute force attacks. On port 22 I would get at least 10 messages that it had blocked a brute force attack every day. I thought about disabling that rule, but then I realized that what I wanted to do was block out the annoying scripts, not the deliberate attacks on my systems. So I moved the SSH port to 831 (just made the number up). Now I don’t get the attack messages unless someone scans my system to look at open ports and attack the services on them, something which indicates a much more dedicated attack which I might actually be worried about. I think I’ve gotten all of one ssh brute force alert across 10 servers.

    To mitigate the inconvenience I just put the ports in my .ssh/config file along with shorthands, such as:

    Host s1 HostName server1 Port 831

    Really quite elegant.

  • Drew

    I do this too. A while back I got really annoyed by the number of brute force attempts on my servers.

    I have a HIDS system in place which alerts me to brute force attacks. On port 22 I would get at least 10 messages that it had blocked a brute force attack every day. I thought about disabling that rule, but then I realized that what I wanted to do was block out the annoying scripts, not the deliberate attacks on my systems. So I moved the SSH port to 831 (just made the number up). Now I don’t get the attack messages unless someone scans my system to look at open ports and attack the services on them, something which indicates a much more dedicated attack which I might actually be worried about. I think I’ve gotten all of one ssh brute force alert across 10 servers.

    To mitigate the inconvenience I just put the ports in my .ssh/config file along with shorthands, such as:

    Host s1 HostName server1 Port 831

    Really quite elegant.

  • http://Monkeystealsthepeach.com/ Sol Invictus

    This is a really, really good idea. Security through obscurity is not a replacement for other standard industry-best security practices, but it is a very helpful part.

    The bottom line is it consumes server resources to deal with bogus connections. Even if you have an effective rejection system in place, a non-standard port reduces the amount of traffic you have to deal with.

  • http://Monkeystealsthepeach.com/ Sol Invictus

    This is a really, really good idea. Security through obscurity is not a replacement for other standard industry-best security practices, but it is a very helpful part.

    The bottom line is it consumes server resources to deal with bogus connections. Even if you have an effective rejection system in place, a non-standard port reduces the amount of traffic you have to deal with.

  • simon at simon period vc

    I switched mine back to port 22 for 24 hours and (using a specially compiled version of SSH) recorded what usernames/passwords the bot is trying.

    If anyone wants the list email me.

  • http://dmiessler.com/ Daniel Miessler

    Very interesting, Simon.

  • http://dmiessler.com/ Daniel Miessler

    Just add another port to the Port line in your sshd conf file.

  • http://mooism.livejournal.com DAH

    sftp respects ~/.ssh/config; you only have to put the non-standard port in that file, and ssh, sftp, etc will use it.

    man ssh_config.

  • http://mooism.livejournal.com DAH

    sftp respects ~/.ssh/config; you only have to put the non-standard port in that file, and ssh, sftp, etc will use it.

    man ssh_config.

  • http://linuxcritic.com Linux News

    A very interesting article and a very simple, yet effective suggestion. I wish more people would stop exposing themselves needelessly. As I rant, I realize that it'd be sweet if a linux distribution could randomize ports automatically for ssh during the install.
    hm.

  • Pat Niemeyer

    It would be interesting if you try your experiment again but instead of having the two ports open simply move the port to 24. I am wondering how many scripts first try port 22 and then move on to try other ports. This is probably reducing your counts a bit.

  • Pat Niemeyer

    It would be interesting if you try your experiment again but instead of having the two ports open simply move the port to 24. I am wondering how many scripts first try port 22 and then move on to try other ports. This is probably reducing your counts a bit.

  • http://twitter.com/WebDesignHero WebDesignHero

    From my own personal experience, I have no seen a difference in switching ports. I have to connect from hotels quite frequently. Obviously someone makes their living from hacking there, because when I get home I am still seeing attack on the port I selected for that week. If you just open the port, most automated attacks will use the default. If you are scanned and have banners, they will figure it out if they want. My guess is since they saw the traffic going to the particular receiver socket, they recorded it then performed their attack. In your experiment, how many connections were you making to port 24 from the public? Besides the minor annoyance of the attacker opening connections, and I had high hopes they were not going to crack my key and password.

  • http://twitter.com/Apreche Apreche

    I run SSH on a non-standard port sometimes, but I don’t have any delusions that it actually helps anything. All my SSH are key-auth only. Since every bot in the universe attempts to connect with password auth, they will never get in even if I’m on port 22. The reason I move the port is simply to make the log files cleaner, since they won’t be full of failed attempts.

    • Russell VT

      I think you discount the idea that many Internet-daemon compromises have nothing to do with successful authentication. And, as-is the case with past SSH vulnerabilities, buffer overflows can happen early-on in the protocol exchange, possibly leading to a root shell. Yeah, it’s only a stop-gap measure, but moving services like SSH to a port not normally seen/probed in a basic namp scan tends to at least keep the script kiddies away (and, as you say, keeps your logs MUCh cleaner).

  • http://twitter.com/radiosilence_ James Cleveland

    Not really, they could try millions of times and fail if you have root password disabled and fail2ban set up.

  • http://digitalflophouse.com/ Evan Kaufman

    I think it’s much simpler in the long run to just set up (for example) fail2ban, and never have to worry about what port your ssh was on or whether some other service or app will support a custom ssh port. That’s what I do for my VPS’s and I have no complaints whatsoever. Still, it makes an interesting point that an obscurity layer on top of already sound security can usually only make a good thing better.

    The only worry is that the security may fail and you may never notice because it’s already obscured. This is most likely in a situation where a system is likely to switch maintainers at some point and the new maintainer may not know all the ins & outs.

  • Bob Smith

    port 22, zero attempts. Iptables for the win.

  • http://pronto185.com Pronto185

    I change my ssh port to 443, though for a completely different reason. My school blocks outbound 22 on wifi…

  • Russell VT

    You need to pick a “better” non-standard port … preferably something not already defined on the “common list of TCP ports.” You’ve experienced more probes on 24 in a weekend than I tend to see in a year or two. Simply adding some multiples of a hundred tends to get you off the list…

    Ref: http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

    Someone submitted you to Reddit, BTW:

    http://www.reddit.com/r/netsec/comments/fnz1h/obscurity_does_changing_your_ssh_port_lower_your/

  • Arik

    The problem is that you measure the risk by the number of hits on your port.

    Perhaps the 3 hits on the non-standard port are more risky than all of the other hits combined?

    – Arik

  • Pingback: Secure SSH connection: Use another port » CactusBanana.com


Top

Popular

Information Security / Technology

Politics

Philosophy & Religion

Technology & Science

Culture & Society

Miscellaneous

Arguments

Projects

Collections

Twitter

What I'm Reading

Favorite Books and Essays

Top Blog Categories

Inputs