<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="html">cipherdyne.org | System and Network Security</title>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org"/>
<link rel="self" type="application/atom+xml" href="http://www.cipherdyne.org/atom.xml"/>
<updated>2012-02-13T14:05:53-05:00</updated>
<author>
<name>Michael Rash</name>
<uri>http://www.cipherdyne.org</uri>
</author>
<icon>/images/favicon.ico</icon>
<logo>/images/favicon.ico</logo>
<id>http://www.cipherdyne.org/</id>
<generator uri="http://www.cipherdyne.org" version="3.0">
perl
</generator>

<!-- begin_stories -->
<entry>
<title type="html">On SPA Cross-Packet Ciphertext Entropy</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2012/02/on-spa-cross-packet-ciphertext-entropy.html"/>
<id>http://www.cipherdyne.org/blog/2012/02/on-spa-cross-packet-ciphertext-entropy.html</id>

<published>2012-02-13T21:01:30-05:00</published>
<updated>2012-02-13T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

<link type="text/html" href="/fwknop/">
<img align="right" src="/images/random_dice.jpg" title="fwknop SPA packet entropy" alt="fwknop SPA packet entropy" width="200" height="150" /></link>
With fwknop now re-written in C for the <link type="text/html" href="/blog/2012/01/software-release-fwknop-2.0.html">2.0 release</link>,
I thought it would be a good idea to take a look at how close encrypted SPA packet data comes to having
high levels of entropy - as understood to be a measure of randomness - from one packet to the next.  If
fwknop is properly using encryption, and the ciphers themselves are also well-implemented (fwknop can
use either Rijndael or GPG), then we would expect there to be no obvious relationship between SPA packets
even for repeated access requests to the same service.  If there are any such relationships in the
encrypted data across multiple SPA packets, then an adversary <i>might</i> be able to infer things about
the underlying plaintext - precisely what strong encryption is supposed to make difficult.  This blog
post covers SPA packet entropy for AES (Rijndael) CBC and ECB encryption modes, and leaves GPG to another
post.
<br/><br/>
Although this post has some similarities with an older blog entry
"<link type="text/html" href="/blog/2008/09/visualizing-spa-packet-randomness.html">Visualizing SPA Packet Randomness</link>",
a more rigorous and automated way of measuring cross-packet SPA entropy will be presented.  In addition,
we'll take a look at what happens when (normally) random
<link type="text/html" href="http://en.wikipedia.org/wiki/Salt_%28cryptography%29">salt</link>
values for AES encrypted SPA packets are artificially forced to be constant.  This helps to highlight
some real differences in AES electronic codebook (ECB) and cipher block chaining (CBC) encryption
modes.
<br/><br/>
First, the next release of fwknop will most likely offer the ability to select different AES encryption
modes (such as cipher feedback (CBF) mode and output feedback (OFB) mode), and a dedicated
"<link type="text/html" href="/cgi-bin/gitweb.cgi?p=fwknop.git;a=shortlog;h=refs/heads/crypto_update">crypto_update</link>"
branch has been created for this work.  The default AES encryption mode used by fwknop is cipher block chaining
(CBC) mode as defined
<link type="text/html" href="/cgi-bin/gitweb.cgi?p=fwknop.git;a=blob;f=lib/fko.h;h=e694a718a8fd51b02572384e57428101903d592e;hb=71690a1de45b273789af4e26a01594e9d5150eff#l179">here</link>.
Within the <b>crypto_update</b> branch there is a new script
"<link type="text/html" href="/cgi-bin/gitweb.cgi?p=fwknop.git;a=blob;f=extras/spa-entropy/spa-entropy.pl;h=a5ebd7fddaba9bae7393227fb395422781de816d;hb=71690a1de45b273789af4e26a01594e9d5150eff">spa-entropy.pl</link>"
that is designed to execute the fwknop client multiple times, collect the encrypted SPA packet data, use the
<link type="text/html" href="http://www.fourmilab.ch/random/">ent</link> program to measure the entropy in slices for each byte
position across the SPA data set, and then plot the results with gnuplot.  What does this accomplish?  It
allows us to easily see for any given byte position within a collection of SPA packets whether there is a
relation from one to the next.  If there is such a relation, then the cipher used to encrypt the
data was not very good at achieving high levels of entropy in the ciphertext across multiple packets.
<br/><br/>
As a motivating
<link type="text/html" href="http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation">example</link> from Wikipedia, AES in
ECB mode encrypts identical plaintext blocks into identical ciphertext blocks, and this results in patterns
in plaintext data being preserved to some extent in the ciphertext.  So, an adversary can make good guesses
about the underlying plaintext just by looking at the ciphertext!  Wikipedia does a nice job of illustrating
this with the following two images of the Linux kernel mascot "Tux" - before and after AES encryption in
ECB mode:
<br/><br/>

<table>
<tr>
<td><img src="/images/tux.jpg" title="plaintext Tux" alt="plaintext Tux" /></td>
<td><b>AES ECB encryption -&gt;
</b></td>
<td><img src="/images/tux_ecb.jpg" title="AES ECB encrypted Tux" alt="AES ECB encrypted Tux" /></td>
</tr>
</table>

<i><b>Encryption Fail.</b></i>
<br/><br/>
Now, let's take a look at SPA packet entropy with the <b>spa-entropy.pl</b> script.  For reference, fwknop
builds SPA packets according to the following data format before encryption:
<br/><br/>
<b>[random data: 16 bytes]:[username]:[timestamp]:[version]:[message type]:[access request]:[digest]</b>
<br/><br/>

So, if a user wants repeated access to the same service protected behind fwknopd on some
system, then several fields above will be identical across the corresponding SPA packets before
they are encrypted.  The username, version, message type, and access request fields will likely be the
same.  If fwknop has made proper use of encryption, then the fact that these fields are the same across
multiple SPA packets should not matter.  After encryption, an observer should not be
able to tell anything about the underlying plaintext (other than perhaps size since AES is a block
cipher).  Let's verify this for 1,000 SPA packets encrypted with the default CBC mode - they are all
encrypted with the same key 'fwknoptest' by the <b>spa-entropy.pl</b> script:

<br/><br/>
<code>
$ ./spa-entropy.pl -f 1000_pkts.data -r -c 1000 --base64-decode<br/>
[+] Running fwknop client via the following command:<br/>
<br/>
LD_LIBRARY_PATH=../../lib/.libs ../../client/.libs/fwknop -A tcp/22 -a 127.0.0.2 -D 127.0.0.1 --get-key local_spa.key -B 1000_pkts.data -b -v --test -M cbc<br/>
<br/>
[+] Read in 1000 SPA packets...<br/>
[+] Min entropy: 7.75 at byte: 54<br/>
[+] Max entropy: 7.86 at byte: 115<br/>
[+] Creating entropy.gif gnuplot graph...<br/>
</code>
<br/><br/>

This produces the gnuplot graph below.  Perfectly random data would produce
8 bits of entropy per byte, and the min/max values of 7.75 and 7.86 along with the fairly
uniform distribution of similar values across all of the SPA byte positions implies that
there is little relation from one SPA packet to the next - good.

<img src="/images/1000_spa_cbc.gif" title="SPA entropy for CBC mode" alt="SPA entropy for CBC mode" />

As an aside, here is
what <b>ent</b> reports against the local <b>/dev/urandom</b> entropy source on my Linux system, and it is
the "Entropy =" line that <b>spa-entropy.pl</b> parses for each SPA byte slice:

<br/><br/>
<code>
$ dd if=/dev/urandom count=1000 |ent<br/>
1000+0 records in<br/>
1000+0 records out<br/>
512000 bytes (512 kB) copied, 0.128497 s, 4.0 MB/s<br/>
Entropy = 7.999625 bits per byte.<br/>
<br/>
Optimum compression would reduce the size<br/>
of this 512000 byte file by 0 percent.<br/>
<br/>
Chi square distribution for 512000 samples is 265.77, and randomly<br/>
would exceed this value 50.00 percent of the times.<br/>
<br/>
Arithmetic mean value of data bytes is 127.5076 (127.5 = random).<br/>
Monte Carlo value for Pi is 3.138715386 (error 0.09 percent).<br/>
Serial correlation coefficient is -0.001293 (totally uncorrelated = 0.0).
</code>
<br/><br/>

Now, let's switch to ECB mode and see what happens (just run the <b>spa-entropy.pl</b> script
with '-e ecb'):

<img src="/images/1000_spa_ecb.gif" title="SPA entropy for ECB mode" alt="SPA entropy for ECB mode" />

Well, that still looks pretty good.  Revisiting the ECB encrypted image of Tux above
for a moment - the reason that the Tux outline can be seen in the encrypted version
is that in the JPG image file there must be identical blocks in multiple locations
to represent the solid black regions.  These blocks are all encrypted in the same
way by AES in ECB mode, so the outline persists.  But, this is one instance of ECB
encryption against a file that has multiple identical blocks.  For the encrypted SPA
packets, we're dealing with 1,000 separate instances of encrypted data (all with the
same key).  Across this data set there are certainly lots of identical plaintext
blocks (all of the SPA packets request access for source IP 127.0.0.2 to destination
port tcp/22 for example), but the encrypted data still shows a high level of entropy.
This source of entropy is provided by the random salt values that are used to
generate the initialization vector and final encryption key for each encrypted SPA
packet.  As proof, if we apply the following patch to force the salt to zero for all
SPA packets (of course, one would not want to use this patch in practice):

<br/><br/>
<code>
$ git diff lib/cipher_funcs.c<br/>
diff --git a/lib/cipher_funcs.c b/lib/cipher_funcs.c<br/>
index 0a0ce3b..32c8bd6 100644<br/>
--- a/lib/cipher_funcs.c<br/>
+++ b/lib/cipher_funcs.c<br/>
@@ -153,6 +153,8 @@ rij_salt_and_iv(RIJNDAEL_context *ctx, const char *pass, const unsigned char *da<br/>
 get_random_data(ctx-&gt;salt, 8);<br/>
 }<br/>
 <br/>
