Slashdot Mirror


"Port Knocking" For Added Security

Jeff writes "The process of Port Knocking is a way to allow only people who know the "secret knock" access to a certain port on a system. For example, if I wanted to connect via SSH to a server, I could build a backdoor on the server that does not directly listen on port 22 (or any port for that matter) until it detects connection attempts to closed ports 1026,1027,1029,1034,1026,1044 and 1035 in that sequence within 5 seconds, then listens on port 22 for a connection within 10 seconds. The web site explains it in some detail, and there is even an experimental perl implementation of it that is available for download. I can't think of any easy ways you could get around a system using this security method - let alone even know that a system is implementing it. Another article on port knocking is here."

66 of 950 comments (clear)

  1. not bad by maelstrom · · Score: 5, Insightful

    But it does seem like a layer of obscurity to what should otherwise be a secure port. What if someone is sniffing your network? Unlike an encrypted password, they could easily replay this sequence and gain access to your "hidden" port.

    --
    The more you know, the less you understand.
    1. Re:not bad by Kenja · · Score: 5, Interesting
      "But it does seem like a layer of obscurity to what should otherwise be a secure port. What if someone is sniffing your network? Unlike an encrypted password, they could easily replay this sequence and gain access to your "hidden" port."

      And? It is still more secure. By using "port knocking" they HAVE to sniff out your network traffic and find the port combo. Without "port knocking" they just need to run nmap and see what ports they can try to attack.

      --

      "Have you ever thought about just turning off the TV, sitting down with your kids, and hitting them?"
    2. Re:not bad by LostCluster · · Score: 5, Interesting

      Think of it this way... it's an extra password combined with bonus security-by-obscurity of not having a visible password prompt.

      The "knocking ports" could also be configured that if there are random hits to the standard port without the proper knock, the system could lock down for 30 seconds and even ignore the proper knock so that if somebody's trying to brute force all the possible knocks, they'll never get feedback when they have the right one.

      Yeah, this is no substitute for properly securing the original service, but it's an extra layer that means there's even more that needs to be captured for a successful hack...

    3. Re:not bad by 26199 · · Score: 5, Interesting

      Hmm, lots of people have pointed this out, but it's easy to set up a system of one-time passwords... provided it's done in a cryptographically secure way, there's little point in sniffing for combinations.

      Of course, you can still sniff to see what ports are actually in use...

    4. Re:not bad by ComputerSlicer23 · · Score: 4, Informative
      But it's not as secure as not running SSH.

      Hence, weather or not it is secure, is all a matter of opinion. Personally, I think if you can't run SSH out in the open, you shouldn't run it thru an obscurity filter.

      We have no SSH configured on our outside network. Not with OTP, not from only allowed IP's. Not from only a specific port. Not with KnownHosts only. Not with known RSA keys only.

      You want on, you've gotta be in the building. It'd be nice to fix problems while remote, but it's just not an option because of the security problems it presents. I live within a mile of the building, specifically so not having remote access isn't a big deal. I can go from sleeping in bed, to in the building in less then 10 minutes. It's a pain for small problems. However, it's small issue in comparison to dealing with a full blown network breakin due to SSH.

      On occasion, I believe we have had someone local build an SSH tunnel that we can VPN thru onto our network. However, someone who already had access had to initiate the connection by hand with the correct IP. That's only allowed if we voice authenticate from you.

      Kirby

    5. Re:not bad by Jerf · · Score: 5, Interesting

      ignore the proper knock so that if somebody's trying to brute force all the possible knocks, they'll never get feedback when they have the right one.

      Re "brute forcing"... the number of possible knocks is (ports used for knocking) ** (ports in knock sequence). Yes, that's exponentiation.

      In fact, I'd suggest making the knock sequence much longer then in the article; ten might be good. Then, if you allocate 100 ports to the knocked and randomly select a 10 port sequence for the knocking, you get 100 ** 10 possible knocks, or 100,000,000,000,000,000,000 (100 sextillion) possible knocks.

      With just a few more ports in the sequence and just a modest investment in ports, you can make brute forcing impossible.

      (And if you mix up the ports so they aren't sequential and the attacker has to guess THOSE ports, it goes to approx. (2**16)**(number of knock), so for a 10-port sequence on potentially all TCP ports it's 1,461,501,637,330,902,918,203,684,832,716,283,019, 655,932,542,976 possible knocks, a.k.a. "way the hell more then can be brute-forced".

      (I love posting big numbers on Slashdot.)

      You need to worry about sniffers way more then brute forcers. (And as this is another layer of security, hopefully on top of an already fairly secure protocol like SSH, it's a good thing; now the 'man in the middle' has to have advanced knowlege to even know there's something to get into the middle of!)

    6. Re:not bad by platypus · · Score: 4, Insightful

      Ok, let me rephrase what I wrote in another message.

      Open ports per se are not insecure!

      The whole point behind port knocking is the wrong impression that "open" ports are more insecure than "closed" ports. This is totally bogus.
      It's about the applications behind the open ports, and it's not more complicated to write code which listens to a specific port and drops the connection if it doesn't recieve some secret number as the only payload of the first packet, than it is to write the kernel tcp/ip stack.

      That brings me to another mantra

      Kernel code is not intrinsically more secure than application level code!.

      There are many examples for buggy and overflowing tcp/ip stacks (ping-o-death comes to mind if you're somewhat older).

    7. Re:not bad by h4x0r-3l337 · · Score: 5, Insightful
      The whole point behind port knocking is the wrong impression that "open" ports are more insecure than "closed" ports. This is totally bogus.

      No it isn't. A closed port does not accept any data, therefore you cannot attack the application "behind it". A port that is open is only as secure as the application listening on that port, which AT BEST is as secure as a closed port, assuming the listening service is absolutely perfect, and has no flaws whatsoever.

      There does seem to be some confusion as to what it means for a port to be "closed", judging from most of the posts I've seen so far. You can close a port, but send "connection denied" replies to anyone trying to connect. This makes the port itself safe, but tells the attacker that there is in fact a machine there on the network (which could be a reason for an attacker to continue to probe and/or attack you in other ways). You can also close the port by not responding to anything directed at it at all. If *all* of your ports are like this, an attacker won't even know if your machine is turned on or off, or if there's even a machine there at all. In a way, you've become invisible. Ideally, that's what you want. Port knocking is simply a way to allow your machine to be invisible while still being able to initiate connections to it from arbitrary IPs.

    8. Re:not bad by Anonymous Coward · · Score: 4, Informative

      It is a common misconception that an attacker can't tell a system which doesn't send reject packets from a system which is disconnected/off. This is not true. The difference lies in the reply from the next hop router. An existing system will not cause a response from the router, but you will get a "Destination unreachable" ICMP packet from said router if the target system is offline. This is because the router times out the target system's ARP entry and then, when the router needs to reach it, can't find the target if it is actually offline. A connected system cannot not answer arp requests (or it doesn't get its packets), so the router always knows where to send the packets and doesn't return "destination unreachable".

    9. Re:not bad by pclminion · · Score: 5, Funny
      In a way it does. It firsts asks for a username, and then a password. If one of them is incorrect, you don't get access. But SSH doesn't tell you which one was incorrect.

      This reminds me of a cgi driven website I visited a loooong time ago (1996?)

      I was creating a user account, and was using the password "beelzebub". However, the system refused to let me create the account. It displayed a page which stated "That password is invalid: It is being used by another user. Please select a unique password."

      Apparently, some genius thought it was good security to ensure that no two users had the same password. I hope you can see the intrinsic flaw in this :-)

  2. My idea by Catskul · · Score: 4, Interesting

    I though about this along time ago as a way of hiding a trojan. Of course I didnt patent it so no money for me : /

    --

    Im not here now... Im out KILLING pepperoni
  3. Easy enough... by wishus · · Score: 4, Insightful

    I can't think of any easy ways you could get around a system using this security method - let alone even know that a system is implimenting it.

    Sniffing.

  4. Worse? by glpierce · · Score: 4, Interesting

    Right now, script kiddies have their computers automatically try to access other peoples' computers, looking for ones without firewalls, etc.. If this happens, wouldn't you expect them to just send out random knocks in the hopes of getting something? If that happens, you will be more secure personally, but the increased traffic may cause more problems that it solves.

    --
    G
  5. Knock knock... who's there? by bc90021 · · Score: 4, Funny

    Knock knock...

    Who's there?

    Usher.

    Usher who?

    Usher wish I could SSH to your server!

    Sorry... ;)

  6. Before you complain about "Obscurity" by pclminion · · Score: 5, Insightful
    This adds a layer of obscurity to a security policy. It can't substitute for security, but it certainly can help.

    An analogy would be a military base with a ten-foot-thick steel blast door. This is like having a door that teleports around at random, which can only be frozen in one spot by speaking some magic word. Even if you know the word, you still don't have the key to the door. But if you do have the key, you still can't get in without the magic word because the door keeps teleporting around.

    Obscurity is great, if it is part of a layered security policy which is ultimately based on strong cryptography. This is a really cool idea!

  7. Old stuff by Britz · · Score: 5, Funny

    That is a very old method i developed with my friends. We would only open the door after a "secret" knock sequence. We had seen this on TV and thought this would be cool. We jeopardized the security regularly when we said "wrong knock" after someone else knocked. Usually parents. Then they would say "open up". And we had to comply.

  8. I see an easy way by Apreche · · Score: 4, Insightful

    There is an easy way around it. The problem is you will make yourself very obvious. Simply pick a time at which the server in question is in high use. Hammer the port. Eventually someone will knock on the door opening it for 10 seconds and you put your foot in the door before they do. The other way is if you can get a packet sniffer simply look at the packets that came before and determine the secret knock.

    This is still an interesting idea and definitely has at least a few places in which it would be an effective authentication mechanism.

    --
    The GeekNights podcast is going strong. Listen!
  9. Slashdotted? by Fulkkari · · Score: 5, Funny

    Is the site slashdotted...

    ...or do I have to knock my way in?

    --
    I demand the Cone of Silence!
  10. Re:Password by 26199 · · Score: 4, Insightful

    Except it hides that the port is open at all, which is useful.

  11. Silent Bob by Sanity · · Score: 5, Informative
    A few years ago Freenet implemented something similar to this called "Silent Bob". The name comes from Alice and Bob, the names given to sender and receiver respectively when describing cryptographic protocols.

    The idea was that you didn't want to disclose that you were running a Freenet node unless the person connecting to you already knew your node's public key.

    So when someone wants to establish a connection to you, they must send some encrypted data providing they know your public key. Your node can receive this data and only respond if it is correct. Furthermore, you could let your Freenet node sit on port 25, for example, and forward invalid connection attempts to a mail server on a different port.

    Through this mechanism, your Freenet node could quite effectively hide behind another server, only making itself known to those already part of the Freenet network.

    IIRC this wasn't actually implemented in Freenet, but it is the intention to add it at some point. Still, it is amazing how many ideas were pioneered by Freenet years ago and are only showing up in the wider public conciousness now.

  12. NOT security through obscurity by 3Suns · · Score: 5, Interesting

    It should be noted that this is NOT (necessarily) an example of security through obscurity. One could treat the port-knocking sequence as a "key". Long enough keys could make port-scanning impossible for anyone who doesn't know the key. Real mathematical cryptography is based on a similar principle.

    Also, this is only a defense against port-scanning. Even if someone did manage to break the knocking sequence, they would still have to use some kind of exploit against the machine on the port they discovered.

    --

    -3Suns

    ~~~~
    The Revolution will be Slashdotted
  13. Old Idea, Different Use by jsonic · · Score: 5, Informative

    The shady side of hackerdom has been using this very technique to hide their backdoors from port scanning admins. Or, uh, so I've heard...

  14. Not good by glpierce · · Score: 5, Insightful

    "The "knocking ports" could also be configured that if there are random hits to the standard port without the proper knock, the system could lock down for 30 seconds and even ignore the proper knock so that if somebody's trying to brute force all the possible knocks, they'll never get feedback when they have the right one."

    That would just create a new variant to DOS attacks. Instead of taking you offline, they just persistantly knock on random ports, thereby disabling your ability to communicate with trusted sources.

    --
    G
    1. Re:Not good by theLOUDroom · · Score: 4, Informative

      Host 'a' (the server, 192.168.0.1) requires the correct knocking combination to allow access. Host 'b' (random knocker, 192.168.0.2) knocks on random ports attempting to cause a DoS. Host 'a' detects the wrong ports being knocked on and does not grant access from host b Host 'c' (geniune client, 192.168.0.3) knocks on the correct ports, host 'a' allows access from host c (192.168.0.3/32). Host 'b' can continue knocking on random ports, but at the same time, host 'a' does not grant access from the misbehaving host b, but it doesn't have to revoke access from host c either.

      So how does this cause a DoS?


      The ports being knocked are closed. This means that the server can never veify the the knocks coming from 192.168.0.3 are really coming from there, or if they're coming from 192.168.0.2.

      If the server is .1, I'm .2 and you're .3, I just keep knocking ports at random spoofing my ip to say that I'm .3 You can't IP block me, and my knocks look just like your knocks. This keeps screwing up your login and you can never open the connection.

      --
      Life is too short to proofread.
  15. Possible problems by Mr.+McGibby · · Score: 4, Interesting

    What if multiple attempts from the same IP are made to access the port at the same time? Wouldn't the knocks get all mixed up?

    --
    Mad Software: Rantings on Developing So
  16. Reverse-knock by Seft · · Score: 5, Interesting

    Has anyone implemented a system where a service would be stopped if the ports next to it were scanned? i.e. if 1024, 1025, 1026, 1027 were scanned, a service running on 1028 would stop.

  17. Security through obscurity by Dominic_Mazzoni · · Score: 5, Insightful

    As everyone else is saying, this is just security by obscurity. That doesn't mean that you shouldn't use it, because it probably would help a lot in keeping out script kiddies and casual hackers. But the flip side, as always, is that you're giving yourself and your users a false sense of security when you pretend that measures like this will actually prevent motivated hackers from getting past it.

    The most obvious way to break into a system like this is to compromise a nearby machine first and install a packet sniffer. Once you can see the traffic to the host running this port knocking system, it would be easy to discover the pattern. In fact, port knocking is less secure than a lot of other nonstandard authentication mechanisms because you could figure out the secret simply by looking at packet headers (since they contain the port numbers).

    The other problem I see with this system is that it requires users to either memorize the secret knock, or use a program that automatically knocks for them. Since most people have a hard time even remembering all of their usernames and passwords, you'd see a lot of people writing down the knock, sending it via email, or writing scripts to knock for them. Dozens of opportunities to a hacker, especially one skilled in social engineering, to figure out the knock.

  18. Not the point by s20451 · · Score: 4, Insightful

    come on kids. Have we not learned our lessons? Even as a one time pad, this is lame

    You are very much missing the point. Yes, security through obscurity is terrible when it is the only security method you use. However, it can be used to augment a better security system. Even if somebody figured out the secret knock, they would still have to get past your sshd. And if an sshd exploit was found, your secret knock might give you enough time to patch the system before it could be exploited. More security is always a good thing.

    Disbelief in security through obscurity doesn't mean you have to paint a bull's eye on your head and dare people to attack you.

    --
    Toronto-area transit rider? Rate your ride.
  19. hmm... by Kitsune · · Score: 5, Interesting

    Improperly done, the knock sentry could become a security/QOS issue in itself.

    This definitely is security through obscurity and perhaps would work in the same way as a car alarm. There's lots more systems out there that are easier to break into, and if someone does try, just hope that they get fed up and moves on to the next one.

    If you've gone this far, why not do something like they do on radio. Open up severable ports at the same time and multiplex your signal over several of them while sending noise over the ununsed ports randomly switching between ports using a syncronized random selector.

  20. go a step further by Casca · · Score: 5, Interesting

    Implement it in combination with a onetime type password arrangement. You look up what the series of knocks is supposed to be on your secureID card (or whatever), then knock in the combination it tells you to use. Tie it in with the server you want to get into, and the port you actually connect to for ssh can be different every time.

    IE, secureID says sequence is "1234 1441 1114 5123", you knock on the first three, and 5123 is the ssh port activated for you only.

    --
    Casca
  21. Re:Brute Force by HeghmoH · · Score: 5, Informative

    Somebody do the math, but it doesn't look to be that secure. Brute-forcing this would not take long.

    Assuming a 5 'letter' password, you have (2^16 - 1024)^5 possible passwords, which is 1.1 X 10^24. Assuming both the server and the attacker are on fat pipes and the server is implemented in a dumb way so that it doesn't recognize brute-force attempts, you could pull off perhaps 100 attempts per second. So it would take you about 10^22 seconds, or 350 trillion years.

    In security, I think this technique is comparable to a reasonably strong plaintext password. It can be sniffed, but it can't really be brute-forced.

    Today's show was brought to you by Google Calculator.

    --
    Mod down posts with a "Free Mac Mini/iPod" sig, they're spam!
  22. Re:Well, there go the logfiles by aldousd666 · · Score: 4, Interesting

    It doesn't have to be listening on the 'knock' ports, it can be dropping the packets and either logging the drop or setting a flag via some daemon. There are a million ways to tell if someone attempted to access a closed port without having to open the port. All of this, by my calculation, makes port knocking indeed more secure.

    --
    Speak for yourself.
  23. Obscurity IS Security by CedgeS · · Score: 5, Insightful

    There is only one form of security for a publicly accessible interface: obscurity. What is a password? It is a piece of information that you know that someone else doesn't - it is obscurity. The key to your house is something you have that someone else doesn't. If they knew the obscure details of your key they could make one. What is a private key, a key for SSH, a kerberos function? They are all information you know which (hopefully) a potential attacker doesn't. This is obscurity.

    If you have a security system for a public interface (the front door to your house, a computer port, etc...) that does not rely on obscurity you have a system better than any theoretical system anyone has ever thought of. (Biometrics don't count - they are just another piece of information that you have that someone else probably doesn't. That's obscurity.)

    1. Re:Obscurity IS Security by cheezit · · Score: 4, Insightful

      I think you are overreaching here. As far as I'm concerned, the phrase "security through obscurity" means obscurity of system design. If you don't tell anyone about your unprotected resource, that's security through obscurity. All I need to do is discover your resource.

      Most security is based on secrets of one kind or another---that doesn't make it "obscurity."

      --
      Premature optimization is the root of all evil
    2. Re:Obscurity IS Security by Xenographic · · Score: 4, Insightful

      We usually call such a thing a secret, not "obscurity" ... at least, when talking about a password.

      So this just makes part of the protocol secret, and one of our assumptions about security protocols is that the protocols are known.

      Yes, it's an interesting and reasonably clever little hack (it is not, however, new), it does tend to hide some information (e.g. that the ports are even open) but if you're going to make the port look closed, anyhow, why not just listen on that port for something that would cause the service to "wake up"? I guess they thought it seemed a bit more clever the other way, who knows?

  24. Re:Well, there go the logfiles by RollingThunder · · Score: 5, Interesting

    Actually, an interesting potential of this is to have you "knock" at the NAT gateway. Proper knocking opens up a given service and knock ports to an internal system.

    Different knock patterns at the NAT open you to different internal hosts. Quite interesting possibilities there.

  25. Re:Well, there go the logfiles by Mod+Me+God · · Score: 5, Interesting

    That is the point.

    1. Many ports getting a sequence is much more like noise than one port getting it -> much harder to identify an attempt of intrusion.

    2. If you have a backdoor, as mentioned in the article, how will you know it has not been accessed? It was not listening, it gets activated, does its duty, deactivates. If it is a good backdoor it is invisible to that system (only visible though an additional layer).

    So it is a better way of getting a connection, but not a solve-all for the intruder, and I doubt the intruder cares about any waste of your resources.

    --
    --

    FreeNET user? Comfortable with the adverse selection?
  26. Knock Knock Honey Pot by ifreakshow · · Score: 5, Interesting

    One interesting way to use this would be to forward incorrect knocks to a honeypot instead of the legitamite service. Then the attacker could never determine if he had indeed knocked successfully and would waste time running around in a fake system giving you valuable data about there intrusion methods and freeing up the actual service for legit users.

  27. Christ people! by Stonent1 · · Score: 4, Informative

    How many people are going to say sniff and repeat the sequence. You still have to get through the service after it opens. The whole point is that they don't know what is going on in the first place. And rotating keys are a good idea anyway. I like this idea for running some kind of server behind your ISP that normally doesn't allow such things. When I had excite@home I would regularly get firewall logs that said "authorizedscan.home.com" portscanning me.

  28. Re:Well, there go the logfiles by pegr · · Score: 4, Informative

    Any good admin knows the most secure system is one that is listening on as few ports as possible.


    Is zero secure enough for you? The ports used for knocking are not open. The knock is the connect attempt which is recorded as an event on the server. The client gets nothing, not a NAK not a reset, nothing.

  29. This was discussed extensively... by amplt1337 · · Score: 4, Informative

    on debian-security a couple of months back.

    Anyway, one of the biggest problems is failure rate. If that "secret knock" fails unless you correctly use the appropriate sequence of knocks, then anyone malicious can implement a trivial denial-of-service attack just by constantly hitting random ports, preventing any knock completion.
    Alternatively, if you ignore non-knockable ports, or ports that aren't part of the knock, then you've dramatically whittled down the strength of your virtual password, and made it that much easier to brute-force.
    Perhaps this would deter some of the lowest levels of sk|21p7 |<1dd13z from getting in, but that would be true only for about two weeks, whereupon new toyz are released that automate these attacks, and you've given the black hats one more weapon (DoS through spoofed noise packets) in the meantime.

    I guess if you really, really wanted to do this, you could have a single accessible port that would listen for access, and then receive an encrypted key that determines which other port your server opens for a possible connection. But basically all you're doing then is adding on another layer of password protection, whose effect will be circumvented when somebody finally decides it's annoying to have to login twice or enter multiple passwords, and sets them both to the same thing, on auto-login, then leaves his laptop sitting around for three minutes. And you've still not fixed the sniffing problem. There are bigger security soft spots to be addressed than trivially hiding access to your ssh port.

    --
    Freedom isn't free; its price is the well-being of others.
  30. Re:Equivalent to a password by pla · · Score: 4, Interesting

    This is equivalent to to putting a password on access to the port.

    This seems much better than a password, I would think (Though I certainly would still use a password as well).

    As an analogy, if you want to get into a house, and find a locked door, you have a few options... You can try one of those M x N position key blanks, which will take a very very long time (exhaustive search). You can try to pick it (exploit a weakness in the password algorithm). You can try to get ahold of a copy of the real key (packet sniffing, "shoulder surfing", etc). But you have no doubt that somewhere, a key exists that will open that door.

    Now compare that to a solid block of concrete, roughly the size of a house. What does it do? Do helicopters land on it? Does it cover something, or hold something down? Does it have something sealed inside it? You'd never suspect that that, if you utter the magic phrase "Sim sala bim bamba sala do saladim", a door will appear in the side of this large concrete block, allowing those with a key to gain entrance.

    The main difference involves knowing whether or not a way in exists. With just a passworded port, an attacker knows that enough effort will pay off. Adding in port knocking, that attacker doesn't know whether or not their hard work can ever gain them entrance, since a port might well not exist.


    Now, in my opinion, the more interesting question here involves how to hide this from one's ISP (ie, make it snoop-proof).

  31. freq. hopping analogy- by Samuel+Nitzberg · · Score: 5, Interesting

    This looks similar to how frequency-hopping is used on secure radios.

    Two radios synchronize, based on a key, and both change frequency every so many milliseconds. If you don't know the key, you can't send or receive to either of them.

    I would like to see this extended to a port-hopping system for all ports and services. Sure -- it will burn some clock cycles, but I like the approach.

    - Sam
    http://www.iamsam.com

  32. Re:Well, there go the logfiles by Esion+Modnar · · Score: 4, Insightful
    Actually, I think this article has been one of the most "nerd-worthy" postings on Slashdot in quite a while...

    And yes, one the most annoying things about sitting behind a NAT is only being able to forward a port to a single host at a time. This would be great if "port knocking" could solve this, though in a very Rube Goldberg fashion.

    --

    They say the first thing to go is your penis. Well, it's either that or your brain. I forget which...
  33. Neither. by khasim · · Score: 4, Insightful

    #1. DoS attacks - how is this different from any other DoS attack?

    #2. Sniffing the port knocks - to do this, you would already have to have the upstream compromised or be on some shared network.

  34. Re:Open a whole range of ports by ViXX0r · · Score: 5, Informative

    The summary says that the ports to knock on are closed. Portscanning shouldn't reveal which ones are available to be knocked on.

    --
    University - a box of academia nuts.
  35. not so shady... by Hubert_Shrump · · Score: 4, Interesting

    i've been running SSH on a nonstandard port with this in the way:


    iptables -N ${SSH_TABLE}
    iptables -Z ${SSH_TABLE}
    iptables -A ${SSH_TABLE} -m state --state NEW -m limit --limit 2/minute --limit-
    burst 2 -j DROP
    iptables -A ${SSH_TABLE} -m state --state NEW -m limit --limit 7/hour --limit-bu
    rst 7 -j DROP
    iptables -A ${SSH_TABLE} -m state --state NEW -m limit --limit 10/day --limit-bu
    rst 10 -j ACCEPT
    iptables -A ${SSH_TABLE} -j DROP


    well, I thought it was cool...

    --
    Keep your packets off my GNU/Girlfriend!
  36. Re:Well, there go the logfiles by diablobynight · · Score: 4, Interesting

    does it only open the port for that one IP somehow, using also advanced IP filtering, cause otherwise this is dumb, it would be like unlocking your door for the first customer to knock right, but having to leave it open the whole time the customer is shopping.

    --
    Anonymous Cowards - Oh God, How I hate you
  37. Re:Open a whole range of ports by lactose99 · · Score: 4, Insightful

    That depends on the NAT gateway, as per the original poster. If the NAT gateway is dropping all packets that aren't part of a) valid incoming connections or b) a port knocking scheme, a portscan would reveal some or all of the ports utilized in the port knocking scheme. Ports that are closed but part of the knocking scheme would return a connection refused, while all the other (filtered) ports would simply be dropped.

    Granted, most anyone implementing this sort of security setup on their firewall would most likely think about this and either a) open an entire range of ports, only some of which would be used for port knocking (as a previous poster mentioned) or b) simply close everything at the NAT gateway and not drop any packets, thereby not revealing any detail regarding a port knocking scheme.

    I'm sure there are several other ways to deal with this at a NAT gateway, but they just aren't coming to mind at the moment.

    --
    Fully licensed blockchain psychiatrist
  38. Re:Promiscuous mode by _Sharp'r_ · · Score: 4, Informative

    Most switches have, uhh.... "features" that allow an experienced attacker to trick them into broadcasting traffic to multiple ports.

    Essentially, with a little judicious arp spoofing and a flood or two, the switch can be confused into just "making sure" the packets get to the right destination by broadcasting like a hub when it would normally be switching.

    --
    The party of stupid and the party of evil get together and do something both stupid and evil, then call it bipartisan.
  39. Services listen on ports. by khasim · · Score: 4, Insightful

    It isn't the port. It's the service listening on that port.

    If the port is closed, then it is impossible to attack that service through that port.

    This process closes those ports.

  40. Re:Well, there go the logfiles by S.Lemmon · · Score: 5, Interesting

    That doesn't seem right. If the order of the knocks is important, how do you get around that there's never a guarantee in what order network packets arrive? If no packets are sent back at all, how do you know when to send the next knock or even if the knock made it to the server?

  41. TCP/IP problems with this method. by Vellmont · · Score: 4, Informative

    Everyone has focused on the "does it make you more secure" arguments about this method. I'd be more interested in how it can be implemented properly since no TCP connection is being established using the knocks. I'd assume either a TCP SYN is being sent to the TCP ports, or the protocol uses UDP.

    The problem is of course that since no connection is being established, there's no guaranteed delivery of packets, and no guaranteed delivery of packets in the order they were sent. This could be very problematic across network connections that drop packets, and provide you no feedback as to why you can't open your connection. If only 10 % of my packets get dropped, and I require 10 "knocks", I only have .9^10, or 35% chance of my sequence getting to its destination intact. 5% packet loss would up my chances to about 60%. Increasing amounts of knocks decreases my chances of the sequence arriving intact.

    Is there a clever way to solve this problem, or is the reliability of it tied to a low amount of packet loss on a network?

    --
    AccountKiller
  42. Re:Well, there go the logfiles by 3.1415926535 · · Score: 4, Insightful

    How about, "Yeah, NAT breaks stuff, let's fix it" instead?

  43. It's _not_ just another password... by jdreed1024 · · Score: 4, Interesting

    I see a lot of comments saying "Well, why not just have two passwords?". It seems that people didn't read the article (the first link is /.ed, the second is not). The whole point is that with this, until you knock, the machine appears as a closed machine. No ports open. All ports will simply drop packets on the floor, meaning that a hacker scanning your subnet will not bother with that machine. The machine essentially appears invisible until knocked. Even with the most secure system, the hacker can still see that you're running, say, sshd, Apache, CUPS, and a few other services. And if a buffer overflow was announced 5 minutes ago for, say, sshd, they know that they can attempt to exploit the machine, since they see port 22 open. If you are using Port Knocking, you can have a vulnerable sshd, and it's a hell of a lot less likely to get exploited since the cracker has no way of knowing that you're running sshd...

    --
    There is no sig, there is only Zuul.
  44. Stop complainin about "security through obscurity" by Tom7 · · Score: 4, Insightful

    God damn, if I hear one more of you go, "this is just security through obscurity!" I am going to puke. This is the same as cleartext passwords, which are pretty secure if (a) you know nobody is sniffing the network and (b) you know nobody is masquerading as the host you want to connect to. Of course those things aren't typically true, so this alone isn't very secure. But it does disguise your exchange which, contrary to what the security-through-obscurity folks are saying, does give you some small measure of security.

    This is just a way of encoding some bit transfer in the IP protocol instead of in the beginning of whatever protocol you're using after the connection. You could also use it to send cryptographic credentials which could be as secure as any other protocol (plus some extra security by obscurity). The only problem with that is that you need a way to send back information via TCP (because most good authentication protocols are two-way), but I think you need that anyway in order to serialize your knocks.

  45. Re:Well, there go the logfiles by Smidge204 · · Score: 4, Insightful

    Or other problems to be seen, also now hackers won't just port scan me, they'll port scan me a trillion times, trying to find the right combination to open my ports.

    And what stops them from brute-forcing regular password protected access on a known port?

    1) You don't know how many ports are in the knock sequence
    2) You don't know that the range is
    3) You don't know what port will open when you get it right

    Similar to a password, only instead of base 94 (a-z,A-Z,0-9`~-_=+\][|}{';":/.,?>million trillion trillion trials to crack. Then you have to do one more scan to figure out which port actually opened after each trial and hope no other service opened a port for some unrelated reason.

    I'm thinking it's a tad more secure than password authentication alone... and you can always throw password auth in after the client connects, so you can throw in a few false-positives (bogus logins) to keep them busy.

    And a five second window to transmit the sequence is pretty generous. If you wanted to harden it even more against brute forcing, you could require a full 5 second wait and accept all connection attempts from a particular host. That would limit an attacker to 20 attempts per minute max. So it'll take the better part of 32 billion trillion years to crack it.

    At that point, you can consider the end of the universe as "The ultimate connection timeout"
    =Smidge=

  46. All the time the same arguments by phoenix321 · · Score: 5, Interesting

    This is security by obscurity, but it is useful. Don't repeat this mantra just because "the experts" say so.

    Since some still don't understand its use, i'll be speaking metaphorical:

    Assume you need to have a special key to open a certain otherwise secure door. OpenSSH might be that door and your passphrase and your certificate are the key.

    An attacker can still forge the key or attack the lock with a different approach, picking etc. - comparable to "social engineering" to get the password, brute forcing or exploits.

    And that port knocking sequence now effectively hides the lock, leaving an attacker without a first approach to pick or break the lock. It just adds another layer of security. You just don't know where to start your attack. You can't use exploits, you can't try brute force - nothing, heck you don't even know what type of daemon your target is.

    A clean stainless steel door with a covert RFID-detector one square inch in size, hidden somewhere, sure as hell beats the same door with a clearly visible lock. You still need to pick the lock, but you can't poke your lockpicking tools into solid steel and you can't crack something you cannot discern.

    --- Still one addition to say: having a machine connected to the internet with no ports open makes you a prime suspect for the port knocking scheme.

    A good stealth scheme may be implemented, so a potential attacker (excuse for this metaphor again) does not even see the door (or the building, for that matter).

  47. Re:Open a whole range of ports by blazerw11 · · Score: 5, Insightful

    That depends on the NAT gateway

    No, the gateway or direct host has ALL PORTS CLOSED, however it does log port requests. If the log shows the knocking sequence, then and only then, will it open a port.

    --
    A great many people think they are thinking when they are merely rearranging their prejudices. -- William James
  48. I did this about 5 years ago by Skapare · · Score: 4, Interesting

    I did this about 5 years ago. But my method was a bit different. Instead of using port numbers to contain the information (and that's all it really is, is just information), I sent a single UDP packet, with a source port of 53 (so it looks like a DNS answer), formatted like a DNS answer, that contained the information in the DNS answer data. Then it opened the SSH filter for that IP address to come in (I did it for 5 minutes, not 10 seconds). It still had to fully authenticate via SSH, so even if someone sniffed my DNS packet and tried to fake it, they could at most have a locked door to jiggle the handle on. Next time I do this, it will be to generate an MD5 checksum from the client IP and a secret salt, and send that as an IPv6 address in the packet. Then it can't even be faked from some other IP address.

    --
    now we need to go OSS in diesel cars
  49. Counter Proposal: Port Traps by henrypijames · · Score: 5, Interesting

    What if I turn this whole thing around and install fake services on a number of ports?

    For example, whenever you make a connection to a port between 1025 and 2048 on my system, you're greeted with "OpenSSH ...", and prompted to authenticate. But only behind one among those 1024 ports is the real SSH. On any other port, the fake service takes the username and password you've entered, wait a few seconds (just idling around), and tell you "Authentication failed". If you try too often to connect to faked services, you're put on the black list to avoid DOS, of course.

  50. Re:Well, there go the logfiles by WNight · · Score: 4, Interesting

    You can also open up inbound ports from specific external IP addresses only, and do many at once. So ten inbound connections can reach ten different internal webservers, and at the next request, reach the same one again.

    This can be done dynamically as a form of load balancing which is a neat hack. Expire the specific forward rule after 30s or something. Means similar requests cluster - less DB traffic.

    But, combine this with knocking and you've got the next step. Secret services on a 'stealthed' IP, where you can request which quake server (for instance) by knocking in a different way.

    Port scanning isn't what it once was. Especially once you factor in time-sensitive keys (easily doable - both machines need a net connect to reach each other, ntp is then trivial) and ID-sensitive keys (so my key isn't like yours, even at the same time). Even if you managed to snoop on a 'knock' you couldn't repeat it.

  51. Re:Well, there go the logfiles by smeenz · · Score: 5, Informative
    When a port is 'open', that means there's a process listening for connections on that port

    When a process is listening for new connections, it doesn't block existing connections from carrying on sending and receving data

    When a port is 'connected', it means that a process has an established connection to another host.

    Therefore, no, just because a port is not listening/open, doesn't prevent an existing connection from sending and receiving data.

    If that was the case, then the first person to telnet/ssh to your box would tie up that port and a second connection would be blocked until the first had freed up the port, however that is not what happens at all.

    All they're saying is that when the portknocking daemon detected the correct knock sequence on closed ports, it starts a process to LISTEN for new connections, ideally from just the host that did the knocking, for a limited period of time (10 seconds). Once a TCP connection is established with the listening host, that host no longer needs to listen, and that's why it stops after 10 seconds.

  52. encoding for noise rejection by firewood · · Score: 4, Interesting

    This is a great idea.

    It adds security to any existing methods (passwords, etc.).

    It can be implemented behind a firewall that doesn't even respond on any port probes, so an attacker can't even tell if the firewall was just unplugged.

    If the firewall stays closed, the protocol can't be used by an exploited machine, unless a method for exploiting the firewall is also known.

    Or the method can be implemented in user space of a machine behind a completely closed firewall, just by pre-arranging for the logging of firewall port probes, and the forwarding of appropriately filtered contents of the firewall logs into user space.

    They key sequence can also be made long enough to make it just as hard to crack as a long pgp private key, e.g. nobody except (3 letter agency) and distributed.net will even bother to try.

    The sequence key can be from a one-time pad, meaning that even if the protocol is completely revealed to a local sniffer, they'll just end up with a useless password.

    And lastly, it's possible to additionally encode the key sequence with a modulation wrapper and enough redundancy to withstand a given signal to noise ratio and mis-sequencing rate, which means one could even make the sequence key usable in the face of probing or an outright DoS attack against the protocol up to a certain attack bandwidth and knowledge of which ports might be in the sequence.

    Where's my coding textbook and patent attorney...

  53. security through obscurity? no sorry by wolfdvh · · Score: 5, Informative
    For all of you arguing that port knocking is security through obscurity, please take a couple minutes and read this article from the site:

    http://www.portknocking.org/view/about/obscurity

    It does a much better job of explaining this than anything yet posted here.

  54. Re:Open a whole range of ports by Bill+Privatus · · Score: 4, Interesting

    Sorry, wrong. There are several messages in this thread that mention REJECT (response to packet) instead of DROP (total silence). With this scheme in place, you need not listen on *any* ports, and you need not respond in any way. You can have a totally silent box, even with 10 or 20 services "listening". Nothing gets through until your iptables/ipchains software allows the traffic through.

    Admittedly, if you're running a public site, you're mixing two kinds of solution --- publicly available vs secured, but analogous statements can be made here - you can't tell a public site using port knocking for some special services from a public site that doesn't support same.

    This is like a void fn() in C (no return status). You knock on the 5, 10, or 25 ports in the right sequence to "send your message". You get nothing back. You then try to open the port that is your ultimate destination - if it's open, you're fine, if it's not, you have issues. This isn't a full-duplex kind of protocol, folks. I love it :-)

    Thus, it is impossible to distinguish a totally silent box (listening on no ports, dropping all packets) that has implemented port knocking from a box that is merely totally silent.

    As a two-laptop user who attaches to corporate LANs and public high-speed networks in hotels, I just love the idea of having all packets dropped until someone sends "shave & a haircut!" - then letting them in for a bit.

    It would certainly be better than my current approach - using ethernet addresses (maclist in Shorewall! :-) to allow ftp and http etc to my linux box.

    --
    Redundancy is good; triple redundancy is twice as good! - Me.