Giter Club home page Giter Club logo

mrash / fwknop Goto Github PK

View Code? Open in Web Editor NEW
1.0K 54.0 225.0 15.16 MB

Single Packet Authorization > Port Knocking

Home Page: http://www.cipherdyne.org/fwknop/

License: GNU General Public License v2.0

Makefile 0.96% C 36.06% Shell 0.96% Perl 52.39% Objective-C 0.36% XS 1.58% Python 1.36% HTML 0.11% Java 0.44% Limbo 0.07% M4 0.77% 1C Enterprise 1.12% Erlang 0.18% Roff 3.29% Raku 0.35%
port-knocker authentication authorization spa zero-trust firewall hmac

fwknop's Introduction

fwknop - Single Packet Authorization

Introduction

fwknop implements an authorization scheme known as Single Packet Authorization (SPA) for strong service concealment. SPA requires only a single packet which is encrypted, non-replayable, and authenticated via an HMAC in order to communicate desired access to a service that is hidden behind a firewall in a default-drop filtering stance. The main application of SPA is to use a firewall to drop all attempts to connect to services such as SSH in order to make the exploitation of vulnerabilities (both 0-day and unpatched code) more difficult. Because there are no open ports, any service that is concealed by SPA naturally cannot be scanned for with Nmap. The fwknop project supports four different firewalls: iptables, firewalld, PF, and ipfw across Linux, OpenBSD, FreeBSD, and Mac OS X. There is also support for custom scripts so that fwknop can be made to support other infrastructure such as ipset or nftables.

SPA is essentially next generation Port Knocking (PK), but solves many of the limitations exhibited by PK while retaining its core benefits. PK limitations include a general difficulty in protecting 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 shortcomings are solved by SPA. At the same time, 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.

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:

  1. Without an HMAC, cryptographically strong authentication is not possible with fwknop unless GnuPG is used, but even then an HMAC should still be applied.
  2. 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).
  3. The code required by the fwknopd daemon 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.

The final reason above is why an HMAC should still be used even when SPA packets are encrypted with GnuPG due to the fact that 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 /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.

Use Cases

People who use Single Packet Authorization (SPA) or its security-challenged cousin Port Knocking (PK) usually access SSHD running on the same system where the SPA/PK software is deployed. That is, a firewall running on a host has a default-drop policy against all incoming SSH connections so that SSHD cannot be scanned, but a SPA daemon reconfigures the firewall to temporarily grant access to a passively authenticated SPA client:

SPA-basic-access-SSHD "Basic SPA usage to access SSHD"

fwknop supports the above, but also goes much further and makes robust usage of NAT (for iptables/firewalld firewalls). After all, important firewalls are usually gateways between networks as opposed to just being deployed on standalone hosts. NAT is commonly used on such firewalls (at least for IPv4 communications) to provide Internet access to internal networks that are on RFC 1918 address space, and also to allow external hosts access to services hosted on internal systems.

Because fwknop integrates with NAT, SPA can be leveraged to access internal services through the firewall by users on the external Internet. Although this has plenty of applications on modern traditional networks, it also allows fwknop to support cloud computing environments such as Amazon's AWS:

SPA-Amazon-AWS-cloud "SPA usage on Amazon AWS cloud environments"

User Interface

The official cross-platform fwknop client user interface fwknop-gui (download, github) is developed by Jonathan Bennett. Most major client-side SPA modes are supported including NAT requests, HMAC and Rijndael keys (GnuPG is not yet supported), fwknoprc stanza saving, and more. Currently fwknop-gui runs on Linux, Mac OS X, and Windows - here is a screenshot from OS X: fwknop-gui-OS-X-screenshot "fwknop-gui on Mac OS X" Similarly, an updated Android client is available as well.

Tutorial

A comprehensive tutorial on fwknop can be found here:

http://www.cipherdyne.org/fwknop/docs/fwknop-tutorial.html

Features

