本文会介绍将Linux history 记录发往远程Rsyslog 服务器的2种方法。
0×01. 方法1,修改bash源码,使其支持将history历史记录发往远程Rsyslog 服务器
从bash4.1 版本开始,bash开始支持Rsyslog,所以我们需要下载bash4.1以后版本,这里以bash4.4为例
bash源码下载地址: https://ftp.gnu.org/gnu/bash/
共计需要修改两处源码:
1) 先修改bashhist.c
从源码文件名字也可以看出这个源码文件和linux history记录处理有关
748 #if defined (SYSLOG_HISTORY)
749 #define SYSLOG_MAXLEN 600
750
751 extern char *shell_name;
752
753 #ifndef OPENLOG_OPTS
754 #define OPENLOG_OPTS 0
755 #endif
756
757 void
758 bash_syslog_history (line)
759 const char *line;
760 {
761 char trunc[SYSLOG_MAXLEN];
762 static int first = 1;
763
764 if (first)
765 {
766 openlog (shell_name, OPENLOG_OPTS, SYSLOG_FACILITY);
767 first = 0;
768 }
769
770 if (strlen(line) < SYSLOG_MAXLEN)
771 syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY: PID=%d UID=%d User=%s CMD=%s", getpid(), current_user.uid, current_user.user_name, line);
772 else
773 {
774 strncpy (trunc, line, SYSLOG_MAXLEN);
775 trunc[SYSLOG_MAXLEN - 1] = '\0';
776 syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY (TRUNCATED): PID=%d UID=%d User=%s CMD=%s", getpid(), current_user.uid, current_user.user_name, trunc);
777 }
778 }
779 #endif
需要修改771行和776行,修改内容,如上所示
其