【问题标题】:Packetbeat interface detectionPacketbeat 接口检测
【发布时间】:2019-10-03 21:03:58
【问题描述】:

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

有没有人能够编写脚本来选择适当的接口来监控 packetbeat?

【问题讨论】:

  • 看来你可以拥有任意数量的 packetbeat.interfaces.device: 只要设备存在。我的理论是执行以下操作:1)powershell ./packetbeat.exe devices 2)计算每个“设备”返回的值写入 packetbeat.yml packetbeat.interfaces.device:“device”“device”++ 然后运行每次用户登录以确保其持续准确。它很混乱,但似乎是我能找到的最接近解决方法的方法。

标签: elasticsearch elk packetbeat


【解决方案1】:

我把它放在一起 - 它使用 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")

【讨论】:

    【解决方案2】:

    Powershell 版本 -

    $count = (C:\path\to\packetbeat.exe - devices).count
    
    $line = ''
    
    
    for($i=0; $i -le ($count-1); $i++){
    
        $line +="packetbeat.interfaces.device:"+" $i `r`n" 
    
        }
    
    $line  | Out-File -FilePath "C:\path\to\packetbeat\Interfaces.yml"
    
    $configTemplate = Get-Content -Path "C:\path\to\packetbeat\ConfigTemplate.yml"
    
    $interfaces = Get-Content -Path "C:\path\to\packetbeat\Interfaces.yml"
    
    $interfaces + "`r`n" + $configTemplate | Out-File -FilePath "C:\path\to\packetbeat\packet.yml"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-03
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多