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()
二、通过延迟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()
成果截图
0x02:后话
其实网上很多大佬写的工具都挺好的,但是我们不能只会用别人的工具,我们应该学会自己写工具.自己慢慢的完善自己的不足之处,才能跟上大佬们的脚步,不是么?
根据以上的代码还可以改成RCE脚本的监控,或者两者一起推送.看个人的喜好,可随意增加
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有