<?xml version="1.0"?>
<?xml-stylesheet type='text/xsl' href='./rfc2629.xslt' ?>

<?rfc toc="yes"?>
<?rfc tocdepth='5'?>
<?rfc symrefs="no"?>
<?rfc compact="no" ?>
<?rfc sortrefs="yes" ?>
<?rfc strict="yes" ?>
<?rfc linkmailto="yes" ?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" >

<?xml-stylesheet type='text/xsl' href='./rfc2629.xslt' ?>

<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc compact="no" ?>
<?rfc subcompact="yes" ?>
<?rfc sortrefs="yes" ?>
<rfc category="info" ipr="pre5378Trust200902" docName="draft-gutmann-ssh-preauth-05">

  <!-- ======================================================================== -->
  <front>
    <title>A Pre-Authentication Mechanism for SSH</title>
    <author initials="P." surname="Gutmann" fullname="Peter Gutmann">
      <organization abbrev="University of Auckland">University of Auckland</organization>
      <address>
        <postal>
          <street>Department of Computer Science</street>
          <city>Auckland</city>
          <country>New Zealand</country>
        </postal>
        <email>pgut001@cs.auckland.ac.nz</email>
      </address>
    </author>
    <date year="2026"/>
    <area>Security Area</area>
    <keyword>Internet-Draft</keyword>
    <abstract>
      <t>

Devices running SSH are frequently exposed on the Internet, either because of
operational considerations or through misconfiguration, making them vulnerable
to the constant 3-degree background radiation of scanning and probing attacks
that pervade the Internet.  This document describes a simple
pre-authentication mechanism that limits these attacks with minimal changes to
SSH implementations and no changes to the SSH protocol itself.

      </t>
    </abstract>

  </front>
  <!-- ======================================================================== -->
  <middle>

    <!-- ====================================================================== -->
    <section anchor="introduction" title="Introduction">
      <t>

Devices running SSH are frequently exposed on the Internet, either because of
operational considerations or through misconfiguration, making them vulnerable
to the constant 3-degree background radiation of scanning and probing attacks
that pervade the Internet.  This document describes a simple
pre-authentication mechanism that limits these attacks with minimal changes to
SSH implementations and no changes to the SSH protocol itself.

      </t>
      <t>

      </t>
      <section anchor="mustshouldmay" title="Conventions Used in This Document">
        <t> The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
		  NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED",
		  "MAY", and "OPTIONAL" in this document are to be interpreted as
		  described in <xref target="RFC2119"/> and <xref target="RFC8174"/>
		  when, and only when, they appear in all capitals, as shown here.</t>
      </section>

    </section>
    <!-- ====================================================================== -->
    <section anchor="background" title="Background">
      <t>

This section covers the background and threat model for the SSH
pre-authentication process and mechanism.

      </t>
      <section anchor="requirements" title="Requirements">
        <t>

The mechanism to limit scanning and probing attacks needs to meet the following
requirements:

<ul>

<li>It should stop attackers at the gate, preventing probing past the first
message exchanged.  This both limits information leakage and mitigates against
exploitation of pre-auth vulnerabilities in implementations.</li>

<li>It should require no changes to the SSH protocol, for example the addition
of new handshake messages or changes to existing handshake messages.</li>

</ul>

In addition to these requirements there are also additional desirable
properties:

<ul>

<li>Ideally it would require no user-visible changes to the operation of an
SSH client or server, in other words no need to supply additional or auxiliary
keying material or perform other configuration changes.  Unfortunately this
goal can't easily be met, see the comments in <xref target="security"/>, with
one configuration change on the client and server being required to enable
pre-authentication.</li>

<li>In order to encourage adoption by implementers of embedded SSH, it should
require minimal effort to retrofit to existing SSH implementations, both
because embedded systems using SSH are frequent targets and because these
systems often have minimal effort applied to keep current with new
mechanisms.</li>

</ul>

Note that although this mechanism can be applied to any SSH implementation,
its primary intended target is embedded SSH where few if any mitigations such
as privilege separation or frequent patches to address vulnerabilities are
possible.

        </t>
      </section>
      <section anchor="threat" title="Threat Model">
        <t>

This document considers two different attacker types:

<ol>

<li>The generic three-degree background radiation of non-targeted Internet
scanning and probing from off-path attackers.  Any pre-authentication measure,
for example including a static non-public value at the start of the handshake,
will stop this type of attack.</li>

<li>More targeted attacks from on-path attackers, which require something like
a challenge/response mechanism to stop.</li>

</ol>

The pre-authentication mechanism described here targets both off-path and
on-path attackers.

        </t>
      </section>
      <section anchor="usage" title="Usage Scenarios">
        <t>

This document considers three different SSH usage scenarios:

