你可以做几件事来适应这样的脚本。首先可以问dtrace
一下它有哪些探测点:
$ sudo dtrace -l -f 'syscall::exec*'
ID PROVIDER MODULE FUNCTION NAME
18442 syscall execve entry
18443 syscall execve return
其次,您可以跟踪单个进程上的所有系统调用以查看发生了什么。
$ sudo dtruss ssh somewhere 2>dtrussout
Password: (type something here)
如果你看透dtrussout
你会看到
read_nocancel(0x5, "a\0", 0x1) = 1 0
read_nocancel(0x5, "s\0", 0x1) = 1 0
read_nocancel(0x5, "d\0", 0x1) = 1 0
read_nocancel(0x5, "f\0", 0x1) = 1 0
read_nocancel(0x5, "\n\0", 0x1) = 1 0
有了这些知识,改编脚本就很容易了。
$ diff sshkeysnoop.d{.orig,}
40c40
< syscall::exec:return, syscall::exece:return
---
> syscall::execve:return
51c51
< syscall::open:entry, syscall::open64:entry
---
> syscall::open:entry
58c58
< syscall::open:return, syscall::open64:return
---
> syscall::open:return
68c68
< syscall::read:entry
---
> syscall::read_nocancel:entry
75c75
< syscall::read:return
---
> syscall::read_nocancel:return