事后如何确定连接到特定端口的程序或用户?

Que*_*low 3 iptables tcp

我正在检查我的计算机昨天的出口 IPTABLES 日志并注意以下几点:

IN= OUT=eth0 SRC=192.168.1.1 DST=69.46.36.10 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=12345 DF PROTO=TCP SPT=56789 DPT=4000 WINDOW=290xUR00=RES000

在查找众所周知的TCP 端口列表后,只有一个暗黑破坏神 II 游戏使用端口4000。我的电脑上没有安装游戏。我尝试过,但无法确定哪些其他服务可以连接到该端口。

由于这仅在昨天发生,如果我使用netstat,我可以整天盯着屏幕以了解正在运行的服务。有没有更好的方法来确定连接到这个特定端口的程序或用户?

Sté*_*las 5

您可以使用审计系统来记录所有connect()系统调用。

sudo auditctl -a exit,always -F arch=b64 -S connect -k connectLog
sudo auditctl -a exit,always -F arch=b32 -S connect -k connectLog
Run Code Online (Sandbox Code Playgroud)

然后你可以搜索:

sudo ausearch -i -k connectLog -w --host 69.46.36.10
Run Code Online (Sandbox Code Playgroud)

这将显示如下内容:

type=SOCKADDR msg=audit(02/09/14 12:31:57.966:60482) : saddr=inet host:69.46.36.10 serv:4000
type=SYSCALL msg=audit(02/09/14 12:31:57.966:60482) : arch=x86_64 syscall=connect success=no exit=-4(Interrupted system call) a0=0x3 a1=0x20384b0 a2=0x10 a3=0x7fffbf8c9540 items=0 ppid=21712 pid=25423 auid=stephane uid=stephane gid=stephane euid=stephane suid=stephane fsuid=stephane egid=stephane sgid=stephane fsgid=stephane tty=pts5 ses=4 comm=telnet exe=/usr/bin/telnet.netkit key=connect
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我已经看到grm.feedjit.comiPhone 在 400x 端口上解析 IP 地址并尝试连接到 IP 地址。