+memset(ctx-&gt;salt, 0x00, 8);<br/>
+<br/>
 /* Now generate the key and initialization vector.<br/>
  * (again it is the perl Crypt::CBC way, with a touch of<br/>
  * fwknop).
</code>
<br/><br/>

Here is what <b>spa-entropy.pl</b> reports after recompiling fwknop with the patch above:

<img src="/images/1000_spa_ecb_zero_salt.gif" title="SPA entropy for ECB mode zero salt" alt="SPA entropy for ECB mode zero salt" />

Now we can easily see where there are identical blocks across the SPA packet data set.  The first
eight bytes contains the salt, so these are all zero (note that fwknop strips the
usual "Salted__" prefix before transmitting an SPA packet on the wire).  The next
16 bytes are the random bytes that fwknop includes in every SPA packet so these bytes
have high entropy.  Next up are the username and timestamp - the later changes with
each second, so there is some entropy there since it takes a few seconds to create the
1,000 SPA packet data set.  Then the entropy goes back to zero with the next fields
and there isn't any decent entropy until the final message digest.
<br/><br/>

As a final contrasting case, let's leave the patch applied to force the salt to zero, but now
switch back to CBC mode:

<img src="/images/1000_spa_cbc_zero_salt.gif" title="SPA entropy for CBC mode zero salt" alt="SPA entropy for CBC mode zero salt" />

In CBC mode, the random data included by the fwknop client now results in decent entropy
even though the salt is zero.  This is because every ciphertext block in CBC mode
depends on all previous plaintext blocks, so randomness in one plaintext block implies
that every subsequent encrypted block will look different from one SPA packet to the
next.  This graphically shows that CBC mode is a better choice for strong security.
Now, if the pseudo random number generator on the local operating system is poorly
implemented, this will negatively impact ciphertext entropy regardless of the encryption
mode, but still CBC mode is a better alternative than ECB mode.
<br/><br/>
Although <b>spa-entropy.pl</b> is geared towards measuring SPA packet entropy, this technique
could certainly be generalized to arbitrary collections of ciphertext.  If you know of such
an implementation, please email me.

</p>
</div>
</content>
</entry>

<entry>
<title type="html">Bing Indexing of gitweb.cgi Links</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2012/01/bing-indexing-of-gitweb.cgi-links.html"/>
<id>http://www.cipherdyne.org/blog/2012/01/bing-indexing-of-gitweb.cgi-links.html</id>

<published>2012-01-21T21:01:30-05:00</published>
<updated>2012-01-21T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

<link type="text/html" href="http://www.bing.com/">
<img align="right" src="/images/bing-logo.png" height="100" width="130" title="Bing indexing of gitweb.cgi links" alt="Bing indexing of gitweb.cgi links" /></link>
In June, 2011, all of the cipherdyne.org software projects were switched over to git from svn,
and at the same time the web interface was switched to gitweb (along with hosting at github)
from trac.  Given the switch, I knew there would be a change to how search engines indexed the
code/data, and one question would be whether any particular search engine would take a specific
interest in the code provided via git and/or gitweb.  Note that each of the fwknop, psad,
fwsnort, and gpgdir projects have raw git repositories that can be cloned directly over HTTP
from cipherdyne.org (a nice feature of git), or viewed with any browser through
<link type="text/html" href="http://www.cipherdyne.org/cgi-bin/gitweb.cgi">gitweb</link>.
(Personally, I like the "<link type="text/html" href="http://atrey.karlin.mff.cuni.cz/~clock/twibright/links">links2</link>"
text-based browser rendering of gitweb pages - nice and clean.)
<br/><br/>
First, here are some stats for indexing bots from major search engines across all cipherdyne.org
Apache log data for hits against gitweb.cgi from June, 2011 to today:
<br/><br/>
<table class="ctable" cellspacing="1" cellpadding="1">
<tr><td>Hits</td><td>Percentage</td><td>User-Agent</td></tr>
<tr><td><b>505055</b></td><td>81.01%</td><td><b>Mozilla/5.0 (compatible; bingbot/2.0;)</b></td></tr>
<tr><td><b>50242</b></td><td>8.06%</td><td><b>msnbot/2.0b (+http://search.msn.com/msnbot.htm)._</b></td></tr>
<tr><td><b>25707</b></td><td>4.12%</td><td><b>Mozilla/5.0 (compatible; Ezooms/1.0; ezooms.bot@gmail.com)</b></td></tr>
<tr><td><b>6583</b></td><td>1.06%</td><td><b>Feedfetcher-Google; (+http://www.google.com/feedfetcher.html;)</b></td></tr>
<tr><td><b>4310</b></td><td>0.69%</td><td><b>Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)</b></td></tr>
<tr><td><b>1956</b></td><td>0.31%</td><td><b>Mozilla/5.0 (compatible; SISTRIX Crawler; http://crawler.sistrix.net/)</b></td></tr>
<tr><td><b>1905</b></td><td>0.31%</td><td><b>Mozilla/5.0 (compatible; Purebot/1.1; +http://www.puritysearch.net/)</b></td></tr>
<tr><td><b>1751</b></td><td>0.28%</td><td><b>Mozilla/5.0 (compatible; Yahoo! Slurp;)</b></td></tr>
<tr><td><b>1625</b></td><td>0.26%</td><td><b>Mozilla/5.0 (compatible; MJ12bot/v1.4.0;)</b></td></tr>
<tr><td><b>1451</b></td><td>0.23%</td><td><b>TwengaBot-Discover (http://www.twenga.fr/bot-discover.html)</b></td></tr>
</table>
<br/><br/>
Wow!  So bots associated with Microsoft's Bing search engine take the top two spots for a
combined hit total of well over 500,000 since June, 2011.  If spread out over the entire time
period (which it's not as we'll see) that would be an average of about 2,600 hits <i>per day</i>,
and this figure is more than 20 times the third place bot.  Google is in
a distant forth place, even though Google used to
<link type="text/html" href="/blog/2009/09/google-indexing-of-trac-repositories.html">heavily index Trac repositories</link>.
<br/><br/>
So, let's see how the search engine hits are distributed since June, 2011.  First, here is a
graph of just gitweb hits by the top five crawlers:
<img src="/images/gitweb_user_agents.gif" title="top 5 gitweb indexers" alt="top 5 gitweb indexers" />

Clearly, that is not a very uniform distribution from day to day.  It looks like Bing has been
hitting the gitweb interface at a rate of over 17,000 hits per day for a significant portion
of late December and early January.  The other search engines hardly even show up in the graph -
you know there are big spikes when everything looks better on a logarithmic scale:
<img src="/images/gitweb_user_agents_logscale.gif" title="top 5 gitweb indexers logarithmic" alt="top 5 gitweb indexers logarithmic" />

With some additional work, it looks like the gitweb.cgi links that Bing is indexing are not all
unique.  That is, one might expect that Bing would hit a link, grab the content, and then not return
to the same link for a while.  Some gitweb.cgi links were hit more than 10 times and more than 100,000
links were hit more than once during this time period.
<br/><br/>
How does this compare with hits across other portions of cipherdyne.org?  Bing indexing is still
far and away the largest outlier:
<img src="/images/all_user_agents.gif" title="top 5 indexers of cipherdyne.org" alt="top 5 indexers of cipherdyne.org" />

Given that 1) all of the information gitweb displays is derived from the underlying git repositories,
and 2) the git repositories are directly accessible via HTTP anyway, it would seem that a better way for
search engines to behave would be to just ignore gitweb altogether and pull directly from git.  That
would certainly cut down on the server-side resources necessary to service search engine requests.
Perhaps though the general strategy of search engines is not to be too smart about such things - they
probably just want access to data, and when they see a link they go after it.
Either way, the kind of dedicated and repetitive indexing the Bing is doing against gitweb is a bit much,
and it certainly seems as though they could implement a less intensive crawler.  I'm curious if other
server admins are seeing similar behavior.
<br/><br/>
<b>Update 01/23</b>: There are tons of web analysis tools out there, but I wrote a couple of quick
scripts to generate the data in this blog post.  The first "<link type="text/html" href="/scripts/user_agent_stats_pl.tar.gz">user_agent_stats.pl</link>"
parses Apache logs and produces user-agent graphs with Gnuplot as shown in this post.  The second
"<link type="text/html" href="/scripts/uniq_hits_pl.tar.gz">uniq_hits.pl</link>" is extremely simple and just counts the
number of hits against the same links within the Apache log data.  Both scripts accept log data via
TDIN - here is an example where user agents who hit any "index.html" link are plotted (graph is
not shown):
<br/><br/>
<code>
$ zcat ../logs/cipherdyne.org*.gz |grep "index.html" | ./user_agent_stats.pl -p index_hits<br/>
[+] Parsing Apache log data...<br/>
[+] Total agents: 1769 (abbreviated to: 174 agents)<br/>
[+] Executing gnuplot...<br/>
    Plot file:  index_hits.gif<br/>
    Agent stats: index_hits.agents
</code>
<br/><br/>


</p>
</div>
</content>
</entry>

<entry>
<title type="html">Software Release - fwknop-2.0</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2012/01/software-release-fwknop-2.0.html"/>
<id>http://www.cipherdyne.org/blog/2012/01/software-release-fwknop-2.0.html</id>

<published>2012-01-02T21:01:30-05:00</published>
<updated>2012-01-02T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

<link type="text/html" href="/fwknop/download/">
<img align="right" src="/images/release.png" title="fwknop-2.0" alt="fwknop-2.0 released" /></link>
After a long development cycle, <link type="text/html" href="/fwknop"><b>fwknop-2.0</b></link> has
been <link type="text/html" href="/fwknop/download">released</link>.  This is the first production release of the
fully re-written C version of fwknop, and is the culmination of an effort to provide
<link type="text/html" href="/fwknop/docs/SPA.html">Single Packet Authorization</link> to multiple open source
firewalls, embedded systems, mobile devices, and more.  On the "server" side, supported
firewalls now include iptables on Linux, ipfw on FreeBSD and Mac OS X, and pf on OpenBSD.
The fwknop client is known to run on all of these platforms, and also functions on
Windows systems running under Cygwin.  There is also an Android client, and a good start
on a iPhone client as well.  On a personal note, I wish to thank Damien Stuart for a
heroic effort to port most of the original perl code over to C.  Also, several other
people have made significant contributions including Jonathan Bennet, Max Kastanas,
Sebastien Jeanquier, Ozmart, and others.  If there are any issues, please get in touch
with me directly or send an email to the fwknop
<link type="text/html" href="https://lists.sourceforge.net/lists/listinfo/fwknop-discuss">mailing list</link>.
<br/><br/>
<b>Update 01/03</b>: Both libfko library that powers much of fwknop operations and the
fwknop client can be compiled as native Windows executables.  In addition, there are perl
and python bindings to libfko as well.
<br/><br/>
<b>Update 01/07</b>: Damien Stuart has built
<link type="text/html" href="/fwknop/download/binaries.html">RPM files</link> for fwknop on RHEL5, RHEL6,
Fedora 15, 16, and 17 and for other architectures the Fedora koji build system can
produce.

</p>
</div>
</content>
</entry>

<entry>
<title type="html">Software Release - fwknop-2.0rc5</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2011/12/software-release-fwknop-2.0rc5.html"/>
<id>http://www.cipherdyne.org/blog/2011/12/software-release-fwknop-2.0rc5.html</id>

<published>2011-12-11T21:01:30-05:00</published>
<updated>2011-12-11T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

<link type="text/html" href="/fwknop/download/">
<img align="right" src="/images/fwknop-iphone.jpg" height="275" width="147" title="fwknop-2.0rc5" alt="fwknop-2.0rc5 released" /></link>
The 2.0rc5 candidate release of <link type="text/html" href="/fwknop"><b>fwknop</b></link> is available for
<link type="text/html" href="/fwknop/download/"><b>download</b></link>.  There may be a few tweaks to the
code before the official 2.0 release is made, but this is pretty close as-is.  Significant
development work has gone into fwknop since the 2.0rc4 release, and adds some major new
functionality as well as fixing a few bugs.  Here is a summary of the changes:
<br/><br/>
<b>iPhone fwknop client</b>:  Max Kastanas has contributed an iPhone port of the fwknop client.  He had
already contributed on Android client, so the iPhone was the next natural step!  We're looking for a
maintainer of the iPhone code so that eventually it can be made available through the App Store.  If
you have iPhone development experience and are interested in taking this on, please
<link type="text/html" href="http://www.cipherdyne.org/contact.html">contact me</link>.
<br/><br/>
<b>PF firewall support on OpenBSD</b>:  For quite a while now fwknop has brought Single Packet Authorization
 support to iptables firewalls on Linux and ipfw firewalls on FreeBSD and Mac OS X systems. The 2.0rc5
release now introduces support for the <link type="text/html" href="http://www.openbsd.org/cgi-bin/man.cgi?query=pf">PF</link>
firewall on OpenBSD systems.  By interfacing with the <b>pfctl</b> command, fwknop creates new rules to
access a protected service (such as SSHD) to a PF anchor.  Rules are deleted out of a running
anchor with <i>pfctl -a &lt;anchor&gt; -f -</i> with the expired rule(s) removed.  There is support
in the fwknop test suite (see the test/ directory in the fwknop-2.0rc5 sources) to validate fwknop
operations on OpenBSD systems, and if there are any issues please let me know.
<br/><br/>
<b>Expiring SPA keys</b>:  With large SPA deployments where many different encryption
keys - either Rijndael or GPG keys - are used to service lots of external users, key
management can become somewhat of a burden.  This feature allows an expiration date
to be set in the <b>access.conf</b> file on a per-key basis.  Any SPA packet received
for an expired key is ignored by fwknopd.  This feature was suggested by ozmart from
the fwknop mailing list.
<br/><br/>
<b>FORCE_NAT mode</b>:  For iptables firewalls, a new FORCE_NAT mode has been
implemented that works as follows: for any valid SPA packet, force the requested
connection to be NAT'd through to the specified (usually internal) IP and port value.
This is useful if there are multiple internal systems running a service such as
SSHD, and you want to give transparent access to only one internal system
for each stanza in the access.conf file.  This way, multiple external
users can each directly access only one internal system per SPA key.
<br/><br/>
<b>lsof launcher</b>: The fwknop lsof launcher (extras/fwknop-launcher/fwknop-launcher-lsof.pl)
is a lightweight daemon that allows the user to not have to manually run the fwknop
client when attempting to gain access to a service that is protected by
via fwknopd.  This is accomplished by checking the output
of lsof to look for pending connections in the SYN_SENT state, which (usually)
indicate that a remote firewall is blocking the attempted connection.  At this
point, the launcher executes the fwknop client with the --get-key arg (so the
user must place the key in the local filesystem) to generate an SPA packet for
the attempted connection.  The remote fwknopd daemon will reconfigure the
firewall to allow temporary access, and this usually happens fast enough that
the original connection attempt will then succeed as TCP retries to establish
the connection.  The idea for this was originally for a pcap-based connection
watcher by Sebastien Jeanquier.
<br/><br/>
Several other changes and small fixes have been made as well.  The fwknop test
suite supports running all tests through the excellent
<link type="text/html" href="http://www.valgrind.org/">valgrind</link> project, and this enabled
several memory handling issues to be found and corrected.
<br/><br/>
fwknop is released under the GPL version 2, and the complete fwknop-2.0rc5
ChangeLog can be found
<link type="text/html" href="/cgi-bin/gitweb.cgi?p=fwknop.git;a=blob;f=ChangeLog-v2.0rc5;h=65f565b705c1a74ccd93deef24d68e738eb288d4;hb=7ac5319847b6cf75dc5d5cdb4cdd41b55ee711b3">here</link>
via the fwknop <link type="text/html" href="/cgi-bin/gitweb.cgi?p=fwknop.git;a=summary">gitweb</link> interface.


</p>
</div>
</content>
</entry>

<entry>
<title type="html">WebKnock.org Single Packet Authorization Proxy</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2011/10/webknock.org-single-packet-authorization-proxy.html"/>
<id>http://www.cipherdyne.org/blog/2011/10/webknock.org-single-packet-authorization-proxy.html</id>

<published>2011-10-10T21:01:30-05:00</published>
<updated>2011-10-10T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

Vasilis Mavroudis has developed a web proxy called <link type="text/html" href="https://webknock.org/">WebKnock.org</link>
that allows anyone to generate an fwknop SPA packet on their behalf with just a web browser.
Although fwknop client portability has improved quite a bit in anticipation of the upcoming
fwknop-2.0 release, it is a nice addition to the SPA world to not need the fwknop client
installed at all.  There are probably several platforms where the native client might not
function but can run a web browser.
<br/><br/>
Using the webknock.org proxy requires that the user provide the SPA key over SSL to
webknock.org, but this is a necessary step in exchange for not having to install the fwknop
client.  As of this writing, SPA via <link type="text/html" href="/fwknop/docs/gpghowto.html">gpg keys</link> is
not yet supported, but there are plans to support this in the future.  All requests to
generate an SPA packet are protected by a captcha.
<br/><br/>
Behind the scenes, webknock.org executes the fwknop client on behalf of users, and Vasilis
informed me that he's using the latest client code (written in C) instead of the older perl
client.  This is good since all recent development is done on the C version of fwknop in
order to make it as small and lightweight as possible.
<br/><br/>
The service is free, and will hopefully be open-sourced at some point as well.  If there are
any issues, please either <link type="text/html" href="/contact.html">email me</link> or open a ticket on the fwknop
<link type="text/html" href="https://github.com/mrash/fwknop/issues">github interface</link>.  Here is a
screenshot of the current webknock.org site:
<link type="text/html" href="/images/webknock_screenshot.png"><img src="/images/webknock_screenshot.png" height="320" width="500" title="webknock.org SPA proxy" alt="webknock.org SPA proxy" /></link>

</p>
</div>
</content>
</entry>

<entry>
<title type="html">fwknop in the OpenWrt and Pentoo Linux Distributions</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2011/08/fwknop-in-the-openwrt-and-pentoo-linux-distributions.html"/>
<id>http://www.cipherdyne.org/blog/2011/08/fwknop-in-the-openwrt-and-pentoo-linux-distributions.html</id>

<published>2011-08-23T21:01:30-05:00</published>
<updated>2011-08-23T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

<link type="text/html" href="https://openwrt.org/">
<img align="right" src="/images/openwrt-logo.png" height="51" width="200" title="fwknop in OpenWrt" alt="fwknop in OpenWrt" /></link>
The C version <link type="text/html" href="/fwknop">fwknop</link> has now made it into the <link type="text/html" href="https://openwrt.org">OpenWrt</link>
Linux distribution for embedded devices.  Jonathan Bennett made this possible
by contributing a <link type="text/html" href="http://www.cipherdyne.org/cgi-bin/gitweb.cgi?p=fwknop.git;a=commitdiff;h=e7d275ee312c618c3233a504c5aa54b72312f39a">Makefile</link>
for OpenWrt, and it was picked up the OpenWrt maintainers.  It is good to
see progress made towards the integration of
<link type="text/html" href="/fwknop/docs/SPA.html">Single Packet Authorization</link> into operating
systems that are designed to function as secure gateway devices between multiple
networks.
<br/><br/>
So far, fwknop is available in the OpenWrt trunk packages feed, but will eventually become
available via the opkg package manager too.  Fortunately, OpenWrt makes everything
available via git:
<br/><br/>
<code>
$ git clone git://nbd.name/packages.git openwrt_packages.git<br/>
Initialized empty Git repository in /home/mbr/src/openwrt_packages.git/.git/<br/>
remote: Counting objects: 56118, done.<br/>
remote: Compressing objects: 100% (21342/21342), done.<br/>
remote: Total 56118 (delta 29694), reused 54875 (delta 29054)<br/>
Receiving objects: 100% (56118/56118), 11.85 MiB | 2.57 MiB/s, done.<br/>
Resolving deltas: 100% (29694/29694), done.<br/>
$ cd openwrt_packages.git<br/>
$ git ls-files |grep fwknop<br/>
net/fwknop/Makefile<br/>
$ git log net/fwknop/Makefile<br/>
commit 89475e5d6136833fa3b59c3d47c4f2be02718c7a<br/>
Author: florian &lt;florian@3c298f89-4303-0410-b956-a3cf2f4a3e73&gt;<br/>
Date:   Wed Aug 17 10:13:20 2011 +0000<br/>
<br/>
    [package] add fwknopd<br/>
<br/>
    Signed-off-by; Jonathan Bennett &lt;[email removed]&gt;<br/>
<br/>
    git-svn-id: svn://svn.openwrt.org/openwrt/packages@28030 3c298f89-4303-0410-b956-a3cf2f4a3e73<br/>
<br/>
</code>
<br/><br/>

In other news, both the perl and C versions of fwknop are also available in the
<link type="text/html" href="http://www.pentoo.ch/"><img src="/images/pentoo-logo.png" align="left" height="100" width="100">Pentoo</img></link> Linux
distribution thanks to <link type="text/html" href="https://www.pentoo.ch/pentoo/search?q=fwknop">ozmart and the Pentoo maintainers</link>.
Pentoo is a live-cd distribution that is focused on security and derived from
<link type="text/html" href="http://www.gentoo.org">Gentoo</link>.  ozmart wrote a description of the
use case for fwknop on Pentoo from a pentration testing perspective:
<br/><br/>
<i>
"...This is a useful script when combined with iptables and sshd. Configuration can accommodate
pgp and replay attack checks. It allows the box to appear silent when running daemons
if your box is deployed in say, a hostile environment.
<br/><br/>
It can also allow commands to be run without actually having to log into the box, say if
you wanted to trigger something interesting from a remote location..."
</i>

</p>
</div>
</content>
</entry>

<entry>
<title type="html">Software Release - fwsnort-1.6</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2011/07/software-release-fwsnort-1.6.html"/>
<id>http://www.cipherdyne.org/blog/2011/07/software-release-fwsnort-1.6.html</id>

<published>2011-07-28T21:01:30-05:00</published>
<updated>2011-07-28T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

<link type="text/html" href="/fwsnort/download/">
<img align="right" src="/images/release.png" title="fwsnort-1.6" alt="fwsnort-1.6 released" /></link>
The 1.6 release of <link type="text/html" href="/fwsnort"><b>fwsnort</b></link> is available for
<link type="text/html" href="/fwsnort/download/"><b>download</b></link>.  This is a fairly significant
release that adds support for the Snort <b>fast_pattern</b> keyword, makes enhancements to
the --QUEUE and --NFQUEUE modes, supports the conntrack module for connection tracking,
adds support for case-insensitive pattern matches using the --icase argument to the iptables
string match extension, and several other things.  The Snort fast_pattern keyword allows the
rule author to influence the order in which Snort tries
to match a pattern against network traffic.  When multiple patterns are included in a rule,
Snort usually tries to match the longest pattern first reasoning that the longest pattern
is probably the least likely to trigger a match and therefore the remaining pattern searches
would not have to be performed.  But, there are times when the rule author would like to
explicitly ask Snort to match on a particular pattern first, and the fast_pattern keyword
is the mechanism that makes this possible.  Because iptables matches are evaluated in order
and a failing match short circuits a rule, fast_pattern support with the string match
extension is possible through proper ordering in the iptables rule.  Here is an example
Snort rule from <link type="text/html" href="http://www.emergingthreats.net">Emerging Threats</link> with the
fast_pattern keyword applied to the forth pattern:

<br/><br/>
<code>
alert tcp $EXTERNAL_NET $HTTP_PORTS -&gt; $HOME_NET any (msg:"ET WEB_CLIENT Possible Internet Explorer srcElement Memory Corruption Attempt"; flow:established,to_client; file_data; content:"document.createEventObject"; distance:0; nocase; content:".innerHTML"; within:100; nocase; content:"window.setInterval"; distance:0; nocase; content:"srcElement"; fast_pattern; nocase; distance:0; classtype:attempted-user; reference:url,www.microsoft.com/technet/security/bulletin/ms10-002.mspx; reference:url,tools.cisco.com/security/center/viewAlert.x?alertId=19726; reference:url,www.kb.cert.org/vuls/id/492515; reference:cve,2010-0249; reference:url,doc.emergingthreats.net/2010799; reference:url,www.emergingthreats.net/cgi-bin/cvsweb.cgi/sigs/CURRENT_EVENTS/CURRENT_MSIE; sid:2010799; rev:5;)
</code>
<br/><br/>

fwsnort translates this rule as follows in iptables-save format from the <b>/etc/fwsnort/fwsnort.save</b>
file - the original iptables commands in non-save format are also available in the
<b>/etc/fwsnort/fwsnort_iptcmd.sh</b> script:

<br/><br/>
<code>
-A FWSNORT_FORWARD_ESTAB -p tcp -m tcp --sport 80 -m string --string "srcElement" --algo bm --from 82 --icase -m string --string "document.createEventObject" --algo bm --from 64 --icase -m string --string ".innerHTML" --algo bm --to 190 --icase -m string --string "window.setInterval" --algo bm --from 74 --icase -m comment --comment "sid:2010799; msg:ET WEB_CLIENT Possible Internet Explorer srcElement Memory Corruption Attempt; classtype:attempted-user; reference:url,www.microsoft.com/technet/security/bulletin/ms10-002.mspx; rev:5; FWS:1.6;" -j LOG --log-ip-options --log-tcp-options --log-prefix "SID2010799 ESTAB "
</code>
<br/><br/>

Note that the <b>srcElement</b> string is matched first in the iptables rule even though
it is the last string in the original Snort rule.

With fast_pattern support, fwsnort policies should be a bit faster at run time in the
in the Linux kernel.

On a final note, the iptables <b>multiport</b> match is also supported with the fwsnort-1.6
release, so Snort rules with lists of source or destination ports (like this:
"alert tcp $HOME_NET [0:20,22:24,26:138,140:444,446:464,466:586,588:901,903:1432,1434:65535] -&gt; any any")
can be translated.
<br/><br/>
The complete fwsnort-1.6 ChangeLog can be found
<link type="text/html" href="/cgi-bin/gitweb.cgi?p=fwsnort.git;a=blob;f=ChangeLog-v1.6;h=345f18c259c655bb2946f55bb676ca699e90e5c5;hb=fwsnort-1.6">here</link>
via the fwsnort <link type="text/html" href="/cgi-bin/gitweb.cgi?p=fwsnort.git;a=summary">gitweb</link> interface.


</p>
</div>
</content>
</entry>

<entry>
<title type="html">Switched from subversion to git</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2011/06/switched-from-subversion-to-git.html"/>
<id>http://www.cipherdyne.org/blog/2011/06/switched-from-subversion-to-git.html</id>

<published>2011-06-26T21:01:30-05:00</published>
<updated>2011-06-26T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

<link type="text/html" href="http://www.git-scm.com/">
<img align="right" src="/images/git-logo.png" title="switched to git" alt="switched to git" /></link>
After using <link type="text/html" href="http://subversion.tigris.org/">subversion</link> for several years, I've switched
to <link type="text/html" href="http://www.git-scm.com/">git</link> for all cipherdyne.org projects.  Subversion has
certainly served its purpose, but it is hard to look at git and not feel a compelling draw.  Further,
with easy to set up web interfaces to git repositories such as
<link type="text/html" href="https://git.wiki.kernel.org/index.php/Gitweb">gitweb</link> and free hosting services such
as <link type="text/html" href="http://github.com/">github</link>, providing a public git repository is trivial.  Git itself
can allow repositories to be cloned directly over HTTP without needing infrastructure like WebDAV,
and here are links for the cipherdyne.org projects (github and gitweb links too):
<br/><br/>
<ul>
<li><link type="text/html" href="/git/fwknop.git">fwknop</link> (<link type="text/html" href="/cgi-bin/gitweb.cgi?p=fwknop.git;a=summary">gitweb</link>, <link type="text/html" href="http://github.com/mrash/fwknop">github</link>)</li>
<li><link type="text/html" href="/git/fwsnort.git">fwsnort</link> (<link type="text/html" href="/cgi-bin/gitweb.cgi?p=fwsnort.git;a=summary">gitweb</link>, <link type="text/html" href="http://github.com/mrash/fwsnort">github</link>)</li>
<li><link type="text/html" href="/git/psad.git">psad</link> (<link type="text/html" href="/cgi-bin/gitweb.cgi?p=psad.git;a=summary">gitweb</link>, <link type="text/html" href="http://github.com/mrash/psad">github</link>)</li>
<li><link type="text/html" href="/git/gpgdir.git">gpgdir</link> (<link type="text/html" href="/cgi-bin/gitweb.cgi?p=gpgdir.git;a=summary">gitweb</link>, <link type="text/html" href="http://github.com/mrash/gpgdir">github</link>)</li>
</ul>

The <link type="text/html" href="http://trac.cipherdyne.org/trac/">trac</link> interface will remain active for a little
while to see the legacy svn repositories, but the git repositories were all converted from these in
order to preserve the history so trac is no longer important.  If you are interested in the latest
code changes in, say, fwsnort then just clone the repository and then you can make your own changes:

<br/><br/>
<code>
$ git clone http://www.cipherdyne.org/git/fwsnort.git<br/>
Initialized empty Git repository in /home/mbr/tmp/git/fwsnort/.git/<br/>
$ cd fwsnort<br/>
$ git status<br/>
# On branch master<br/>
nothing to commit (working directory clean)<br/>
$ git show --summary<br/>
commit 00c4379a69975097948ed9e5ba356eeba69c0c93<br/>
Author: Michael Rash &lt;mbr@cipherdyne.org&gt;<br/>
Date:   Mon Jun 20 21:00:57 2011 -0400<br/>
<br/>
    Added the --Conntrack-state argument<br/>
<br/>
    Added the --Conntrack-state argument to specify a conntrack state in place of<br/>
    the "established" state that commonly accompanies the Snort "flow" keyword.<br/>
    By default, fwsnort uses the conntrack state of "ESTABLISHED" for this.  In<br/>
    certain corner cases, it might be useful to use "ESTABLISHED,RELATED" instead<br/>
    to apply application layer inspection to things like ICMP port unreachable<br/>
    messages that are responses to real attempted communications.  (Need to add<br/>
    UDP tracking for the _ESTAB chains for this too - coming soon.)<br/>
</code>
<br/><br/>


</p>
</div>
</content>
</entry>

<entry>
<title type="html">fwknop in BackTrack 5</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2011/06/fwknop-in-backtrack-5.html"/>
<id>http://www.cipherdyne.org/blog/2011/06/fwknop-in-backtrack-5.html</id>

<published>2011-06-23T21:01:30-05:00</published>
<updated>2011-06-23T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
fwknop has made it into <link type="text/html" href="http://www.backtrack-linux.org/">BackTrack</link>
Linux distribution.  Well, it didn't make it into the default image, but it is in
the BackTrack software repository so installing it is a snap with <b>apt-get</b>
or <b>aptitude</b>.  Below is a screenshot of the BackTrack 5 VM installed under
VMware Player running on Ubuntu, and running a search shows both the
<b>fwknop-client</b> and <b>fwknop-server</b> packages that are maintained by
<link type="text/html" href="http://packages.qa.debian.org/f/fwknop.html">Franck Joncourt</link> for
the Debian distribution.

<link type="text/html" href="/images/bt_fwknop_in_repos.png">
<img src="/images/bt_fwknop_in_repos.png" width="600" height="450" title="fwknop in BackTrack 5" alt="fwknop in BackTrack 5" />
</link>
<br/>
Update 06/24/2011: Thanks to <link type="text/html" href="http://www.securitygeneration.com">Sebastien Jeanquier</link>
for calling this to my attention and helping to support the inclusion of fwknop in BackTrack Linux.
<br/><br/>

</p>
</div>
</content>
</entry>

<entry>
<title type="html">Software Release - fwsnort-1.5</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2011/01/software-release-fwsnort-1.5.html"/>
<id>http://www.cipherdyne.org/blog/2011/01/software-release-fwsnort-1.5.html</id>

<published>2011-01-09T21:01:30-05:00</published>
<updated>2011-01-09T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

<link type="text/html" href="/fwsnort/download/">
<img align="right" src="/images/release.png" title="fwsnort-1.5" alt="fwsnort-1.5 released" /></link>
The 1.5 release of <link type="text/html" href="/fwsnort"><b>fwsnort</b></link> is available for
<link type="text/html" href="/fwsnort/download/"><b>download</b></link>.  This is a major release
that moves to using the iptables-save format for instantiating the fwsnort policy, and
this allows the run time for adding the fwsnort policy to the kernel to be drastically reduced.
fwsnort now splices in the translated Snort rules into the iptables policy in the running
kernel <i>at the time of translation</i>.  So, any updates to the iptables
policy that are made after fwsnort is executed and before <b>fwsnort.sh</b> is run would be lost.
Hence, it is advisable to execute fwsnort.sh soon after running fwsnort.
This is a reasonable tradeoff though considering the performance benefit as seen
below - which gives an example of how long it takes to add an fwsnort iptables policy
via the old strategy of executing one iptables command at a time vs. implementing the
same policy with iptables-restore.  First, fwsnort is used to translate the Snort
<b>web-misc.rules</b>, <b>web-cgi.rules</b>, <b>backdoor.rules</b> files like so:
<br/><br/>
<code>
[root@minastirith /etc/fwsnort]# fwsnort --snort-rfile web-misc.rules,web-cgi.rules,backdoor.rules --no-ipt-sync<br/>
<br/>
[+] Generated iptables rules for 713 out of 754 signatures: 94.56%<br/>
<br/>
[+] Logfile: /var/log/fwsnort/fwsnort.log<br/>
[+] iptables script (individual commands): /etc/fwsnort/fwsnort_iptcmds.sh<br/>
<br/>
    Main fwsnort iptables-save file: /etc/fwsnort/fwsnort.save<br/>
<br/>
    You can instantiate the fwsnort policy with the following command:<br/>
<br/>
    /sbin/iptables-restore &lt; /etc/fwsnort/fwsnort.save<br/>
<br/>
    Or just execute: /etc/fwsnort/fwsnort.sh<br/>
</code>
<br/><br/>

The output above illustrates the changes for the fwsnort-1.5 release.  All of the previous
behavior in fwsnort has been preserved in the <b>/etc/fwsnort/fwsnort_iptcmds.sh</b>
script.  That is, each individual iptables command to add every fwsnort rule one by
one is implemented in this script - this is analogous to how the <b>fwsnort.sh</b> script was
built by older versions of fwsnort.  But, with the 1.5 release the <b>fwsnort.sh</b> script
now just executes the iptables-restore command against the new <b>fwsnort.save</b> file.
<br/><br/>
If we execute the <b>fwsnort_iptcmds.sh</b> script and time its execution, we get the
following on my desktop system:
<br/><br/>
<code>
[root@minastirith /etc/fwsnort]# time /etc/fwsnort/fwsnort_iptcmds.sh<br/>
[+] Adding backdoor rules:<br/>
    Rules added: 122<br/>
[+] Adding web-cgi rules:<br/>
    Rules added: 696<br/>
[+] Adding web-misc rules:<br/>
    Rules added: 600<br/>
[+] Finished.<br/>
<br/>
real    0m24.391s<br/>
user    0m1.560s<br/>
sys     0m11.500s<br/>
[root@minastirith /etc/fwsnort]# iptables -v -nL |wc -l<br/>
1509
</code>
<br/><br/>

So, the fwsnort policy together with the running iptables policy is about 1500
rules long, and it took over 24 seconds to add to the running kernel.  Now, let's
time the <b>fwsnort.sh</b> script instead (which is just a
wrapper around the iptables-restore command):

<br/><br/>
<code>
[root@minastirith /etc/fwsnort]# time /etc/fwsnort/fwsnort.sh<br/>
<br/>
[+] Splicing fwsnort rules into the iptables policy...<br/>
    Done.<br/>
<br/>
<br/>
real    0m0.121s<br/>
user    0m0.060s<br/>
sys     0m0.040s<br/>
[root@minastirith /etc/fwsnort]# iptables -v -nL |wc -l<br/>
1509
</code>
<br/><br/>

Ok, over 24 seconds to instantiate the fwsnort policy for the old strategy, and about
a 10th of a second for the new strategy for a speed up of 240 times!  This gets even
better for an fwsnort policy with thousands of rules.  Note that the number of iptables
rules is the same between the two executions.
<br/><br/>

The complete
<link type="text/html" href="http://trac.cipherdyne.org/trac/fwsnort/browser/fwsnort/tags/fwsnort-1.5/ChangeLog">
ChangeLog</link> entries are displayed below:
<br/><br/>
<ul>
<li>Major update to use the iptables-save format instead of the older
strategy of always just executing iptables commands directly (which was
very flow for large fwsnort policies).  The /etc/fwsnort/fwsnort.sh
script now just executes:<br/>
<br/>
/sbin/iptables-restore &lt; /etc/fwsnort/fwsnort.save<br/>
<br/>
All fwsnort rules are now placed in the /etc/fwsnort/fwsnort.save file,
but the older fwsnort.sh output (for the individual commands version)
is still available at /etc/fwsnort/fwsnort_iptcmds.sh.  This
functionality extends to ip6tables policies as well.  The fwsnort man
page explain this in better detail:<br/>
<br/>
"As of fwsnort-1.5 all iptables rules built by fwsnort are written out
to the /etc/fwsnort/fwsnort.save file in iptables-save format.  This
allows a long fwsnort policy (which may contain thousands of iptables
rules translated from a large Snort signature set) to be quickly
instantiated via the "iptables-restore" command.  A wrapper script
/etc/fwsnort/fwsnort.sh is also written out to make this easy.  Hence,
the typical work flow for fwsnort is to: 1) run fwsnort, 2) note the
Snort rules that fwsnort was able to successfully translate (the number
of such rules is printed to stdout), and then 3) execute the
/etc/fwsnort/fwsnort.sh wrapper script to instantiate the policy in the
running kernel."</li>
<li>Added the --rules-url argument so that the URL for updating the
Emerging Threats rule set can be specified from the command line.  The
default is:
<br/><br/>
http://rules.emergingthreats.net/open/snort-2.9.0/emerging-all.rules
</li>
<li>Updated to automatically check for the maximum length string that the
string match supports, and this is used to through out any Snort rules
with content matches longer than this length.</li>
<li>Updated the iptables capabilities testing routines to add and delete
testing rules to/from the custom chain 'FWS_CAP_TEST'.  This maintains a
a cleaner separation between fwsnort and any existing iptables policy
even during the capabilities testing phase.</li>
<li>Added the --ipt-check-capabilities argument to have fwsnort test the
capabilities of the local iptables firewall and exit.</li>
<li>Added the --string-match-alg argument to allow the string matching
algorithm used by fwsnort to be specified from the command line.  The
default algorithm is 'bm' for 'Boyer-Moore', but 'kmp' may also be
specified (short for the 'Knuth-Morris-Pratt' algorithm).</li>
<li>Updated to the latest complete rule set from Emerging Threats (see
http://www.emergingthreats.net/).
</li>
</ul>


</p>
</div>
</content>
</entry>

<entry>
<title type="html">Single Packet Authorization on Android</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2011/01/single-packet-authorization-on-android.html"/>
<id>http://www.cipherdyne.org/blog/2011/01/single-packet-authorization-on-android.html</id>

<published>2011-01-07T21:01:30-05:00</published>
<updated>2011-01-07T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
<img align="right" src="/images/android-logo.jpg" width="140" height="150" title="fwknop on Android" alt="fwknop on Android" />
Kicking off 2011 with a bang is easy this year - Max Kastanas has ported the <link type="text/html" href="/fwknop">fwknop</link>
client to the <link type="text/html" href="http://www.android.com">Android</link> mobile operating sytem.  This brings Single
Packet Authorization to Google's smart phones, and was accomplished using Damien Stuart's
<link type="text/html" href="http://trac.cipherdyne.org/trac/fwknop/browser/trunk/lib">libfko</link> implementation.
All of the Android code can be found in the Cipherdyne
<link type="text/html" href="http://trac.cipherdyne.org/trac/fwknop/browser/trunk/android">Trac respository</link>.
A couple of screenshots of using the SPA app from an Android phone appear below - after the
SPA packet is sent and verified passively by the fwknop daemon on the remote system, the
fwknop Android app automatically launches <link type="text/html" href="http://code.google.com/p/connectbot/">Connectbot</link>
to access SSHD:
<br/><br/>
<img align="right" src="/images/android_fwknop.png" width="245" height="400" title="fwknop Android app" alt="fwknop Android app" />
<img class="rightfr" src="/images/android_connectbot.png" width="245" height="400" title="fwknop Android app" alt="fwknop Android app" />


</p>
</div>
</content>
</entry>

<entry>
<title type="html">How to avoid ClamAV matches on bundled Snort rules</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2010/08/how-to-avoid-clamav-matches-on-bundled-snort-rules.html"/>
<id>http://www.cipherdyne.org/blog/2010/08/how-to-avoid-clamav-matches-on-bundled-snort-rules.html</id>

<published>2010-08-22T21:01:30-05:00</published>
<updated>2010-08-22T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
<img align="right" src="/images/clamav.png" title="ClamAV matches on Snort rules" alt="ClamAV matches on Snort rules" />
Recently a <link type="text/html" href="/psad">psad</link> user notified me via email that the psad-2.1.7.tar.gz tarball
was flagged by <link type="text/html" href="http://www.clamav.net">ClamAV</link> as being infected with <b>Exploit.HTML.MHTRedir-8</b>.
After checking a few things, it turns out that ClamAV is triggering on a Snort rule in the
<link type="text/html" href="http://www.emergingthreats.net/">Emerging Threats</link> rule set which is bundled in both
<link type="text/html" href="/psad">psad</link> and <link type="text/html" href="/fwsnort">fwsnort</link>.  The following analysis shows
exactly what ClamAV is detecting and why, and also provides some guidance for how to avoid
this for any software projects that distribute Snort rules.  Similar logic would apply to
other software engineering efforts - including commercial intrusion detection systems - that
are (by their nature) looking for malicious artifacts on the filesystem or within network
traffic.
<br/><br/>
First, let's download psad-2.1.7.tar.gz and check the gpg signature (just to make sure we're
talking about exactly the same file):
<br/><br/>
<code>
$ wget --quiet http://www.cipherdyne.org/psad/download/psad-2.1.7.tar.gz<br/>
$ wget --quiet http://www.cipherdyne.org/psad/download/psad-2.1.7.tar.gz.asc<br/>
$ gpg --verify psad-2.1.7.tar.gz.asc<br/>
gpg: Signature made Wed 14 Jul 2010 06:01:42 PM EDT using DSA key ID 0D3E7410<br/>
gpg: Good signature from "Michael Rash (Signing key for cipherdyne.org projects) &lt;mbr@cipherdyne.org&gt;"
</code>
<br/><br/>
Ok, now here is what <b>clamscan</b> says about the psad-2.1.7.tar.gz tarball:
<br/><br/>
<code>
$ clamscan psad-2.1.7.tar.gz<br/>
psad-2.1.7.tar.gz: Exploit.HTML.MHTRedir-8 FOUND<br/>
<br/>
----------- SCAN SUMMARY -----------<br/>
Known viruses: 816934<br/>
Engine version: 0.96.1<br/>
Scanned directories: 0<br/>
Scanned files: 1<br/>
Infected files: 1<br/>
Data scanned: 6.42 MB<br/>
Data read: 1.16 MB (ratio 5.55:1)<br/>
Time: 7.169 sec (0 m 7 s)
</code>
<br/><br/>
Let's see which file within the psad-2.1.7 tarball matches the <b>Exploit.HTML.MHTRedir-8</b>
signature:
<br/><br/>
<code>
$ tar xfz psad-2.1.7.tar.gz<br/>
$ clamscan -r -i psad-2.1.7<br/>
psad-2.1.7/deps/snort_rules/emerging-all.rules: Exploit.HTML.MHTRedir-8 FOUND<br/>
<br/>
----------- SCAN SUMMARY -----------<br/>
Known viruses: 816934<br/>
Engine version: 0.96.1<br/>
Scanned directories: 41<br/>
Scanned files: 405<br/>
Infected files: 1<br/>
Data scanned: 12.55 MB<br/>
Data read: 6.41 MB (ratio 1.96:1)<br/>
Time: 8.446 sec (0 m 8 s)
</code>
<br/><br/>
Intuitively, this makes sense.  That is, given that ClamAV is out to identify nasty things
within files, and given that Snort rules are designed to identify nasty things as they
communicate over the network, it stands to reason that there might be some overlap.  This
overlap is <i>not</i> an indication of something wrong in either the Snort rules or in ClamAV.
Now, let's find out specifically which Snort rule within the <b>emerging-all.rules</b>
file is triggering the ClamAV match.  We first take a look at the <b>Exploit.HTML.MHTRedir-8</b>
signature:
<br/><br/>
<code>
$ cp /var/lib/clamav/main.cvd .<br/>
$ sigtool --unpack main.cvd<br/>
$ grep Exploit.HTML.MHTRedir-8 main.ndb<br/>
Exploit.HTML.MHTRedir-8:3:*:6d68746d6c3a66696c653a2f2f{1-20}2168
</code>
<br/><br/>
The last line above is the entire ClamAV signature, and the pattern <b>6d68746d6c3a66696c653a2f2f</b>
is the key.  The ":3:" part identifies the signature as type "normalized HTML", so ClamAV
matches the pattern <b>6d68746d6c3a66696c653a2f2f</b> against the "normalized HTML" representation
of each processed file.  We can decode the pattern as follows:
<br/><br/>
<code>
echo 6d68746d6c3a66696c653a2f2f | xxd -r -p<br/>
mhtml:file://
</code>
<br/><br/>
So, within the <b>emerging-all.rules</b> file, we are interested in any Snort rule that
contains the string <b>mhtml:file://</b>.  There is also the "<b>{1-20}2168</b>" criteria
which says to match the hex bytes 2168 anywhere from 1 to 20 bytes after the first
pattern match.
<br/><br/>
<code>
$ grep mhtml psad-2.1.7/deps/snort_rules/emerging-all.rules<br/>
alert tcp $HOME_NET any -&gt; $EXTERNAL_NET $HTTP_PORTS (msg:"ET MALWARE Bundleware Spyware CHM Download"; flow: to_server,established; content:"Referer\: ms-its\:mhtml\:file\://C\:counter.mht!http\://"; nocase; content:"/counter/HELP3.CHM\:\:/help.htm"; nocase; classtype: trojan-activity; sid: 2001452; rev:4;)<br/>
</code>
<br/><br/>
Sure enough, sid:2001452 "<b>ET MALWARE Bundleware Spyware CHM Download</b>" has the
keyword <b>content:"Referer\: ms-its\:mhtml\:file\://C\:counter.mht!http\://"</b>.  Even
though there are escaping backslashes, the normalized HTML processing in ClamAV takes
this into account and matches the pattern anyway from the ClamAV signature.
<br/><br/>
So, how can we keep the original Snort rule, but change it so that ClamAV not longer
flags it?
<br/><br/>
Fortunately, ClamAV does not interpret the Snort rules convention of specifying non-printable
bytes between "|" characters within content fields, so we simply need to change one of
characters to hex notation.  Snort will still offer the same detection if network traffic
matches the rule, and ClamAV won't flag it.  So, let's just change the "m" in "<b>mhtml\:file\://</b>"
to its hex equivalent, like so: "<b>|6d|html\:file\://</b>".  Once we make this change and save the
psad-2.1.7/deps/snort_rules/emerging-all.rules file, we rerun clamscan:
<br/><br/>
<code>
$ clamscan -r -i psad-2.1.7<br/>
<br/>
----------- SCAN SUMMARY -----------<br/>
Known viruses: 816934<br/>
Engine version: 0.96.1<br/>
Scanned directories: 41<br/>
Scanned files: 405<br/>
Infected files: 0<br/>
Data scanned: 17.23 MB<br/>
Data read: 6.41 MB (ratio 2.69:1)<br/>
Time: 10.024 sec (0 m 10 s)
</code>
<br/><br/>
That's better.  Over the next few days I'll re-release all affected versions of psad and
fwsnort with the above change to ensure that there aren't any additional ClamAV matches.
<br/><br/>
In conclusion, if you are involved in any software engineering effort that distributes
or makes use of Snort rules, it is probably a good idea to run distribution packages
through ClamAV and see if there are any matches.  If so, it may be possible to take
advantage of Snort rule syntax options to still achieve the same signature coverage while
not having ClamAV flag anything.


</p>
</div>
</content>
</entry>

<entry>
<title type="html">A new SSH password guessing botnet: dd_ssh</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2010/08/a-new-ssh-password-guessing-botnet-dd_ssh.html"/>
<id>http://www.cipherdyne.org/blog/2010/08/a-new-ssh-password-guessing-botnet-dd_ssh.html</id>

<published>2010-08-20T21:01:30-05:00</published>
<updated>2010-08-20T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
<img align="right" src="/images/malware.jpg" height="165" width="220" title="dd_ssh botnet" alt="dd_ssh botnet" />
Every few months it seems that there is a new variation of a password guessing botnet.
This time around, as reported by the <link type="text/html" href="http://isc.sans.edu/diary.html?storyid=9370">SANS ISC</link>
and also by <link type="text/html" href="http://www.malwarecity.com/community/index.php?showtopic=1177">malwarecity.com</link>,
a botnet called "<b>dd_ssh</b>" has been built up around a vulnerability in phpMyAdmin.
(Here is the <link type="text/html" href="http://lists.debian.org/debian-security-announce/2010/msg00074.html">vulnerability announcement</link>
from the Debian security list.)  Once a vulnerable webserver has been compromised, the
botnet starts scanning random IP addresses for SSH servers and attempts to brute force
passwords for those systems that accept an SSH connection.  Although software like
<b>Fail2ban</b> and <b>DenyHosts</b> can offer detection and mitigation by applying thresholds to
the number of failed login attempts in the SSH log and communicate offending source IP's
to a set of interested users, a fundamental problem is that the targeted SSH daemons
are reachable in the first place from arbitrary source IP's.  A more powerful
solution is to hide your SSH daemon behind a default-drop firewall policy and only
grant access through <link type="text/html" href="/fwknop">Single Packet Authorization</link>.
Any botnet that is scanning for SSH servers will not be able to guess any
passwords or even exploit a zero-day vulnerability in an SSH daemon that is protected
in this way.
<br/><br/>
Further, SSH brute forcing botnets have shown some
<link type="text/html" href="http://bsdly.blogspot.com/2008/12/low-intensity-distributed-bruteforce.html">innovative techniques</link>
where password guessing attempts are spread out over a long period of time and failed
passwords are distributed across the botnet.  The end result is that each botnet
node knows the population of passwords that other nodes have already tried on
each targeted SSH daemon, and so new passwords can be tried while still slipping
beneath common detection thresholds.  The same password never has to be tried twice
botnet-wide.  It is not clear yet whether the dd_ssh botnet uses a similar password
distribution strategy, but either way I intend to stop such guessing games at the
earliest stage possible and block all SSH connections by default.

</p>
</div>
</content>
</entry>

<entry>
<title type="html">HTTP Response Times for cipherdyne.org</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2010/08/http-response-times-for-cipherdyne.org.html"/>
<id>http://www.cipherdyne.org/blog/2010/08/http-response-times-for-cipherdyne.org.html</id>

<published>2010-08-15T21:01:30-05:00</published>
<updated>2010-08-15T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

<link type="text/html" href="http://oss.oetiker.ch/smokeping/index.en.html">
<img align="right" src="/images/smokeping.png" title="smokeping" alt="smokeping" /></link>
I'm a big fan of the <link type="text/html" href="http://oss.oetiker.ch/smokeping/index.en.html">Smokeping</link>
project developed by Tobi Oetiker, and I use it to graph ICMP, DNS, and HTTP round trip
times for my local internet connections and also for cipherdyne.org.  Since the beginning
of 2010, I've switched around where cipherdyne.org was hosted from a system at a hosting
provider in Canada to a system running on my home network (serviced by a Verizon FiOS
connection).  The drop in RTT's in mid-February was expected and quite large - going
from an average of around 200ms down to about 20ms.  Then, in June, I switched to a
different Verizon DSL connection and moved the cipherdyne.org webserver system to a
newer Verizon FiOS connection at a different location, and the RTT's went up a bit to
about 50ms.  Here is the graph:

<img src="/images/cipherdyne_400_days.png" title="cipherdyne.org 400 days" alt="cipherdyne.org 400 days" />


</p>
</div>
</content>
</entry>

<entry>
<title type="html">fwsnort Available in Fedora Repositories</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2010/08/fwsnort-available-in-fedora-repositories.html"/>
<id>http://www.cipherdyne.org/blog/2010/08/fwsnort-available-in-fedora-repositories.html</id>

<published>2010-08-13T21:01:30-05:00</published>
<updated>2010-08-13T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

<link type="text/html" href="http://fedoraproject.org/">
<img align="right" src="/images/fedora_logo.png" title="fwsnort on Fedora" alt="fwsnort on Fedora" /></link>
The <link type="text/html" href="/fwsnort/">fwsnort</link> project is now available directly through the
<link type="text/html" href="https://admin.fedoraproject.org/pkgdb/acls/name/fwsnort?_csrf_token=a9cbb9cbe99f8d2953b015db95f4f30a2bfd7395">Fedora RPM repositories</link>
(for Fedora 12 and 13) thanks to
<link type="text/html" href="http://koji.fedoraproject.org/koji/userinfo?userID=1466">Guillermo Gomez</link>.
The version that is currently bundled is fwsnort-1.0.6.  Once fwsnort-1.2 is
released, the implementation of large iptables rule sets that are derived from
Snort rules will become a lot faster.  This is because fwsnort is going to
support the <b>iptables-save</b> format by integrating the complex rules built by
fwsnort with any existing iptables policy that is instantiated in the kernel.
This is made possible by interpreting the local policy and splicing in all
of the fwsnort rules in the right places - each iptables chain is built from
scratch upon an <b>iptables-restore</b> (including the built-in chains), so
integrating with a running policy is not as easy as just adding each fwsnort
rule into a set of custom chains.  Compatibility with the iptables-save format
has largely been completed with <link type="text/html" href="http://trac.cipherdyne.org/trac/fwsnort/changeset/528">this patch</link>
in the fwsnort-1.2 development effort.
<br/><br/>
If you are running a Fedora 12 or 13 system, you can install fwsnort like so:
<br/><br/>
<code>
# yum install fwsnort
</code>
<br/><br/>

</p>
</div>
</content>
</entry>

<entry>
<title type="html">Pure C Implementation of Single Packet Authorization</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2010/07/pure-c-implementation-of-single-packet-authorization.html"/>
<id>http://www.cipherdyne.org/blog/2010/07/pure-c-implementation-of-single-packet-authorization.html</id>

<published>2010-07-25T21:01:30-05:00</published>
<updated>2010-07-25T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
<link type="text/html" href="/fwknop/">
<img align="right" src="/images/chinesedoor5.jpg" width="180" height="120" title="Pure C Implementation of Single Packet Authorization" alt="Pure C Implementation of Single Packet Authorization" /></link>
For the past several months, the pure-C implementation of Single Packet Authorization
with fwknop has been in development, and the first release candidate of
<link type="text/html" href="/fwknop/download/">fwknop-2.0.0</link> is ready for <link type="text/html" href="/fwknop/download/">download</link>.
Damien Stuart is the primary developer of this code, and I wish to thank him for
all of his efforts in making this release possible.  The original perl version of
fwknop will continue to receive bug fixes as they are found, but the primary
development effort is now on the lightweight and portable C code.  The Trac
interface for the perl code has moved to
<link type="text/html" href="http://trac.cipherdyne.org/trac/fwknop-perl">fwknop-perl</link>.  Any release
that is at fwknop-2.0.0 or above will be the C implementation, and any release in
the 1.9 series or before are in perl (and will remain available
<link type="text/html" href="/fwknop/download/">here</link>).  The perl and C versions are compatible with
each other, so SPA packets created by the fwknop perl client can be properly
decrypted and decoded by the new fwknopd C server, and similarly SPA packets
built with the fwknop C client can be interpreted by the fwknopd perl server.
<br/><br/>
The heart of the new C code is the
<link type="text/html" href="http://trac.cipherdyne.org/trac/fwknop/browser/trunk/lib">libfko library</link>,
which is used by both the fwknop client and the fwknopd server for SPA packet
encryption/decryption and interpretation.  The libfko library is portable to
several platforms including Linux and Windows, and the standard
<link type="text/html" href="http://www.gnu.org/software/autoconf/">GNU autoconf</link>
project is used for building fwknop from sources.
<br/><br/>
Given the compact nature of the C code, the fwknop-2.0.0rc1 release candidate
is already known to function on <link type="text/html" href="http://openwrt.org/">OpenWRT</link>, and
Damien Stuart (the primary developer of the fwknop C code) has built packages
for the OpenWRT Kamikaze and Backfire releases.  This brings SPA functionality
to embedded systems, and has been tested on a Linksys WRT54GS V2.0 router.  The
OpenWRT packages are available <link type="text/html" href="/fwknop/download/">here</link>.
<br/><br/>
There will be a few release candidates of <b>fwknop-2.0.0</b> to ensure proper
operation on a variety of platforms, and the emphasis will be on stability and
ironing out any bugs.  Also, fwknop-2.0.0 will initially support iptables
firewalls on the servers side, with <b>ipfw</b> support coming soon after.  There
is one nice feature in fwknop-2.0.0rc1 that deserves a mention - the fwknop client
now supports the notion of a <b>~/.fwknoprc</b> file that allows a set of
stanzas to be defined for remote SPA servers and customize the command line
arguments used to access each one.  Here is an example stanza:

<br/><br/>
<code>
# Example for a destination server of 192.168.1.20 to open access to<br/>
# SSH for an IP that is resolved externally<br/>
#<br/>
[myssh]<br/>
SPA_SERVER          192.168.1.20<br/>
ACCESS              tcp/22<br/>
ALLOW_IP            resolve<br/>
SPA_SERVER_PORT     50023<br/>
</code>
<br/><br/>

Now, with the fwknop client, we reference this stanza with the <b>-n</b> command
line argument like so:

<br/><br/>
<code>
$ fwknop -n myssh -vvv<br/>
Resolved external IP (via http://www.cipherdyne.org/cgi-bin/myip) as: 123.1.2.3<br/>
Enter encryption password:<br/>
<br/>
FKO Field Values:<br/>
=================<br/>
<br/>
   Random Value: 8308719569638051<br/>
       Username: mbr<br/>
      Timestamp: 1280030806<br/>
    FKO Version: 1.9.12<br/>
   Message Type: 1<br/>
 Message String: 123.1.2.3,tcp/22<br/>
     Nat Access: &lt;NULL&gt;<br/>
    Server Auth: &lt;NULL&gt;<br/>
 Client Timeout: 0<br/>
    Digest Type: 3<br/>
<br/>
   Encoded Data: 8308719569638051:bWJy:1280030806:1.9.12:1:OTYuMjQ0LjE3MS4yNTMsdGNwLzIy<br/>
<br/>
SPA Data Digest: WcUEVesZDIY+CKRKYTck8zMW7HG0S7RcqmXVIMC4L58<br/>
<br/>
Final Packed/Encrypted/Encoded Data:<br/>
<br/>
87wQ3s171if9x8628P6k1oBrQEJEmS5c/+ECed5cfDmu8hGhC5esUCEVcI8IH5TdjWva44efebX+cfXUVPBU9c/6tJpOLwC8k/8sN87SgYkBK+m64aD4FnnndaeqsrIcO/oHcpXHk9S/8rqqypcumNtlXVZD/isS3Q729LMTa+2uI6TsGX9OQ3<br/>
<br/>
Generating SPA packet:<br/>
    protocol: udp<br/>
    port: 50023<br/>
send_spa_packet: bytes sent: 182
</code>
<br/><br/>

On the fwknopd server side, we see the following printed to the terminal in
<b>--foreground</b> mode as the SPA packet is received and an iptables ACCEPT
rule is added for SSH access and then removed after 30 seconds.

<br/><br/>
<code>
Using Digest Cache: '/usr/var/run/fwknop/digest.cache' (entry count = 93)<br/>
PCAP filter is: udp port 50023<br/>
Starting fwknopd main event loop.<br/>
<br/>
<br/>
SPA Packet from IP: 123.1.2.3 received.<br/>
SPA Packet: '87wQ3s171if9x8628P6k1oBrQEJEmS5c/+ECed5cfDmu8hGhC5esUCEVcI8IH5TdjWva44efebX+cfXUVPBU9c/6tJpOLwC8k/8sN87SgYkBK+m64aD4FnnndaeqsrIcO/oHcpXHk9S/8rqqypcumNtlXVZD/isS3Q729LMTa+2uI6TsGX9OQ3'<br/>
<br/>
SPA Decode (res=0):<br/>
SPA Field Values:<br/>
=================<br/>
   Random Value: 8308719569638051<br/>
       Username: mbr<br/>
      Timestamp: 1280030806<br/>
    FKO Version: 1.9.12<br/>
   Message Type: 1<br/>
 Message String: 123.1.2.3,tcp/22<br/>
     Nat Access: &lt;NULL&gt;<br/>
    Server Auth: &lt;NULL&gt;<br/>
 Client Timeout: 0<br/>
    Digest Type: 3<br/>
   Encoded Data: 8308719569638051:bWJy:1280030806:1.9.12:1:OTYuMjQ0LjE3MS4yNTMsdGNwLzIy<br/>
SPA Data Digest: WcUEVesZDIY+CKRKYTck8zMW7HG0S7RcqmXVIMC4L58<br/>
<br/>
Added Rule to FWKNOP_INPUT for 123.1.2.3, tcp/22 expires at 1280030886<br/>
RES=0, CMD_BUF: /sbin/iptables -t filter -L FWKNOP_INPUT --line-numbers -n 2&gt;&amp;1<br/>
RULES LIST: Chain FWKNOP_INPUT (1 references)<br/>
num  target     prot opt source               destination<br/>
1    ACCEPT     tcp  --  123.1.2.3       0.0.0.0/0           tcp dpt:22 /* _exp_1280030886 */<br/>
<br/>
Removed rule 1 from FWKNOP_INPUT with expire time of 1280030886.<br/>
</code>
<br/><br/>


