<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:admin="http://webns.net/mvcb/"
>
<channel>
<title>cipherdyne.org | System and Network Security</title>
<link>http://www.cipherdyne.org</link>
<description>The network and system security blog of Michael Rash</description>
<dc:language>en-us</dc:language>
<dc:rights>Copyright 2001-2010, Michael Rash.  All Rights Reserved.</dc:rights>
<dc:creator>Michael Rash</dc:creator>
<dc:date>2006-02-28T16:48:01-05:00</dc:date>
<admin:generatorAgent rdf:resource="http://www.cipherdyne.org" />

<!-- begin_stories -->
<item>
<link>http://www.cipherdyne.org/blog/2018/10/wireguard-macos-and-linux-virtual-machines.html</link>
<title>Wireguard, macOS, and Linux Virtual Machines</title>
<dc:date>2018-10-06T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

(The primary material for this blog post was
<a href="https://github.com/mrash/Wireguard-macOS-LinuxVM">released on github</a>. I'm reproducing
part it here as a blog post.)
<br/><br/>
Over the long term, the <a href="https://www.wireguard.com/">Wireguard VPN</a> is set to send shockwaves
through the VPN community with its modern cryptographic design, performance, stealthiness against
active network scanners, and commitment to security through a minimally complex code base. It is
my belief that these characteristics firmly place Wireguard among the best VPN options available.
Over time, it is likely that commercial solutions will be developed around Wireguard similarly to
commercial wrappers around OpenVPN.
<br/><br/>
This repository is dedicated to deploying a Wireguard VPN on macOS via a Linux VM running
under a virtualization solution such as Parallels. There are many alternatives to this
approach - including omitting the Linux piece altogether and using the cross-platform macOS
<a href="https://www.wireguard.com/xplatform/">Wireguard tools</a> - but I'm interested in using the
Wireguard kernel module from a Mac. This has to be done from a Linux VM or container, and we'll
talk about the VM route in this write up.
<br/><br/>
The primary use case for running such a VPN solution is to provide security for network traffic
emanating from a Mac laptop that is connected to a potentially hostile wireless network. This
includes the network at the local coffee shop among many others. Nothing against coffee shops of
course (I love coffee), but they are in the business of making wonderful caffeinated potions - not
hardening their network infrastructure against adversaries. In terms of general threats to network
traffic, a properly deployed VPN allows you to shift much of the security burden to the other side
of the VPN. In this case, the remote Wireguard end point will be deployed in a major cloud provider
or ISP network. The security of, say, Google's GCE network or Amazon's AWS network is far higher
than the network of the local coffee shop.
<br/><br/>
Note macOS security is a broad topic, and this repository is meant only to discuss a VPN
solution based on Wireguard. For a comprehensive treatment of macOS security, including other
VPN options, see the excellent
<a href="https://github.com/drduh/macOS-Security-and-Privacy-Guide">macOS Security and Privacy Guide</a>.
<br/>
<h3>Prerequisites</h3>
To fully implement Wireguard in this manner, we'll assume the following:
<br/><br/>
<ul>
<li>An Ubuntu Linux VM is running under Parallels on a Mac laptop. Wireguard will run from
    this VM, and will constitute the "client" side of the VPN.</li>
<li>The Mac laptop will be connected wirelessly to the network at the local coffee shop, and
    have an IP assigned via DHCP as usual.</li>
<li>The "server" side of the Wireguard VPN is an Ubuntu system running on a major cloud
    provider with an Internet-facing IP address.</li>
