个人工具

“UbuntuHelp:PortKnocking”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第6行: 第6行:
 
On the client side, the only thing needed is to play the sequence with the client of your choice (such as '''knock''').
 
On the client side, the only thing needed is to play the sequence with the client of your choice (such as '''knock''').
 
== Server Setup ==
 
== Server Setup ==
The setup of the server is straightforward. First, ensure that your server has a running firewall. Then, install the <code><nowiki>knockd</nowiki></code> package (see InstallingSoftware).
+
The setup of the server is straightforward. First, ensure that your server has a running firewall. Then, install the <code><nowiki>knockd</nowiki></code> package (see [[UbuntuHelp:InstallingSoftware|InstallingSoftware]]).
 
After the package is installed, edit its configuration file. Two approaches are presented below: the first is intended for connections with no keep-alive (such as HTTP), while the other is intended for permanent connections (such as SSH and IRC).
 
After the package is installed, edit its configuration file. Two approaches are presented below: the first is intended for connections with no keep-alive (such as HTTP), while the other is intended for permanent connections (such as SSH and IRC).
 
== Example 1 ==
 
== Example 1 ==
第46行: 第46行:
 
== Client Side ==
 
== Client Side ==
 
On the client side, you can "knock" with the client of your choice: <code><nowiki>telnet</nowiki></code>, <code><nowiki>nc</nowiki></code> or even the software used to connect to the server (for example <code><nowiki>ssh</nowiki></code>). If you do not use a client designed for portknocking, you must do the knock sequence manually.
 
On the client side, you can "knock" with the client of your choice: <code><nowiki>telnet</nowiki></code>, <code><nowiki>nc</nowiki></code> or even the software used to connect to the server (for example <code><nowiki>ssh</nowiki></code>). If you do not use a client designed for portknocking, you must do the knock sequence manually.
An easier method is to use the knock client. Install the <code><nowiki>knockd</nowiki></code> package (see InstallingSoftware).
+
An easier method is to use the knock client. Install the <code><nowiki>knockd</nowiki></code> package (see [[UbuntuHelp:InstallingSoftware|InstallingSoftware]]).
 
For knocking, launch the command:
 
For knocking, launch the command:
 
<pre><nowiki>
 
<pre><nowiki>

2007年12月4日 (二) 11:16的版本

What is Port Knocking ?

Port knocking is a simple method to grant remote access without leaving a port constantly open. This preserves your server from port scanning and script kiddie attacks. To utilize port knocking, the server must have a firewall and run the knock-daemon. As the name conveys, the daemon is listening for a specific sequence of TCP or UDP "knocks". If the sequence is given correctly, then a command is executed; typically the source IP address is given access through the firewall to the port of an application (such as SSH). This method is reasonably secure, as port knocking is located at a very low level in the TCP/IP stack and does not require any opened ports. The knock-daemon is also invisible to potential attackers. On the client side, the only thing needed is to play the sequence with the client of your choice (such as knock).

Server Setup

The setup of the server is straightforward. First, ensure that your server has a running firewall. Then, install the knockd package (see InstallingSoftware). After the package is installed, edit its configuration file. Two approaches are presented below: the first is intended for connections with no keep-alive (such as HTTP), while the other is intended for permanent connections (such as SSH and IRC).

Example 1

[options]
logfile = /var/log/knockd.log
[openHTTP]
sequence    = 7000,8000,9000
seq_timeout = 5
command     = /sbin/iptables -A INPUT -s %IP% -p tcp --dport 80 -j ACCEPT
tcpflags    = syn
[closeHTTP]
sequence    = 9000,8000,7000
seq_timeout = 5
command     = /sbin/iptables -D INPUT -s %IP% -p tcp --dport 80 -j ACCEPT
tcpflags    = syn

Here we have defined two sequences :

  • openHTTP opens the HTTP port if the 7000, 8000 and 9000 port sequence is "knocked"
  • closeHTTP closes the HTTP port if the 9000, 8000 and 7000 port sequence is "knocked"

Example 2

The second example is a bit different from the original:

[options]
logfile = /var/log/knockd.log
[SSH]
sequence    = 7000,8000,9000
seq_timeout = 5
command     = /sbin/iptables -A INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
tcpflags    = syn
cmd_timeout   = 10
stop_command  = /sbin/iptables -D INPUT -s %IP% -p tcp --dport 22 -j ACCEPT

It's recommended to open the port for a short time (ten seconds, in this example). For this to be functional, you must have a state-full firewall running on your server (there must be a rule to accept connections with -m state --state RELATED,ESTABLISHED). Let's explain this configuration file. If a user "knocks" on ports 7000, 8000 and 9000 (in order), the command will be played (opening port 22). Ten seconds later, the stop_command will be executed, closing the port to new connections. Do not forget to change the sequence (this is the example provided by the default installation) and, of course provide the sequence to your users. You must also change the default configuration file /etc/default/knockd for the knockd daemon to start. Uncomment the START_KNOCKD=1 line to enable the daemon. That's it!

Client Side

On the client side, you can "knock" with the client of your choice: telnet, nc or even the software used to connect to the server (for example ssh). If you do not use a client designed for portknocking, you must do the knock sequence manually. An easier method is to use the knock client. Install the knockd package (see InstallingSoftware). For knocking, launch the command:

knock ''hostname'' ''port1'' ''port2'' ''port3''

Then connect to your application.

Notice

Simple portknocking daemons (such as knockd) are vulnerable because a sniffer may recover the port sequence that was used. A better solution is Cryptknock (http://cryptknock.sourceforge.net/) Cryptknock's description says: "Cryptknock is an encrypted port knocking tool. Unlike other port knockers which use TCP ports or other protocol information to signal the knock, an encrypted string is used as the knock. This makes it extremely difficult for an eavesdropper to recover your knock (unlike other port knockers where tcpdump can be used to discover a port knock)."

Links

The orginal project Detailed explanations on how it works and a reference implementation. The port knocking daemon The Ubuntu package is build from this release. A Win32 package is also available. You will also find other examples and some documentation.