shell每隔一秒钟就记录下netstat状态

说明

木马可能类似随机发送心跳包的操作,随机sleep。对这类情况写好了一个监听shell脚本,每隔一秒钟就记录下netstat状态。

代码

#!/bin/bash
#功能:用于定时执行lsof 和 netstat 的执行状态并记录到文件

slptime=1   #默认一秒执行一次
filedir=/tmp        #默认存储在/tmp下
lsoffile=lsof.log   #存储lsof的执行结果
netstatfile=netstatfile.log #存储netstat执行结果



while true

do
    sleep $slptime
    date=$(date '+%Y-%m-%d %H:%M:%S')
    
    echo $date":" >> $filedir/$lsoffile
    echo $date":" >> $filedir/$netstatfile
    lsof -i   >> $filedir/$lsoffile
    netstat -tunlp >> $filedir/$netstatfile

done

猜你喜欢

转载自www.cnblogs.com/17bdw/p/11495108.html