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

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

我正在检查昨天计算机的出口 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=29200 RES=0x00 SYN URGP=0

查阅了知名名单后TCP端口,只有暗黑破坏神II游戏使用端口4000。我的电脑上没有安装该游戏。我尝试过,但无法确定哪些其他服务可以连接到该端口。

由于这只是昨天发生的,如果我使用netstat,我可能会整天盯着屏幕来捕捉正在运行的服务。是否有更好的方法来确定连接到该特定端口的程序或用户?

答案1

您可以使用审核系统来记录所有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

然后你可以搜索:

sudo ausearch -i -k connectLog -w --host 69.46.36.10

这将显示类似以下内容:

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

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

答案2

与特定用途grep一起使用netstat港口。要检查具有时间延迟的无限时间段,您可以使用以下命令--

while($1); do netstat -anp | grep :80; sleep 1s;done > output.txt

相关内容