如何判断Mac OS X中的进程数据包来源



关闭所有应用程序后,tcpdump显示我的Mac偶尔会向少数IP发送数据包。它们是没有数据有效载荷和具有异常TCP序列号的数据包突发(就像一个隐蔽通道)。有没有一种方法可以确定是哪个进程从命令行或编程方式发起这些数据包?

注意:我已经使用ipfw对目的IP进行了出口过滤,所以我不担心数据的出口过滤。

我会很懒,只需安装Little Snitch(免费试用);)

但是,如果是TCP连接,如果在发送可疑数据包期间或之后不久进行检查,则应该能够很容易地在netstat中找到罪魁祸首。

如果你想得到真正的幻想,给自己写一个内核扩展,做你想做的。苹果有一个可爱的指南,甚至还有一些示例代码,可以满足您的需求。

Apple对tcpdump进行了修改,因此它支持一些元数据选项,这些选项来自Mac OS X tcpdump:的手动页面

 -k     Control the display of packet metadata via an optional metadata_arg argument. This is useful when displaying packet saved in the pcap-ng file format
          or with interfaces that support the PKTAP data link type.
          By default, when the metadata_arg optional argument is not specified, any available packet metadata information is printed out.
          The metadata_arg argument controls the display of specific packet metadata information using a flag word, where each character corresponds to a type
          of packet metadata as follows:
                 I     interface name (or interface ID)
                 N     process name
                 P     process ID
                 S     service class
                 D     direction
                 C     comment
          This is an Apple modification.

因此,当使用-k N运行tcpdump时,我们可以看到进程名称:

19:12:51.823518 pid Google Chrome.313 svc BK IP 192.168.100.191.49424 > 216.58.209.133.443: Flags [.], ack 74, win 4093, options [nop,nop,TS val 507317615 ecr 3185588461], length 0 19:12:51.823518 pid Google Chrome.313 svc BK IP 192.168.100.191.49424 > 216.58.209.133.443: Flags [.], ack 329, win 4088, options [nop,nop,TS val 507317615 ecr 3185588462], length 0

我也有同样的问题,但有一个例外-我的TCP流量在lo0上,它没有建立,但一些进程试图连接到localhost和一些端口。我的任务是确定谁试图连接。小飞贼在这一点上毫无用处。

但我发现nettop非常有用。我发现进程在其输出中不断更改TCP连接状态SynSent/Fin等,这就是我想要的。

最新更新