我想获取在Linux启动过程中使用的文件列表。我们正在开发基于RHEL 6.4的受保护企业系统。指定文件的完整性将通过特殊硬件检查。
因此,问题是-如何获取这些文件的列表(已解决的依赖关系来自不同的引导服务和守护程序)。
感谢RHEL的支持,发现了明确的解决方案。它基于systemtap内核模块的使用情况。从这里引用以避免链接腐烂。再次感谢您的所有建议:)
我什至无法想象systemtap甚至可以在初始化脚本之前启动并跟踪启动过程。我非常感谢Red Hat 支持和我个人Pushpendra Chavan在此完美工具方面的帮助(不幸的是,我不知道该方法确切属于开发人员-否则我会首先归功于他们)。
因此,我们需要创建两个简单的脚本:
bootinit.sh
:
#!/bin/sh
# Use tmpfs to collect data
/bin/echo "Mounting tmpfs to /tmp/stap/data"
/bin/mount -n -t tmpfs -o size=40M none /tmp/stap/data
# Start systemtap daemon & probe
/bin/echo "Loading bootprobe2.ko in the background. Pid is :"
/usr/bin/staprun \
/root/bootprobe2.ko \
-o /root/bootprobe2.log -D
# Give daemon time to start collecting...
/bin/echo "Sleeping a bit.."
sleep 5
# Hand off to real init
/bin/echo "Starting."
exec /sbin/init 3
并bootprobe2.1.stp
用嵌入式systemtap脚本语言编写:
global ident
function get_usertime:long() {
return task_utime() + @cast(task_current(), "task_struct", "kernel<linux/sched.h>")->signal->utime;
}
function get_systime:long() {
return task_stime() + @cast(task_current(), "task_struct", "kernel<linux/sched.h>")->signal->stime;
}
function timestamp() {
return sprintf("%d %s", gettimeofday_s(), ident[pid()])
}
function proc() {
return sprintf("%d \(%s\)", pid(), execname())
}
function push(pid, ppid) {
ident[ppid] = indent(1)
ident[pid] = sprintf("%s", ident[ppid])
}
function pop(pid) {
delete ident[pid]
}
probe syscall.fork.return {
ret = $return
printf("%s %s forks %d \n", timestamp(), proc(), ret)
push(ret, pid())
}
probe syscall.execve {
printf("%s %s execs %s \n", timestamp(), proc(), filename)
}
probe syscall.open {
if ($flags & 1) {
printf("%s %s writes %s \n", timestamp(), proc(), filename)
} else {
printf("%s %s reads %s \n", timestamp(), proc(), filename)
}
}
probe syscall.exit {
printf("%s %s exit with user %d sys %d \n", timestamp(), proc(), get_usertime(), get_systime())
pop(pid())
}
<linux sched.h=""><linux sched.h="">
</linux></linux>
为了接收在启动过程中以systemtap日志格式访问的文件列表,我们应该实现以下内容:
下载并安装适当命名的版本的systemtap
和kernel debuginfo
软件包(已获得此链接,但如果您使用的是CentOS,则最好使用此链接);
创建/tmp/stap
并/tmp/stap/data
mkdir -p /tmp/stap/data
地方bootprobe2.1.stp
和bootinit.sh
成/root
,使它们可执行的:chmod + X /根/启动*
bootinit.sh
如果默认运行级别为5,则将“ exec / sbin / init 3”编辑并更改为“ exec / sbin / init 5”。
从bootprobe2.stp创建.ko模块
cd /root
stap bootprobe2.1.stp -m bootprobe2 -p4
重启。
停止grub
(按Esc或Shift)并在默认内核上按'a'。在内核行的末尾输入以下内容,然后按Enter键:
init=/root/bootinit.sh,
正常启动将恢复。登录后,kill
将其stapio
复制bootprobe2.log
到tmpfs
/tmp/stap/data
目录中并卸载。
killall stapio
cp /tmp/stap/data/bootprobe2.log /tmp/stap/
umount /tmp/stap/data
现在,检查文件/tmp/stap/bootprobe2.log
文件以获取在引导过程中读取的所有文件的列表。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句