DCSO/nightwatch

GitHub: DCSO/nightwatch

Nightwatch 是一个基于插件架构的 Suricata 文件分析框架,用于实时扫描和处理从网络流量中提取的文件。

Stars: 4 | Forks: 0

# nightwatch Nightwatch 是一个基于插件架构的 Suricata 文件存储分析框架。 Nightwatch 守护进程响应 Suricata 文件提取功能从流量中提取的文件, 并调用各种插件对其进行分析。每个已扫描文件的 JSON 报告(包含所有插件输出) 可以转发给 AMQP 消费者以进行进一步分析和存储。此外,被标记为可疑的文件 也可以选择性地上传到兼容 S3 的文件存储,以便后续进行集中式分析。 ## 当前插件 * _yarascan_: 使用从给定 URL 下载的 YARA 规则集扫描文件 ## 构建守护进程 由于 YARA 插件需要 YARA 库文件才能构建,您需要先 安装它们(例如在 Debian/Ubuntu 上): ``` apt install libyara-dev libmagic-dev ``` Nightwatch 使用标准的 Go 构建系统。要在 `build` 子目录中构建二进制文件,只需使用提供的 Makefile: ``` make ``` 可以使用以下命令执行静态构建: ``` ./build/nightwatch -h ``` ## 测试 测试套件使用标准的 Go 测试框架,可以通过运行以下命令调用: ``` make test ``` ## 用法 守护进程依赖各种软件组件才能完全发挥作用: * Suricata 配置为提取文件并将其转储到 `-dir` * RabbitMQ 正在运行并为 `-amqpuser` 和 `-amqppass` 在 `-amqpexch` 上接受投递 这是当前命令行参数的转储: ``` ❯ ./build/nightwatch -h Usage of ./build/nightwatch: -amqpexch string Exchange to post messages to (default "nightwatch") -amqppass string Password for the AMQP connection (default "sensor") -amqpuri string Endpoint and port for the AMQP connection (default "localhost:5672") -amqpuser string User name for the AMQP connection (default "sensor") -data string Path for the file database (default "/var/lib/nightwatch/") -dir string Directory where suricata stores files (default "/var/log/suricata/files") -dummy Log verdicts to file instead of submitting to AMQP -log string Path for nightwatch log files (default "/var/log/") -logjson JSON log output -maxage duration max age of file before being cleaned up (default 8760h0m0s) -maxspace uint max total space used for files in MB (default 20000) -mproffile string Dump memory profiling information to file -proffile string Dump profiling information to file -profsrv Enable profiling server on port 6060 -rescantime duration rescan files older than time period (default 72h0m0s) -rule-file string Path for compiled YARA rule file -rule-uri string Download URL for YARA rules (default "http://localhost/yara/current.yac") -rule-xz YARA rules are XZ compressed -socket string Path for fileinfo EVE input socket (default "/tmp/files.sock") -storeversion int Filestore version (default 2) -uploadaccesskey string Access key for S3 upload -uploadbucket string Bucket name for S3 upload -uploadendpoint string Endpoint for suspicious file S3 upload -uploadregion string Region for S3 upload -uploadscratchdir string Temp directory for S3 upload (default "/tmp/nightwatch_scratch") -uploadsecretaccesskey string Secret access key for S3 upload -uploadssl Use SSL for S3 upload -verbose Verbose output ``` ## Suricata 配置 请注意,Suricata 需要 libmagic 支持才能识别 从提取的文件中提取的可执行文件。 ### 额外的 EVE 输出 Nightwatch 根据 Suricata `fileinfo` 事件构建扫描积压:它 接收每个提取文件的 EVE(可扩展事件格式)通知 并在其上运行插件。为了确保 `fileinfo` 事件 包含在输出中,并减少 Nightwatch 每秒可能必须处理数千个非 `fileinfo` 事件的负载, 最好在 `suricata.yaml` 中的 Suricata 配置中添加 一个专用的 EVE 输出: ``` outputs: [...] # for nightwatch we log file events to a socket - eve-log: enabled: yes filetype: unix_stream filename: /tmp/files.sock types: - files: force-magic: no [...] ``` 然后,我们将此 socket 配置为 Nightwatch 的输入(`-socket` 参数)。 ### 规则集补充 Suricata 需要运行一些规则来检测提取文件中的可执行文件, 并将其转储到磁盘上的文件存储中: ``` alert http any any -> any any (msg:"FILE magic - Windows executable"; file.magic; content:"for MS Windows"; filestore; noalert; sid:1; rev:1;) alert smtp any any -> any any (msg:"FILE magic - Windows executable"; file.magic; content:"for MS Windows"; filestore; noalert; sid:2; rev:1;) alert smb any any -> any any (msg:"FILE magic - Windows executable"; file.magic; content:"for MS Windows"; filestore; noalert; sid:3; rev:1;) alert nfs any any -> any any (msg:"FILE magic - Windows executable"; file.magic; content:"for MS Windows"; filestore; noalert; sid:4; rev:1;) alert ftp-data any any -> any any (msg:"FILE magic - Windows executable"; file.magic; content:"for MS Windows"; filestore; ftpdata_command:stor; noalert; sid:5; rev:1;) ``` 可以根据需要扩展这些规则以支持其他架构或二进制类型。 ## 将 Nightwatch 作为服务运行 包含 `nightwatch.service` 文件,以便在安装于 `/usr/local/bin` 中时运行 Nightwatch。可以将其放置在 `/etc/systemd/system` 中,使其对 整个系统可用(随后运行 `systemctl daemon-reload` 以使其生效)。 `nightwatch.default` 文件可以复制到 `/etc/default/nightwatch`,以便 更轻松地配置参数,并且已经包含了 `-maxspace` 和 `-log` 的一些默认值。 ## 服务的运行时控制 一旦运行,可以通过向 `nightwatch` 进程发送信号来影响服务的行为: * `SIGHUP`: 重新初始化所有插件,例如重新加载 YARA 规则 * `SIGUSR1`: 重新扫描所有文件,而不清理现有数据库 * `SIGUSR2`: 从头开始重新扫描所有文件,覆盖现有数据库 ## 许可证 3-clause BSD,参见 [LICENSE](LICENSE)
标签:AMQP, AMSI绕过, EVTX分析, Go语言, Metaprompt, RabbitMQ, S3存储, Suricata, YARA, 云安全监控, 云计算, 云资产可视化, 威胁检测, 恶意软件扫描, 插件架构, 文件分析, 文件提取, 文件监控, 日志审计, 漏洞探索, 现代安全运营, 程序破解, 网络安全, 自动化分析, 规则引擎, 跨站脚本, 隐私保护, 静态分析