Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Software Security The Internet

Port Knocking in Action 430

tyldis writes "There was something called "port knocking" mentioned on Slashdot earlier, and now an implementation has sprung to life. Is this something worth pursuing?" The page is to an application called knockd which is a simple proof of concept with hard coded knock sequences. Really interesting stuff.
This discussion has been archived. No new comments can be posted.

Port Knocking in Action

Comments Filter:
  • Knock Knock? (Score:4, Informative)

    by qualico ( 731143 ) <worldcouchsurfer@@@gmail...com> on Wednesday April 14, 2004 @05:58PM (#8863791) Journal
    Who's there?

    Just a bunch of hackers knocking with sequences they captured from sniffing.
  • by caluml ( 551744 ) <slashdot@NosPAM.spamgoeshere.calum.org> on Wednesday April 14, 2004 @06:03PM (#8863842) Homepage
    I fear the ISP might just watch for large amounts of data spewing out on tcp/20.
  • by Dwedit ( 232252 ) on Wednesday April 14, 2004 @06:04PM (#8863855) Homepage
    In QBASIC:

    s$ = "shave and a haircut"

    FOR i = 1 TO LEN(s$) STEP 2
    IF i LEN(s$) THEN
    PRINT ASC(MID$(s$, i, 1)) * 256 + ASC(MID$(s$, i + 1, 1))
    ELSE
    PRINT ASC(MID$(s$, i, 1))
    END IF
    NEXT

    Output:
    29544, 24950, 25888, 24942, 25632, 24864, 26721, 26994, 25461, 29544, 24950, 25888, 24942, 25632, 24864, 26721, 26994, 25461, 29544, 24950, 25888, 24942, 25632, 24864, 26721, 26994, 25461, 116
  • by Anonymous Coward on Wednesday April 14, 2004 @06:07PM (#8863885)
    2093, 1568, 1568, 880, 988, 1568, the frequency of the pitch of the notes.
  • by frobisch ( 630854 ) on Wednesday April 14, 2004 @06:08PM (#8863901)
    is pasmal [sourceforge.net]
  • Re:Multiple kocks (Score:4, Informative)

    by aWalrus ( 239802 ) <sergio AT overcaffeinated DOT net> on Wednesday April 14, 2004 @06:09PM (#8863911) Homepage Journal
    Well, the knocks do come from the same IP, so this thing just needs to be able to see that to filter different knock sequences, I guess.
  • by bwhaley ( 410361 ) <bwhaley AT gmail DOT com> on Wednesday April 14, 2004 @06:11PM (#8863929)
    Lots of info available via a google search [google.com]...

    A few implementations [portknocking.org] here.

    I don't think will be very useful/valuable until clients (such as ssh) have it built in. I don't feel like going through the hassle each time I want to connect. Though it would keep comcast from discovering my ssh service...

  • by Dr. Zowie ( 109983 ) <slashdotNO@SPAMdeforest.org> on Wednesday April 14, 2004 @06:13PM (#8863945)
    The problem here is that the ``password'' (the port knock sequence) is sent in plaintext. Anyone with a sniffer anywhere between you and the other machine can see what you're doing. If this ever catches on, any L337 |1dd13 with half a rootkit will be sniffing for anomalous port-requests, and you'll be just as hosed as if you logged on via telnetd.
  • portknocking.org (Score:5, Informative)

    by trip23 ( 727132 ) on Wednesday April 14, 2004 @06:13PM (#8863955)
    You'll find some more stuff on http://www.portknocking.org [portknocking.org]...
  • no (Score:1, Informative)

    by Anonymous Coward on Wednesday April 14, 2004 @06:15PM (#8863979)

    No, the knock-sequence itself is no more secure than a plaintext password. So using it for access to ssh is no more secure than simply using ssh alone.

  • Re:Knock Knock? (Score:5, Informative)

    by timeOday ( 582209 ) on Wednesday April 14, 2004 @06:17PM (#8863989)
    Not unless they can get into a router on the path between you and someone valid who logged in, or the same ethernet segment.
  • Re:no (Score:1, Informative)

    by Anonymous Coward on Wednesday April 14, 2004 @06:18PM (#8864006)
    It prevents people from doing evil things to your sshd.
  • Re:ISP Port-Scanning (Score:2, Informative)

    by meme_police ( 645420 ) on Wednesday April 14, 2004 @06:18PM (#8864010)
    That would be a benefit. Those using port-knocking for extra security are misguided, though.
  • Re:Multiple kocks (Score:3, Informative)

    by JPriest ( 547211 ) on Wednesday April 14, 2004 @06:22PM (#8864054) Homepage
    The nimrod that modded this as insightful need to go back and read TCP/IP for dummies. They knock from different IP addresses, and even in situations where 2 hosts are knocking from the same IP (behind NAT) you still have a different source port.
  • Sorry Wrong URL (Score:2, Informative)

    by image53 ( 543653 ) on Wednesday April 14, 2004 @06:23PM (#8864058) Homepage
    Can you tell I don't post to blogs much? Port Knocking [desktopappliances.org]
  • by Anonymous Coward on Wednesday April 14, 2004 @06:26PM (#8864100)

    Generate a knock sequence that includes (a) some random data and (b) the same random data, but encrypted by a key that only you have.

    Have knockd decrypt the encrypted part and make sure it's the same as the random data.

    Have knockd keep track of what random data has been used, to prevent replay attacks.

    Highly unlikely you'll generate the same random data twice. But an eavesdropper cannot replay your key, and cannot generate random knock sequences either.

    You could also set up error-correction in case somebody blocks one of the ports you're using for knocking.

  • Re:knock-knock (Score:1, Informative)

    by Anonymous Coward on Wednesday April 14, 2004 @06:28PM (#8864118)
    > This is an interesting idea, but not very secure. If there was,
    > for example, a need to "knock" a server to activate some sort
    >of access control, then anyone can send the TCP/UPD packets
    >(AFAIK) someone correct me if i'm wrong.

    It's another layer of protection and is easy to implement. E.g. port scans wouldn't show up the port. Once you've knocked there is still the next level of authentication to get through (SSH key exchange, password etc.)

    >Looks interesting though, but inetd could do the same thing.

    inetd acts at the application layer. knockd is down at the link layer ( according the the man page, surely at the TCP level so it can get port numbers?). Regardless, inetd does a different job.

    Mods, if you don't understand something, how about not modding it up?
  • by 3Volker ( 66162 ) <slashdot@w4lk[ ]net ['er.' in gap]> on Wednesday April 14, 2004 @06:29PM (#8864134)
    www.portknocking.org [portknocking.org]

    Note the encryption/hash of the ports, source IP, and port to be opened.

    www.portknocking.org/view/documentation [portknocking.org]
    There is a Perl reference implementation. (GPL'd, of course)

    "I am in no way affiliated with this group."
  • Re:how long till... (Score:2, Informative)

    by jg_elliott ( 731553 ) on Wednesday April 14, 2004 @06:35PM (#8864208)
    I may be wrong, but I was under the impression that all knocked ports were closed and a cron job watched logs, and then opened a port if it noticed the correct knock. This is great for linux, were things are logged, but does windows have a loging facility of this kind? If not, the ports must be open for a program to know if someone has tried to connnect, which defeats the point. With most trojans being on windows, it seems that this isn't a viable feature to add.
  • Re:authpf? (Score:5, Informative)

    by debrain ( 29228 ) on Wednesday April 14, 2004 @06:52PM (#8864379) Journal
    The usable alphabet for a suicide TCP packet header is, I do believe, in bits:
    16: dest. port
    16: src port
    32: seq id
    6: flags
    16: window
    16: urgent
    40: options
    That gives us an alphabet 2^142 ~= 5.6 * 10^42. Not to mention that a sequence of packets can be combined, extending the language. Indeed, its cardinality is a natural ordinal, so the same as any password, if not more, by virtue of passwords being limited by an input buffer.

    Knocking need only finite state between packets, simply indicating a status of "last packet correct knock?"; successive knocking therein is in a cardinality greater than passwords. Knocking can happen over a period of months (as I have seen it), and be virtually undetectable for all but the most sophisticted (ie. expensive) means of detection.

    In combination with a time-synchronized one-time pad, you can generate an unrepeatable, provably (in the mathematical sense) secure system of access or commands. For example, for the minute of 13:01 EST, there can be a specific TCP packet, or series of packets that unlocks the door or executes a command. At no other predictable time would this knock be useful. (Time synchronization here is an issue, but often this attack will be used on machines that do care about an atomic clock sync).

    You can do the same thing with a password over SSH, but that's higher level, using more complex code, and inherently more likely to succumb to high-level assaults such as buffer overflows, as well as mathematical assaults on the encryption itself, both of which fundamentally compromise the system's security.

    In short, time-synchronized knocking is safer, simpler, and smarter than passwords or encryption for a certain number of niche applications.
  • Re:Knock Knock? (Score:4, Informative)

    by Anonymous Coward on Wednesday April 14, 2004 @06:54PM (#8864390)
    Encrypted port knocking is pointless. Here's why: Port knocking only makes sense if the protected system reacts to the individual knocks as if there was no port knocking system. Only when the knock sequence has been completed it opens the port. This means that you can't do any handshaking. All communication is one-way until it's "too late". Consequentially, since there is no challenge which could require a different response, replay attacks are unavoidable unless you use one-time passwords and then there's no point in encrypting the passwords.

    If you decide to send a challenge to the knocker, you could just as well use regular authentication over a TCP channel.

    The point of port knocking is to hide the existence of a regular channel, not to protect it from someone who knows that it's there. Someone who can sniff your packets is by definition already past that layer of protection, so any attempt to complicate the knock-layer will only increase the chance of creating another vulnerable interface. Keep it simple or don't do it.
  • A different solution (Score:5, Informative)

    by Pros_n_Cons ( 535669 ) on Wednesday April 14, 2004 @06:55PM (#8864401)
    there is another similar idea written by Brian Hatch author of Hacking Linux Exposed. Instead of 'knocking' ports which as I understand it can be vulnerable to brute force like attacks Hatch's solution uses dns queries to dynamicly open up ports through the firewall, using the dns query as a password. There is no 'service' listening but there is a sniffer waiting for a key string on port 53 that it will take action on. The best thing is it is OS agnostic since DNS query tools are already on all OS's no client software, or technical know-how is needed. And easily customizable if you're fluent in perl.
    These kind of things are not ment for full access, only by allowing you access to the daemon which still has its own acl. When you travel sometimes you're not aware of what IP address your laptop will have so you set a dns query to your home machine which opens the SSH port for you. The whole point is to prevent random attacks from people scanning vulnerable daemons. The following are links to Brian Hatches explinations and code.

    Part 1 [hackinglinuxexposed.com]
    Part 2 [hackinglinuxexposed.com]
    Part 2 [hackinglinuxexposed.com]
  • by ubiquitin ( 28396 ) * on Wednesday April 14, 2004 @06:56PM (#8864408) Homepage Journal
    My friend Thom Harrison at the Omaha Linux Users Group [olug.org] has posted some scripts [google.com] which do port knocking and have the following CPAN dependencies:

    |use File::Tail;
    |use Crypt::CBC;
    |use Schedule::At;
    |use Math::VecStat qw(sum);
    |use POSIX qw(strftime);
    |use Pod::Usage;
  • Re:how long till... (Score:3, Informative)

    by hank ( 294 ) on Wednesday April 14, 2004 @07:00PM (#8864443)
    As I understand it, the ports do not have to be open. You can listen on the link-level and monitor incoming packets even if the port is closed.

    At least, this is how the implementation this article mentions does it (or advertises it does). I've yet to thumb through the code.
  • by Creepy Crawler ( 680178 ) on Wednesday April 14, 2004 @07:06PM (#8864479)
    Because UDP is usually bandwidth filtered as it's the easiest protocol to flood a connection.

    Ethernet has a exponential-wait scheme to prevent cloging of pipes, and TCP uses a authorized sent only packet. No data is send until prior ones are OK'ed.
  • by MerlynEmrys67 ( 583469 ) on Wednesday April 14, 2004 @07:08PM (#8864513)
    I remember when:

    Seems my office was 2 miles down the road from my house - traceroute from my house in Portland, OR to my office went through both Seattle AND MAE-West (Bay Area, CA)

    Many external countries only have external connections to the USA, not directly to each other (don't know how true this currently is - but several asian countries used to have to hit the W Coast, USA to get between each other)

  • by F.Z.Bunny ( 749528 ) on Wednesday April 14, 2004 @07:38PM (#8864801)
    For portknocking, try doorman.sourceforge.net Got crypto.
  • by Anonymous Coward on Wednesday April 14, 2004 @08:04PM (#8865044)
    This is only implementing basic static knock sequences, but it could (and likely will) be further developed to support cryptographic knocks that are embedded with other data, such as which port to open.

    The guy at portknocking.org has a good example of how to do this.

    check it out [portknocking.org]
  • Re:how long till... (Score:3, Informative)

    by hank ( 294 ) on Wednesday April 14, 2004 @08:25PM (#8865219)
    "This port need not be open -- since knockd listens at the link-layer level, it sees all traffic even if it's destined for a closed port." This is from the page of the implementation this article is about.

    Also, the first sentence from portknocking.org: "Port knocking is a method of establishing a connection to a networked computer that has no open ports." A little further down on the page: "This is a form of IP over closed ports."

    Also, you may wish to read the FAQ: http://www.portknocking.org/view/faq [portknocking.org].
  • Re:how long till... (Score:3, Informative)

    by xsbellx ( 94649 ) on Wednesday April 14, 2004 @08:37PM (#8865308) Homepage
    You are quite correct, ports are not used at the link level, however once the packet is received by the adapter it is processed by a software stack.

    There are several products that implement similar concepts. Take a look at bridging firewalls. Neither interface on the bridge has an IP address but can still inspect packets and take action as required.
  • by revmoo ( 652952 ) <.sw.peem. .ta. .todhsals.> on Wednesday April 14, 2004 @09:05PM (#8865505) Homepage Journal
    Incorrect.

    You connect first to the server, it then queries your machine on 113 to see if you are who you say you are and let you in(or not).

    How is a server supposed to know to ident you if the ftp port isn't open first?
  • by kir ( 583 ) on Wednesday April 14, 2004 @09:16PM (#8865563)

    Worms port knocking? That would be one very very very slow moving worm!

    Remember. There are 65535 different ports available. So, given that you can repeat port numbers and one uses a 4 port "combination", you get this.

    65535^4 = 18,445,618,199,572,250,625 different "combinations"

    I'm not even sure how to read that, but I doubt a worm would try it. It might take it a while.

  • Packets are not guaranteed to arrive in the order that they were sent, or even to arrive at all. The longer or more complex the knock sequence, the more unreliable this system will be. Especially for a busy server.

    There are less stealthy but more secure alternatives. I wrote one [homeunix.org].

  • Parent is wrong (Score:5, Informative)

    by Ernesto Alvarez ( 750678 ) on Wednesday April 14, 2004 @10:02PM (#8865904) Homepage Journal

    Encrypted port knocking is pointless. Here's why: Port knocking only makes sense if the protected system reacts to the individual knocks as if there was no port knocking system. Only when the knock sequence has been completed it opens the port. This means that you can't do any handshaking. All communication is one-way until it's "too late".


    The idea in the grandparent post wasn't a challenge-response in the traditional way. It was some authentication data along with the knocking.
    The knock won't be encrypted, but it will have some data that is characteristic of the source (the source IP) that can't be spoofed (because of the password and the one way hash).

    An example of this would be:

    1.Real owner takes his IP (public info)
    2.Real owner takes his secret password (known only to him)
    3.Using IP and password he computes the hash and sends it in the knocking packets (let's say it's in the IP id)
    4.The receiving system captures the knocking packets and takes IP source and the hash
    5.It reads the secret password (from config file)
    6.It calculates the hash with the source IP and password

    If the hash sent and the hash calculated match, the system "accepts" that part of the port knocking. If not, discards the packet.

    An intruder might only spoof the whole packet (including IP source) and might open the firewall only for that IP. If he tries to use the hash to open it for HIS ip, the calculated hash won't match the hash sent. He cannot calculate the hash he would need because he does not know the password, and the hash is one way.

    In this protocol the target system does not need to respond with a challenge, it just discards packets that are "spoofed" (that have a non matching hash).
  • by lommer ( 566164 ) on Thursday April 15, 2004 @03:21AM (#8866901)
    I think that ISPs could simply then start looking for seemingly random port probes by machine A on machine B, followed by machine B spewing gobs of data to machine A on a random port. That's the trick, make your protocol too good and it'll stand out because it's too random. If you ever actually talk to anyone who works at ISPs though, they generally just flag those customers with unbelievable upload/download ratios and then have a human look at their logs to see if they're violating the TOS (running a server, hosting warez, whatever).
  • Re:one of many (Score:5, Informative)

    by Anonymous Coward on Thursday April 15, 2004 @03:42AM (#8866939)
    Why [slashdot.org] not [portknocking.org] just [linuxjournal.com] mod [slashdot.org] me [about.com] up [linuxsecurity.com] instead [jacobsen.no]? I [deadly.org] provide [aplawrence.com] links! [librenix.com]

"If anything can go wrong, it will." -- Edsel Murphy

Working...