天天看点

用systemtap研究内核以及相关漏洞

作者联系方式:李先静 <xianjimli at hotmail dot com>

更新时间:2007-6-6

前几天写了一篇关于kprobes的BLOG,kprobes是个好东西,不过要编写C代码,要编译内核模块,稍嫌有些麻烦。今天我们介绍一个基于kprobes实现的工具systemtap,systemtap是一个内核trace工具,用它来研究内核,跟踪内核执行非常方便。我玩了一下,感觉不错,这里做个笔记。

Systemtap提供了一种简单的脚本语言,用户使用脚本语言就可以跟踪内核执行。Systemtap把脚本语言转换成C语言,编译成内核模块,内核模块通过kprobes实现对内核的反射,动态修改函数的行为,增加trace功能,这样用户就不必写C代码,也不必编译内核模块了,用起来方便多了。

其实网上已经有一些文章介绍systemtap,不过一般都针对特定系统而言的,这里我们尽量不依赖特定系统,而从源代码构建内核和工具。

1.       编译内核,让内核支持设计kprobes和debuginfo。

下载FC 6所带的kernel源代码包(或者标准kernel源代码)。

做如下配置:

Kernel hacking

  [*] Kernel debugging  

[*]   Compile the kernel with debug info

Instrumentation Support

      [*] Kprobes (EXPERIMENTAL)

    编译/安装:

    make;make modules_install;make install

    安装调试信息:

    cp vmlinux /lib/modules/2.6.18-prep

    用新内核起动。

2.       下载/编译/安装elfutils

tar zxvf elfutils-0.125.tar.gz

cd elfutils-0.125

./configure ;make;make install

3.       下载/编译/安装systemtap

tar jxvf systemtap-20070602.tar.bz2

cd systemtap

./configure;make;make install

4.       试试

#stap -ve 'probe begin { log("hello world") exit () }'

#stap -c df -e 'probe syscall.open { if (target()==pid()) log(name." ".argstr) }'

好,可以工作了,下一步开始研究内核吧。

参考资源:

<a href="http://sourceware.org/systemtap/">http://sourceware.org/systemtap/</a>

~~end~~

漏洞:

stap-client /; ...

stap-client -; ...

stap-client -D 'asdf ; ls /etc' ...

stap-client -e 'script' -D 'asdf ; /; '

继续阅读