mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22:48 -05:00
New option to reject 'trivial' success of userauth.
Suggested by Manfred Kaiser, who also wrote most of this patch (although outlying parts, like documentation and SSH-1 support, are by me). This is a second line of defence against the kind of spoofing attacks in which a malicious or compromised SSH server rushes the client through the userauth phase of SSH without actually requiring any auth inputs (passwords or signatures or whatever), and then at the start of the connection phase it presents something like a spoof prompt, intended to be taken for part of userauth by the user but in fact with some more sinister purpose. Our existing line of defence against this is the trust sigil system, and as far as I know, that's still working. This option allows a bit of extra defence in depth: if you don't expect your SSH server to trivially accept authentication in the first place, then enabling this option will cause PuTTY to disconnect if it unexpectedly does so, without the user having to spot the presence or absence of a fiddly little sigil anywhere. Several types of authentication count as 'trivial'. The obvious one is the SSH-2 "none" method, which clients always try first so that the failure message will tell them what else they can try, and which a server can instead accept in order to authenticate you unconditionally. But there are two other ways to do it that we know of: one is to run keyboard-interactive authentication and send an empty INFO_REQUEST packet containing no actual prompts for the user, and another even weirder one is to send USERAUTH_SUCCESS in response to the user's preliminary *offer* of a public key (instead of sending the usual PK_OK to request an actual signature from the key). This new option detects all of those, by clearing the 'is_trivial_auth' flag only when we send some kind of substantive authentication response (be it a password, a k-i prompt response, a signature, or a GSSAPI token). So even if there's a further path through the userauth maze we haven't spotted, that somehow avoids sending anything substantive, this strategy should still pick it up.
This commit is contained in:
14
ssh/login1.c
14
ssh/login1.c
@ -27,7 +27,7 @@ struct ssh1_login_state {
|
||||
|
||||
char *savedhost;
|
||||
int savedport;
|
||||
bool try_agent_auth;
|
||||
bool try_agent_auth, is_trivial_auth;
|
||||
|
||||
int remote_protoflags;
|
||||
int local_protoflags;
|
||||
@ -105,6 +105,8 @@ PacketProtocolLayer *ssh1_login_new(
|
||||
s->savedhost = dupstr(host);
|
||||
s->savedport = port;
|
||||
s->successor_layer = successor_layer;
|
||||
s->is_trivial_auth = true;
|
||||
|
||||
return &s->ppl;
|
||||
}
|
||||
|
||||
@ -645,6 +647,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
|
||||
s->ppl.bpp, SSH1_CMSG_AUTH_RSA_RESPONSE);
|
||||
put_data(pkt, ret + 5, 16);
|
||||
pq_push(s->ppl.out_pq, pkt);
|
||||
s->is_trivial_auth = false;
|
||||
crMaybeWaitUntilV(
|
||||
(pktin = ssh1_login_pop(s))
|
||||
!= NULL);
|
||||
@ -814,6 +817,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
|
||||
s->ppl.bpp, SSH1_CMSG_AUTH_RSA_RESPONSE);
|
||||
put_data(pkt, buffer, 16);
|
||||
pq_push(s->ppl.out_pq, pkt);
|
||||
s->is_trivial_auth = false;
|
||||
|
||||
mp_free(challenge);
|
||||
mp_free(response);
|
||||
@ -1105,6 +1109,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
|
||||
put_stringz(pkt, prompt_get_result_ref(s->cur_prompt->prompts[0]));
|
||||
pq_push(s->ppl.out_pq, pkt);
|
||||
}
|
||||
s->is_trivial_auth = false;
|
||||
ppl_logevent("Sent password");
|
||||
free_prompts(s->cur_prompt);
|
||||
s->cur_prompt = NULL;
|
||||
@ -1121,6 +1126,13 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
|
||||
}
|
||||
}
|
||||
|
||||
if (conf_get_bool(s->conf, CONF_ssh_no_trivial_userauth) &&
|
||||
s->is_trivial_auth) {
|
||||
ssh_proto_error(s->ppl.ssh, "Authentication was trivial! "
|
||||
"Abandoning session as specified in configuration.");
|
||||
return;
|
||||
}
|
||||
|
||||
ppl_logevent("Authentication successful");
|
||||
|
||||
if (conf_get_bool(s->conf, CONF_compression)) {
|
||||
|
@ -116,7 +116,7 @@ PacketProtocolLayer *ssh2_transport_new(
|
||||
PacketProtocolLayer *ssh2_userauth_new(
|
||||
PacketProtocolLayer *successor_layer,
|
||||
const char *hostname, const char *fullhostname,
|
||||
Filename *keyfile, bool show_banner, bool tryagent,
|
||||
Filename *keyfile, bool show_banner, bool tryagent, bool notrivialauth,
|
||||
const char *default_username, bool change_username,
|
||||
bool try_ki_auth,
|
||||
bool try_gssapi_auth, bool try_gssapi_kex_auth,
|
||||
|
@ -254,7 +254,9 @@ static void ssh_got_ssh_version(struct ssh_version_receiver *rcv,
|
||||
connection_layer, ssh->savedhost, ssh->fullhostname,
|
||||
conf_get_filename(ssh->conf, CONF_keyfile),
|
||||
conf_get_bool(ssh->conf, CONF_ssh_show_banner),
|
||||
conf_get_bool(ssh->conf, CONF_tryagent), username,
|
||||
conf_get_bool(ssh->conf, CONF_tryagent),
|
||||
conf_get_bool(ssh->conf, CONF_ssh_no_trivial_userauth),
|
||||
username,
|
||||
conf_get_bool(ssh->conf, CONF_change_username),
|
||||
conf_get_bool(ssh->conf, CONF_try_ki_auth),
|
||||
#ifndef NO_GSSAPI
|
||||
|
@ -28,7 +28,7 @@ struct ssh2_userauth_state {
|
||||
|
||||
PacketProtocolLayer *transport_layer, *successor_layer;
|
||||
Filename *keyfile;
|
||||
bool show_banner, tryagent, change_username;
|
||||
bool show_banner, tryagent, notrivialauth, change_username;
|
||||
char *hostname, *fullhostname;
|
||||
char *default_username;
|
||||
bool try_ki_auth, try_gssapi_auth, try_gssapi_kex_auth, gssapi_fwd;
|
||||
@ -82,6 +82,7 @@ struct ssh2_userauth_state {
|
||||
int len;
|
||||
PktOut *pktout;
|
||||
bool want_user_input;
|
||||
bool is_trivial_auth;
|
||||
|
||||
agent_pending_query *auth_agent_query;
|
||||
bufchain banner;
|
||||
@ -134,7 +135,7 @@ static const PacketProtocolLayerVtable ssh2_userauth_vtable = {
|
||||
PacketProtocolLayer *ssh2_userauth_new(
|
||||
PacketProtocolLayer *successor_layer,
|
||||
const char *hostname, const char *fullhostname,
|
||||
Filename *keyfile, bool show_banner, bool tryagent,
|
||||
Filename *keyfile, bool show_banner, bool tryagent, bool notrivialauth,
|
||||
const char *default_username, bool change_username,
|
||||
bool try_ki_auth, bool try_gssapi_auth, bool try_gssapi_kex_auth,
|
||||
bool gssapi_fwd, struct ssh_connection_shared_gss_state *shgss)
|
||||
@ -149,6 +150,7 @@ PacketProtocolLayer *ssh2_userauth_new(
|
||||
s->keyfile = filename_copy(keyfile);
|
||||
s->show_banner = show_banner;
|
||||
s->tryagent = tryagent;
|
||||
s->notrivialauth = notrivialauth;
|
||||
s->default_username = dupstr(default_username);
|
||||
s->change_username = change_username;
|
||||
s->try_ki_auth = try_ki_auth;
|
||||
@ -157,6 +159,7 @@ PacketProtocolLayer *ssh2_userauth_new(
|
||||
s->gssapi_fwd = gssapi_fwd;
|
||||
s->shgss = shgss;
|
||||
s->last_methods_string = strbuf_new();
|
||||
s->is_trivial_auth = true;
|
||||
bufchain_init(&s->banner);
|
||||
bufchain_sink_init(&s->banner_bs, &s->banner);
|
||||
|
||||
@ -818,6 +821,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
||||
sigblob);
|
||||
pq_push(s->ppl.out_pq, s->pktout);
|
||||
s->type = AUTH_TYPE_PUBLICKEY;
|
||||
s->is_trivial_auth = false;
|
||||
} else {
|
||||
ppl_logevent("Pageant refused signing request");
|
||||
ppl_printf("Pageant failed to "
|
||||
@ -1038,6 +1042,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
||||
ssh_key_free(key->key);
|
||||
sfree(key->comment);
|
||||
sfree(key);
|
||||
s->is_trivial_auth = false;
|
||||
}
|
||||
|
||||
#ifndef NO_GSSAPI
|
||||
@ -1169,6 +1174,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
||||
* no longer says CONTINUE_NEEDED
|
||||
*/
|
||||
if (s->gss_sndtok.length != 0) {
|
||||
s->is_trivial_auth = false;
|
||||
s->pktout =
|
||||
ssh_bpp_new_pktout(
|
||||
s->ppl.bpp, SSH2_MSG_USERAUTH_GSSAPI_TOKEN);
|
||||
@ -1288,7 +1294,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
||||
* Loop while the server continues to send INFO_REQUESTs.
|
||||
*/
|
||||
while (pktin->type == SSH2_MSG_USERAUTH_INFO_REQUEST) {
|
||||
|
||||
ptrlen name, inst;
|
||||
strbuf *sb;
|
||||
|
||||
@ -1308,6 +1313,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
||||
*/
|
||||
s->num_prompts = get_uint32(pktin);
|
||||
for (uint32_t i = 0; i < s->num_prompts; i++) {
|
||||
s->is_trivial_auth = false;
|
||||
ptrlen prompt = get_string(pktin);
|
||||
bool echo = get_bool(pktin);
|
||||
|
||||
@ -1472,7 +1478,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
||||
pq_push_front(s->ppl.in_pq, pktin);
|
||||
|
||||
} else if (s->can_passwd) {
|
||||
|
||||
s->is_trivial_auth = false;
|
||||
/*
|
||||
* Plain old password authentication.
|
||||
*/
|
||||
@ -1731,6 +1737,12 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
||||
}
|
||||
|
||||
userauth_success:
|
||||
if (s->notrivialauth && s->is_trivial_auth) {
|
||||
ssh_proto_error(s->ppl.ssh, "Authentication was trivial! "
|
||||
"Abandoning session as specified in configuration.");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* We've just received USERAUTH_SUCCESS, and we haven't sent
|
||||
* any packets since. Signal the transport layer to consider
|
||||
|
Reference in New Issue
Block a user