对github新CVE的监控并推送到微信

admin 2022年5月23日10:40:23评论162 views字数 3079阅读10分15秒阅读模式

0x00:前言

    Github是国内外技术工具的分(基)享(佬)基(社)地(区),很多新的CVE利用脚本也都会第一之间的公布出来,但是每次要用到什么脚本的时候,就只能自己去查找.或者新的CVE利用脚本出来的时候,又会完美的错过.

    现在,经过我一天时间的研究,结合github的API写一下自动监控CVE利用脚本的小工具,并把新结果第一时间的推送到微信上.主要是目前网上有个工具,但是它是E语言写的工具.本人就只想搞懂思路,并用纯Python写一遍.

0x01:思路

一、采用API

https://api.github.com/search/repositories?q=CVE-2020&sort=updated

其中"CVE-2020"为你要搜索的内容通过正则把想要显示的关键字匹配出来

def getNews():  api = "https://api.github.com/search/repositories?q=CVE-2020&sort=updated"  req = requests.get(api).text  cve_total_count=re.findall ('"total_count":*.{1,10}"incomplete_results"',req)[0][14:17]  cve_description=re.findall ('"description":*.{1,200}"fork"',req)[0].replace("","fork"",'').replace(""description":"",'')  cve_url=re.findall ('"svn_url":*.{1,200}"homepage"',req)[0].replace("","homepage"",'').replace(""svn_url":"",'')if __name__ == '__main__':    sendNews()


  • "total_count"是一个统计参数,后面我们可以用它来判断是否变化

  • "description"是Github仓库的描述

  • "svn_url"是该CVE的Github页面链接

二、通过延迟60秒时间的前后比对来判断是否有新的脚本出现.

api = "https://api.github.com/search/repositories?q=CVE-2020&sort=updated"req = requests.get(api).texttotal_count=re.findall ('"total_count":*.{1,10}"incomplete_results"',req)[0][14:17]time.sleep(60)msg1 = str(getNews())msg=str(getNews())[7:]#getNews()是调用上面的抓取关键字的函数返回值if total_count!=getNews()[0]:#比对两个参数值  ...else:  pass


三、如果出现新的脚本,推送至指定微信号

#会弹出网页二维码扫描登录微信itchat.auto_login() #不想每次都扫描,登录时预配置#itchat.auto_login(hotReload=True)#itchat.run()#想给谁发信息,先找到该朋友,备注名my_friend = itchat.search_friends(name = r'大人啊冤枉')user_id = my_friend[0]["UserName"]itchat.send(msg,toUserName = user_id)#获取getNews()内容msg = str(getNews())itchat.send(msg,toUserName = user_id)#把msg的内容发送到指定微信号上,我这里指定的微信号是"大人啊冤枉"(我的小号)

四、完整代码

from itchat.content import *import requests,itchat,re,time
def getNews(): try: api = "https://api.github.com/search/repositories?q=CVE-2020&sort=updated" req = requests.get(api).text cve_total_count=re.findall ('"total_count":*.{1,10}"incomplete_results"',req)[0][14:17] cve_description=re.findall ('"description":*.{1,200}"fork"',req)[0].replace("","fork"",'').replace(""description":"",'') cve_url=re.findall ('"svn_url":*.{1,200}"homepage"',req)[0].replace("","homepage"",'').replace(""svn_url":"",'')
return cve_total_count,cve_description,cve_url
except Exception as e: print (e,"github链接不通")
def sendNews(): try: #会弹出网页二维码扫描登录微信 itchat.auto_login() #不想每次都扫描,登录时预配置 #itchat.auto_login(hotReload=True) #itchat.run() #1.想给谁发信息,先找到该朋友,备注名 my_friend = itchat.search_friends(name = r'大人啊冤枉') #2.找到UserName user_id = my_friend[0]["UserName"] #msg1 = str(getNews()) #获取getNews()内容 while True: api = "https://api.github.com/search/repositories?q=CVE-2020&sort=updated" req = requests.get(api).text total_count=re.findall ('"total_count":*.{1,10}"incomplete_results"',req)[0][14:17] time.sleep(60) msg1 = str(getNews()) msg=str(getNews())[7:]
if total_count!=getNews()[0]: itchat.send(msg,toUserName = user_id)
else: pass #itchat.send(cont,toUserName = my_love) except Exception as e: #print (e,"WeChat error") raise eif __name__ == '__main__': sendNews()

成果截图

对github新CVE的监控并推送到微信

0x02:后话

    其实网上很多大佬写的工具都挺好的,但是我们不能只会用别人的工具,我们应该学会自己写工具.自己慢慢的完善自己的不足之处,才能跟上大佬们的脚步,不是么?

    根据以上的代码还可以改成RCE脚本的监控,或者两者一起推送.看个人的喜好,可随意增加

小彩蛋:搜索关键字改成 username password RCE mysql等,不一样的惊喜哟!

对github新CVE的监控并推送到微信

对github新CVE的监控并推送到微信



本文始发于微信公众号(Khan安全攻防实验室):对github新CVE的监控并推送到微信

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年5月23日10:40:23
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   对github新CVE的监控并推送到微信https://cn-sec.com/archives/535647.html

发表评论

匿名网友 填写信息