</p>
</div>
</content>
</entry>

<entry>
<title type="html">Software Release - psad-2.1.7</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2010/07/software-release-psad-2.1.7.html"/>
<id>http://www.cipherdyne.org/blog/2010/07/software-release-psad-2.1.7.html</id>

<published>2010-07-14T21:01:30-05:00</published>
<updated>2010-07-14T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>

<link type="text/html" href="/psad/download/">
<img align="right" src="/images/release.png" title="psad-2.1.7" alt="psad-2.1.7 released" /></link>
The 2.1.7 release of <link type="text/html" href="/psad"><b>psad</b></link> is available for
<link type="text/html" href="/psad/download/"><b>download</b></link>.  This release adds some
relatively minor functionality to switch whois lookups to the destination IP
whenever the source IP is part of a directly connected subnet.  This change gives
better reporting data in normal psad email alerts.  The complete
<link type="text/html" href="http://trac.cipherdyne.org/trac/psad/browser/psad/tags/psad-2.1.7/ChangeLog">
ChangeLog</link> entries are displayed below.  The psad-2.1.6 release was also made
a few days ago, and fixes a bug that caused psad to die on some Ubuntu systems
when using the Date::Calc Decode_Month() function, and it also added the
<b>--Override-config</b> feature so that alternate configuration variables can
be specified via config files besides psad.conf (implemented by Franck Joncourt).
<br/><br/>
<ul>
<li>(Dan A. Dickey) Added the ability to use the "ip" command from the
iproute2 tools to acquire IP addresses from local interfaces.  Dan's
description is as follows: "...A main reason for doing this is in the
case of multi-homed hosts. ifconfig sets these up on an interface using
aliases, iproute2 does not.  So, for a multi-homed interface (eth0 with
multiple addresses), ifconfig -a only shows the first one configured and
not the rest.  ip addr shows all of the configured addresses...".</li>
<li>Added ENABLE_WHOIS_FORCE_ASCII to replace any non-ascii characters in
whois data (which is common with whois lookups against Chinese IP
addresses for example) with the string "NA".  This option is disabled by
default, but can be useful if errors like the following are seen upon
receiving an email alert from psad:
<br/><br/>
        &lt;&lt;&lt; 554 5.6.1 Eight bit data not allowed<br/>
        554 5.0.0 Service unavailable
