forked from EXP-Tools/threat-broadcast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·145 lines (108 loc) · 3.78 KB
/
main.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : EXP
# @Time : 2020/4/25 22:17
# @File : main.py
# -----------------------------------------------
import sys
from src.cfg import env
from src.utils import log
from src.utils._sqlite import SqliteDBC
from src.crawler.cert360 import Cert360
from src.crawler.nsfocus import Nsfocus
from src.crawler.qianxin import QiAnXin
from src.crawler.redqueen import RedQueen
from src.crawler.anquanke import AnQuanKe
from src.crawler.vas import Vas
from src.crawler.nvd import NVD
from src.crawler.cnvd import CNVD
from src.crawler.cnnvd import CNNVD
from src.crawler.tenable import Tenable
import src.notice.page as page
import src.notice.mail as mail
import src.notice.qq as qq
import src.notice.wechat as wechat
import src.utils._git as git
def help_info():
return '''
-h 帮助信息
-top <number> 播报时每个来源最多取最新的前 N 个 CVE(默认 10)
-ac 自动提交变更到仓库(可自动归档、生成 Github Page,默认关闭)
-gtk Github Token,若非空值则使用 Github Actions 发送播报邮件
-ms <mail-smtp> 用于发送播报信息的邮箱 SMTP 服务器(默认 smtp.126.com)
-mu <mail-user> 用于发送播报信息的邮箱账号(默认 [email protected])
-mp <mail-pass> 用于发送播报信息的邮箱密码(部分邮箱为授权码)
-qu <qq-user> 用于向 QQ 群发送播报信息的 QQ 账号
-qp <qq-pass> 用于发送播报信息的 QQ 密码
'''
def init():
log.init()
sdbc = SqliteDBC(env.DB_PATH)
sdbc.init(env.SQL_PATH)
def main(help, top, auto_commit, gtk, mail_smtp, mail_user, mail_pass, qq_user, qq_pass):
if help:
log.info(help_info())
else:
all_cves = {}
srcs = [ Cert360(), Nsfocus(), QiAnXin(), RedQueen(), AnQuanKe(), Vas(), NVD(), CNVD(), CNNVD(), Tenable() ]
for src in srcs:
cves = src.cves()
if cves:
to_log(cves)
all_cves[src] = cves
if all_cves:
page.to_page(top)
mail.to_mail(gtk, all_cves, mail_smtp, mail_user, mail_pass)
qq.to_group(all_cves, qq_user, qq_pass)
wechat.to_wechat(all_cves)
if auto_commit:
git.auto_commit()
def to_log(cves):
for cve in cves :
log.info(cve.to_msg())
def get_sys_args(sys_args) :
help = False
top = 30
auto_commit = False
gtk = ''
mail_smtp = 'smtp.qq.com'
mail_user = '[email protected]'
mail_pass = ''
qq_user = ''
qq_pass = ''
idx = 1
size = len(sys_args)
while idx < size :
try :
if sys_args[idx] == '-h' :
help = True
elif sys_args[idx] == '-top' :
idx += 1
top = int(sys_args[idx])
elif sys_args[idx] == '-ac' :
auto_commit = True
elif sys_args[idx] == '-gtk' :
idx += 1
gtk = sys_args[idx]
elif sys_args[idx] == '-ms' :
idx += 1
mail_smtp = sys_args[idx]
elif sys_args[idx] == '-mu' :
idx += 1
mail_user = sys_args[idx]
elif sys_args[idx] == '-mp' :
idx += 1
mail_pass = sys_args[idx]
elif sys_args[idx] == '-qu' :
idx += 1
qq_user = sys_args[idx]
elif sys_args[idx] == '-qp' :
idx += 1
qq_pass = sys_args[idx]
except :
pass
idx += 1
return help, top, auto_commit, gtk, mail_smtp, mail_user, mail_pass, qq_user, qq_pass
if __name__ == '__main__':
init()
main(*get_sys_args(sys.argv))