root/fwknop/tags/fwknop-1.8.4-pre1/fwknop.8

Revision 807, 20.3 kB (checked in by mbr, 1 year ago)

minor URL text fix

  • 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 "Jun, 2007" Linux
5 .SH NAME
6 .B fwknop
7 \- Firewall Knock Operator
8 .SH SYNOPSIS
9 .B fwknop -A <ports> -D <host> [options]
10 .SH DESCRIPTION
11
12 .B fwknop
13 implements an authorization scheme known as Single Packet Authorization (SPA)
14 that requires only a single encrypted
15 packet to communicate various pieces of information including desired access
16 through an iptables policy and/or specific commands to execute on the target
17 system.  The main application of this program is to protect services such as
18 .B SSH
19 with an additional layer of security in order to make the exploitation of
20 vulnerabilities (both 0-day and unpatched code) much more difficult.  An
21 authorization server
22 .B fwknopd
23 passively monitors authorization packets via
24 .B libpcap
25 and hence there is no "server" to which to connect in the traditional sense.
26 Any service protected by fwknop is inaccessible (by using iptables to intercept
27 packets within the Linux kernel) before authenticating; anyone scanning for
28 the service will not be able to detect that it is even listening.  Single Packet
29 Authorization offers many advantages over port knocking, including non-replayability
30 of SPA packets, ability to use asymmetric ciphers (such as Elgamal), and SPA cannot
31 be broken by simply spoofing packets to duplicate ports within the knock sequence
32 on the server to break port knocking authentication.  SPA packets can easily be
33 spoofed as well (this is a good thing in this context), and this makes it possible
34 to make it appear as though, say, www.yahoo.com is trying to authenticate to a
35 target system but in reality the actual connection will come from a seemingly
36 unrelated IP. Although the default data collection method in Single Packet
37 Authorization mode is to use libpcap to sniff packets off the wire, fwknop can also
38 read packets out of a file that is written by the iptables
39 . B ulogd
40 pcap writer (or a separate sniffer process that is writing packet data to a file).
41 .PP
42 Authorization packets are either encrypted with the Rijndael block cipher
43 or via GnuPG and associated asymmetric ciphers.  If the symmetric encryption
44 method is chosen, then the encryption key is shared between between the
45 client and server (see the
46 .I /etc/fwknop/access.conf
47 file).  If the GnuPG
48 method is chosen, then the encryption keys are derived from GnuPG key
49 rings.  SPA packets generated by fwknop running as a client adhere
50 to the following format (before they are encrypted):
51 .PP
52     random number (16 bytes)
53     username
54     timestamp
55     software version
56     mode (command mode (0) or access mode (1))
57     if command mode => command to execute
58     else access mode  => IP,proto,port
59     MD5 sum
60 .PP
61 Each of the above fields are separated by a ":" character due to the
62 variable length of several of the fields, and those that might contain
63 ":" characters are base64 encoded.  The MD5 message sum allows the
64 server to check message integrity after decryption, and the 16 bytes
65 of random data ensures (with high probability) that no two messages are
66 identical.  For each packet coming from an
67 .B fwknop
68 client, the
69 .B fwknopd
70 server caches the MD5 sum calculated over the entire packet and compares against
71 previous MD5 sums in order to detect attempted replay attacks.  The MD5 sum
72 cache file is located at
73 .I /var/log/fwknop/md5sums
74 and is not rotated so that the detection of duplicate SPA messages is maximized.
75 Both syslog and email alerts are generated if a replay is detected (although
76 this can be tuned via the
77 .B ALERTING_METHODS
78 variable in the
79 .I /etc/fwknop/fwknop.conf
80 file).  By default, the
81 .B fwknop
82 client sends authorization packets over UDP
83 port 62201, but this can be altered with the
84 .B --Server-port
85 argument. The server must first be configured to acquire the SPA data on
86 the changed ptotocol-port.  See
87 .B fwknopd(8)
88 for further details.  See the
89 .B EXAMPLES
90 section for example invocations of the
91 .B fwknop
92 client.
93
94 .SH REQUIRED ARGUMENTS
95
96 .TP
97 .BR \-D "\fR,\fP " \-\^\-target\ \<IP-address>
98 Direct the
99 .B fwknop
100 client to authenticate with the
101 .B fwknopd
102 daemon/service at the destination address <IP> .  The connection mode is discovered by the
103 .B fwknopd
104 daemon/service when it decrypts and parses the authentication packet.
105 .TP
106 .BR \-A "\fR,\fP " \-\^\-Access\ \<port\ list>
107 Provide a list of ports and protocols to access on a remote computer running
108 .B fwknopd.
109 The format of this list is '<proto>/<port>...<proto>/<port>,
110 e.g. "tcp/22,udp/53".
111 .B NOTE:
112 The vast majority of usages for
113 .B fwknop
114 require the -A argument, but sending full commands with the --Server-cmd
115 argument via an SPA packet to be executed by
116 .B fwknopd
117 does not require this argument.
118
119 .SH OPTIONS
120
121 .TP
122 .BR \-a "\fR,\fP " \-\^\-allow-ip\ \<allow-IP>
123 Specify IP address that should be permitted through the destination
124 .B fwknopd
125 server firewall (this IP is encrypted within the SPA packet itself). This is
126 useful to prevent a Man-In-The-Middle (MTIM) attack where an SPA packet can be
127 intercepted en-route and sent from a different IP than the original. Hence, if
128 the
129 .B fwknopd
130 server trusts the source address on the SPA packet IP header then the attacker
131 gains access.  The
132 .B -a
133 option puts the source address within the encrypted
134 SPA packet, and so thwarts this attack.  The
135 .B -a
136 option is also useful to specify the IP that will be granted access when SPA
137 packet itself is spoofed with the
138 .B --Spoof-src
139 option.  Another related option is -R (see below) which instructs the
140 .B fwknop
141 client to automatically resolve the externally routable IP address the local
142 system is connected to by querying the
143 .B http://www.whatismyip.com
144 website.
145 .TP
146 .BR \-R "\fR,\fP " \-\^\-Resolve-external-IP
147 This is an important option, and instructs the
148 .B fwknop
149 client and the
150 .B fwknopd
151 daemon/service to query
152 .B http://www.whatismyip.com
153 to determine the IP address that should be allowed through the iptables policy
154 at the remote
155 .B fwknopd
156 server side.  This is useful if the
157 .B fwknop
158 client is being used on a system that is behind an obscure NAT address.  Note
159 that you can use the
160 .B --URL
161 option to have fwknop resolve an externally routable address by using the
162 specific web service instead of http://www.whatismyip.org (see below).
163 .TP
164 .BR \-\^\-URL\ \<web\ resolution\ \URL>
165 This option is used in conjunction with the
166 .B -R
167 option so that fwknop will resolve the externally routable IP address (useful
168 if fwknop is run on a system being a NAT) via a web service URL supplied on
169 the command line. A custom web resolution CGI script is available at the URL
170 below if http://www.whatismyip.org is not available:
171 .B http://www.cipherdyne.org/cgi/clientip.cgi
172 .TP
173 .BR \-\^\-gpg-agent
174 Instruct
175 .B fwknop
176 to acquire GnuPG key password from a running
177 .B gpg-agent
178 instance.
179 .TP
180 .BR \-\^\-gpg-agent-info\ \<connection\ \info>
181 Specify the value of the GPG_AGENT_INFO environment variable as returned
182 by the
183 .B gpg-agent --daemon
184 command. If the
185 .B fwknop --gpg-agent
186 command line argument is used instead of
187 .B --gpg-agent-info,
188 then fwknop assumes that the GPG_AGENT_INFO environment variable has already
189 been set in the current shell.
190 .TP
191 .BR \-\^\-gpg-default-key
192 Use the key that GnuPG defines as the default, i.e. the key that is specified
193 by the
194 .B default-key
195 variable in
196 .I ~/.gnupg/options.
197 If the
198 .B default-key
199 variable is not defined
200 within
201 .I ~/.gnupg/options
202 , then GnuPG tries to use the first suitable key on
203 its key ring.  If the user does not know the password for this key, then the
204 standard password error will be thrown by GnuPG and reported back to the
205 user.
206 .TP
207 .BR \-\^\-gpg-home-dir\ \<dir>
208 Specify the path to the GnuPG directory; normally this path is derived from the
209 home directory of the user that is running the
210 .B fwknop
211 client.  This is useful when a 'root' user wishes to log into a remote machine
212 whose
213 .B sshd
214 daemon/service does not permit 'root' login.
215 .TP
216 .BR \-\^\-gpg-recipient\ \<key\ \ID>
217 Specify the GnuPG key ID, e.g. "1234ABCD" (see the output of "gpg --list-keys")
218 of the recipient of the Single Packet Authorization message.  This key is imported
219 by the
220 .B fwknopd
221 server and the associated private key is used to decrypt the SPA packet.  The
222 recipient's key must first be imported into the client GnuPG key ring.
223 .TP
224 .BR \-\^\-gpg-signing-key\ \<key\ \ID>
225 Specify the GnuPG key ID, e.g. "ABCD1234" (see the output of "gpg --list-keys")
226 to use when signing the SPA message.  The user is prompted for
227 the associated GPG password to create the signature.  This
228 adds a cryptographically strong mechanism to allow the
229 .B fwknopd
230 daemon on the remote server to authenticate who created the SPA message.
231 .TP
232 .BR \-\^\-gpg-verbose
233 Instruct
234 .B fwknop
235 to allow all output from the
236 .B gpg
237 process that is used by fwknop in GPG mode.  This is primarily used for debugging
238 purposes if it appears that the GPG encrypt/decrypt is not performing correctly.
239 .TP
240 .BR \-l "\fR,\fP " \-\^\-last-cmd
241 Instruct
242 .B fwknop
243 client to run with the same command line arguments that were used in a previous execution.
244 This option is useful because the clients'
245 .B fwknop
246 command line can be complex and difficult to recall.
247 .TP
248 .BR \-L "\fR,\fP " \-\^\-Last-host\ \<host>
249 Instruct
250 .B fwknop
251 to use the same command line arguments that were used to authenticate to
252 .B host.
253 .TP
254 .BR \-q "\fR,\fP " \-\^\-quiet
255 This option instructs the
256 .B fwknop
257 to be as quiet as possible and only print absolutely necessary information to
258 the terminal.
259 .TP
260 .BR \-s "\fR,\fP " \-\^\-source-ip
261 Instruct the
262 .B fwknop
263 client to form an SPA packet that contains the special-case IP
264 address "0.0.0.0" which will inform the destination
265 .B fwknopd
266 SPA server to use the source IP address from which the SPA packet originates as
267 the IP that will be allowed through upon modification of the firewall ruleset.
268 This option is useful if the fwknop client is deployed on a machine that is
269 behind a NAT device. The permit-address options
270 .B -s
271 (default),
272 .B -R
273 and
274 .B -a
275 are mutually exclusive.
276 .TP
277 .BR \-\^\-Server-port\ \<port>
278 Specify the port number where
279 .B fwknop
280 accepts packets via libpcap or ulogd pcap writer.  By default fwknop looks for
281 authorization packets over UDP port 62201.
282 .TP
283 .BR \-\^\-Spoof-cmd\ \<cmd>
284 Specify the path to the command
285 .B knopspoof
286 which is used by the
287 .B fwknop
288 client in
289 .B --Spoof-src
290 mode.  This command is install by default at
291 .I /usr/sbin/knopspoof.
292 .TP
293 .BR \-\^\-Spoof-file\ \<file>
294 Specify the path to the cache file that
295 .B knopspoof
296 reads in order to correctly generate the authorization packet.
297 This file defaults to
298 .I /tmp/spoof.cache
299 , and contains source and destination
300 IP addresses, protocol and port numbers, and the encrypted authorization
301 message.
302 .TP
303 .BR \-\^\-Spoof-src\ \<IP>
304 Spoof the source address from which the
305 .B fwknop
306 client sends SPA packets.  This requires root on the client side access since a raw socket
307 is required to accomplish this.  Note that the
308 .B --Spoof-user
309 argument can be given in this mode in order to pass any
310 .B REQUIRE_USERNAME
311 keyword that might
312 be specified in
313 .I /etc/fwknop/access.conf.
314 .TP
315 .BR \-\^\-Spoof-user\ \<user>
316 Specify the username that is included within SPA packet.  This allows
317 the
318 .B fwknop
319 client to satisfy any non-root
320 .B REQUIRE_USERNAME
321 keyword on the
322 .B fwknopd
323 server (
324 .B --Spoof-src
325 mode requires that the
326 .B fwknop
327 client is executed as root).
328 .TP
329 .BR \-T "\fR,\fP " \-\^\-TCP-sock
330 Have the
331 .B fwknop
332 client send an SPA packet over an established TCP connection.  This is not normally
333 done, but is useful for compatibility with the Tor for strong anonymity; see
334 .B http://tor.eff.org/.
335 .TP
336 .BR \-h "\fR,\fP " \-\^\-help
337 Display usage information and exit.
338 .TP
339 .BR \-V "\fR,\fP " \-\^\-Version
340 Display version information and exit.
341 .TP
342 .BR \-v "\fR,\fP " \-\^\-verbose
343 Run the
344 .B fwknop
345 client in verbose mode.
346 .TP
347 .BR \-\^\-Server-cmd\ \<cmd>
348 .B NOTE:
349 This is for command mode only (i.e. when you want to send a command across
350 to a system running
351 .B fwknopd
352 and have it execute the command). This option is not needed when trying to
353 gain access to a service via the SPA mechanism.  To use this feature, please
354 ensure that ENABLE_CMD_EXEC; is set in the file
355 .I /etc/fwknop/access.conf
356 on the
357 .B fwknopd
358 server you are sending the command to.
359 The --Server-cmd argument allows a complete command (e.g. "ping -c 1 www.yahoo.com",
360 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")
361 to be send to an
362 .B fwknop
363 server, which will execute the command as root.  Command execution is enabled only
364 if the
365 .B ENABLE_CMD_EXEC keyword is given in
366 .I /etc/fwknop/access.conf
367 (note that commands can easily be restricted with the
368 .B CMD_REGEX
369 keyword as well).
370 .TP
371
372 .B Legacy Port-knock mode only
373
374 All of the following options in this section are for the traditional port knocking
375 mode mode.  This is a legacy mode and is
376 .B not
377 the preferred or recommended mode next to Single Packet Authorization ( see
378 .B http://www.cipherdyne.org/fwknop/docs/SPA.html
379 for details on why).
380 .RS
381 .TP
382 .BR \-\^\-offset\ \<port>
383 Specify a port offset to use when running
384 .B fwknop
385 in encrypted knock mode.  The default is 61000.
386 .TP
387 .BR \-r "\fR,\fP " \-\^\-rotate-proto
388 Rotate the protocol across tcp and udp for
389 encrypted sequences.  This just adds one more additional layer of obfuscation
390 to an encrypted sequence.
391 .TP
392 .BR \-\^\-Server-mode\ \<mode>
393 This command line switch provides an interface to
394 the old port knocking method if
395 the mode argument is "knock".  If the
396 .B --Server-mode
397 argument is not given then the
398 .B fwknop
399 client defaults to using the SPA method which provides much better
400 security characteristics than port knocking (encrypted or not).
401 .TP
402 .BR \-t "\fR,\fP " \-\^\-time-delay\ \<seconds>
403 Specify a time delay to introduce between successive
404 connection attempts.  This option is used by the
405 .B fwknop
406 client.  On the server side,
407 .B fwknopd
408 uses the variables MIN_TIME_DIFF
409 and MAX_TIME_DIFF to control whether the time delay actually means
410 something (i.e. if the MIN_TIME_DIFF is 2 seconds for a SOURCE block,
411 then the argument to the --time-delay option must be at least 2 at the
412 client side).
413 .TP
414 .BR \-u "\fR,\fP " \-\^\-user-rc\ \<rc-file>
415 The default connection rc file the
416 .B fwknop
417 client uses to know what shared port knocking sequence to send to a destination machine
418 is defined in the file
419 .I ~/.fwknoprc.
420 The path to this file can be changed with the
421 .B --user-rc
422 command line option.
423 .RE
424
425 .SH FILES
426 .TP
427 .B ~/.fwknop.run
428 Contains the last command line arguments that the
429 .B fwknop
430 client was invoked with.
431
432 .TP
433 .B ~/.fwknop.hosts
434 Contains the last command line arguments for individual hosts that the
435 .B fwknop
436 client has been used to gain access to.  By using the
437 .B --Last-host
438 switch, these arguments can be recalled and used.
439
440 .SH ENVIRONMENT:
441
442 .B GPG_AGENT_INFO
443 (only used in --gpg-agent mode).
444
445 .SH EXAMPLES:
446 The following examples illustrate the command line arguments that could
447 be supplied to the
448 .B fwknop
449 client in a few situations:
450
451 .B Access mode examples
452 .RS
453 Packet contents printed to stdout at the
454 .B fwknop
455 client when creating a 'access mode' SPA packet:
456 .PP
457         Random data: 7457916043504181
458         Username:    user_name
459         Timestamp:   1185272057
460         Version:     1.8.1
461         Action:      1 (access mode)
462         Access:      NNN.NNN.NNN.NNN,tcp/22
463         MD5 sum:     35rdd5f8tZTavUy0MuEdqw
464 .PP
465
466 Use the Single Packet Authorization mode to gain access to tcp/22 (ssh)
467 and udp/53 running on the system 10.0.0.123 from the IP 192.168.10.4:
468 .PP
469 .B $ fwknop -A 'tcp/22,udp/53' -a 192.168.10.4 -D 10.0.0.123
470 .PP
471 Same as above example, but gain access from whatever source IP is seen
472 by the fwknop server (useful if the fwknop client is behind a NAT device):
473 .PP
474 .B $ fwknop -A 'tcp/22,udp/53' -s -D 10.0.0.123
475 .PP
476 Same as above example, but use the IP identification website http://www.whatismyip.com/
477 to derive the client IP address.  This is a safer method of acquiring the client IP
478 address than using the
479 .B -s
480 option because the source IP is put within the encrypted
481 packet instead of having the
482 .B fwknopd
483 daemon grant the requested access from whatever IP address the SPA packet originates:
484 .PP
485 .B $ fwknop -A 'tcp/22,udp/53' -R -D 10.0.0.123
486 .PP
487 Use the Single Packet Authorization mode to gain access to tcp/22 (ssh)
488 and udp/53 running on the system 10.0.0.123, and use GnuPG keys to encrypt
489 and decrypt:
490 .PP
491 .B $ fwknop -A 'tcp/22,udp/53' --gpg-sign ABCD1234 --gpg--recipient 1234ABCD -R -D 10.0.0.123
492 .PP
493 Instruct the fwknop server running at 10.0.0.123 to allow 172.16.5.4 to
494 connect to TCP/22, but spoof the authorization packet from an IP associated
495 with www.yahoo.com:
496 .PP
497 .B # fwknop --Spoof-src 'www.yahoo.com' -A tcp/22 -a 172.16.5.4 -D 10.0.0.123
498 .PP
499 .RE
500
501 .B Command mode examples
502 .RS
503 .B NOTE:
504 Please ensure that ENABLE_CMD_EXEC; is set in the file
505 .I /etc/fwknop/access.conf
506 on the
507 .B fwknopd
508 server you are attempting to connect to.
509 Packet contents printed to stdout at the
510 .B fwknop
511 client when creating a 'command mode' SPA packet:
512 .PP
513         Random data: 1387393943305159
514         Username:    user_name
515         Timestamp:   1185349703
516         Version:     1.8.1
517         Action:      0 (command mode)
518         Cmd:         echo "The commands sent - minus quote charaters around the command" & sleep 10; echo "The End"
519         MD5 sum:     fJtQkAcK1A1XMRAHEG1UcA
520 .PP
521 Instruct the fwknop server running at 10.0.0.123 to send a single ICMP
522 echo request to www.yahoo.com:
523 .PP
524 .B $ fwknop --Server-cmd 'ping -c 1 www.yahoo.com' -D 10.0.0.123
525 .PP
526 .RE
527
528 .B Port-knock mode (legacy) examples
529 .RS
530 This connection mode is a legacy mode and is
531 .B not
532 the preferred or recommended mode.
533
534 Packet contents printed to stdout at the
535 .B fwknop
536 client when in 'port-knock mode':
537 <TODO>
538
539 Send an encrypted knock sequence to the IP "10.0.0.123" instructing the
540 fwknop daemon running there to open tcp port 22 to source address
541 192.168.10.4:
542 .PP
543 .B $ fwknop --Server-mode 'knock' -A tcp/22 -a 192.168.10.4 -D 10.0.0.123
544 .PP
545 Same as above, but this time instruct the remote fwknop daemon to open
546 tcp port 22 to whatever source address the encrypted sequence originates
547 from (useful if the fwknop client is behind a NAT device):
548 .PP
549 .B $ fwknop --Server-mode 'knock' -A tcp/22 -s -D 10.0.0.123
550 .PP
551 Same as above, but rotate the knock sequence through the tcp and udp
552 protocols (remember that iptables must be configured to log both tcp and
553 udp packets to the default port range of 61000-61255):
554 .PP
555 .B $ fwknop --Server-mode 'knock' -A tcp/22 -s -r -D 10.0.0.123
556 .PP
557 Same as above, but change the base port for the encrypted sequence to
558 55000 (the default is 61000):
559 .PP
560 .B $ fwknop --Server-mode 'knock' -A tcp/22 -s -r --offset 55000 -D 10.0.0.123
561 .PP
562 Send a shared knock sequence to the IP 10.11.11.123.  The fwknop client
563 will read the sequence out of the file
564 .B ~/.fwknoprc
565 and the server will read the sequence out of
566 .B /etc/fwknop/access.conf:
567 .PP
568 .B $ fwknop --Server-mode 'knock' -D 10.11.11.123
569 .RE
570
571 .SH DEPENDENCIES
572 .B fwknop
573 requires perl.  To take advantage of all of the authentication and access management features of the
574 .B fwknopd
575 daemon/service a functioning iptables firewall is required on the underlying
576 operating system.  If fwknop is being run in the legacy port knocking mode,
577 then iptables must log packets via syslog, and ideally the
578 .B --log-tcp-options
579 argument will be specified in the iptables logging rule so that the
580 .B fwknopd
581 daemon/service will
582 be able to use a strategy similar to
583 .B p0f
584 to passively fingerprint operating systems.
585
586 .SH DIAGNOSTICS
587 .B fwknop
588 can be run in debug mode with the
589 .B --debug
590 command line option.  This will
591 disable daemon mode execution, and print verbose information to the screen
592 on STDERR as packets are received.
593
594 .SH "SEE ALSO"
595 .BR fwknopd (8),
596 .BR iptables (8),
597 .BR gpg (1),
598 .BR gpg-agent (1),
599 .BR knopmd (8),
600 .BR knopwatchd (8)
601 .BR p0f (1),
602 More information on the
603 differences between port knocking and Single Packet Authorization can be found
604 in the paper "Single Packet Authorization with fwknop" available here:
605 .B http://www.cipherdyne.org/fwknop/docs/SPA.html
606
607 .SH AUTHOR
608 Michael Rash <mbr@cipherdyne.org>
609
610 .SH CREDITS
611 The phrase "Single Packet Authorization" was coined by MadHat, see:
612 .B http://www.nmrc.org/
613 The term "port knocking" was coined by Martin Krzywinski, see:
614 .B http://www.portknocking.org/
615  The original p0f passive OS fingerprinter was written by Michal Zalewski, and is
616 available here:
617 .B http://lcamtuf.coredump.cx/p0f.shtml
618
619 .SH BUGS
620 Send bug reports to mbr@cipherdyne.org.  Suggestions and/or comments are
621 always welcome as well.
622
623 .SH DISTRIBUTION
624 .B fwknop
625 is distributed under the GNU General Public License (GPL), and the latest
626 version may be downloaded from
627 .B http://www.cipherdyne.org/
628
629
Note: See TracBrowser for help on using the browser.