数据包节拍接口检测



我正在使用 packbeat 来监控网络流量,以便使用 ELK 进行类似 SIEM 的设置。我想将其推送到大量计算机,但设置需要在 packetbeat.yml 中手动识别。

是否有人能够编写选择适当接口来监视数据包跳动的过程的脚本?

我已经把它放在一起 - 它使用 3 个单独的 .yml

ConfigTemplate.yml,其中包含 packetbeat.yml 的其余部分减去接口。

Interfaces.yml 这是一个用于写入接口的临时文件。

packetbeat.yml 这是 packetbeat 将使用的最终配置文件。

python脚本应该与配置.yml一起位于packetbeat目录中。

唯一的限制是它在主机上需要python - 下一阶段是看看它是否可以用Powershell完成。

希望这对其他人有所帮助!欢迎任何改进!

import subprocess
devices = subprocess.check_output(["powershell.exe", "(./packetbeat.exe   devices).count"])
devicesCount = int(devices.decode('utf-8'))
print(devicesCount)
deviceCount = range(devicesCount)

with open('ConfigTemplate.yml', 'r') as original: data1 = original.read()

with open('Interfaces.yml', 'w') as modified: 
for i in deviceCount:
modified.write("packetbeat.interfaces.device: " + str(i)+ "n" )

with open('Interfaces.yml', 'r') as original: data2 = original.read()

with open('Packetbeat.yml', 'w') as modified2: modified2.write("# ================== Set listening interfaces ==================" +"n"+ data2 + "n" + data1 + "n")

Powershell 版本 -

$count = (C:pathtopacketbeat.exe - devices).count
$line = ''

for($i=0; $i -le ($count-1); $i++){
$line +="packetbeat.interfaces.device:"+" $i `r`n" 
}
$line  | Out-File -FilePath "C:pathtopacketbeatInterfaces.yml"
$configTemplate = Get-Content -Path "C:pathtopacketbeatConfigTemplate.yml"
$interfaces = Get-Content -Path "C:pathtopacketbeatInterfaces.yml"
$interfaces + "`r`n" + $configTemplate | Out-File -FilePath "C:pathtopacketbeatpacket.yml"

最新更新