FWKNOP(8)
β¨ NAME β¨
fwknop β the Firewall Knock Operator π
(Also: this is FWKNOP(8), the Fwknop Client page, bestie. Part one of a whole saga, so buckle up π)
πΈ SYNOPSIS πΈ
fwknop -A <'proto/ports'> -R|-a|-s -D <'host'> [options]
π¦ DESCRIPTION π¦
Okay so picture this: fwknop runs a whole authorization scheme called Single Packet Authorization (SPA) and it exists purely so your services can be strongly concealed. We're talking one (1) single packet. It's encrypted, it's non-replayable, and it's authenticated via an HMAC, and that one lil packet is how you tell a service sitting behind a firewall in a default-drop filtering stance that you'd like in, please π
The main character application of SPA? Using a firewall to drop all attempts to connect to stuff like SSH, which makes exploiting vulnerabilities (both 0-day and unpatched code, yikes π) way harder. And here's the slay: any service concealed by SPA naturally cannot be scanned for with Nmap. Periodt. π‘οΈ
The fwknop project natively supports four different firewalls: iptables, firewalld, PF, and ipfw, across Linux, OpenBSD, FreeBSD, and Mac OS X. There's also support for custom scripts, so you can make fwknop support other infrastructure like ipset or nftables. Versatile icon behavior β¨
SPA is essentially next generation Port Knocking (PK), except it solves sooo many of the limitations PK is out here exhibiting while keeping its core benefits. Like, PK's limitations include:
- it's generally difficult to protect against replay attacks,
- asymmetric ciphers and HMAC schemes are not usually possible to reliably support, and
- it is trivially easy to mount a DoS attack against a PK server just by spoofing an additional packet into a PK sequence as it traverses the network β thereby convincing the PK server that the client doesn't know the proper sequence π
All of these limitations are solved by SPA. Meanwhile SPA hides services behind a default-drop firewall policy, acquires SPA data passively (usually via libpcap or other means), and implements standard cryptographic operations for SPA packet authentication and encryption/decryption. No cap.
This is the manual page for the fwknop client, which is the one responsible for constructing SPA packets and sending them over the network π« The server side is implemented by the fwknopd daemon, which sniffs the network for SPA packets and interacts with the local firewall to allow SPA authenticated connections. Highly recommend you read the fwknopd(8) manual page as well, bestie β it's giving required reading π
Further detailed information may be found in the tutorial "Single Packet Authorization: A Comprehensive Guide to Strong Service Concealment with fwknop", available online (see: http://www.cipherdyne.org/fwknop/docs/fwknop-tutorial.html).
SPA packets generated by fwknop leverage HMAC for authenticated encryption in the encrypt-then-authenticate model π
Although the usage of an HMAC is currently optional (enabled via the --use-hmac command line switch), it is highly recommended for three reasons:
- without an HMAC, cryptographically strong authentication is not possible with
fwknopunless GnuPG is used β but even then an HMAC should still be applied; - an HMAC applied after encryption protects against cryptanalytic CBC-mode padding oracle attacks such as the Vaudenay attack and related trickery (like the more recent "Lucky 13" attack against SSL); and
- the code required by the
fwknopddaemon to verify an HMAC is much more simplistic than the code required to decrypt an SPA packet, so an SPA packet without a proper HMAC isn't even sent through the decryption routines.
Reason 3) is why an HMAC should still be used even when SPA packets are encrypted with GnuPG β because SPA data is not sent through libgpgme functions unless the HMAC checks out first. GnuPG and libgpgme are relatively complex bodies of code, and therefore limiting the ability of a potential attacker to interact with this code through an HMAC operation helps to maintain a stronger security stance π‘οΈβ¨
Generating an HMAC for SPA communications requires a dedicated key in addition to the normal encryption key, and both can be generated with the --key-gen option ππ
fwknop encrypts SPA packets either with the Rijndael block cipher or via GnuPG and associated asymmetric cipher.
If the symmetric encryption method is chosen, then as usual the encryption key is shared between the client and server (see the fwknopd /etc/fwknop/access.conf file for details). The actual encryption key used for Rijndael encryption is generated via the standard PBKDF1 key derivation algorithm, and CBC mode is set.
If the GnuPG method is chosen, then the encryption keys are derived from GnuPG key rings.
SPA packets generated by fwknop running as a client adhere to the following format (before encryption and the HMAC is applied):
random data (16 digits)
username
timestamp
software version
mode (command mode (0) or access mode (1))
if command mode => command to execute
else access mode => IP,proto,port
message digest (SHA512 / SHA384 / SHA256 / SHA1 / MD5 / SHA3_256 / SHA3_512)
Each of the above fields are separated by a ":" character due to the variable length of several of the fields, and those that might contain ":" characters are base64 encoded.
The message digest (SHA256 by default) is part of the data to be encrypted and is independent of the HMAC which is appended to the SPA packet data after encryption.
The 16 digits of random data (about 53 bits) ensures that no two SPA packets are identical, and this is in addition to and independent of using PBKDF1 for key derivation for Rijndael in CBC mode (which uses an 8-byte random "salt" value) π§
Because fwknopd tracks the SHA256 digest of all incoming valid SPA packets and throws out duplicates, replay attacks are not feasible against fwknop π
ββοΈ Syslog alerts are generated if a replay is detected. Not me catching you trying to replay π
By default, the fwknop client sends authorization packets over UDP port 62201, but this can be altered with the --server-port argument (this requires fwknopd to be configured to acquire SPA data over the selected port). Also, fwknop can send the SPA packet over a random port via the --rand-port argument π² See fwknopd(8) for further details. See the EXAMPLES section for example invocations of the fwknop client.
The fwknop client is quite portable, and is known to run on various Linux distributions (all major distros and embedded ones such as OpenWRT as well), FreeBSD, OpenBSD, Mac OS X, and Cygwin on Windows πͺβ¨
There is also a library libfko that both fwknop and fwknopd use for SPA packet encryption/decryption and HMAC authentication operations. This library can be used to allow third party applications to use SPA subject to the terms of the GNU General Public License (GPL v2+).
π REQUIRED ARGUMENTS π
These required arguments can be specified via command-line or from within the ~/.fwknoprc file (see -n, --named-config option and the FWKNOPRC FILE section below) π
-A,--access=<port list>β Hand over a list of ports and protocols to access on a remote computer runningfwknopd. The format of this list is+<proto>/<port>...<proto>/<port>+, e.g.tcp/22,udp/53.
NOTE: The vast majority of usages forfwknoprequire the-Aargument, but sending full commands with the--server-cmdargument via an SPA packet to be executed byfwknopddoes not require this argument. π
-D,--destination=<hostname/IP-address>β Direct thefwknopclient to authenticate with thefwknopddaemon/service at the specified destination hostname or IP address π The connection mode is discovered by thefwknopddaemon/service when it decrypts and parses the authentication packet.-R|-a|-sβ One of these options (see below) is required to tell the remotefwknopddaemon what IP should be allowed through the firewall πͺ
It is recommend to use the -R or -a options instead of -s in order to harden SPA communications against possible Man-In-The-Middle (MITM) attacks, and on the server side set the REQUIRE_SOURCE_ADDRESS variable in the /etc/fwknop/access.conf file.
Important: note that the most secure option is-aso thatfwknopdoes not have to issue any HTTPS request tohttps://www.cipherdyne.org/cgi-bin/myipin order to resolve the externally routable IP address. Using-arequires that the user already knows what the external IP is for the network wherefwknopis running. iykyk π«Ά
β¨ GENERAL OPTIONS β¨
okay bestie, this is the general-options era, and there are so many little switches. let's get into it. π
-h,--helpβ prints a usage summary message and exits. bye bestie, but usefully. π-G,--get-key=<file>β loads an encryption key/password from the specified file. the key file has one line for each destination hostname or IP address, then a colon (":"), then optional space, then the password, then a newline. note that the last line has to have a terminating newline character. also note: even though this is convenient, having a file on your system with clear text passwords is not a good idea and is not recommended. having thefwknopclient prompt you for the key is generally more secure. and note also that if a key is stored on disk, thefwknoprc file is a more powerful mechanism for specifying not only the key but other options as well. π«£--stdinβ reads the encryption key/password from stdin. you can use this to send the data via a pipe, for example. this command is similar to--fd 0.--fd=<number>β specifies the file descriptor number to read the key/password from. this command avoids the user being prompted for a password if none has been found in the user specific stanza, or none has been supplied on the command line. a file descriptor set to0is similar to the stdin command.--get-hmac-key=<file>β loads an HMAC key/password from the specified file. similarly to the format for the--get-keyoption, the HMAC key file contains a line for each destination hostname or IP address, a colon (":"), optional space and the password, followed by a newline. note that the last line has to have a terminating newline character. also note: though this is a convenience, having a file on your system with clear text passwords is not a good idea and is not recommended. having thefwknopclient prompt you for the HMAC key is generally more secure. note also that if a key is stored on disk, thefwknoprc file is a more powerful mechanism for specifying not only the HMAC key but other options as well. π«Ά--key-genβ havefwknopgenerate both Rijndael and HMAC keys that can be used for SPA packet encryption and authentication. these keys are derived from/dev/urandomand then base64 encoded before being printed to stdout, and are meant to be included within theβ$HOME/.fwknoprcβfile (or the file referenced by--get-key). such keys are generally more secure than passphrases that are typed in from the command line. πβ¨--key-gen-file=<file>β writes generated keys to the specified file. note that the file is overwritten if it already exists. if this option is not given, then--key-genwrites the keys to stdout.--key-len=<length>β specifies the number of bytes for a generated Rijndael key. the maximum size is currently128bytes.--hmac-key-len=<length>β specifies the number of bytes for a generated HMAC key. the maximum size is currently128bytes.-l,--last-cmdβ executesfwknopwith the command-line arguments from the previous invocation (if any). the previous arguments are parsed out of the~/.fwknop.runfile. π°οΈ-n,--named-config=<stanza name>β specifies the name of the configuration stanza in theβ$HOME/.fwknoprcβfile to pull configuration and command directives. these named stanzas alleviate the need for remembering the various command-line arguments for frequently used invocations offwknop. see the section labeled,FWKNOPRC FILEbelow for a list of the valid configuration directives in the.fwknoprcfile.--key-rijndael=<key>β specifies the Rijndael key on the command line. since the key may be visible to utilities such aspsunder Unix, this form should only be used where security is not critical. having thefwknopclient either prompt you for the key or acquire via theβ$HOME/.fwknoprcβfile is generally more secure. π--key-base64-rijndael=<key>β specifies the base64 encoded Rijndael key. since the key may be visible to utilities such aspsunder Unix, this form should only be used where security is not critical. having thefwknopclient either prompt you for the key or acquire via theβ$HOME/.fwknoprcβfile is generally more secure.--key-base64-hmac=<key>β specifies the base64 encoded HMAC key. since the key may be visible to utilities such aspsunder Unix, this form should only be used where security is not critical. having thefwknopclient either prompt you for the key or acquire via theβ$HOME/.fwknoprcβfile is generally more secure.--key-hmac=<key>β specifies the raw HMAC key (not base64 encoded). since the key may be visible to utilities such aspsunder Unix, this form should only be used where security is not critical. having thefwknopclient either prompt you for the key or acquire via theβ$HOME/.fwknoprcβfile is generally more secure.--rc-file=<file>β specifies the path to thefwknoprc file. default isβ$HOME/.fwknoprcβ.--no-rc-fileβ performsfwknopclient operations without referencing theβ$HOME/.fwknoprcβfile.--no-home-dirβ does not allow thefwknopclient to look for the home directory associated with the user.--save-rc-stanza=<stanza name>β saves command line arguments to theβ$HOME/.fwknoprcβstanza specified with the-noption. if the-noption is omitted, then the stanza name will default to the destination server value (hostname or IP) given with the-Dargument.--force-stanzaβ used with--save-rc-stanzato overwrite all of the variables for the specified stanza.--stanza-listβ dumps a list of the stanzas found inβ$HOME/.fwknoprcβ. π--show-lastβ displays the last command-line arguments used byfwknop.-E,--save-args-file=<file>β saves command line arguments to a specified file path. without this option, and when--no-save-argsis not also specified, then the default save args path is~/.fwknop.run.--no-save-argsβ does not save the command line arguments given whenfwknopis executed.-T,--testβ test mode. generate the SPA packet data, but do not send it. instead, print a break-down of the SPA data fields, then run the data through the decryption and decoding process and print the break-down again. this is primarily a debugging feature. π§ͺ-B,--save-packet=<file>β instructs thefwknopclient to write a newly created SPA packet out to the specified file so that it can be examined off-line.-b,--save-packet-appendβ appends the generated packet data to the file specified with the-Boption.--fault-injection-tag=<tag>β this option is only used for fault injection testing whenfwknopis compiled to support the libfiu library (see:http://blitiri.com.ar/p/libfiu/). under normal circumstances this option is not used, and any packaged version offwknopwill not have code compiled in so this capability is not enabled at run time. it is documented here for completeness.-v,--verboseβ runs thefwknopclient in verbose mode. this causesfwknopto print some extra information about the current command and the resulting SPA data.-V,--versionβ displays version information and exits.
π₯ SPA OPTIONS π₯
these are the options that get real specific about SPA packet behavior. main character energy only. π
--use-hmacβ sets HMAC mode for authenticated encryption of SPA communications. as offwknop 2.5, this is an optional feature, but this will become the default in a future release.-a,--allow-ip=<IP-address>β specifies an IP address that should be permitted through the destinationfwknopdserver firewall (this IP is encrypted within the SPA packet itself). this is useful to prevent a MITM attack where a SPA packet can be intercepted en-route and sent from a different IP than the original. hence, if thefwknopdserver trusts the source address on the SPA packet IP header then the attacker gains access. the-aoption puts the source address within the encrypted SPA packet, and so thwarts this attack. the-aoption is also useful to specify the IP that will be granted access when the SPA packet itself is spoofed with the--spoof-srcoption. another related option is-R(see below) which instructs thefwknopclient to automatically resolve the externally routable IP address the local system is connected to by queryinghttps://www.cipherdyne.org/cgi-bin/myip. this returns the actual IP address it sees from the calling system. π‘οΈ-g,--gpg-encryptionβ uses GPG encryption on the SPA packet. default if not specified is Rijndael. note: use of this option will also require a GPG recipient (see--gpg-recipientalong with other GPG-related options below).--hmac-digest-type=<digest>β sets the HMAC digest algorithm for authenticated encryption of SPA packets. choices are:MD5,SHA1,SHA256(the default),SHA384,SHA512,SHA3_256, andSHA3_512.-N,--nat-access=<internalIP:forwardPort>β thefwknopdserver offers the ability to provide SPA access through an iptables firewall to an internal service by interfacing with the iptables NAT capabilities. so, if thefwknopdserver is protecting an internal network on an RFC-1918 address space, an externalfwknopclient can request that the server port forward an external port to an internal IP, i.e.+--NAT-access 192.168.10.2,55000+. in this case, access will be granted to192.168.10.2via port55000to whatever service is requested via the--accessargument (usuallytcp/22). hence, after sending such an SPA packet, one would then dossh -p 55000 user@hostand the connection would be forwarded on through to the internal192.168.10.2system automatically. note that the portβ55000βcan be randomly generated via the--nat-rand-portargument (described later). π--nat-localβ on thefwknopdserver, a NAT operation can apply to the local system instead of being forwarded through the system. that is, for iptables firewalls, a connection to, say, port55,000can be translated to port22on the local system. by making use of the--nat-localargument, thefwknopclient can be made to request such access. this means that any external attacker would only see a connection over port55,000instead of the expected port22after the SPA packet is sent. π--nat-portβ okay so normally you're out here requesting access to a specific port liketcp/22on a box runningfwknopd. But--nat-portlets you request access to that port (yes,tcp/22again, keep up bestie) while the access gets granted through a different, specified port β so the-pargument is what you'd then use on your SSH client command line. Want the full lore on reaching services via a NAT operation? Go peep--nat-localand--nat-access. π¦--nat-rand-portβ same energy as above, but make it chaotic: you request access to a particular service (yeah,tcp/22), and the access gets granted through a random translated port. So once you run thefwknopclient in this mode and it shows you the random port it picked, you gotta go change the destination port your follow-on client uses to match. For SSH, that's the-pargument doing the work. Again,--nat-localand--nat-accesshave the extra deets on NAT-based service access. β¨-p,--server-port=<port>β tell it which portfwknopdaccepts packets on vialibpcapor theulogdpcap writer. Default vibe:fwknopdlooks for authorization packets over UDP port 62201. π-P,--server-proto=<protocol>β sets the protocol for the outgoing SPA packet. Your options areudp,tcp,http,udpraw,tcpraw, oricmp. Heads up: theudpraw,tcpraw, andicmpmodes use raw sockets, so they require root access to run, no cap. Also:tcpmode expects to establish a TCP connection to the server before sending the SPA packet. That's not normally done, but it's useful for compatibility with Tor for strong anonymity β seehttp://tor.eff.org/. In that case yourfwknopdserver needs to be configured to listen on the target TCP port (which is62201by default). π§-Q,--spoof-src=<IP>β spoof the source address thefwknopclient sends SPA packets from. This needs root on the client side since a raw socket is required to pull it off. Ngl, in this mode you can also pass the--spoof-userargument to satisfy anyREQUIRE_USERNAMEkeyword that might be sitting in/etc/fwknop/access.conf. π-r,--rand-portβ tells thefwknopclient to send an SPA packet over a random destination port between 10,000 and 65535. Yourfwknopdserver must use aPCAP_FILTERvariable configured to accept those packets. For example,PCAP_FILTERcould be set toudp dst portrange 10000-65535. π₯-R,--resolve-ip-httpsβ this one's important, bestie. It tells thefwknopclient to fire an HTTPS request at a script running oncipherdyne.orgthat returns the client's IP address (as the web server sees it). Sometimes you need this to figure out which IP address should be allowed through the firewall policy on the remotefwknopdside. It's a lifesaver when yourfwknopclient is behind some obscure NAT address and the external internet-facing IP is a mystery to the user. The full resolution URL ishttps://www.cipherdyne.org/cgi-bin/myip, andfwknophits it viawgetin--secure-protocolmode. But ngl, it's generally more secure to use-aif the externally routable IP address for the client is already known to the user, since that skips the whole HTTPS request thing entirely. πΈ--resolve-url <url>β override the default URL used for resolving the source IP address. For best results, point this at a web service that returns just an IP address in the body of the HTTP response. Keep it clean, keep it simple. β¨--resolve-http-onlyβ forces thefwknopclient to resolve the external IP via HTTP instead of HTTPS. There are some circumstances where this might be necessary, like whenwgetisn't available (or wasn't compiled with SSL support), but generally this is not recommended since it opens up the possibility of a MITM attack through manipulation of the IP resolution HTTP response. Either specify the IP manually with-a, or use-Rand omit this option. Periodt. π-w,--wget-cmd=<wget full path>β manually set the full path to thewgetcommand. Normally theconfigurescript findswgetfor you, but this option exists for when it's chilling in a non-standard place. π-s,--source-ipβ tells thefwknopclient to form an SPA packet containing the special-case IP address0.0.0.0, which informs the destinationfwknopdSPA server to use the source IP address the SPA packet originates from as the IP that gets allowed through once the firewall ruleset is modified. Useful if yourfwknopclient is deployed on a machine behind a NAT device and the external IP is unknown. However, usage of this option is not recommended β use either-aor-Rinstead. Also note: the permit-address options-s,-Rand-aare mutually exclusive, so pick one and commit. π-S,--source-port=<port>β set the source port for the outgoing SPA packet. That's it, that's the vibe. π--server-resolve-ipv4β forces thefwknopclient to only accept an IPv4 address from DNS when a hostname is used for the SPA server. Necessary in some cases where DNS is being messy and returning both IPv6 and IPv4 addresses. π-f,--fw-timeout=<seconds>β specifies how long (in seconds) the remote firewall rule granting access to a service stays active. The default maintained byfwknopdis 30 seconds, but any established connection can be kept open after the initial accept rule is deleted, thanks to a connection tracking mechanism that your firewall may offer. π-C,--server-cmd=<command to execute>β instead of requesting access to a service with an SPA packet, this specifies a command that thefwknopdserver will execute. The command is encrypted inside the SPA packet and sniffed off the wire (as usual, bestie) byfwknopd. π₯-H,--http-proxy=<proxy-host>[:port]β specify an HTTP proxy thefwknopclient will use to send the SPA packet through. Using this option automatically sets the SPA packet transmission mode (usually set via--server-proto) tohttp. You can also specify the proxy port by tacking:<port>onto the proxy host name or ip. π¦-m,--digest-type=<digest>β pick the message digest algorithm used in the SPA data. Choices are:MD5,SHA1,SHA256(the default),SHA384, andSHA512,SHA3_256, andSHA3_512. π-M,--encryption-mode=<mode>β specify the encryption mode when AES is used for encrypting SPA packets. Default isCBCmode, but you can choose others likeCFBorOFBβ as long as that's also specified in/etc/fwknop/access.confon the server side via theENCRYPTION_MODEvariable. In general, it's recommended to not include this argument and just let the default (CBC) do its thing. Also: you can pass the stringlegacyto generate SPA packets with the old initialization vector strategy used byfwknopversions prior to2.5. With the2.5release,fwknopgenerates initialization vectors in a manner compatible with OpenSSL via thePBKDF1algorithm. π--time-offset-plus=<time>β by default, thefwknopddaemon on the server side enforces time synchronization between the clocks running on client and server systems. Thefwknopclient places the local time inside each SPA packet as a time stamp, validated by thefwknopdserver after decryption. But sometimes the clocks are out of sync and the user on the client system doesn't have the access needed to change the local clock setting, which makes it lowkey hard to construct an SPA packet with a time stamp the server will accept. Enter--time-offset-plus, which lets you specify an offset (like60sec,60min,2days, etc.) that gets added to the local time. β--time-offset-minus=<time>β same as--time-offset-plusabove, but it subtracts the specified time offset instead of adding it to the local time stamp. Symmetry, we love her. β¨-u,--user-agent=<user-agent-string>β set the HTTPUser-Agentfor resolving the external IP via-R, or for sending SPA packets over HTTP. π--use-wget-user-agentβ by default, when thefwknopclient resolves the external IP withwgetvia SSL, it sets theUser-AgenttoFwknop/<version>unless it was already manually specified with the--user-agentoption mentioned above. However, the--user-wget-user-agentoption lets the defaultwgetUser-Agentstring apply, without any influence fromfwknop. π«Ά-U,--spoof-user=<user>β specify the username that gets included within the SPA packet. This lets thefwknopclient satisfy any non-rootREQUIRE_USERNAMEkeyword on thefwknopdserver (and psst:--spoof-srcmode requires thefwknopclient to be executed as root). π--icmp-type=<type>β in-P icmpmode, specify the ICMP type value that gets set in the SPA packet ICMP header. The default isecho reply. π§--icmp-code=<code>β in-P icmpmode, specify the ICMP code value that gets set in the SPA packet ICMP header. The default iszero. πΈ
π GPG OPTIONS π
okay bestie listen up, because this part is important π First things first: using GPG for SPA encryption/decryption can and should involve GPG keys that are signed by each side (client and server, both of them, no skipping π ). The basic procedure for this, after the client key has been transferred to the server and vice-versa, goes like this:
[spaserver]# gpg --import client.asc
[spaserver]# gpg --edit-key 1234ABCD
Command> sign
[spaclient]$ gpg --import server.asc
[spaclient]$ gpg --edit-key ABCD1234
Command> sign
If you want the full lore, more comprehensive info lives here: http://www.cipherdyne.org/fwknop/docs/gpghowto.html.
--gpg-agentβ tells fwknop to go get the GnuPG key password from a runninggpg-agentinstance (if one is available, that is π§).--gpg-home-dir=<dir>β point fwknop at the path to the GnuPG directory. Normally this path gets derived from the home directory of whoever's running the fwknop client (so the default is~/.gnupg). This is lowkey a lifesaver when a "root" user wants to log into a remote machine whosesshddaemon/service does not permit root login πΈ.--gpg-recipient=<key ID or Name>β specify the GnuPG key ID, e.g.1234ABCD(peep the output ofgpg --list-keys), or the key name (the associated email address) of the recipient of the Single Packet Authorization message. The fwknopd server imports this key and the associated private key is what decrypts the SPA packet. Heads up though: the recipient's key has to be imported into the client GnuPG key ring first π.--gpg-signer-key=<key ID or Name>β specify the GnuPG key ID, e.g.ABCD1234(again, see the output ofgpg --list-keys), or the key name to use when signing the SPA message. You'll get prompted for the associated GnuPG password so the signature can be created. This is the glow-up that adds a cryptographically strong mechanism letting the fwknopd daemon on the remote server authenticate who created the SPA message π₯.--gpg-no-signing-pwβ tells fwknop to not acquire a passphrase for usage of the GnuPG signing key. This option exists to make SPA packet construction easier for client-side operations in automated environments where the passphrase for the signing key has been removed from the GnuPG key ring. Buuut it is usually better to leveragegpg-agentinstead of using this option, fr fr π.
π FWKNOPRC FILE π
The .fwknoprc file is what you use to set various parameters that override default program parameters at runtime. It also lets you make additional named configuration stanzas for setting program parameters for a particular invocation π.
The fwknop client will create this file if it doesn't already exist in the user's home directory. This initial version has some sample directives that are commented out, and it is up to you, the user, to edit this file to meet your needs.
The .fwknoprc file contains a default configuration area or stanza which holds global configuration directives that override the program defaults. You can edit this file and create additional named stanzas that can be specified with the -n or --named-config option. Parameters defined in the named stanzas will override any matching default stanza directives. Note that command-line options will still override any corresponding .fwknoprc directives β command line stays undefeated, periodt π
.
There are directives to match most of the command-line parameters fwknop supports. Here's the current list of each directive, along with a brief description and its matching command-line option(s):
SPA_SERVER <hostname/IP-address>β specify the hostname or IP of the destination (fwknopd) server (-D,--destination).ALLOW_IP <IP-address>β specify the address to allow within the SPA data. Note: this parameter covers the-a,-s, and-Rcommand-line options. You can specify a hostname or IP address (the-aoption), specify the wordsourceto tell the fwknopd server to accept the source IP of the packet as the IP to allow (the-soption), or use the wordresolveto have fwknop resolve the external network IP via HTTP request (the-Roption) π.ACCESS <port list>β set the one or more protocol/ports to open on the firewall (-A,--access). The format of this list is<proto>/<port>...<proto>/<port>, e.g.tcp/22,udp/53.SPA_SERVER_PORT <port>β set the server port to use for sending the SPA packet (-p,--server-port).SPA_SERVER_PROTO <protocol>β set the protocol to use for sending the SPA packet (-P,--server-proto).KEY <passphrase>β this is the passphrase used for SPA packet encryption, and it applies to both Rijndael or GPG encryption modes. The actual encryption key used for Rijndael is derived from the PBKDF1 algorithm, and the GPG key is derived from the specified GPG key ring π.KEY_BASE64 <base64 encoded passphrase>β specify the encryption passphrase as a base64 encoded string. This is how you sneak non-ascii characters into the base64-decoded key β¨.USE_HMAC <Y/N>β set HMAC mode for authenticated encryption of SPA packets. This makes fwknop prompt the user for a dedicated HMAC key that is independent of the encryption key. Alternatively, the HMAC key can be specified with theHMAC_KEYorHMAC_KEY_BASE64directives (see below π).HMAC_KEY <key>β specify the HMAC key for authenticated encryption of SPA packets. This supports both Rijndael and GPG encryption modes, and is applied according to the encrypt-then-authenticate model.HMAC_KEY_BASE64 <base64 encoded key>β specify the HMAC key as a base64 encoded string. Again: non-ascii characters, base64-decoded key, you know the vibe π.HMAC_DIGEST_TYPE <digest algorithm>β set the HMAC digest algorithm used for authenticated encryption of SPA packets. Choices are:MD5,SHA1,SHA256(the default),SHA384,SHA512,SHA3_256, andSHA3_512.SPA_SOURCE_PORT <port>β set the source port to use for sending the SPA packet (-S,--source-port).FW_TIMEOUT <seconds>β set the firewall rule timeout value (-f,--fw-timeout).RESOLVE_IP_HTTPS <Y/N>β set toYto automatically resolve the externally routable IP associated with the fwknop client. This is done over SSL via wget in--secure-protocolmode against the IP resolution service available athttps://www.cipherdyne.org/cgi-bin/myipπ¦.RESOLVE_HTTP_ONLY <Y/N>β when the fwknop client is instructed to resolve the external client IP, this option can be used to force an HTTP connection instead of an HTTPS connection when set toY. Super handy when wget isn't installed on the local OS, or when it isn't compiled against an SSL library.RESOLVE_URL <url>β set to a URL that will be used for resolving the source IP address (--resolve-url).WGET_CMD <wget full path>β set the full path to the wget command (used for client IP resolution).TIME_OFFSET <time>β set a value to apply to the timestamp in the SPA packet. This can be either a positive or negative value (--time-offset-plus/minus).ENCRYPTION_MODE <mode>β specify the encryption mode when AES is used. This variable is a synonym for the-M,--encryption-modecommand line argument. In general, it's recommended to not include this argument and just let the default (CBC) apply. Note that the stringlegacycan be specified in order to generate SPA packets with the old initialization vector strategy used by versions of fwknop prior to2.5π.DIGEST_TYPE <digest algorithm>β set the SPA message digest type (-m,--digest-type). Choices are:MD5,SHA1,SHA256(the default),SHA384,SHA512,SHA3_256, andSHA3_512.USE_GPG <Y/N>β set toYto specify the use of GPG for encryption (--gpg-encryption).USE_GPG_AGENT <Y/N>β set toYto have fwknop interface with a GPG agent instance for the GPG key password (--gpg-agent). The agent information itself is specified with theGPG_AGENT_INFOenvironmental variable.GPG_SIGNING_PW <passphrase>β this is the passphrase used for signing SPA packet data in GPG encryption mode, and it's a synonym for theKEYvariable (i.e. the signing passphrase can be specified with theKEYvariable instead). The SPA packet is encrypted with the remote server key and signed with the local client key π.GPG_SIGNING_PW_BASE64 <base64 encoded passphrase>β specify the GPG signing passphrase as a base64 encoded string. Yes, non-ascii characters in the base64-decoded key, you already know πΈ.GPG_SIGNER <key ID or Name>β specify the GPG key name or ID for signing the GPG-encrypted SPA data (--gpg-signer-key).GPG_RECIPIENT <key ID or Name>β specify the GPG key name or ID for the recipient of the GPG-encrypted SPA data (--gpg-recipient-key).GPG_HOMEDIR <dir>β specify the GPG home directory (--gpg-home-dir). Defaults to~/.gnupg.GPG_EXE <path>β specify the path to GPG (--gpg-exe). Defaults to/usr/bin/gpg.SPOOF_USER <user>β set the username in the SPA data to the specified value (-U,--spoof-user).SPOOF_SOURCE_IP <IP>β set the source IP of the outgoing SPA packet to the specified value (-Q,--spoof-source).RAND_PORT <Y/N>β send the SPA packet over a randomly assigned port (-r,--rand-port).KEY_FILE <file>β load an encryption key/password from a file (-G,--get-key).HTTP_USER_AGENT <agent string>β set the HTTP User-Agent for resolving the external IP via-R, or for sending SPA packets over HTTP (-u,--user-agent).USE_WGET_USER_AGENT <Y/N>β allow the default wget User-Agent string to be used when resolving the external IP instead of a User-Agent supplied by the fwknop client.NAT_ACCESS <internalIP:forwardPort>β gain NAT access to an internal service protected by the fwknop server (-N,--nat-access).NAT_LOCAL <Y/N>β access a local service via a forwarded port on the fwknopd server system (--nat-local).NAT_PORT <port>β specify the port to forward to access a service via NAT (--nat-port).NAT_RAND_PORT <Y/N>β have the fwknop client assign a random port for NAT access (--nat-rand-port).
π ENVIRONMENT π
SPOOF_USERGPG_AGENT_INFO(only used in--gpg-agentmode)
that's the whole env lineup bestie, short and sweet π«Ά
π SPA PACKET SPOOFING π
okay so here's the tea bestie: fwknop tucks the IP that's supposed to get through the firewall inside the encrypted SPA payload β unless you use -s, which is not recommended and can even be straight-up prohibited in the fwknopd server config. so because of that, SPA packets can be spoofed super easily, and in this context that's actually iconic. π
fr fr: the source IP of an SPA packet gets ignored by the fwknopd daemon (when the REQUIRE_SOURCE_ADDRESS variable is set in the /etc/fwknop/access.conf file) and the only IP that gets granted firewall access is the one sitting inside an authenticated and properly decrypted SPA packet. so you can make it look like, say, www.yahoo.com is trying to authenticate to a target system, when actually the real connection is coming from some seemingly unrelated IP. main character energy honestly. π
β¨ EXAMPLES β¨
here's what the command line args could look like in a few situations, bestie:
πΈ Quick start πΈ
the most effective and easiest way to use fwknop is to have the client generate both an encryption key and an HMAC key, then save them to the "$HOME/.fwknoprc" file along with your access request specifics. you'll also need to transfer those keys over to the system where fwknopd is running. and the client supports a separate set of encryption and HMAC keys for each SPA destination if you've got multiple fwknopd servers running on different systems. π¦
so, assuming the IP 2.2.2.2 is the system where fwknopd is deployed, and SSH is protected by the firewall on that system in a default-drop stance, run the client like so to generate encryption and HMAC keys:
$ fwknop -A tcp/22 --use-hmac -R -D 2.2.2.2 --key-gen --save-rc-stanza --verbose
[+] Wrote Rijndael and HMAC keys to rc file: /home/user/.fwknoprc
with the access request arguments and encryption and HMAC keys generated and saved in "$HOME/.fwknoprc", the keys themselves need to be transferred to the 2.2.2.2 system where fwknopd is running. as always, do this via some secure means such as SSH before SPA is enabled and SSHD is blocked by the firewall. here's what the new 2.2.2.2 stanza looks like in the ~/.fwknoprc file:
$ tail -n 8 /home/user/.fwknoprc
[2.2.2.2]
ACCESS tcp/22
SPA_SERVER 2.2.2.2
KEY_BASE64 HvUtIOramehLGKimD4ECXOzinaH4h3U8H1WXum7b54Q=
HMAC_KEY_BASE64 DLeLf93a3yBT2vhEpM+dWlirGta5GU+jdyG5uXp4461HgOtbqMem4gX0Bp2PJGzYZlbbcavcOM00UPm+0GqkXA==
USE_HMAC Y
VERBOSE Y
RESOLVE_IP_HTTPS Y
the keys are base64 encoded blobs of random data, and both the KEY_BASE64 and HMAC_KEY_BASE64 lines should be copied verbatim and placed within the /etc/fwknop/access.conf file on 2.2.2.2. once that's done, fwknopd can be started on that system, a default-drop policy against SSH connections can be put in place, and then access to SSH is managed via fwknop. to access SSH, just use the -n argument to reference the 2.2.2.2 stanza out of the .fwknoprc file (some --verbose output is included for illustration):
$ fwknop -n 2.2.2.2
FKO Field Values:
=================
Random Value: 8950423288486978
Username: mbr
Timestamp: 1370194770
FKO Version: 2.5
Message Type: 1 (Access msg)
Message String: 1.1.1.1,tcp/22
Nat Access: <NULL>
Server Auth: <NULL>
Client Timeout: 0 (seconds)
Digest Type: 3 (SHA256)
HMAC Type: 3 (SHA256)
Encryption Type: 1 (Rijndael)
Encryption Mode: 2 (CBC)
...
$ ssh -l user 2.2.2.2
user@2.2.2.2's password:
π Access mode examples π
the most common usage of fwknop is to gain access to SSH running on a remote system that has the fwknopd daemon deployed along with a default-drop firewall policy. the following command illustrates this, where IP 1.1.1.1 is the IP to be allowed through the firewall running on 3.3.3.3 (note that the /etc/fwknop/access.conf file consumed by fwknopd will need to have matching encryption and HMAC keys, and configuration specifics can be found in the fwknopd(8) manual page). also, note the examples below prompt the user to supply the encryption and HMAC keys via stdin instead of writing them to disk like in the "$HOME/.fwknoprc" file case above. but you can convert all of the following examples to use the ~/.fwknoprc file just by adding the --save-rc-stanza argument:
$ fwknop -A tcp/22 --use-hmac -a 1.1.1.1 -D 3.3.3.3
Enter encryption key:
Enter HMAC key:
$ ssh -l user 3.3.3.3
user@3.3.3.3's password:
if the --verbose flag gets added to the command line, then some SPA packet specifics get printed to stdout (not all output is shown, for brevity):
$ fwknop -A tcp/22 --use-hmac -a 1.1.1.1 -D 3.3.3.3 --verbose
Enter encryption key:
Enter HMAC key:
Random Value: 1916307060193417
Username: mbr
Timestamp: 1368498909
FKO Version: 2.5
Message Type: 1 (Access msg)
Message String: 1.1.1.1,tcp/22
Nat Access: <NULL>
Server Auth: <NULL>
Client Timeout: 0 (seconds)
Digest Type: 3 (SHA256)
HMAC Type: 3 (SHA256)
Encryption Type: 1 (Rijndael)
Encryption Mode: 2 (CBC)
simultaneous access to multiple services is also supported β here's an example of requesting access to both SSH and OpenVPN on 3.3.3.3:
$ fwknop -A "tcp/22,tcp/1194" --use-hmac -a 1.1.1.1 -D 3.3.3.3
there are so many cases where an fwknop client is deployed on a network behind a NAT device and the externally routable IP is just... not known to the user. π in that case, use the IP resolution service available at https://www.cipherdyne.org/cgi-bin/myip via the -R command line switch to derive the external client IP address. this is a safer way of acquiring the client IP address than using the -s option mentioned earlier in this manual page, because the source IP gets put within the encrypted packet instead of having the fwknopd daemon grant the requested access from whatever IP address the SPA packet originates (i.e. using -s opens the possibility of a MITM attack):
$ fwknop -A tcp/22 --use-hmac -R -D 3.3.3.3
use the Single Packet Authorization mode to gain access to SSH, and this time use GnuPG keys to encrypt and decrypt:
$ fwknop -A tcp/22 --use-hmac --gpg-sign ABCD1234 --gpg--recipient 1234ABCD -R -D 3.3.3.3
instruct the fwknop server running at 3.3.3.3 to allow 1.1.1.1 to connect to SSH, but spoof the authorization packet from an IP associated with www.yahoo.com (requires root on the fwknop client OS):
# fwknop --spoof-src "www.yahoo.com" -A tcp/22 --use-hmac -a 1.1.1.1 -D 3.3.3.3
when fwknopd is running on an iptables firewall with systems deployed behind it, it's possible to take advantage of the NAT capabilities offered by iptables in order to transparently reach systems behind the firewall via SPA. π here's an example where the fwknop client is used to gain access to SSH running on the non-routable IP 192.168.10.23 that's deployed on the network behind 3.3.3.3. in this case, the SSH connection made to 3.3.3.3 is translated via NAT to the 192.168.10.2 system automatically:
$ fwknop -A tcp/22 -N 192.168.10.2:22 -R -D 3.3.3.3
π§ BACKWARDS COMPATIBILITY π§
with the 2.5 release, fwknop went through significant changes in its usage of cryptography β including adding support for HMAC authenticated encryption for both Rijndael and GnuPG modes, making sure PBKDF1 is used properly for key derivation when SPA packets are encrypted with Rijndael, and fixing several bugs from previous versions of fwknop. β¨
in general, this means that when Rijndael is used, SPA packets produced by the 2.5 release are incompatible with previous versions of fwknop. the GnuPG encryption mode is unaffected by these updates. but even when Rijndael is used, backwards compatibility is supported through setting the legacy encryption mode with -M on the fwknop client command line and/or the ENCRYPTION_MODE variable in the /etc/fwknop/access.conf file. that way, a pre-2.5 server can decrypt SPA packets produced by a 2.5 and later client (set -M legacy), and a 2.5 and later server can decrypt SPA packets produced by pre-2.5 clients (set ENCRYPTION_MODE legacy in the access.conf file).
heads up bestie: HMAC is only supported as of2.5and it's an optional feature, so backwards compatibility is only for configurations that don't use an HMAC on either side. it is strongly recommended to upgrade all fwknop clients and servers to2.5and use the new HMAC mode for properly authenticated SPA communications. the backwards compatibility support exists to make it easier to upgrade clients and servers with a phased approach. π
for emphasis β if the fwknopd server is upgraded to 2.5 (or later), but older clients can't be upgraded at the same time, then for each SOURCE stanza in the /etc/fwknop/access.conf file, add the following line:
ENCRYPTION_MODE legacy
in addition, if the KEY variable has an encryption key longer than 16 bytes, it will need to be truncated to 16 characters in the access.conf file in order for pre-2.5 clients to work properly. this limitation is fixed in 2.5, and provides additional motivation for upgrading all clients and servers to 2.5 or later. π₯
now, flipping the scenario around β if the fwknop clients are upgraded but the fwknopd server is still at a pre-2.5 version, then add the -M legacy argument to the fwknop command line:
$ fwknop -A tcp/22 -M legacy -R -D 2.2.2.2
π§© DEPENDENCIES π§©
okay so bestie, here's the tea on what fwknop needs to actually function π
The fwknop client requires libfko, which is normally included with both source and binary distributions, and is a dedicated library developed by the fwknop project. So like, you don't have to go hunting for it, it usually just shows up with the rest of the package β¨
Whenever the fwknopd server is used, libpcap is a required dependency. required, bestie, not optional π
But!! the upcoming 2.6 release will offer a UDP listener mode along with privilege separation support, and will not require libpcap in this mode. slay.
In UDP listener mode, even thoughfwknopdbinds to a UDP port, SPA packets are never acknowledged β so from an attacker's perspective there is no difference betweenfwknopdsniffing the wire passively vs. listening on a UDP socket in terms of what can be scanned for. π
For GPG functionality, GnuPG must also be correctly installed and configured along with the libgpgme library. no gpgme, no gpg vibes, that's just how it is π
To take advantage of all of the authentication and access management features of the fwknopd daemon/service, a functioning iptables, ipfw, or pf firewall is required on the underlying operating system. pick your fighter π₯
π©Ί DIAGNOSTICS π©Ί
The most comprehensive way to gain diagnostic information on fwknop is to run the test suite test-fwknop.pl script located in the test/ directory in the fwknop sources. She's thorough, okay?
The test suite sends fwknop through a large number of run time tests, has valgrind support, validates both SPA encryption and HMAC results against OpenSSL, and even has its own built in fuzzer for SPA communications. and fwknop in version 2.6.4 supports the American Fuzzy Lop (AFL) from Michal Zalewski as well π (fuzzing? in my SPA implementation? it's more likely than you think)
For more basic diagnostic information, fwknop can be executed with the -T (or --test) command line option. This will have fwknop simply create and print the SPA packet information, then run it through a decrypt/decode cycle and print it again. a little round trip just to prove she works π
In addition, the --verbose command line switch is useful to see various SPA packet specifics printed to stdout. turn it on, watch the magic, be obsessed β
π SEE ALSO π
fwknopd(8)iptables(8)pf(4)pfctl(8)ipfw(8)gpg(1)libfkodocumentation
More information on Single Packet Authorization can be found in the paper "Single Packet Authorization with fwknop" available at http://www.cipherdyne.org/fwknop/docs/SPA.html πΈ
A comprehensive tutorial on fwknop operations and theory can be found at http://www.cipherdyne.org/fwknop/docs/fwknop-tutorial.html. This tutorial also includes information about the design of fwknop that may be worth reading for those interested in why fwknop is different from other SPA implementations. (spoiler: she's different because she's her π )
fwknop uses the git versioning system as its source code repository along with Github for tracking of issues and milestones:
$ git clone https://github.com/mrash/fwknop.git fwknop.git
Additional commentary on Single Packet Authorization can be found via Michael Rash's Twitter feed: http://twitter.com/michaelrash, @michaelrash π¦
π AUTHORS π
The primary developers of fwknop are:
- Michael Rash (project creator)
<mbr@cipherdyne.org> - Damien Stuart
<dstuart@dstuart.org> - Jonathan Bennett
<jbennett@incomsystems.biz>
legends, honestly π
π CONTRIBUTORS π
This "C" version of fwknop was derived from the original Perl-based version on which many people who are active in the open source community have contributed. See the CREDITS file in the fwknop sources, or visit https://github.com/mrash/fwknop/blob/master/CREDITS to view the online list of contributors π
A few contributors deserve to be singled out including: Franck Joncourt, Max Kastanas, Vlad Glagolev, Sean Greven, Hank Leininger, Fernando Arnaboldi, and Erik Gomez. icons only, no notes π
The phrase "Single Packet Authorization" was coined by MadHat and Simple Nomad at the BlackHat Briefings of 2005. history was made fr fr πβ¨
π BUGS π
Send bug reports to dstuart@dstuart.org or mbr@cipherdyne.org, or open a new issue on Github (see https://github.com/mrash/fwknop.git). Suggestions and/or comments are always welcome as well π«Ά
Additional information may be found in the fwknop mailing list archives (see: https://lists.sourceforge.net/lists/listinfo/fwknop-discuss). come say hi, we don't bite π
π¦ DISTRIBUTION π¦
fwknop is distributed under the GNU General Public License (GPL v2+), and the latest version may be downloaded from http://www.cipherdyne.org. π§
and that's the whole page bestie!! πβ¨π this was the Fwknop Client page, dated 08/06/2018, from the FWKNOP(8) source β go forth and SPA responsibly, you absolute main character ππ¦πΈ
π¦ where this page comes from
- alpine 3.24: fwknop-doc 2.6.11-r2 Β· GPL-2.0-or-later
- arch rolling: fwknop 2.6.11-1 Β· GPL-2.0-only
- debian bookworm: fwknop-client 2.6.10-16 Β· GPL-2.0-or-later
- debian trixie: fwknop-client 2.6.11-2+b1 Β· GPL-2.0-or-later
- epel 10: fwknop 2.6.11-4.el10_1 Β· GPL-2.0-only
- epel 9: fwknop 2.6.10-10.el9 Β· GPLv2
- fedora 43: fwknop 2.6.11-5.fc43 Β· GPL-2.0-only
- fedora 43: fwknop 2.6.11-5.fc43 Β· GPL-2.0-only
- fedora 44: fwknop 2.6.11-6.fc44 Β· GPL-2.0-only
- fedora 44: fwknop 2.6.11-6.fc44 Β· GPL-2.0-only
- nixos 26.05: fwknop 2.6.11
- nixpkgs unstable: fwknop 2.6.11
- opensuse-leap 16.0: fwknop 2.6.11-bp160.1.6 Β· GPL-2.0-or-later
- opensuse-leap 16.0: fwknop 2.6.11-bp160.1.6 Β· GPL-2.0-or-later
- opensuse-leap 16.0: fwknop 2.6.11-bp160.1.6 Β· GPL-2.0-or-later
- opensuse-leap 16.0: fwknop 2.6.11-bp160.1.6 Β· GPL-2.0-or-later
- ubuntu jammy: fwknop-client 2.6.10-13build1 Β· GPL-2.0-or-later
- ubuntu noble: fwknop-client 2.6.10-20.2build3 Β· GPL-2.0-or-later
- ubuntu questing: fwknop-client 2.6.11-2build1
- ubuntu resolute: fwknop-client 2.6.11-2build3 Β· GPL-2.0-or-later
- ubuntu stonking: fwknop-client 2.6.11-4 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms