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

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).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:]#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 e
if __name__ == '__main__':
    sendNews()

0x02:后话#

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

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

欢迎关注我的微信公众号:洛米唯熊
6 个赞

现在itchat还可以用吗?

应该可以,你可以去尝试一下

刚才试了下,说不让网页登录 :joy:

嗯呐 确实有部分人可以,有人就存在你这个问题

我们群里有人搞了一个,还是很不错的

之前网盘还有个暗网的监控,原理不太一样,也分享给大家学习学习。
链接:https://pan.baidu.com/s/1IhEo5psQgGbvHwe2IkHncg
提取码:rp5r

3 个赞

林总居然光临咱们90sec,厉害 :kissing_heart:

嫌弃我辣鸡咯?大佬带带我

我嫌弃自己没被林总带,ddddhm :kissing_heart:

大佬,我自己本地复现写了一个同样的脚本,但是当重复请求此页面多次之后会出现IP被拉黑的情况,不知道楼主出现过吗?

github 有时候会被禁止访问 你换国外的IP访问会稳定点

哦哦,看来应该是这个问题,我说怎么我隔30分钟去访问还是拉黑