整体功能
先看一段最简单的 get 请求:
func main(){
url :="https://www.seebug.org/vuldb/vulnerabilities?page=1"
res, err := http.Get(url)
if err !=nil{
fmt.Println("Error request:", err)
return
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
GET 方法访问 seebug 漏洞库,打印出的结果如下:
这是一段 js 混淆的代码,而不是期望的 html 数据。
curl 的结果同样如此,随后尝试用 burp 补全正常请求的参数,依然无法得到正确的数据。因此考虑使用 chromedp 来进行访问。
chromedp
https://github.com/chromedp/chromedp
先看一段 demo,通过 chromedp 来访问百度并且搜索特定内容,再点击搜索按钮:
package main
import(
"context"
"fmt""github.com/chromedp/chromedp")
func main(){
ctx, _ := chromedp.NewExecAllocator(context.Background(),
append(
chromedp.DefaultExecAllocatorOptions[:], chromedp.Flag("headless",false), chromedp.Flag("enable-automation",false),
)...,
)
ctx, _ = chromedp.NewContext(ctx)
chromedp.Run(ctx, chromedp.Navigate("http://www.baidu.com"))
chromedp.Run(ctx, chromedp.SendKeys(`#kw`,"111", chromedp.ByID))
fmt.Println("wait for 2 seconds")
chromedp.Run(ctx, chromedp.WaitVisible(`#su`, chromedp.ByID))
chromedp.Run(ctx, chromedp.Click(`document.querySelector("#su")`, chromedp.ByJSPath))
}
首先是新建一个执行上下文,通过 append 来覆盖 options 中的一些参数,DefaultExecAllocatorOptions 的默认配置如下:
varDefaultExecAllocatorOptions=[...]ExecAllocatorOption{
NoFirstRun,
NoDefaultBrowserCheck,
Headless,
Flag("disable-background-networking",true),
Flag("enable-features","NetworkService,NetworkServiceInProcess"),
Flag("disable-background-timer-throttling",true),
Flag("disable-backgrounding-occluded-windows",true),
Flag("disable-breakpad",true),
Flag("disable-client-side-phishing-detection",true),
Flag("disable-default-apps",true),
Flag("disable-dev-shm-usage",true),
Flag("disable-extensions",true),
Flag("disable-features","site-per-process,Translate,BlinkGenPropertyTrees"),
Flag("disable-hang-monitor",true),
Flag("disable-ipc-flooding-protection",true),
Flag("disable-popup-blocking",true),
Flag("disable-prompt-on-repost",true),
Flag("disable-renderer-backgrounding",true),
Flag("disable-sync",true),
Flag("force-color-profile","srgb"),
Flag("metrics-recording-only",true),
Flag("safebrowsing-disable-auto-update",true),
Flag("enable-automation",true),// 会显示自动化测试标识
Flag("password-store","basic"),
Flag("use-mock-keychain",true),
}
headless 参数如果设置为 false,就会打开一个窗口,反之则无,为了调试方便这里将参数设置为 false。通过 chromedp.Navigate()导航到 baidu,再通过 chromedp.SendKeys()模拟键盘输入,QueryOptions 设置为 ByID,再找到 id 为 kw 的部分,实现了在搜索框中输入内容:
接着通过 chromedp.WaitVisible()等待搜索按钮出现,并进行点击:
最终结果如下:
下面尝试访问 seebug。
chrome 打开了一个空白网页,可能是有反爬的逻辑,在 options 中添加头:chromedp.Flag("disable-blink-features", "AutomationControlled"),
即可。
在控制台中查看 window.navigator.webdriver,可以发现不加参数时为 true,加上参数之后 webdriver 变为 false。
目前已经能够正常访问,尝试打印出 html 内容:
可以看到网页还在加载,打印出的内容依然是混淆的 js 数据。这里只需要 sleep 一段时间等待网页加载完成就好:
或者使用更高效的方法,例如等待第一个漏洞的漏洞名称加载完再打印:
xpath :="/html/body/div[2]/div/div/div/div/table/tbody/tr[1]/td[4]/a"
chromedp.WaitVisible(xpath, chromedp.BySearch),
能够拿到正确的html之后,进行解析提取出想要的信息即可。
爬取逻辑
每天凌晨通过chromedp访问seebug漏洞库第一页的内容,通过提交时间判断是否为新漏洞,如果是则插入数据库。
实现效果
目前seebug源的监控已经加入crush项目:
https://github.com/leesinz/crush
原文始发于微信公众号(Crush Sec):golang 实现漏洞监控04——seebug 漏洞信息监控
- 左青龙
- 微信扫一扫
- 右白虎
- 微信扫一扫
评论