-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbot.py
109 lines (100 loc) · 4.1 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import json
from xmlrpc.client import Boolean
import requests
from utils import Color
class feishuBot:
"""飞书群机器人
https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN
"""
def __init__(self, key, proxy_url='') -> None:
self.key = key
self.proxy = {'http': proxy_url, 'https': proxy_url} if proxy_url else {'http': None, 'https': None}
def make_card(self, hit: bool, cve: dict):
vendor = product = None
if vendors := cve['vendors']:
vendor = vendors[0]['vendor']
product = vendors[0]['products'][0]['product']
publishedDate = cve['publishedDate'][:10] if cve['publishedDate'] else None
lastModifiedDate = cve['lastModifiedDate'][:10] if cve['lastModifiedDate'] else None
epss_score = '{:.2%}'.format(float(cve['epss_score'] or 0))
vendor_advisories = cve['vendor_advisories'][0] if cve['vendor_advisories'] else None
github = '\n'.join([i['url'] for i in cve['github_repos']])
reddit = '\n'.join([i['reddit_url'] for i in cve['reddit_posts']])
twitter = '\n'.join([f'https://twitter.com/{i["twitter_user_handle"]}/status/{i["tweet_id"]}' for i in cve['tweets']])
card = {
'header': {
'template': 'red' if hit else 'orange',
'title': {
'content': f'【漏洞情报】{cve["cve"]} | {vendor} - {product}',
'tag': 'plain_text'
}
},
'elements': [
{
'tag': 'div',
'fields': [
{
'is_short': True,
'text': {
'content': f'**漏洞时间**\n公开:{publishedDate}\n更新:{lastModifiedDate}',
'tag': 'lark_md'
}
},
{
'is_short': True,
'text': {
'content': f'**漏洞等级**\nCVSS:{cve["severity"]}\nEPSS:{epss_score}',
'tag': 'lark_md'
}
}
]
},
{
'tag': 'div',
'text': {
'content': f'**漏洞公告**\nhttps://nvd.nist.gov/vuln/detail/{cve["cve"]}\n{vendor_advisories}',
'tag': 'lark_md'
}
},
{
'tag': 'div',
'text': {
'content': f'**漏洞概要**\n{cve["description"]}',
'tag': 'lark_md'
}
},
{
'tag': 'div',
'text': {
'content': f'**GitHub**\n{github}',
'tag': 'lark_md'
}
},
{
'tag': 'div',
'text': {
'content': f'**Reddit**\n{reddit}',
'tag': 'lark_md'
}
},
{
'tag': 'div',
'text': {
'content': f'**Twitter**\n{twitter}',
'tag': 'lark_md'
}
}
]
}
return card
def send(self, cves: list):
for cve in cves:
data = {'msg_type': 'interactive', 'card': self.make_card(cve[0], cve[1])}
headers = {'Content-Type': 'application/json'}
url = f'https://open.feishu.cn/open-apis/bot/v2/hook/{self.key}'
r = requests.post(url=url, headers=headers, data=json.dumps(data), proxies=self.proxy)
if r.status_code == 200:
Color.print_success(f'[+] feishuBot 发送成功 {cve[1]["cve"]}')
else:
Color.print_failed(f'[-] feishuBot 发送失败 {cve[1]["cve"]}')
print(r.text)