diff options
author | Darren Tucker <dtucker@zip.com.au> | 2008-07-02 22:56:09 +1000 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2008-07-02 22:56:09 +1000 |
commit | 4230a5dc305d1b39bc118befcc1ccfe933281b75 (patch) | |
tree | 68bd413a4e590c6aae5ea8e0b90c76baf933a7e6 /auth2-none.c | |
parent | 33c787f23c0267c679ad3e3f8bc4679c6ced5ea3 (diff) |
- djm@cvs.openbsd.org 2008/07/02 12:36:39
[auth2-none.c auth2.c]
Make protocol 2 MaxAuthTries behaviour a little more sensible:
Check whether client has exceeded MaxAuthTries before running
an authentication method and skip it if they have, previously it
would always allow one try (for "none" auth).
Preincrement failure count before post-auth test - previously this
checked and postincremented, also to allow one "none" try.
Together, these two changes always count the "none" auth method
which could be skipped by a malicious client (e.g. an SSH worm)
to get an extra attempt at a real auth method. They also make
MaxAuthTries=0 a useful way to block users entirely (esp. in a
sshd_config Match block).
Also, move sending of any preauth banner from "none" auth method
to the first call to input_userauth_request(), so worms that skip
the "none" method get to see it too.
Diffstat (limited to 'auth2-none.c')
-rw-r--r-- | auth2-none.c | 72 |
1 files changed, 3 insertions, 69 deletions
diff --git a/auth2-none.c b/auth2-none.c index 28e593e6c..10accfe55 100644 --- a/auth2-none.c +++ b/auth2-none.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: auth2-none.c,v 1.14 2007/08/23 03:22:16 djm Exp $ */ | 1 | /* $OpenBSD: auth2-none.c,v 1.15 2008/07/02 12:36:39 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -31,9 +31,10 @@ | |||
31 | 31 | ||
32 | #include <fcntl.h> | 32 | #include <fcntl.h> |
33 | #include <stdarg.h> | 33 | #include <stdarg.h> |
34 | #include <unistd.h> | ||
35 | #include <string.h> | 34 | #include <string.h> |
35 | #include <unistd.h> | ||
36 | 36 | ||
37 | #include "atomicio.h" | ||
37 | #include "xmalloc.h" | 38 | #include "xmalloc.h" |
38 | #include "key.h" | 39 | #include "key.h" |
39 | #include "hostfile.h" | 40 | #include "hostfile.h" |
@@ -42,7 +43,6 @@ | |||
42 | #include "log.h" | 43 | #include "log.h" |
43 | #include "buffer.h" | 44 | #include "buffer.h" |
44 | #include "servconf.h" | 45 | #include "servconf.h" |
45 | #include "atomicio.h" | ||
46 | #include "compat.h" | 46 | #include "compat.h" |
47 | #include "ssh2.h" | 47 | #include "ssh2.h" |
48 | #ifdef GSSAPI | 48 | #ifdef GSSAPI |
@@ -56,77 +56,11 @@ extern ServerOptions options; | |||
56 | /* "none" is allowed only one time */ | 56 | /* "none" is allowed only one time */ |
57 | static int none_enabled = 1; | 57 | static int none_enabled = 1; |
58 | 58 | ||
59 | char * | ||
60 | auth2_read_banner(void) | ||
61 | { | ||
62 | struct stat st; | ||
63 | char *banner = NULL; | ||
64 | size_t len, n; | ||
65 | int fd; | ||
66 | |||
67 | if ((fd = open(options.banner, O_RDONLY)) == -1) | ||
68 | return (NULL); | ||
69 | if (fstat(fd, &st) == -1) { | ||
70 | close(fd); | ||
71 | return (NULL); | ||
72 | } | ||
73 | if (st.st_size > 1*1024*1024) { | ||
74 | close(fd); | ||
75 | return (NULL); | ||
76 | } | ||
77 | |||
78 | len = (size_t)st.st_size; /* truncate */ | ||
79 | banner = xmalloc(len + 1); | ||
80 | n = atomicio(read, fd, banner, len); | ||
81 | close(fd); | ||
82 | |||
83 | if (n != len) { | ||
84 | xfree(banner); | ||
85 | return (NULL); | ||
86 | } | ||
87 | banner[n] = '\0'; | ||
88 | |||
89 | return (banner); | ||
90 | } | ||
91 | |||
92 | void | ||
93 | userauth_send_banner(const char *msg) | ||
94 | { | ||
95 | if (datafellows & SSH_BUG_BANNER) | ||
96 | return; | ||
97 | |||
98 | packet_start(SSH2_MSG_USERAUTH_BANNER); | ||
99 | packet_put_cstring(msg); | ||
100 | packet_put_cstring(""); /* language, unused */ | ||
101 | packet_send(); | ||
102 | debug("%s: sent", __func__); | ||
103 | } | ||
104 | |||
105 | static void | ||
106 | userauth_banner(void) | ||
107 | { | ||
108 | char *banner = NULL; | ||
109 | |||
110 | if (options.banner == NULL || | ||
111 | strcasecmp(options.banner, "none") == 0 || | ||
112 | (datafellows & SSH_BUG_BANNER) != 0) | ||
113 | return; | ||
114 | |||
115 | if ((banner = PRIVSEP(auth2_read_banner())) == NULL) | ||
116 | goto done; | ||
117 | userauth_send_banner(banner); | ||
118 | |||
119 | done: | ||
120 | if (banner) | ||
121 | xfree(banner); | ||
122 | } | ||
123 | |||
124 | static int | 59 | static int |
125 | userauth_none(Authctxt *authctxt) | 60 | userauth_none(Authctxt *authctxt) |
126 | { | 61 | { |
127 | none_enabled = 0; | 62 | none_enabled = 0; |
128 | packet_check_eom(); | 63 | packet_check_eom(); |
129 | userauth_banner(); | ||
130 | #ifdef HAVE_CYGWIN | 64 | #ifdef HAVE_CYGWIN |
131 | if (check_nt_auth(1, authctxt->pw) == 0) | 65 | if (check_nt_auth(1, authctxt->pw) == 0) |
132 | return (0); | 66 | return (0); |