起因是Jetty9默认把war包解压到了/tmp目录,有一天发现测试用的jsp页面不能访问了,发现是解压出来的目录被清空了,当时没有任何证据来找到罪魁祸首,所以就找到了audit。
先稍微看看http://www.cyberciti.biz/tips/linux-audit-files-to-see-who-made-changes-to-a-file.html,有了一定了解之后,安装运行,看看相关的manual。
man auditctl
To recursively watch a directory for changes (2 ways to express):
auditctl -w /etc/ -p wa
auditctl -a exit,always -F dir=/etc/ -F perm=wa
man ausearch
# ausearch -f /path/to/file
这是搜索某个文件的操作记录
建立监控
> auditctl -w /tmp/ -p wa
做一下测试:
> touch /tmp/test
> rm /tmp/test
> ausearch -f /tmp/
有结果了:
#---- time->Tue Jan 7 10:44:27 2014 type=PATH msg=audit(1389062667.570:200): item=1 name="/tmp/test" inode=811024 dev=ca:01 mode=0100644 ouid=0 ogid=0 rdev=00:00 type=PATH msg=audit(1389062667.570:200): item=0 name="/tmp/" inode=811009 dev=ca:01 mode=041777 ouid=0 ogid=0 rdev=00:00 type=CWD msg=audit(1389062667.570:200): cwd="/root" type=SYSCALL msg=audit(1389062667.570:200): arch=c000003e syscall=2 success=yes exit=3 a0=7fff5937f8f3 a1=941 a2=1b6 a3=7fff5937e280 items=2 ppid=32629 pid=1524 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts2 ses=3740 comm="touch" exe="/bin/touch" key=(null) #---- time->Tue Jan 7 10:46:01 2014 type=PATH msg=audit(1389062761.354:213): item=1 name="/tmp/test" inode=811024 dev=ca:01 mode=0100644 ouid=0 ogid=0 rdev=00:00 type=PATH msg=audit(1389062761.354:213): item=0 name="/tmp/" inode=811009 dev=ca:01 mode=041777 ouid=0 ogid=0 rdev=00:00 type=CWD msg=audit(1389062761.354:213): cwd="/root" type=SYSCALL msg=audit(1389062761.354:213): arch=c000003e syscall=263 success=yes exit=0 a0=ffffffffffffff9c a1=6ad0c0 a2=0 a3=7ffff1fb4740 items=2 ppid=32629 pid=1531 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts2 ses=3740 comm="rm" exe="/bin/rm" key=(null)布置完毕,等待下次作案。
过了一段时间,20140121上午,案情再现。
先用jps跟lsof找到目前jetty持有的临时目录:/tmp/jetty-0.0.0.0-9090-test.war-_-any-8756072411520154567.dir/。
# ausearch -f /tmp/jetty-0.0.0.0-9090-test.war-_-any-8756072411520154567.dir/ > ausearch.temp
发现只有两种类型的syscall,如果是目录,那syscall=84,如果是文件,那syscall=87,目录下的所有子目录跟文件都被操作过。
都是被tmpwatch操作的,man tmpwatch
tmpwatch - removes files which haven’t been accessed for a period of time
还不清楚syscall=84/87是什么意思,http://linux.die.net/include/asm/unistd.h给的意思不符合日志的情况:
#define __NR_oldlstat 84
#define __NR_swapon 87
在本地openSUSE上,/usr/include/asm/unistd_64.h
#define __NR_rmdir 84
#define __NR_unlink 87
在服务器CentOS 6上,/usr/include/asm/unistd_64.h
#define __NR_rmdir 84
__SYSCALL(__NR_rmdir, sys_rmdir)
#define __NR_unlink 87
__SYSCALL(__NR_unlink, sys_unlink)
man unlink(3p) : The unlink() function shall remove a link to a file.
就是被tmpwatch给删了,但是在进程里没有发现tmpwatch,crontab里也没有发现这个任务的配置,找到tmpwatch命令的使用 - Author: 云飛 - m114.org
# find /etc/ -name "tmpwatch*"
/etc/cron.daily/tmpwatch
原来在这
有两种方法可以解决上面的问题:(1)修改/etc/cron.daily/tmpwatch,增加-X '/tmp/jetty*'用来排除相关目录,(2)把Jetty9的工作目录换到别的地方。
一开始用的是方法1,找到方法2之后就换了。
No comments:
Post a Comment