OSSIM开源安全信息管理系统(十七)

2021SC@SDUSC




七、Agent部分源代码分析

1、Agent 简介

OSSIM Agent中所有脚本采用 Python 编写,负责从安全设备采集相关信息(比如报警日志等),并将采集到的各类信息统一格式,最后将这些数据传至 Server。从采集方式上看,Agent 属于主动采集,可以形象理解为由OSSIM Server 安插在各个监控网段的“耳目”,由它们收集数据,并主动推送到 Collector 中,然后 Collector 又连接着消息队列系统、缓存系统及存储系统。

Agent 相关目录在 /etc/ossim/agent/ ,代理插件目录在 /etc/ossim/agent/plugins/ ,配置文件路径:/etc/ossim/agent/config.cfg ,OSSIM系统的代理信息查看方法,通过 Analysis→Detection 下的 HIDS 标签中 Agents 查看。

Agent 结构:

在这里插入图片描述

Agent 的主要功能是接收或抓取 Plugins 发送过来或者生成的日志,经过归一化处理,然后有序地传送到 OSSIM的 Server,它的功能很复杂,因为它的设计要考虑到如果 Agent 和 Server 之间的网络中断、拥堵、丢包等情况。

Agent 会主动连接两个端口与外界通信,一个是连接 Server 的40001端口,而另一个是连接数据库的3306端口。如图所示。

在这里插入图片描述


Agent 将原始日志分成若干段并填充到相应的域中,相关字段如下:

  • date、sensor、interface、plugin_id、plugin_sid、priority、protocol、src_ip、src_port、dst_ip、dst_port

  • username、password、filename、userdata1、userdata2、userdata3、userdata4、userdata5、userdata6、userdata7、userdata8、userdata9


2、Agent.py 源码分析

首先导入一些必要的模块

import os
import sys
import time
import signal
import threading
import socket
import codecs
import uuid
import yaml
import subprocess as sub

然后导入本地模块

Conf 类继承自 ConfigParser

from Config import Conf, Plugin, Aliases, CommandLineOptions
from ConfigParser import Error as BaseConfigError
from ParserLog import ParserLog
from ParserJson import ParserJson
from Watchdog import Watchdog
from Logger import Logger
from Output import Output
from Stats import Stats
from Conn import ServerConn, IDMConn, FrameworkConn
from Exceptions import AgentCritical
from ParserDatabase import ParserDatabase
from ParserWMI import ParserWMI
from ParserSDEE import ParserSDEE
from ParserRemote import ParserRemote
from ParserUtil import HostResolv
from ParserFtp import ParserFTP
from ParserFormattedSnort import SnortEventsParser

定义全局变量:

Logger 类:用于日志记录的静态类。用于输出运行日志,可以设置输出日志的等级、日志保存路径、日志文件回滚等。

logger = Logger.logger

STAT_SIGNALS = {'clients': 40, 'plugins': 41, 'all': 50}
DEFAULT_SYSTEM_FILE = "/etc/ossim/agent/agentuuid.dat"
DEFAULT_PULSE_PLUGIN_PATH = '/etc/ossim/agent/av_pulse.cfg'

接下来就是具体类 Agent 的代码部分。

1、初始化方法 __init__

def __init__(self):
        # 调用CommandLineOptions的get_options()方法,解析命令行选项
        self.options = CommandLineOptions().get_options()
        # 读取相关配置
        self.conf = Conf()
        if self.options.config_file:
            self.__conffile = self.options.config_file
		#如果options中未通过“-c”命令行指定配置文件,则采用Conf类中默认的配置文件
        #DEFAULT_CONFIG_FILE = "/etc/ossim/agent/config.cfg"
        else:
            self.__conffile = self.conf.DEFAULT_CONFIG_FILE
		#通过类Conf的read方法以latin1编码方式读取配置文件
        #Latin1是一种编码方式,为ISO-8859-1的别名
        self.conf.read([self.__conffile], 'latin1')
        # 插件列表
        self.__plugins = []
        #其中的规则总数
        self.__nrules = 0
        #从/etc/ossim/agent/host_cache.dic中加载缓存
        HostResolv.loadHostCache()
        self.detector_objs = []
        self.watchdog = None
        self.shutdown_running = False
        self.__outputServerConnection = None
        self.__outputIDMConnection = None
        self.__frameworkConnection = None
        self.__keep_working = True
        self.__checkThread = None
        self.__stop_server_counter = 9999
        self.__pluginStopEvent = threading.Event()
        self.__sensorID = ""
        self.__systemUUIDFile = ""

配置文件格式:


在这里插入图片描述




本篇文章部分内容参考或转载自下列文章及书籍。侵权即删。

参考书籍:

  • 《开源安全运维平台OSSIM疑难解析(入门篇)》——李晨光著
  • 《开源安全运维平台OSSIM疑难解析(提高篇)》——李晨光著
  • 《开源安全运维平台:OSSIM最佳实践》——李晨光著

参考文章:

  • https://blog.51cto.com/chenguang/2426473
  • https://blog.csdn.net/lcgweb/article/details/101284949
  • https://blog.51cto.com/chenguang/1665012
  • https://www.cnblogs.com/lsdb/p/10000061.html
  • https://blog.51cto.com/chenguang/1691090
  • https://blog.51cto.com/chenguang/category10.html
  • https://blog.51cto.com/topic/ossim.html
  • https://blog.csdn.net/isinstance/article/details/53694361
  • https://blog.51cto.com/chenguang/1332329
  • https://www.cnblogs.com/airoot/p/8072727.html
  • https://blog.51cto.com/chenguang/1738731
  • https://blog.csdn.net/security_yj/article/details/120153992

上一篇:
下一篇:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陌兮_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值