<ol>

<li>A conventional server, possibly behind a firewall.  Firewall rules and
security/access-control proxies, if available, would typically be used to
handle any required SSH access control.</li>

<li>An embedded device that, for operational reasons or possibly just through
misconfiguration, is exposed to the Internet.</li>

<li>As above, but on a private network that's been penetrated by attackers who
are probing it for targets.  In other words the call is coming from inside the
building.</li>

</ol>

The pre-authentication mechanism described in this document is primarily
targeted at the latter two scenarios.

        </t>
      </section>
    </section>
    <!-- ====================================================================== -->
    <section anchor="description" title="Description">
      <t>

The pre-authentication mechanism for SSH takes the existing exchange of client
and server ID strings and adds a simple challenge/response to them, preventing
the exchange of any SSH handshake messages, in other words any actual SSH
protocol messages, unless the pre-authentication succeeds.  It does this by
adding a random challenge in the Comment field of the server's SSH ID, with
the client responding with the response in the comment field of its SSH ID.
The server challenge in the comment field is denoted with
'C=&lt;challenge&gt;' and the client response with 'R=&lt;response&gt;'.
When the pre-authentication mechanism used in this document is used, these
MUST be the first values in the Comment field, with any further entries that
follow separated by a comma.

      </t>
      <t>

The challenge is a 64-bit server-generated nonce which is then base64-encoded
to create a text string suitable for use in the Comment field.  This encoded
form, and the base64-encoded response from the client, are sent without any
base64 padding characters '=' at the end, so that the encoded values consist
of 11 alphanumeric characters.

      </t>
      <t>

The response to the challenge is an HMAC-SHA256 of the challenge, with the MAC
value truncated to 64 bits and base64-encoded to an 11-character form in the
same manner as the server's challenge.  The server challenge is MAC'd in
11-character base64 form as sent, without decoding back to binary form.

      </t>
      <t>

Computing the response to the challenge requires a shared secret
'preAuthSecret' between the client and server.  This SHOULD NOT be the same as
any user password or other authentication value that might be used for
authentication but should be created or generated independently and only used
for pre-authentication.  In the situation where more than a single user or
account exists on the device, the preAuthSecret functions in a manner similar
to a WiFi password, with the preAuthSecret granting access to the SSH server
and subsequent user authentication granting access to whatever sits behind the
server.

      </t>
      <t>

The HMAC key is calculated as:

      </t>

      <figure>
        <artwork><![CDATA[
    key = SHA256( string    challenge
                  string    preAuthSecret )
        ]]></artwork>
      </figure>

      <t>

