欢迎,来自IP地址为:3.84.7.255 的朋友


本文将介绍如何使用autrace命令查看给定进程的详细信息,来跟踪进程的系统调用。

什么是autrace

autrace是一个进程在运行时一直运行的命令行工具,就像strace命令一样。它会将跟踪结果保存在/var/www/audit/audit.log文件中,为了使这个命令可以正常运行,你需要先将所有的跟踪规则删除。

autrace命令的语法如下,它只接受一个选项即为需要跟踪的进程,-r参数为限定跟踪的进程为系统调用。

# autrace -r program program-args

注意:在autrace的man页面,其介绍的语法如下面所示,这实际上是一个书写错误。因为如果采用这种格式,程序会认为输入的内容是一种程序内部的选项,从而导致错误或者使用了默认选项。

# autrace program -r program-args

如果你的系统之前没有跟踪规则,那么系统会报没有跟踪规则的错误,可以使用autrace -D命令删除所有的规则,再执行该命令。命令示意如下:

# autrace /bin/df -h
Waiting to execute: /bin/df
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  2.7G   16G  15% /
/dev/vdb1        18G  3.7G   14G  22% /dataroot
Cleaning up...
Trace complete. You can locate the records with 'ausearch -i -p 28253'

命令执行完成后,可以使用ausearch命令查询跟踪内容。

# ausearch -i -p 28253
----
type=SYSCALL msg=audit(09/30/17 11:52:23.137:22506) : arch=x86_64 syscall=write success=yes exit=48 a0=0x1 a1=0x7f167f093000 a2=0x30 a3=0x5 items=0 ppid=28251 pid=28253 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts0 ses=3198 comm=df exe=/bin/df key=(null) 
----
type=PROCTITLE msg=audit(09/30/17 11:52:23.137:22507) : proctitle=autrace /bin/df -h 
type=SYSCALL msg=audit(09/30/17 11:52:23.137:22507) : arch=x86_64 syscall=close success=yes exit=0 a0=0x1 a1=0x7f167f093000 a2=0x0 a3=0x7ffd049e9080 items=0 ppid=28251 pid=28253 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts0 ses=3198 comm=df exe=/bin/df key=(null) 
----
type=PROCTITLE msg=audit(09/30/17 11:52:23.137:22508) : proctitle=autrace /bin/df -h 
type=SYSCALL msg=audit(09/30/17 11:52:23.137:22508) : arch=x86_64 syscall=munmap success=yes exit=0 a0=0x7f167f093000 a1=0x1000 a2=0x0 a3=0x7ffd049e9080 items=0 ppid=28251 pid=28253 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts0 ses=3198 comm=df exe=/bin/df key=(null) 
----
type=PROCTITLE msg=audit(09/30/17 11:52:23.138:22509) : proctitle=autrace /bin/df -h 
type=SYSCALL msg=audit(09/30/17 11:52:23.138:22509) : arch=x86_64 syscall=close success=yes exit=0 a0=0x2 a1=0x1 a2=0x7f167ee716c0 a3=0x7ffd049e9080 items=0 ppid=28251 pid=28253 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts0 ses=3198 comm=df exe=/bin/df key=(null) 
----
type=PROCTITLE msg=audit(09/30/17 11:52:23.138:22510) : proctitle=autrace /bin/df -h 
type=SYSCALL msg=audit(09/30/17 11:52:23.138:22510) : arch=x86_64 syscall=exit_group a0=0x0 a1=0x3c a2=0x0 a3=0x4 items=0 ppid=28251 pid=28253 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts0 ses=3198 comm=df exe=/bin/df key=(null)
......

这个命令有两个参数:

-i 使用数值文本解读

-p 要搜索进程的ID

使用-p参数加进程ID方式,使用ausearch和aureport命令结合使用,如下所示可以产生一个报告文件:

# ausearch -i -p 28253 --raw | aureport -i -f

其中各项参数说明如下:

–raw 告诉ausearch命令将raw结果发送给aureport

-i 使得数值文本解读

-f 保存报告文件

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注