<li>Wireguard has been [installed](https://www.wireguard.com/install/) on both Ubuntu VM's,
    and key pairs have been [generated and shared](https://www.wireguard.com/quickstart/).</li>
<li>Wireguard client - Mac laptop hostname and IP addresses:</li>
<li>Mac laptop hostname: <b>maclaptop</b></li>
<li>Mac laptop wireless IP on the coffee shop network: <b>192.168.0.54</b>, interface: <b>en0</b></li>
<li>Mac laptop virtual NIC IP (under Parallels): <b>10.211.44.2</b>, interface: <b>vnic0</b></li>
<li>Mac laptop Ubuntu VM Wireguard hostname: <b>wgclientvm</b>, IP: <b>10.211.44.31</b></li>
<li>Mac laptop Ubuntu VM Wireguard IP: <b>10.33.33.2</b>, interface: <b>wg0</b></li>
<li>Wireguard server - Ubuntu system hostname and IP addresses:</li>
<li>Hostname: <b>wgserver</b></li>
<li>IP: <b>1.1.1.1</b>, interface: <b>eth0</b></li>
<li>Wireguard IP: <b>10.33.33.1</b>, interface: <b>wg0</b></li>
</ul>
Graphically, the network setup looks like this:

<img src="/images/Wireguard_net.png" title="Wireguard network diagram" alt="Wireguard network diagram" height="250" width="600" />

For the remainder of the writeup, head on over to the
<a href="https://github.com/mrash/Wireguard-macOS-LinuxVM">github repository</a>.

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2018/08/software-release-fwknop-2.6.10.html</link>
<title>Software Release: fwknop-2.6.10</title>
<dc:date>2018-08-06T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

The 2.6.10 release of <a href="/fwknop"><b>fwknop</b></a> is available for
<a href="/fwknop/download"><b>download</b></a> (or via the
<a href="https://github.com/mrash/fwknop/releases/tag/2.6.10">github release tag</a>).
Here is the complete
<a href="https://github.com/mrash/fwknop/blob/master/ChangeLog">ChangeLog</a>:
<br/><br/>
<ul>
<li>[server] Add MAX_FW_TIMEOUT to access.conf stanzas to allow a maximum
number of seconds for client-specified timeouts in SPA packets. This
fixes issue #226 which was spotted by Jeremiah Rothschild.</li>
<li>[server] Bug fix in CMD_EXEC mode to make sure to call exit() upon any
error from execvpe(). Without this fix, additional fwknopd processes
would be started upon a user specifying a command without the necessary
permissions. This bug was reported by Stephen Isard.</li>
<li>[build] Jérémie Courrèges-Anglas and Ingo Feinerer contributed a patch
to fix endian detection on OpenBSD systems based on information
contained here: https://www.opengroup.org/austin/docs/austin_514.txt</li>
<li>[client/server] (Michael Stair) Added client and server infrastructure
written in Erlang. See the erlang/ directory.</li>
</ul>

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2018/07/software-release-psad-2.4.6-and-fwsnort-1.6.8.html</link>
<title>Software Release: psad-2.4.6 and fwsnort-1.6.8</title>
<dc:date>2018-07-31T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

A pair of software releases is available for download -
<a href="/psad/download">psad-2.4.6</a> and <a href="/fwsnort/download/">fwsnort-1.6.8</a>.
The main change is that now both pieces of software support the Snort 'metadata'
keyword. This keyword and associated field is a common fixture of modern Snort rule
sets, and usually contains important data such as IPS policy preferences, information
about vulnerable target software or OS, date created, and more.
<br/><br/>
As an example, when fwsnort detects TCP traffic over port 21 that matches the Snort rule
"<b>ET ATTACK_RESPONSE FTP inaccessible directory access COM2</b>" (sid 2000500), the
following syslog message is generated:
<pre>
Jul 30 21:24:44 moria kernel: [650982.555939] [1] SID2000500 ESTAB IN=enx0014d1b0da65 OUT= MAC=00:12:34:56:78:65:60:e3:27:39:12:34:56:00 SRC=192.168.10.11 DST=192.168.10.1 LEN=59 TOS=0x00 PREC=0x00 TTL=63 ID=0 DF PROTO=TCP SPT=58801 DPT=21 WINDOW=4117 RES=0x00 ACK PSH URGP=0 OPT (0101080A4538966A09B20FBC)
</pre>
When psad monitors this out of the syslog data, an email alert is generated as usual.
However, in this email alert the metadata 'created_at' and 'updated_at' fields are now
included as defined in the original rule:
<pre>
   "ET ATTACK_RESPONSE FTP inaccessible directory access COM2"
          dst port:  21 (no server bound to local port)
          flags:     ACK PSH
          content:   "/COM2/"
          content:   "/COM2/"
          sid:       2000500
          chain:     FWSNORT_INPUT_ESTAB
          packets:   36
          classtype: string-detect
          reference: (url) http://doc.emergingthreats.net/bin/view/Main/2000500
          reference: (url) http://doc.emergingthreats.net/bin/view/Main/2000500
          created_at 2010_07_30
          updated_at 2010_07_30
</pre>

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2016/06/software-release-fwknop-2.6.9.html</link>
<title>Software Release: fwknop-2.6.9</title>
<dc:date>2016-06-08T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

The 2.6.9 release of <a href="/fwknop"><b>fwknop</b></a> is available for
<a href="/fwknop/download"><b>download</b></a> (or via the
<a href="https://github.com/mrash/fwknop/releases/tag/2.6.9">github release tag</a>).
Here is the complete
<a href="https://github.com/mrash/fwknop/blob/master/ChangeLog">ChangeLog</a>:
<br/><br/>
<ul>
<li>(Jonathan Bennett) Added support for the SHA3 "Keccak" algorithm
(specifically SHA3_256 and SHA3_512) for SPA HMAC and digest checking.
Enabling SHA3 from the fwknop client command line is done with the -m
option for the embedded SPA digest, or with the --hmac-digest-type
argument for the HMAC. On the server side, SHA3_256 or SHA3_512 can be
required for the incoming SPA packet HMAC via the HMAC_DIGEST_TYPE
configuration variable in access.conf stanzas. The SHA3 implementation
is from, Keyak and Ketje Teams, namely, Guido Bertoni, Joan Daemen,
Michael Peeters, Gilles Van Assche and Ronny Van Keer - see:
http://keyak.noekeon.org/</li>
<li>(Damien Stuart) Added support for libnetfilter_queue so that fwknopd can
acquire SPA packets via the NFQ target. This feature is enabled with a
new command line switch --enable-nfq-capture for the configure script,
and libpcap is not required in this mode. In support of capturing SPA
packets via the NFQ target, new configuration variables have been added
to the fwknopd.conf file: ENABLE_NFQ_CAPTURE, NFQ_INTERFACE, NFQ_PORT,
NFQ_TABLE, NFQ_CHAIN, NFQ_QUEUE_NUMBER, and NFQ_LOOP_SLEEP.</li>
<li>(Vlad Glagolev) Added support for deriving the source IP from the
X-Forwarded-For HTTP header when SPA packets are sent over HTTP
connections.</li>
<li>Bug fix in command open/close cycle feature to ensure that the first
successful match on a valid incoming SPA packet finishes all access.conf
stanza processing. That is, no other stanzas should be looked at after
the first match, and this is consistent with other SPA modes (such as
basic access requests). This bug was reported by Jonathan Bennett.</li>
<li>(Jonathan Bennett) Various fixes and enhancements to the test suite to
extend code coverage to new code, ensure valgrind bytes lost detection
works for amount of memory less than 10 bytes, better timing strategy
for fwknop client/server interactions, and more.</li>
</ul>

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2015/12/single-packet-authorization-and-third-party-devices.html</link>
<title>Single Packet Authorization and Third Party Devices</title>
<dc:date>2015-12-23T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

A major new feature in fwknop has been introduced today with the
<a href="/fwknop/download/">2.6.8 release</a>
(<a href="https://github.com/mrash/fwknop/releases/tag/2.6.8">github tag</a>) - the
ability to integrate with third-party devices. This brings SPA operations easily to
any device or software that offers a command line interface. By default,
the fwknop daemon supports four different firewalls: iptables, firewalld, ipfw, and PF.
But, suppose you want to have fwknopd leverage
<a href="http://ipset.netfilter.org/">ipset</a> instead? Or, suppose you have an
SSH pre-shared key between a Linux system and a Cisco router, and you want fwknopd
(running on the Linux box) to control the ACL on the router for the filtering portion of
SPA? Finally, suppose that you want a stronger measure of protection for an SSH daemon
that <a href="https://community.rapid7.com/community/infosec/blog/2015/12/20/cve-2015-7755-juniper-screenos-authentication-backdoor">may have been backdoored</a>, and that runs on a
proprietary OS where fwknopd can't be deployed natively? The sky is the limit, and
I would be interested in hearing about other deployment scenarios.
<br/><br/>
These scenarios and many others are now supported with a new "command open/close cycle"
feature in <a href="/fwknop/download/">fwknop-2.6.8</a>. Essentially, fwknopd has the ability to execute an arbitrary command
upon receiving a valid SPA packet (the "open"), and then execute a different command after a
configurable timeout (the "close"). This allows fwknopd to integrate with any third-party
device or software if open and close commands can be defined for how to interact. These
commands are specified on a per-stanza basis in the access.conf file, and a set of variable
substitutions are supported such as '<em>$SRC</em>', '<em>$PORT</em>',
'<em>$PROTO</em>', and '<em>$CLIENT_TIMEOUT</em>'. Naturally, the IP address, port, and
protocol are authenticated and decrypted out a valid SPA packet - i.e., SPA packet headers
are not trusted.
<br/><br/>
Let's see an example on a Linux system ("<b>spaserver</b>"). Here, we're going to have fwknopd interface with
ipset instead of iptables. First, we'll create an ipset named <em>fwknop_allow</em>,
and we'll link it into the local iptables policy. If a packet hits the
<em>fwknop_allow</em> ipset and there is no matching source IP, then the DROP rule at the
end of the iptables policy implements the default-drop policy. No userspace daemon such
as SSHD can be scanned or otherwise attacked from remote IP addresses without first
producing a valid SPA packet.

<pre style='color:#000000;background:#ffffff;'><span style='color:#a65700; '>[</span><span style='color:#5f5035; '>spaserver</span><span style='color:#a65700; '>]</span># ipset create fwknop_allow hash<span style='color:#808030; '>:</span>ip<span style='color:#808030; '>,</span>port timeout <span style='color:#008c00; '>30</span>
</pre>

Now, we create a stanza in the fwknop <em>/etc/fwknop/access.conf</em> file and fire up
fwknopd like this:

<pre style='color:#000000;background:#ffffff;'><span style='color:#a65700; '>[</span><span style='color:#5f5035; '>spaserver</span><span style='color:#a65700; '>]</span># cat <span style='color:#797997; '>/</span><span style='color:#007997; '>etc/fwknop/access.conf</span>
SOURCE            ANY
KEY_BASE64        &lt;base64 string&gt;
HMAC_KEY_BASE64   &lt;base64 string&gt;
CMD_CYCLE_OPEN    ipset add fwknop_allow <span style='color:#797997; '>$SRC</span><span style='color:#808030; '>,</span><span style='color:#797997; '>$PROTO</span><span style='color:#808030; '>:</span><span style='color:#797997; '>$PORT</span> timeout <span style='color:#797997; '>$CLIENT_TIMEOUT</span>
CMD_CYCLE_CLOSE   NONE

</pre>

With fwknopd running and iptables configured to drop everything except for IP
communications that match the <em>fwknop_allow</em> ipset, let's use the fwknop client
from a remote system "<b>spaclient</b>" to gain access to SSHD on the server for 30 seconds
(note that the iptables conntrack module will keep the connection open after the SPA
client IP is removed from the ipset). We'll assume that the encryption and HMAC keys
have been previous shared between the two systems, and on the client these keys have
been written to the "spaserver" stanza in the <em>~/.fwknoprc</em> file:

<pre style='color:#000000;background:#ffffff;'><span style='color:#a65700; '>[</span><span style='color:#5f5035; '>spaclient</span><span style='color:#a65700; '>]</span>$ fwknop <span style='color:#797997; '>-</span><span style='color:#007997; '>A</span> tcp<span style='color:#808030; '>/</span><span style='color:#008c00; '>22</span> <span style='color:#797997; '>-</span><span style='color:#007997; '>a</span> <span style='color:#008000; '>1.1</span><span style='color:#808030; '>.</span><span style='color:#008000; '>1.1</span> <span style='color:#797997; '>-</span><span style='color:#007997; '>f</span> <span style='color:#008c00; '>30</span> <span style='color:#797997; '>-</span><span style='color:#007997; '>n</span> spaserver
</pre>

So, behind the scenes after the SPA packet has been sent above, fwknopd on the server has
authenticated and decrypted the SPA packet, and has executed the following ipset command.
In this case, there is no need for a corresponding close command because ipset implements
the timer provided by the client itself, so the client IP is deleted from the ipset
automatically. (In other scenarios, the close command can be fully specified instead of
using the string '<em>NONE</em>' as we have above.) Here are the syslog messages that
fwknopd has generated, along with the
'<em>ipset list</em>' command output to show the 1.1.1.1 IP as a member of the set:

<pre style='color:#000000;background:#ffffff;'><span style='color:#a65700; '>[</span><span style='color:#5f5035; '>spaserver</span><span style='color:#a65700; '>]</span># grep fwknopd <span style='color:#797997; '>/</span><span style='color:#007997; '>var/log/syslog</span> |tail <span style='color:#797997; '>-</span><span style='color:#007997; '>n</span> <span style='color:#008c00; '>2</span>
Dec <span style='color:#008c00; '>23</span> <span style='color:#008c00; '>15</span><span style='color:#808030; '>:</span><span style='color:#008c00; '>38</span><span style='color:#808030; '>:</span><span style='color:#008c00; '>06</span> ubuntu fwknopd[<span style='color:#008c00; '>13537</span>]<span style='color:#808030; '>:</span> <span style='color:#808030; '>(</span>stanza #<span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span> SPA Packet from IP<span style='color:#808030; '>:</span> <span style='color:#008000; '>1.2</span><span style='color:#808030; '>.</span><span style='color:#008000; '>3.4</span> received with access source match
Dec <span style='color:#008c00; '>23</span> <span style='color:#008c00; '>15</span><span style='color:#808030; '>:</span><span style='color:#008c00; '>38</span><span style='color:#808030; '>:</span><span style='color:#008c00; '>06</span> ubuntu fwknopd[<span style='color:#008c00; '>13537</span>]<span style='color:#808030; '>:</span> [<span style='color:#008000; '>1.2</span><span style='color:#808030; '>.</span><span style='color:#008000; '>3.4</span>] <span style='color:#808030; '>(</span>stanza #<span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span> Running CMD_CYCLE_OPEN command<span style='color:#808030; '>:</span> <span style='color:#797997; '>/</span><span style='color:#007997; '>sbin/ipset</span> add fwknop_allow <span style='color:#008000; '>1.1</span><span style='color:#808030; '>.</span><span style='color:#008000; '>1.1</span><span style='color:#808030; '>,</span><span style='color:#008c00; '>6</span><span style='color:#808030; '>:</span><span style='color:#008c00; '>22</span> timeout <span style='color:#008c00; '>30</span>

Name<span style='color:#808030; '>:</span> fwknop_allow
Type<span style='color:#808030; '>:</span> hash<span style='color:#808030; '>:</span>ip<span style='color:#808030; '>,</span>port
Revision<span style='color:#808030; '>:</span> <span style='color:#008c00; '>5</span>
Header<span style='color:#808030; '>:</span> family inet hashsize <span style='color:#008c00; '>1024</span> maxelem <span style='color:#008c00; '>65536</span> timeout <span style='color:#008c00; '>30</span>
Size in memory<span style='color:#808030; '>:</span> <span style='color:#008c00; '>224</span>
References<span style='color:#808030; '>:</span> <span style='color:#008c00; '>0</span>
Members<span style='color:#808030; '>:</span>
</pre>

In addition to the ability to swap out the existing firewall with a completely
different filtering infrastructure, there are other notable features and fixes in the
2.6.8 release. The most important of these is a new feature implemented by Jonathan Bennett
(and suggested by Hank Leininger in github issue
<a href="https://github.com/mrash/fwknop/issues/62">#62</a>)
that allows access.conf files to be imported via a new '<em>%include</em>' directive.
This can be advantageous in some scenarios by letting non-privledged users define
their own encryption and authentication keys for SPA operations. This way, users do
not need write permissions to the main <em>/etc/fwknop/access.conf</em> file to change keys
around or define new ones.
<br/><br/>
The complete ChangeLog is available <a href="https://github.com/mrash/fwknop/blob/master/ChangeLog">here</a>, and the current test suite has achieved
<a href="/fwknop/lcov-results/">90.7% code coverage</a> (measured by lines).

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2015/08/software-release-fwknop-2.6.7.html</link>
<title>Software Release: fwknop-2.6.7</title>
<dc:date>2015-08-24T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

<a href="/fwknop/download/">
<img align="right" src="/images/chinesedoor.jpg" title="fwknop-2.6.7 software release" alt="fwknop-2.6.7 software release" height="170" width="120" /></a>
The 2.6.7 release of <a href="/fwknop"><b>fwknop</b></a> is available for
<a href="/fwknop/download"><b>download</b></a> (or via the
<a href="https://github.com/mrash/fwknop/releases/tag/2.6.7">github release tag</a>).
This release adds significant support for running commands delivered by SPA packets via
'sudo' on the server, and this allows the powerful 'sudoers' syntax to filter commands
that remote users are allowed to execute.
<br/><br/>
In addition, the <em>--key-gen</em> (key generation) mode has been added to
fwknopd. This will allow better integration with Jonathan Bennett's
<a href="http://incomsystems.biz/linux/fwknop2/">Fwknop2</a> Android client - particularly
when only the fwknopd server is installed on a system (as is usually the case for embedded
distributions such as OpenWRT). Further, Jonathan contributed a
console QR code generator, so that fwknop encryption and HMAC keys can be imported into
the Fwknop2 Android client via the phone's camera. Here is an example:

<br/><br/>
<code>
$ fwknopd --key-gen | ./extras/console-qr/console-qr.sh
</code>
<br/><br/>
<img src="/images/fwknop-qrcode.png" title="fwknop QR key code" alt="fwknop QR key code" height="200" width="200" />

In other news, Jonathan and I will be giving a lengthy interview on
Single Packet Authorization with fwknop for the
<a href="http://wiki.twit.tv/wiki/FLOSS_Weekly">FLOSS Weekly</a> show organized by the venerable
<a href="http://wiki.twit.tv/wiki/Randal_Schwartz">Randal Schwartz</a>
of perl fame. Tune in <a href="https://docs.google.com/spreadsheets/d/1_dOHpYlzRlMb0JEzwUcAUflPz8PLq7dKkosBkjISeyo/pub">September 2nd</a> at 11am Eastern time.

<br/><br/>
As usual, fwknop has a <a href="http://www.coverity.com">Coverity Scan</a> score of zero,
and the code coverage report achieved by the 2.6.7 test suite is available
<a href="/fwknop/2.6.7-lcov-results">here</a>. Note that the fwknop test suite is now
achieving 90% code coverage counted by lines, and 100% code coverage counted by
functions. This reflects the commitment the fwknop project makes towards rigorous
security and testing quality.
<br/><br/>
Here is the complete
<a href="https://github.com/mrash/fwknop/blob/master/ChangeLog">ChangeLog</a> for fwknop-2.6.7:
<br/><br/>
<ul>
<li>[server] When command execution is enabled with ENABLE_CMD_EXEC for an
access.conf stanza, added support for running commands via sudo. This was
suggested by Github user 'freegigi' (issue #159) as a means to provide
command filtering using the powerful sudoers syntax. This feature is
implemented by prefixing any incoming command from a valid SPA packet
with the sudo command along with optional user and group requirements
as defined by the following new access.conf variables:
ENABLE_CMD_SUDO_EXEC, CMD_SUDO_EXEC_USER, and CMD_SUDO_EXEC_GROUP.</li>
<li>[server] Kevin Layer reported a bug to the fwknop mailing list that
simultaneous NAT access for two different access.conf stanza was not
functioning properly. After some diagnosis, this was a result of
rule_exists() not properly detecting and differentiating existing DNAT
rules from new ones with different port numbers when 'iptables -C'
support is not available. This was against iptables-1.4.7, and has been
fixed in this release of fwknop (tracked as issue #162).</li>
<li>[server] Added --key-gen to fwknopd. This feature was suggested by
Jonathan Bennett, and will help with ease of use efforts. The first
platform to take advantage of this will likely be OpenWRT thanks to
Jonathan.</li>
<li>[server] By default, fwknopd will now exit if the interface that it is
sniffing goes down (patch contributed by Github user 'sgh7'). If this
happens, it is expected that the native process monitoring feature in
things like systemd or upstart will restart fwknopd. However, if fwknopd
is not being monitored by systemd, upstart, or anything else, this
behavior can be disabled with the EXIT_AT_INTF_DOWN variable in the
fwknopd.conf file. If disabled, fwknopd will try to recover when a
downed interface comes back up.</li>
<li>[extras] Added a script from Jonathan Bennett at
extras/console-qr/console-qr.sh to generate QR codes from fwknopd
access.conf keys.</li>
<li>[build] Added --with-firewalld to the autoconf configure script. This is
a synonym for --with-firewall-cmd to avoid confusion. Some package
maintainers use --with-firewalld to build fwknop.</li>
</ul>

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2015/06/android-fwknop2-client-and-openwrt.html</link>
<title>Android Fwknop2 Client and OpenWRT</title>
<dc:date>2015-06-22T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[
<a href="http://incomsystems.biz/linux/fwknop2/">Jonathan Bennett's</a> new Android
'Fwknop2' client is ready for prime time. It is available now in the
<a href="https://play.google.com/store/apps/details?id=org.cipherdyne.fwknop2">Google Play</a> store as well as on
<a href="https://f-droid.org/repository/browse/?fdfilter=fwknop2&amp;fdid=org.cipherdyne.fwknop2">F-Droid</a>,
and Jonathan put together a nice video demonstration of Fwknop2 being used to access
SSHD on a router running OpenWRT. Also demonstrated is the usage of NAT to transparently
access SSHD running on a system <em>behind</em> the router. This illustrates the ability
fwknopd offers for creating inbound NAT rules for external SPA clients - something that is,
to my knowledge, unique to the fwknop in the world of SPA software. Finally, in an
innovative twist, the Fwknop2 client can read encryption and authentication keys from
a QR code via the phone's camera. This simplifies the task of getting longer keys
- particularly those that are base64-encoded - to the phone for SPA operations.
<br/><br/>
<iframe width="450" height="300" src="https://www.youtube.com/embed/aTy89lEuEcc" frameborder="0" allowfullscreen="1"></iframe>


]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2015/06/new-android-single-packet-authorization-client-fwknop2.html</link>
<title>New Android Single Packet Authorization Client: Fwknop2</title>
<dc:date>2015-06-12T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[
<img align="right" src="/images/android-logo.jpg" width="100" height="105" title="Fwknop2 on Android" alt="Fwknop2 on Android" />
After a long while without updates to the fwknop clients on Android or iOS, I'm
excited to announce that <a href="https://github.com/jp-bennett/">Jonathan Bennett</a>
has developed an entirely new client for Android called <b>Fwknop2</b>. This
client adds significant features such as the ability to save configurations (including
both encryption and authentication keys), proper handling of base64 encoded keys, and
support for manually specified IP addresses to be allowed through the remote firewall.
Further, Fwknop2 integrates with
<a href="https://play.google.com/store/apps/details?id=com.sonelli.juicessh&amp;hl=en">JuiceSSH</a>
so that an SSH connection can seamlessly be launched right after the SPA packet is
sent. Finally, in an interesting twist, Fwknop2 will be able to read encryption
and HMAC keys via a QR code via the camera. The QR code itself is generated from
key material in --key-gen mode (which is currently available in the standard fwknop
client and will be available in the fwknopd server in the next release).
<br/><br/>
Fwknop2 will be available on both the Google Play store and via F-Droid within
the next few hours, and in the meantime the APK is available on github
<a href="https://github.com/jp-bennett/Fwknop2/releases">here</a>.
<br/><br/>
Below are a couple of screenshots of the new Android client in action - these are
from an Android VM running under Parallels on Mac OS X (Yosemite):

<img src="/images/Android_fwknop2_config.png" width="700" height="590" title="fwknop Android app" alt="fwknop Android app" />
<img src="/images/Android_fwknop2_send_SPA_packet.png" width="700" height="590" title="fwknop Android app" alt="fwknop Android app" />


]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2015/04/nat-and-single-packet-authorization.html</link>
<title>NAT and Single Packet Authorization</title>
<dc:date>2015-04-23T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

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:

<img src="/images/SPA_basic.png" title="SPA and basic SSH access" alt="SPA and basic SSH access" />

This works
<a href="/blog/2013/10/port-knocking-why-you-should-give-it-another-look.html">well enough</a>,
but both port knocking and SPA work in conjunction with a firewall, and "important" firewalls
are usually gateways between networks as opposed to just being deployed on standalone hosts.
Further, Network Address Translation (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.
<br/><br/>
The prevalence of NAT suggests that SPA should integrate strongly with it. Properly done,
this would extend the notion of SPA beyond just supporting the basic feature of granting
access to a local service. To drive this point home, and to see what a NAT-enabled vision
for SPA would look like, consider the following two scenarios:
<br/><br/>
<ol>
<li>A user out on the Internet wants to leverage SPA to access an SSH daemon that
is running on a system <em>behind</em> a firewall.
One option is to just use SPA to access SSHD on the firewall first, and then
initiate a new SSH connection to the desired internal host from the firewall itself.
However, this is clunky and unnecessary. The SPA system should just integrate with
the NAT features of the firewall to translate a SPA-authenticated incoming SSH
connection through to the internal host and bypass the firewall SSH daemon
altogether:
<img src="/images/SPA_DNAT.png" title="SPA and DNAT SSH access to internal host" alt="SPA and DNAT SSH access to internal host" />
</li>
<br/>
<li>A local user population is behind a firewall that is configured to block all access
by default from the internal network out to the Internet. Any user can acquire an IP on
the local network via DHCP, but gaining access to the Internet is only possible after
authenticating to the SPA daemon running on the firewall. So, instead of gaining
access to a specific service on a single IP via SPA, the local users leverage SPA
to gain access to <em>every</em> service on <em>every</em> external IP. In effect,
the firewall in this configuration does not trust the local user population, and Internet
access is only granted for users that can authenticate via SPA. I.e., only those users
who have valid SPA encryption and HMAC keys can access the Internet:
<img src="/images/SPA_SNAT.png" title="SPA and SNAT to external hosts" alt="SPA and SNAT to external hosts" />
</li>
</ol>

(A quick note on the network diagrams above - each red line represents a connection that
is only possible to establish after a proper SPA packet is sent.)
<br/><br/>
Both of the above scenarios are supported with fwknop-2.6.6, which has been
<a href="/fwknop/download/">released today</a>. So far, to my knowledge, fwknop is the
only SPA/PK implementation with any built-in NAT support. The first scenario of gaining
access to an internal service through the firewall has been supported by fwknop for a long time, but
the second is new for 2.6.6. The idea for using SPA to gain access to the Internet
instead of just for a specific service was
<a href="https://github.com/mrash/fwknop/issues/131">proposed</a> by "spartan1833"
to the fwknop mailing list, and is a powerful extension of SPA into the world of NAT - in
this case, <em>SNAT</em> in iptables parlance.
<br/><br/>
Before diving into the technical specifics, below is a video demonstration of the
NAT capabilities of fwknop being used within Amazon's AWS cloud. This shows fwknop using
NAT to turn a VPC host into a new gateway within Amazon's own border controls for the
purposes of accessing SSH and RDP running on other internal VPC hosts. So, this illustrates
the first scenario above. In addition, the video shows the usage of SPA
<a href="/blog/2009/11/creating-ghost-services-with-single-packet-authorization.html">ghost services</a>
to NAT both SSH and RDP connections through port 80 instead of their respective default
ports. This shows yet another twist that strong NAT integration makes possible in the SPA
world.

<br/><br/>
<iframe width="560" height="315" src="https://www.youtube.com/embed/tz-xK1BarKk" frameborder="0" ></iframe>
<br/><br/>
Now, let's see a practical example. This is for the second scenario above where a system
with the fwknop client installed is on a network behind a default-drop firewall running
the fwknop daemon, and the new SNAT capabilities are used to grant access to the Internet.
<br/><br/>
First, we fire up fwknopd on the firewall after showing the access.conf and fwknopd.conf
files (note that some lines have been abbreviated for space):

<pre>
[firewall]# cat /etc/fwknop/access.conf
SOURCE                      ANY
KEY_BASE64                  wzNP62oPPgEc+k...XDPQLHPuNbYUTPP+QrErNDmg=
HMAC_KEY_BASE64             d6F/uWTZmjqYor...eT7K0G5B2W9CDn6pAqqg6Oek=
FW_ACCESS_TIMEOUT           1000
FORCE_SNAT                  123.1.2.3
DISABLE_DNAT                Y
FORWARD_ALL                 Y

[firewall]# cat /etc/fwknop/fwknopd.conf
ENABLE_IPT_FORWARDING       Y;
ENABLE_IPT_SNAT             Y;

[firewall]# fwknopd -i eth0 -f
Starting fwknopd
Added jump rule from chain: FORWARD to chain: FWKNOP_FORWARD
Added jump rule from chain: POSTROUTING to chain: FWKNOP_POSTROUTING
iptables 'comment' match is available
Sniffing interface: eth3
PCAP filter is: 'udp port 62201'
Starting fwknopd main event loop.
</pre>

With the fwknopd daemon up and running on the firewall/SPA gateway system, we now run
the client to gain access to the Internet after showing the "[internet]" stanza in the
~/.fwknoprc file:

<pre>
[spaclient]$ cat ~/.fwknoprc
[internet]
KEY_BASE64                  wzNP62oPPgEc+k...XDPQLHPuNbYUTPP+QrErNDmg=
HMAC_KEY_BASE64             d6F/uWTZmjqYor...eT7K0G5B2W9CDn6pAqqg6Oek=
ACCESS                      tcp/22  ### ignored by FORWARD_ALL
SPA_SERVER                  192.168.10.1
USE_HMAC                    Y
ALLOW_IP                    source

[spaclient]$ nc -v google.com 80
### nothing comes back here because the SPA packet hasn't been sent yet
### and therefore everything is blocked (except for DNS in this case)
[spaclient]$ fwknop -n internet
[spaclient]$ nc -v google.com 80
Connection to google.com 80 port [tcp/http] succeeded!
</pre>

Back on the server, below are the rules that are added to grant Internet access to
the spaclient system. Note that all ports/protocols are accepted for forwarding
through the firewall, and an SNAT rule has been applied to the spaclient source IP
of 192.168.10.55:

<pre>
(stanza #1) SPA Packet from IP: 192.168.10.55 received with access source match
Added FORWARD ALL rule to FWKNOP_FORWARD for 192.168.10.55 -&gt; 0.0.0.0/0 */*, expires at 1429387561
Added SNAT ALL rule to FWKNOP_POSTROUTING for 192.168.10.55 -&gt; 0.0.0.0/0 */*, expires at 1429387561
</pre>

<b>Conclusion</b>
<br/>
Most users think of port knocking and Single Packet Authorization as a means to passively
gain access to a service like SSHD running on the same system as the PK/SPA software itself.
This notion can be greatly extended through strong integration with NAT features in a firewall.
If the SPA daemon integrates with SNAT and DNAT (in the iptables world), then both internal
services can be accessed from outside the firewall, and Internet access can be gated by SPA too.
The latest release of fwknop supports both of these scenarios, and please <a href="mailto:mbr.at.cipherdyne.org">email me</a>
or send me a message on Twitter <a href="https://twitter.com/michaelrash">@michaelrash</a> if
you have any questions or comments.


]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2015/03/single-packet-authorization-threat-modeling.html</link>
<title>Single Packet Authorization Threat Modeling</title>
<dc:date>2015-03-16T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

<img align="right" src="/images/chinesedoor4.jpg" title="fwknop Threat Modeling" alt="fwknop Threat Modeling" height="200" width="133" />
Last week there was an interesting question
<a href="http://sourceforge.net/p/fwknop/mailman/message/33587766/">posed by Peter Smith</a>
to the fwknop mailing list that focused on running fwknop in
<a href="https://github.com/mrash/fwknop/commit/1fd0e7e96012d9bdce0a2a3912bff3498fff3637">UDP listener mode</a>
vs. using libpcap. I thought it would be useful to turn this into a blog post, so here is Peter's
original question along with my response:
<br/><br/>
<em>"...I want to deploy fwknop on my server, but I'm not sure If I should use
the UDP listener mode or libpcap. At first UDP listener mode seems to be
the choice, because I don't have to compile libpcap. However, I then
have to open a port in the firewall. Thinking about this, I get the
feeling that I'm defeating the purpose of using SPA, by allowing
Internet access to a privileged processe.
<br/><br/>
If an exploitable security issue is found, even though fwknop remains
passive and undiscoverable, an attacker could blindly send his exploit
to random ports on servers he suspects running fwknopd, and after
maximum 65535 tries he would have root access. I'm not a programmer, so
I can't review the code of fwknop or SSH daemon, but if both is equally
likely of having security issues, I might as well just allow direct
access to the SSH daemon and skip using SPA.
<br/><br/>
Is my point correct?..."
</em>
<br/><br/>
First, let me acknowledge your point as an important issue to bring up. If
someone finds a vulnerability in fwknopd, it doesn't matter whether fwknopd
is collecting packets via UDP sockets or from libpcap (assuming we're
talking about a vulnerability in fwknopd itself). The mere processing of
network traffic is the problem.
<br/><br/>
So, why run fwknopd at all?
<br/><br/>
This is something of a long-winded answer, but I want to be thorough. I'll
likely not settle the issue with this response, but it's good to start the
discussion.
<br/><br/>
Starting with your example above with SSHD open to the world, suppose there
is a vulnerability in SSHD. What does the exploit model look like? Well, an
attacker armed with an exploit can trivially find the SSH daemon with any
scanner, and from there a single TCP connection is sufficient for
exploitation. I would argue that a primary enabling factor benefiting the
attacker in this scenario is that vulnerable targets that listen on TCP
sockets are so easy to find. The combination of scannable services +
zero-day exploits is just too nice for an attacker. Several years ago I
personally had a system running SSHD compromised because of this. (At the
time, it was my fault for not patching SSHD before I put it out on the
Internet, but still - the system was compromised within about 12 hours of
being online.)
<br/><br/>
Now, in the fwknopd world, assuming a vulnerability, what would
exploitation look like? Well, targets aren't scannable as you say, so an
attacker would have to guess that a target is running fwknopd and the
corresponding port on which it watches/listens for SPA packets <a href="#1">[1]</a>.
Forcing an attacker to send thousands of packets to different ports (assuming a
custom non-default port instead of UDP port 62201 that fwknopd normally
watches) is likely a security benefit in contrast to an obviously
targetable service. That is, sending tons of SPA exploit packets to
different ports is a common pattern that is quite noisy and is frequently
flagged by IDS's, firewalls, SIEM's, and flow analysis engines. How many
systems could an attacker target with such heavyweight scans before the
attacker's own ISP would notice? Or before the attacker's IP is included
within one of the Emerging Threats compromised hosts lists? Or within
DShield as a known bad actor? 10 million?  How many of these are actually
running fwknopd? I know there are some spectacular scanning results out
there, so it's really hard to quantify this, but either way there is a big
difference between sending thousands of &gt; 100-byte UDP packets to each
target vs. a port sweep for TCP/22.
<br/><br/>
Further, when a system is literally blocking every incoming packet <a href="#2">[2]</a>,
an attacker can't even necessarily be sure there is any target connected to
the network at all. Many attackers would likely move on fairly quickly from
a system that is simply returning zero data to some other system.
<br/><br/>
In contrast, for a service that advertises itself via TCP, an attacker
immediately knows - with 100% certainty - there is a userspace daemon with
a set of functions that they can interact with. This presents a risk. In my
view, this risk is greater than the risk of running fwknopd where an
attacker gets no data.
<br/><br/>
Another fair question to ask is about the architecture of fwknopd. When an
HMAC is used (this will be the default in a future release), fwknopd reads
SPA packet data, computes an HMAC, and does nothing else if the HMAC does
not match. This is an effort to try to stay faithful to a simplistic
design, and to minimize the functions an attacker can interact with - even
for packets that are blindly sent to the correct port where fwknopd is
watching. Thus, most functions in fwknopd, including those that parse
user-supplied data and hence where bugs are more likely to crop up, are not
even accessible without first passing the HMAC which is a cryptographically
strong test. When libpcap is also eliminated through the use of UDP, not
even libpcap functions are in the mix <a href="#3">[3]</a>. In other words,
the security of fwknop does not rely on not being discoverable or scannable - it is merely
a nice side effect of not using TCP to gather data from the network.
<br/><br/>
To me, another way to think of fwknopd in UDP mode is that it provides a
lightweight generic UDP authenticator for TCP-based services. Suppose that
SSHD had a design built-in where it would bind to a UDP socket, wait for a
similar authentication packet as SPA provides, and then switch over to TCP.
In this case, there would not be a need for SPA because you would get the
best of both worlds - non-scannability <a href="#4">[4]</a> plus everything that TCP provides
for reliable data delivery at the same time. SPA in UDP listening mode is
an effort to bridge these worlds. Further, there is nothing that ties
fwknopd to SSH. I know people who expose RDP to the Internet for example.
Personally, I'm quite confident there are fewer vulnerabilities in fwknopd
than something like RDP. Even if there isn't a benefit in terms of the
arguments above in terms of service concealment and forcing an attacker to
be noisy, my bet is that fwknopd - even if it advertised itself via TCP -
would provide better security than RDP or other services derived from
massive code bases.
<br/><br/>
Now, beyond all of the above, there are some additional blog posts and other
material that may interest some readers:
<br/><br/>
<ul>
    <li><a href="/blog/2013/10/port-knocking-why-you-should-give-it-another-look.html">Port Knocking: Why You Should Give It Another Look</a></li>
    <li><a href="/blog/2012/09/single-packet-authorization-the-fwknop-approach.html">Single Packet Authorization: The fwknop Approach</a></li>
    <li><a href="/fwknop/docs/fwknop-tutorial.html">A Comprehensive Guide to Strong Service Concealment with fwknop</a></li>
</ul>
<br/>
<a name="1">[1]</a> If an attacker is in the position to watch legitimate SPA packets from
an existing client then this guesswork can be largely eliminated. However,
even in this case, if fwknopd is sniffing via libpcap (so not using the UDP
only mode), there is no requirement for fwknopd to be running on the system
where access is actually granted. It only needs to be able to sniff packets
somewhere on the routing path of the destination IP chosen by the client. I
mention this to illustrate that it may not be obvious to an attacker where
a targetable fwknopd instance runs even when SPA packets can be monitored.
Also, there aren't too many attackers who are in this position. At least,
the number of attackers in this position is _far_ lower than those people
(everyone) who are in a position to discover a vulnerable service from any
system worldwide with a single TCP connection.
<br/><br/>
<a name="2">[2]</a> As you point out, in UDP-only mode, the firewall must allow incoming
packets to the UDP port where fwknopd is listening. But, given that fwknopd
never sends anything back over this port, it remains indistinguishable to
every other filtered port.
<br/><br/>
<a name="3">[3]</a> There are more things built into the development process that may be
worth noting too that heighten security such as the use of Coverity, AFL
fuzzing, valgrind, etc., but these probably takes us too far afield from
the topic at hand. Also, there are some roadmap items that have not been
implemented yet (such as privilege separation) that will make the
architecture even stronger.
<br/><br/>
<a name="4">[4]</a> Assuming a strong firewall stance against incoming UDP packets to
other ports so one cannot infer service existence because UDP/22 doesn't
respond to a scan but other ports respond with an ICMP port unreachable,
etc.


]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2014/12/ram-disks-and-saving-your-ssd-from-afl-fuzzing.html</link>
<title>RAM Disks and Saving Your SSD From AFL Fuzzing</title>
<dc:date>2014-12-09T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

The <a href="http://lcamtuf.coredump.cx/afl/">American Fuzzy Lop</a> fuzzer has become a critical
tool for finding security vulnerabilities in all sorts of software. It has the ability to send fuzzing
data through programs on the order of hundreds of millions of executions per day on a capable system,
and can certainly put strain on your hardware and OS. If you are fuzzing a target program with the AFL
mode where a file is written and the target binary reads from this file, then AFL is going to conduct
a huge number of writes to the local disk. For a solid-state drive this can reduce its life expectancy
because of <a href="http://en.wikipedia.org/wiki/Write_amplification">write amplification</a>.
<br/><br/>
My main workstation is a Mac running OS X Yosemite, and I run a lot of Linux, FreeBSD, and OpenBSD
virtual machines under Parallels for development purposes. The drive on this system is an SSD which
keeps everything quite fast, but I don't want to prematurely shorten its life through huge AFL fuzzing
runs. Normally, I'm using AFL to fuzz <a href="/fwknop">fwknop</a> from an Ubuntu-14.10 VM, and what is
needed is a way to keep disk writes down. The solution is to use a RAM disk from within the VM.
<br/><br/>
First, from the Ubuntu VM, let's get set up for AFL fuzzing and show what the disk writes look like
without using a RAM disk from the perspective of the host OS X system. This assumes AFL 0.89 has been
installed already and is in the current path:

<pre>
$ git clone https://github.com/mrash/fwknop.git fwknop.git
$ cd fwknop.git
$ ./autogen.sh
$ cd test/afl/
$ ./compile/afl-compile.sh
</pre>

We're not running AFL yet. Now, from the Mac, launch the Activity Monitor (under <em>Applications
&gt; Utilities</em>) and look at current disk utilization:
<img src="/images/AFL_writes1.png" title="AFL not running disk writes" alt="AFL not running disk writes" width="700" />

So, not terrible - currently 31 writes per second at the time the snapshot was taken, and that includes
OS X itself and the VM at the same time. But, now let's fire up AFL using the digest cache wrapper on
the Ubuntu VM (the main AFL text UI is not shown for brevity):

<pre>
$ ./fuzzing-wrappers/server-digest-cache.sh
[+] All right - fork server is up.
[+] All test cases processed.

[+] Here are some useful stats:

    Test case count : 1 favored, 0 variable, 1 total
           Bitmap range : 727 to 727 bits (average: 727.00 bits)
                   Exec timing : 477 to 477 us (average: 477 us)

[+] All set and ready to roll!
</pre>

And now let's take a look at disk writes again from OS X:
<img src="/images/AFL_writes2.png" title="AFL no RAM disk writes" alt="AFL no RAM disk writes" width="700" />
Whoa, that's a massive difference - nearly two orders of magnitude. AFL has caused disk writes to spike
to over 2,700 per second with total data written averaging at 19.5MB/sec. Long term fuzzing at this
level of disk writes would clearly present a problem for the SSD - AFL frequently needs to be left running
for days on end in order to be thorough. So, let's switch everything over to use a RAM disk on the Ubuntu
VM instead and see if that reduces disk writes:

<pre>
# mkdir /tmp/afl-ramdisk &amp;&amp; chmod 777 /tmp/afl-ramdisk
# mount -t tmpfs -o size=512M tmpfs /tmp/afl-ramdisk
$ mv fwknop.git /tmp/afl-ramdisk
$ cd /tmp/afl-ramdisk/fwknop.git/test/afl/
$ ./fuzzing-wrappers/server-digest-cache.sh
</pre>

Here is disk utilization once again from the Mac:
<img src="/images/AFL_writes3.png" title="AFL RAM disk writes" alt="AFL RAM disk writes" width="700" />

We're back to less than 10 writes per second to the SSD even though AFL is going strong on the Ubuntu
VM (not shown). The writes for the previous fuzzing run are still shown to the left of the graph (since
they haven't quite aged out yet when the screenshot was taken), and new writes are so low they don't
even make it above the X-axis at this scale. Although the total execs per second - about 2,000 - achieved
by AFL is not appreciably faster under the RAM disk, the main benefit is that my SSD will last a lot
longer. For those that don't run AFL underneath a VM, a similar strategy should still apply on the main
OS. Assuming enough RAM is available for whatever software you want to fuzz, just create a RAM disk and
run everything from it and extend the life of your hard drive in the process.

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2014/11/integrating-fwknop-with-the-american-fuzzy-lop-fuzzer.html</link>
<title>Integrating fwknop with the 'American Fuzzy Lop' Fuzzer</title>
<dc:date>2014-11-23T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

Over the past few months, the <a href="http://lcamtuf.coredump.cx/afl/">American Fuzzy Lop</a>
(AFL) fuzzer written by Michal Zalewski has become a tour de force in the security field. Many interesting bugs
have been found, including a late breaking bug in the venerable <b>cpio</b> utility
that Michal <a href="http://seclists.org/fulldisclosure/2014/Nov/74">announced</a> to the full-disclosure list.
It is clear that AFL is succeeding perhaps where other fuzzers have either failed or not been applied, and this
is an important development for anyone trying to maintain a secure code base. That is, the ease of use coupled with
powerful fuzzing strategies offered by AFL mean that open source projects should integrate it directly
into their testing systems. This has been done for the fwknop project with some basic
scripting and one <a href="https://github.com/mrash/fwknop/commit/aaa44656bcfcb705d80768a7b9aa0d45a0e55e21">patch</a>
to the fwknop code base. The patch was necessary because according to AFL documentation,
projects that leverage things like encryption and cryptographic signatures are not well
suited to brute force fuzzing coverage, and fwknop definitely fits into this category.
Crypto being a fuzzing barrier is not unique to AFL - other fuzzers have the same problem.
So, similarly to the <b>libpng-nocrc.patch</b> included in the AFL sources, encryption,
digests, and base64 encoding are bypassed when fwknop is compiled with
<b>--enable-afl-fuzzing</b> on the configure command line. One doesn't need to apply
the patch manually - it is built directly into fwknop as of the 2.6.4 release. This is
in support of a major goal for the fwknop project which is comprehensive
<a href="/blog/2014/08/code-coverage-challenges-for-open-source-projects.html">testing</a>.
<br/><br/>
If you maintain an open source project that involves crypto and does any sort of
encoding/decoding/parsing gated by crypto operations, then you should patch your project so that
it natively supports fuzzing with AFL through an optional compile time step. As an example, here is a
portion of the patch to fwknop that disables base64 encoding by just copying data manually:

<pre style='color:#000000;background:#ffffff;'>
index b<span style='color:#008c00; '>8423</span>c<span style='color:#008c00; '>2</span>..<span style='color:#008c00; '>5</span>b<span style='color:#008c00; '>51121</span> <span style='color:#008c00; '>100644</span>
 int
 b<span style='color:#008c00; '>64</span>_decode(const char *in, unsigned char *out)
 {
     unsigned char *dst = out;
     v = <span style='color:#008c00; '>0</span>;
     for (i = <span style='color:#008c00; '>0</span>; in[i] &amp;&amp; in[i] != '='; i++) {
         unsigned int index= in[i]-<span style='color:#008c00; '>43</span>;
@@ -<span style='color:#008c00; '>68</span>,<span style='color:#008c00; '>6</span> +<span style='color:#008c00; '>80</span>,<span style='color:#008c00; '>7</span> @@ b<span style='color:#008c00; '>64</span>_decode(const char *in, unsigned char *out)
         if (i &amp; <span style='color:#008c00; '>3</span>)
             *dst++ = v >> (<span style='color:#008c00; '>6</span> - <span style='color:#008c00; '>2</span> * (i &amp; <span style='color:#008c00; '>3</span>));
     }

     *dst = '\<span style='color:#008c00; '>0</span>';
</pre>
Fortunately, so far all fuzzing runs with AFL have turned up zero issues (crashes or
hangs) with fwknop, but the testing continues.
<br/><br/>
Within fwknop, a series of wrapper scripts are used to fuzz the following four areas
with AFL. These areas represent the major places within fwknop where data is consumed
either via a configuration file or from over the network in the form of an SPA packet:
<br/><br/>
<ol>
    <li>SPA packet encoding/decoding: <a href="https://github.com/mrash/fwknop/blob/master/test/afl/fuzzing-wrappers/spa-pkts.sh">spa-pkts.sh</a></li>
    <li>Server access.conf parsing: <a href="https://github.com/mrash/fwknop/blob/master/test/afl/fuzzing-wrappers/server-access.sh">server-access.sh</a></li>
    <li>Server fwknopd.conf parsing: <a href="https://github.com/mrash/fwknop/blob/master/test/afl/fuzzing-wrappers/server-conf.sh">server-conf.sh</a></li>
    <li>Client fwknoprc file parsing: <a href="https://github.com/mrash/fwknop/blob/master/test/afl/fuzzing-wrappers/spa-pkts.sh">client-rc.sh</a></li>
</ol>

Each wrapper script makes sure fwknop is compiled with AFL support, executes <b>afl-fuzz</b>
with the corresponding test cases necessary for good coverage, archives previous
fuzzing output data, and supports resuming of previously stopped fuzzing jobs. Here is
an example where the SPA packet encoding/decoding routines are fuzzed with AFL after
fwknop is compiled with AFL support:

<pre>
$ cd fwknop.git/test/afl/
$ ./compile/afl-compile.sh
$ ./fuzzing-wrappers/spa-pkts.sh
+ ./fuzzing-wrappers/helpers/fwknopd-stdin-test.sh
+ SPA_PKT=1716411011200157:root:1397329899:2.0.1:1:127.0.0.2,tcp/22:AAAAA
+ LD_LIBRARY_PATH=../../lib/.libs ../../server/.libs/fwknopd -c ../conf/default_fwknopd.conf -a ../conf/default_access.conf -A -f -t
Warning: REQUIRE_SOURCE_ADDRESS not enabled for access stanza source: 'ANY'+ echo -n 1716411011200157:root:1397329899:2.0.1:1:127.0.0.2,tcp/22:AAAAA

SPA Field Values:
=================
   Random Value: 1716411011200157
       Username: root
      Timestamp: 1397329899
    FKO Version: 2.0.1
   Message Type: 1 (Access msg)
 Message String: 127.0.0.2,tcp/22
     Nat Access: &lt;NULL&gt;
    Server Auth: &lt;NULL&gt;
 Client Timeout: 0
    Digest Type: 3 (SHA256)
      HMAC Type: 0 (None)
Encryption Type: 1 (Rijndael)
Encryption Mode: 2 (CBC)
   Encoded Data: 1716411011200157:root:1397329899:2.0.1:1:127.0.0.2,tcp/22
SPA Data Digest: AAAAA
           HMAC: &lt;NULL&gt;
 Final SPA Data: 200157:root:1397329899:2.0.1:1:127.0.0.2,tcp/22:AAAAA

SPA packet decode: Success
+ exit 0
+ LD_LIBRARY_PATH=../../lib/.libs afl-fuzz -T fwknopd,SPA,encode/decode,00ffe19 -t 1000 -i test-cases/spa-pkts -o fuzzing-output/spa-pkts.out ../../server/.libs/fwknopd -c ../conf/default_fwknopd.conf -a ../conf/default_access.conf -A -f -t
afl-fuzz 0.66b (Nov 23 2014 22:29:48) by &lt;lcamtuf@google.com&gt;
[+] You have 1 CPU cores and 2 runnable tasks (utilization: 200%).
[*] Checking core_pattern...
[*] Setting up output directories...
[+] Output directory exists but deemed OK to reuse.
[*] Deleting old session data...
[+] Output dir cleanup successful.
[*] Scanning 'test-cases/spa-pkts'...
[*] Creating hard links for all input files...
[*] Validating target binary...
[*] Attempting dry run with 'id:000000,orig:spa.start'...
[*] Spinning up the fork server...
[+] All right - fork server is up.
</pre>

And now AFL is up and running (note the <b>git --abbrev-commit</b> tag integrated
into the text banner to make clear which code is being fuzzed):

<img src="/images/AFL_SPA_pkts.png" title="AFL SPA packets fuzzing" alt="AFL SPA packets fuzzing" width="700" />

If the fuzzing run is stopped by hitting Ctrl-C, it can always be resumed as follows:
<pre>
$ ./fuzzing-wrappers/spa-pkts.sh resume
</pre>

Although major areas in fwknop where data is consumed are effectively fuzzed with
AFL, there is always room for improvement. With the wrapper scripts in place, it is
easy to add new support for fuzzing other functionality in fwknop. For example, the
digest cache file (used by fwknopd to track SHA-256 digests of previously seen SPA
packets) is a good candidate.
<br/><br/>
<b>UPDATE (11/30/2014):</b> The suggestion above about fuzzing the digest cache file proved
to be fruitful, and AFL discovered a bounds checking bug that has been fixed in
<a href="https://github.com/mrash/fwknop/commit/82cf8b1c9cc9c3256bfbd97cbd3a40353851dc02">this commit</a>.
The next release of fwknop (2.6.5) will contain this fix and will be made soon.
<br/><br/>
Taking things to the next level, another powerful technique that would make an interesting
side project would be to build a syntax-aware version of AFL that handles SPA packets
and/or configuration files natively. The AFL documentation hints at this type of
modification, and states that this could be done by altering the fuzz_one() routine in
afl-fuzz.c. There is already a fuzzer written in python for the fwknop project that is
syntax-aware of the SPA data format
(see: <a href="https://github.com/mrash/fwknop/blob/master/test/spa_fuzzing.py">spa_fuzzing.py</a>),
but the mutators within AFL are undoubtedly much better than in spa_fuzzing.py. Hence, modifying
AFL directly would be an effective strategy.
<br/><br/>
Please feel free to open an issue against fwknop in
<a href="https://github.com/mrash/fwknop/issues">github</a> if you have a suggestion
for enhanced integration with AFL. Most importantly, if you find a bug please let me
know. Happy fuzzing!

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2014/11/software-release-fwknop-2.6.4.html</link>
<title>Software Release: fwknop-2.6.4</title>
<dc:date>2014-11-16T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

<a href="/fwknop/download/">
<img align="right" src="/images/chinesedoor.jpg" title="fwknop-2.6.4 software release" alt="fwknop-2.6.4 software release" height="170" width="120" /></a>
The 2.6.4 release of <a href="/fwknop"><b>fwknop</b></a> is available for
<a href="/fwknop/download"><b>download</b></a>. New functionality has been developed
for 2.6.4, including a new UDP listener mode to remove libpcap as a dependency for
fwknopd, support for <b>firewalld</b> on recent versions of Fedora, RHEL, and Centos
(contributed by Gerry Reno), and support for Michal Zalewski's 'American Fuzzy Lop'
fuzzer. Further, on systems where execvpe() is available, all system() and popen()
calls have been replaced so that the shell is not invoked and no environment is used.
As usual, fwknop has a <a href="http://www.coverity.com">Coverity Scan</a> score of zero,
and the code coverage report achieved by the 2.6.4 test suite is available
<a href="/fwknop/2.6.4-lcov-results">here</a>.
<br/><br/>
Here is the complete ChangeLog for fwknop-2.6.4:
<br/><br/>
<ul>
<li>[server] Added a UDP server mode so that SPA packets can be acquired via
UDP directly without having to use libpcap. This is an optional feature
since it opens a UDP port (and therefore requires the local firewall be
opened for communications to this port), but fwknopd is careful to never
send anything back to a client that sends data to this port. So, from the
perspective of an attacker or scanner, fwknopd remains invisible. This
feature is enabled in fwknopd either with a new command line argument
--udp-server or in the fwknopd.conf file with the ENABLE_UDP_SERVER
variable. When deployed in this mode, it is advisable to recompile fwknop
beforehand with './configure --enable-udp-server' so that fwknopd does
not link against libpcap.</li>
<li>[server] Replaced all popen() and system() calls with execvpe() with no
usage of the environment. This is a defensive measure to not make use of
the shell for firewall command execution, and is supported on systems
where execvpe() is available.</li>
<li>(Gerry Reno) Added support for firewalld to the fwknopd daemon on RHEL 7
and CentOS 7. This is implemented using the current firewalld '--direct
--passthrough' capability which accepts raw iptables commands. More
information on firewalld can be found here:

https://fedoraproject.org/wiki/FirewallD
</li>
<li>[server] Added support for the 'American Fuzzy Lop' (AFL) fuzzer from
Michal Zalewski. This requires that fwknop is compiled with the
'--enable-afl-fuzzing' argument to the configure script as this allows
encryption/digest short circuiting in a manner necessary for AFL to
function properly. The benefit of this strategy is that AFL can fuzz the
SPA packet decoding routines implemented by libfko. See the test/afl/
directory for some automation around AFL fuzzing.</li>
<li>(Bill Stubbs) submitted a patch to fix a bug where fwknopd could not
handle Ethernet frames that include the Frame Check Sequence (FCS)
header. This header is four bytes long, and is placed at the end of each
Ethernet frame. Normally the FCS header is not visible to libpcap, but
some card/driver combinations result in it being included. Bill noticed
this on the following platform:

BeagleBone Black rev C running 3.8.13-bone50 #1 SMP Tue May 13
13:24:52 UTC 2014 armv7l GNU/Linux
</li>
<li>[client] Bug fix to ensure that a User-Agent string can be specified
when the fwknop client uses wget via SSL to resolve the external IP
address. This closes issue #134 on github reported by Barry Allard. The
fwknop client now uses the wget '-U' option to specify the User-Agent
string with a default of "Fwknop/&lt;version&gt;". In addition, a new command
line argument "--use-wget-user-agent" to allow the default wget
User-Agent string to apply instead.</li>
<li>[python module] When an HMAC key is passed to spa_data_final() then
default to HMAC SHA256 if no HMAC mode was specified.</li>
</ul>

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2014/08/code-coverage-challenges-for-open-source-projects.html</link>
<title>Code Coverage: Challenges For Open Source Projects</title>
<dc:date>2014-08-08T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

In this blog post I'll pose a few challenges to open source projects. These challenges,
among other goals, are designed to push automated test suites to maximize code coverage.
For motivation, I'll present code coverage stats from the OpenSSL and OpenSSH test suites,
and contrast this with what I'm trying to achieve in the fwknop project.
<br/><br/>
Stated bluntly, if comprehensive code coverage is not achieved by your test suite,
<em>you're doing it wrong</em>.
<br/><br/>
With major bugs like
<a href="http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2014-0160">Heartbleed</a> and
"<a href="http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2014-1266">goto fail</a>",
there is clearly a renewed need for better automated testing. As Mike Bland
<a href="http://martinfowler.com/articles/testing-culture.html">demonstrated</a>, the
problem isn't so much about technology since unit tests can be built for both Heartbleed
and "goto fail". Rather, the problem is that the whole software engineering life cycle
needs to embrace better testing.
<br/><br/>

<h3><b>1) Publish your code coverage stats</b></h3>
Just as open source projects publish source code, test suite code coverage results should
be published too. The mere act of publishing code coverage - just as open source itself -
is a way to engage developers and users alike to improve such results. Clearly displayed
should be all branches, lines, and functions that are exercised by the test suite, and
these results should be published for every software release. Without such stats, how can
users have confidence that the project test suite is comprehensive? Bugs still crop up
even with good code coverage, but many <em>many</em> bugs will be squashed during the
development of a test suite that strives to exercise every line of source code.
<br/><br/>
For a project written in C and compiled with gcc, the
<a href="http://ltp.sourceforge.net/coverage/lcov.php">lcov</a> tool provides a nice
front-end for <a href="https://gcc.gnu.org/onlinedocs/gcc/Gcov.html">gcov</a> coverage
data. lcov was used to generate the following
<a href="/lcov-results/openssl-1.0.1h">code</a>
<a href="/lcov-results/openssh-6.6p1">coverage</a>
<a href="/lcov-results/fwknop-2.6.3">reports</a> on OpenSSL-1.0.1h, OpenSSH-6.6p1,
and fwknop-2.6.3 using the respective test suite in each project:
<br/><br/>

<table cellpadding="1" border="0" width="100%">
    <tr>
    <td width="5%"></td>
    <td width="5%"></td>
    <td width="10%" class="headerCovTableHead">Hit</td>
    <td width="10%" class="headerCovTableHead">Total</td>
    <td width="15%" class="headerCovTableHead">Coverage</td>
    </tr>
    <tr>
    <td class="headerItem">OpenSSL-1.0.1h</td>
    <td class="headerItem">Lines:</td>
    <td class="headerCovTableEntry">44604</td>
    <td class="headerCovTableEntry">96783</td>
    <td class="headerCovTableEntryLo">46.1 %</td>
    </tr>
    <tr>
    <td class="headerItem"><a href="/lcov-results/openssl-1.0.1h">Full code coverage report</a></td>
    <td class="headerItem">Functions:</td>
    <td class="headerCovTableEntry">3518</td>
    <td class="headerCovTableEntry">6574</td>
    <td class="headerCovTableEntryLo">53.5 %</td>
    </tr>
    <tr>
    <td width="5%"></td>
    <td class="headerItem">Branches:</td>
    <td class="headerCovTableEntry">22653</td>
    <td class="headerCovTableEntry">67181</td>
    <td class="headerCovTableEntryLo">33.7 %</td>
    </tr>
    <tr>
        <td width="100%" colspan="5"><br/></td>
    </tr>
    <tr>
    <td class="headerItem">OpenSSH-6.6p1</td>
    <td class="headerItem">Lines:</td>
    <td class="headerCovTableEntry">18241</td>
    <td class="headerCovTableEntry">33466</td>
    <td class="headerCovTableEntryLo">54.5 %</td>
    </tr>
    <tr>
    <td class="headerItem"><a href="/lcov-results/openssh-6.6p1">Full code coverage report</a></td>
    <td class="headerItem">Functions:</td>
    <td class="headerCovTableEntry">1217</td>
    <td class="headerCovTableEntry">1752</td>
    <td class="headerCovTableEntryLo">69.5 %</td>
    </tr>
    <tr>
    <td width="5%"></td>
    <td class="headerItem">Branches:</td>
    <td class="headerCovTableEntry">9362</td>
    <td class="headerCovTableEntry">22674</td>
    <td class="headerCovTableEntryLo">41.3 %</td>
    </tr>
    <tr>
        <td width="100%" colspan="5"><br/></td>
    </tr>
    <tr>
    <td class="headerItem">fwknop-2.6.3</td>
    <td class="headerItem">Lines:</td>
    <td class="headerCovTableEntry">6971</td>
    <td class="headerCovTableEntry">7748</td>
    <td class="headerCovTableEntryMed">90.0 %</td>
    </tr>
    <tr>
    <td class="headerItem"><a href="/lcov-results/fwknop-2.6.3">Full code coverage report</a></td>
    <td class="headerItem">Functions:</td>
    <td class="headerCovTableEntry">376</td>
    <td class="headerCovTableEntry">377</td>
    <td class="headerCovTableEntryHi">99.7 %</td>
    </tr>
    <tr>
    <td width="5%"></td>
    <td class="headerItem">Branches:</td>
    <td class="headerCovTableEntry">4176</td>
    <td class="headerCovTableEntry">5239</td>
    <td class="headerCovTableEntryMed">79.7 %</td>
    </tr>
</table>

<br/><br/>
The numbers speak for themselves. To be fair, fwknop has a much smaller code base than OpenSSL
or OpenSSH - less than 1/10th the size of OpenSSL and about 1/5th the size of OpenSSH in terms
of lines reported by gcov. So, presumaby it's a lot easier to reach higher levels of code
coverage in fwknop than the other two projects. Nevertheless, it is shocking that the line
coverage
in the OpenSSL test suite is below 50%, and not much better in OpenSSH. What are the odds that
the other half of the code is bug free? What are the odds that changes in newer versions won't
break assumptions made in the untested code? What are the odds that one of the next security
vulnerabilities announced in either project stems from this code? Of course, test suites are
not a panacea, but there are almost certainly bugs lying in wait within the
untested code. It is easier to have confidence in code that has at least <em>some</em> test
suite coverage than code that has <em>zero</em> coverage - at least as far as the test suite
is concerned (I'm not saying that other tools are not being used).
Both OpenSSL and OpenSSH use tools beyond their respective test suites to try and maintain
code quality - OpenSSL uses <a href="http://www.coverity.com/">Coverity</a> for example -
but these tools are not integrated with test suite results and do not contribute to the code
coverage stats above. What I'm suggesting is that the test suites themselves should get much
closer to 100% coverage, and this may require the integration of infrastructure like a custom
fuzzer or fault injection library (more on this below).
<br/><br/>
On another note, given that an explicit design goal of the fwknop test suite is to maximize
code coverage, and given the results above, it is clear there is significant work left to do.
<br/><br/>

<h3><b>2) Make it easy to automatically produce code coverage results</b></h3>
Neither OpenSSL nor OpenSSH make it easy to automatically generate code coverage stats like
those shown above. One can always Google for the appropriate
CFLAGS and LDFLAGS settings, recompile, and run lcov, but you shouldn't have to. This should
be automatic and built into the test suite as an option. If your project is using autoconf,
then there should be a top level <b>--enable-code-coverage</b> switch (or similar) to the
<b>configure</b> script, and the test suite should take the next steps to produce the
code coverage reports. Without this, there is unnecessary complexity and manual work,
and this affects users and developers alike. My guess is this lack of automation is a factor
for why code coverage for OpenSSL and OpenSSH is not better. Of course, it takes a lot of
effort to develop a test suite with comprehensive code coverage support, but automation is
low hanging fruit.
<br/><br/>
If you want to generate the code coverage reports above, here are two trivial scripts -
<a href="https://gist.github.com/mrash/4e26359c399a98d8542a">one</a> for OpenSSH and
<a href="https://gist.github.com/mrash/8383288c66f973a2bbb2">another</a> for OpenSSL.
This one works for OpenSSH:

<pre style='color:#000000;background:#ffffff;'>


mkdir <span style='color:#797997; '>$LCOV_DIR</span>

make clean
make
make tests

lcov --capture --directory <span style='color:#800000; font-weight:bold; '>.</span> --output-file <span style='color:#797997; '>$LCOV_FILE</span>
lcov <span style='color:#44aadd; '>-r</span> <span style='color:#797997; '>$LCOV_FILE</span> <span style='color:#40015a; '>/usr/include</span><span style='color:#40015a; '>/</span><span style='color:#0f69ff; '>\*</span> --output-file <span style='color:#797997; '>$LCOV_DIR</span><span style='color:#40015a; '>/</span><span style='color:#797997; '>$LCOV_FILTERED</span>

genhtml <span style='color:#797997; '>$LCOV_DIR</span><span style='color:#40015a; '>/</span><span style='color:#797997; '>$LCOV_FILTERED</span> --output-directory <span style='color:#797997; '>$LCOV_DIR</span>

</pre>

<h3><b>3) Integrate a fuzzer into your test suite</b></h3>
If your test suite does not achieve 99%/95% function/line coverage, architectural changes
should be made to reach these goals and beyond. This will likely require that test suite
drive a fuzzer against your project and measure how well it exercises the code base.
<br/><br/>
Looking at code coverage results for older versions of the fwknop project was an eye opener.
Although the test suite had hundreds of tests, there were large sections of code that were
not exercised. It was for this reason the 2.6.3 release concentrated on more comprehensive
automated test coverage. However, achieving better coverage was not a simple matter of
executing fwknop components with different configuration files or command line arguments -
it required the development of a dedicated SPA packet
<a href="https://github.com/mrash/fwknop/blob/master/test/spa_fuzzing.py">fuzzer</a> along
with a special macro
<a href="https://github.com/mrash/fwknop/commit/9901d8a76a75e8d2bb5088fe92cc370f084e85cb">-DENABLE_FUZZING</a>
built into the source code to allow the fuzzer to reach portions
of code that would have otherwise been more difficult to trigger due to encryption and
authentication requirements. This is a similar to the strategy proposed in Michal
Zalewski's fuzzer <a href="https://code.google.com/p/american-fuzzy-lop">American Fuzzy Lop</a>
<a href="https://code.google.com/p/american-fuzzy-lop/wiki/AflDoc">here</a> (see the "Known
Limitations" section).
<br/><br/>
The main point is that fwknop was changed to support fuzzing driven by the test suite as a
way to extend code coverage. It is the strong <em>integration</em> of fuzzing into the test
suite that provides a powerful testing technique, and looking at code coverage results allows
you to measure it.
<br/><br/>
Incidentally, an example double free() bug that the fwknop packet fuzzer triggered
in conjunction with the test suite can be found
<a href="https://github.com/mrash/fwknop/commit/add2c913ab84e28b699941299d9ee26ff9b85d59">here</a> (fixed in 2.6.3).
<br/><br/>

<h3><b>4) Further extend your code coverage with fault injection</b></h3>
Any C project leveraging libc functions should implement error checking against function
return values. The canonical example is checking to see whether malloc() returned
NULL, and if so this is usually treated as an unrecoverable error like so:

<pre style='color:#000000;background:#ffffff;'>

    clean_up<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
</pre>

Some projects elect to
write a "safe_malloc()" wrapper for malloc() or other libc functions so that error handling
can be done in one place, but it is not feasible to do this for every libc function.
So, how to verify whether error conditions are properly handled at run
time? For malloc(), NULL is typically returned under extremely high memory
pressure, so it is hard to trigger this condition and still have a functioning system let
alone a functioning test suite. In other words, in the example above, how can the test suite
achieve code coverage for the <b>clean_up()</b> function? Other examples include filesystem
or network function errors that are returned when disks fill up, or a network communication
is blocked, etc.
<br/><br/>
What's needed is a mechanism for triggering libc faults artificially, without requiring the
underlying conditions to actually exist that would normally  cause such faults. This is where
a fault injection library like <a href="http://blitiri.com.ar/p/libfiu/">libfiu</a> comes in.
Not only does it support fault injection at run time against libc functions without the need to
link against libfiu (a dedicated binary "<b>fiu-run</b>" takes care of this), but it can
also be used to trigger faults in arbitrary non-libc functions within a project to see how
function callers handle errors. In fwknop, both strategies are used by the test suite, and
this turned up a number of bugs
like <a href="https://github.com/mrash/fwknop/commit/9f2e01eb0114ee0cb0bc101dda036779c456915d">this one</a>.
<br/><br/>
Full disclosure: libfiu does not yet support code coverage when executing a
binary under fiu-run because there are problems interacting with libc functions necessary
to write out the various source_file.c.gcno and source_file.c.gcda coverage files. This
issue is being worked on for an upcoming release of libfiu. So, in the context of fwknop,
libfiu is used to trigger faults directly in fwknop functions to see how calling functions
handle errors, and this strategy is compatible with gcov coverage results. The fiu-run tool
is also used, but more from the perspective of trying to crash one of the fwknop binaries
since we can't (yet) see code coverage results under fiu-run. Here is an example fault
introduced into the fko_get_username() function:

<pre style='color:#000000;background:#ffffff;'>
fko_get_username<span style='color:#808030; '>(</span>fko_ctx_t ctx<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>char</span> <span style='color:#808030; '>*</span><span style='color:#808030; '>*</span>username<span style='color:#808030; '>)</span>
    fiu_return_on<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>fko_get_username_init</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> FKO_ERROR_CTX_NOT_INITIALIZED<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
</pre>

With the fault set (there is a special command line argument <b>--fault-injection-tag</b> on
the fwknopd server command line to enable the fault), the error handling code seen at the
end of the example below is executed via the test suite. For proof of error handling execution,
see the
<a href="/lcov-results/fwknop-2.6.3/fwknop.git/server/incoming_spa.c.gcov.html">full coverage report</a>
(look at line 240).

<pre style='color:#000000;background:#ffffff;'>
get_spa_data_fields<span style='color:#808030; '>(</span>fko_ctx_t ctx<span style='color:#808030; '>,</span> spa_data_t <span style='color:#808030; '>*</span>spdat<span style='color:#808030; '>)</span>

    res <span style='color:#808030; '>=</span> fko_get_username<span style='color:#808030; '>(</span>ctx<span style='color:#808030; '>,</span> <span style='color:#808030; '>&amp;</span><span style='color:#808030; '>(</span>spdat<span style='color:#808030; '>-</span><span style='color:#808030; '>></span>username<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
</pre>

<br/>
Once again, it is the <em>integration</em> of fault injection with the test suite and
corresponding code coverage reports that extends testing efforts in a powerful way.
libfiu offers many nice features, including thread safey, the ability to enable a fault
injection tag relative to other functions in the stack, and
<a href="http://blitiri.com.ar/p/libfiu/doc/man-libfiu.html">more</a>.
<br/><br/>

<h3><b>5) Negative valgrind findings should force tests to fail</b></h3>
So far, a theme in this blog post has been better code coverage through <em>integration</em>.
I've attempted to make the case for the integration of fuzzing and fault injection with project
test suites, and code coverage stats should be produced for both styles of testing.
<br/><br/>
A third integration effort is to leverage
<a href="http://www.valgrind.org">valgrind</a>. That is, the test suite should run tests
underneath valgrind when possible (speed and memory usage may be constraints here depending
on the project). If valgrind discovers a memory leak, double free(), or other problem, this
finding should automatically cause corresponding tests to fail. In some
<a href="https://github.com/mrash/fwknop/blob/master/test/valgrind_suppressions">cases</a>
valgrind suppressions will need to be created if a project depends on libraries or other
code that is known to have issues under valgrind, but findings within project sources should
cause tests to fail. For projects heavy on the crypto side, there are some instances where
code is very deliberately built in a manner that triggers a valgrind error (see Tonnerre
Lombard's <a href="https://blogs.fsfe.org/tonnerre/archives/24">write up</a> on the old
Debian OpenSSL vulnerability), but these are not common occurrences and suppressions can
always be applied. The average valgrind finding in a large code base should cause test
failure.
<br/><br/>
Although running tests under valgrind will not expand code coverage, valgrind is a powerful
tool that should be tightly integrated with your test suite.
<br/><br/>

<h3><b>Summary</b></h3>
<ul>
    <li>Publish your code coverage stats</li>
    <li>Make it easy to automatically produce code coverage results</li>
    <li>Integrate a fuzzer into your test suite</li>
    <li>Further extend your code coverage with fault injection</li>
    <li>Negative valgrind findings should automatically force tests to fail</li>
</ul>


]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2014/07/software-release-fwknop-2.6.3.html</link>
<title>Software Release: fwknop-2.6.3</title>
<dc:date>2014-07-29T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

<a href="/fwknop/download/">
<img align="right" src="/images/chinesedoor.jpg" title="fwknop-2.6.3 software release" alt="fwknop-2.6.3 software release" height="170" width="120" /></a>
The 2.6.3 release of <a href="/fwknop"><b>fwknop</b></a> is available for
<a href="/fwknop/download"><b>download</b></a>. The emphasis in this release is maximizing
code coverage through a new python SPA packet fuzzer, and also on fault injection testing
with the excellent fault injection library <a href="http://blitiri.com.ar/p/libfiu/">libfiu</a>
developed by Alberto Bertogli. Another important change in 2.6.3 is all IP resolution
lookups in '-R' mode now happen over SSL to make it harder for an adversary to mount a MITM
attack on the resolution lookup. As always, manually specifying the IP to allow through the
remote firewall is safer than relying on any network communication - even when SSL would be
involved.
<br/><br/>
Here is the complete ChangeLog for fwknop-2.6.3:
<br/><br/>
<ul>
<li>[client] External IP resolution via '-R' (or '--resolve-ip-http') is now
done via SSL by default. The IP resolution URL is now
'https://www.cipherdyne.org/cgi-gin/myip', and a warning is generated
in '-R' mode whenever a non-HTTPS URL is specified (it is safer just to
use the default). The fwknop client leverages 'wget' for this operation
since that is cleaner than having fwknop link against an SSL library.</li>
<li>Integrated the 'libfiu' fault injection library available from
http://blitiri.com.ar/p/libfiu/  This feature is disabled by default,
and requires the --enable-libfiu-support argument to the 'configure'
script in order to enable it. With fwknop compiled against libfiu, fault
injections are done at various locations within the fwknop sources and
the test suite verifies that the faults are properly handled at run time
via test/fko-wrapper/fko_fault_injection.c. In addition, the libfiu tool
'fiu-run' is used against the fwknop binaries to ensure they handle
faults that libfiu introduces into libc functions. For example, fiu-run
can force malloc() to fail even without huge memory pressure on the
local system, and the test suite ensures the fwknop binaries properly
handle this.</li>
<li>[test suite] Integrated a new python fuzzer for fwknop SPA packets (see
test/spa_fuzzing.py). This greatly extends the ability of the test suite
to validate libfko operations since SPA fuzzing packets are sent through
libfko routines directly (independently of encryption and
authentication) with a special 'configure' option
--enable-fuzzing-interfaces. The python fuzzer generates over 300K SPA
packets, and when used by the test suite consumes about 400MB of disk.
For reference, to use both the libfiu fault injection feature mentioned
above and the python fuzzer, use the --enable-complete option to the
test suite.</li>
<li>[test suite] With the libfiu fault injection support and the new python
fuzzer, automated testing of fwknop achieves 99.7% function coverage and
90.2% line coverage as determined by 'gcov'. The full report may be
viewed here: http://www.cipherdyne.org/fwknop/lcov-results/</li>
<li>[server] Add a new GPG_FINGERPRINT_ID variable to the access.conf file
so that full GnuPG fingerprints can be required for incoming SPA packets
in addition to the abbreviated GnuPG signatures listed in GPG_REMOTE_ID.
From the test suite, an example fingerprint is:
<pre>
GPG_FINGERPRINT_ID     00CC95F05BC146B6AC4038C9E36F443C6A3FAD56
</pre>
</li>
<li>[server] When validating access.conf stanzas make sure that one of
GPG_REMOTE_ID or GPG_FINGERPRINT_ID is specified whenever GnuPG
signatures are to be verified for incoming SPA packets. Signature
verification is the default, and can only be disabled with
GPG_DISABLE_SIG but this is NOT recommended.</li>
<li>[server] Bug fix for PF firewalls without ALTQ support on FreeBSD. With
this fix it doesn't matter whether ALTQ support is available or not.
Thanks to Barry Allard for discovering and reporting this issue.
Closes issue #121 on github.</li>
<li>[server] Bug fix discovered with the libfiu fault injection tag
"fko_get_username_init" combined with valgrind analysis. This bug is
only triggered after a valid authenticated and decrypted SPA packet is
sniffed by fwknopd:
<pre>
==11181== Conditional jump or move depends on uninitialised value(s)
==11181==    at 0x113B6D: incoming_spa (incoming_spa.c:707)
==11181==    by 0x11559F: process_packet (process_packet.c:211)
==11181==    by 0x5270857: ??? (in /usr/lib/x86_64-linux-gnu/libpcap.so.1.4.0)
==11181==    by 0x114BCC: pcap_capture (pcap_capture.c:270)
==11181==    by 0x10F32C: main (fwknopd.c:195)
==11181==  Uninitialised value was created by a stack allocation
==11181==    at 0x113476: incoming_spa (incoming_spa.c:294)
</pre>
</li>
<li>[server] Bug fix to handle SPA packets over HTTP by making sure to honor
the ENABLE_SPA_OVER_HTTP fwknopd.conf variable and to properly account
for SPA packet lengths when delivered via HTTP.</li>
<li>[server] Add --test mode to instruct fwknopd to acquire and process
SPA packets, but not manipulate firewall rules or execute commands that
are provided by SPA clients. This option is mostly useful for the fuzzing
tests in the test suite to ensure broad code coverage under adverse
conditions.</li>
</ul>

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2014/01/software-release-fwknop-2.6.0.html</link>
<title>Software Release: fwknop-2.6.0</title>
<dc:date>2014-01-12T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

<a href="/fwknop/download/">
<img align="right" src="/images/chinesedoor4.jpg" title="fwknop-2.6.0 software release" alt="fwknop-2.6.0 software release" height="200" width="133" /></a>
The 2.6.0 release of <a href="/fwknop"><b>fwknop</b></a> is available for
<a href="/fwknop/download"><b>download</b></a>.  This release incorporates a number of
feature enhancements such as an AppArmor policy for fwknopd, HMAC authenticated encryption
support for the Android client, new NAT criteria that are independently configurable
for each access.conf stanza, and more rigorous valgrind verification powered by the
CPAN Test::Valgrind module.  A few bugs were fixed as well, and similarly to the 2.5 and
2.5.1 releases, the fwknop project has a Coverity defect count of zero.  As proof of this,
you can see the Coverity high-level defect stats for fwknop here (you'll need to sign up
for an account):

<a href="https://scan.coverity.com/projects/403"> <img alt="Coverity Scan Build Status" src="https://scan.coverity.com/projects/403/badge.svg"/> </a>

I would encourage any open source project that is using Coverity to publish their
scan results.  At last count, it appears that over 1,100 projects are using Coverity,
but OpenSSH is still not one of them.
<br/><br/>
Development on fwknop-2.6.1 will begin shortly, and here is the complete ChangeLog for
fwknop-2.6.0:
<br/><br/>
<ul>
<li>(Radostan Riedel) Added an AppArmor policy for fwknopd that is known to
work on Debian and Ubuntu systems.  The policy file is available at
extras/apparmor/usr.sbin/fwknopd.</li>
<li>[libfko] Nikolay Kolev reported a build issue with Mac OS X Mavericks
where local fwknop copies of strlcat() and strlcpy() were conflicting
with those that already ship with OS X 10.9. Closes #108 on github.</li>
<li>[libfko] (Franck Joncourt) Consolidated FKO context dumping function into
lib/fko_util.c. In addition to adding a shared utility function for
printing an FKO context, this change also makes the FKO context output
slightly easier to parse by printing each FKO attribute on a single line
(this change affected the printing of the final SPA packet data).  The
test suite has been updated to account for this change as well.</li>
<li>[libfko] Bug fix to not attempt SPA packet decryption with GnuPG without
an fko object with encryption_mode set to FKO_ENC_MODE_ASYMMETRIC.  This
bug was caught with valgrind validation against the perl FKO extension
together with the set of SPA fuzzing packets in
test/fuzzing/fuzzing_spa_packets.  Note that this bug cannot be
triggered via fwknopd because additional checks are made within fwknopd
itself to force FKO_ENC_MODE_ASYMMETRIC whenever an access.conf stanza
contains GPG key information.  This fix strengthens libfko itself to
independently require that the usage of fko objects without GPG key
information does not result in attempted GPG decryption operations.
Hence this fix applies mostly to third party usage of libfko - i.e.
stock installations of fwknopd are not affected.  As always, it is
recommended to use HMAC authenticated encryption whenever possible even
for GPG modes since this also provides a work around even for libfko
prior to this fix.</li>
<li>[Android] (Gerry Reno) Updated the Android client to be compatible with
Android-4.4.</li>
<li>[Android] Added HMAC support (currently optional).</li>
<li>[server] Updated pcap_dispatch() default packet count from zero to 100.
This change was made to ensure backwards compatibility with older
versions of libpcap per the pcap_dispatch() man page, and also because
some of a report from Les Aker of an unexpected crash on Arch Linux with
libpcap-1.5.1 that is fixed by this change (closes #110).</li>
<li>[server] Bug fix for SPA NAT modes on iptables firewalls to ensure that
custom fwknop chains are re-created if they get deleted out from under
the running fwknopd instance.</li>
<li>[server] Added FORCE_SNAT to the access.conf file so that per-access
stanza SNAT criteria can be specified for SPA access.</li>
<li>[test suite] added --gdb-test to allow a previously executed fwknop
or fwknopd command to be sent through gdb with the same command line
args as the test suite used.  This is for convenience to rapidly allow
gdb to be launched when investigating fwknop/fwknopd problems.</li>
<li>[client] (Franck Joncourt) Added --stanza-list argument to show the
stanza names from ~/.fwknoprc.</li>
<li>[libfko] (Hank Leininger) Contributed a patch to greatly extend libfko
error code descriptions at various places in order to give much better
information on what certain error conditions mean.  Closes #98.</li>
<li>[test suite] Added the ability to run perl FKO module built-in tests in
the t/ directory underneath the CPAN Test::Valgrind module.  This allows
valgrind memory checks to be applied to libfko functions via the perl
FKO module (and hence rapid prototyping can be combined with memory leak
detection).  A check is made to see whether the Test::Valgrind module
has been installed, and --enable-valgrind is also required (or
--enable-all) on the test-fwknop.pl command line.</li>
</ul>

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2013/10/validating-libfko-memory-usage-with-test-valgrind.html</link>
<title>Validating libfko Memory Usage with Test::Valgrind</title>
<dc:date>2013-10-26T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

<a href="http://www.cpan.org/">
<img align="right" src="/images/cpan_logo.png" title="Validating libfko Memory Usage with Test::Valgrind" alt="Validating libfko Memory Usage with Test::Valgrind" /></a>
The <a href="/fwknop">fwknop</a> project consistently uses <a href="http://www.valgrind.org/">valgrind</a>
to ensure that memory leaks, double free() conditions, and other problems do not creep into the code base.
A high level of <a href="/fwknop/docs/fwknop-tutorial.html#valgrind-mode">automation</a> is built around
valgrind usage with the fwknop test suite, and a
<a href="https://github.com/mrash/fwknop/commit/b063bd57349e4e71e2f2cec527482487d27f1d51">recent addition</a>
extends this even further by using the excellent CPAN
<a href="http://search.cpan.org/~vpit/Test-Valgrind-1.14/lib/Test/Valgrind.pm">Test::Valgrind</a> module.  Even
though the test suite has had the ability to run tests through valgrind, previous to this change these
tests only applied to the fwknop C binaries when executed directly by the test suite.  Further, some of the most
rigorous testing is done through the usage of the perl FKO extension to fuzz libfko functions, so
without the Test::Valgrind module these tests also could not take advantage of valgrind support.  Now
that the test suite supports Test::Valgrind (and a check is done to see if it is installed), all fuzzing
tests can also be validated with valgrind.  Technically, the fuzzing tests have been added as FKO built-in
tests in the t/ directory, and the test suite runs them through Test::Valgrind like this:

<pre>
# prove --exec 'perl -Iblib/lib -Iblib/arch -MTest::Valgrind' t/*.t
</pre>

Here is a complete example - first, run the test suite like so:

<pre>
# ./test-fwknop.pl --enable-all --include perl --test-limit 3

[+] Starting the fwknop test suite...

    args: --enable-all --include perl --test-limit 3

[+] Total test buckets to execute: 3

[perl FKO module] [compile/install] to: ./FKO...................pass (1)
[perl FKO module] [make test] run built-in tests................pass (2)
[perl FKO module] [prove t/*.t] Test::Valgrind..................pass (3)
[valgrind output] [flagged functions] ..........................pass (4)

    Run time: 1.27 minutes

[+] 0/0/0 OpenSSL tests passed/failed/executed
[+] 0/0/0 OpenSSL HMAC tests passed/failed/executed
[+] 4/0/4 test buckets passed/failed/executed
</pre>

Note that all tests passed as shown above.  This indicates that the test suite has not
found any memory leaks through the fuzzing tests run via Test::Valgrind.  But, let's
validate this by artificially introducing a memory leak and see if the test suite can
automatically catch it.  For example, here is a patch that forces a memory leak in the
<a href="https://github.com/mrash/fwknop/blob/master/lib/fko_message.c#L248">validate_access_msg()</a>
libfko function.  This function ensures that the shape of the access request conforms to something fwknop
expects like "1.2.3.4,tcp/22".  The memory leak happens because a new buffer is allocated
from the heap but is never free()'d before returning from the function (obviously this
patch is for illustration and testing purposes only):

<pre>
$ git diff
diff --git a/lib/fko_message.c b/lib/fko_message.c
index fa6803b..c04e035 100644
--- a/lib/fko_message.c
+++ b/lib/fko_message.c
@@ -251,6 +251,13 @@ validate_access_msg(const char *msg)
     const char   *ndx;
     int     res         = FKO_SUCCESS;
     int     startlen    = strnlen(msg, MAX_SPA_MESSAGE_SIZE);
+    char *leak = NULL;
+
+    leak = malloc(100);
+    leak[0] = 'a';
+    leak[1] = 'a';
+    leak[2] = '\0';
+    printf("LEAK: %s\n", leak);

     if(startlen == MAX_SPA_MESSAGE_SIZE)
         return(FKO_ERROR_INVALID_DATA_MESSAGE_ACCESS_MISSING);
</pre>

Now recompile fwknop and run the test suite again, after applying the patch (recompilation
output is not shown):

<pre>
# cd ../
# make
# test
# ./test-fwknop.pl --enable-all --include perl --test-limit 3
[+] Starting the fwknop test suite...

    args: --enable-all --include perl --test-limit 3

    Saved results from previous run to: output.last/

    Valgrind mode enabled, will import previous coverage from:
        output.last/valgrind-coverage/

[+] Total test buckets to execute: 3

[perl FKO module] [compile/install] to: ./FKO...................pass (1)
[perl FKO module] [make test] run built-in tests................pass (2)
[perl FKO module] [prove t/*.t] Test::Valgrind..................fail (3)
[valgrind output] [flagged functions] ..........................fail (4)

    Run time: 1.27 minutes

[+] 0/0/0 OpenSSL tests passed/failed/executed
[+] 0/0/0 OpenSSL HMAC tests passed/failed/executed
[+] 2/2/4 test buckets passed/failed/executed

</pre>

This time two tests fail.  The first is the test that runs the perl FKO module built-in
tests under Test::Valgrind, and the second is the "flagged functions" test which compares
test suite output looking for new functions that valgrind has flagged vs. the previous
test suite execution.  By looking at the output file of the "flagged functions" test it
is easy to see the offending function where the new memory leak exists.  This provides an
easy, automated way of memory leak detection that is driven by perl FKO fuzzing tests.

<pre>
# cat output/4.test
[+] fwknop client functions (with call line numbers):
       10 : validate_access_msg [fko_message.c:256]
        6 : fko_set_spa_message [fko_message.c:184]
        4 : fko_new_with_data [fko_funcs.c:263]
        4 : fko_decrypt_spa_data [fko_encryption.c:264]
        4 : fko_decode_spa_data [fko_decode.c:350]
</pre>

Currently, there are no known memory leaks in the fwknop code, and automation built
around the Test::Valgrind module will help keep it that way.

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2013/10/port-knocking-why-you-should-give-it-another-look.html</link>
<title>Port Knocking: Why You Should Give It Another Look</title>
<dc:date>2013-10-17T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

<a href="/fwknop/download/">
<img align="right" src="/images/chinesedoor.jpg" title="Port Knocking: Why you Should Give It Another Look" alt="Port Knocking: Why you Should Give It Another Look" height="200" width="133" /></a>
(<i>Update 10/20/2013: There is a Reddit comment thread going on this post
    <a href="http://www.reddit.com/r/netsec/comments/1oqhhs/port_knocking_why_you_should_give_it_another_look/">here</a>.</i>)
<br/><br/>
It has been a decade since Port Knocking was first <a href="http://www.portknocking.org/">introduced</a> to the
security community in 2003, so it seemed fitting to recap how far the concept has evolved.  Much effort has gone
into solving architectural problems with PK systems, and today
<a href="/fwknop/docs/fwknop-tutorial.html">Single Packet Authorization</a> (SPA) embodies the primary benefits
of PK while fixing its limitations.
<br/><br/>
There are noted security researchers on both sides of the debate as to whether
PK/SPA has any security value, but it is interesting that researchers who don't find value seem to concentrate on
aspects of PK/SPA that have little to do with the chief benefit: <i>cryptographically strong concealment</i>.
At least, this is the property offered by Single Packet Authorization but admittedly not necessarily with
Port Knocking.  Let's first go through some of the more common criticisms of PK/SPA, and show what the SPA answer
is to each one.  For those that haven't considered SPA in the past, perhaps it is time to give it a second
look if for no other reason than to propose a method for breaking it.

<h3>1) Isn't PK/SPA just another password?</h3>
Suppose I hand you an arbitrary IP, say 2.2.2.2 that is running a default-drop firewall policy.  As an
attacker, you scan 2.2.2.2 and can't get any information back whatsoever.  It doesn't respond to pings,
Nmap cannot detect any TCP or UDP service under all scanning techniques, and any Metasploit module that
relies on a TCP connect() call is ineffective.  In the absence of a routing issue, it is safe to assume there
is a firewall or ACL blocking all incoming scans.  It is not feasible
to tell whether there are any services listening (SSH or otherwise), and it also not feasible to tell whether
there is a PK/SPA daemon either - the firewall is being used to do what it does best: block network traffic.
The point is that <b><i>there is no information</i></b> coming back from the
target.  A PK/SPA daemon <i>may</i> be deployed, but the passive nature of PK/SPA makes it undiscoverable [1].
<br/><br/>
As a thought experiment, what would it take to make PK/SPA "just another password"?  Well, if the PK/SPA
daemon listened on a TCP socket and advertised itself via a server banner (like
"<i>fwknop-2.5.1, enter password for SSH access:</i>") this would go a long way.  Then Nmap would once again become
an effective tool for finding the PK/SPA daemon, and an attacker could start to try different passwords.
In other words, the daemon would no longer be passive, which is the whole point of PK/SPA to begin with.
<br/><br/>
But wait, you might say "but attackers can just try to brute force passive PK/SPA
daemons anyway (even though they can't scan for them directly) and see if a port opens up", which brings us to:

<h3>2) Can PK/SPA be brute-forced?</h3>
Port Knocking implementations that use simple shared sequences are
certainly vulnerable to brute forcing, and they are also vulnerable to replay attacks.  These vulnerabilities
(among <a href="/fwknop/index.html#spa-advantages-over-port-knocking">other problems</a>) were primary motivators
for the development of SPA, and any modern SPA implementation is <b><i>not</i></b>
vulnerable to either of these attacks.  For example, fwknop uses AES in CBC mode
authenticated with an HMAC SHA-256 in the encrypt-then-authenticate model, and both the encryption and HMAC
keys (256 and 512 bits respectively for a total of 768 bits) are generated from random data in
<a href="/fwknop/docs/fwknop-tutorial.html#basic-outline">--key-gen</a> mode.
Further, fwknop can leverage GnuPG instead of AES, and 2048-bit GnuPG keys are fully supported.  If it were
practical to brute force fwknop encryption and authentication, then it would also be practical to brute
force a lot of other cryptographic software too.  Hence, fwknop is not vulnerable to such attacks in any practical sense [2].

<!-- Brute force attacks can be <i>attempted</i> against just about everything that uses cryptography.  The real question
is whether a brute force attack is practical given the strength of the crypto vs. the computing power and delivery
mechanisms available to an attacker.  -->
<br/><br/>
Beyond this, from 1) above remember that the very existence of the SPA daemon is not discoverable by
an attacker.  For the average adversary, interacting with the SPA daemon must be done blindly "by chance".
So, the target - even if it is running an SPA daemon which the attacker can't see - which implementation should
the attacker try to brute force?  If the target is running Moxie Marlinspike's
<a href="http://www.thoughtcrime.org/software/knockknock/">knockknock</a> (which uses AES in CTR mode
authenticated with a truncated HMAC SHA-1), then the attacker needs to try and brute force the daemon with
crafted TCP SYN packets via the following fields: TCP window size, TCP sequence, TCP acknowledgement, and
the network layer IP ID.
On the other hand, if the target is running fwknop, then the attacker would have to try and brute force the
fwknopd daemon with UDP payloads to a port that the fwknopd pcap filter statement allows (although fwknopd can also
be configured to only accept SPA payloads over ICMP instead).  Should the attacker try to brute force the fwknop
AES-CBC + HMAC SHA-256 mode?  Or the GnuPG + HMAC SHA-256 mode?  Further, the fwknopd daemon can place restrictions
on the services that an authenticated client is authorized to request via the
<a href="/fwknop/docs/fwknop-tutorial.html#multiple-services">access.conf</a> file.  There are a lot of bits
adding up, and the entire time the attacker doesn't even know whether an SPA daemon is actually running let
alone <i>which one</i>.
<br/><br/>
Unfortunately for the attacker it gets worse.  Even if the attacker could somehow brute force both
the encryption and authentication steps in fwknop or other SPA software, to which service should the attacker
try to make a connection?  No service has to listen on the default port, so if a connection to SSH isn't answered
should the attacker scan the target looking for a service?  Maybe SPA is being used to conceal an
IMAP daemon, a webserver, or OpenVPN instead of SSHD?  Further, because the SPA daemon never
acknowledges anything to begin with, the attacker can only infer that a brute force attempt was successful
by seeing if a service is finally available after each attempt.  So, in order for the attacker to be effective,
the work flow <i>for every brute force attempt</i> should be: (1) brute force attempt, (2) scan for
SSH (just because SPA is usually used to conceal SSH), (3) full scan if the SSH scan doesn't work.
This starts to become extremely noisy to say the least.  Even if full scans aren't also used, the volume of
traffic just to attempt brute force operations by themselves is prohibitively huge.
<br/><br/>
Regardless of the attacker work flow, which service is concealed, or how heavily the attacker scans the
target after every attempt, the brute force resistance offered by fwknop is fundamentally provided through
the strength of cryptography.  Getting past the authentication step alone would require breaking the 512-bit
HMAC SHA-256 key (or forcing a hash collision against SHA-256), and fwknop even supports HMAC SHA-512 if one
prefers that instead.  Beyond this, the encryption key would also need to be brute-forced.  For all intents
and purposes it is not practical to brute force fwknop, and similar arguments apply to other SPA software.

<h3>3) Does PK/SPA add intolerable complexity?</h3>
Every security measure has some associated complexity.  Firewalls add complexity.  Encryption adds complexity.
SSH itself adds complexity.  If complexity were always the trump card against higher levels of security,
then people would connect admin shells to sockets directly via netcat (or just run telnet) and not worry about
encryption.  People would not run firewalls because vanilla IP stacks without firewalling hooks would be simpler.
Filesystem permissions overlays would be considered insecure because they add complexity.  Obviously such
viewpoints don't pass muster in the real world.  The point is that using more complex code sometimes
enables higher levels of security against widely understood threat models.
For example, people use SSH and SSL because they want
authentication and confidentiality over untrusted networks.  Firewalls are used to reduce the attack surface that
an adversary can easily communicate with.  Application and/or filesystem layer policy controls are engineered to
place restrictions on classes of users.  The list continues.
<br/><br/>
This is not to say that complexity is not an important consideration - far from it.  Rather, a real security
benefit must be realized in order to justify increasing the complexity of a system.  In the SPA community,
we assert there is a security benefit afforded by passive, cryptographically strong service concealment.
How would an attacker try to brute force user passwords via SSH when it is concealed by SPA?
How would an attacker exploit even a zero-day vulnerability in a service protected by SPA?
How would an attacker exploit a vulnerability in the SPA daemon itself when it is
indistinguishable from a system that is running a default-drop firewall policy?  (An attacker may interact
with the SPA daemon, but it is more or less "by chance" [3].)
<br/><br/>
In the context of PK/SPA, the real issue is whether the complexity of the code that an attacker can interact
with is more or less when PK/SPA is deployed.  Anyone protecting
networked services is probably already running a firewall, so the firewall usage by the PK/SPA software
isn't adding to complexity that wasn't already there.  Next, if PK/SPA is used to conceal multiple
services (say, SSH, an IMAP daemon, and a webserver all at the same time), a would-be attacker cannot interact with
any of those code bases without first getting past the PK/SPA daemon.  It is a good bet that the complexity
of the PK/SPA daemon is a lot less than the aggregate complexity of all three of those services if they
were open to the world.  Further, this may still be true even for a single daemon such as SSH as well.  In essence,
the effective complexity of code that an attacker can interact with may actually go down with PK/SPA deployed - that
is, until the PK/SPA daemon can be circumvented (and hence a method for doing this becomes an important question for
an attacker).

<h3>4) What happens if the PK/SPA daemon dies?</h3>
This is a solved problem.  Process monitoring software has been around for decades.  Many options
exist for any OS on which a PK/SPA daemon is deployed.  For example, on Ubuntu systems fwknopd is monitored by
<a href="http://upstart.ubuntu.com/">upstart</a>.  Having said this, fwknopd is extremely stable
anyway so this feature is hardly ever needed in practice.  Still, it is certainly important to ensure
that PK/SPA usage does not cause a single point of failure, so using process monitoring software is a good
idea.

<h3>Summary</h3>
There are other criticisms of SPA that are not included in this blog post, and certainly some of them
are legitimate such as the fact that SPA requires a specialized client to access concealed services and
the fact that "NAT piggybacking" is possible for users on the same network from which an SPA client is
used when behind a NAT.  However, these points don't generally rise to the level that they invalidate the
SPA strategy.  This blog post attempts to address those criticisms that could rise to this level were it not
for the effort that has gone into solid SPA design by fwknop and other projects.  More information on the
<a href="/fwknop/docs/fwknop-tutorial.html#design">design goals</a> that guide fwknop can be
found in the <a href="/fwknop/docs/fwknop-tutorial.html">project tutorial</a>.
<br/><br/>
In conclusion, SSL uses cryptography to provide authentication and confidentiality, Tor uses cryptography
to provide anonymity, and SPA uses cryptography to conceal service existence.  For those that assert there
is no security value in the later strategy, it should consequently not be difficult to circumvent.  To those
in this camp, given the material in this post, please propose a method for breaking SPA.
<br/><br/>

<b>[1]</b> At least, a PK/SPA daemon is not discoverable by attackers who aren't already in a privileged position
to sniff all traffic to and from the target.  Clearly, <i>most</i> attackers - including password-guessing
botnets - do not fall into this category.
<br/><br/>

<b>[2]</b> It is possible to weaken the security of fwknop SPA communications by not using --key-gen mode to
generate random encryption and HMAC keys and thereby make them more susceptible to brute force attacks.
However, this type of problems similarly affects other cryptographic software so it isn't unique to fwknop.
And, even if a user doesn't use --key-gen mode, it is still not as easy to brute force fwknopd (which never confirms its
existence to an attacker) as other software which an attacker can readily see is available to exploit.
<br/><br/>

<b>[3]</b> The security of fwknopd code itself is nonetheless quite important, and this is why the fwknop
project uses static analysis provided by <a href="http://www.coverity.com/">Coverity</a> (and has a Coverity
scan score of zero), the CLANG static analyzer, and also implements dynamic analysis with
<a href="http://www.valgrind.org/">valgrind</a> via a comprehensive test suite.

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2013/09/tcp-options-and-detection-of-masscan-port-scans.html</link>
<title>TCP Options and Detection of Masscan Port Scans</title>
<dc:date>2013-09-30T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[

After Errata Security <a href="http://blog.erratasec.com/2013/09/we-scanned-internet-for-port-22.html">scanned port 22</a>
across the entire Internet earlier this month, I thought I would go back through my iptables logs to see
how the scan appeared against one of my systems.  Errata Security published the IP they used for the
scan as <b>71.6.151.167</b> so that it is easy to differentiate their scan from all of the other scans
and probes:
<pre>
[minastirith]# grep 71.6.151.167 /var/log/syslog | grep "DPT=22 "
Sep 12 21:19:15 minastirith kernel: [555953.034807] DROP IN=eth0 OUT= MAC=00:13:46:11:11:11:78:cd:11:6b:11:7e:11:00 SRC=71.6.151.167 DST=1.2.3.4 LEN=40 TOS=0x00 PREC=0x20 TTL=241 ID=17466 PROTO=TCP SPT=61000 DPT=22 WINDOW=0 RES=0x00 SYN URGP=0
</pre>
Interestingly, the SYN packet that produced the log message above does not contain TCP options.
The LOG rule in the iptables policy was built with the <b>--log-tcp-options</b> switch, and yet
the OPT field for TCP options is not included.  Looking through the Masscan sources, TCP SYN
packets are created with the <b>tcp_create_packet()</b> function which
<a href="https://github.com/robertdavidgraham/masscan/blob/master/src/templ-pkt.c#L321">does not appear</a>
to include code to set TCP options, and neither does the default
<a href="https://github.com/robertdavidgraham/masscan/blob/master/src/templ-pkt.c#L24">template</a>
used for describing TCP packets.  This is most likely done in order to maximize performance - not from the
perspective of the sender since a static hard-coded TLV encoded buffer would have done nicely - but
rather to minimize the time that scanned TCP stacks must spend processing the incoming SYN packets
before a response is made.  While this processing time is trivial for individual TCP connections,
it would start to become substantial when trying to rapidly scan the entire IPv4 address space.
<br/><br/>
A consequence of this strategy is that SYN packets produced by Masscan look
different on the wire from SYN packets produced by most operating systems (at least according to
<a href="http://lcamtuf.coredump.cx/p0f3/releases/old/2.x/">p0f</a>), and they also differ
from SYN scans produced by Nmap (which do include options as we'll see below).  This is not to
say that every SYN packet without options necessarily comes from Masscan.  There are operating
systems in the p0f signature set (such as Ultrix-4.4) that
do not include options, and the Scapy project also seems not to set options by default when
producing SYN scans like <a href="http://www.secdev.org/projects/scapy/doc/usage.html#syn-scans">this</a>.
In addition it looks like Zmap also
<a href="https://github.com/zmap/zmap/blob/master/src/probe_modules/module_tcp_synscan.c#L53">does not include</a>
TCP options in SYN scans.  For reference, here are three iptables LOG messages for SYN packets produced
by a standard TCP connect() call from an Ubuntu 12.04 system, an Nmap SYN (-sS) scan, and Scapy (source
and destination IP's and MAC addresses have been obscured):
<pre>
### TCP connect() SYN:
Sep 29 21:16:00 minastirith kernel: [171470.436701] DROP IN=eth0 OUT= MAC=00:13:46:11:11:11:78:cd:11:6b:11:7e:11:00 SRC=2.2.2.2 DST=1.2.3.4 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=15593 DF PROTO=TCP SPT=58884 DPT=12345 WINDOW=14600 RES=0x00 SYN URGP=0 OPT (020405B40402080A0CE97C070000000001030306)

### Nmap SYN (-sS):
Sep 29 21:16:12 minastirith kernel: [171482.094163] DROP IN=eth0 OUT= MAC=00:13:46:11:11:11:78:cd:11:6b:11:7e:11:00 SRC=2.2.2.2 DST=1.2.3.4 LEN=44 TOS=0x00 PREC=0x00 TTL=39 ID=26480 PROTO=TCP SPT=48271 DPT=12345 WINDOW=4096 RES=0x00 SYN URGP=0 OPT (020405B4)

### Scapy SYN via: sr1(IP(dst="1.2.3.4")/TCP(dport=12345,flags="S"))
Sep 29 21:35:15 minastirith kernel: [172625.207745] DROP IN=eth0 OUT= MAC=00:13:46:11:11:11:78:cd:11:6b:11:7e:11:00 SRC=2.2.2.2 DST=1.2.3.4 LEN=40 TOS=0x00 PREC=0x00 TTL=64 ID=1 PROTO=TCP SPT=20 DPT=12345 WINDOW=8192 RES=0x00 SYN URGP=0
</pre>

As a result, we can infer that SYN scans without options <i>may</i> originate from Masscan (the
Scapy example not withstanding since Scapy's usage as a port scanner is a probably a lot less
common than Masscan usage), and this will become more likely true over time as Masscan's popularity
increases.  (It is included as a tool leveraged by
<a href="https://community.rapid7.com/community/infosec/sonar/blog/2013/09/26/welcome-to-project-sonar">Rapid7's Sonar</a>
project for example.)
<br/><br/>
The upcoming 2.2.2 release of <a href="/psad">psad</a> will include detection of scans that
originate from Masscan, and if you check out the latest psad sources from git, this feature
has <a href="https://github.com/mrash/psad/commit/b19a03fd59ab60a1a8811ee506b82905fbe00542">already been added</a>.
To make this work, the iptables LOG rule needs to be instantiated with
the <b>--log-tcp-options</b> switch, and a new psad.conf configuration variable "EXPECT_TCP_OPTIONS"
has been added to assist.  When looking for Masscan SYN scans, psad requires at least one TCP
options field to be populated within a LOG message (so that it knows --log-tcp-options has been
set for at least some logged traffic), and after seeing this then subsequent SYN packets with no options
are attributed to Masscan traffic.  All usual psad threshold variables continue to apply however,
so (by default) a single Masscan SYN packet will not trigger a psad alert.  Masscan detection
can be disabled altogether by setting EXPECT_TCP_OPTIONS to "N", and this will not affect any
other psad detection techniques such as passive OS fingerprinting, etc.

]]></description>
</item>

<item>
<link>http://www.cipherdyne.org/blog/2013/08/design-of-a-new-xbits-cross-stream-ids-keyword.html</link>
<title>Design of a New 'xbits' Cross-Stream IDS Keyword</title>
<dc:date>2013-08-22T21:01:30-05:00</dc:date>
<dc:creator>Michael Rash</dc:creator>
<description><![CDATA[


In the previous <a href="/blog/2013/07/crossing-the-streams-in-ids-signature-languages.html">blog post</a> a proposal
was made for a new Snort and Suricata keyword "<b>xbits</b>" for cross-stream signature matching.
This post had little discussion of implementation tradeoffs, and some have reacted to the blog post by saying
that it is difficult to properly design and implement the type of cross-stream state tracking that would be
necessary for xbits to work.  I agree.  However, the initial xbits proposal did not assume that such an implementation
would be easy or straightforward, and this blog post will attempt to illustrate where some of the pitfalls are
likely to be.  In the end, I'm confident that is possible to develop something similar to <b>xbits</b>.
<a href="http://blog.inliniac.net/">Victor Julien</a>, lead developer of Suricata, commented on my
<a href="https://plus.google.com/108005327469166871589">Google+</a> posting on the xbits keyword to state that
Suricata has been considering implementing something similar to xbits for a while.
<br/><br/>
First, before diving into xbits itself, I would argue that there is already precedent in IDS/IPS engines
for detecting an important class of communications that
cross multiple transport layer "conversations" (using this term loosely for a moment): port scans
and sweeps.  Detecting such traffic is mostly about setting thresholds on various things such
as the number of ports and IP addresses that are contacted within a given period of time, prioritizing
on sets of ports that are usually associated with important services (with sweeps for certain
ports sometimes spiking after a new vulnerability is discovered), and differentiating
TCP flags that are used (a TCP FIN scan looks a lot different than a connect() scan and indicates some
things about the adversary such as privileged OS access).  By definition, the raw ability to differentiate
scans and sweeps vs. normal traffic requires the capability of keeping some state across transport
layer conversations.  It just so happens that Snort and Suricata track this state
within dedicated preprocessors and do not also expose port scan detection configuration in the signature
language itself.  By contrast, other preprocessors do offer signature language interfaces such as
<em>stream5</em> with the <em>flow</em> keyword.  To be clear, I'm <em><b>not</b></em> at all advocating
that configuration aspects of the <a href="http://manual.snort.org/node17.html#SECTION00323000000000000000">sfPortscan</a>
preprocessor actually belong in the signature language (that would be unnatural to say the least) - I'm
merely making the point that the idea of maintaining some state across transport layer conversations is
something that Snort and Suricata already do.  So, in this area at least, such a concept is not foreign.

<h3>Traffic Visibility</h3>
Now, in terms of factors that would affect an xbits implementation, it should be noted that not every IDS/IPS
necessarily has a global view of all traffic on a given network.  This can be the result of several different factors
that depend not only on the physical hardware, but also how the IDS/IPS itself is developed (multi-threaded
or not), and configured.  Starting with the hardware, I've seen major IDS deployments that require multiple
IDS appliances working together in order to inspect all of the network traffic.  Essentially the IDS
appliances form a cluster of systems (not in the HPC sense) where portions of the traffic are split
across each appliance with a device such as a <a href="http://www.gigamon.com">Gigamon</a> tap.  This allows
each IDS appliance to handle a fraction of the traffic that it would otherwise have had to inspect, and this
in turn enables the cluster as a whole to scale to massive amounts of network traffic.  But, this also means
portions of the traffic are physically separated from one IDS to the next, and therefore xbits on a single
IDS can only apply to the set of transport layer conversations that actually traverse it.  So, is there an
opportunity for an attacker to evade xbits when deployed in this fashion?  Sure, if the attacker knows how the
traffic splitting is done, then attacks could most likely be sent against systems in ways that nullify xbits
criteria just by using different source networks to force each individual IDS appliance into having only a
limited view of a cross-stream attack.  There are potential evasions at every level, but many attackers are
not going to have access to such traffic splitting details.
<br/><br/>
Other IDS/IPS architectures such as those that rely on network processors or specialized packet acquisition
hardware can also result in limited traffic visibility.  Some organizations run multiple Snort processes on
a single appliance, and have a network processor split packet data based on IP network ranges or transport
layer port number across the Snort instances.  Once again, each Snort process has a limited few of the
traffic.  Similarly, in a multi-threaded IDS/IPS such as Suricata, each thread may be tasked with processing
a portion of the total network traffic, and this can result in a limited view within software even if there
is no hardware enforced traffic splitting mechanism.

<h3>The Stream Preprocessor</h3>
Modifying the stream preprocessor to handle the xbits keyword could be tricky.  By its nature, xbits
would force the stream preprocessor to consider information that is not derived from
single transport layer conversations, so locking issues against a global xbits tracking data structure
in a multi-threaded context would become important.  Also, it would be nice to not place onerous
restrictions on xbits such as requiring that a connection close before a set xbit can be tested within
a different connection.  My guess is that stream preprocessor modifications have previously been a barrier
to implementing something like xbits.

<h3>xbits Design</h3>
Given all of the above, what would be the ideal xbits design?  Stepping back for a moment, when any
signature language feature is implemented in an IDS, what should be the primary goal?
<em><b>Better attack detection.</b></em>
Performance is certainly a consideration too, and performance features sometimes bleed into
the signature language (see the <a href="http://manual.snort.org/node382.html">fast_pattern</a> keyword
for example), but usually a new signature language feature is added
because it enables better detection of threats at acceptable performance levels.  Further, some features
of the language are important enough to expend lots of CPU cycles and consume precious memory anyway
because the detection accuracy would be significantly harmed without them - see the
<a href="http://manual.snort.org/node32.html#SECTION004523000000000000000">pcre</a> keyword for example.
So, we should strive for the ideal xbits design from a detection perspective and let performance and other
tradeoffs take place where they must:
<br/><br/>
<ol>
<li>Allow an xbit to be set on one transport layer conversation and inspected in a different conversation
before the first is closed.</li>
<li>Allow an xbit to be set on a conversation that involves one IP protocol, and tested
in a conversation that involves a different IP protocol.  E.g. set a bit on a UDP flow and test it in
a subsequent TCP connection.</li>
<li>Interface with the current stream preprocessor to allow the setting and testing of xbits to
take advantage of existing connection tracking capabilities.  This most likely can be implemented as
an extension to stream5 without requiring a wholly new preprocessor.</li>
<li>For multi-threaded intrusion detection engines such as Suricata, some of the same tradeoffs that
allow port scan detection to apply across threads could be used for xbits.  Ideally, xbits would not
be limited to traffic that is seen within a single thread.</li>
</ol>

]]></description>
</item>

<!-- end_stories -->

</channel>
</rss>
