我如何知道 Mac OS X 中的数据包源自哪个进程?
在所有应用程序关闭的情况下,tcpdump 显示我的 Mac 偶尔向少数 IP 发送数据包。它们是没有数据有效负载且具有不寻常 TCP 序列号(如隐蔽通道)的数据包突发。有没有办法确定哪个进程从命令行或以编程方式发起这些数据包?
注意:我已经使用ipfw对出口IP进行过滤,所以我不担心数据泄露。
With all applications closed, tcpdump reveals that my Mac is sending packets to a handful of IPs sporadically. They're are bursts of packets with no data payload and with unusual TCP sequence numbers (like a covert channel). Is there a way to determine which process is originating these packets from either the command line or programmatically?
Note: I have used ipfw to egress filter the destination IPs, so I am not worried about data exfiltration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会很懒,只需安装 Little Snitch (提供免费试用);)
但是,如果是 TCP 连接,如果您在可疑数据包发送期间或发送后不久进行检查,您应该能够轻松地在
netstat
中找到罪魁祸首。如果你想真正变得更奇特,可以自己编写一个内核扩展来完成你想要的事情。 Apple 有一个可爱的指南,甚至示例代码 正是您所寻找的。
I'd be lazy and simply install Little Snitch (free trial available) ;)
However, if it's a TCP connection, you should easily be able to find the culprit in
netstat
if you check during or shortly after the suspicious packets are sent.And if you want to get really fancy, write yourself a kernel extension that does what you want. Apple has a lovely guide and even sample code that does just what you are looking for.
Apple 对 tcpdump 进行了修改,因此它支持 Mac OS X 手册页中的一些元数据选项 tcpdump:
因此,当使用 -k N 运行 tcpdump 时,我们可以看到进程名称:
19:12:51.823518 pid Google Chrome.313 svc BK IP 192.168.100.191.49424 > 216.58.209.133.443:标志[.],ack 74,win 4093,选项[nop,nop,TS val 507317615 ecr 3185588461],长度0
19:12:51.823518 pid Google Chrome.313 svc BK IP 192.168.100.191.49424 > 216.58.209.133.443:标志[.],ack 329,win 4088,选项[nop,nop,TS val 507317615 ecr 3185588462],长度0
Apple has made a modification to tcpdump so it supports a few metadata options, from the manual page of Mac OS X tcpdump:
So when running tcpdump with -k N we can see the process name:
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 并且尚未建立,但某些进程正在尝试连接到本地主机和某个端口。我的任务是确定谁正在尝试连接。
那时的小飞贼已经毫无用处了。
但我发现
nettop
非常有帮助。我发现进程在其输出中不断改变 TCP 连接状态 SynSent/Fin/等,这就是我正在寻找的。I had the same question, with one exception - my TCP traffic was on lo0 and it was not established, but some process was trying to connect to localhost and some port. My task was to identify who is trying to connect.
Little Snitch was useless at that point.
But I found that
nettop
is pretty helpful. I found process in its output constantly changing TCP connection states SynSent/Fin/etc and it was what I was looking for.