-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathinit.py
319 lines (296 loc) · 14.3 KB
/
init.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @author: orleven
import asyncio
import warnings
from argparse import ArgumentParser
from sqlalchemy.sql import text
from sqlalchemy.ext.asyncio import create_async_engine
from lib.core.g import conf
from lib.core.g import mysql
from lib.core.g import async_engine
from lib.core.g import async_session
from lib.core.model import Base
from lib.core.model import User
from lib.core.model import DictPassword
from lib.core.model import DictUsername
from lib.core.model import ScanBlack
from lib.core.model import ScanWhite
from lib.core.model import VulFilter
from lib.core.enums import ScanMatchPosition
from lib.core.enums import ScanMatchType
from lib.core.enums import UserRole
from lib.util.util import get_time
from lib.util.util import random_string
warnings.filterwarnings("ignore", module=r"aiomysql")
async def create_table(flag=False):
"""
创建数据库、表结构
:return:
"""
# 创建数据库
async_sqlalchemy_database_url_without_db = mysql.get_async_sqlalchemy_database_url_without_db()
temp_async_engine = create_async_engine(async_sqlalchemy_database_url_without_db)
async with temp_async_engine.begin() as session:
await session.execute(text(f"CREATE DATABASE IF NOT EXISTS `{mysql.dbname}` CHARACTER SET {mysql.charset} COLLATE {mysql.collate};"))
await session.commit()
# 初始化表结构
async with async_engine.begin() as session:
if flag:
await session.run_sync(Base.metadata.drop_all)
await session.run_sync(Base.metadata.create_all)
await session.commit()
async def init_filter_list():
filter_list = [
{"match_position": ScanMatchPosition.RESPONSE_BODY, "value": u'g.alicdn.com/sd/punish/waf_block', "match_type": ScanMatchType.IN},
]
async with async_session.begin() as session:
for filter in filter_list:
match_position = filter["match_position"]
value = filter["value"]
match_type = filter["match_type"]
update_time = get_time()
filter = VulFilter(match_position=match_position, value=value, match_type=match_type,
update_time=update_time)
session.add(filter)
await session.commit()
async def init_black_list():
black_list = [
{"match_position": ScanMatchPosition.PATH, "value": u"/wp-", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.PATH, "value": u".min.js", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.PATH, "value": u"/docs/", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.PATH, "value": u"/examples/jsp/", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.PATH, "value": u".css", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.PATH, "value": u".svg", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.PATH, "value": u"/gitbook/", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.PATH, "value": u"/resource/upload/", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"firefox.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"firefoxchina.cn", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"mozilla.org", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"mozilla.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"mozilla.net", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"g-fox.cn", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"gitee.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"portswigger.net", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"google.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"google-analytics.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"googletagmanager.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"googleusercontent.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"googleapis.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"trackingio.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"github.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"githubassets.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"gitlab.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"getui.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"gov.cn", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"org.cn", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"123cha.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"edu.cn", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"cnzz.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"189.cn", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": u"360buyimg.com", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.URL, "value": u"?amp;", "match_type": ScanMatchType.EQUAL},
{"match_position": ScanMatchPosition.HOST, "value": "localhost", "match_type": ScanMatchType.EQUAL},
{"match_position": ScanMatchPosition.HOST, "value": "127.0.0.1", "match_type": ScanMatchType.EQUAL},
{"match_position": ScanMatchPosition.METHOD, "value": "DELETE", "match_type": ScanMatchType.EQUAL},
{"match_position": ScanMatchPosition.METHOD, "value": "OPTIONS", "match_type": ScanMatchType.EQUAL},
{"match_position": ScanMatchPosition.METHOD, "value": "CONNECT", "match_type": ScanMatchType.EQUAL},
{"match_position": ScanMatchPosition.HOST, "value": ".*\d{5}.cn", "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.PATH, "value": ".*refresh.*", "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.PATH, "value": ".*delete.*", "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.PATH, "value": ".*clear.*", "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.PATH, "value": '.*insert.*', "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.PATH, "value": '.*create.*', "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.PATH, "value": '.*save.*', "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.PATH, "value": '.*remove.*', "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.PATH, "value": "(/\S+)\1/", "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.PATH, "value": u"/\d{4}/\d{2}/\d{2}/", "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.URL, "value": '^(http|https)://10\..*', "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.URL, "value": '^(http|https)://100\..*', "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.URL, "value": '^(http|https)://172\..*', "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.URL, "value": '^(http|https)://192\..*', "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.HOST, "value": conf.platform.dnslog_top_domain, "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": "oast.fun","match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": "oast.site", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": "oast.online", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": "oast.live", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": "oast.pro", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.HOST, "value": "oast.me", "match_type": ScanMatchType.IN},
]
async with async_session.begin() as session:
for black in black_list:
match_position = black["match_position"]
value = black["value"]
match_type = black["match_type"]
update_time = get_time()
if value != '':
black = ScanBlack(match_position=match_position, value=value, match_type=match_type, update_time=update_time)
session.add(black)
await session.commit()
async def init_white_list():
white_list = [
{"match_position": ScanMatchPosition.HOST, "value": ".", "match_type": ScanMatchType.IN},
{"match_position": ScanMatchPosition.URL, "value": '^(http|https)://10\..*', "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.URL, "value": '^(http|https)://100\..*', "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.URL, "value": '^(http|https)://172\..*', "match_type": ScanMatchType.REGEX},
{"match_position": ScanMatchPosition.URL, "value": '^(http|https)://192\..*', "match_type": ScanMatchType.REGEX},
]
async with async_session.begin() as session:
for white in white_list:
match_position = white["match_position"]
value = white["value"]
match_type = white["match_type"]
update_time = get_time()
if value != '':
white = ScanWhite(match_position=match_position, value=value, match_type=match_type, update_time=update_time)
session.add(white)
await session.commit()
async def init_username_list():
username_list = [
"admin",
"tomcat",
"manager",
"role",
"security",
"administrator",
"super",
"root",
"web",
"test",
"test1",
"test2",
"test123",
"guest",
"user",
"user1",
"user2",
"user123",
]
async with async_session.begin() as session:
for value in username_list:
update_time = get_time()
username_data = DictUsername(value=value, update_time=update_time)
session.add(username_data)
await session.commit()
async def init_password_list():
password_list = [
"%user%",
"%user%123",
"%user%1234",
"%user%123456",
"%user%12345",
"%user%888",
"%user%@123",
"%user%@123456",
"%user%@12345",
"%user%#123",
"%user%#123456",
"%user%#12345",
"%user%_123",
"%user%_123456",
"%user%_12345",
"%user%123!@#",
"%user%!@#$",
"%user%!@#",
"%user%~!@",
"%user%!@#123",
"%user%2017",
"%user%2016",
"%user%2015",
"%user%2018",
"%user%2019",
"%user%2020",
"%user%2021",
"%user%2022",
"%user%2023",
"%user%2024",
"%user%2025",
"%user%@2019",
"%user%@2020",
"%user%@2021",
"%user%@2022",
"%user%@2023",
"%user%@2024",
"%user%@2025",
"%user%@2018",
"%user%@2017",
"%user%@2016",
"%user%@2015",
"Passw0rd",
"tomcat",
"123456",
"password",
"123",
"1",
"123123",
"1q2w3e4r",
"1qaz2wsx",
"1qaz@WSX",
"1qazXSW@123",
"1qaz2wsx#EDC",
"123qwe",
"123qaz",
"111111",
"Aa123456",
"123456qwerty",
"qwer1234",
"12345678",
"1q2w3e",
"abc123",
"123456789",
"q1w2e3r4",
"abcd1234",
]
async with async_session.begin() as session:
for value in password_list:
update_time = get_time()
password_data = DictPassword(value=value, update_time=update_time)
session.add(password_data)
await session.commit()
async def init_user():
default_mail_siffix = conf.basic.default_mail_siffix
user_list = [
{"email": f"admin@{default_mail_siffix}", "description": u"administrator", "username": "admin", "role": UserRole.ADMIN},
]
async with async_session.begin() as session:
for user in user_list:
email = user["email"]
username = user["username"]
description = user["description"]
role = user["role"]
update_time = get_time()
user = User(email=email, username=username, description=description, role=role, update_time=update_time, api_key=random_string(32))
user.password = user.generate_password_hash(conf.basic.default_password)
session.add(user)
await session.commit()
async def run(args):
"""
运行相关初始化函数
:return:
"""
await create_table()
await init_user()
await init_filter_list()
await init_black_list()
await init_white_list()
await init_username_list()
await init_password_list()
def main(args):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
loop.run_until_complete(run(args))
except KeyboardInterrupt:
pass
def arg_set(parser):
parser.add_argument("-d", "--debug", action='store_true', help="Run debug", default=False)
parser.add_argument("-h", "--help", action='store_true', help="Show help", default=False)
return parser
if __name__ == '__main__':
parser = ArgumentParser(add_help=False)
parser = arg_set(parser)
args = parser.parse_args()
if args.help:
parser.print_help()
else:
main(args)