整体功能
监控 metasploit 官方的 github 源,如果有更新,则通过脚本处理,筛选出是否为 exploit,是否有 cve 号等等,并通过邮件推送。
代码逻辑
首先通过 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 号,并记录日志。
实现效果
参数为 init 时,首先将仓库克隆到本地。参数为 monitor 时,git pull 并且对数据进行处理,本地仓库已经是最新,因此 mail_log,msf_update_info.log,msf_update_history.log 都为 Already up to date. 将 log 改为如下内容进行测试:
2022-03-1706:00:01
Updating0080718..c63490c
Fast-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 文件。
原文始发于微信公众号(Crush Sec):golang 实现漏洞监控03——metasploit 漏洞信息监控
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论