golang 实现漏洞监控03——metasploit 漏洞信息监控

admin 2024年1月24日16:08:26评论13 views字数 2202阅读7分20秒阅读模式

整体功能

监控 metasploit 官方的 github 源,如果有更新,则通过脚本处理,筛选出是否为 exploit,是否有 cve 号等等,并通过邮件推送。

代码逻辑

golang 实现漏洞监控03——metasploit 漏洞信息监控

首先通过 init 参数,将 metasploit 仓库 clone 到本地,接着通过 monitor 参赛来进行日常监控。完整的流程如图所示,主要看一下 check 的部分。

 func CheckMSFUpdate(){    result :=""    file, err := os.Open(updateInfoPath)if err !=nil{       fmt.Println("open file err:", err)return}    defer file.Close()    scanner := bufio.NewScanner(file)for scanner.Scan(){       line := scanner.Text()if upToDate.MatchString(line){//fmt.Println("Already up to date.")            result +="Already up to date."}if newExploitInfo.MatchString(line){          cveFlag :=""          newFilePath := newExploitInfo.FindStringSubmatch(line)[1]          file, err := os.Open(msfDir +"/"+ newFilePath)if err !=nil{             fmt.Println("Error opening file:", err)return}          scanner := bufio.NewScanner(file)for scanner.Scan(){             rbLine := scanner.Text()if cvePattern.MatchString(rbLine){sub:= cvePattern.FindStringSubmatch(rbLine)                cve :=sub[1]+"-"+sub[2]                newCVEInfos[cve]= newFilePath                  cveFlag = cve +":"}}          result += cveFlag + newFilePath +"n"}}//fmt.Println(result)      now := time.Now().Format("2006-01-02")    logContent := now +"n"+ result      utils.WriteToLog(logContent, mailLogPath)}

也就是对 git pull 的信息进行正则匹配,再到 rb 文件里找 CVE 号,并记录日志。

实现效果

golang 实现漏洞监控03——metasploit 漏洞信息监控

参数为 init 时,首先将仓库克隆到本地。参数为 monitor 时,git pull 并且对数据进行处理,本地仓库已经是最新,因此 mail_log,msf_update_info.log,msf_update_history.log 都为 Already up to date. 将 log 改为如下内容进行测试:

2022-03-1706:00:01Updating0080718..c63490cFast-forward db/modules_metadata_base.json                      |56+++.../local/cve_2022_21999_spoolfool_privesc.md      |210++++++++++.../stdapi/railgun/def/windows/api_constants.rb    |35+-.../stdapi/railgun/def/windows/def_advapi32.rb     |71++++.../stdapi/railgun/def/windows/def_ntdll.rb        |6+.../stdapi/railgun/def/windows/def_spoolss.rb      |28++.../stdapi/railgun/def/windows/def_winspool.rb     |102+++++.../extensions/stdapi/railgun/railgun.rb           |4+-.../local/cve_2022_21999_spoolfool_privesc.rb      |429+++++++++++++++++++++9 files changed,939 insertions(+),2 deletions(-) create mode 100644 documentation/modules/exploit/windows/local/cve_2022_21999_spoolfool_privesc.md create mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/def/windows/def_spoolss.rb create mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/def/windows/def_winspool.rb create mode 100644 modules/exploits/windows/local/cve_2022_21999_spoolfool_privesc.rb

成功解析到更新的模块,并且将日志写入了 log 文件。

golang 实现漏洞监控03——metasploit 漏洞信息监控

原文始发于微信公众号(Crush Sec):golang 实现漏洞监控03——metasploit 漏洞信息监控

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年1月24日16:08:26
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   golang 实现漏洞监控03——metasploit 漏洞信息监控http://cn-sec.com/archives/2426245.html

发表评论

匿名网友 填写信息