免费教程_免费网赚教程_破解版软件-寂涯网络学习基地

当前位置: 主页 > 系统综合 > linux > 简单构建Linux操作审计系统(2)

简单构建Linux操作审计系统(2)

时间:2011-11-06 13:59来源:未知 整理:寂涯网络 点击:


载回来看了一下Changelog,找到如下:
但是,这个方法非常容易被发现和被绕过。用set命令就可以看到PROMPT_COMMAND,而
且现在的黑客都非常聪明,上来就执行unset HISTORY HISTFILE HISTSAVE HISTZONE HISTORY
HISTLOG; export HISTFILE=/dev/null; export HISTSIZE=0; export HISTFILESIZE=0 这
样的命令防止执行的命令记录到history,那上面这个方法自然就失效了。
[root@linuxtest tmp]# tail -f /var/log/messages
Apr 18 15:27:49 linuxtest logger:    19  set
Apr 18 15:31:58 linuxtest logger:    20  ll
Apr 18 15:32:00 linuxtest logger:    21  cd /tmp
Apr 18 15:32:00 linuxtest logger:    22  ls
Apr 18 15:32:21 linuxtest logger:    23  echo "zsf test"
  
这样当zsf用户登录使用之后,其操作均会被记录到syslog,简单测试的效果如下:
 
[root@linuxtest tmp]# tail -f /var/log/messages
Apr 18 15:27:49 linuxtest logger:    19  set
Apr 18 15:31:58 linuxtest logger:    20  ll
Apr 18 15:32:00 linuxtest logger:    21  cd /tmp
Apr 18 15:32:00 linuxtest logger:    22  ls
Apr 18 15:32:21 linuxtest logger:    23  echo "zsf test"
 
config-top.h
 - new define SYSLOG_HISTORY, disabled by default
config-bot.h
 -  if HAVE_SYSLOG or HAVE_SYSLOG_H are not defined, undef SYSLOG_HISTORY
bashhist.c
 - if SYSLOG_HISTORY is defined, call bash_syslog_history with the
   line added to the history in bash_add_history.
 - new function, bash_syslog_history(line), sends line to syslog at
   user.info.  The line is truncated to send no more than 600
   (SYSLOG_MAXLEN) bytes to syslog. Feature requested by many, and
   required by some national laws
看来只需改一个头文件config-top.h就好啊,如下:
/* Define if you want each line saved to the history list in bashhist.c:
   bash_add_history() to be sent to syslog(). */
/* #define SYSLOG_HISTORY */
#if defined (SYSLOG_HISTORY)
#  define SYSLOG_FACILITY LOG_USER
#  define SYSLOG_LEVEL LOG_INFO
#endif
只需将#define SYSLOG_HISTORY 这一行两边的注释去掉就可以了,改完之后开始
进行编译以及安装,命令:
./configure --prefix=/usr/local/xbash
make
make install
改完之后,我们将要记录的用户的bash改为新的bash,如下:
zsf:x:500:500::/home/zsf:/usr/local/xbash/bin/bash

这样当zsf用户登录使用之后,其操作均会被记录到syslog,简单测试的效果如下: 
而为了能在日志中更好的跟踪用户,比如一个用户以 a 用户登录然后 su,那 uid 就变
,但我们可以通过 sid 知道是哪个用户在操作,我们将源代码中关于将 history 调用
slog 函数的地方进行适当修改,如下:
 
Apr  2 21:49:49 localhost -bash: HISTORY: PID=2732 UID=500 w
Apr  2 21:49:52 localhost -bash: HISTORY: PID=2732 UID=500 history
Apr  2 21:54:07 localhost -bash: HISTORY: PID=2732 UID=500 pwd
Apr  2 21:54:10 localhost -bash: HISTORY: PID=2732 UID=500 cd /tmp
Apr  2 21:54:15 localhost -bash: HISTORY: PID=2732 UID=500 echo "fuck"
Apr  2 21:54:29 localhost  -bash: HISTORY: PID=2732 UID=500 echo
"fuck" >a.log
Apr  2 21:54:32 localhost -bash: HISTORY: PID=2732 UID=500 cat a.log
Apr  2 21:54:51 localhost  -bash: HISTORY: PID=2732 UID=500 ping
www.baidu.com
Apr  2 21:55:00 localhost  -bash: HISTORY: PID=2732 UID=500 ssh
ssh.testssh.com
Apr  2 21:55:11 localhost -bash: HISTORY: PID=2732 UID=500 asdfadsf
syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY: PID=%d PPID=%d SID=%d
User=%s CMD=%s", getpid(), getppid(), getsid(getpid()),
current_user.user_name, line);
else
{
strncpy (trunc, line, SYSLOG_MAXLEN);
trunc[SYSLOG_MAXLEN - 1] = '\0';
syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY (TRUNCATED): PID=%d
PPID=%d SID=%d User=%s CMD=%s", getpid(), getppid(), getsid(getpid()),
current_user.user_name, trunc);
}

就可以得到如下的效果:
  
Apr  2 22:11:08 localhost -bash: HISTORY: PID=14048 PPID=14047 SID=14048
User=zsf CMD=ping aaa
Apr  2 22:11:13 localhost -bash: HISTORY: PID=14048 PPID=14047 SID=14048

本页地址 http://www.jybase.net/linux/20111106576.html

百度搜索更多

谷歌搜索更多

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------

评价:
昵称: 验证码:点击我更换图片
推荐内容
赞助商
赞助商


关于本站免责声明视频更新google百度地图视频地图RRS订阅

如有什么问题请在本站留言,或发邮件到 hxt167#foxmail.com