The following is a complete list of features supported by the fwknop project:

  • Implements Single Packet Authorization around iptables and firewalld firewalls on Linux, ipfw firewalls on *BSD and Mac OS X, and PF on OpenBSD.
  • The fwknop client runs on Linux, Mac OS X, *BSD, and Windows under Cygwin. In addition, there is an Android app to generate SPA packets.
  • Supports both Rijndael and GnuPG methods for the encryption/decryption of SPA packets.
  • Supports HMAC authenticated encryption for both Rijndael and GnuPG. The order of operation is encrypt-then-authenticate to avoid various cryptanalytic problems.
  • Replay attacks are detected and thwarted by SHA-256 digest comparison of valid incoming SPA packets. Other digest algorithms are also supported, but SHA-256 is the default.
  • SPA packets are passively sniffed from the wire via libpcap. The fwknopd server can also acquire packet data from a file that is written to by a separate Ethernet sniffer (such as with tcpdump -w <file>), from the iptables ULOG pcap writer, or directly via a UDP socket in --udp-server mode.
  • For iptables firewalls, ACCEPT rules added by fwknop are added and deleted (after a configurable timeout) from custom iptables chains so that fwknop does not interfere with any existing iptables policy that may already be loaded on the system.
  • Supports inbound NAT connections for authenticated SPA communications (iptables firewalls only for now). This means fwknop can be configured to create DNAT rules so that you can reach a service (such as SSH) running on an internal system on an RFC 1918 IP address from the open Internet. SNAT rules are also supported which essentially turns fwknopd into a SPA-authenticating gateway to access the Internet from an internal network.
  • Multiple users are supported by the fwknop server, and each user can be assigned their own symmetric or asymmetric encryption key via the /etc/fwknop/access.conf file.
  • Automatic resolution of external IP address via https://www.cipherdyne.org/cgi-bin/myip (this is useful when the fwknop client is run from behind a NAT device). Because the external IP address is encrypted within each SPA packet in this mode, Man-in-the-Middle (MITM) attacks where an inline device intercepts an SPA packet and only forwards it from a different IP in an effort to gain access are thwarted.
  • Port randomization is supported for the destination port of SPA packets as well as the port over which the follow-on connection is made via the iptables NAT capabilities. The later applies to forwarded connections to internal services and to access granted to local sockets on the system running fwknopd.
  • Integration with Tor (as described in this DefCon 14 presentation). Note that because Tor uses TCP for transport, sending SPA packets through the Tor network requires that each SPA packet is sent over an established TCP connection, so technically this breaks the "single" aspect of "Single Packet Authorization". However, Tor provides anonymity benefits that can outweigh this consideration in some deployments.
  • Implements a versioned protocol for SPA communications, so it is easy to extend the protocol to offer new SPA message types and maintain backwards compatibility with older fwknop clients at the same time.
  • Supports the execution of shell commands on behalf of valid SPA packets.
  • The fwknop server can be configured to place multiple restrictions on inbound SPA packets beyond those enforced by encryption keys and replay attack detection. Namely, packet age, source IP address, remote user, access to requested ports, and more.
  • Bundled with fwknop is a comprehensive test suite that issues a series of tests designed to verify that both the client and server pieces of fwknop work properly. These tests involve sniffing SPA packets over the local loopback interface, building temporary firewall rules that are checked for the appropriate access based on the testing config, and parsing output from both the fwknop client and fwknopd server for expected markers for each test. Test suite output can easily be anonymized for communication to third parties for analysis.
  • fwknop was the first program to integrate port knocking with passive OS fingerprinting. However, Single Packet Authorization offers many security benefits beyond port knocking, so the port knocking mode of operation is generally deprecated.

License

The fwknop project is released as open source software under the terms of the GNU General Public License (GPL v2) or (at your option) any later version. The latest release can be found at http://www.cipherdyne.org/fwknop/

Current State

This README file describes the present state of the fwknop project as of the 2.5 release made in July, 2013. At present, we have an implementation of the Firewall Knock Operator library; libfko, as well as the fwknop client and server applications. The library provides the API and back-end functionality for managing the Single Packet Authorization (SPA) data that the other fwknop components employ. It also can be used by other programs that need SPA functionality (see the perl directory for the FKO perl module as an example, and there are python bindings as well in the python directory).

