root/fwknop/tags/fwknop-0.9.7-pre3/fwknop.8

Revision 488, 17.1 kB (checked in by mbr, 2 years ago)

minor bolding for http link

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 .\" Process this file with
2 .\" groff -man -Tascii foo.1
3 .\"
4 .TH FWKNOP 8 "May, 2005" Linux
5 .SH NAME
6 .B fwknop
7 \- Firewall Knock Operator
8 .SH SYNOPSIS
9 .B fwknop [-u
10 .I user-rc file
11 .B ] [-k
12 .I knock-dst
13 .B ] [-a
14 .I allow-IP
15 .B ] [--gpg-signing-key
16 .I keyID
17 .B ] [--gpg-recipient
18 .I keyID
19 .B ] [--gpg-verbose] [--gpg-home-dir
20 .I GnuPG dir
21 .B ] [--Server-port
22 .I port
23 .B ] [--Server-mode
24 .I mode
25 .B ] [--Server-cmd
26 .I command
27 .B ] [--Spoof-src
28 .I IP
29 .B ] [--Spoof-cmd
30 .I command
31 .B ] [--Spoof-file
32 .I file
33 .B ] [--Spoof-user
34 .I user
35 .B ] [--no-save-args] [-d] [-e] [-s] [-r] [-w] [-K] [-R] [-A] [-t
36 .I time-delay
37 .B ] [-g
38 .I key-file
39 .B ] [--offset
40 .I port-offset
41 .B ] [-H
42 .I homedir
43 .B ] [--Status] [-l] [-v] [-V] [-h]
44 .SH DESCRIPTION
45
46 .B fwknop
47 implements an authorization scheme known as Single Packet Authorization (SPA)
48 that requires only a single encrypted
49 packet to communicate various pieces of information including desired access
50 through a Netfilter policy and/or specific commands to execute on the target
51 system.  The main application of this program is to protect services such as
52 .B SSH
53 with an additional layer of security in order to make the exploitation of
54 vulnerabilities (both 0-day and unpatched code) much more difficult.  The
55 authorization server passively monitors authorization packets via
56 .B libpcap
57 and hence there is no "server" to which to connect in the traditional sense.
58 Any service protected by fwknop
59 is inaccessible (by using Netfilter to intercept packets within the Linux
60 kernel) before authenticating; anyone scanning for the service will not be
61 able to detect that it is even listening.  This authorization scheme offers
62 many advantages over port knocking, include being non-replayable, much more
63 data can be communicated, and the scheme cannot be broken by simply
64 connecting to extraneous ports on the server in an effort to break
65 knock sequences.  The authorization packets can easily be spoofed as
66 well, and this makes it possible to make it appear as though, say, www.yahoo.com
67 is trying to authenticate to a target system but in reality the actual
68 connection will come from a seemingly unrelated IP. Although the default data
69 collection method in Single Packet Authorization mode is to use libpcap to sniff
70 packets off the wire, fwknop can also read packets out of a file that is written
71 by the Netfilter
72 . B ulogd
73 pcap writer (or a separate sniffer process that is writing to a file).
74 .PP
75 Authorization packets are either encrypted with the Rijndael block cipher
76 or via GnuPG and associated asymmetric ciphers.  If the symmetric encryption
77 method is chosen, then the encryption key is shared between between the
78 client and server (see the file /etc/fwknop/access.conf).  If the GnuPG
79 method is chosen, then the encryption keys are derived from GnuPG key
80 rings.  Authorization packets generated by fwknop running as a client adhere
81 to the following format before being encrypted:
82 .PP
83     random number (16 bytes)
84     username
85     timestamp
86     software version
87     mode (command mode (0) or access mode (1))
88     if command mode => command to execute
89     else access mode  => IP,proto,port
90     MD5 sum
91 .PP
92 Each of the above fields are separated by a ":" character due to the
93 variable length of several of the fields, and those that might contain
94 ":" characters are base64 encoded.  The MD5 message sum allows the
95 server to check message integrity after decryption, and the 16 bytes
96 of random data ensures (with high probability) that no two messages are
97 identical.  For each packet coming from an fwknop client, the server
98 caches the MD5 sum calculated over the entire packet and compares against
99 previous MD5 sums in order to detect attempted replay attacks.  Both
100 syslog and email alerts are (optionally) generated if a replay is
101 attempted.  By default, fwknop sends authorization packets over UDP
102 port 62201, but this can be altered with the --Server-port argument.
103 The fwknop server is not limited to acquiring authorization packets
104 over any particular port or protocol, but the PCAP_FILTER and
105 ULOG_PCAP_FILTER keywords in /etc/fwknop/fwknop.conf limit the server
106 to inspecting traffic over the default UDP port 62201.  See the EXAMPLES
107 section for example invocations of fwknop in client mode, and see the
108 FWKNOP CONFIG section for an explanation of server configuration
109 keywords.
110 .PP
111 A note about the interaction between
112 .B fwknop
113 and Netfilter; fwknop maintains a strict separation between dynamically
114 generated rules and any existing Netfilter policy by adding all rules
115 to a custom chain "FWKNOP_INPUT".  Packets are jumped to this chain from
116 the INPUT chain.  Interaction with the FORWARD chain can be accomplished
117 by altering the IPT_AUTO_CHAIN{n} keywords in
118 .B /etc/fwknop/fwknop.conf.
119 .PP
120 In addition to the Single Packet Authorization method, fwknop maintains
121 the ability to generate encrypted port knocking sequences and combine
122 them with passive OS fingerprinting, but this mode is not enabled by
123 default.  This scheme is based around log
124 messages generated by the Netfilter firewall in the Linux kernel.
125 .B fwknop
126 supports both shared and encrypted port knock sequences, passive OS fingerprinting,
127 multi-protocol knock sequences (tcp, udp, and icmp), firewall access across
128 multiple ports and protocols, firewall access timeouts, relative timeouts between
129 knock packets, and more.
130 .PP
131 The server component of fwknop is the
132 .B fwknopd
133 daemon which normally sniffs the wire directly or monitors a pcap file for SPA
134 packets generated by fwknop clients.  If run in legacy port knocking mode, fwknopd
135  watches iptables log messages as they are written via syslog to a named pipe
136 .B /var/lib/fwknop/fwknopfifo.
137 If a valid knock sequence is seen, then fwknop will modify the iptables ruleset to
138 grant the appropriate access to the originating IP address.  Knock sequence parameters
139 are defined in the file
140 .B /etc/fwknop/access.conf.
141 When run in client mode, fwknop generates either an encrypted knock sequence (see
142 the
143 .B EXAMPLES
144 section below), or a shared knock sequence.  Shared knock sequences are defined in
145 the file
146 .B ~/.fwknoprc
147 (this file is not used for encrypted sequences).
148
149 See the
150 .B fwknopd (8)
151 man page for more information.  Also, more information on the
152 differences between port knocking and Single Packet Authorization can be found
153 in the paper "Single Packet Authorization with fwknop" available here:
154 .B http://www.cipherdyne.org/fwknop/docs/SPA.html
155
156 .SH OPTIONS
157 .TP
158 .BR \-A "\fR,\fP " \-\^\-Access\ \<port\ list>
159 Provide a list of ports and protocols to access via a remote
160 .B fwknop
161 server. The format of this list is "<proto>/<port>...<proto>/<port>",
162 e.g. "tcp/22,udp/53".
163 .TP
164 .BR \-\^\-gpg-signing-key\ \<key ID>
165 Specify the GnuPG key ID, e.g. "ABCD1234" (see the output of "gpg --list-keys")
166 to use to sign a Single Packet Authorization message.  The user prompted for the
167 associated GPG password which is required for creating the signature.  This
168 .TP
169 .BR \-\^\-gpg-recipient\ \<key ID>
170 Specify the GnuPG key ID, e.g. "1234ABCD" (see the output of "gpg --list-keys")
171 of the recipient of the Single Packet Authorization message.  This key is imported
172 by the
173 .B fwknopd
174 server and the associated private key is used to decrypt the SPA packet.  The
175 recipient's key must be imported into the client GnuPG key ring.
176 .TP
177 .BR \-\^\-gpg-home-dir\ \<dir>
178 Specify the path to the GnuPG directory; normally this path is derived from the
179 home directory of the user that is running the
180 .B fwknop
181 client.
182 .TP
183 .BR \-\^\-gpg-verbose
184 Instruct
185 .B fwknop
186 to allow all output from the
187 .B gpg
188 process that is used by fwknop in GPG mode.  This is primarily used for debugging
189 purposes if it appears that the GPG encrypt/decrypt is not performing correctly.
190 .TP
191 .BR \-\^\-Server-port\ \<port>
192 Specify the port number where
193 .B fwknop
194 accepts packets via libpcap or ulogd pcap writer.  By default fwknop looks for
195 authorization packets over UDP port 62201.
196 .TP
197 .BR \-\^\-Server-cmd\ \<cmd>
198 The --Server-cmd argument allows a complete command (e.g. "ping -c 1 www.yahoo.com",
199 or "iptables -t nat -A PREROUTING -p tcp -s 65.x.x.x --dport 443 -i eth0 -j DNAT --to 192.168.10.20:443")
200 to be send to an
201 .B fwknop
202 server, which will execute the command as root.  Command execution is enabled only
203 if the ENABLE_CMD_EXEC keyword is given in /etc/fwknop/access.conf (note that
204 commands can easily be restricted with the CMD_REGEX keyword as well).
205 .TP
206 .BR \-u "\fR,\fP " \-\^\-user-rc\ \<rc-file>
207 The default connection rc file
208 .B fwknop
209 uses to know what shared port knocking sequence to send to a destination machine
210 is defined in the file
211 .B ~/.fwknoprc.
212 The path to this file can be changed with the
213 .B --user-rc
214 command line option.
215 .TP
216 .BR \-k "\fR,\fP " \-\^\-knock-dst\ \<IP>
217 Run
218 .B fwknop
219 in port knocking mode against the destination IP address.  The specific port
220 knock sequence that is sent to the destination will either be encrypted (if
221 .B --encrypt
222 is passed on the command line) or read out of the file
223 .B ~/.fwknoprc.
224 .TP
225 .BR \-a "\fR,\fP " \-\^\-allow-ip\ \<allow-IP>
226 Specify a third-party IP address (can be the local machine) to allow
227 through the destination knock server firewall.  This option is only used
228 when
229 .B fwknop
230 is being run in
231 .B --encrypt
232 encrypted knock mode.
233 .TP
234 .BR \-s "\fR,\fP " \-\^\-source-ip
235 Instruct
236 .B fwknop
237 to form an encrypted knock sequence that will contain the special-case IP
238 address "0.0.0.0" which will inform the destination knock server to use
239 the source IP address from which an encrypted knock sequence originates as
240 the IP that will be allowed through upon modification of the firewall ruleset.
241 This option is useful if the fwknop client is deployed on a machine that is
242 behind a NAT device.  This option is only used in
243 .B --encrypt
244 encrypted knock mode.
245 .TP
246 .BR \-\^\-Spoof-src\ \<IP>
247 Spoof the source address from which
248 .B fwknop
249 sends authorization packets.  This requires root access since a raw socket
250 is required to accomplish this.  Note that the --Spoof-user argument can be
251 given in this mode in order to pass any REQUIRE_USERNAME keyword that might
252 be specified in /etc/fwknop/access.conf.
253 .TP
254 .BR \-\^\-Spoof-cmd\ \<cmd>
255 Specify the path to the command
256 .B knopspoof
257 which is used by
258 .B fwknop
259 in --Spoof-src mode.  This command is install by default at /usr/sbin/knopspoof.
260 .TP
261 .BR \-\^\-Spoof-user\ \<user>
262 Specify the username that is included within authorization messages.  This allows
263 the client to satisfy any non-root REQUIRE_USERNAME keyword on the
264 .B fwknop
265 server (--Spoof-src mode requires that fwknop is executed as root).
266 .TP
267 .BR \-\^\-Spoof-file\ \<file>
268 Specify the path to the cache file that
269 .B knopspoof
270 reads in order to correctly generate the authorization packet.  This
271 file defaults to /tmp/spoof.cache, and contains source and destination
272 IP addresses, protocol and port numbers, and the encrypted authorization
273 message.
274 .TP
275 .BR \-\^\-offset\ \<port>
276 Specify a port offset to use when running
277 .B fwknop
278 in encrypted knock mode.  The default is 61000.
279 .TP
280 .BR \-r "\fR,\fP " \-\^\-rotate-proto
281 Rotate the protocol across tcp and udp for encrypted sequences.  This just
282 adds one more additional layer of obfuscation to an encrypted sequence.
283 .TP
284 .BR \-t "\fR,\fP " \-\^\-time-delay\ \<seconds>
285 Specify a time delay to introduce between successive connection attempts.
286 This option is only used when
287 .B fwknop
288 is run in client mode.  On the server side, the variables MIN_TIME_DIFF
289 and MAX_TIME_DIFF will control whether the time delay actually means
290 something (i.e. if the MIN_TIME_DIFF is 2 seconds for a SOURCE block,
291 then the argument to the --time-delay option must be at least 2 at the
292 client side).
293 .TP
294 .BR \-\^\-Server-mode\ \<mode>
295 This command line switch provides an interface to the old port knocking method if
296 the mode argument is "knock".  If the --Server-mode argument is not given then
297 .B fwknop
298 defaults to the Single Packet Authorization method which provides much better
299 security characteristics than port knocking (encrypted or not).
300 .TP
301 .BR \-g "\fR,\fP " \-\^\-get-key\ \<file>
302 Get encryption key from
303 .B <file>
304 instead of from STDIN.  This option can only be specified when running
305 .B fwknop
306 in encrypted knock mode against a system running a fwknop server.
307 .TP
308 .BR \-l "\fR,\fP " \-\^\-last-cmd
309 Run
310 .B fwknop
311 with the command line arguments given for the previous execution.  This
312 makes it easy to run the same fwknop command over and over without having
313 to remember complicated command line args.
314 .TP
315 .BR \-\^\-no-save-args
316 Instruct
317 .B fwknop
318 to not save the command line arguments it was invoked with.  This is useful to
319 test fwknop with new command line args that should not be saved to disk, and
320 this leaves existing saved arguments from a previous fwknop execution intact.
321 .TP
322 .BR \-H "\fR,\fP " \-\^\-Home-dir\ \<directory>
323 Manually specify the home directory associated with the current user (useful
324 if fwknop is unable to automatically determine the home directory).
325 .TP
326 .BR \-v "\fR,\fP " \-\^\-verbose
327 Run fwknop in verbose mode.
328 .TP
329 .BR \-h "\fR,\fP " \-\^\-help
330 Display usage information and exit.
331 .TP
332 .BR \-V "\fR,\fP " \-\^\-Version
333 Display version information and exit.
334 .SH EXAMPLES
335 The following examples illustrate the command line arguments that could
336 be supplied to fwknop in a few situations:
337 .PP
338 Use the Single Packet Authorization mode to gain access to tcp/22 (ssh)
339 and udp/53 running on the system 10.0.0.123 from the IP 192.168.10.4:
340 .PP
341 .B $ fwknop -A "tcp/22,udp/53" -a 192.168.10.4 -k 10.0.0.123
342 .PP
343 Same as above example, but gain access from whatever source IP is seen
344 by the fwknop server (useful if the fwknop client is behind a NAT device):
345 .PP
346 .B $ fwknop -A "tcp/22,udp/53" -s -k 10.0.0.123
347 .PP
348 Same as above example, but use the IP identification website http://www.whatismyip.com
349 to derive the client IP address.  This is a safer method of acquiring the client IP
350 address than using the "-s" option because the IP is put within the encrypted packet
351 (a man-in-the-middle attack becomes infeasible against this).
352 .PP
353 .B $ fwknop -A "tcp/22,udp/53" -w -k 10.0.0.123
354 .PP
355 Use the Single Packet Authorization mode to gain access to tcp/22 (ssh)
356 and udp/53 running on the system 10.0.0.123, and use GnuPG keys to encrypt
357 and decrypt:
358 .PP
359 .B $ fwknop -A "tcp/22,udp/53" --gpg-sign ABCD1234 --gpg--recipient 1234ABCD -w -k 10.0.0.123
360 .PP
361 Instruct the fwknop server running at 10.0.0.123 to send a single ICMP
362 echo request to www.yahoo.com:
363 .PP
364 .B $ fwknop --Server-cmd "ping -c 1 www.yahoo.com" -k 10.0.0.123
365 .PP
366 Instruct the fwknop server running at 10.0.0.123 to allow 172.16.5.4 to
367 connect to TCP/22, but spoof the authorization packet from an IP associated
368 with www.yahoo.com:
369 .PP
370 .B # fwknop --Spoof-src "www.yahoo.com" -A tcp/22 -a 172.16.5.4 -k 10.0.0.123
371 .PP
372 LEGACY: Send an encrypted knock sequence to the IP "10.0.0.123" instructing the
373 fwknop daemon running there to open tcp port 22 to source address
374 192.168.10.4:
375 .PP
376 .B $ fwknop --Server-mode "knock" -A tcp/22 -a 192.168.10.4 -k 10.0.0.123
377 .PP
378 LEGACY: Same as above, but this time instruct the remote fwknop daemon to open
379 tcp port 22 to whatever source address the encrypted sequence originates
380 from (useful if the fwknop client is behind a NAT device):
381 .PP
382 .B $ fwknop --Server-mode "knock" -A tcp/22 -s -k 10.0.0.123
383 .PP
384 LEGACY: Same as above, but rotate the knock sequence through the tcp and udp
385 protocols (remember that iptables must be configured to log both tcp and
386 udp packets to the default port range of 61000-61255):
387 .PP
388 .B $ fwknop --Server-mode "knock" -A tcp/22 -s -r -k 10.0.0.123
389 .PP
390 LEGACY: Same as above, but change the base port for the encrypted sequence to
391 55000 (the default is 61000):
392 .PP
393 .B $ fwknop --Server-mode "knock" -A tcp/22 -s -r --offset 55000 -k 10.0.0.123
394 .PP
395 LEGACY: Send a shared knock sequence to the IP 10.11.11.123.  The fwknop client
396 will read the sequence out of the file
397 .B ~/.fwknoprc
398 and the server will read the sequence out of
399 .B /etc/fwknop/access.conf:
400 .PP
401 .B $ fwknop --Server-mode "knock" -k 10.11.11.123
402 .SH DEPENDENCIES
403 .B fwknop
404 requires perl.  To take advantage of all of the features in fwknop when run
405 in server mode a functioning Netfilter firewall is required on the underlying
406 operating system.  If fwknop is being run in the legacy port knocking mode,
407 then Netfilter must log packets via syslog, and ideally the --log-tcp-options
408 argument will be specified in the iptables logging rule so that fwknop will
409 be able to use a strategy similar to
410 .B p0f
411 to passively fingerprint operating systems.
412 .SH DIAGNOSTICS
413 .B fwknop
414 can be run in debug mode with the --debug command line option.  This will
415 disable daemon mode execution, and print verbose information to the screen
416 on STDERR as packets are received.
417 .SH "SEE ALSO"
418 .BR fwknopd (8),
419 .BR iptables (8),
420 .BR p0f (1),
421 .BR knopmd (8),
422 .BR knopwatchd (8)
423 .SH AUTHOR
424 Michael Rash <mbr@cipherdyne.org>
425 .SH CREDITS
426 The phrase "Single Packet Authorization" was coined by MadHat, see:
427 .B http://www.nmrc.org/
428 The term "port knocking" was coined by Martin Krzywinski, see:
429 .B http://www.portknocking.org/
430  The original p0f passive OS fingerprinter was written by Michal Zalewski, and is
431 available here:
432 .B http://lcamtuf.coredump.cx/p0f.shtml
433 .SH BUGS
434 Send bug reports to mbr@cipherdyne.org.  Suggestions and/or comments are
435 always welcome as well.
436 .SH DISTRIBUTION
437 .B fwknop
438 is distributed under the GNU General Public License (GPL), and the latest
439 version may be downloaded from
440 .B http://www.cipherdyne.org/
Note: See TracBrowser for help on using the browser.