Bugzilla – Attachment 800 Details for
Bug 125
add BSM audit support
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Use audit hooks for BSM auditting (still work in progress)
openssh-audit-bsm.patch (text/plain), 17.04 KB, created by
Darren Tucker
on 2005-02-03 00:43:56 AEDT
(
hide
)
Description:
Use audit hooks for BSM auditting (still work in progress)
Filename:
MIME Type:
Creator:
Darren Tucker
Created:
2005-02-03 00:43:56 AEDT
Size:
17.04 KB
patch
obsolete
>Index: LICENCE >=================================================================== >RCS file: /usr/local/src/security/openssh/cvs/openssh_cvs/LICENCE,v >retrieving revision 1.17 >diff -u -p -r1.17 LICENCE >--- LICENCE 5 Nov 2004 09:00:03 -0000 1.17 >+++ LICENCE 30 Jan 2005 12:15:38 -0000 >@@ -203,6 +203,7 @@ OpenSSH contains no GPL code. > Wayne Schroeder > William Jones > Darren Tucker >+ Sun Microsystems > > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions >Index: Makefile.in >=================================================================== >RCS file: /usr/local/src/security/openssh/cvs/openssh_cvs/Makefile.in,v >retrieving revision 1.268 >diff -u -p -r1.268 Makefile.in >--- Makefile.in 2 Feb 2005 13:20:53 -0000 1.268 >+++ Makefile.in 2 Feb 2005 13:27:40 -0000 >@@ -85,7 +85,8 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passw > monitor_mm.o monitor.o monitor_wrap.o kexdhs.o kexgexs.o \ > auth-krb5.o \ > auth2-gss.o gss-serv.o gss-serv-krb5.o \ >- loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o audit.o >+ loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \ >+ audit.o audit-bsm.o > > MANPAGES = scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-rand-helper.8.out ssh-keysign.8.out sshd_config.5.out ssh_config.5.out > MANPAGES_IN = scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-rand-helper.8 ssh-keysign.8 sshd_config.5 ssh_config.5 >Index: README.platform >=================================================================== >RCS file: /usr/local/src/security/openssh/cvs/openssh_cvs/README.platform,v >retrieving revision 1.2 >diff -u -p -r1.2 README.platform >--- README.platform 23 Apr 2004 08:57:13 -0000 1.2 >+++ README.platform 30 Jan 2005 12:15:38 -0000 >@@ -23,8 +23,20 @@ openssl-devel, zlib, minres, minires-dev > > Solaris > ------- >-Currently, sshd does not support BSM auditting. This can show up as errors >-when editting cron entries via crontab. See. >-http://bugzilla.mindrot.org/show_bug.cgi?id=125 >+If you enable BSM auditing on Solaris, you need to update audit_event(4) >+for praudit(1m) to give sensible output. The following line needs to be >+added to /etc/security/audit_event: >+ >+ 32800:AUE_openssh:OpenSSH login:lo >+ >+If the contrib/buildpkg.sh script is used, the included postinstall >+script will add the line for you. >+ >+The BSM audit event range available for third party TCB applications is >+32768 - 65535. Event number 32800 has been choosen for AUE_openssh. >+There is no official registry of 3rd party event numbers, so if this >+number is already in use on your system, you may change it at build time >+by configure'ing --with-cflags=-DAUE_openssh=32801 then rebuilding. >+ > > $Id: README.platform,v 1.2 2004/04/23 08:57:13 dtucker Exp $ >Index: audit-bsm.c >=================================================================== >RCS file: audit-bsm.c >diff -N audit-bsm.c >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ audit-bsm.c 2 Feb 2005 13:31:46 -0000 >@@ -0,0 +1,331 @@ >+/* $Id$ */ >+ >+/* >+ * TODO >+ * >+ * - deal with overlap between this and sys_auth_allowed_user >+ * sys_auth_record_login and record_failed_login. >+ * >+ * - check the HAVE_GETAUDIT_ADDR replacement code for IPv6 safety. >+ */ >+ >+/* >+ * Copyright 1988-2002 Sun Microsystems, Inc. All rights reserved. >+ * Use is subject to license terms. >+ * >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR >+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES >+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. >+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, >+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT >+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, >+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY >+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF >+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ * >+ */ >+/* #pragma ident "@(#)bsmaudit.c 1.1 01/09/17 SMI" */ >+ >+#include "includes.h" >+#if defined(USE_BSM_AUDIT) >+ >+#ifndef AUE_openssh >+# define AUE_openssh 32800 >+#endif >+ >+#include "ssh.h" >+#include "log.h" >+#include "auth.h" >+#include "xmalloc.h" >+#include "audit-bsm.h" >+ >+#ifndef HAVE_GETTEXT >+# define gettext(a) (a) >+#endif >+ >+extern Authctxt *the_authctxt; >+ >+static int sav_port = -1; >+static uint32_t sav_machine[4] = { 0,0,0,0}; >+static uint32_t sav_iptype = 0; >+static char sav_host[MAXHOSTNAMELEN]; >+static char *sav_cmd = NULL; >+ >+void >+audit_connection_from(const char *host, int port) >+{ >+ int i; >+#if !defined(HAVE_GETAUDIT_ADDR) >+ in_addr_t ia; >+#endif >+ >+ if (cannot_audit(0)) >+ return; >+ >+ /* save port */ >+ sav_port = port; >+ debug3("BSM audit: sav_port=%d", sav_port); >+ >+ /* save host */ >+ (void) strlcpy(sav_host, host, sizeof(sav_host)); >+ debug3("BSM audit: sav_host=%s", sav_host); >+ memset(sav_machine, 0, sizeof(sav_machine)); >+#if defined(HAVE_GETAUDIT_ADDR) >+ (void) aug_get_machine(sav_host, &sav_machine[0], &sav_iptype); >+ debug3("BSM audit: sav_iptype=%ld", (long)sav_iptype); >+#else >+ ia = inet_addr(host); >+ memcpy(&sav_machine[0], &ia, sizeof(sav_machine[0])); >+ sav_iptype = 0; /* not used, but just in case */ >+#endif >+ for (i = 0; i < sizeof(sav_machine) / sizeof(sav_machine[0]); i++) { >+ debug3("BSM audit: sav_machine[%d]=%08lx", >+ i, (long)sav_machine[i]); >+ } >+} >+ >+void >+audit_run_command(const char *command) >+{ >+ if (cannot_audit(0)) >+ return; >+ >+ if (sav_cmd != NULL) { >+ free(sav_cmd); >+ sav_cmd = NULL; >+ } >+ sav_cmd = xstrdup(command); >+ debug3("BSM audit: sav_cmd=%s", sav_cmd); >+} >+ >+void >+audit_session_open(const char *ttyn) >+{ >+ /* not implemented */ >+} >+ >+void >+audit_session_close(const char *ttyn) >+{ >+ /* not implemented */ >+} >+ >+static void >+bsm_audit_record(int typ, char *string, au_event_t event_no) >+{ >+ int ad, rc, sel; >+ uid_t uid = -1; >+ gid_t gid = -1; >+ pid_t pid = getpid(); >+ AuditInfoTermID tid; >+ >+ if (the_authctxt->valid) { >+ uid = the_authctxt->pw->pw_uid; >+ gid = the_authctxt->pw->pw_gid; >+ } >+ get_terminal_id(&tid); >+ >+ if (typ == 0) >+ rc = 0; >+ else >+ rc = -1; >+ >+ sel = selected(the_authctxt->user, uid, event_no, rc); >+ debug3("BSM audit: typ %d rc %d \"%s\"", typ, rc, string); >+ if (!sel) >+ return; >+ >+ ad = au_open(); >+ >+ (void) au_write(ad, AUToSubjectFunc(uid, uid, gid, uid, gid, >+ pid, pid, &tid)); >+ (void) au_write(ad, au_to_text(string)); >+ if (sav_cmd != NULL) { >+ (void) au_write(ad, au_to_text(sav_cmd)); >+ } >+ (void) au_write(ad, AUToReturnFunc(typ, rc)); >+ >+ rc = au_close(ad, AU_TO_WRITE, event_no); >+ if (rc < 0) { >+ error("BSM audit: %s failed to write \"%s\" record: %s", >+ __func__, string, strerror(errno)); >+ } >+} >+ >+static void >+bsm_audit_session_setup(void) >+{ >+ int rc; >+ struct AuditInfoStruct info; >+ au_mask_t mask; >+ struct AuditInfoStruct now; >+ >+ if (the_authctxt->valid) >+ info.ai_auid = the_authctxt->pw->pw_uid; >+ else >+ info.ai_auid = -1; >+ info.ai_asid = getpid(); >+ mask.am_success = 0; >+ mask.am_failure = 0; >+ >+ (void) au_user_mask(the_authctxt->user, &mask); >+ >+ info.ai_mask.am_success = mask.am_success; >+ info.ai_mask.am_failure = mask.am_failure; >+ >+ /* see if terminal id already set */ >+ if (GetAuditFunc(&now, sizeof(now)) < 0) { >+ error("BSM audit: %s: %s failed: %s", __func__, >+ GetAuditFuncText, strerror(errno)); >+ } >+ >+ debug("%s: calling get_terminal_id", __func__); >+ get_terminal_id(&(info.ai_termid)); >+ >+ rc = SetAuditFunc(&info, sizeof(info)); >+ if (rc < 0) { >+ error("BSM audit: %s: %s failed: %s", __func__, >+ SetAuditFuncText, strerror(errno)); >+ } >+} >+ >+ >+static void >+get_terminal_id(AuditInfoTermID *tid) >+{ >+#if defined(HAVE_GETAUDIT_ADDR) >+ tid->at_port = sav_port; >+ tid->at_type = sav_iptype; >+ tid->at_addr[0] = sav_machine[0]; >+ tid->at_addr[1] = sav_machine[1]; >+ tid->at_addr[2] = sav_machine[2]; >+ tid->at_addr[3] = sav_machine[3]; >+#else >+ tid->port = sav_port; >+ tid->machine = sav_machine[0]; >+#endif >+} >+ >+static void >+bsm_audit_bad_login(const char *what) >+{ >+ char textbuf[BSM_TEXTBUFSZ]; >+ >+ if (the_authctxt->valid) { >+ (void) snprintf(textbuf, sizeof (textbuf), >+ gettext("invalid %s for user %s"), >+ what, the_authctxt->user); >+ bsm_audit_record(4, textbuf, AUE_openssh); >+ } else { >+ (void) snprintf(textbuf, sizeof (textbuf), >+ gettext("invalid user name \"%s\""), >+ the_authctxt->user); >+ bsm_audit_record(3, textbuf, AUE_openssh); >+ } >+} >+ >+void >+audit_event(ssh_audit_event_t event) >+{ >+ char textbuf[BSM_TEXTBUFSZ]; >+ static int logged_in = 0; >+ const char *user = the_authctxt ? the_authctxt->user : "(unknown user)"; >+ >+ if (cannot_audit(0)) >+ return; >+ >+ switch(event) { >+ case AUTH_SUCCESS: >+ logged_in = 1; >+ bsm_audit_session_setup(); >+ snprintf(textbuf, sizeof(textbuf), >+ gettext("successful login %s"), user); >+ bsm_audit_record(0, textbuf, AUE_openssh); >+ break; >+ >+ case CONNECTION_CLOSE: >+ /* >+ * We can also get a close event if the user attempted auth >+ * but never succeeded. >+ */ >+ if (logged_in) { >+ snprintf(textbuf, sizeof(textbuf), >+ gettext("sshd logout %s"), the_authctxt->user); >+ bsm_audit_record(0, textbuf, AUE_logout); >+ } else { >+ debug("%s: connection closed without authentication", >+ __func__); >+ } >+ break; >+ >+ case NOLOGIN: >+ bsm_audit_record(1, >+ gettext("logins disabled by /etc/nologin"), AUE_openssh); >+ break; >+ >+ case LOGIN_EXCEED_MAXTRIES: >+ snprintf(textbuf, sizeof(textbuf), >+ gettext("too many tries for user %s"), the_authctxt->user); >+ bsm_audit_record(1, textbuf, AUE_openssh); >+ break; >+ >+ case LOGIN_ROOT_DENIED: >+ bsm_audit_record(2, gettext("not_console"), AUE_openssh); >+ break; >+ >+ case AUTH_FAIL_PASSWD: >+ bsm_audit_bad_login("password"); >+ break; >+ >+ case AUTH_FAIL_KBDINT: >+ bsm_audit_bad_login("interactive password entry"); >+ break; >+ >+#if 0 >+ case AUTH_FAILED: >+ bsm_audit_bad_login("authorization"); >+ break; >+#endif >+ >+ default: >+ debug("%s: unhandled event %d", __func__, event); >+ } >+} >+ >+static int >+selected(char *nam, uid_t uid, au_event_t event, int sf) >+{ >+ int rc, sorf; >+ char naflags[512]; >+ struct au_mask mask; >+ >+ mask.am_success = mask.am_failure = 0; >+ if (uid < 0) { >+ rc = getacna(naflags, 256); /* get non-attrib flags */ >+ if (rc == 0) >+ (void) getauditflagsbin(naflags, &mask); >+ } else { >+ rc = au_user_mask(nam, &mask); >+ } >+ >+ if (sf == 0) { >+ sorf = AU_PRS_SUCCESS; >+ } else { >+ sorf = AU_PRS_FAILURE; >+ } >+ rc = au_preselect(event, &mask, sorf, AU_PRS_REREAD); >+ >+ return rc; >+} >+#endif /* BSM */ >Index: audit-bsm.h >=================================================================== >RCS file: audit-bsm.h >diff -N audit-bsm.h >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ audit-bsm.h 30 Jan 2005 13:01:05 -0000 >@@ -0,0 +1,98 @@ >+/* $Id$ */ >+ >+/* >+ * Copyright 1988-2002 Sun Microsystems, Inc. All rights reserved. >+ * Use is subject to license terms. >+ * >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR >+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES >+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. >+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, >+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT >+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, >+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY >+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF >+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ * >+ */ >+/* #pragma ident "@(#)bsmaudit.c 1.1 01/09/17 SMI" */ >+ >+#include "includes.h" >+#ifdef USE_BSM_AUDIT >+ >+#define AUE_openssh 32800 >+ >+#include <bsm/audit.h> >+#include <bsm/libbsm.h> >+#include <bsm/audit_uevents.h> >+#include <bsm/audit_record.h> >+#include <locale.h> >+ >+#if defined(HAVE_GETAUDIT_ADDR) >+#define AuditInfoStruct auditinfo_addr >+#define AuditInfoTermID au_tid_addr_t >+#define GetAuditFunc(a,b) getaudit_addr((a),(b)) >+#define GetAuditFuncText "getaudit_addr" >+#define SetAuditFunc(a,b) setaudit_addr((a),(b)) >+#define SetAuditFuncText "setaudit_addr" >+#define AUToSubjectFunc au_to_subject_ex >+#define AUToReturnFunc(a,b) au_to_return32((a), (int32_t)(b)) >+#else >+#define AuditInfoStruct auditinfo >+#define AuditInfoTermID au_tid_t >+#define GetAuditFunc(a,b) getaudit(a) >+#define GetAuditFuncText "getaudit" >+#define SetAuditFunc(a,b) setaudit(a) >+#define SetAuditFuncText "setaudit" >+#define AUToSubjectFunc au_to_subject >+#define AUToReturnFunc(a,b) au_to_return((a), (u_int)(b)) >+#endif >+ >+static void bsm_audit_record(int typ, char *string, au_event_t event_no); >+static void bsm_audit_session_setup(void); >+static int selected(char *nam, uid_t uid, au_event_t event, int sf); >+ >+static void get_terminal_id(AuditInfoTermID *tid); >+ >+extern int cannot_audit(int); >+extern void aug_init(void); >+extern dev_t aug_get_port(void); >+extern int aug_get_machine(char *, u_int32_t *, u_int32_t *); >+extern void aug_save_auid(au_id_t); >+extern void aug_save_uid(uid_t); >+extern void aug_save_euid(uid_t); >+extern void aug_save_gid(gid_t); >+extern void aug_save_egid(gid_t); >+extern void aug_save_pid(pid_t); >+extern void aug_save_asid(au_asid_t); >+extern void aug_save_tid(dev_t, unsigned int); >+extern void aug_save_tid_ex(dev_t, u_int32_t *, u_int32_t); >+extern int aug_save_me(void); >+extern int aug_save_namask(void); >+extern void aug_save_event(au_event_t); >+extern void aug_save_sorf(int); >+extern void aug_save_text(char *); >+extern void aug_save_text1(char *); >+extern void aug_save_text2(char *); >+extern void aug_save_na(int); >+extern void aug_save_user(char *); >+extern void aug_save_path(char *); >+extern int aug_save_policy(void); >+extern void aug_save_afunc(int (*)(int)); >+extern int aug_audit(void); >+extern int aug_na_selected(void); >+extern int aug_selected(void); >+extern int aug_daemon_session(void); >+ >+#endif >Index: configure.ac >=================================================================== >RCS file: /usr/local/src/security/openssh/cvs/openssh_cvs/configure.ac,v >retrieving revision 1.237 >diff -u -p -r1.237 configure.ac >--- configure.ac 2 Feb 2005 12:30:25 -0000 1.237 >+++ configure.ac 2 Feb 2005 13:26:13 -0000 >@@ -877,6 +877,21 @@ AC_ARG_WITH(libedit, > fi ] > ) > >+BSM_MSG="no" >+AC_ARG_WITH(bsmaudit, >+ [ --with-bsmaudit Enable BSM audit support], >+ [ if test "x$withval" != "no" ; then >+ dnl Checks for headers, libs and functions >+ AC_CHECK_HEADERS(bsm/audit.h, [], >+ [AC_MSG_ERROR(BSM enabled and bsm/audit.h not found)]) >+ AC_CHECK_LIB(bsm, getaudit, [], >+ [AC_MSG_ERROR(BSM enabled and required library not found)]) >+ AC_CHECK_FUNCS(getaudit getaudit_addr gettext, [], >+ [AC_MSG_ERROR(BSM enabled and required function not found)]) >+ AC_DEFINE(USE_BSM_AUDIT, [], [Use BSM auditting]) >+ fi ] >+) >+ > dnl Checks for library functions. Please keep in alphabetical order > AC_CHECK_FUNCS(\ > arc4random __b64_ntop b64_ntop __b64_pton b64_pton bcopy \ >@@ -1779,6 +1794,8 @@ fi > TYPE_SOCKLEN_T > > AC_CHECK_TYPES(sig_atomic_t,,,[#include <signal.h>]) >+ >+AC_CHECK_TYPES(in_addr_t,,,[#include <netinet/in.h>]) > > AC_CACHE_CHECK([for size_t], ac_cv_have_size_t, [ > AC_TRY_COMPILE( >Index: defines.h >=================================================================== >RCS file: /usr/local/src/security/openssh/cvs/openssh_cvs/defines.h,v >retrieving revision 1.118 >diff -u -p -r1.118 defines.h >--- defines.h 2 Feb 2005 12:30:25 -0000 1.118 >+++ defines.h 2 Feb 2005 13:26:13 -0000 >@@ -288,6 +288,10 @@ struct sockaddr_un { > }; > #endif /* HAVE_SYS_UN_H */ > >+#ifndef HAVE_IN_ADDR_T >+typedef u_int32_t in_addr_t; >+#endif >+ > #if defined(BROKEN_SYS_TERMIO_H) && !defined(_STRUCT_WINSIZE) > #define _STRUCT_WINSIZE > struct winsize { >@@ -528,6 +532,11 @@ struct winsize { > > #ifndef GETPGRP_VOID > # define getpgrp() getpgrp(0) >+#endif >+ >+#ifdef USE_BSM_AUDIT >+# define AUDIT_EVENTS >+# define CUSTOM_AUDIT_EVENTS > #endif > > /* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 125
:
131
|
192
|
355
|
438
|
500
|
560
|
618
|
619
|
647
|
753
|
754
|
755
|
756
|
793
|
794
|
795
|
796
|
800
|
804
|
820
|
826
|
845
|
846