Upgrading

If you are upgrading from an older version of fwknop (and this includes the original perl implementation as well), then you will want to read the following link to ensure a smooth transition to fwknop-2.5 or later:

http://www.cipherdyne.org/fwknop/docs/fwknop-tutorial.html#backwards-compatibility

Misc

  • Questions or comments about fwknop will be fielded on the fwknop mailing list.
  • For static analysis, fwknop uses the CLANG static analyzer and also the powerful Coverity Scan tool:

Building fwknop

This distribution uses GNU autoconf for setting up the build. Please see the INSTALL file for the general basics on using autoconf.

There are some "configure" options that are specific to fwknop. They are (extracted from ./configure --help):

  --disable-client        Do not build the fwknop client component. The
                          default is to build the client.
  --disable-server        Do not build the fwknop server component. The
                          default is to build the server.
  --with-gpgme            support for gpg encryption using libgpgme
                          [default=check]
  --with-gpgme-prefix=PFX prefix where GPGME is installed (optional)
  --with-gpg=/path/to/gpg Specify path to the gpg executable that gpgme will
                          use [default=check path]
  --with-firewalld=/path/to/firewalld
                          Specify path to the firewalld executable
                          [default=check path]
  --with-iptables=/path/to/iptables
                          Specify path to the iptables executable
                          [default=check path]
  --with-ipfw=/path/to/ipfw
                          Specify path to the ipfw executable [default=check
                          path]
  --with-pf=/path/to/pfctl
                          Specify path to the pf executable [default=check
                          path]
  --with-ipf=/path/to/ipf Specify path to the ipf executable [default=check
                          path]

Examples:

./configure --disable-client --with-firewalld=/bin/firewall-cmd
./configure --disable-client --with-iptables=/sbin/iptables --with-firewalld=no

Notes

Migrating from the Perl version of fwknop

For those of you who are currently using the Perl version and plan to migrate to this version, there are some things to be aware of:

  • Not all of the features and functionality of the Perl-based fwknop were ported to this implementation. We felt it important to keep the C version as lean and lightweight as possible. Most of the omitted feature/functions (like email alerts) can be accomplished through other means (i.e. use an external script to monitor log files and alert based on appropriate log messages).

  • There are some differences in the fwknop configuration and access file directives and values. Some of these are fairly subtle. You should pay careful attention to the documentation and comments in those files.

For fwknop developers

If you are pulling this distribution from git, you should run the autogen.sh script to generate the autoconf files. If you get errors about missing directories or files, try running autogen.sh again. After that you can run the autoreconf -i when you want to regenerate the configuration. If, for some reason, autoreconf does not work for you, the autogen.sh script should suffice.

The fwknop and fwknopd man page nroff sources are included in their respective directories (client and server). These nroff files are derived from the asciidoc sources in the 'docs' directory. See the README in docs for details.

fwknop's People

Contributors

alexaltea avatar alteman avatar anthchirp avatar bbalp avatar coacher avatar damienstuart avatar digitaldj avatar e40 avatar fjoncourt avatar fmarier avatar g-reno avatar hlein avatar jakuje avatar jp-bennett avatar jwilk avatar khorben avatar micha137 avatar mrash avatar mrdanbrooks avatar mstair avatar schuellerf avatar seb35 avatar sgh7 avatar skull-squadron avatar sparrell avatar stubbsw avatar tombriden avatar vaygr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fwknop's Issues

Privilege separation support

Only two areas of fwknopd need to run as root: packet acquisition and firewall rule adjustment. Everything else should run as non-privileged user.

Rijndael keys are limited to 16 characters

Current fwknop-2.x code limits Rijndael keys to 16 chars whereas anything up to RIJNDAEL_MAX_KEYSIZE (32 chars) should be allowed.

This issue was reported by Michael T. Dean.

Log module for fwknop

What do you think about adding a log module for fwknop?

I mean I see sometimes if (options->verbose > 3) then print a message.

A log module could be registered :

Log_InitCtx(verbose, facility)

