前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >对github新CVE的监控并推送到微信

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

作者头像
洛米唯熊
发布2020-04-26 13:24:23
1.6K0
发布2020-04-26 13:24:23
举报
文章被收录于专栏:洛米唯熊洛米唯熊

0x00:前言

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

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

0x01:思路

一、采用API

代码语言:javascript
复制
https://api.github.com/search/repositories?q=CVE-2020&sort=updated

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

代码语言:javascript
复制
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秒时间的前后比对来判断是否有新的脚本出现.

代码语言:javascript
复制
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

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

代码语言:javascript
复制
#会弹出网页二维码扫描登录微信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的内容发送到指定微信号上,我这里指定的微信号是"大人啊冤枉"(我的小号)

四、完整代码

代码语言:javascript
复制
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()

成果截图

0x02:后话

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

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

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-04-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 洛米唯熊 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档