commit
This commit is contained in:
commit
cfba2070b0
44
README.md
Normal file
44
README.md
Normal file
@ -0,0 +1,44 @@
|
||||
# github-cve-monitor
|
||||
|
||||
## 监控github上新增的cve编号项目漏洞,推送钉钉或者server酱
|
||||
|
||||
|
||||
|
||||
python3 -m pip install dingtalkchatbot
|
||||
|
||||
每3分钟检测一次github是否有新的cve漏洞提交记录,若有则通过server酱和钉钉机器人推送(二者配置一个即可)
|
||||
|
||||
时间间隔修改在 58 行
|
||||
|
||||
建议使用[screen命令](https://www.runoob.com/linux/linux-comm-screen.html)运行在自己的linux vps后台上,就可以愉快的接收各种cve了
|
||||
|
||||
```bash
|
||||
screen -S github_cve #创建一个screen,名字为github_cve,在新窗口运行本项目, 成功后直接叉掉该窗口, 项目就会在后台一直运行了
|
||||
|
||||
screen -ls #查看创建的screen
|
||||
|
||||
screen -r github_cve #连接github_cve后台screen,如果存在的话
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
钉钉机器人配置在 33行的 dingding函数中,需要钉钉建群,添加钉钉机器人,复制 webhook 替换即可
|
||||
|
||||
server酱配置在 40行的 server 函数中,ps:因微信的原因,server酱的旧版将在2021年4月后下线,新版以企业微信为主,这里使用的是旧版,想改新版的话,搞个企业微信,从新配置server酱,使用新链接 sctapi.ftqq.com
|
||||
|
||||
具体查看server酱官方,http://sc.ftqq.com/ ,配置简单,只需要将脚本中的uri换掉即可
|
||||
|
||||
[server酱新版](https://sct.ftqq.com/)支持多通道(微信、客户端、群机器人、邮件和短信)
|
||||
|
||||
## 效果图
|
||||
|
||||
![image-20210225090416314](images/image-20210225090416314.png)
|
||||
|
||||
![image-20210225090811212](images/image-20210225090811212.png)
|
||||
|
||||
![image-20210225092350481](images/image-20210225092350481.png)
|
||||
|
||||
参考 [洛米唯熊](https://my.oschina.net/u/4581868/blog/4380482)、[kiang70](https://github.com/kiang70/Github-Monitor)
|
||||
|
78
github_cve_monitor.py
Normal file
78
github_cve_monitor.py
Normal file
@ -0,0 +1,78 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding:utf-8 -*-
|
||||
# @Author : yhy
|
||||
|
||||
# 每3分钟检测一次github是否有新的cve漏洞提交记录,若有则通过server酱和钉钉机器人推送(二者配置一个即可)
|
||||
# 建议使用screen命令运行在自己的linux vps后台上,就可以愉快的接收各种cve了
|
||||
|
||||
# https://my.oschina.net/u/4581868/blog/4380482
|
||||
# https://github.com/kiang70/Github-Monitor
|
||||
|
||||
import urllib
|
||||
import requests,re,time
|
||||
import dingtalkchatbot.chatbot as cb
|
||||
import datetime
|
||||
|
||||
|
||||
def getNews():
|
||||
try:
|
||||
# 抓取本年的
|
||||
year = datetime.datetime.now().year
|
||||
api = "https://api.github.com/search/repositories?q=CVE-{}&sort=updated".format(year)
|
||||
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 dingding(text, msg):
|
||||
# 将此处换为钉钉机器人的api
|
||||
webhook = 'xxxxx'
|
||||
ding = cb.DingtalkChatbot(webhook)
|
||||
ding.send_text(msg='{}\r\n{}'.format(text, msg), is_at_all=False)
|
||||
|
||||
# server酱 http://sc.ftqq.com/?c=code
|
||||
def server(text, msg):
|
||||
# 将 xxxx 换成自己的server SCKEY
|
||||
uri = 'https://sc.ftqq.com/xxxx.send?text={}&desp={}'.format(text, msg)
|
||||
send = requests.get(uri)
|
||||
|
||||
|
||||
def sendNews():
|
||||
try:
|
||||
while True:
|
||||
print("cve 监控中 ...")
|
||||
# 抓取本年的
|
||||
year = datetime.datetime.now().year
|
||||
api = "https://api.github.com/search/repositories?q=CVE-{}&sort=updated".format(year)
|
||||
#请求API
|
||||
req = requests.get(api).text
|
||||
#正则获取
|
||||
total_count=re.findall ('"total_count":*.{1,10}"incomplete_results"',req)[0][14:17]
|
||||
#监控时间间隔3分钟
|
||||
time.sleep(180)
|
||||
#推送正文内容
|
||||
msg = str(getNews())
|
||||
#推送标题
|
||||
text = r'有新的CVE送达!'
|
||||
|
||||
# 检查是否更新
|
||||
if total_count!=getNews()[0]:
|
||||
# 二选一即可,没配置的 注释或者删掉
|
||||
server(text, msg)
|
||||
dingding(text, msg)
|
||||
print(msg)
|
||||
else:
|
||||
pass
|
||||
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sendNews()
|
BIN
images/image-20210225090416314.png
Normal file
BIN
images/image-20210225090416314.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 141 KiB |
BIN
images/image-20210225090811212.png
Normal file
BIN
images/image-20210225090811212.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 550 KiB |
BIN
images/image-20210225092350481.png
Normal file
BIN
images/image-20210225092350481.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 454 KiB |
Loading…
Reference in New Issue
Block a user