Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F145905302
D7051.id19846.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
13 KB
Referenced Files
None
Subscribers
None
D7051.id19846.diff
View Options
Index: head/crypto/openssh/auth-pam.c
===================================================================
--- head/crypto/openssh/auth-pam.c
+++ head/crypto/openssh/auth-pam.c
@@ -98,6 +98,7 @@
#include "ssh-gss.h"
#endif
#include "monitor_wrap.h"
+#include "blacklist_client.h"
extern ServerOptions options;
extern Buffer loginmsg;
@@ -794,6 +795,7 @@
free(msg);
return (0);
}
+ BLACKLIST_NOTIFY(BLACKLIST_AUTH_FAIL);
error("PAM: %s for %s%.100s from %.100s", msg,
sshpam_authctxt->valid ? "" : "illegal user ",
sshpam_authctxt->user,
Index: head/crypto/openssh/auth.c
===================================================================
--- head/crypto/openssh/auth.c
+++ head/crypto/openssh/auth.c
@@ -75,6 +75,7 @@
#include "authfile.h"
#include "ssherr.h"
#include "compat.h"
+#include "blacklist_client.h"
/* import */
extern ServerOptions options;
@@ -292,8 +293,11 @@
authmsg = "Postponed";
else if (partial)
authmsg = "Partial";
- else
+ else {
authmsg = authenticated ? "Accepted" : "Failed";
+ BLACKLIST_NOTIFY(authenticated ?
+ BLACKLIST_AUTH_OK : BLACKLIST_AUTH_FAIL);
+ }
authlog("%s %s%s%s for %s%.100s from %.200s port %d %s%s%s",
authmsg,
@@ -640,6 +644,7 @@
}
#endif
if (pw == NULL) {
+ BLACKLIST_NOTIFY(BLACKLIST_AUTH_FAIL);
logit("Invalid user %.100s from %.100s",
user, get_remote_ipaddr());
#ifdef CUSTOM_FAILED_LOGIN
Index: head/crypto/openssh/auth1.c
===================================================================
--- head/crypto/openssh/auth1.c
+++ head/crypto/openssh/auth1.c
@@ -43,6 +43,7 @@
#endif
#include "monitor_wrap.h"
#include "buffer.h"
+#include "blacklist_client.h"
/* import */
extern ServerOptions options;
@@ -337,6 +338,7 @@
char *msg;
size_t len;
+ BLACKLIST_NOTIFY(BLACKLIST_AUTH_FAIL);
error("Access denied for user %s by PAM account "
"configuration", authctxt->user);
len = buffer_len(&loginmsg);
@@ -404,6 +406,7 @@
else {
debug("do_authentication: invalid user %s", user);
authctxt->pw = fakepw();
+ BLACKLIST_NOTIFY(BLACKLIST_AUTH_FAIL);
}
/* Configuration may have changed as a result of Match */
Index: head/crypto/openssh/auth2.c
===================================================================
--- head/crypto/openssh/auth2.c
+++ head/crypto/openssh/auth2.c
@@ -52,6 +52,7 @@
#include "pathnames.h"
#include "buffer.h"
#include "canohost.h"
+#include "blacklist_client.h"
#ifdef GSSAPI
#include "ssh-gss.h"
@@ -248,6 +249,7 @@
} else {
logit("input_userauth_request: invalid user %s", user);
authctxt->pw = fakepw();
+ BLACKLIST_NOTIFY(BLACKLIST_AUTH_FAIL);
#ifdef SSH_AUDIT_EVENTS
PRIVSEP(audit_event(SSH_INVALID_USER));
#endif
Index: head/crypto/openssh/blacklist.c
===================================================================
--- head/crypto/openssh/blacklist.c
+++ head/crypto/openssh/blacklist.c
@@ -0,0 +1,97 @@
+/*-
+ * Copyright (c) 2015 The NetBSD Foundation, Inc.
+ * Copyright (c) 2016 The FreeBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Kurt Lidl
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "includes.h"
+
+#include <ctype.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <syslog.h>
+#include <unistd.h>
+
+#include "ssh.h"
+#include "packet.h"
+#include "log.h"
+#include "misc.h"
+#include "servconf.h"
+#include "blacklist_client.h"
+#include <blacklist.h>
+
+static struct blacklist *blstate = NULL;
+
+/* import */
+extern ServerOptions options;
+
+/* internal definition from bl.h */
+struct blacklist *bl_create(bool, char *, void (*)(int, const char *, va_list));
+
+/* impedence match vsyslog() to sshd's internal logging levels */
+void
+im_log(int priority, const char *message, va_list args)
+{
+ LogLevel imlevel;
+
+ switch (priority) {
+ case LOG_ERR:
+ imlevel = SYSLOG_LEVEL_ERROR;
+ break;
+ case LOG_DEBUG:
+ imlevel = SYSLOG_LEVEL_DEBUG1;
+ break;
+ case LOG_INFO:
+ imlevel = SYSLOG_LEVEL_INFO;
+ break;
+ default:
+ imlevel = SYSLOG_LEVEL_DEBUG2;
+ }
+ do_log(imlevel, message, args);
+}
+
+void
+blacklist_init(void)
+{
+
+ if (options.use_blacklist)
+ blstate = bl_create(false, NULL, im_log);
+}
+
+void
+blacklist_notify(int action)
+{
+
+ if (blstate != NULL && packet_connection_is_on_socket())
+ (void)blacklist_r(blstate, action,
+ packet_get_connection_in(), "ssh");
+}
Index: head/crypto/openssh/blacklist_client.h
===================================================================
--- head/crypto/openssh/blacklist_client.h
+++ head/crypto/openssh/blacklist_client.h
@@ -0,0 +1,57 @@
+/*-
+ * Copyright (c) 2015 The NetBSD Foundation, Inc.
+ * Copyright (c) 2016 The FreeBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Kurt Lidl
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BLACKLIST_CLIENT_H
+#define BLACKLIST_CLIENT_H
+
+enum {
+ BLACKLIST_AUTH_OK = 0,
+ BLACKLIST_AUTH_FAIL
+};
+
+#ifdef USE_BLACKLIST
+void blacklist_init(void);
+void blacklist_notify(int);
+
+#define BLACKLIST_INIT() blacklist_init()
+#define BLACKLIST_NOTIFY(x) blacklist_notify(x)
+
+#else
+
+#define BLACKLIST_INIT()
+#define BLACKLIST_NOTIFY(x)
+
+#endif
+
+
+#endif /* BLACKLIST_CLIENT_H */
Index: head/crypto/openssh/packet.c
===================================================================
--- head/crypto/openssh/packet.c
+++ head/crypto/openssh/packet.c
@@ -86,6 +86,7 @@
#include "packet.h"
#include "ssherr.h"
#include "sshbuf.h"
+#include "blacklist_client.h"
#ifdef PACKET_DEBUG
#define DBG(x) x
@@ -2071,6 +2072,7 @@
case SSH_ERR_NO_KEX_ALG_MATCH:
case SSH_ERR_NO_HOSTKEY_ALG_MATCH:
if (ssh && ssh->kex && ssh->kex->failed_choice) {
+ BLACKLIST_NOTIFY(BLACKLIST_AUTH_FAIL);
fatal("Unable to negotiate with %.200s port %d: %s. "
"Their offer: %s", ssh_remote_ipaddr(ssh),
ssh_remote_port(ssh), ssh_err(r),
Index: head/crypto/openssh/servconf.h
===================================================================
--- head/crypto/openssh/servconf.h
+++ head/crypto/openssh/servconf.h
@@ -195,6 +195,7 @@
char *auth_methods[MAX_AUTH_METHODS];
int fingerprint_hash;
+ int use_blacklist;
} ServerOptions;
/* Information about the incoming connection as used by Match */
Index: head/crypto/openssh/servconf.c
===================================================================
--- head/crypto/openssh/servconf.c
+++ head/crypto/openssh/servconf.c
@@ -172,6 +172,7 @@
options->ip_qos_bulk = -1;
options->version_addendum = NULL;
options->fingerprint_hash = -1;
+ options->use_blacklist = -1;
}
/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
@@ -360,6 +361,8 @@
options->fwd_opts.streamlocal_bind_unlink = 0;
if (options->fingerprint_hash == -1)
options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
+ if (options->use_blacklist == -1)
+ options->use_blacklist = 0;
assemble_algorithms(options);
@@ -437,6 +440,7 @@
sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
sStreamLocalBindMask, sStreamLocalBindUnlink,
sAllowStreamLocalForwarding, sFingerprintHash,
+ sUseBlacklist,
sDeprecated, sUnsupported
} ServerOpCodes;
@@ -579,6 +583,7 @@
{ "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
{ "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
{ "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
+ { "useblacklist", sUseBlacklist, SSHCFG_GLOBAL },
{ "noneenabled", sUnsupported, SSHCFG_ALL },
{ "hpndisabled", sDeprecated, SSHCFG_ALL },
{ "hpnbuffersize", sDeprecated, SSHCFG_ALL },
@@ -1861,6 +1866,10 @@
options->fingerprint_hash = value;
break;
+ case sUseBlacklist:
+ intptr = &options->use_blacklist;
+ goto parse_flag;
+
case sDeprecated:
logit("%s line %d: Deprecated option %s",
filename, linenum, arg);
@@ -2304,6 +2313,7 @@
dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
+ dump_cfg_fmtint(sUseBlacklist, o->use_blacklist);
/* string arguments */
dump_cfg_string(sPidFile, o->pid_file);
Index: head/crypto/openssh/sshd.c
===================================================================
--- head/crypto/openssh/sshd.c
+++ head/crypto/openssh/sshd.c
@@ -135,6 +135,7 @@
#include "ssh-sandbox.h"
#include "version.h"
#include "ssherr.h"
+#include "blacklist_client.h"
#ifdef LIBWRAP
#include <tcpd.h>
@@ -388,6 +389,8 @@
kill(0, SIGTERM);
}
+ BLACKLIST_NOTIFY(BLACKLIST_AUTH_FAIL);
+
/* Log error and exit. */
sigdie("Timeout before authentication for %s", get_remote_ipaddr());
}
@@ -2251,6 +2254,8 @@
buffer_init(&loginmsg);
auth_debug_reset();
+ BLACKLIST_INIT();
+
if (use_privsep) {
if (privsep_preauth(authctxt) == 1)
goto authenticated;
Index: head/crypto/openssh/sshd_config
===================================================================
--- head/crypto/openssh/sshd_config
+++ head/crypto/openssh/sshd_config
@@ -120,6 +120,7 @@
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
+#UseBlacklist no
#VersionAddendum FreeBSD-20160310
# no default banner path
Index: head/crypto/openssh/sshd_config.5
===================================================================
--- head/crypto/openssh/sshd_config.5
+++ head/crypto/openssh/sshd_config.5
@@ -1537,6 +1537,15 @@
.Cm TrustedUserCAKeys .
For more details on certificates, see the CERTIFICATES section in
.Xr ssh-keygen 1 .
+.It Cm UseBlacklist
+Specifies whether
+.Xr sshd 8
+attempts to send authentication success and failure messages
+to the
+.Xr blacklistd 8
+daemon.
+The default is
+.Dq no .
.It Cm UseDNS
Specifies whether
.Xr sshd 8
Index: head/secure/usr.sbin/sshd/Makefile
===================================================================
--- head/secure/usr.sbin/sshd/Makefile
+++ head/secure/usr.sbin/sshd/Makefile
@@ -40,6 +40,13 @@
LIBADD+= bsm
.endif
+.if ${MK_BLACKLIST_SUPPORT} != "no"
+CFLAGS+= -DUSE_BLACKLIST -I${SRCTOP}/contrib/blacklist/include
+SRCS+= blacklist.c
+LIBADD+= blacklist
+LDFLAGS+=-L${LIBBLACKLISTDIR}
+.endif
+
.if ${MK_KERBEROS_SUPPORT} != "no"
CFLAGS+= -include krb5_config.h
SRCS+= krb5_config.h
Index: head/secure/usr.sbin/sshd/Makefile.depend
===================================================================
--- head/secure/usr.sbin/sshd/Makefile.depend
+++ head/secure/usr.sbin/sshd/Makefile.depend
@@ -17,6 +17,7 @@
kerberos5/lib/libroken \
kerberos5/lib/libwind \
lib/${CSU_DIR} \
+ lib/libblacklist \
lib/libbsm \
lib/libc \
lib/libcom_err \
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Feb 27, 12:13 AM (3 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29009304
Default Alt Text
D7051.id19846.diff (13 KB)
Attached To
Mode
D7051: Add refactored blacklist support to sshd
Attached
Detach File
Event Timeline
Log In to Comment