The response is then computed as a truncated HMAC:

      </t>

      <figure>
        <artwork><![CDATA[
    rawResponse = HMAC-SHA256( key, challenge )
    response = base64( rawRespone[ 0...7 ]
        ]]></artwork>
      </figure>

      <t>

In other words the response is the base64 encoding (without adding base64
padding) of the first 64 bits of the HMAC value to give the required 11-byte
response value.

      </t>

	</section>
    <!-- ====================================================================== -->
    <section anchor="test" title="Test Vectors">
	  <t>

Test vectors to be added when the format is finalised.

	  </t>
	</section>
    <!-- ====================================================================== -->
    <section anchor="ack" title="Contributors/Acknowledgements">
	  <t>
	  </t>
	</section>
    <!-- ====================================================================== -->
    <section anchor="iana" title="IANA Considerations">
	  <t>
      </t>
	</section>
    <!-- ====================================================================== -->
    <section anchor="security" title="Security Considerations">
	  <t>

As the introduction points out, using this pre-authentication mechanism for
SSH is not intended to be all things to all people but to address a specific
problem, stopping scanning and probing attacks of SSH-enabled devices at the
gates.  Conceptually it works like a WiFi password, granting initial access to
the SSH server while subsequent user authentication grants access to whatever
sits behind the server.  Its primary usage scenario is embedded devices with
few users, most commonly only one.  Use with public SSH systems with large
numbers of users is optionally possible, although unlike embedded devices
these are expected to have up-to-date software and proper mitigations in
place.

	  </t>
	  <t>

However even in the latter case it can provide some protection against
protocol and implementation vulnerabilities by reducing the possibility of
compromise of the vulnerable implementation or system until the software is
updated.  Legitimate users could continue to access the system while attackers
who couldn't pass the pre-authentication check would be prevented from
attacking the vulnerable system behind it.

	  </t>
	  <t>

(When fuzzing an implementation that provides pre-authentication protection,
remember to disable the authentication check for the fuzzing process otherwise
the fuzzer will be prevented from progressing through to fuzzing the SSH
protocol implementation itself).

	  </t>
	  <t>

The pre-authentication can also be used to provide risk-based security in the
same way that CAPTCHAs are used on some web sites in which suspicious accesses
requiring a CAPTCHA in addition to the normal logon process.  For example
accesses from the local subnet or only one or two hops away could be permitted
without pre-authentication while ones that don't fall into these requirements
could only be permitted with pre-authentication, complicating the task for
remote attackers while leaving local users unaffected.

	  </t>
	  <t>

The use of a separate preAuthSecret is the lesser of two evils, the other
option being to reuse existing authentication information like a password,
after due cryptographic processing, for the pre-authentication.  This makes
the pre-authentication process transparent without requiring the management of
additional keying material, since more than two decades of SSH compromise
history have taught us that many users are not good at managing such keying
material.  However with a simple gatekeeper pre-authentication mechanism of
the kind described here it appears to be impossible to implement it in a
manner that doesn't open it up to an offline dictionary attack by an on-path
attacker who, even in the presence of countermeasures like a severely
truncated MAC that leads to false positives, can intercept many
challenge/response pairs over time and use those to get to true positives.

	  </t>
	  <t>

An additional benefit of using a distinct preAuthSecret is that it makes
enabling and use of pre-authentication explicit.  A downside of using a
distinct preAuthSecret is that it requires explicit configuration actions to
enable and use pre-authentication.

	  </t>
	  <t>

It is recommended that implementations perform rate-limiting on
pre-authentication attempts, throttling back responses if too many
pre-authentication failures occur in a given time interval.  To further
confound attackers, servers may in addition opt to continue with an emulated
handshake if the pre-authentication fails, eventually failing anyway or
dropping the attacker into a tarpit.

	  </t>
	  <t>

Since the authentication is unidirectional, a pass-the-hash attack is possible
in the presence of an active attacker who convinces a victim to connect to a
fake server and then MITMs the challenge and response from/to the genuine
server.  However this is merely a pre-authentication mechanism whose main
design goal is to protect the SSH implementation behind it from scanning and
probing attacks rather than a full-blown (and complex) client/server
authentication protocol.  The SSH protocol behind the protective
pre-authentication step provides the required full client/server
authentication, assuming the client verifies the server fingerprint <xref
target="fingerprints"/>.

	  </t>
	  <t>

The server nonce generation process is described explicitly rather than in
general terms like "a random string" to avoid implementations using things
like the server name as a nonce value, or more generally just hardcoding
something into the otherwise static server ID.

	  </t>
	  <t>

Following Grigg's Law, "There is only one mode and that is secure", the
pre-authentication mechanism hardcodes use of SHA256, the de facto universal
standard hash in SSH implementations.  Since the security property required of
the hash function is preimage resistance rather than collision resistance, and
even beyond that the ability to find one specific preimage rather than any
valid preimage, almost any hash function would suffice; SHA256 is chosen
because of its universal acceptance and use.

	  </t>
    </section>
    <!-- ====================================================================== -->

  </middle>
  <!-- ======================================================================== -->
  <back>

    <references title="Normative References">

      <reference anchor='RFC2119'>
        <front>
          <title abbrev='RFC Key Words'>Key words for use in RFCs to Indicate Requirement Levels</title>
          <author initials='S.' surname='Bradner' fullname='Scott Bradner'>
            <organization>Harvard University</organization>
          </author>
          <date year='1997' month='March' />
          <area>General</area>
          <keyword>keyword</keyword>
        </front>
        <seriesInfo name='BCP' value='14' />
        <seriesInfo name='RFC' value='2119' />
        <format type='TXT' target='http://www.ietf.org/rfc/rfc2119.txt' />
        <format type='HTML' target='http://xml.resource.org/public/rfc/html/rfc2119.html' />
        <format type='XML' target='http://xml.resource.org/public/rfc/xml/rfc2119.xml' />
      </reference>

      <reference anchor='RFC8174'>
        <front>
          <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
          <author initials='B.' surname='Leiba' fullname='Barry Leiba'>
            <organization>Huawei Technologies</organization>
          </author>
          <date year='2017' month='May' />
        </front>
        <seriesInfo name='RFC' value='8174' />
        <format type='TXT' target='http://www.ietf.org/rfc/rfc8174.txt' />
      </reference>

    </references>
    <references title="Informative References">

      <reference anchor="fingerprints" target="https://github.com/jscep/jscep">
        <front>
          <title>Do Users Verify SSH Keys?</title>
          <author initials='P.' surname='Gutmann' fullname='Peter Gutmann'>
            <organization>University of Auckland</organization>
          </author>
          <date year='2011' month='August' />
        </front>
        <seriesInfo name=';login' value='Volume 36, Number 4' />
      </reference>

    </references>
    <!-- ====================================================================== -->
   </back>
</rfc>
