zoukankan      html  css  js  c++  java
  • Wazuh连接外部的API

    7、Wazuh连接外部的API

    该集成服务允许Wazuh连接到外部的API和报警工具

    7.1、集成组件配置

    要开始定制集成, 必须在管理器中修改ossec.conf文件(包括块集成组件)。可以使用以下参数:

    name:执行集成的脚本的名称。对于像本文讨论的那样的定制集成,名称必须以“ custom-”开头。
    hook_url:由软件API提供的URL,用于连接到API本身。它的使用是可选的,因为它可以包含在脚本中。
    api_key:使我们能够使用它的API的密钥。出于相同的原因,hook_url的使用也是可选的,因此它的使用也是可选的。
    level:设置级别过滤器,以使脚本不会接收低于特定级别的警报。
    rule_id:设置警报标识符的过滤器。
    group:设置警报组过滤器。
    event_location:设置警报源过滤器。
    alert_format:指示脚本以JSON格式接收警报(推荐)。默认情况下,脚本将以full_log格式接收警报。

    <integration>
      <name>custom-integration</name>
      <hook_url>WEBHOOK</hook_url>
      <level>10</level>
      <group>multiple_drops|authentication_failures</group>
      <alert_format>json</alert_format>
    </integration>
    

    例如:

    <ossec_config>
      <integration>
        <name>custom-opapi-send-weixin</name>
        <level>12</level>
        <alert_format>json</alert_format>
      </integration>
    

    7.2、创建集成脚本

    集成脚本的第一行必须指示其解释器,否则Wazuh将不知道如何读取和执行脚本。

    #!/usr/bin/env python
    

    该脚本必须检查其参数,因为它将接收来自它们的配置选项。第一个参数包括包含警报的文件的位置。第二个参数包含api_key,第三个参数包含hook_url选项。如果上述均未指示,则参数将被接收为空。

    alert_file = sys.argv[1]
    api_key = sys.argv[2]
    hook_url = sys.argv[3]
    

    下一步是读取第一个参数中指示的文件的内容,并从警报中提取与集成相关的字段。如果在alert_format选项中使用了JSON,则该信息必须作为JSON对象加载。

    alert_level = alert_json['rule']['level']
    description = alert_json['rule']['description']
    

    我们建议您在开始开发集成之前检查文件/logs/alerts/alerts.json,以便找到要解释的警报的格式。
    例如:

    cd /var/ossec/integrations && ls
    custom-opapi-send-weixin
    custom-opapi-send-weixin.py
    

    cat custom-opapi-send-weixin.py

    #!/usr/bin/env python3
    import sys
    import json
    import requests
    
    # Read configuration parameters
    alert_file = open(sys.argv[1])
    hook_url="http://opapi.qq.com/weixin/gaojing/"
    # Read the alert file
    alert_json = json.loads(alert_file.read())
    alert_file.close()
    # Extract issue fields
    remark = alert_json['agent']['ip']
    description = alert_json['rule']['description']
    full_log = alert_json['full_log']
    
    msg_data={
    "sendto":"ID",
    "status":"PROBLEM",
    "title":"%s" %description,
    "remark":"%s" %remark,
    "content":"%s" %full_log,
    }
    
    headers = {'Content-Type': 'application/json', 'Authorization': 'Token b1e6e7b5'}
    requests.post(url=hook_url, headers=headers, data=json.dumps(msg_data))
    sys.exit(0)
    

    7.3、修改脚本属性

    chmod 750 /var/ossec/integrations/custom-opapi-send-weixin*
    chown root:ossec /var/ossec/integrations/custom-opapi-send-weixin*
    

    7.4、重启wazuh-manager服务

    service wazuh-manager restart
  • 相关阅读:
    HTB-靶机-Charon
    第一篇Active Directory疑难解答概述(1)
    Outlook Web App 客户端超时设置
    【Troubleshooting Case】Exchange Server 组件状态应用排错?
    【Troubleshooting Case】Unable to delete Exchange database?
    Exchange Server 2007的即将生命周期,您的计划是?
    "the hypervisor is not running" 故障
    Exchange 2016 体系结构
    USB PE
    10 months then free? 10个月,然后自由
  • 原文地址:https://www.cnblogs.com/stone1989/p/14037372.html
Copyright © 2011-2022 走看看