Then when there is something to print, it could be done by

Log_Msg(LOG_VERBOSITY_DEBUG, LOG_FACILITY_1, msg)

Debug information could be sent to stdout and errors to stderr for example.

Such a module could avoid reading the options->verbose context variable to know whether we have to print the message or not.

Key generation support

Allow encryption and HMAC keys to be automatically generated and stored. This allows stronger keys to be used than normal user-provided passwords.

HMAC-SHA256 support

Usage of an HMAC will be optional and not the default in order to remain backwards compatible with older non-HMAC capable versions of fwknop. The libfko API will change though, so backwards compatibility will be maintained in the sense that an SPA packet produced by the fwknop-2.5 client can be decrypted by a pre-2.5 server, but pre-2.5 code cannot use the libfko 2.5 code and vice versa.

Add --save capability for saving stanzas

fwknop --save -D 10.0.0.1 -A tcp/22 -s -p 12345

... would create a stanza entry in .fwknoprc. This could then be executed as normal with:

fwknop -n

NB: Need to decide whether a stanza could be overwritten or not (ie. require manual editing of .fwknoprc).

Optional pthreads support

This should be an optional feature gated by autoconf #defines, and not enabled by default. For users that want this, it would make for a cleaner way to implement firewall rules on the server side.

SELinux + AppArmor policy support

Both SELinux and AppArmor implement a Mandatory Access Control (MAC) layer within the kernel, and the fwknop sources should include policies to leverage these tools.

OpenSSL compatibility by default for AES usage

The legacy way of generating salt + IV will be available through server access.conf variable support and a client command line argument. This will allow users to upgrade and not break backwards compatibility from a raw SPA communications perspective.

UDP listener support (no pcap dependency)

Since nmap cannot tell the difference between a filtered or open UDP server when nothing is sent back in response to a probe (no UDP server is ever obligated to return anything out of necessity), there is room for a mode of operation where fwknopd binds to a UDP port and uses it to acquire SPA packet data. The advantage of this approach is that a fwknopd would not need to link against libpcap and can run as an unprivileged user except for the code that must adjust the firewall rule set.

Use REDIRECT target for --nat-local implementation

Karthik Ganesan suggested to the fwknop mailing list the ability to use the iptables REDIRECT target on the fwknopd server side to implement --nat-local access. This would be a more natural way of accomplishing NAT to the local system instead of using the SNAT capability as well.

add knopwatchd to extras/ directory

Kevin Hilton reported that knopwatchd is not included in the fwknop-2.0 sources distribution. knopwatchd was part of the older perl fwknop distribution, and it wasn't promoted to the current fwknop C release. The reasoning was that there are other programs that are designed for this (such as monit, etc.). However, after thinking about it a bit, with fwknopd potentially deployed on small embedded systems where these other programs might not run, it seems like knopwatchd should be included in the extras/ directory at least. knopwatchd is extremely lightweight, and includes a feature set that is something controlled by the fwknop developers.

SPA packet size encryption method differentiation

The current message size test is a problem in some cases such as in command mode with long command strings being included within an SPA packet. One alternative would just be to pretty much ignore packet size and just try decrypting incoming packets according to the keys defined in the access.conf file. If no Rijndael key is defined in any stanza and only gpg is used, then decryption would only be attempted via gpg and vice versa.

This issue was reported by Ruhsam Bernhard.

NAT mode not resolving hostnames to IP's

From Josh Smith:

There appears to be bug when using --nat-local in fwknop:

fwknop client version 2.0.4

When I do the following command:

fwknop -R -D www.mywebserver.tld -v -A tcp/PORT --nat-local --nat-port 22

I get the following error:

fwknop: fko_set_nat_access_str: Error 13 - Invalid SPA nat_access message format

However, when I replace www.mywebserver.tld with its actual IP the
command works. The basic command without natting works when I supply
the domain rather than the IP.

Add ability to specify external script to take SPA command data and args

Add ability to specify external script to take SPA command data and args instead of calling the local iptables/ipfw directly. The first cut could be a simple hand off to the script with the script being responsible for creating the FW entry as well as removing that entry after the allotted time.

