-
Notifications
You must be signed in to change notification settings - Fork 0
/
CXX.py
367 lines (332 loc) · 15.8 KB
/
CXX.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
import requests
import string
import signal
import sys
import os
import re
import urllib
from bs4 import BeautifulSoup
class CXX:
def __init__(self, TARGET_URL, TARGET_METHOD):
self.ASSET_EXT = ['pdf', 'png', 'jpg', 'jpeg', 'gif', 'bmp', 'svg', 'ico', 'webp', 'mp3', 'mp4', 'ogg', 'wav', 'flac', 'aac', 'wma', 'm4a', 'm4v', 'mov', 'wmv', 'avi', 'mpg', 'mpeg', 'mkv', '3gp', '3g2', 'm4v', 'm4p', 'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p',
'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'm4s', 'm4v', 'm4a', 'm4p', 'm4b', 'm4r']
self.SOURCE_EXT = ['js', 'css']
self.TARGET_METHOD = "OPTIONS"
self.TARGET_URL = TARGET_URL
self.BAD_URL = TARGET_URL
self.URL_SECURITY_STRUCT = dict()
self.URL_KEYWORD_STRUCT = dict()
self.DOMAIN = list()
self.URL_TEXT = "" # url parser text
self.URL_ASSET_TEXT = ""
self.URL_SOURCE_TEXT = ""
self.URL_INNER_SCRIPT = ""
self.PROXIES = {
'http': 'socks5h://127.0.0.1:9050',
'https': 'socks5h://127.0.0.1:9050'
}
# [API:INNER] TARGET_URL schema check
def schema_check(self, url):
try:
if ((url.find(self.BAD_URL) != -1) and (url.find("https")) != -1):
return url
elif (url.find('http') | url.find('https')) == -1:
url = self.TARGET_URL + url
return url
except:
return url
# [API:INNER] method check
def cehck_method(self):
print(f"[*] Method check")
try:
for i in self.URL_TEXT.split('\n'):
try:
print(i)
res_opt = requests.options(i, proxies=self.PROXIES)
except:
print(f"EXCEPT: {res_opt.url}")
continue
headers = res_opt.headers
# key-value
self.URL_SECURITY_STRUCT[i] = {
"SECURITY": {}, "COOKIE": {}, "ENV": {}, "EXTEND": {}}
self.security_check(
g_url_sec_check_dict=self.URL_SECURITY_STRUCT, urlName=i, url=headers)
for i in self.URL_ASSET_TEXT.split('\n'):
try:
res_opt = requests.options(i, proxies=self.PROXIES)
except:
print(f"EXCEPT: {res_opt.url}")
continue
headers = res_opt.headers
# key-value
self.URL_SECURITY_STRUCT[i] = {
"SECURITY": {}, "COOKIE": {}, "ENV": {}, "EXTEND": {}}
self.security_check(
g_url_sec_check_dict=self.URL_SECURITY_STRUCT, urlName=i, url=headers)
for i in self.URL_SOURCE_TEXT.split('\n'):
try:
res_opt = requests.options(i, proxies=self.PROXIES)
except:
print(f"EXCEPT: {res_opt.url}")
continue
headers = res_opt.headers
# key-value
self.URL_SECURITY_STRUCT[i] = {
"SECURITY": {}, "COOKIE": {}, "ENV": {}, "EXTEND": {}}
self.security_check(
g_url_sec_check_dict=self.URL_SECURITY_STRUCT, urlName=i, url=headers)
except:
pass
# security check pattern with re
def security_check(self, g_url_sec_check_dict, urlName, url={}):
try:
for url_key, url_value in url.items():
# iframe security check pattern "X-Frame-Options"
if (url_key.find("X-Frame-Options") != -1):
g_url_sec_check_dict[urlName]["SECURITY"]["X-Frame-Options"] = url_value
# content security policy "Content-Security-Policy"
elif (url_key.find("Content-Security-Policy") != -1):
g_url_sec_check_dict[urlName]["SECURITY"]["Content-Security-Policy"] = url_value
# X-XSS-Protection
elif (url_key.find("X-XSS-Protection") != -1):
g_url_sec_check_dict[urlName]["SECURITY"]["X-XSS-Protection"] = url_value
# Access-Control-Allow-Origin
elif (url_key.find("Access-Control-Allow-Origin") != -1):
g_url_sec_check_dict[urlName]["SECURITY"]["Access-Control-Allow-Origin"] = url_value
# Access-Control-Allow-Credentials
elif (url_key.find("Access-Control-Allow-Credentials") != -1):
g_url_sec_check_dict[urlName]["SECURITY"]["Access-Control-Allow-Credentials"] = url_value
# Access-Control-Expose-Headers
elif (url_key.find("Access-Control-Expose-Headers") != -1):
g_url_sec_check_dict[urlName]["SECURITY"]["Access-Control-Expose-Headers"] = url_value
# Access-Control-Max-Age
elif (url_key.find("Access-Control-Max-Age") != -1):
g_url_sec_check_dict[urlName]["SECURITY"]["Access-Control-Max-Age"] = url_value
# Access-Control-Allow-Methods
elif (url_key.find("Access-Control-Allow-Methods") != -1):
g_url_sec_check_dict[urlName]["SECURITY"]["Access-Control-Allow-Methods"] = url_value
# Access-Control-Allow-Headers
elif (url_key.find("Access-Control-Allow-Headers") != -1):
g_url_sec_check_dict[urlName]["SECURITY"]["Access-Control-Allow-Headers"] = url_value
# COOP: Cross-Origin-Opener-Policy
elif (url_key.find("Cross-Origin-Opener-Policy") != -1):
g_url_sec_check_dict[urlName]["SECURITY"]["Cross-Origin-Opener-Policy"] = url_value
# Server
elif (url_key.find("Server") != -1):
g_url_sec_check_dict[urlName]["ENV"]["Server"] = url_value
# Allow method
elif (url_key.find("Allow") != -1):
g_url_sec_check_dict[urlName]["ENV"]["Allow-Methid"] = url_value
# setCookies
elif (url_key.find("set-cookie") != -1):
g_url_sec_check_dict[urlName]["COOKIE"]["set-cookie"] = url_value
except:
pass
# print(self.URL_SECURITY_STRUCT)
# csp check
def csp_check(self):
print("[*] CSP check")
for url_key, url_value in self.URL_SECURITY_STRUCT.items():
if url_value["SECURITY"].get("Content-Security-Policy") is not None:
_ = (url_value['SECURITY']
['Content-Security-Policy']).split('\';')
print(_)
# inner script gadget find
def inner_script_gadget(self):
# value of url_sec_check dict key
try:
for url_key, url_value in self.URL_SECURITY_STRUCT.items():
if url_value["SECURITY"].get("X-XSS-Protection") is None or url_value["SECURITY"].get("X-XSS-Protection") == "0":
req = requests.get(url_key, proxies=self.PROXIES)
soup = BeautifulSoup(req.text, 'html.parser')
for script in soup.find_all('script'):
self.URL_INNER_SCRIPT += f"[**]//[host]:{url_key}[/host]\n<script>{script.text}</script>[**]\n"
else:
pass
except:
pass
# requests response text find regex pattern
# onion url = s4k4ceiapwwgcm3mkb6e4diqecpo7kvdnfr5gg7sph7jjppqkvwwqtyd.onion
def keyword_check_gadget(self, _url):
regex_telegram = r'''(?:@|(?:(?:(?:https?://)?t(?:elegram)?)\.me\/))(\w{4,})$'''
regex_bank = r'''^\d{5}\-\d{5}\-\d{3,12}$'''
regex_number = r'''\\b[(0-9)]{10,20}\\b'''
# string "call", "contact", "phone", "real money" regex pattern
regex_keyword = r'''(call|contact|phone|real money|drug)'''
regex_email = r'''((?!\.)[\w-_.]*[^.])(@\w+)(\.\w+(\.\w+)?[^.\W])$'''
regex_url = r'''(http(s)?:\/\/)([a-z0-9\w]+\.*)+[a-z0-9]{2,4}'''
# chain
regex_bitcoinCash = r'''((bitcoincash:)?(q|p)[a-z0-9]{41})'''
regex_eth = r'''0x[a-fA-F0-9]{40}$'''
regex_btc = r'''[13][a-km-zA-HJ-NP-Z1-9]{25,34}$'''
regex_dash = r'''[1-9A-HJ-NP-Za-km-z]{33}$'''
regex_xmr = r'''[0-9AB][1-9A-HJ-NP-Za-km-z]{93}$'''
try:
req = requests.get(_url, proxies=self.PROXIES)
_content = req.text
_reSearchData = re.search(regex_keyword, _content)
# keyword check
if _reSearchData is not none:
# _reSearchData parser content
_reSearchData = _reSearchData.group()
print(_reSearchData)
# print(req.text)
# telegram
# if re.search(regex_telegram, req.text):
# self.URL_KEYWORD_STRUCT[_url]["TELEGRAM"] = re.findall(
# regex_telegram, req.text)
# # bank
# if re.search(regex_bank, req.text):
# self.URL_KEYWORD_STRUCT[_url]["BANK"] = re.findall(
# regex_bank, req.text)
# # number
# if re.search(regex_number, req.text):
# self.URL_KEYWORD_STRUCT[_url]["NUMBER"] = re.findall(
# regex_number, req.text)
# # keyword
# if re.search(regex_keyword, req.text):
# self.URL_KEYWORD_STRUCT[_url]["KEYWORD"] = re.findall(
# regex_keyword, req.text)
# # email
# if re.search(regex_email, req.text):
# self.URL_KEYWORD_STRUCT[_url]["EMAIL"] = re.findall(
# regex_email, req.text)
# # url
# if re.search(regex_url, req.text):
# self.URL_KEYWORD_STRUCT[_url]["URL"] = re.findall(
# regex_url, req.text)
# # bitcoin cash
# if re.search(regex_bitcoinCash, req.text):
# self.URL_KEYWORD_STRUCT[_url]["BITCOIN_CASH"] = re.findall(
# regex_bitcoinCash, req.text)
# # eth
# if re.search(regex_eth, req.text):
# self.URL_KEYWORD_STRUCT[_url]["ETH"] = re.findall(
# regex_eth, req.text)
# # btc
# if re.search(regex_btc, req.text):
# self.URL_KEYWORD_STRUCT[_url]["BTC"] = re.findall(
# regex_btc, req.text)
# # dash
# if re.search(regex_dash, req.text):
# self.URL_KEYWORD_STRUCT[_url]["DASH"] = re.findall(
# regex_dash, req.text)
# # xmr
# if re.search(regex_xmr, req.text):
# self.URL_KEYWORD_STRUCT[_url]["XMR"] = re.findall(
# regex_xmr, req.text)
# print(self.URL_KEYWORD_STRUCT)
except:
pass
# subdomain parser
def subdomain_parser(self):
print("[*] Subdomain parser")
# hostname filter
for i in ((self.URL_ASSET_TEXT).split('\n')):
try:
self.DOMAIN.append(((i).split("/"))[2])
except:
continue
for i in ((self.URL_SOURCE_TEXT).split('\n')):
try:
self.DOMAIN.append(((i).split("/"))[2])
except:
continue
for i in ((self.URL_TEXT).split('\n')):
try:
self.DOMAIN.append(((i).split("/"))[2])
except:
continue
print(list(set(self.DOMAIN)))
# cookie parser
def cookie_parser(self):
print("[*] Cookie parser")
# self.URL_SECURITY_STRUCT
for url_key, url_value in self.URL_SECURITY_STRUCT.items():
if url_value["COOKIE"].get("set-cookie") is not None:
print(url_value["COOKIE"]["set-cookie"])
# [API] TARGET_URL in ALL URL
def get_all_url_parse(self):
print("=========================================== START ===========================================")
try:
req = requests.get(self.TARGET_URL, proxies=self.PROXIES)
print(req)
# response statuc code check 400, 500 is return
if req.status_code == 400 or req.status_code == 500:
return
saveHtml = req.text
soup = BeautifulSoup(saveHtml, 'html.parser')
current_url = []
src_list = ["audio", "embed", "iframe", "img",
"input", "script", "source", "track", "video"]
src_allow_list = []
for i in src_list:
if saveHtml.find(i) != -1:
src_allow_list.append(i)
for i in src_allow_list:
for j in soup.find_all(i):
_j = j.get('src')
if _j is not None:
# print(_j)
# print(self.schema_check(_j))
current_url.append(self.schema_check(_j))
# href parser
for link in soup.find_all('a'):
# filter is not http and https
_f = link.get('href')
if _f is not None:
# print(self.schema_check(_f))
current_url.append(self.schema_check(_f))
# multiple remove url
current_url = list(set(current_url))
current_decode_url = []
# if url encode, decode url
for i in current_url:
try:
# print(i)
# print(urllib.parse.unquote(i))
current_decode_url.append(urllib.parse.unquote(i))
except:
current_decode_url.append(i)
# multiple url search
http_cnt = 0
https_cnt = 0
# counting http and https miu
for i in current_decode_url:
result = [(g.start(), g.group()) for g in re.compile(r'(http://|https://)').finditer(i)]
if len(result) > 1:
for j in result:
if j[1] == "http://":
http_cnt += 1
elif j[1] == "https://":
https_cnt += 1
# counting check
if (http_cnt > 1 or https_cnt > 1):
for x in result:
if (x[0] == 0):
continue
elif (x[0] > 1):
current_decode_url.append(i[:x[0]])
current_decode_url.append(i[x[0]:])
current_decode_url.remove(i)
current_url = list(set(current_decode_url))
# check asset ext is in list
for i in current_url:
block = i.split(".")
print(i)
for j in block:
if j in self.ASSET_EXT:
self.URL_ASSET_TEXT += f"{i}\n"
current_url.remove(i)
if j in self.SOURCE_EXT:
self.URL_SOURCE_TEXT += f"{i}\n"
current_url.remove(i)
for i in current_url:
print(i)
self.keyword_check_gadget(i)
self.URL_TEXT += i + "\n"
print(f"====================== finish ======================")
except Exception as e:
print(e)
pass