|
|
4369a3 |
diff -up openssh/audit-bsm.c.audit openssh/audit-bsm.c
|
|
|
4369a3 |
--- openssh/audit-bsm.c.audit 2019-03-27 23:26:14.000000000 +0100
|
|
|
4369a3 |
+++ openssh/audit-bsm.c 2019-04-03 17:02:20.713886041 +0200
|
|
|
4369a3 |
@@ -372,13 +372,26 @@ audit_connection_from(const char *host,
|
|
|
f5835d |
#endif
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+audit_run_command(struct ssh *ssh, const char *command)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ /* not implemented */
|
|
|
4369a3 |
+ return 0;
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
4369a3 |
void
|
|
|
4369a3 |
-audit_run_command(const char *command)
|
|
|
4369a3 |
+audit_end_command(struct ssh *ssh, int handle, const char *command)
|
|
|
4369a3 |
{
|
|
|
4369a3 |
/* not implemented */
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
void
|
|
|
4369a3 |
+audit_count_session_open(void)
|
|
|
4369a3 |
+{
|
|
|
4369a3 |
+ /* not necessary */
|
|
|
4369a3 |
+}
|
|
|
4369a3 |
+
|
|
|
4369a3 |
+void
|
|
|
4369a3 |
audit_session_open(struct logininfo *li)
|
|
|
4369a3 |
{
|
|
|
4369a3 |
/* not implemented */
|
|
|
4369a3 |
@@ -390,6 +403,12 @@ audit_session_close(struct logininfo *li
|
|
|
f5835d |
/* not implemented */
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+audit_keyusage(struct ssh *ssh, int host_user, char *fp, int rv)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ /* not implemented */
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
void
|
|
|
4369a3 |
audit_event(struct ssh *ssh, ssh_audit_event_t event)
|
|
|
f5835d |
{
|
|
|
4369a3 |
@@ -451,4 +470,28 @@ audit_event(struct ssh *ssh, ssh_audit_e
|
|
|
f5835d |
debug("%s: unhandled event %d", __func__, event);
|
|
|
f5835d |
}
|
|
|
f5835d |
}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_unsupported_body(struct ssh *ssh, int what)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ /* not implemented */
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_kex_body(struct ssh *ssh, int ctos, char *enc, char *mac, char *compress, char *pfs, pid_t pid, uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ /* not implemented */
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_session_key_free_body(struct ssh * ssh, int ctos, pid_t pid, uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ /* not implemented */
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_destroy_sensitive_data(struct ssh *ssh, const char *fp, pid_t pid, uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ /* not implemented */
|
|
|
f5835d |
+}
|
|
|
f5835d |
#endif /* BSM */
|
|
|
4369a3 |
diff -up openssh/audit.c.audit openssh/audit.c
|
|
|
4369a3 |
--- openssh/audit.c.audit 2019-03-27 23:26:14.000000000 +0100
|
|
|
4369a3 |
+++ openssh/audit.c 2019-04-03 17:02:20.713886041 +0200
|
|
|
4369a3 |
@@ -34,6 +34,12 @@
|
|
|
f5835d |
#include "log.h"
|
|
|
f5835d |
#include "hostfile.h"
|
|
|
f5835d |
#include "auth.h"
|
|
|
f5835d |
+#include "ssh-gss.h"
|
|
|
f5835d |
+#include "monitor_wrap.h"
|
|
|
f5835d |
+#include "xmalloc.h"
|
|
|
f5835d |
+#include "misc.h"
|
|
|
f5835d |
+#include "servconf.h"
|
|
|
f5835d |
+#include "ssherr.h"
|
|
|
f5835d |
|
|
|
f5835d |
/*
|
|
|
f5835d |
* Care must be taken when using this since it WILL NOT be initialized when
|
|
|
f5835d |
@@ -41,6 +47,7 @@
|
|
|
f5835d |
* audit_event(CONNECTION_ABANDON) is called. Test for NULL before using.
|
|
|
f5835d |
*/
|
|
|
f5835d |
extern Authctxt *the_authctxt;
|
|
|
f5835d |
+extern ServerOptions options;
|
|
|
f5835d |
|
|
|
f5835d |
/* Maybe add the audit class to struct Authmethod? */
|
|
|
f5835d |
ssh_audit_event_t
|
|
|
f5835d |
@@ -69,13 +76,10 @@ audit_classify_auth(const char *method)
|
|
|
f5835d |
const char *
|
|
|
f5835d |
audit_username(void)
|
|
|
f5835d |
{
|
|
|
f5835d |
- static const char unknownuser[] = "(unknown user)";
|
|
|
f5835d |
- static const char invaliduser[] = "(invalid user)";
|
|
|
f5835d |
+ static const char unknownuser[] = "(unknown)";
|
|
|
f5835d |
|
|
|
f5835d |
- if (the_authctxt == NULL || the_authctxt->user == NULL)
|
|
|
f5835d |
+ if (the_authctxt == NULL || the_authctxt->user == NULL || !the_authctxt->valid)
|
|
|
f5835d |
return (unknownuser);
|
|
|
f5835d |
- if (!the_authctxt->valid)
|
|
|
f5835d |
- return (invaliduser);
|
|
|
f5835d |
return (the_authctxt->user);
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
@@ -109,6 +113,35 @@ audit_event_lookup(ssh_audit_event_t ev)
|
|
|
f5835d |
return(event_lookup[i].name);
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_key(struct ssh *ssh, int host_user, int *rv, const struct sshkey *key)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ char *fp;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ fp = sshkey_fingerprint(key, options.fingerprint_hash, SSH_FP_HEX);
|
|
|
4369a3 |
+ if (audit_keyusage(ssh, host_user, fp, (*rv == 0)) == 0)
|
|
|
f5835d |
+ *rv = -SSH_ERR_INTERNAL_ERROR;
|
|
|
f5835d |
+ free(fp);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_unsupported(struct ssh *ssh, int what)
|
|
|
f5835d |
+{
|
|
|
4369a3 |
+ PRIVSEP(audit_unsupported_body(ssh, what));
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_kex(struct ssh *ssh, int ctos, char *enc, char *mac, char *comp, char *pfs)
|
|
|
f5835d |
+{
|
|
|
4369a3 |
+ PRIVSEP(audit_kex_body(ssh, ctos, enc, mac, comp, pfs, getpid(), getuid()));
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_session_key_free(struct ssh *ssh, int ctos)
|
|
|
f5835d |
+{
|
|
|
4369a3 |
+ PRIVSEP(audit_session_key_free_body(ssh, ctos, getpid(), getuid()));
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
# ifndef CUSTOM_SSH_AUDIT_EVENTS
|
|
|
f5835d |
/*
|
|
|
f5835d |
* Null implementations of audit functions.
|
|
|
4369a3 |
@@ -138,6 +171,17 @@ audit_event(struct ssh *ssh, ssh_audit_e
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
/*
|
|
|
f5835d |
+ * Called when a child process has called, or will soon call,
|
|
|
f5835d |
+ * audit_session_open.
|
|
|
f5835d |
+ */
|
|
|
f5835d |
+void
|
|
|
f5835d |
+audit_count_session_open(void)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ debug("audit count session open euid %d user %s", geteuid(),
|
|
|
f5835d |
+ audit_username());
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+/*
|
|
|
f5835d |
* Called when a user session is started. Argument is the tty allocated to
|
|
|
f5835d |
* the session, or NULL if no tty was allocated.
|
|
|
f5835d |
*
|
|
|
4369a3 |
@@ -172,13 +216,82 @@ audit_session_close(struct logininfo *li
|
|
|
f5835d |
/*
|
|
|
f5835d |
* This will be called when a user runs a non-interactive command. Note that
|
|
|
f5835d |
* it may be called multiple times for a single connection since SSH2 allows
|
|
|
f5835d |
- * multiple sessions within a single connection.
|
|
|
f5835d |
+ * multiple sessions within a single connection. Returns a "handle" for
|
|
|
f5835d |
+ * audit_end_command.
|
|
|
f5835d |
*/
|
|
|
f5835d |
-void
|
|
|
4369a3 |
-audit_run_command(const char *command)
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+audit_run_command(struct ssh *ssh, const char *command)
|
|
|
f5835d |
{
|
|
|
f5835d |
debug("audit run command euid %d user %s command '%.200s'", geteuid(),
|
|
|
f5835d |
audit_username(), command);
|
|
|
f5835d |
+ return 0;
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+/*
|
|
|
f5835d |
+ * This will be called when the non-interactive command finishes. Note that
|
|
|
f5835d |
+ * it may be called multiple times for a single connection since SSH2 allows
|
|
|
f5835d |
+ * multiple sessions within a single connection. "handle" should come from
|
|
|
f5835d |
+ * the corresponding audit_run_command.
|
|
|
f5835d |
+ */
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_end_command(struct ssh *ssh, int handle, const char *command)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ debug("audit end nopty exec euid %d user %s command '%.200s'", geteuid(),
|
|
|
f5835d |
+ audit_username(), command);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+/*
|
|
|
f5835d |
+ * This will be called when user is successfully autherized by the RSA1/RSA/DSA key.
|
|
|
f5835d |
+ *
|
|
|
f5835d |
+ * Type is the key type, len is the key length(byte) and fp is the fingerprint of the key.
|
|
|
f5835d |
+ */
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+audit_keyusage(struct ssh *ssh, int host_user, char *fp, int rv)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ debug("audit %s key usage euid %d user %s fingerprint %s, result %d",
|
|
|
f5835d |
+ host_user ? "pubkey" : "hostbased", geteuid(), audit_username(),
|
|
|
f5835d |
+ fp, rv);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+/*
|
|
|
f5835d |
+ * This will be called when the protocol negotiation fails.
|
|
|
f5835d |
+ */
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_unsupported_body(struct ssh *ssh, int what)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ debug("audit unsupported protocol euid %d type %d", geteuid(), what);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+/*
|
|
|
f5835d |
+ * This will be called on succesfull protocol negotiation.
|
|
|
f5835d |
+ */
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_kex_body(struct ssh *ssh, int ctos, char *enc, char *mac, char *compress, char *pfs, pid_t pid,
|
|
|
f5835d |
+ uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ debug("audit protocol negotiation euid %d direction %d cipher %s mac %s compresion %s pfs %s from pid %ld uid %u",
|
|
|
f5835d |
+ (unsigned)geteuid(), ctos, enc, mac, compress, pfs, (long)pid,
|
|
|
f5835d |
+ (unsigned)uid);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+/*
|
|
|
f5835d |
+ * This will be called on succesfull session key discard
|
|
|
f5835d |
+ */
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_session_key_free_body(struct ssh *, int ctos, pid_t pid, uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ debug("audit session key discard euid %u direction %d from pid %ld uid %u",
|
|
|
f5835d |
+ (unsigned)geteuid(), ctos, (long)pid, (unsigned)uid);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+/*
|
|
|
f5835d |
+ * This will be called on destroy private part of the server key
|
|
|
f5835d |
+ */
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_destroy_sensitive_data(struct ssh *ssh, const char *fp, pid_t pid, uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ debug("audit destroy sensitive data euid %d fingerprint %s from pid %ld uid %u",
|
|
|
f5835d |
+ geteuid(), fp, (long)pid, (unsigned)uid);
|
|
|
f5835d |
}
|
|
|
f5835d |
# endif /* !defined CUSTOM_SSH_AUDIT_EVENTS */
|
|
|
f5835d |
#endif /* SSH_AUDIT_EVENTS */
|
|
|
4369a3 |
diff -up openssh/audit.h.audit openssh/audit.h
|
|
|
4369a3 |
--- openssh/audit.h.audit 2019-03-27 23:26:14.000000000 +0100
|
|
|
4369a3 |
+++ openssh/audit.h 2019-04-03 17:02:20.713886041 +0200
|
|
|
f5835d |
@@ -26,6 +26,7 @@
|
|
|
f5835d |
# define _SSH_AUDIT_H
|
|
|
f5835d |
|
|
|
f5835d |
#include "loginrec.h"
|
|
|
f5835d |
+#include "sshkey.h"
|
|
|
f5835d |
|
|
|
4369a3 |
struct ssh;
|
|
|
4369a3 |
|
|
|
4369a3 |
@@ -45,13 +46,32 @@ enum ssh_audit_event_type {
|
|
|
f5835d |
SSH_CONNECTION_ABANDON, /* closed without completing auth */
|
|
|
f5835d |
SSH_AUDIT_UNKNOWN
|
|
|
f5835d |
};
|
|
|
f5835d |
+
|
|
|
f5835d |
+enum ssh_audit_kex {
|
|
|
f5835d |
+ SSH_AUDIT_UNSUPPORTED_CIPHER,
|
|
|
f5835d |
+ SSH_AUDIT_UNSUPPORTED_MAC,
|
|
|
f5835d |
+ SSH_AUDIT_UNSUPPORTED_COMPRESSION
|
|
|
f5835d |
+};
|
|
|
f5835d |
typedef enum ssh_audit_event_type ssh_audit_event_t;
|
|
|
f5835d |
|
|
|
f5835d |
+int listening_for_clients(void);
|
|
|
f5835d |
+
|
|
|
f5835d |
void audit_connection_from(const char *, int);
|
|
|
4369a3 |
void audit_event(struct ssh *, ssh_audit_event_t);
|
|
|
f5835d |
+void audit_count_session_open(void);
|
|
|
f5835d |
void audit_session_open(struct logininfo *);
|
|
|
f5835d |
void audit_session_close(struct logininfo *);
|
|
|
f5835d |
-void audit_run_command(const char *);
|
|
|
4369a3 |
+int audit_run_command(struct ssh *, const char *);
|
|
|
4369a3 |
+void audit_end_command(struct ssh *, int, const char *);
|
|
|
f5835d |
ssh_audit_event_t audit_classify_auth(const char *);
|
|
|
4369a3 |
+int audit_keyusage(struct ssh *, int, char *, int);
|
|
|
4369a3 |
+void audit_key(struct ssh *, int, int *, const struct sshkey *);
|
|
|
4369a3 |
+void audit_unsupported(struct ssh *, int);
|
|
|
4369a3 |
+void audit_kex(struct ssh *, int, char *, char *, char *, char *);
|
|
|
4369a3 |
+void audit_unsupported_body(struct ssh *, int);
|
|
|
4369a3 |
+void audit_kex_body(struct ssh *, int, char *, char *, char *, char *, pid_t, uid_t);
|
|
|
4369a3 |
+void audit_session_key_free(struct ssh *, int ctos);
|
|
|
4369a3 |
+void audit_session_key_free_body(struct ssh *, int ctos, pid_t, uid_t);
|
|
|
4369a3 |
+void audit_destroy_sensitive_data(struct ssh *, const char *, pid_t, uid_t);
|
|
|
f5835d |
|
|
|
f5835d |
#endif /* _SSH_AUDIT_H */
|
|
|
4369a3 |
diff -up openssh/audit-linux.c.audit openssh/audit-linux.c
|
|
|
4369a3 |
--- openssh/audit-linux.c.audit 2019-03-27 23:26:14.000000000 +0100
|
|
|
4369a3 |
+++ openssh/audit-linux.c 2019-04-03 17:02:20.713886041 +0200
|
|
|
f5835d |
@@ -33,27 +33,40 @@
|
|
|
f5835d |
|
|
|
f5835d |
#include "log.h"
|
|
|
f5835d |
#include "audit.h"
|
|
|
f5835d |
+#include "sshkey.h"
|
|
|
f5835d |
+#include "hostfile.h"
|
|
|
f5835d |
+#include "auth.h"
|
|
|
f5835d |
+#include "misc.h" /* servconf.h needs misc.h for struct ForwardOptions */
|
|
|
f5835d |
+#include "servconf.h"
|
|
|
f5835d |
#include "canohost.h"
|
|
|
f5835d |
#include "packet.h"
|
|
|
f5835d |
-
|
|
|
f5835d |
+#include "cipher.h"
|
|
|
f5835d |
+#include "channels.h"
|
|
|
f5835d |
+#include "session.h"
|
|
|
f5835d |
+
|
|
|
f5835d |
+#define AUDIT_LOG_SIZE 256
|
|
|
f5835d |
+
|
|
|
f5835d |
+extern ServerOptions options;
|
|
|
f5835d |
+extern Authctxt *the_authctxt;
|
|
|
f5835d |
+extern u_int utmp_len;
|
|
|
f5835d |
const char *audit_username(void);
|
|
|
f5835d |
|
|
|
f5835d |
-int
|
|
|
f5835d |
-linux_audit_record_event(int uid, const char *username, const char *hostname,
|
|
|
f5835d |
- const char *ip, const char *ttyn, int success)
|
|
|
f5835d |
+static void
|
|
|
f5835d |
+linux_audit_user_logxxx(int uid, const char *username,
|
|
|
f5835d |
+ const char *ip, const char *ttyn, int success, int event)
|
|
|
f5835d |
{
|
|
|
f5835d |
int audit_fd, rc, saved_errno;
|
|
|
f5835d |
|
|
|
f5835d |
if ((audit_fd = audit_open()) < 0) {
|
|
|
f5835d |
if (errno == EINVAL || errno == EPROTONOSUPPORT ||
|
|
|
f5835d |
errno == EAFNOSUPPORT)
|
|
|
f5835d |
- return 1; /* No audit support in kernel */
|
|
|
f5835d |
+ return; /* No audit support in kernel */
|
|
|
f5835d |
else
|
|
|
f5835d |
- return 0; /* Must prevent login */
|
|
|
f5835d |
+ goto fatal_report; /* Must prevent login */
|
|
|
f5835d |
}
|
|
|
f5835d |
- rc = audit_log_acct_message(audit_fd, AUDIT_USER_LOGIN,
|
|
|
f5835d |
+ rc = audit_log_acct_message(audit_fd, event,
|
|
|
f5835d |
NULL, "login", username ? username : "(unknown)",
|
|
|
f5835d |
- username == NULL ? uid : -1, hostname, ip, ttyn, success);
|
|
|
f5835d |
+ username == NULL ? uid : -1, NULL, ip, ttyn, success);
|
|
|
f5835d |
saved_errno = errno;
|
|
|
f5835d |
close(audit_fd);
|
|
|
f5835d |
|
|
|
f5835d |
@@ -65,9 +78,96 @@ linux_audit_record_event(int uid, const
|
|
|
f5835d |
rc = 0;
|
|
|
f5835d |
errno = saved_errno;
|
|
|
f5835d |
|
|
|
f5835d |
- return rc >= 0;
|
|
|
f5835d |
+ if (rc < 0) {
|
|
|
f5835d |
+fatal_report:
|
|
|
f5835d |
+ fatal("linux_audit_write_entry failed: %s", strerror(errno));
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+static void
|
|
|
f5835d |
+linux_audit_user_auth(int uid, const char *username,
|
|
|
f5835d |
+ const char *ip, const char *ttyn, int success, int event)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int audit_fd, rc, saved_errno;
|
|
|
f5835d |
+ static const char *event_name[] = {
|
|
|
f5835d |
+ "maxtries exceeded",
|
|
|
f5835d |
+ "root denied",
|
|
|
f5835d |
+ "success",
|
|
|
f5835d |
+ "none",
|
|
|
f5835d |
+ "password",
|
|
|
f5835d |
+ "challenge-response",
|
|
|
f5835d |
+ "pubkey",
|
|
|
f5835d |
+ "hostbased",
|
|
|
f5835d |
+ "gssapi",
|
|
|
f5835d |
+ "invalid user",
|
|
|
f5835d |
+ "nologin",
|
|
|
f5835d |
+ "connection closed",
|
|
|
f5835d |
+ "connection abandoned",
|
|
|
f5835d |
+ "unknown"
|
|
|
f5835d |
+ };
|
|
|
f5835d |
+
|
|
|
f5835d |
+ audit_fd = audit_open();
|
|
|
f5835d |
+ if (audit_fd < 0) {
|
|
|
f5835d |
+ if (errno == EINVAL || errno == EPROTONOSUPPORT ||
|
|
|
f5835d |
+ errno == EAFNOSUPPORT)
|
|
|
f5835d |
+ return; /* No audit support in kernel */
|
|
|
f5835d |
+ else
|
|
|
f5835d |
+ goto fatal_report; /* Must prevent login */
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if ((event < 0) || (event > SSH_AUDIT_UNKNOWN))
|
|
|
f5835d |
+ event = SSH_AUDIT_UNKNOWN;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH,
|
|
|
f5835d |
+ NULL, event_name[event], username ? username : "(unknown)",
|
|
|
f5835d |
+ username == NULL ? uid : -1, NULL, ip, ttyn, success);
|
|
|
f5835d |
+ saved_errno = errno;
|
|
|
f5835d |
+ close(audit_fd);
|
|
|
f5835d |
+ /*
|
|
|
f5835d |
+ * Do not report error if the error is EPERM and sshd is run as non
|
|
|
f5835d |
+ * root user.
|
|
|
f5835d |
+ */
|
|
|
f5835d |
+ if ((rc == -EPERM) && (geteuid() != 0))
|
|
|
f5835d |
+ rc = 0;
|
|
|
f5835d |
+ errno = saved_errno;
|
|
|
f5835d |
+ if (rc < 0) {
|
|
|
f5835d |
+fatal_report:
|
|
|
f5835d |
+ fatal("linux_audit_write_entry failed: %s", strerror(errno));
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+audit_keyusage(struct ssh *ssh, int host_user, char *fp, int rv)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ char buf[AUDIT_LOG_SIZE];
|
|
|
f5835d |
+ int audit_fd, rc, saved_errno;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ audit_fd = audit_open();
|
|
|
f5835d |
+ if (audit_fd < 0) {
|
|
|
f5835d |
+ if (errno == EINVAL || errno == EPROTONOSUPPORT ||
|
|
|
f5835d |
+ errno == EAFNOSUPPORT)
|
|
|
f5835d |
+ return 1; /* No audit support in kernel */
|
|
|
f5835d |
+ else
|
|
|
f5835d |
+ return 0; /* Must prevent login */
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+ snprintf(buf, sizeof(buf), "%s_auth grantors=auth-key", host_user ? "pubkey" : "hostbased");
|
|
|
f5835d |
+ rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH, NULL,
|
|
|
4369a3 |
+ buf, audit_username(), -1, NULL, ssh_remote_ipaddr(ssh), NULL, rv);
|
|
|
f5835d |
+ if ((rc < 0) && ((rc != -1) || (getuid() == 0)))
|
|
|
f5835d |
+ goto out;
|
|
|
f5835d |
+ snprintf(buf, sizeof(buf), "op=negotiate kind=auth-key fp=%s", fp);
|
|
|
f5835d |
+ rc = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER, buf, NULL,
|
|
|
4369a3 |
+ ssh_remote_ipaddr(ssh), NULL, rv);
|
|
|
f5835d |
+out:
|
|
|
f5835d |
+ saved_errno = errno;
|
|
|
f5835d |
+ audit_close(audit_fd);
|
|
|
f5835d |
+ errno = saved_errno;
|
|
|
f5835d |
+ /* do not report error if the error is EPERM and sshd is run as non root user */
|
|
|
f5835d |
+ return (rc >= 0) || ((rc == -EPERM) && (getuid() != 0));
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+static int user_login_count = 0;
|
|
|
f5835d |
+
|
|
|
f5835d |
/* Below is the sshd audit API code */
|
|
|
f5835d |
|
|
|
f5835d |
void
|
|
|
4369a3 |
@@ -76,49 +176,210 @@ audit_connection_from(const char *host,
|
|
|
f5835d |
/* not implemented */
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+audit_run_command(struct ssh *ssh, const char *command)
|
|
|
4369a3 |
+{
|
|
|
f5835d |
+ if (!user_login_count++)
|
|
|
f5835d |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
4369a3 |
+ ssh_remote_ipaddr(ssh),
|
|
|
f5835d |
+ "ssh", 1, AUDIT_USER_LOGIN);
|
|
|
f5835d |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
4369a3 |
+ ssh_remote_ipaddr(ssh),
|
|
|
f5835d |
+ "ssh", 1, AUDIT_USER_START);
|
|
|
f5835d |
+ return 0;
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
4369a3 |
void
|
|
|
4369a3 |
-audit_run_command(const char *command)
|
|
|
4369a3 |
+audit_end_command(struct ssh *ssh, int handle, const char *command)
|
|
|
4369a3 |
{
|
|
|
4369a3 |
- /* not implemented */
|
|
|
f5835d |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
4369a3 |
+ ssh_remote_ipaddr(ssh),
|
|
|
f5835d |
+ "ssh", 1, AUDIT_USER_END);
|
|
|
f5835d |
+ if (user_login_count && !--user_login_count)
|
|
|
f5835d |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
4369a3 |
+ ssh_remote_ipaddr(ssh),
|
|
|
f5835d |
+ "ssh", 1, AUDIT_USER_LOGOUT);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
f5835d |
+audit_count_session_open(void)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ user_login_count++;
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
void
|
|
|
f5835d |
audit_session_open(struct logininfo *li)
|
|
|
f5835d |
{
|
|
|
f5835d |
- if (linux_audit_record_event(li->uid, NULL, li->hostname, NULL,
|
|
|
f5835d |
- li->line, 1) == 0)
|
|
|
f5835d |
- fatal("linux_audit_write_entry failed: %s", strerror(errno));
|
|
|
f5835d |
+ if (!user_login_count++)
|
|
|
f5835d |
+ linux_audit_user_logxxx(li->uid, NULL, li->hostname,
|
|
|
f5835d |
+ li->line, 1, AUDIT_USER_LOGIN);
|
|
|
f5835d |
+ linux_audit_user_logxxx(li->uid, NULL, li->hostname,
|
|
|
f5835d |
+ li->line, 1, AUDIT_USER_START);
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
void
|
|
|
f5835d |
audit_session_close(struct logininfo *li)
|
|
|
f5835d |
{
|
|
|
f5835d |
- /* not implemented */
|
|
|
f5835d |
+ linux_audit_user_logxxx(li->uid, NULL, li->hostname,
|
|
|
f5835d |
+ li->line, 1, AUDIT_USER_END);
|
|
|
f5835d |
+ if (user_login_count && !--user_login_count)
|
|
|
f5835d |
+ linux_audit_user_logxxx(li->uid, NULL, li->hostname,
|
|
|
f5835d |
+ li->line, 1, AUDIT_USER_LOGOUT);
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
void
|
|
|
4369a3 |
audit_event(struct ssh *ssh, ssh_audit_event_t event)
|
|
|
4369a3 |
{
|
|
|
f5835d |
switch(event) {
|
|
|
f5835d |
- case SSH_AUTH_SUCCESS:
|
|
|
f5835d |
- case SSH_CONNECTION_CLOSE:
|
|
|
f5835d |
case SSH_NOLOGIN:
|
|
|
f5835d |
- case SSH_LOGIN_EXCEED_MAXTRIES:
|
|
|
f5835d |
case SSH_LOGIN_ROOT_DENIED:
|
|
|
f5835d |
+ linux_audit_user_auth(-1, audit_username(),
|
|
|
f5835d |
+ ssh_remote_ipaddr(ssh), "ssh", 0, event);
|
|
|
f5835d |
+ linux_audit_user_logxxx(-1, audit_username(),
|
|
|
f5835d |
+ ssh_remote_ipaddr(ssh), "ssh", 0, AUDIT_USER_LOGIN);
|
|
|
f5835d |
break;
|
|
|
f5835d |
- case SSH_AUTH_FAIL_NONE:
|
|
|
f5835d |
case SSH_AUTH_FAIL_PASSWD:
|
|
|
f5835d |
+ if (options.use_pam)
|
|
|
f5835d |
+ break;
|
|
|
f5835d |
+ case SSH_LOGIN_EXCEED_MAXTRIES:
|
|
|
f5835d |
case SSH_AUTH_FAIL_KBDINT:
|
|
|
f5835d |
case SSH_AUTH_FAIL_PUBKEY:
|
|
|
f5835d |
case SSH_AUTH_FAIL_HOSTBASED:
|
|
|
f5835d |
case SSH_AUTH_FAIL_GSSAPI:
|
|
|
f5835d |
+ linux_audit_user_auth(-1, audit_username(),
|
|
|
f5835d |
+ ssh_remote_ipaddr(ssh), "ssh", 0, event);
|
|
|
f5835d |
+ break;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ case SSH_CONNECTION_CLOSE:
|
|
|
f5835d |
+ if (user_login_count) {
|
|
|
f5835d |
+ while (user_login_count--)
|
|
|
f5835d |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
f5835d |
+ ssh_remote_ipaddr(ssh),
|
|
|
f5835d |
+ "ssh", 1, AUDIT_USER_END);
|
|
|
f5835d |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
f5835d |
+ ssh_remote_ipaddr(ssh),
|
|
|
f5835d |
+ "ssh", 1, AUDIT_USER_LOGOUT);
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+ break;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ case SSH_CONNECTION_ABANDON:
|
|
|
f5835d |
case SSH_INVALID_USER:
|
|
|
f5835d |
- linux_audit_record_event(-1, audit_username(), NULL,
|
|
|
f5835d |
- ssh_remote_ipaddr(ssh), "sshd", 0);
|
|
|
f5835d |
+ linux_audit_user_logxxx(-1, audit_username(),
|
|
|
f5835d |
+ ssh_remote_ipaddr(ssh), "ssh", 0, AUDIT_USER_LOGIN);
|
|
|
f5835d |
break;
|
|
|
f5835d |
default:
|
|
|
f5835d |
debug("%s: unhandled event %d", __func__, event);
|
|
|
f5835d |
break;
|
|
|
f5835d |
}
|
|
|
f5835d |
}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_unsupported_body(struct ssh *ssh, int what)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+#ifdef AUDIT_CRYPTO_SESSION
|
|
|
f5835d |
+ char buf[AUDIT_LOG_SIZE];
|
|
|
f5835d |
+ const static char *name[] = { "cipher", "mac", "comp" };
|
|
|
f5835d |
+ char *s;
|
|
|
f5835d |
+ int audit_fd;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ snprintf(buf, sizeof(buf), "op=unsupported-%s direction=? cipher=? ksize=? rport=%d laddr=%s lport=%d ",
|
|
|
4369a3 |
+ name[what], ssh_remote_port(ssh), (s = get_local_ipaddr(ssh_packet_get_connection_in(ssh))),
|
|
|
4369a3 |
+ ssh_local_port(ssh));
|
|
|
f5835d |
+ free(s);
|
|
|
f5835d |
+ audit_fd = audit_open();
|
|
|
f5835d |
+ if (audit_fd < 0)
|
|
|
f5835d |
+ /* no problem, the next instruction will be fatal() */
|
|
|
f5835d |
+ return;
|
|
|
f5835d |
+ audit_log_user_message(audit_fd, AUDIT_CRYPTO_SESSION,
|
|
|
4369a3 |
+ buf, NULL, ssh_remote_ipaddr(ssh), NULL, 0);
|
|
|
f5835d |
+ audit_close(audit_fd);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+const static char *direction[] = { "from-server", "from-client", "both" };
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_kex_body(struct ssh *ssh, int ctos, char *enc, char *mac, char *compress,
|
|
|
f5835d |
+ char *pfs, pid_t pid, uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+#ifdef AUDIT_CRYPTO_SESSION
|
|
|
f5835d |
+ char buf[AUDIT_LOG_SIZE];
|
|
|
f5835d |
+ int audit_fd, audit_ok;
|
|
|
f5835d |
+ const struct sshcipher *cipher = cipher_by_name(enc);
|
|
|
f5835d |
+ char *s;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ snprintf(buf, sizeof(buf), "op=start direction=%s cipher=%s ksize=%d mac=%s pfs=%s spid=%jd suid=%jd rport=%d laddr=%s lport=%d ",
|
|
|
f5835d |
+ direction[ctos], enc, cipher ? 8 * cipher->key_len : 0, mac, pfs,
|
|
|
f5835d |
+ (intmax_t)pid, (intmax_t)uid,
|
|
|
4369a3 |
+ ssh_remote_port(ssh), (s = get_local_ipaddr(ssh_packet_get_connection_in(ssh))), ssh_local_port(ssh));
|
|
|
f5835d |
+ free(s);
|
|
|
f5835d |
+ audit_fd = audit_open();
|
|
|
f5835d |
+ if (audit_fd < 0) {
|
|
|
f5835d |
+ if (errno == EINVAL || errno == EPROTONOSUPPORT ||
|
|
|
f5835d |
+ errno == EAFNOSUPPORT)
|
|
|
f5835d |
+ return; /* No audit support in kernel */
|
|
|
f5835d |
+ else
|
|
|
f5835d |
+ fatal("cannot open audit"); /* Must prevent login */
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+ audit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_SESSION,
|
|
|
4369a3 |
+ buf, NULL, ssh_remote_ipaddr(ssh), NULL, 1);
|
|
|
f5835d |
+ audit_close(audit_fd);
|
|
|
f5835d |
+ /* do not abort if the error is EPERM and sshd is run as non root user */
|
|
|
f5835d |
+ if ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))
|
|
|
f5835d |
+ fatal("cannot write into audit"); /* Must prevent login */
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_session_key_free_body(struct ssh *ssh, int ctos, pid_t pid, uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ char buf[AUDIT_LOG_SIZE];
|
|
|
f5835d |
+ int audit_fd, audit_ok;
|
|
|
f5835d |
+ char *s;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ snprintf(buf, sizeof(buf), "op=destroy kind=session fp=? direction=%s spid=%jd suid=%jd rport=%d laddr=%s lport=%d ",
|
|
|
f5835d |
+ direction[ctos], (intmax_t)pid, (intmax_t)uid,
|
|
|
4369a3 |
+ ssh_remote_port(ssh),
|
|
|
4369a3 |
+ (s = get_local_ipaddr(ssh_packet_get_connection_in(ssh))),
|
|
|
4369a3 |
+ ssh_local_port(ssh));
|
|
|
f5835d |
+ free(s);
|
|
|
f5835d |
+ audit_fd = audit_open();
|
|
|
f5835d |
+ if (audit_fd < 0) {
|
|
|
f5835d |
+ if (errno != EINVAL && errno != EPROTONOSUPPORT &&
|
|
|
f5835d |
+ errno != EAFNOSUPPORT)
|
|
|
f5835d |
+ error("cannot open audit");
|
|
|
f5835d |
+ return;
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+ audit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,
|
|
|
4369a3 |
+ buf, NULL, ssh_remote_ipaddr(ssh), NULL, 1);
|
|
|
f5835d |
+ audit_close(audit_fd);
|
|
|
f5835d |
+ /* do not abort if the error is EPERM and sshd is run as non root user */
|
|
|
f5835d |
+ if ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))
|
|
|
f5835d |
+ error("cannot write into audit");
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_destroy_sensitive_data(struct ssh *ssh, const char *fp, pid_t pid, uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ char buf[AUDIT_LOG_SIZE];
|
|
|
f5835d |
+ int audit_fd, audit_ok;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ snprintf(buf, sizeof(buf), "op=destroy kind=server fp=%s direction=? spid=%jd suid=%jd ",
|
|
|
f5835d |
+ fp, (intmax_t)pid, (intmax_t)uid);
|
|
|
f5835d |
+ audit_fd = audit_open();
|
|
|
f5835d |
+ if (audit_fd < 0) {
|
|
|
f5835d |
+ if (errno != EINVAL && errno != EPROTONOSUPPORT &&
|
|
|
f5835d |
+ errno != EAFNOSUPPORT)
|
|
|
f5835d |
+ error("cannot open audit");
|
|
|
f5835d |
+ return;
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+ audit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,
|
|
|
f5835d |
+ buf, NULL,
|
|
|
4369a3 |
+ listening_for_clients() ? NULL : ssh_remote_ipaddr(ssh),
|
|
|
f5835d |
+ NULL, 1);
|
|
|
f5835d |
+ audit_close(audit_fd);
|
|
|
f5835d |
+ /* do not abort if the error is EPERM and sshd is run as non root user */
|
|
|
f5835d |
+ if ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))
|
|
|
f5835d |
+ error("cannot write into audit");
|
|
|
f5835d |
+}
|
|
|
f5835d |
#endif /* USE_LINUX_AUDIT */
|
|
|
4369a3 |
diff -up openssh/auditstub.c.audit openssh/auditstub.c
|
|
|
4369a3 |
--- openssh/auditstub.c.audit 2019-04-03 17:02:20.714886050 +0200
|
|
|
4369a3 |
+++ openssh/auditstub.c 2019-04-03 17:02:20.714886050 +0200
|
|
|
4369a3 |
@@ -0,0 +1,52 @@
|
|
|
f5835d |
+/* $Id: auditstub.c,v 1.1 jfch Exp $ */
|
|
|
f5835d |
+
|
|
|
f5835d |
+/*
|
|
|
f5835d |
+ * Copyright 2010 Red Hat, Inc. All rights reserved.
|
|
|
f5835d |
+ * Use is subject to license terms.
|
|
|
f5835d |
+ *
|
|
|
f5835d |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
f5835d |
+ * modification, are permitted provided that the following conditions
|
|
|
f5835d |
+ * are met:
|
|
|
f5835d |
+ * 1. Redistributions of source code must retain the above copyright
|
|
|
f5835d |
+ * notice, this list of conditions and the following disclaimer.
|
|
|
f5835d |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
|
f5835d |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
f5835d |
+ * documentation and/or other materials provided with the distribution.
|
|
|
f5835d |
+ *
|
|
|
f5835d |
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
f5835d |
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
f5835d |
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
f5835d |
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
f5835d |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
f5835d |
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
f5835d |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
f5835d |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
f5835d |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
f5835d |
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
f5835d |
+ *
|
|
|
f5835d |
+ * Red Hat author: Jan F. Chadima <jchadima@redhat.com>
|
|
|
f5835d |
+ */
|
|
|
f5835d |
+
|
|
|
f5835d |
+#include <sys/types.h>
|
|
|
f5835d |
+
|
|
|
4369a3 |
+struct ssh;
|
|
|
4369a3 |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_unsupported(struct ssh *ssh, int n)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_kex(struct ssh *ssh, int ctos, char *enc, char *mac, char *comp, char *pfs)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_session_key_free(struct ssh *ssh, int ctos)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+audit_session_key_free_body(struct ssh *ssh, int ctos, pid_t pid, uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+}
|
|
|
4369a3 |
diff -up openssh/auth2.c.audit openssh/auth2.c
|
|
|
4369a3 |
--- openssh/auth2.c.audit 2019-04-03 17:02:20.651885453 +0200
|
|
|
4369a3 |
+++ openssh/auth2.c 2019-04-03 17:02:20.714886050 +0200
|
|
|
4369a3 |
@@ -303,9 +303,6 @@ input_userauth_request(int type, u_int32
|
|
|
f5835d |
} else {
|
|
|
f5835d |
/* Invalid user, fake password information */
|
|
|
f5835d |
authctxt->pw = fakepw();
|
|
|
f5835d |
-#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
- PRIVSEP(audit_event(ssh, SSH_INVALID_USER));
|
|
|
f5835d |
-#endif
|
|
|
f5835d |
}
|
|
|
f5835d |
#ifdef USE_PAM
|
|
|
f5835d |
if (options.use_pam)
|
|
|
4369a3 |
diff -up openssh/auth2-hostbased.c.audit openssh/auth2-hostbased.c
|
|
|
4369a3 |
--- openssh/auth2-hostbased.c.audit 2019-04-03 17:02:20.612885083 +0200
|
|
|
4369a3 |
+++ openssh/auth2-hostbased.c 2019-04-03 17:02:20.714886050 +0200
|
|
|
4369a3 |
@@ -158,7 +158,7 @@ userauth_hostbased(struct ssh *ssh)
|
|
|
f5835d |
authenticated = 0;
|
|
|
4369a3 |
if (PRIVSEP(hostbased_key_allowed(ssh, authctxt->pw, cuser,
|
|
|
4369a3 |
chost, key)) &&
|
|
|
f5835d |
- PRIVSEP(sshkey_verify(key, sig, slen,
|
|
|
4369a3 |
+ PRIVSEP(hostbased_key_verify(ssh, key, sig, slen,
|
|
|
f5835d |
sshbuf_ptr(b), sshbuf_len(b), pkalg, ssh->compat)) == 0)
|
|
|
f5835d |
authenticated = 1;
|
|
|
f5835d |
|
|
|
4369a3 |
@@ -175,6 +175,19 @@ done:
|
|
|
f5835d |
return authenticated;
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+hostbased_key_verify(struct ssh *ssh, const struct sshkey *key, const u_char *sig,
|
|
|
4369a3 |
+ size_t slen, const u_char *data, size_t datalen, const char *pkalg, u_int compat)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int rv;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ rv = sshkey_verify(key, sig, slen, data, datalen, pkalg, compat);
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
+ audit_key(ssh, 0, &rv, key);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+ return rv;
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
/* return 1 if given hostkey is allowed */
|
|
|
f5835d |
int
|
|
|
4369a3 |
hostbased_key_allowed(struct ssh *ssh, struct passwd *pw,
|
|
|
4369a3 |
diff -up openssh/auth2-pubkey.c.audit openssh/auth2-pubkey.c
|
|
|
4369a3 |
--- openssh/auth2-pubkey.c.audit 2019-04-03 17:02:20.691885832 +0200
|
|
|
4369a3 |
+++ openssh/auth2-pubkey.c 2019-04-03 17:02:20.714886050 +0200
|
|
|
4369a3 |
@@ -219,7 +219,7 @@ userauth_pubkey(struct ssh *ssh)
|
|
|
f5835d |
/* test for correct signature */
|
|
|
f5835d |
authenticated = 0;
|
|
|
f5835d |
if (PRIVSEP(user_key_allowed(ssh, pw, key, 1, &authopts)) &&
|
|
|
f5835d |
- PRIVSEP(sshkey_verify(key, sig, slen,
|
|
|
4369a3 |
+ PRIVSEP(user_key_verify(ssh, key, sig, slen,
|
|
|
f5835d |
sshbuf_ptr(b), sshbuf_len(b),
|
|
|
f5835d |
(ssh->compat & SSH_BUG_SIGTYPE) == 0 ? pkalg : NULL,
|
|
|
f5835d |
ssh->compat)) == 0) {
|
|
|
4369a3 |
@@ -278,6 +278,19 @@ done:
|
|
|
f5835d |
return authenticated;
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+user_key_verify(struct ssh *ssh, const struct sshkey *key, const u_char *sig,
|
|
|
4369a3 |
+ size_t slen, const u_char *data, size_t datalen, const char *pkalg, u_int compat)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int rv;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ rv = sshkey_verify(key, sig, slen, data, datalen, pkalg, compat);
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
+ audit_key(ssh, 1, &rv, key);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+ return rv;
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
static int
|
|
|
f5835d |
match_principals_option(const char *principal_list, struct sshkey_cert *cert)
|
|
|
f5835d |
{
|
|
|
4369a3 |
diff -up openssh/auth.c.audit openssh/auth.c
|
|
|
4369a3 |
--- openssh/auth.c.audit 2019-04-03 17:02:20.691885832 +0200
|
|
|
4369a3 |
+++ openssh/auth.c 2019-04-03 17:02:20.714886050 +0200
|
|
|
4369a3 |
@@ -366,7 +366,7 @@ auth_log(struct ssh *ssh, int authentica
|
|
|
f5835d |
# endif
|
|
|
f5835d |
#endif
|
|
|
f5835d |
#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
- if (authenticated == 0 && !authctxt->postponed)
|
|
|
f5835d |
+ if (authenticated == 0 && !authctxt->postponed && !partial)
|
|
|
4369a3 |
audit_event(ssh, audit_classify_auth(method));
|
|
|
f5835d |
#endif
|
|
|
f5835d |
}
|
|
|
4369a3 |
@@ -592,9 +592,6 @@ getpwnamallow(struct ssh *ssh, const cha
|
|
|
4369a3 |
record_failed_login(ssh, user,
|
|
|
f5835d |
auth_get_canonical_hostname(ssh, options.use_dns), "ssh");
|
|
|
f5835d |
#endif
|
|
|
f5835d |
-#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
- audit_event(ssh, SSH_INVALID_USER);
|
|
|
f5835d |
-#endif /* SSH_AUDIT_EVENTS */
|
|
|
f5835d |
return (NULL);
|
|
|
f5835d |
}
|
|
|
4369a3 |
if (!allowed_user(ssh, pw))
|
|
|
4369a3 |
diff -up openssh/auth.h.audit openssh/auth.h
|
|
|
4369a3 |
--- openssh/auth.h.audit 2019-04-03 17:02:20.692885842 +0200
|
|
|
4369a3 |
+++ openssh/auth.h 2019-04-03 17:02:20.714886050 +0200
|
|
|
4369a3 |
@@ -195,6 +195,8 @@ struct passwd * getpwnamallow(struct ssh
|
|
|
f5835d |
|
|
|
f5835d |
char *expand_authorized_keys(const char *, struct passwd *pw);
|
|
|
f5835d |
char *authorized_principals_file(struct passwd *);
|
|
|
4369a3 |
+int user_key_verify(struct ssh *, const struct sshkey *, const u_char *, size_t,
|
|
|
f5835d |
+ const u_char *, size_t, const char *, u_int);
|
|
|
f5835d |
|
|
|
f5835d |
FILE *auth_openkeyfile(const char *, struct passwd *, int);
|
|
|
f5835d |
FILE *auth_openprincipals(const char *, struct passwd *, int);
|
|
|
4369a3 |
@@ -214,6 +216,8 @@ struct sshkey *get_hostkey_private_by_ty
|
|
|
f5835d |
int get_hostkey_index(struct sshkey *, int, struct ssh *);
|
|
|
4369a3 |
int sshd_hostkey_sign(struct ssh *, struct sshkey *, struct sshkey *,
|
|
|
4369a3 |
u_char **, size_t *, const u_char *, size_t, const char *);
|
|
|
4369a3 |
+int hostbased_key_verify(struct ssh *, const struct sshkey *, const u_char *, size_t,
|
|
|
f5835d |
+ const u_char *, size_t, const char *, u_int);
|
|
|
f5835d |
|
|
|
f5835d |
/* Key / cert options linkage to auth layer */
|
|
|
f5835d |
const struct sshauthopt *auth_options(struct ssh *);
|
|
|
4369a3 |
diff -up openssh/cipher.c.audit openssh/cipher.c
|
|
|
4369a3 |
--- openssh/cipher.c.audit 2019-03-27 23:26:14.000000000 +0100
|
|
|
4369a3 |
+++ openssh/cipher.c 2019-04-03 17:02:20.714886050 +0200
|
|
|
f5835d |
@@ -61,25 +61,6 @@ struct sshcipher_ctx {
|
|
|
f5835d |
const struct sshcipher *cipher;
|
|
|
f5835d |
};
|
|
|
f5835d |
|
|
|
f5835d |
-struct sshcipher {
|
|
|
f5835d |
- char *name;
|
|
|
f5835d |
- u_int block_size;
|
|
|
f5835d |
- u_int key_len;
|
|
|
f5835d |
- u_int iv_len; /* defaults to block_size */
|
|
|
f5835d |
- u_int auth_len;
|
|
|
f5835d |
- u_int flags;
|
|
|
f5835d |
-#define CFLAG_CBC (1<<0)
|
|
|
f5835d |
-#define CFLAG_CHACHAPOLY (1<<1)
|
|
|
f5835d |
-#define CFLAG_AESCTR (1<<2)
|
|
|
f5835d |
-#define CFLAG_NONE (1<<3)
|
|
|
f5835d |
-#define CFLAG_INTERNAL CFLAG_NONE /* Don't use "none" for packets */
|
|
|
f5835d |
-#ifdef WITH_OPENSSL
|
|
|
f5835d |
- const EVP_CIPHER *(*evptype)(void);
|
|
|
f5835d |
-#else
|
|
|
f5835d |
- void *ignored;
|
|
|
f5835d |
-#endif
|
|
|
f5835d |
-};
|
|
|
f5835d |
-
|
|
|
f5835d |
static const struct sshcipher ciphers[] = {
|
|
|
f5835d |
#ifdef WITH_OPENSSL
|
|
|
f5835d |
#ifndef OPENSSL_NO_DES
|
|
|
4369a3 |
@@ -410,7 +391,7 @@ cipher_get_length(struct sshcipher_ctx *
|
|
|
f5835d |
void
|
|
|
f5835d |
cipher_free(struct sshcipher_ctx *cc)
|
|
|
f5835d |
{
|
|
|
f5835d |
- if (cc == NULL)
|
|
|
f5835d |
+ if (cc == NULL || cc->cipher == NULL)
|
|
|
f5835d |
return;
|
|
|
f5835d |
if ((cc->cipher->flags & CFLAG_CHACHAPOLY) != 0)
|
|
|
f5835d |
explicit_bzero(&cc->cp_ctx, sizeof(cc->cp_ctx));
|
|
|
4369a3 |
diff -up openssh/cipher.h.audit openssh/cipher.h
|
|
|
4369a3 |
--- openssh/cipher.h.audit 2019-03-27 23:26:14.000000000 +0100
|
|
|
4369a3 |
+++ openssh/cipher.h 2019-04-03 17:02:20.714886050 +0200
|
|
|
f5835d |
@@ -45,7 +45,25 @@
|
|
|
f5835d |
#define CIPHER_ENCRYPT 1
|
|
|
f5835d |
#define CIPHER_DECRYPT 0
|
|
|
f5835d |
|
|
|
f5835d |
-struct sshcipher;
|
|
|
f5835d |
+struct sshcipher {
|
|
|
f5835d |
+ char *name;
|
|
|
f5835d |
+ u_int block_size;
|
|
|
f5835d |
+ u_int key_len;
|
|
|
f5835d |
+ u_int iv_len; /* defaults to block_size */
|
|
|
f5835d |
+ u_int auth_len;
|
|
|
f5835d |
+ u_int flags;
|
|
|
f5835d |
+#define CFLAG_CBC (1<<0)
|
|
|
f5835d |
+#define CFLAG_CHACHAPOLY (1<<1)
|
|
|
f5835d |
+#define CFLAG_AESCTR (1<<2)
|
|
|
f5835d |
+#define CFLAG_NONE (1<<3)
|
|
|
f5835d |
+#define CFLAG_INTERNAL CFLAG_NONE /* Don't use "none" for packets */
|
|
|
f5835d |
+#ifdef WITH_OPENSSL
|
|
|
f5835d |
+ const EVP_CIPHER *(*evptype)(void);
|
|
|
f5835d |
+#else
|
|
|
f5835d |
+ void *ignored;
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+};
|
|
|
f5835d |
+
|
|
|
f5835d |
struct sshcipher_ctx;
|
|
|
f5835d |
|
|
|
f5835d |
const struct sshcipher *cipher_by_name(const char *);
|
|
|
4369a3 |
diff -up openssh/kex.c.audit openssh/kex.c
|
|
|
4369a3 |
--- openssh/kex.c.audit 2019-04-03 17:02:20.652885462 +0200
|
|
|
4369a3 |
+++ openssh/kex.c 2019-04-03 17:02:20.715886060 +0200
|
|
|
4369a3 |
@@ -60,6 +60,7 @@
|
|
|
f5835d |
#include "ssherr.h"
|
|
|
f5835d |
#include "sshbuf.h"
|
|
|
f5835d |
#include "digest.h"
|
|
|
f5835d |
+#include "audit.h"
|
|
|
f5835d |
|
|
|
f5835d |
#ifdef GSSAPI
|
|
|
f5835d |
#include "ssh-gss.h"
|
|
|
4369a3 |
@@ -758,12 +759,16 @@ kex_start_rekex(struct ssh *ssh)
|
|
|
4369a3 |
}
|
|
|
4369a3 |
|
|
|
4369a3 |
static int
|
|
|
4369a3 |
-choose_enc(struct sshenc *enc, char *client, char *server)
|
|
|
4369a3 |
+choose_enc(struct ssh *ssh, struct sshenc *enc, char *client, char *server)
|
|
|
f5835d |
{
|
|
|
f5835d |
char *name = match_list(client, server, NULL);
|
|
|
f5835d |
|
|
|
f5835d |
- if (name == NULL)
|
|
|
f5835d |
+ if (name == NULL) {
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
+ audit_unsupported(ssh, SSH_AUDIT_UNSUPPORTED_CIPHER);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
return SSH_ERR_NO_CIPHER_ALG_MATCH;
|
|
|
f5835d |
+ }
|
|
|
f5835d |
if ((enc->cipher = cipher_by_name(name)) == NULL) {
|
|
|
f5835d |
free(name);
|
|
|
f5835d |
return SSH_ERR_INTERNAL_ERROR;
|
|
|
4369a3 |
@@ -783,8 +788,12 @@ choose_mac(struct ssh *ssh, struct sshma
|
|
|
f5835d |
{
|
|
|
f5835d |
char *name = match_list(client, server, NULL);
|
|
|
f5835d |
|
|
|
f5835d |
- if (name == NULL)
|
|
|
f5835d |
+ if (name == NULL) {
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
+ audit_unsupported(ssh, SSH_AUDIT_UNSUPPORTED_MAC);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
return SSH_ERR_NO_MAC_ALG_MATCH;
|
|
|
f5835d |
+ }
|
|
|
f5835d |
if (mac_setup(mac, name) < 0) {
|
|
|
f5835d |
free(name);
|
|
|
f5835d |
return SSH_ERR_INTERNAL_ERROR;
|
|
|
4369a3 |
@@ -796,12 +805,16 @@ choose_mac(struct ssh *ssh, struct sshma
|
|
|
4369a3 |
}
|
|
|
4369a3 |
|
|
|
4369a3 |
static int
|
|
|
4369a3 |
-choose_comp(struct sshcomp *comp, char *client, char *server)
|
|
|
4369a3 |
+choose_comp(struct ssh *ssh, struct sshcomp *comp, char *client, char *server)
|
|
|
f5835d |
{
|
|
|
f5835d |
char *name = match_list(client, server, NULL);
|
|
|
f5835d |
|
|
|
f5835d |
- if (name == NULL)
|
|
|
f5835d |
+ if (name == NULL) {
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
+ audit_unsupported(ssh, SSH_AUDIT_UNSUPPORTED_COMPRESSION);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
return SSH_ERR_NO_COMPRESS_ALG_MATCH;
|
|
|
f5835d |
+ }
|
|
|
f5835d |
if (strcmp(name, "zlib@openssh.com") == 0) {
|
|
|
f5835d |
comp->type = COMP_DELAYED;
|
|
|
f5835d |
} else if (strcmp(name, "zlib") == 0) {
|
|
|
4369a3 |
@@ -933,7 +946,7 @@ kex_choose_conf(struct ssh *ssh)
|
|
|
4369a3 |
nenc = ctos ? PROPOSAL_ENC_ALGS_CTOS : PROPOSAL_ENC_ALGS_STOC;
|
|
|
4369a3 |
nmac = ctos ? PROPOSAL_MAC_ALGS_CTOS : PROPOSAL_MAC_ALGS_STOC;
|
|
|
4369a3 |
ncomp = ctos ? PROPOSAL_COMP_ALGS_CTOS : PROPOSAL_COMP_ALGS_STOC;
|
|
|
4369a3 |
- if ((r = choose_enc(&newkeys->enc, cprop[nenc],
|
|
|
4369a3 |
+ if ((r = choose_enc(ssh, &newkeys->enc, cprop[nenc],
|
|
|
4369a3 |
sprop[nenc])) != 0) {
|
|
|
4369a3 |
kex->failed_choice = peer[nenc];
|
|
|
4369a3 |
peer[nenc] = NULL;
|
|
|
4369a3 |
@@ -948,7 +961,7 @@ kex_choose_conf(struct ssh *ssh)
|
|
|
4369a3 |
peer[nmac] = NULL;
|
|
|
4369a3 |
goto out;
|
|
|
4369a3 |
}
|
|
|
4369a3 |
- if ((r = choose_comp(&newkeys->comp, cprop[ncomp],
|
|
|
4369a3 |
+ if ((r = choose_comp(ssh, &newkeys->comp, cprop[ncomp],
|
|
|
4369a3 |
sprop[ncomp])) != 0) {
|
|
|
4369a3 |
kex->failed_choice = peer[ncomp];
|
|
|
4369a3 |
peer[ncomp] = NULL;
|
|
|
4369a3 |
@@ -971,6 +984,10 @@ kex_choose_conf(struct ssh *ssh)
|
|
|
f5835d |
dh_need = MAXIMUM(dh_need, newkeys->enc.block_size);
|
|
|
f5835d |
dh_need = MAXIMUM(dh_need, newkeys->enc.iv_len);
|
|
|
f5835d |
dh_need = MAXIMUM(dh_need, newkeys->mac.key_len);
|
|
|
f5835d |
+ debug("kex: %s need=%d dh_need=%d", kex->name, need, dh_need);
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
+ audit_kex(ssh, mode, newkeys->enc.name, newkeys->mac.name, newkeys->comp.name, kex->name);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
}
|
|
|
f5835d |
/* XXX need runden? */
|
|
|
f5835d |
kex->we_need = need;
|
|
|
4369a3 |
@@ -1129,6 +1146,36 @@ dump_digest(const char *msg, const u_cha
|
|
|
f5835d |
}
|
|
|
f5835d |
#endif
|
|
|
4369a3 |
|
|
|
f5835d |
+static void
|
|
|
f5835d |
+enc_destroy(struct sshenc *enc)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ if (enc == NULL)
|
|
|
f5835d |
+ return;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if (enc->key) {
|
|
|
f5835d |
+ memset(enc->key, 0, enc->key_len);
|
|
|
f5835d |
+ free(enc->key);
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if (enc->iv) {
|
|
|
f5835d |
+ memset(enc->iv, 0, enc->iv_len);
|
|
|
f5835d |
+ free(enc->iv);
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+
|
|
|
f5835d |
+ memset(enc, 0, sizeof(*enc));
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
f5835d |
+newkeys_destroy(struct newkeys *newkeys)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ if (newkeys == NULL)
|
|
|
f5835d |
+ return;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ enc_destroy(&newkeys->enc);
|
|
|
f5835d |
+ mac_destroy(&newkeys->mac);
|
|
|
f5835d |
+ memset(&newkeys->comp, 0, sizeof(newkeys->comp));
|
|
|
f5835d |
+}
|
|
|
4369a3 |
+
|
|
|
4369a3 |
/*
|
|
|
4369a3 |
* Send a plaintext error message to the peer, suffixed by \r\n.
|
|
|
4369a3 |
* Only used during banner exchange, and there only for the server.
|
|
|
4369a3 |
diff -up openssh/kex.h.audit openssh/kex.h
|
|
|
4369a3 |
--- openssh/kex.h.audit 2019-04-03 17:02:20.652885462 +0200
|
|
|
4369a3 |
+++ openssh/kex.h 2019-04-03 17:02:20.715886060 +0200
|
|
|
4369a3 |
@@ -226,6 +226,8 @@ int kexgss_client(struct ssh *);
|
|
|
f5835d |
int kexgss_server(struct ssh *);
|
|
|
f5835d |
#endif
|
|
|
f5835d |
|
|
|
f5835d |
+void newkeys_destroy(struct newkeys *newkeys);
|
|
|
f5835d |
+
|
|
|
4369a3 |
int kex_dh_keypair(struct kex *);
|
|
|
4369a3 |
int kex_dh_enc(struct kex *, const struct sshbuf *, struct sshbuf **,
|
|
|
4369a3 |
struct sshbuf **);
|
|
|
4369a3 |
diff -up openssh/mac.c.audit openssh/mac.c
|
|
|
4369a3 |
--- openssh/mac.c.audit 2019-04-03 17:02:20.652885462 +0200
|
|
|
4369a3 |
+++ openssh/mac.c 2019-04-03 17:02:20.715886060 +0200
|
|
|
4369a3 |
@@ -243,6 +243,20 @@ mac_clear(struct sshmac *mac)
|
|
|
f5835d |
mac->umac_ctx = NULL;
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+void
|
|
|
f5835d |
+mac_destroy(struct sshmac *mac)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ if (mac == NULL)
|
|
|
f5835d |
+ return;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if (mac->key) {
|
|
|
f5835d |
+ memset(mac->key, 0, mac->key_len);
|
|
|
f5835d |
+ free(mac->key);
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+
|
|
|
f5835d |
+ memset(mac, 0, sizeof(*mac));
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
/* XXX copied from ciphers_valid */
|
|
|
f5835d |
#define MAC_SEP ","
|
|
|
f5835d |
int
|
|
|
4369a3 |
diff -up openssh/mac.h.audit openssh/mac.h
|
|
|
4369a3 |
--- openssh/mac.h.audit 2019-03-27 23:26:14.000000000 +0100
|
|
|
4369a3 |
+++ openssh/mac.h 2019-04-03 17:02:20.715886060 +0200
|
|
|
f5835d |
@@ -49,5 +49,6 @@ int mac_compute(struct sshmac *, u_int3
|
|
|
f5835d |
int mac_check(struct sshmac *, u_int32_t, const u_char *, size_t,
|
|
|
f5835d |
const u_char *, size_t);
|
|
|
f5835d |
void mac_clear(struct sshmac *);
|
|
|
f5835d |
+void mac_destroy(struct sshmac *);
|
|
|
f5835d |
|
|
|
f5835d |
#endif /* SSHMAC_H */
|
|
|
4369a3 |
diff -up openssh/Makefile.in.audit openssh/Makefile.in
|
|
|
4369a3 |
--- openssh/Makefile.in.audit 2019-04-03 17:02:20.705885965 +0200
|
|
|
4369a3 |
+++ openssh/Makefile.in 2019-04-03 17:02:20.715886060 +0200
|
|
|
4369a3 |
@@ -109,7 +109,8 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \
|
|
|
4369a3 |
kexgexc.o kexgexs.o \
|
|
|
4369a3 |
sntrup4591761.o kexsntrup4591761x25519.o kexgen.o \
|
|
|
4369a3 |
kexgssc.o \
|
|
|
f5835d |
- platform-pledge.o platform-tracing.o platform-misc.o
|
|
|
f5835d |
+ platform-pledge.o platform-tracing.o platform-misc.o \
|
|
|
f5835d |
+ auditstub.o
|
|
|
f5835d |
|
|
|
4369a3 |
|
|
|
f5835d |
SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \
|
|
|
4369a3 |
diff -up openssh/monitor.c.audit openssh/monitor.c
|
|
|
4369a3 |
--- openssh/monitor.c.audit 2019-04-03 17:02:20.674885671 +0200
|
|
|
4369a3 |
+++ openssh/monitor.c 2019-04-03 17:03:17.201421405 +0200
|
|
|
4369a3 |
@@ -93,6 +93,7 @@
|
|
|
f5835d |
#include "compat.h"
|
|
|
f5835d |
#include "ssh2.h"
|
|
|
f5835d |
#include "authfd.h"
|
|
|
f5835d |
+#include "audit.h"
|
|
|
f5835d |
#include "match.h"
|
|
|
f5835d |
#include "ssherr.h"
|
|
|
f5835d |
|
|
|
4369a3 |
@@ -107,6 +108,8 @@ extern u_char session_id[];
|
|
|
f5835d |
extern struct sshbuf *loginmsg;
|
|
|
f5835d |
extern struct sshauthopt *auth_opts; /* XXX move to permanent ssh->authctxt? */
|
|
|
f5835d |
|
|
|
4369a3 |
+extern void destroy_sensitive_data(struct ssh *, int);
|
|
|
f5835d |
+
|
|
|
f5835d |
/* State exported from the child */
|
|
|
f5835d |
static struct sshbuf *child_state;
|
|
|
f5835d |
|
|
|
4369a3 |
@@ -157,6 +160,11 @@ int mm_answer_gss_updatecreds(struct ssh
|
|
|
f5835d |
#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
int mm_answer_audit_event(struct ssh *, int, struct sshbuf *);
|
|
|
4369a3 |
int mm_answer_audit_command(struct ssh *, int, struct sshbuf *);
|
|
|
4369a3 |
+int mm_answer_audit_end_command(struct ssh *, int, struct sshbuf *);
|
|
|
4369a3 |
+int mm_answer_audit_unsupported_body(struct ssh *, int, struct sshbuf *);
|
|
|
4369a3 |
+int mm_answer_audit_kex_body(struct ssh *, int, struct sshbuf *);
|
|
|
4369a3 |
+int mm_answer_audit_session_key_free_body(struct ssh *, int, struct sshbuf *);
|
|
|
4369a3 |
+int mm_answer_audit_server_key_free(struct ssh *, int, struct sshbuf *);
|
|
|
f5835d |
#endif
|
|
|
f5835d |
|
|
|
4369a3 |
static Authctxt *authctxt;
|
|
|
4369a3 |
@@ -215,6 +223,10 @@ struct mon_table mon_dispatch_proto20[]
|
|
|
f5835d |
#endif
|
|
|
f5835d |
#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
{MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
|
|
|
f5835d |
+ {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
|
|
|
f5835d |
+ {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
|
|
|
f5835d |
+ {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
|
|
|
f5835d |
+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
|
|
|
f5835d |
#endif
|
|
|
f5835d |
#ifdef BSD_AUTH
|
|
|
f5835d |
{MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
|
|
|
4369a3 |
@@ -249,6 +261,11 @@ struct mon_table mon_dispatch_postauth20
|
|
|
f5835d |
#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
{MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
|
|
|
f5835d |
{MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},
|
|
|
f5835d |
+ {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},
|
|
|
f5835d |
+ {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
|
|
|
f5835d |
+ {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
|
|
|
f5835d |
+ {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
|
|
|
f5835d |
+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
|
|
|
f5835d |
#endif
|
|
|
f5835d |
{0, 0, NULL}
|
|
|
f5835d |
};
|
|
|
4369a3 |
@@ -1445,8 +1462,10 @@ mm_answer_keyverify(struct ssh *ssh, int
|
|
|
f5835d |
char *sigalg;
|
|
|
f5835d |
size_t signaturelen, datalen, bloblen;
|
|
|
f5835d |
int r, ret, valid_data = 0, encoded_ret;
|
|
|
f5835d |
+ int type = 0;
|
|
|
f5835d |
|
|
|
f5835d |
- if ((r = sshbuf_get_string(m, &blob, &bloblen)) != 0 ||
|
|
|
f5835d |
+ if ((r = sshbuf_get_u32(m, &type)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_get_string(m, &blob, &bloblen)) != 0 ||
|
|
|
f5835d |
(r = sshbuf_get_string(m, &signature, &signaturelen)) != 0 ||
|
|
|
f5835d |
(r = sshbuf_get_string(m, &data, &datalen)) != 0 ||
|
|
|
f5835d |
(r = sshbuf_get_cstring(m, &sigalg, NULL)) != 0)
|
|
|
4369a3 |
@@ -1455,6 +1474,8 @@ mm_answer_keyverify(struct ssh *ssh, int
|
|
|
f5835d |
if (hostbased_cuser == NULL || hostbased_chost == NULL ||
|
|
|
f5835d |
!monitor_allowed_key(blob, bloblen))
|
|
|
f5835d |
fatal("%s: bad key, not previously allowed", __func__);
|
|
|
f5835d |
+ if (type != key_blobtype)
|
|
|
f5835d |
+ fatal("%s: bad key type", __func__);
|
|
|
f5835d |
|
|
|
f5835d |
/* Empty signature algorithm means NULL. */
|
|
|
f5835d |
if (*sigalg == '\0') {
|
|
|
4369a3 |
@@ -1470,21 +1491,24 @@ mm_answer_keyverify(struct ssh *ssh, int
|
|
|
f5835d |
case MM_USERKEY:
|
|
|
f5835d |
valid_data = monitor_valid_userblob(data, datalen);
|
|
|
f5835d |
auth_method = "publickey";
|
|
|
4369a3 |
+ ret = user_key_verify(ssh, key, signature, signaturelen, data,
|
|
|
4369a3 |
+ datalen, sigalg, ssh->compat);
|
|
|
f5835d |
break;
|
|
|
f5835d |
case MM_HOSTKEY:
|
|
|
f5835d |
valid_data = monitor_valid_hostbasedblob(data, datalen,
|
|
|
f5835d |
hostbased_cuser, hostbased_chost);
|
|
|
4369a3 |
+ ret = hostbased_key_verify(ssh, key, signature, signaturelen, data,
|
|
|
4369a3 |
+ datalen, sigalg, ssh->compat);
|
|
|
f5835d |
auth_method = "hostbased";
|
|
|
f5835d |
break;
|
|
|
f5835d |
default:
|
|
|
f5835d |
valid_data = 0;
|
|
|
f5835d |
+ ret = 0;
|
|
|
f5835d |
break;
|
|
|
f5835d |
}
|
|
|
f5835d |
if (!valid_data)
|
|
|
f5835d |
fatal("%s: bad signature data blob", __func__);
|
|
|
f5835d |
|
|
|
f5835d |
- ret = sshkey_verify(key, signature, signaturelen, data, datalen,
|
|
|
4369a3 |
- sigalg, ssh->compat);
|
|
|
f5835d |
debug3("%s: %s %p signature %s", __func__, auth_method, key,
|
|
|
f5835d |
(ret == 0) ? "verified" : "unverified");
|
|
|
f5835d |
auth2_record_key(authctxt, ret == 0, key);
|
|
|
4369a3 |
@@ -1536,13 +1560,19 @@ mm_record_login(struct ssh *ssh, Session
|
|
|
4369a3 |
}
|
|
|
4369a3 |
|
|
|
4369a3 |
static void
|
|
|
4369a3 |
-mm_session_close(Session *s)
|
|
|
4369a3 |
+mm_session_close(struct ssh *ssh, Session *s)
|
|
|
4369a3 |
{
|
|
|
4369a3 |
debug3("%s: session %d pid %ld", __func__, s->self, (long)s->pid);
|
|
|
4369a3 |
if (s->ttyfd != -1) {
|
|
|
f5835d |
debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ptyfd);
|
|
|
f5835d |
session_pty_cleanup2(s);
|
|
|
f5835d |
}
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+ if (s->command != NULL) {
|
|
|
f5835d |
+ debug3("%s: command %d", __func__, s->command_handle);
|
|
|
4369a3 |
+ session_end_command2(ssh, s);
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
session_unused(s->self);
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
4369a3 |
@@ -1609,7 +1639,7 @@ mm_answer_pty(struct ssh *ssh, int sock,
|
|
|
4369a3 |
|
|
|
4369a3 |
error:
|
|
|
4369a3 |
if (s != NULL)
|
|
|
4369a3 |
- mm_session_close(s);
|
|
|
4369a3 |
+ mm_session_close(ssh, s);
|
|
|
4369a3 |
if ((r = sshbuf_put_u32(m, 0)) != 0)
|
|
|
4369a3 |
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
4369a3 |
mm_request_send(sock, MONITOR_ANS_PTY, m);
|
|
|
4369a3 |
@@ -1628,7 +1658,7 @@ mm_answer_pty_cleanup(struct ssh *ssh, i
|
|
|
4369a3 |
if ((r = sshbuf_get_cstring(m, &tty, NULL)) != 0)
|
|
|
4369a3 |
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
4369a3 |
if ((s = session_by_tty(tty)) != NULL)
|
|
|
4369a3 |
- mm_session_close(s);
|
|
|
4369a3 |
+ mm_session_close(ssh, s);
|
|
|
4369a3 |
sshbuf_reset(m);
|
|
|
4369a3 |
free(tty);
|
|
|
4369a3 |
return (0);
|
|
|
4369a3 |
@@ -1650,6 +1680,8 @@ mm_answer_term(struct ssh *ssh, int sock
|
|
|
f5835d |
sshpam_cleanup();
|
|
|
f5835d |
#endif
|
|
|
f5835d |
|
|
|
4369a3 |
+ destroy_sensitive_data(ssh, 0);
|
|
|
f5835d |
+
|
|
|
f5835d |
while (waitpid(pmonitor->m_pid, &status, 0) == -1)
|
|
|
f5835d |
if (errno != EINTR)
|
|
|
f5835d |
exit(1);
|
|
|
4369a3 |
@@ -1696,12 +1728,47 @@ mm_answer_audit_command(struct ssh *ssh,
|
|
|
f5835d |
{
|
|
|
f5835d |
char *cmd;
|
|
|
f5835d |
int r;
|
|
|
f5835d |
+ Session *s;
|
|
|
f5835d |
|
|
|
f5835d |
debug3("%s entering", __func__);
|
|
|
f5835d |
if ((r = sshbuf_get_cstring(m, &cmd, NULL)) != 0)
|
|
|
f5835d |
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+
|
|
|
f5835d |
/* sanity check command, if so how? */
|
|
|
f5835d |
- audit_run_command(cmd);
|
|
|
f5835d |
+ s = session_new();
|
|
|
f5835d |
+ if (s == NULL)
|
|
|
f5835d |
+ fatal("%s: error allocating a session", __func__);
|
|
|
f5835d |
+ s->command = cmd;
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
+ s->command_handle = audit_run_command(ssh, cmd);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+
|
|
|
f5835d |
+ sshbuf_reset(m);
|
|
|
f5835d |
+ sshbuf_put_u32(m, s->self);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ mm_request_send(socket, MONITOR_ANS_AUDIT_COMMAND, m);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ return (0);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+mm_answer_audit_end_command(struct ssh *ssh, int socket, struct sshbuf *m)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int handle, r;
|
|
|
f5835d |
+ size_t len;
|
|
|
f5835d |
+ u_char *cmd = NULL;
|
|
|
f5835d |
+ Session *s;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ debug3("%s entering", __func__);
|
|
|
f5835d |
+ if ((r = sshbuf_get_u32(m, &handle)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_get_string(m, &cmd, &len)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+
|
|
|
f5835d |
+ s = session_by_id(handle);
|
|
|
f5835d |
+ if (s == NULL || s->ttyfd != -1 || s->command == NULL ||
|
|
|
f5835d |
+ strcmp(s->command, cmd) != 0)
|
|
|
f5835d |
+ fatal("%s: invalid handle", __func__);
|
|
|
4369a3 |
+ mm_session_close(ssh, s);
|
|
|
f5835d |
free(cmd);
|
|
|
f5835d |
return (0);
|
|
|
f5835d |
}
|
|
|
4369a3 |
@@ -1767,6 +1834,7 @@ monitor_apply_keystate(struct ssh *ssh,
|
|
|
f5835d |
void
|
|
|
4369a3 |
mm_get_keystate(struct ssh *ssh, struct monitor *pmonitor)
|
|
|
f5835d |
{
|
|
|
f5835d |
+ struct sshbuf *m;
|
|
|
f5835d |
debug3("%s: Waiting for new keys", __func__);
|
|
|
f5835d |
|
|
|
f5835d |
if ((child_state = sshbuf_new()) == NULL)
|
|
|
4369a3 |
@@ -1774,6 +1842,19 @@ mm_get_keystate(struct ssh *ssh, struct
|
|
|
f5835d |
mm_request_receive_expect(pmonitor->m_sendfd, MONITOR_REQ_KEYEXPORT,
|
|
|
f5835d |
child_state);
|
|
|
f5835d |
debug3("%s: GOT new keys", __func__);
|
|
|
f5835d |
+
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+ m = sshbuf_new();
|
|
|
f5835d |
+ mm_request_receive_expect(pmonitor->m_sendfd,
|
|
|
f5835d |
+ MONITOR_REQ_AUDIT_SESSION_KEY_FREE, m);
|
|
|
4369a3 |
+ mm_answer_audit_session_key_free_body(ssh, pmonitor->m_sendfd, m);
|
|
|
f5835d |
+ sshbuf_free(m);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+
|
|
|
f5835d |
+ /* Drain any buffered messages from the child */
|
|
|
f5835d |
+ while (pmonitor->m_log_recvfd >= 0 && monitor_read_log(pmonitor) == 0)
|
|
|
f5835d |
+ ;
|
|
|
f5835d |
+
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
|
|
|
4369a3 |
@@ -2066,3 +2147,102 @@ mm_answer_gss_updatecreds(struct ssh *ss
|
|
|
f5835d |
|
|
|
f5835d |
#endif /* GSSAPI */
|
|
|
f5835d |
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+mm_answer_audit_unsupported_body(struct ssh *ssh, int sock, struct sshbuf *m)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int what, r;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if ((r = sshbuf_get_u32(m, &what)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+
|
|
|
4369a3 |
+ audit_unsupported_body(ssh, what);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ sshbuf_reset(m);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ mm_request_send(sock, MONITOR_ANS_AUDIT_UNSUPPORTED, m);
|
|
|
f5835d |
+ return 0;
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+mm_answer_audit_kex_body(struct ssh *ssh, int sock, struct sshbuf *m)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int ctos, r;
|
|
|
f5835d |
+ char *cipher, *mac, *compress, *pfs;
|
|
|
f5835d |
+ u_int64_t tmp;
|
|
|
f5835d |
+ pid_t pid;
|
|
|
f5835d |
+ uid_t uid;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if ((r = sshbuf_get_u32(m, &ctos)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_get_cstring(m, &cipher, NULL)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_get_cstring(m, &mac, NULL)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_get_cstring(m, &compress, NULL)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_get_cstring(m, &pfs, NULL)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+ pid = (pid_t) tmp;
|
|
|
f5835d |
+ if ((r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+ uid = (pid_t) tmp;
|
|
|
f5835d |
+
|
|
|
4369a3 |
+ audit_kex_body(ssh, ctos, cipher, mac, compress, pfs, pid, uid);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ free(cipher);
|
|
|
f5835d |
+ free(mac);
|
|
|
f5835d |
+ free(compress);
|
|
|
f5835d |
+ free(pfs);
|
|
|
f5835d |
+ sshbuf_reset(m);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ mm_request_send(sock, MONITOR_ANS_AUDIT_KEX, m);
|
|
|
f5835d |
+ return 0;
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+mm_answer_audit_session_key_free_body(struct ssh *ssh, int sock, struct sshbuf *m)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int ctos, r;
|
|
|
f5835d |
+ u_int64_t tmp;
|
|
|
f5835d |
+ pid_t pid;
|
|
|
f5835d |
+ uid_t uid;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if ((r = sshbuf_get_u32(m, &ctos)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+ pid = (pid_t) tmp;
|
|
|
f5835d |
+ if ((r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+ uid = (uid_t) tmp;
|
|
|
f5835d |
+
|
|
|
4369a3 |
+ audit_session_key_free_body(ssh, ctos, pid, uid);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ sshbuf_reset(m);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ mm_request_send(sock, MONITOR_ANS_AUDIT_SESSION_KEY_FREE, m);
|
|
|
f5835d |
+ return 0;
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+mm_answer_audit_server_key_free(struct ssh *ssh, int sock, struct sshbuf *m)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ size_t len, r;
|
|
|
f5835d |
+ char *fp;
|
|
|
f5835d |
+ u_int64_t tmp;
|
|
|
f5835d |
+ pid_t pid;
|
|
|
f5835d |
+ uid_t uid;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if ((r = sshbuf_get_cstring(m, &fp, &len)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+ pid = (pid_t) tmp;
|
|
|
f5835d |
+ if ((r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+ uid = (uid_t) tmp;
|
|
|
f5835d |
+
|
|
|
4369a3 |
+ audit_destroy_sensitive_data(ssh, fp, pid, uid);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ free(fp);
|
|
|
f5835d |
+ sshbuf_reset(m);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ return 0;
|
|
|
f5835d |
+}
|
|
|
f5835d |
+#endif /* SSH_AUDIT_EVENTS */
|
|
|
4369a3 |
diff -up openssh/monitor.h.audit openssh/monitor.h
|
|
|
4369a3 |
--- openssh/monitor.h.audit 2019-04-03 17:02:20.674885671 +0200
|
|
|
4369a3 |
+++ openssh/monitor.h 2019-04-03 17:02:20.715886060 +0200
|
|
|
4369a3 |
@@ -65,7 +65,13 @@ enum monitor_reqtype {
|
|
|
f5835d |
MONITOR_REQ_PAM_QUERY = 106, MONITOR_ANS_PAM_QUERY = 107,
|
|
|
f5835d |
MONITOR_REQ_PAM_RESPOND = 108, MONITOR_ANS_PAM_RESPOND = 109,
|
|
|
f5835d |
MONITOR_REQ_PAM_FREE_CTX = 110, MONITOR_ANS_PAM_FREE_CTX = 111,
|
|
|
f5835d |
- MONITOR_REQ_AUDIT_EVENT = 112, MONITOR_REQ_AUDIT_COMMAND = 113,
|
|
|
f5835d |
+ MONITOR_REQ_AUDIT_EVENT = 112,
|
|
|
f5835d |
+ MONITOR_REQ_AUDIT_COMMAND = 114, MONITOR_ANS_AUDIT_COMMAND = 115,
|
|
|
f5835d |
+ MONITOR_REQ_AUDIT_END_COMMAND = 116,
|
|
|
f5835d |
+ MONITOR_REQ_AUDIT_UNSUPPORTED = 118, MONITOR_ANS_AUDIT_UNSUPPORTED = 119,
|
|
|
f5835d |
+ MONITOR_REQ_AUDIT_KEX = 120, MONITOR_ANS_AUDIT_KEX = 121,
|
|
|
f5835d |
+ MONITOR_REQ_AUDIT_SESSION_KEY_FREE = 122, MONITOR_ANS_AUDIT_SESSION_KEY_FREE = 123,
|
|
|
4369a3 |
+ MONITOR_REQ_AUDIT_SERVER_KEY_FREE = 124,
|
|
|
4369a3 |
|
|
|
4369a3 |
MONITOR_REQ_GSSSIGN = 150, MONITOR_ANS_GSSSIGN = 151,
|
|
|
4369a3 |
MONITOR_REQ_GSSUPCREDS = 152, MONITOR_ANS_GSSUPCREDS = 153,
|
|
|
4369a3 |
diff -up openssh/monitor_wrap.c.audit openssh/monitor_wrap.c
|
|
|
4369a3 |
--- openssh/monitor_wrap.c.audit 2019-04-03 17:02:20.653885472 +0200
|
|
|
4369a3 |
+++ openssh/monitor_wrap.c 2019-04-03 17:02:20.716886069 +0200
|
|
|
4369a3 |
@@ -513,7 +513,7 @@ mm_key_allowed(enum mm_keytype type, con
|
|
|
f5835d |
*/
|
|
|
f5835d |
|
|
|
f5835d |
int
|
|
|
f5835d |
-mm_sshkey_verify(const struct sshkey *key, const u_char *sig, size_t siglen,
|
|
|
f5835d |
+mm_sshkey_verify(enum mm_keytype type, const struct sshkey *key, const u_char *sig, size_t siglen,
|
|
|
f5835d |
const u_char *data, size_t datalen, const char *sigalg, u_int compat)
|
|
|
f5835d |
{
|
|
|
f5835d |
struct sshbuf *m;
|
|
|
4369a3 |
@@ -525,7 +525,8 @@ mm_sshkey_verify(const struct sshkey *ke
|
|
|
f5835d |
|
|
|
f5835d |
if ((m = sshbuf_new()) == NULL)
|
|
|
f5835d |
fatal("%s: sshbuf_new failed", __func__);
|
|
|
f5835d |
- if ((r = sshkey_puts(key, m)) != 0 ||
|
|
|
f5835d |
+ if ((r = sshbuf_put_u32(m, type)) != 0 ||
|
|
|
f5835d |
+ (r = sshkey_puts(key, m)) != 0 ||
|
|
|
f5835d |
(r = sshbuf_put_string(m, sig, siglen)) != 0 ||
|
|
|
f5835d |
(r = sshbuf_put_string(m, data, datalen)) != 0 ||
|
|
|
f5835d |
(r = sshbuf_put_cstring(m, sigalg == NULL ? "" : sigalg)) != 0)
|
|
|
4369a3 |
@@ -547,6 +548,20 @@ mm_sshkey_verify(const struct sshkey *ke
|
|
|
f5835d |
return 0;
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+mm_hostbased_key_verify(struct ssh *ssh, const struct sshkey *key, const u_char *sig, size_t siglen,
|
|
|
f5835d |
+ const u_char *data, size_t datalen, const char *pkalg, u_int compat)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ return mm_sshkey_verify(MM_HOSTKEY, key, sig, siglen, data, datalen, pkalg, compat);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+mm_user_key_verify(struct ssh *ssh, const struct sshkey *key, const u_char *sig, size_t siglen,
|
|
|
f5835d |
+ const u_char *data, size_t datalen, const char *pkalg, u_int compat)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ return mm_sshkey_verify(MM_USERKEY, key, sig, siglen, data, datalen, pkalg, compat);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
void
|
|
|
4369a3 |
mm_send_keystate(struct ssh *ssh, struct monitor *monitor)
|
|
|
f5835d |
{
|
|
|
4369a3 |
@@ -900,11 +915,12 @@ mm_audit_event(struct ssh *ssh, ssh_audi
|
|
|
f5835d |
sshbuf_free(m);
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
-void
|
|
|
4369a3 |
-mm_audit_run_command(const char *command)
|
|
|
f5835d |
+int
|
|
|
4369a3 |
+mm_audit_run_command(struct ssh *ssh, const char *command)
|
|
|
f5835d |
{
|
|
|
f5835d |
struct sshbuf *m;
|
|
|
f5835d |
int r;
|
|
|
f5835d |
+ int handle;
|
|
|
f5835d |
|
|
|
f5835d |
debug3("%s entering command %s", __func__, command);
|
|
|
f5835d |
|
|
|
4369a3 |
@@ -914,6 +930,30 @@ mm_audit_run_command(const char *command
|
|
|
f5835d |
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
|
|
|
f5835d |
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_COMMAND, m);
|
|
|
f5835d |
+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_COMMAND, m);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if ((r = sshbuf_get_u32(m, &handle)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+ sshbuf_free(m);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ return (handle);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+mm_audit_end_command(struct ssh *ssh, int handle, const char *command)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int r;
|
|
|
f5835d |
+ struct sshbuf *m;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ debug3("%s entering command %s", __func__, command);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if ((m = sshbuf_new()) == NULL)
|
|
|
f5835d |
+ fatal("%s: sshbuf_new failed", __func__);
|
|
|
f5835d |
+ if ((r = sshbuf_put_u32(m, handle)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_put_cstring(m, command)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+
|
|
|
f5835d |
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_END_COMMAND, m);
|
|
|
f5835d |
sshbuf_free(m);
|
|
|
f5835d |
}
|
|
|
f5835d |
#endif /* SSH_AUDIT_EVENTS */
|
|
|
4369a3 |
@@ -1074,3 +1114,83 @@ mm_ssh_gssapi_update_creds(ssh_gssapi_cc
|
|
|
f5835d |
}
|
|
|
4369a3 |
|
|
|
f5835d |
#endif /* GSSAPI */
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+mm_audit_unsupported_body(struct ssh *ssh, int what)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int r;
|
|
|
f5835d |
+ struct sshbuf *m;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if ((m = sshbuf_new()) == NULL)
|
|
|
f5835d |
+ fatal("%s: sshbuf_new failed", __func__);
|
|
|
f5835d |
+ if ((r = sshbuf_put_u32(m, what)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+
|
|
|
f5835d |
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_UNSUPPORTED, m);
|
|
|
f5835d |
+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_UNSUPPORTED,
|
|
|
f5835d |
+ m);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ sshbuf_free(m);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+mm_audit_kex_body(struct ssh *ssh, int ctos, char *cipher, char *mac, char *compress, char *fps, pid_t pid,
|
|
|
f5835d |
+ uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int r;
|
|
|
f5835d |
+ struct sshbuf *m;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if ((m = sshbuf_new()) == NULL)
|
|
|
f5835d |
+ fatal("%s: sshbuf_new failed", __func__);
|
|
|
f5835d |
+ if ((r = sshbuf_put_u32(m, ctos)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_put_cstring(m, cipher)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_put_cstring(m, (mac ? mac : "<implicit>"))) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_put_cstring(m, compress)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_put_cstring(m, fps)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_put_u64(m, pid)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_put_u64(m, uid)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+
|
|
|
f5835d |
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_KEX, m);
|
|
|
f5835d |
+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_KEX,
|
|
|
f5835d |
+ m);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ sshbuf_free(m);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+mm_audit_session_key_free_body(struct ssh *ssh, int ctos, pid_t pid, uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int r;
|
|
|
f5835d |
+ struct sshbuf *m;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if ((m = sshbuf_new()) == NULL)
|
|
|
f5835d |
+ fatal("%s: sshbuf_new failed", __func__);
|
|
|
f5835d |
+ if ((r = sshbuf_put_u32(m, ctos)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_put_u64(m, pid)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_put_u64(m, uid)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+
|
|
|
f5835d |
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SESSION_KEY_FREE, m);
|
|
|
f5835d |
+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_SESSION_KEY_FREE,
|
|
|
f5835d |
+ m);
|
|
|
f5835d |
+ sshbuf_free(m);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+mm_audit_destroy_sensitive_data(struct ssh *ssh, const char *fp, pid_t pid, uid_t uid)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ int r;
|
|
|
f5835d |
+ struct sshbuf *m;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if ((m = sshbuf_new()) == NULL)
|
|
|
f5835d |
+ fatal("%s: sshbuf_new failed", __func__);
|
|
|
f5835d |
+ if ((r = sshbuf_put_cstring(m, fp)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_put_u64(m, pid)) != 0 ||
|
|
|
f5835d |
+ (r = sshbuf_put_u64(m, uid)) != 0)
|
|
|
f5835d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
f5835d |
+
|
|
|
f5835d |
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SERVER_KEY_FREE, m);
|
|
|
f5835d |
+ sshbuf_free(m);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+#endif /* SSH_AUDIT_EVENTS */
|
|
|
4369a3 |
diff -up openssh/monitor_wrap.h.audit openssh/monitor_wrap.h
|
|
|
4369a3 |
--- openssh/monitor_wrap.h.audit 2019-04-03 17:02:20.653885472 +0200
|
|
|
4369a3 |
+++ openssh/monitor_wrap.h 2019-04-03 17:02:20.716886069 +0200
|
|
|
4369a3 |
@@ -57,7 +57,9 @@ int mm_user_key_allowed(struct ssh *, st
|
|
|
f5835d |
struct sshauthopt **);
|
|
|
4369a3 |
int mm_hostbased_key_allowed(struct ssh *, struct passwd *, const char *,
|
|
|
f5835d |
const char *, struct sshkey *);
|
|
|
f5835d |
-int mm_sshkey_verify(const struct sshkey *, const u_char *, size_t,
|
|
|
4369a3 |
+int mm_hostbased_key_verify(struct ssh *, const struct sshkey *, const u_char *, size_t,
|
|
|
f5835d |
+ const u_char *, size_t, const char *, u_int);
|
|
|
4369a3 |
+int mm_user_key_verify(struct ssh*, const struct sshkey *, const u_char *, size_t,
|
|
|
f5835d |
const u_char *, size_t, const char *, u_int);
|
|
|
f5835d |
|
|
|
f5835d |
#ifdef GSSAPI
|
|
|
4369a3 |
@@ -82,7 +84,12 @@ void mm_sshpam_free_ctx(void *);
|
|
|
f5835d |
#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
#include "audit.h"
|
|
|
4369a3 |
void mm_audit_event(struct ssh *, ssh_audit_event_t);
|
|
|
f5835d |
-void mm_audit_run_command(const char *);
|
|
|
4369a3 |
+int mm_audit_run_command(struct ssh *ssh, const char *);
|
|
|
4369a3 |
+void mm_audit_end_command(struct ssh *ssh, int, const char *);
|
|
|
4369a3 |
+void mm_audit_unsupported_body(struct ssh *, int);
|
|
|
4369a3 |
+void mm_audit_kex_body(struct ssh *, int, char *, char *, char *, char *, pid_t, uid_t);
|
|
|
4369a3 |
+void mm_audit_session_key_free_body(struct ssh *, int, pid_t, uid_t);
|
|
|
4369a3 |
+void mm_audit_destroy_sensitive_data(struct ssh *, const char *, pid_t, uid_t);
|
|
|
f5835d |
#endif
|
|
|
f5835d |
|
|
|
f5835d |
struct Session;
|
|
|
4369a3 |
diff -up openssh/packet.c.audit openssh/packet.c
|
|
|
4369a3 |
--- openssh/packet.c.audit 2019-03-27 23:26:14.000000000 +0100
|
|
|
4369a3 |
+++ openssh/packet.c 2019-04-03 17:02:20.716886069 +0200
|
|
|
4369a3 |
@@ -77,6 +77,7 @@
|
|
|
f5835d |
#include <zlib.h>
|
|
|
f5835d |
|
|
|
f5835d |
#include "xmalloc.h"
|
|
|
f5835d |
+#include "audit.h"
|
|
|
f5835d |
#include "crc32.h"
|
|
|
f5835d |
#include "compat.h"
|
|
|
f5835d |
#include "ssh2.h"
|
|
|
4369a3 |
@@ -510,6 +511,13 @@ ssh_packet_get_connection_out(struct ssh
|
|
|
f5835d |
return ssh->state->connection_out;
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+static int
|
|
|
f5835d |
+packet_state_has_keys (const struct session_state *state)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ return state != NULL &&
|
|
|
f5835d |
+ (state->newkeys[MODE_IN] != NULL || state->newkeys[MODE_OUT] != NULL);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
/*
|
|
|
f5835d |
* Returns the IP-address of the remote host as a string. The returned
|
|
|
f5835d |
* string must not be freed.
|
|
|
4369a3 |
@@ -587,22 +595,19 @@ ssh_packet_close_internal(struct ssh *ss
|
|
|
f5835d |
{
|
|
|
f5835d |
struct session_state *state = ssh->state;
|
|
|
f5835d |
u_int mode;
|
|
|
f5835d |
+ u_int had_keys = packet_state_has_keys(state);
|
|
|
f5835d |
|
|
|
f5835d |
if (!state->initialized)
|
|
|
f5835d |
return;
|
|
|
f5835d |
state->initialized = 0;
|
|
|
f5835d |
- if (do_close) {
|
|
|
f5835d |
- if (state->connection_in == state->connection_out) {
|
|
|
f5835d |
- close(state->connection_out);
|
|
|
f5835d |
- } else {
|
|
|
f5835d |
- close(state->connection_in);
|
|
|
f5835d |
- close(state->connection_out);
|
|
|
f5835d |
- }
|
|
|
f5835d |
- }
|
|
|
f5835d |
sshbuf_free(state->input);
|
|
|
f5835d |
+ state->input = NULL;
|
|
|
f5835d |
sshbuf_free(state->output);
|
|
|
f5835d |
+ state->output = NULL;
|
|
|
f5835d |
sshbuf_free(state->outgoing_packet);
|
|
|
f5835d |
+ state->outgoing_packet = NULL;
|
|
|
4369a3 |
sshbuf_free(state->incoming_packet);
|
|
|
f5835d |
+ state->incoming_packet = NULL;
|
|
|
f5835d |
for (mode = 0; mode < MODE_MAX; mode++) {
|
|
|
f5835d |
kex_free_newkeys(state->newkeys[mode]); /* current keys */
|
|
|
f5835d |
state->newkeys[mode] = NULL;
|
|
|
4369a3 |
@@ -636,8 +641,18 @@ ssh_packet_close_internal(struct ssh *ss
|
|
|
f5835d |
}
|
|
|
f5835d |
cipher_free(state->send_context);
|
|
|
f5835d |
cipher_free(state->receive_context);
|
|
|
f5835d |
+ if (had_keys && state->server_side) {
|
|
|
f5835d |
+ /* Assuming this is called only from privsep child */
|
|
|
4369a3 |
+ audit_session_key_free(ssh, MODE_MAX);
|
|
|
f5835d |
+ }
|
|
|
f5835d |
state->send_context = state->receive_context = NULL;
|
|
|
f5835d |
if (do_close) {
|
|
|
f5835d |
+ if (state->connection_in == state->connection_out) {
|
|
|
f5835d |
+ close(state->connection_out);
|
|
|
f5835d |
+ } else {
|
|
|
f5835d |
+ close(state->connection_in);
|
|
|
f5835d |
+ close(state->connection_out);
|
|
|
f5835d |
+ }
|
|
|
f5835d |
free(ssh->local_ipaddr);
|
|
|
f5835d |
ssh->local_ipaddr = NULL;
|
|
|
f5835d |
free(ssh->remote_ipaddr);
|
|
|
4369a3 |
@@ -864,6 +879,7 @@ ssh_set_newkeys(struct ssh *ssh, int mod
|
|
|
f5835d |
(unsigned long long)state->p_send.bytes,
|
|
|
f5835d |
(unsigned long long)state->p_send.blocks);
|
|
|
f5835d |
kex_free_newkeys(state->newkeys[mode]);
|
|
|
4369a3 |
+ audit_session_key_free(ssh, mode);
|
|
|
4369a3 |
state->newkeys[mode] = NULL;
|
|
|
4369a3 |
}
|
|
|
4369a3 |
/* note that both bytes and the seqnr are not reset */
|
|
|
4369a3 |
@@ -2167,6 +2183,71 @@ ssh_packet_get_output(struct ssh *ssh)
|
|
|
f5835d |
return (void *)ssh->state->output;
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+static void
|
|
|
f5835d |
+newkeys_destroy_and_free(struct newkeys *newkeys)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ if (newkeys == NULL)
|
|
|
f5835d |
+ return;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ free(newkeys->enc.name);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if (newkeys->mac.enabled) {
|
|
|
f5835d |
+ mac_clear(&newkeys->mac);
|
|
|
f5835d |
+ free(newkeys->mac.name);
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+
|
|
|
f5835d |
+ free(newkeys->comp.name);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ newkeys_destroy(newkeys);
|
|
|
f5835d |
+ free(newkeys);
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+static void
|
|
|
f5835d |
+packet_destroy_state(struct session_state *state)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ if (state == NULL)
|
|
|
f5835d |
+ return;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ cipher_free(state->receive_context);
|
|
|
f5835d |
+ cipher_free(state->send_context);
|
|
|
f5835d |
+
|
|
|
f5835d |
+ sshbuf_free(state->input);
|
|
|
f5835d |
+ state->input = NULL;
|
|
|
f5835d |
+ sshbuf_free(state->output);
|
|
|
f5835d |
+ state->output = NULL;
|
|
|
f5835d |
+ sshbuf_free(state->outgoing_packet);
|
|
|
f5835d |
+ state->outgoing_packet = NULL;
|
|
|
f5835d |
+ sshbuf_free(state->incoming_packet);
|
|
|
f5835d |
+ state->incoming_packet = NULL;
|
|
|
f5835d |
+ if (state->compression_buffer) {
|
|
|
f5835d |
+ sshbuf_free(state->compression_buffer);
|
|
|
f5835d |
+ state->compression_buffer = NULL;
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+ newkeys_destroy_and_free(state->newkeys[MODE_IN]);
|
|
|
f5835d |
+ state->newkeys[MODE_IN] = NULL;
|
|
|
f5835d |
+ newkeys_destroy_and_free(state->newkeys[MODE_OUT]);
|
|
|
f5835d |
+ state->newkeys[MODE_OUT] = NULL;
|
|
|
f5835d |
+ mac_destroy(state->packet_discard_mac);
|
|
|
f5835d |
+// TAILQ_HEAD(, packet) outgoing;
|
|
|
f5835d |
+// memset(state, 0, sizeof(state));
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+packet_destroy_all(struct ssh *ssh, int audit_it, int privsep)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ if (audit_it)
|
|
|
4369a3 |
+ audit_it = packet_state_has_keys(ssh->state);
|
|
|
4369a3 |
+ packet_destroy_state(ssh->state);
|
|
|
f5835d |
+ if (audit_it) {
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+ if (privsep)
|
|
|
4369a3 |
+ audit_session_key_free(ssh, MODE_MAX);
|
|
|
f5835d |
+ else
|
|
|
4369a3 |
+ audit_session_key_free_body(ssh, MODE_MAX, getpid(), getuid());
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
/* Reset after_authentication and reset compression in post-auth privsep */
|
|
|
f5835d |
static int
|
|
|
f5835d |
ssh_packet_set_postauth(struct ssh *ssh)
|
|
|
4369a3 |
diff -up openssh/packet.h.audit openssh/packet.h
|
|
|
4369a3 |
--- openssh/packet.h.audit 2019-03-27 23:26:14.000000000 +0100
|
|
|
4369a3 |
+++ openssh/packet.h 2019-04-03 17:02:20.716886069 +0200
|
|
|
4369a3 |
@@ -217,4 +217,5 @@ const u_char *sshpkt_ptr(struct ssh *, s
|
|
|
f5835d |
# undef EC_POINT
|
|
|
f5835d |
#endif
|
|
|
f5835d |
|
|
|
4369a3 |
+void packet_destroy_all(struct ssh *, int, int);
|
|
|
f5835d |
#endif /* PACKET_H */
|
|
|
4369a3 |
diff -up openssh/session.c.audit openssh/session.c
|
|
|
4369a3 |
--- openssh/session.c.audit 2019-04-03 17:02:20.712886031 +0200
|
|
|
4369a3 |
+++ openssh/session.c 2019-04-03 17:02:20.716886069 +0200
|
|
|
4369a3 |
@@ -136,7 +136,7 @@ extern char *__progname;
|
|
|
f5835d |
extern int debug_flag;
|
|
|
f5835d |
extern u_int utmp_len;
|
|
|
f5835d |
extern int startup_pipe;
|
|
|
f5835d |
-extern void destroy_sensitive_data(void);
|
|
|
4369a3 |
+extern void destroy_sensitive_data(struct ssh *, int);
|
|
|
f5835d |
extern struct sshbuf *loginmsg;
|
|
|
f5835d |
extern struct sshauthopt *auth_opts;
|
|
|
4369a3 |
extern char *tun_fwd_ifnames; /* serverloop.c */
|
|
|
4369a3 |
@@ -648,6 +648,14 @@ do_exec_pty(struct ssh *ssh, Session *s,
|
|
|
f5835d |
/* Parent. Close the slave side of the pseudo tty. */
|
|
|
f5835d |
close(ttyfd);
|
|
|
f5835d |
|
|
|
f5835d |
+#if !defined(HAVE_OSF_SIA) && defined(SSH_AUDIT_EVENTS)
|
|
|
f5835d |
+ /* do_login in the child did not affect state in this process,
|
|
|
f5835d |
+ compensate. From an architectural standpoint, this is extremely
|
|
|
f5835d |
+ ugly. */
|
|
|
f5835d |
+ if (command != NULL)
|
|
|
f5835d |
+ audit_count_session_open();
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+
|
|
|
f5835d |
/* Enter interactive session. */
|
|
|
f5835d |
s->ptymaster = ptymaster;
|
|
|
4369a3 |
ssh_packet_set_interactive(ssh, 1,
|
|
|
4369a3 |
@@ -740,15 +748,19 @@ do_exec(struct ssh *ssh, Session *s, con
|
|
|
f5835d |
s->self);
|
|
|
f5835d |
|
|
|
f5835d |
#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+ if (s->command != NULL || s->command_handle != -1)
|
|
|
f5835d |
+ fatal("do_exec: command already set");
|
|
|
f5835d |
if (command != NULL)
|
|
|
f5835d |
- PRIVSEP(audit_run_command(command));
|
|
|
f5835d |
+ s->command = xstrdup(command);
|
|
|
f5835d |
else if (s->ttyfd == -1) {
|
|
|
f5835d |
char *shell = s->pw->pw_shell;
|
|
|
f5835d |
|
|
|
f5835d |
if (shell[0] == '\0') /* empty shell means /bin/sh */
|
|
|
f5835d |
shell =_PATH_BSHELL;
|
|
|
f5835d |
- PRIVSEP(audit_run_command(shell));
|
|
|
f5835d |
+ s->command = xstrdup(shell);
|
|
|
f5835d |
}
|
|
|
f5835d |
+ if (s->command != NULL && s->ptyfd == -1)
|
|
|
4369a3 |
+ s->command_handle = PRIVSEP(audit_run_command(ssh, s->command));
|
|
|
f5835d |
#endif
|
|
|
f5835d |
if (s->ttyfd != -1)
|
|
|
f5835d |
ret = do_exec_pty(ssh, s, command);
|
|
|
4369a3 |
@@ -1556,8 +1568,11 @@ do_child(struct ssh *ssh, Session *s, co
|
|
|
4369a3 |
sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id));
|
|
|
f5835d |
|
|
|
f5835d |
/* remove hostkey from the child's memory */
|
|
|
f5835d |
- destroy_sensitive_data();
|
|
|
4369a3 |
+ destroy_sensitive_data(ssh, 1);
|
|
|
4369a3 |
ssh_packet_clear_keys(ssh);
|
|
|
f5835d |
+ /* Don't audit this - both us and the parent would be talking to the
|
|
|
f5835d |
+ monitor over a single socket, with no synchronization. */
|
|
|
4369a3 |
+ packet_destroy_all(ssh, 0, 1);
|
|
|
f5835d |
|
|
|
f5835d |
/* Force a password change */
|
|
|
f5835d |
if (s->authctxt->force_pwchange) {
|
|
|
4369a3 |
@@ -1769,6 +1784,9 @@ session_unused(int id)
|
|
|
f5835d |
sessions[id].ttyfd = -1;
|
|
|
f5835d |
sessions[id].ptymaster = -1;
|
|
|
f5835d |
sessions[id].x11_chanids = NULL;
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+ sessions[id].command_handle = -1;
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
sessions[id].next_unused = sessions_first_unused;
|
|
|
f5835d |
sessions_first_unused = id;
|
|
|
f5835d |
}
|
|
|
4369a3 |
@@ -1851,6 +1869,19 @@ session_open(Authctxt *authctxt, int cha
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
Session *
|
|
|
f5835d |
+session_by_id(int id)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ if (id >= 0 && id < sessions_nalloc) {
|
|
|
f5835d |
+ Session *s = &sessions[id];
|
|
|
f5835d |
+ if (s->used)
|
|
|
f5835d |
+ return s;
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+ debug("%s: unknown id %d", __func__, id);
|
|
|
f5835d |
+ session_dump();
|
|
|
f5835d |
+ return NULL;
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+Session *
|
|
|
f5835d |
session_by_tty(char *tty)
|
|
|
f5835d |
{
|
|
|
f5835d |
int i;
|
|
|
4369a3 |
@@ -2461,6 +2492,32 @@ session_exit_message(struct ssh *ssh, Se
|
|
|
f5835d |
chan_write_failed(ssh, c);
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+void
|
|
|
4369a3 |
+session_end_command2(struct ssh *ssh, Session *s)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ if (s->command != NULL) {
|
|
|
f5835d |
+ if (s->command_handle != -1)
|
|
|
4369a3 |
+ audit_end_command(ssh, s->command_handle, s->command);
|
|
|
f5835d |
+ free(s->command);
|
|
|
f5835d |
+ s->command = NULL;
|
|
|
f5835d |
+ s->command_handle = -1;
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+static void
|
|
|
4369a3 |
+session_end_command(struct ssh *ssh, Session *s)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ if (s->command != NULL) {
|
|
|
f5835d |
+ if (s->command_handle != -1)
|
|
|
4369a3 |
+ PRIVSEP(audit_end_command(ssh, s->command_handle, s->command));
|
|
|
f5835d |
+ free(s->command);
|
|
|
f5835d |
+ s->command = NULL;
|
|
|
f5835d |
+ s->command_handle = -1;
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+}
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+
|
|
|
f5835d |
void
|
|
|
f5835d |
session_close(struct ssh *ssh, Session *s)
|
|
|
f5835d |
{
|
|
|
4369a3 |
@@ -2474,6 +2531,10 @@ session_close(struct ssh *ssh, Session *
|
|
|
f5835d |
|
|
|
f5835d |
if (s->ttyfd != -1)
|
|
|
f5835d |
session_pty_cleanup(s);
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+ if (s->command)
|
|
|
4369a3 |
+ session_end_command(ssh, s);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
free(s->term);
|
|
|
f5835d |
free(s->display);
|
|
|
f5835d |
free(s->x11_chanids);
|
|
|
4369a3 |
@@ -2549,14 +2610,14 @@ session_close_by_channel(struct ssh *ssh
|
|
|
4369a3 |
}
|
|
|
4369a3 |
|
|
|
4369a3 |
void
|
|
|
4369a3 |
-session_destroy_all(struct ssh *ssh, void (*closefunc)(Session *))
|
|
|
4369a3 |
+session_destroy_all(struct ssh *ssh, void (*closefunc)(struct ssh *ssh, Session *))
|
|
|
4369a3 |
{
|
|
|
4369a3 |
int i;
|
|
|
4369a3 |
for (i = 0; i < sessions_nalloc; i++) {
|
|
|
4369a3 |
Session *s = &sessions[i];
|
|
|
4369a3 |
if (s->used) {
|
|
|
4369a3 |
if (closefunc != NULL)
|
|
|
4369a3 |
- closefunc(s);
|
|
|
4369a3 |
+ closefunc(ssh, s);
|
|
|
4369a3 |
else
|
|
|
4369a3 |
session_close(ssh, s);
|
|
|
4369a3 |
}
|
|
|
4369a3 |
@@ -2683,6 +2744,15 @@ do_authenticated2(struct ssh *ssh, Authc
|
|
|
f5835d |
server_loop2(ssh, authctxt);
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+static void
|
|
|
4369a3 |
+do_cleanup_one_session(struct ssh *ssh, Session *s)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ session_pty_cleanup2(s);
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
+ session_end_command2(ssh, s);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
void
|
|
|
f5835d |
do_cleanup(struct ssh *ssh, Authctxt *authctxt)
|
|
|
f5835d |
{
|
|
|
4369a3 |
@@ -2746,7 +2816,7 @@ do_cleanup(struct ssh *ssh, Authctxt *au
|
|
|
f5835d |
* or if running in monitor.
|
|
|
f5835d |
*/
|
|
|
f5835d |
if (!use_privsep || mm_is_monitor())
|
|
|
f5835d |
- session_destroy_all(ssh, session_pty_cleanup2);
|
|
|
f5835d |
+ session_destroy_all(ssh, do_cleanup_one_session);
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
/* Return a name for the remote host that fits inside utmp_size */
|
|
|
4369a3 |
diff -up openssh/session.h.audit openssh/session.h
|
|
|
4369a3 |
--- openssh/session.h.audit 2019-03-27 23:26:14.000000000 +0100
|
|
|
4369a3 |
+++ openssh/session.h 2019-04-03 17:02:20.717886079 +0200
|
|
|
4369a3 |
@@ -61,6 +61,12 @@ struct Session {
|
|
|
f5835d |
char *name;
|
|
|
f5835d |
char *val;
|
|
|
f5835d |
} *env;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ /* exec */
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+ int command_handle;
|
|
|
f5835d |
+ char *command;
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
};
|
|
|
f5835d |
|
|
|
f5835d |
void do_authenticated(struct ssh *, Authctxt *);
|
|
|
4369a3 |
@@ -71,10 +77,12 @@ void session_unused(int);
|
|
|
4369a3 |
int session_input_channel_req(struct ssh *, Channel *, const char *);
|
|
|
4369a3 |
void session_close_by_pid(struct ssh *ssh, pid_t, int);
|
|
|
f5835d |
void session_close_by_channel(struct ssh *, int, void *);
|
|
|
4369a3 |
-void session_destroy_all(struct ssh *, void (*)(Session *));
|
|
|
4369a3 |
+void session_destroy_all(struct ssh *, void (*)(struct ssh*, Session *));
|
|
|
f5835d |
void session_pty_cleanup2(Session *);
|
|
|
4369a3 |
+void session_end_command2(struct ssh *ssh, Session *);
|
|
|
f5835d |
|
|
|
f5835d |
Session *session_new(void);
|
|
|
f5835d |
+Session *session_by_id(int);
|
|
|
f5835d |
Session *session_by_tty(char *);
|
|
|
f5835d |
void session_close(struct ssh *, Session *);
|
|
|
f5835d |
void do_setusercontext(struct passwd *);
|
|
|
4369a3 |
diff -up openssh/sshd.c.audit openssh/sshd.c
|
|
|
4369a3 |
--- openssh/sshd.c.audit 2019-04-03 17:02:20.692885842 +0200
|
|
|
4369a3 |
+++ openssh/sshd.c 2019-04-03 17:02:20.717886079 +0200
|
|
|
f5835d |
@@ -122,6 +122,7 @@
|
|
|
f5835d |
#include "ssh-gss.h"
|
|
|
f5835d |
#endif
|
|
|
f5835d |
#include "monitor_wrap.h"
|
|
|
f5835d |
+#include "audit.h"
|
|
|
f5835d |
#include "ssh-sandbox.h"
|
|
|
f5835d |
#include "auth-options.h"
|
|
|
f5835d |
#include "version.h"
|
|
|
4369a3 |
@@ -261,8 +262,8 @@ struct sshbuf *loginmsg;
|
|
|
f5835d |
struct passwd *privsep_pw = NULL;
|
|
|
f5835d |
|
|
|
f5835d |
/* Prototypes for various functions defined later in this file. */
|
|
|
f5835d |
-void destroy_sensitive_data(void);
|
|
|
4369a3 |
-void demote_sensitive_data(void);
|
|
|
4369a3 |
+void destroy_sensitive_data(struct ssh *, int);
|
|
|
4369a3 |
+void demote_sensitive_data(struct ssh *);
|
|
|
4369a3 |
static void do_ssh2_kex(struct ssh *);
|
|
|
f5835d |
|
|
|
4369a3 |
/*
|
|
|
4369a3 |
@@ -278,6 +279,15 @@ close_listen_socks(void)
|
|
|
f5835d |
num_listen_socks = -1;
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
+/*
|
|
|
f5835d |
+ * Is this process listening for clients (i.e. not specific to any specific
|
|
|
f5835d |
+ * client connection?)
|
|
|
f5835d |
+ */
|
|
|
f5835d |
+int listening_for_clients(void)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ return num_listen_socks >= 0;
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
static void
|
|
|
f5835d |
close_startup_pipes(void)
|
|
|
f5835d |
{
|
|
|
4369a3 |
@@ -380,18 +390,45 @@ grace_alarm_handler(int sig)
|
|
|
4369a3 |
ssh_remote_port(the_active_state));
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
-/* Destroy the host and server keys. They will no longer be needed. */
|
|
|
f5835d |
+/*
|
|
|
f5835d |
+ * Destroy the host and server keys. They will no longer be needed. Careful,
|
|
|
f5835d |
+ * this can be called from cleanup_exit() - i.e. from just about anywhere.
|
|
|
f5835d |
+ */
|
|
|
f5835d |
void
|
|
|
f5835d |
-destroy_sensitive_data(void)
|
|
|
4369a3 |
+destroy_sensitive_data(struct ssh *ssh, int privsep)
|
|
|
f5835d |
{
|
|
|
f5835d |
u_int i;
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+ pid_t pid;
|
|
|
f5835d |
+ uid_t uid;
|
|
|
f5835d |
|
|
|
f5835d |
+ pid = getpid();
|
|
|
f5835d |
+ uid = getuid();
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
for (i = 0; i < options.num_host_key_files; i++) {
|
|
|
f5835d |
if (sensitive_data.host_keys[i]) {
|
|
|
f5835d |
+ char *fp;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if (sshkey_is_private(sensitive_data.host_keys[i]))
|
|
|
f5835d |
+ fp = sshkey_fingerprint(sensitive_data.host_keys[i], options.fingerprint_hash, SSH_FP_HEX);
|
|
|
f5835d |
+ else
|
|
|
f5835d |
+ fp = NULL;
|
|
|
f5835d |
sshkey_free(sensitive_data.host_keys[i]);
|
|
|
f5835d |
sensitive_data.host_keys[i] = NULL;
|
|
|
f5835d |
+ if (fp != NULL) {
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+ if (privsep)
|
|
|
4369a3 |
+ PRIVSEP(audit_destroy_sensitive_data(ssh, fp,
|
|
|
f5835d |
+ pid, uid));
|
|
|
f5835d |
+ else
|
|
|
4369a3 |
+ audit_destroy_sensitive_data(ssh, fp,
|
|
|
f5835d |
+ pid, uid);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+ free(fp);
|
|
|
f5835d |
+ }
|
|
|
f5835d |
}
|
|
|
f5835d |
- if (sensitive_data.host_certificates[i]) {
|
|
|
f5835d |
+ if (sensitive_data.host_certificates
|
|
|
f5835d |
+ && sensitive_data.host_certificates[i]) {
|
|
|
f5835d |
sshkey_free(sensitive_data.host_certificates[i]);
|
|
|
f5835d |
sensitive_data.host_certificates[i] = NULL;
|
|
|
f5835d |
}
|
|
|
4369a3 |
@@ -400,14 +437,26 @@ destroy_sensitive_data(void)
|
|
|
4369a3 |
|
|
|
4369a3 |
/* Demote private to public keys for network child */
|
|
|
4369a3 |
void
|
|
|
4369a3 |
-demote_sensitive_data(void)
|
|
|
4369a3 |
+demote_sensitive_data(struct ssh *ssh)
|
|
|
4369a3 |
{
|
|
|
f5835d |
struct sshkey *tmp;
|
|
|
f5835d |
u_int i;
|
|
|
f5835d |
int r;
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
+ pid_t pid;
|
|
|
f5835d |
+ uid_t uid;
|
|
|
f5835d |
|
|
|
f5835d |
+ pid = getpid();
|
|
|
f5835d |
+ uid = getuid();
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
for (i = 0; i < options.num_host_key_files; i++) {
|
|
|
f5835d |
if (sensitive_data.host_keys[i]) {
|
|
|
f5835d |
+ char *fp;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ if (sshkey_is_private(sensitive_data.host_keys[i]))
|
|
|
f5835d |
+ fp = sshkey_fingerprint(sensitive_data.host_keys[i], options.fingerprint_hash, SSH_FP_HEX);
|
|
|
f5835d |
+ else
|
|
|
f5835d |
+ fp = NULL;
|
|
|
4369a3 |
if ((r = sshkey_from_private(
|
|
|
4369a3 |
sensitive_data.host_keys[i], &tmp)) != 0)
|
|
|
4369a3 |
fatal("could not demote host %s key: %s",
|
|
|
4369a3 |
@@ -415,6 +464,12 @@ demote_sensitive_data(void)
|
|
|
4369a3 |
ssh_err(r));
|
|
|
4369a3 |
sshkey_free(sensitive_data.host_keys[i]);
|
|
|
f5835d |
sensitive_data.host_keys[i] = tmp;
|
|
|
f5835d |
+ if (fp != NULL) {
|
|
|
f5835d |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
4369a3 |
+ audit_destroy_sensitive_data(ssh, fp, pid, uid);
|
|
|
f5835d |
+#endif
|
|
|
f5835d |
+ free(fp);
|
|
|
f5835d |
+ }
|
|
|
f5835d |
}
|
|
|
f5835d |
/* Certs do not need demotion */
|
|
|
f5835d |
}
|
|
|
4369a3 |
@@ -442,7 +497,7 @@ reseed_prngs(void)
|
|
|
4369a3 |
}
|
|
|
4369a3 |
|
|
|
4369a3 |
static void
|
|
|
4369a3 |
-privsep_preauth_child(void)
|
|
|
4369a3 |
+privsep_preauth_child(struct ssh *ssh)
|
|
|
4369a3 |
{
|
|
|
4369a3 |
gid_t gidset[1];
|
|
|
4369a3 |
|
|
|
4369a3 |
@@ -457,7 +512,7 @@ privsep_preauth_child(void)
|
|
|
4369a3 |
reseed_prngs();
|
|
|
4369a3 |
|
|
|
4369a3 |
/* Demote the private keys to public keys. */
|
|
|
4369a3 |
- demote_sensitive_data();
|
|
|
4369a3 |
+ demote_sensitive_data(ssh);
|
|
|
4369a3 |
|
|
|
4369a3 |
#ifdef WITH_SELINUX
|
|
|
4369a3 |
sshd_selinux_change_privsep_preauth_context();
|
|
|
4369a3 |
@@ -496,7 +551,7 @@ privsep_preauth(struct ssh *ssh)
|
|
|
f5835d |
|
|
|
f5835d |
if (use_privsep == PRIVSEP_ON)
|
|
|
f5835d |
box = ssh_sandbox_init(pmonitor);
|
|
|
f5835d |
- pid = fork();
|
|
|
f5835d |
+ pmonitor->m_pid = pid = fork();
|
|
|
f5835d |
if (pid == -1) {
|
|
|
f5835d |
fatal("fork of unprivileged child failed");
|
|
|
f5835d |
} else if (pid != 0) {
|
|
|
4369a3 |
@@ -542,7 +597,7 @@ privsep_preauth(struct ssh *ssh)
|
|
|
4369a3 |
/* Arrange for logging to be sent to the monitor */
|
|
|
4369a3 |
set_log_handler(mm_log_handler, pmonitor);
|
|
|
4369a3 |
|
|
|
4369a3 |
- privsep_preauth_child();
|
|
|
4369a3 |
+ privsep_preauth_child(ssh);
|
|
|
4369a3 |
setproctitle("%s", "[net]");
|
|
|
4369a3 |
if (box != NULL)
|
|
|
4369a3 |
ssh_sandbox_child(box);
|
|
|
4369a3 |
@@ -594,7 +649,7 @@ privsep_postauth(struct ssh *ssh, Authct
|
|
|
4369a3 |
set_log_handler(mm_log_handler, pmonitor);
|
|
|
4369a3 |
|
|
|
4369a3 |
/* Demote the private keys to public keys. */
|
|
|
4369a3 |
- demote_sensitive_data();
|
|
|
4369a3 |
+ demote_sensitive_data(ssh);
|
|
|
4369a3 |
|
|
|
4369a3 |
reseed_prngs();
|
|
|
4369a3 |
|
|
|
4369a3 |
@@ -1057,7 +1112,7 @@ server_listen(void)
|
|
|
4369a3 |
* from this function are in a forked subprocess.
|
|
|
4369a3 |
*/
|
|
|
4369a3 |
static void
|
|
|
4369a3 |
-server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
|
|
|
4369a3 |
+server_accept_loop(struct ssh *ssh, int *sock_in, int *sock_out, int *newsock, int *config_s)
|
|
|
4369a3 |
{
|
|
|
4369a3 |
fd_set *fdset;
|
|
|
4369a3 |
int i, j, ret, maxfd;
|
|
|
4369a3 |
@@ -1112,6 +1167,7 @@ server_accept_loop(int *sock_in, int *so
|
|
|
f5835d |
if (received_sigterm) {
|
|
|
f5835d |
logit("Received signal %d; terminating.",
|
|
|
f5835d |
(int) received_sigterm);
|
|
|
4369a3 |
+ destroy_sensitive_data(ssh, 0);
|
|
|
f5835d |
close_listen_socks();
|
|
|
f5835d |
if (options.pid_file != NULL)
|
|
|
f5835d |
unlink(options.pid_file);
|
|
|
4369a3 |
@@ -1978,7 +2034,7 @@ main(int ac, char **av)
|
|
|
4369a3 |
#endif
|
|
|
4369a3 |
|
|
|
4369a3 |
/* Accept a connection and return in a forked child */
|
|
|
4369a3 |
- server_accept_loop(&sock_in, &sock_out,
|
|
|
4369a3 |
+ server_accept_loop(ssh, &sock_in, &sock_out,
|
|
|
4369a3 |
&newsock, config_s);
|
|
|
4369a3 |
}
|
|
|
4369a3 |
|
|
|
4369a3 |
@@ -2222,6 +2278,9 @@ main(int ac, char **av)
|
|
|
f5835d |
do_authenticated(ssh, authctxt);
|
|
|
f5835d |
|
|
|
f5835d |
/* The connection has been terminated. */
|
|
|
4369a3 |
+ packet_destroy_all(ssh, 1, 1);
|
|
|
4369a3 |
+ destroy_sensitive_data(ssh, 1);
|
|
|
f5835d |
+
|
|
|
4369a3 |
ssh_packet_get_bytes(ssh, &ibytes, &obytes);
|
|
|
f5835d |
verbose("Transferred: sent %llu, received %llu bytes",
|
|
|
f5835d |
(unsigned long long)obytes, (unsigned long long)ibytes);
|
|
|
4369a3 |
@@ -2401,6 +2460,15 @@ do_ssh2_kex(struct ssh *ssh)
|
|
|
4369a3 |
void
|
|
|
f5835d |
cleanup_exit(int i)
|
|
|
f5835d |
{
|
|
|
f5835d |
+ static int in_cleanup = 0;
|
|
|
f5835d |
+ int is_privsep_child;
|
|
|
f5835d |
+
|
|
|
f5835d |
+ /* cleanup_exit can be called at the very least from the privsep
|
|
|
f5835d |
+ wrappers used for auditing. Make sure we don't recurse
|
|
|
f5835d |
+ indefinitely. */
|
|
|
f5835d |
+ if (in_cleanup)
|
|
|
f5835d |
+ _exit(i);
|
|
|
f5835d |
+ in_cleanup = 1;
|
|
|
4369a3 |
if (the_active_state != NULL && the_authctxt != NULL) {
|
|
|
4369a3 |
do_cleanup(the_active_state, the_authctxt);
|
|
|
4369a3 |
if (use_privsep && privsep_is_preauth &&
|
|
|
4369a3 |
@@ -2414,9 +2482,16 @@ cleanup_exit(int i)
|
|
|
f5835d |
pmonitor->m_pid, strerror(errno));
|
|
|
f5835d |
}
|
|
|
f5835d |
}
|
|
|
f5835d |
+ is_privsep_child = use_privsep && pmonitor != NULL && pmonitor->m_pid == 0;
|
|
|
4369a3 |
+ if (sensitive_data.host_keys != NULL && the_active_state != NULL)
|
|
|
4369a3 |
+ destroy_sensitive_data(the_active_state, is_privsep_child);
|
|
|
4369a3 |
+ if (the_active_state != NULL)
|
|
|
4369a3 |
+ packet_destroy_all(the_active_state, 1, is_privsep_child);
|
|
|
f5835d |
#ifdef SSH_AUDIT_EVENTS
|
|
|
f5835d |
/* done after do_cleanup so it can cancel the PAM auth 'thread' */
|
|
|
4369a3 |
- if (the_active_state != NULL && (!use_privsep || mm_is_monitor()))
|
|
|
4369a3 |
+ if (the_active_state != NULL &&
|
|
|
4369a3 |
+ (the_authctxt == NULL || !the_authctxt->authenticated) &&
|
|
|
f5835d |
+ (!use_privsep || mm_is_monitor()))
|
|
|
4369a3 |
audit_event(the_active_state, SSH_CONNECTION_ABANDON);
|
|
|
f5835d |
#endif
|
|
|
f5835d |
_exit(i);
|
|
|
4369a3 |
diff -up openssh/sshkey.c.audit openssh/sshkey.c
|
|
|
4369a3 |
--- openssh/sshkey.c.audit 2019-04-03 17:02:20.657885510 +0200
|
|
|
4369a3 |
+++ openssh/sshkey.c 2019-04-03 17:02:20.718886088 +0200
|
|
|
4369a3 |
@@ -331,6 +331,38 @@ sshkey_type_is_valid_ca(int type)
|
|
|
f5835d |
}
|
|
|
f5835d |
|
|
|
f5835d |
int
|
|
|
f5835d |
+sshkey_is_private(const struct sshkey *k)
|
|
|
f5835d |
+{
|
|
|
f5835d |
+ switch (k->type) {
|
|
|
f5835d |
+#ifdef WITH_OPENSSL
|
|
|
f5835d |
+ case KEY_RSA_CERT:
|
|
|
4369a3 |
+ case KEY_RSA: {
|
|
|
4369a3 |
+ const BIGNUM *d;
|
|
|
4369a3 |
+ RSA_get0_key(k->rsa, NULL, NULL, &d);
|
|
|
4369a3 |
+ return d != NULL;
|
|
|
4369a3 |
+ }
|
|
|
f5835d |
+ case KEY_DSA_CERT:
|
|
|
4369a3 |
+ case KEY_DSA: {
|
|
|
4369a3 |
+ const BIGNUM *priv_key;
|
|
|
4369a3 |
+ DSA_get0_key(k->dsa, NULL, &priv_key);
|
|
|
4369a3 |
+ return priv_key != NULL;
|
|
|
4369a3 |
+ }
|
|
|
f5835d |
+#ifdef OPENSSL_HAS_ECC
|
|
|
f5835d |
+ case KEY_ECDSA_CERT:
|
|
|
f5835d |
+ case KEY_ECDSA:
|
|
|
f5835d |
+ return EC_KEY_get0_private_key(k->ecdsa) != NULL;
|
|
|
f5835d |
+#endif /* OPENSSL_HAS_ECC */
|
|
|
f5835d |
+#endif /* WITH_OPENSSL */
|
|
|
f5835d |
+ case KEY_ED25519_CERT:
|
|
|
f5835d |
+ case KEY_ED25519:
|
|
|
f5835d |
+ return (k->ed25519_pk != NULL);
|
|
|
f5835d |
+ default:
|
|
|
f5835d |
+ /* fatal("key_is_private: bad key type %d", k->type); */
|
|
|
f5835d |
+ return 0;
|
|
|
f5835d |
+ }
|
|
|
f5835d |
+}
|
|
|
f5835d |
+
|
|
|
f5835d |
+int
|
|
|
f5835d |
sshkey_is_cert(const struct sshkey *k)
|
|
|
f5835d |
{
|
|
|
f5835d |
if (k == NULL)
|
|
|
4369a3 |
diff -up openssh/sshkey.h.audit openssh/sshkey.h
|
|
|
4369a3 |
--- openssh/sshkey.h.audit 2019-04-03 17:02:20.657885510 +0200
|
|
|
4369a3 |
+++ openssh/sshkey.h 2019-04-03 17:02:20.718886088 +0200
|
|
|
4369a3 |
@@ -148,6 +148,7 @@ u_int sshkey_size(const struct sshkey
|
|
|
f5835d |
int sshkey_generate(int type, u_int bits, struct sshkey **keyp);
|
|
|
f5835d |
int sshkey_from_private(const struct sshkey *, struct sshkey **);
|
|
|
f5835d |
int sshkey_type_from_name(const char *);
|
|
|
f5835d |
+int sshkey_is_private(const struct sshkey *);
|
|
|
f5835d |
int sshkey_is_cert(const struct sshkey *);
|
|
|
f5835d |
int sshkey_type_is_cert(int);
|
|
|
f5835d |
int sshkey_type_plain(int);
|