Avoid duplicate iptables rules

I have played with fwknop on android and it works fine. Here is a part of my
iptables ruleset dump after sending multiple packets

     0     0 ACCEPT     tcp  --  any    any     192.168.1.14 \
anywhere             tcp dpt:ssh /* _exp_1357764373 */
     0     0 ACCEPT     tcp  --  any    any     192.168.1.14 \
anywhere             tcp dpt:ssh /* _exp_1357764374 */
     0     0 ACCEPT     tcp  --  any    any     192.168.1.14 \
anywhere             tcp dpt:ssh /* _exp_1357764374 */
     0     0 ACCEPT     tcp  --  any    any     192.168.1.14 \
anywhere             tcp dpt:ssh /* _exp_1357764374 */
     0     0 ACCEPT     tcp  --  any    any     192.168.1.14 \
anywhere             tcp dpt:ssh /* _exp_1357764374 */
     0     0 ACCEPT     tcp  --  any    any     192.168.1.14 \
anywhere             tcp dpt:ssh /* _exp_1357764374 */
     0     0 ACCEPT     tcp  --  any    any     192.168.1.14 \
anywhere             tcp dpt:ssh /* _exp_1357764374 */
     0     0 ACCEPT     tcp  --  any    any     192.168.1.14 \
anywhere             tcp dpt:ssh /* _exp_1357764375 */

Using the check option (-C) from iptables will allow fwknop to make sure not to insert duplicate rule (same timestamp). However, I do see any way to avoid adding the same access rule with different timestamps.

Android client limited IP selection

First, excellent excellent work! My security maintenance cost dropped a lot because fwknopd. (I had to upgrade my storage just to prevent disk full from bad login log).

I have two feature requests on the Android client:

  1. Can there be an option to manually input the source IP, in addition to auto-detect? I use my phone to knock open the port but then use my laptop to actually do the ssh session. They have different IPs.
  2. Can the server port be assigned? The code says "Until we make this settable." (android/project/jni/fwknop/fwknop_client.c line 105). Is it the current library limitation or just the client/wrapper implementation?

Thanks!

Build an Amazon fwknopd AMI

Create an Amazon AMI with fwknopd loaded and a default configuration that supports SNAT+DNAT so that other Amazon VPC instances can be reached through this host with SPA.

SPA packet size encryption method differentiation

The current message size test is a problem in some cases such as in command mode with long command strings being included within an SPA packet. One alternative would just be to pretty much ignore packet size and just try decrypting incoming packets according to the keys defined in the access.conf file. If no Rijndael key is defined in any stanza and only gpg is used, then decryption would only be attempted via gpg and vice versa.

This issue was reported by Ruhsam Bernhard.

Ensure HMAC digest modes are selectable

Because we want to minimize libfko API changes after the fwknop-2.5 release, make sure that HMAC digest modes can be specified instead of forcing the mode to be HMAC-SHA256.

Define of FIREWALL_TYPE by configure not possible

The current build system doesn't allow to set desired FIREWALL_TYPE during configure.
Currently it is hard coded to the first found binary following this trail:
iptables -> ipfw -> pf -> ipf

Respect setting of firewall with these options:
--with-iptables
--with-ipfw
--with-pf
--with-ipfw

Key lengths passed to encryption routines - C strings not required

Specify encryption and HMAC key lengths via explicitly passing their length to crypto routines. This allows random data to be used for key information from the key generation code, and does not force libfko to guess at key length by the existence of a NULL char (which can now be part of a key).

libcap-ng support

libcap-ng provides a way to drop privileges for certain operations, and fwknopd should support this.

Ensure fko.h does not depend on other libfko headers

Damien found an issue with the current header file include strategy in fko.h where both rijndael.h and digest.h are required. This introduces unhelpful dependencies. Created the hmac_header_fixes branch to correct this issue.

Document HMAC support for the fwknop-2.5 release

Ensure that the new HMAC support is documented for the 2.5 release. This should include material that describes how to upgrade in a mixed fwknop environment (backwards compatibility, etc.).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.