<br/><br/></li>
<li>Updated psad to issue whois lookups against IP addresses that are not
directly connected to the local system.  This is useful for example when
an internal system is scanning an external destination system, and the
scan is logged in the FORWARD chain.  Issuing whois lookups on the
internal system (frequently on RFC 1918 address space) is not usually
very useful, but issuing the whois lookup against the destination system
gives much more interesting data.  This feature can be disabled with the
new ENABLE_WHOIS_FORCE_SRC_IP variable.</li>
</ul>


</p>
</div>
</content>
</entry>

<entry>
<title type="html">Software Release - fwsnort-1.1</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2010/01/software-release-fwsnort-1.1.html"/>
<id>http://www.cipherdyne.org/blog/2010/01/software-release-fwsnort-1.1.html</id>

<published>2010-01-07T21:01:30-05:00</published>
<updated>2010-01-07T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
<link type="text/html" href="/fwsnort">
<img align="right" src="/images/release.png" title="software release fwsnort-1.1" alt="software release fwsnort-1.1" /></link>
The 1.1 release of <link type="text/html" href="/fwsnort">fwsnort</link> is ready for <link type="text/html" href="/fwsnort/download">download</link>.
This is a significant release that adds support for
<link type="text/html" href="http://www.netfilter.org/projects/iptables/index.html">ip6tables</link> so
that SNORT  inspection logic can be applied to IPv6 traffic within the
Linux kernel.  This release also includes a new feature that allows fwsnort
to build perl commands interfaced with netcat that generate packet data that
matches Snort rules (for those that that can be faithfully
translated - see the <b>--include-perl-triggers</b> command line argument
and associated comments within the fwsnort.sh file).
<br/><br/>
Here is the complete
<link type="text/html" href="http://trac.cipherdyne.org/trac/fwsnort/browser/fwsnort/tags/fwsnort-1.1/ChangeLog">fwsnort-1.1 ChangeLog</link>:
<br/><br/>
<ul>
<li>Added the ability to build an fwsnort policy that utilizes ip6tables
instead of iptables.  This allows fwsnort filtering and altering
capabilities to apply to IPv6 traffic instead of just IPv4 traffic.  To
enable ip6tables usage, use the "-6" or "--ip6tables" command line
arguments.</li>
<li>Added the --include-perl-triggers command line argument so that
translated Snort rules can easily be tested.  This argument instructs
fwsnort to include 'perl -e print ... ' commands as comments in the
/etc/fwsnort/fwsnort.sh script, and these commands can be combined
with netcat to send payloads across the wire that match Snort rules.</li>
<li>Updated fwsnort to create logs in the /var/log/fwsnort/ directory
instead of directly in the /var/log/ directory.  The path is controlled
by a new variable 'LOG_FILE' in the /etc/fwsnort/fwsnort.conf file.</li>
<li>Added several variables in /etc/fwsnort/fwsnort.conf to control paths
to everything from the config file to the snort rules path.  Coupled
with this is the ability to create variables within path components and
fwsnort will expand them (e.g. 'CONF_DIR /etc/fwsnort;
CONF_FILE $CONF_DIR/fwsnort.conf').</li>
<li>Added --Last-cmd arg so that it is easy to rebuild the fwsnort.sh script
with the same command line args as the previous execution.</li>
</ul>

Snort is a registered trademark of <link type="text/html" href="http://www.sourcefire.com">Sourcefire, Inc</link>.
<br/><br/>

</p>
</div>
</content>
</entry>

<entry>
<title type="html">holisticinfosec.org on SPA Ghost Services</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2010/01/holisticinfosec.org-on-spa-ghost-services.html"/>
<id>http://www.cipherdyne.org/blog/2010/01/holisticinfosec.org-on-spa-ghost-services.html</id>

<published>2010-01-05T21:01:30-05:00</published>
<updated>2010-01-05T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
<link type="text/html" href="http://holisticinfosec.org">
<img align="right" src="/images/holisticinfosec_cropped.png" title="holisticinfosec.org on fwknop" alt="holisticinfosec.org on fwknop" /></link>
<link type="text/html" href="http://holisticinfosec.blogspot.com/">Russ McRee</link> of <link type="text/html" href="http://holisticinfosec.org">holisticinfosec.org</link>
has written the January <link type="text/html" href="http://holisticinfosec.blogspot.com/2010/01/single-packet-authorization-ghost-in.html">Toolsmith</link>
issue from the ISSA Journal about <link type="text/html" href="/fwknop/">fwknop</link> and the ability to create
ghost services with Single Packet Authorization.  In his Toolsmith paper, Russ emphasizes
the possibility of using the ghost services concept to bypass strict outbound network
filtering rules on a local network in order to access an external service that is bound
to a port that is filtered by the local firewall.  That is, the service is made accessible
by having the SPA packet created by the fwknop client request that the remote fwknopd server
create iptables DNAT rules to forward connections to a port that the local network actually
allows out to the port where the service is bound.  Russ uses this concept to access a file
that is piped through a netcat listener on TCP port 6543, but do it from the heavily
filtered network over TCP port 110 (normally associated with pop3).
<br/><br/>
Here is a link to the Toolsmith PDF entitled
"<link type="text/html" href="http://holisticinfosec.org/toolsmith/docs/january2010.html">Single Packet Authorization: The Ghost in the Machine</link>".
<br/><br/>

</p>
</div>
</content>
</entry>

<entry>
<title type="html">Creating Ghost Services with Single Packet Authorization</title>
<author>
<name>Michael Rash</name>
</author>
<link rel="alternate" type="text/html" href="http://www.cipherdyne.org/blog/2009/11/creating-ghost-services-with-single-packet-authorization.html"/>
<id>http://www.cipherdyne.org/blog/2009/11/creating-ghost-services-with-single-packet-authorization.html</id>

<published>2009-11-29T21:01:30-05:00</published>
<updated>2009-11-29T21:01:30-05:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
<link type="text/html" href="/fwknop/">
<img align="right" src="/images/chinesedoor5.jpg" width="180" height="120" title="Creating Ghost Services with Single Packet Authorization" alt="Creating Ghost Services with Single Packet Authorization" /></link>
Most usages of <link type="text/html" href="/fwknop/docs/SPA.html">Single Packet Authorization</link>
focus on gaining access to a service such
as sshd that is behind a default-drop packet filter.  The point being that anyone
who is scanning for the service cannot even tell that it is listening - let
alone target it with an exploit or an attempt to brute force a password.  This is fine,
but given that firewalls such as iptables offer well designed NAT capabilities, can
a more interesting access model be developed for SPA?  How about accessing sshd
<i>through</i> a port where another service (such as Apache on port 80) is already
bound?  Because iptables operates on packets within kernel space, NAT functions apply
before there is any conflict with a user space application such as Apache.  This
makes it possible to create "ghost" services where a port switches for a short
period of time to whatever service is requested within an SPA packet (e.g. sshd),
but everyone else always just sees the service that is normally bound there (e.g.
Apache on port 80).
<br/><br/>
To illustrate this concept, let's use fwknop from the <b>spaclient</b> system below
to access sshd on the <b>spaserver</b> system, but request the access be granted
through port 80.  Further, on the spaserver system, let's verify that Apache is
running and from the perspective of any scanner out on the Internet this is the only
service that is accessible.  That is, sshd and all other services are firewalled off
by iptables.  We'll assume that the spaclient system has IP 1.1.1.1, the spaserver
system has IP 2.2.2.2, and the scanner system has IP 3.3.3.3.
<br/><br/>

First, let's scan the spaserver system from the scanner system and verify that
only port 80 is accessible:

<br/><br/>
<code>
[scanner]# nmap -P0 -n -sV 2.2.2.2<br/>
<br/>
Starting Nmap 5.00 ( http://nmap.org ) at 2009-11-29 15:14 EST<br/>
Interesting ports on 2.2.2.2:<br/>
Not shown: 999 filtered ports<br/>
PORT    STATE SERVICE VERSION<br/>
80/tcp  open  http    Apache httpd 2.2.8 ((Ubuntu) mod_python/3.3.1 Python/2.5.2)<br/>
<br/>
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .<br/>
Nmap done: 1 IP address (1 host up) scanned in 90.94 seconds
</code>
<br/><br/>

Good.  Now, from the spaclient system, let's fire up fwknop and request access to
sshd on the spaserver system.  But instead of just gaining access to port 22, we'll
request access to port 22 via port 80 - the fwknopd daemon will build the
appropriate DNAT iptables rules to make this work:

<br/><br/>
<code>
[spaclient]$ fwknop -A tcp/22 --NAT-access 2.2.2.2:80 --NAT-local -a 1.1.1.1 -D 2.2.2.2<br/>
<br/>
[+] Starting fwknop client (SPA mode)...<br/>
[+] Enter an encryption key. This key must match a key in the file<br/>
    /etc/fwknop/access.conf on the remote system.<br/>
<br/>
Encryption Key:<br/>
<br/>
[+] Building encrypted Single Packet Authorization (SPA) message...<br/>
[+] Packet fields:<br/>
<br/>
        Random data:    3829970026924871<br/>
        Username:       mbr<br/>
        Timestamp:      1259526613<br/>
        Version:        1.9.12<br/>
        Type:           5   (Local NAT access mode)<br/>
        Access:         0.0.0.0,tcp/22<br/>
        NAT access:     2.2.2.2,80<br/>
        SHA256 digest:  Om/GsIVQIRyAp6UWyqjXVqlEQhxz+lVsQhCl1rFBfuI<br/>
<br/>
[+] Sending 182 byte message to 2.2.2.2 over udp/62201...<br/>
    Requesting NAT access to tcp/22 on 2.2.2.2 via port 80<br/>

</code>
<br/><br/>

With the receipt of the SPA packet, the fwknopd daemon has reconfigured iptables
to allow an ssh connection through port 80 from the spaclient IP 1.1.1.1 (note
the "<b>-p 80</b>" argument on the ssh command line):

<br/><br/>
<code>
[spaclient]$ ssh -p 80 -l mbr 2.2.2.2<br/>
mbr@2.2.2.2's password:<br/>
[spaserver]$
</code>
<br/><br/>

If we can the spaserver again from the scanner system, we still only see
Apache:

<br/><br/>
<code>
[scanner]# nmap -P0 -n -sV 2.2.2.2<br/>
<br/>
Starting Nmap 5.00 ( http://nmap.org ) at 2009-11-29 15:29 EST<br/>
Interesting ports on 2.2.2.2:<br/>
Not shown: 999 filtered ports<br/>
PORT    STATE SERVICE VERSION<br/>
80/tcp  open  http    Apache httpd 2.2.8 ((Ubuntu) mod_python/3.3.1 Python/2.5.2)<br/>
<br/>
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .<br/>
Nmap done: 1 IP address (1 host up) scanned in 89.22 seconds
</code>
<br/><br/>

So, the IP 1.1.1.1 has access to sshd, but all the scanner can ever see is
'Apache httpd 2.2.8'.
<br/><br/>
A legitimate question at this point is 'why is this useful?'.  Well, I have been
on networks before where local access controls only allowed outbound DNS, HTTP
and HTTPS traffic, so this technique allows ssh connections to be made in a
manner that is consistent with these access controls.  (This assumes that HTTP
connections are not made through a proxy, and that the fwknopd daemon is
configured to sniff SPA packets over port 53.)  Further, to anyone who is able to
sniff traffic, it can be hard to figure out what is really going on in terms
of SPA packets and associated follow-on connections.  This is especially
true when other tricks such as
<link type="text/html" href="/blog/2008/06/single-packet-authorization-with-port-randomization.html">
port randomization</link> are also applied.
<br/><br/>
I demonstrated the service ghosting technique at
<link type="text/html" href="http://www.dojocon.org/">DojoCon</link> a few weeks ago, and
the video of this is available <link type="text/html" href="http://www.ustream.tv/recorded/2505225">here</link>
(towards the end of the video).


</p>
</div>
</content>
</entry>

<!-- end_stories -->
</feed>

