ssh https://www.gremwell.com/ en SSH Man-in-the-Middle Attack and Public-Key Authentication Method https://www.gremwell.com/ssh-mitm-public-key-authentication <span>SSH Man-in-the-Middle Attack and Public-Key Authentication Method</span> <div><p><a href="http://www.snailbook.com/protocols.html">SSH</a> is a protocol for secure remote login and other secure network services over insecure networks. To detect <a href="http://en.wikipedia.org/wiki/Man-in-the-middle_attack">man-in-the-middle attacks</a> SSH clients are supposed to check the host key of the server, for example by comparing it with a known good key. Should the client neglect to check the server key (or an attacker manage to steal the private key of the server) the connection becomes vulnerable to active man-in-the-middle attacks, according to <a href="http://www.snailbook.com/docs/architecture.txt">RFC 4251, The Secure Shell (SSH) Protocol Architecture</a> (section 4.1) and other resources.</p> <p>The above statement is indeed true for password-based authentication. There are some tools implementing the attack, for example <a href="http://www.signedness.org/tools/">MITM-SSH</a>. However, there are no tools implementing MITM against an SSH connection authenticated using public-key method (this feature is in TODO list of the above mentioned tool though). Being pressed to produce a PoC for this attack, I have attempted to implement it only to discover it is quite impossible and here is why.</p> <p>During SSH connection setup the peers use Diffie-Hellman to generate encryption keys and a session ID. We assume that MITM attacker has already managed to circumvent the server host key validation and tricked the peers into establishing the connection. Effectively, there are two connections: first between the client and the attacker, and second between the attacker and the server. In case of password authentication the game is over: the attacker can see the password sent by the client, relay it to the server, and basically do whatever he or she wants.</p> <p>The things are a bit more complicated in case of the public key authentication method. The client uses its private key to generate a signature and submits the signature to the server. <a href="http://www.snailbook.com/docs/userauth.txt">RFC 4252, The Secure Shell (SSH) Authentication Protocol</a> (section 7) tells us exactly how the signature is generated:</p> <pre> To perform actual authentication, the client MAY then send a signature generated using the private key. ... The signature is sent using the following packet: byte SSH_MSG_USERAUTH_REQUEST string user name string service name string "publickey" boolean TRUE string public key algorithm name string public key to be used for authentication string signature The value of 'signature' is a signature by the corresponding private key over the following data, in the following order: string session identifier byte SSH_MSG_USERAUTH_REQUEST string user name string service name string "publickey" boolean TRUE string public key algorithm name string public key to be used for authentication </pre><p> Now the attacker has a problem, as the client and the server have different ideas about what session identifier is supposed to be. Obviously, the server will reject the signature supplied by the client and public-key authentication will fail.</p> <p>The session identifier is calculated based on (among other things) the shared secret negotiated by the peers using <a href="http://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange">Diffie-Hellman</a> algorithm. The algorithm itself does not protect against active MITM attack, but it makes it impossible for MITM attacker to influence the choice of the shared key (and by extension the session ID) by the victims.</p> <p>So public-key authentication has somewhat unexpected side effect of preventing MITM. Nice to know.</p> </div> <span><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">abb</span></span> <span>Sat, 12/25/2010 - 22:44</span> Sat, 25 Dec 2010 21:44:44 +0000 abb 79 at https://www.gremwell.com