Skip to content

Commit c68e26a

Browse files
committedJul 15, 2024
init
init
1 parent c486fcb commit c68e26a

File tree

6 files changed

+124924
-1
lines changed

6 files changed

+124924
-1
lines changed
 

‎.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
doc
2+
.DS_Store
3+
4+
15
# Byte-compiled / optimized / DLL files
26
__pycache__/
37
*.py[cod]

‎LICENSE

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
Apache License
2+
Version 2.0, January 2004
3+
http://www.apache.org/licenses/
4+
5+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6+
7+
1. Definitions.
8+
9+
"License" shall mean the terms and conditions for use, reproduction,
10+
and distribution as defined by Sections 1 through 9 of this document.
11+
12+
"Licensor" shall mean the copyright owner or entity authorized by
13+
the copyright owner that is granting the License.
14+
15+
"Legal Entity" shall mean the union of the acting entity and all
16+
other entities that control, are controlled by, or are under common
17+
control with that entity. For the purposes of this definition,
18+
"control" means (i) the power, direct or indirect, to cause the
19+
direction or management of such entity, whether by contract or
20+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
21+
outstanding shares, or (iii) beneficial ownership of such entity.
22+
23+
"You" (or "Your") shall mean an individual or Legal Entity
24+
exercising permissions granted by this License.
25+
26+
"Source" form shall mean the preferred form for making modifications,
27+
including but not limited to software source code, documentation
28+
source, and configuration files.
29+
30+
"Object" form shall mean any form resulting from mechanical
31+
transformation or translation of a Source form, including but
32+
not limited to compiled object code, generated documentation,
33+
and conversions to other media types.
34+
35+
"Work" shall mean the work of authorship, whether in Source or
36+
Object form, made available under the License, as indicated by a
37+
copyright notice that is included in or attached to the work
38+
(an example is provided in the Appendix below).
39+
40+
"Derivative Works" shall mean any work, whether in Source or Object
41+
form, that is based on (or derived from) the Work and for which the
42+
editorial revisions, annotations, elaborations, or other modifications
43+
represent, as a whole, an original work of authorship. For the purposes
44+
of this License, Derivative Works shall not include works that remain
45+
separable from, or merely link (or bind by name) to the interfaces of,
46+
the Work and Derivative Works thereof.
47+
48+
"Contribution" shall mean any work of authorship, including
49+
the original version of the Work and any modifications or additions
50+
to that Work or Derivative Works thereof, that is intentionally
51+
submitted to Licensor for inclusion in the Work by the copyright owner
52+
or by an individual or Legal Entity authorized to submit on behalf of
53+
the copyright owner. For the purposes of this definition, "submitted"
54+
means any form of electronic, verbal, or written communication sent
55+
to the Licensor or its representatives, including but not limited to
56+
communication on electronic mailing lists, source code control systems,
57+
and issue tracking systems that are managed by, or on behalf of, the
58+
Licensor for the purpose of discussing and improving the Work, but
59+
excluding communication that is conspicuously marked or otherwise
60+
designated in writing by the copyright owner as "Not a Contribution."
61+
62+
"Contributor" shall mean Licensor and any individual or Legal Entity
63+
on behalf of whom a Contribution has been received by Licensor and
64+
subsequently incorporated within the Work.
65+
66+
2. Grant of Copyright License. Subject to the terms and conditions of
67+
this License, each Contributor hereby grants to You a perpetual,
68+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69+
copyright license to reproduce, prepare Derivative Works of,
70+
publicly display, publicly perform, sublicense, and distribute the
71+
Work and such Derivative Works in Source or Object form.
72+
73+
3. Grant of Patent License. Subject to the terms and conditions of
74+
this License, each Contributor hereby grants to You a perpetual,
75+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76+
(except as stated in this section) patent license to make, have made,
77+
use, offer to sell, sell, import, and otherwise transfer the Work,
78+
where such license applies only to those patent claims licensable
79+
by such Contributor that are necessarily infringed by their
80+
Contribution(s) alone or by combination of their Contribution(s)
81+
with the Work to which such Contribution(s) was submitted. If You
82+
institute patent litigation against any entity (including a
83+
cross-claim or counterclaim in a lawsuit) alleging that the Work
84+
or a Contribution incorporated within the Work constitutes direct
85+
or contributory patent infringement, then any patent licenses
86+
granted to You under this License for that Work shall terminate
87+
as of the date such litigation is filed.
88+
89+
4. Redistribution. You may reproduce and distribute copies of the
90+
Work or Derivative Works thereof in any medium, with or without
91+
modifications, and in Source or Object form, provided that You
92+
meet the following conditions:
93+
94+
(a) You must give any other recipients of the Work or
95+
Derivative Works a copy of this License; and
96+
97+
(b) You must cause any modified files to carry prominent notices
98+
stating that You changed the files; and
99+
100+
(c) You must retain, in the Source form of any Derivative Works
101+
that You distribute, all copyright, patent, trademark, and
102+
attribution notices from the Source form of the Work,
103+
excluding those notices that do not pertain to any part of
104+
the Derivative Works; and
105+
106+
(d) If the Work includes a "NOTICE" text file as part of its
107+
distribution, then any Derivative Works that You distribute must
108+
include a readable copy of the attribution notices contained
109+
within such NOTICE file, excluding those notices that do not
110+
pertain to any part of the Derivative Works, in at least one
111+
of the following places: within a NOTICE text file distributed
112+
as part of the Derivative Works; within the Source form or
113+
documentation, if provided along with the Derivative Works; or,
114+
within a display generated by the Derivative Works, if and
115+
wherever such third-party notices normally appear. The contents
116+
of the NOTICE file are for informational purposes only and
117+
do not modify the License. You may add Your own attribution
118+
notices within Derivative Works that You distribute, alongside
119+
or as an addendum to the NOTICE text from the Work, provided
120+
that such additional attribution notices cannot be construed
121+
as modifying the License.
122+
123+
You may add Your own copyright statement to Your modifications and
124+
may provide additional or different license terms and conditions
125+
for use, reproduction, or distribution of Your modifications, or
126+
for any such Derivative Works as a whole, provided Your use,
127+
reproduction, and distribution of the Work otherwise complies with
128+
the conditions stated in this License.
129+
130+
5. Submission of Contributions. Unless You explicitly state otherwise,
131+
any Contribution intentionally submitted for inclusion in the Work
132+
by You to the Licensor shall be under the terms and conditions of
133+
this License, without any additional terms or conditions.
134+
Notwithstanding the above, nothing herein shall supersede or modify
135+
the terms of any separate license agreement you may have executed
136+
with Licensor regarding such Contributions.
137+
138+
6. Trademarks. This License does not grant permission to use the trade
139+
names, trademarks, service marks, or product names of the Licensor,
140+
except as required for reasonable and customary use in describing the
141+
origin of the Work and reproducing the content of the NOTICE file.
142+
143+
7. Disclaimer of Warranty. Unless required by applicable law or
144+
agreed to in writing, Licensor provides the Work (and each
145+
Contributor provides its Contributions) on an "AS IS" BASIS,
146+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147+
implied, including, without limitation, any warranties or conditions
148+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149+
PARTICULAR PURPOSE. You are solely responsible for determining the
150+
appropriateness of using or redistributing the Work and assume any
151+
risks associated with Your exercise of permissions under this License.
152+
153+
8. Limitation of Liability. In no event and under no legal theory,
154+
whether in tort (including negligence), contract, or otherwise,
155+
unless required by applicable law (such as deliberate and grossly
156+
negligent acts) or agreed to in writing, shall any Contributor be
157+
liable to You for damages, including any direct, indirect, special,
158+
incidental, or consequential damages of any character arising as a
159+
result of this License or out of the use or inability to use the
160+
Work (including but not limited to damages for loss of goodwill,
161+
work stoppage, computer failure or malfunction, or any and all
162+
other commercial damages or losses), even if such Contributor
163+
has been advised of the possibility of such damages.
164+
165+
9. Accepting Warranty or Additional Liability. While redistributing
166+
the Work or Derivative Works thereof, You may choose to offer,
167+
and charge a fee for, acceptance of support, warranty, indemnity,
168+
or other liability obligations and/or rights consistent with this
169+
License. However, in accepting such obligations, You may act only
170+
on Your own behalf and on Your sole responsibility, not on behalf
171+
of any other Contributor, and only if You agree to indemnify,
172+
defend, and hold each Contributor harmless for any liability
173+
incurred by, or claims asserted against, such Contributor by reason
174+
of your accepting any such warranty or additional liability.
175+
176+
END OF TERMS AND CONDITIONS
177+
178+
APPENDIX: How to apply the Apache License to your work.
179+
180+
To apply the Apache License to your work, attach the following
181+
boilerplate notice, with the fields enclosed by brackets "[]"
182+
replaced with your own identifying information. (Don't include
183+
the brackets!) The text should be enclosed in the appropriate
184+
comment syntax for the file format. We also recommend that a
185+
file or class name and description of purpose be included on the
186+
same "printed page" as the copyright notice for easier
187+
identification within third-party archives.
188+
189+
Copyright [yyyy] [name of copyright owner]
190+
191+
Licensed under the Apache License, Version 2.0 (the "License");
192+
you may not use this file except in compliance with the License.
193+
You may obtain a copy of the License at
194+
195+
http://www.apache.org/licenses/LICENSE-2.0
196+
197+
Unless required by applicable law or agreed to in writing, software
198+
distributed under the License is distributed on an "AS IS" BASIS,
199+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200+
See the License for the specific language governing permissions and
201+
limitations under the License.

‎README.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
11
# Way
2-
Web指纹识别工具
2+
指纹识别工具
3+
取义:`W(ho) a(re) y(ou)?`
4+
5+
早年出于学习和演示目的写的一个demo,最近翻出来拍拍灰尘,发现能跑,于是发布出来有需要可以参考
6+
7+
```shell
8+
~ $ python3 Way.py
9+
10+
██╗ ██╗ █████╗ ██╗ ██╗
11+
██║ ██║██╔══██╗╚██╗ ██╔╝
12+
██║ █╗ ██║███████║ ╚████╔╝
13+
██║███╗██║██╔══██║ ╚██╔╝
14+
╚███╔███╔╝██║ ██║ ██║
15+
╚══╝╚══╝ ╚═╝ ╚═╝ ╚═╝ W(ho) a(re) y(ou)?
16+
_ Powered by Leonardo.
17+
_ Version_1.0.0
18+
19+
| 支持产品 | 5824 |
20+
| 指纹数量 | 10454 |
21+
```
22+
23+
使用方法:
24+
```shell
25+
#识别单个url
26+
python3 way.py -u http://xxx.com
27+
28+
#识别list文件中的url
29+
python3 way.py -f xxx.txt
30+
```
31+
没有做多线程,指纹库来自一些开源指纹库,自己做了一些优化
32+

‎Way.py

+284
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
import json
2+
import requests
3+
import re
4+
import urllib3
5+
import ssl
6+
import sys
7+
import random
8+
from requests import ConnectionError,ReadTimeout
9+
from bs4 import BeautifulSoup
10+
11+
# Ignore warning
12+
urllib3.disable_warnings()
13+
# Ignore ssl warning info.
14+
try:
15+
_create_unverified_https_context = ssl._create_unverified_context
16+
except AttributeError:
17+
# Legacy Python that doesn't verify HTTPS certificates by default
18+
pass
19+
else:
20+
# Handle target environment that doesn't support HTTPS verification
21+
ssl._create_default_https_context = _create_unverified_https_context
22+
23+
def get_logo(app_num,finger_num):
24+
print("""
25+
26+
██╗ ██╗ █████╗ ██╗ ██╗
27+
██║ ██║██╔══██╗╚██╗ ██╔╝
28+
██║ █╗ ██║███████║ ╚████╔╝
29+
██║███╗██║██╔══██║ ╚██╔╝
30+
╚███╔███╔╝██║ ██║ ██║
31+
╚══╝╚══╝ ╚═╝ ╚═╝ ╚═╝ W(ho) a(re) y(ou)?
32+
_ Powered by Leonardo.
33+
_ Version_1.0.0
34+
35+
| 支持产品 | %s |
36+
| 指纹数量 | %s |
37+
""" % (app_num,finger_num)
38+
)
39+
40+
def random_str(num):
41+
return ''.join(random.sample(['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a','1','2','3','4','5','6','7','8','9','0'], num))
42+
43+
def get_title(htmlcode):
44+
"""
45+
获取网站title
46+
47+
use:
48+
get_title(html_source)
49+
50+
return:
51+
title
52+
"""
53+
soup = BeautifulSoup(htmlcode, 'html.parser')
54+
55+
end = str(soup.title).find("</title>")
56+
title = str(soup.title)[7:end] + "<title>"
57+
58+
return title
59+
60+
def get_finger_rules():
61+
with open("data/FingerRule.json") as f:
62+
finger_rules = f.read()
63+
return json.loads(finger_rules)
64+
65+
def update_finger_rules(new_finger):
66+
"""
67+
考虑到脚本中已经多次出现对指纹库的更新和保存操作了,每次都重写一遍也挺麻烦的,因此决定把这个操作函数化
68+
接收一个参数:new_finger 新指纹库
69+
"""
70+
with open("data/FingerRule.json", "w+", encoding='utf-8') as f:
71+
json.dump(new_finger, # 待写入数据
72+
f, # File对象
73+
indent=2, # 空格缩进符,写入多行
74+
sort_keys=True, # 键的排序
75+
ensure_ascii=False) # 显示中文
76+
77+
def get_app_info():
78+
with open("data/AppInfo.json") as f:
79+
app_info = f.read()
80+
return json.loads(app_info)
81+
82+
def simple_http_req(url):
83+
try:
84+
req = requests.get(url=url,verify=False,timeout=20)
85+
86+
headers = req.headers
87+
title = get_title(req.text)
88+
body = req.text
89+
90+
return headers,title,body
91+
except (ConnectionError,ReadTimeout):
92+
return False
93+
94+
95+
rtitle = re.compile(r'title="(.*)"')
96+
rheader = re.compile(r'header="(.*)"')
97+
rbody = re.compile(r'body="(.*)"')
98+
result = []
99+
todo_url = [] # 计划将来扫描过程中遇到的没有命中任何指纹的url就存放在这里,等扫描完了我就专门去处理这些url,拿到平台去做对比测试,写新的规则
100+
101+
def rule_verify(rule,title,header,body,type):
102+
header = header # {'Connection': 'close', 'Content-Type': 'text/html; charset=utf-8', 'Date': 'Fri, 30 Dec 2022 02:00:30 GMT', 'Server': 'nginx'}
103+
if type == "str":
104+
if "title=\"" in rule:
105+
if re.findall(rtitle,rule)[0].lower() in title.lower():
106+
return True
107+
elif "body=\"" in rule:
108+
if re.findall(rbody,rule)[0] in body:
109+
return True
110+
elif "header=\"" in rule:
111+
rule = re.findall(rheader,rule)[0]
112+
if ": " in rule:
113+
key,value = rule.split(": ")
114+
keys = [key.lower() for key in header.keys()]
115+
if key.lower() in keys and value.lower() in header[key].lower():
116+
return True
117+
else:
118+
for head in header:
119+
if rule.lower() in header[head].lower():
120+
return True
121+
else:
122+
if "title=\"" in rule:
123+
reg = re.findall(rtitle,rule)[0]
124+
if re.search(r'' + reg,title,re.I):
125+
return True
126+
elif "body=\"" in rule:
127+
reg = re.findall(rbody,rule)[0]
128+
if re.search(r'' + reg,body,re.I):
129+
return True
130+
elif "header=\"" in rule:
131+
reg = re.findall(rheader,rule)[0]
132+
if ": " in reg:
133+
key,value = reg.split(": ")
134+
keys = [key.lower() for key in header.keys()]
135+
if key.lower() in keys:
136+
new_header = {}
137+
for k in header:
138+
new_header.update({k.lower(): header[k]})
139+
if re.search(r'' + value,new_header[key.lower()],re.I):
140+
return True
141+
else:
142+
for head in header:
143+
if re.search(r'' + reg,header[head],re.I):
144+
return True
145+
return False
146+
147+
def handle_once(finger_rules,headers,title,body):
148+
hit = False
149+
for i in range(len(finger_rules)):
150+
rule = finger_rules[i]["rule"]
151+
if "&&" in rule:
152+
num = 0
153+
rules = rule.split(" && ")
154+
for subrule in rules:
155+
if rule_verify(subrule,title=title,header=headers,body=body,type=finger_rules[i]["type"]) == True:
156+
num += 1
157+
158+
if num == len(rules):
159+
hit = True
160+
print("[*] 命中 %s 规则,Token:%s" % (finger_rules[i]["name"],finger_rules[i]["token"]))
161+
result.append(
162+
{
163+
"url":url,
164+
"name":finger_rules[i]["name"],
165+
"rule":rule
166+
}
167+
)
168+
finger_rules[i]["hit"] += 1
169+
# break
170+
else:
171+
if rule_verify(rule=rule,title=title,header=headers,body=body,type=finger_rules[i]["type"]):
172+
hit = True
173+
print("[*] 命中 %s 规则,Token:%s" % (finger_rules[i]["name"],finger_rules[i]["token"]))
174+
result.append(
175+
{
176+
"url":url,
177+
"name":finger_rules[i]["name"],
178+
"rule":rule
179+
}
180+
)
181+
finger_rules[i]["hit"] += 1
182+
# break
183+
if hit == False:
184+
print("[!] 未命中任何指纹")
185+
return finger_rules,hit
186+
187+
if len(sys.argv) == 1:
188+
app_info = get_app_info()
189+
finger_rule = get_finger_rules()
190+
get_logo(str(len(app_info)),str(len(finger_rule)))
191+
else:
192+
if sys.argv[1] in ["-u","-f"]:
193+
if sys.argv[1] == "-u":
194+
urls = [sys.argv[2]]
195+
else:
196+
with open(sys.argv[2].strip()) as f:
197+
urls = [i.strip() for i in f.readlines()]
198+
199+
url_num = 0
200+
finger_rules = get_finger_rules()
201+
app_infos = get_app_info()
202+
203+
for url in urls:
204+
url_num += 1
205+
print("[%d/%d] | current task: %s" % (url_num,len(urls),url))
206+
try:
207+
headers,title,body = simple_http_req(url)
208+
except:
209+
print("[!] %s 不可达" % url)
210+
continue
211+
finger_rules,hit = handle_once(finger_rules=finger_rules,headers=headers,title=title,body=body)
212+
todo_url.append(url) if hit == False else ""
213+
214+
update_finger_rules(finger_rules)
215+
216+
if len(urls) > 1:
217+
with open("report.txt","w+") as f:
218+
for i in result:
219+
f.write("目标:%s | 命中:%s | 规则:%s\n" % (i["url"],i["name"],i["rule"]))
220+
with open("todo_url.txt","w+") as f:
221+
for i in todo_url:
222+
f.write(i + "\n")
223+
if sys.argv[1] == "--debug":
224+
rule = "header=\"x-Powered-By: asp\\.NET\""
225+
type = "reg"
226+
url = "http://shx.huel.edu.cn"
227+
228+
try:
229+
headers,title,body = simple_http_req(url)
230+
# body = "jquery-1.2.min.js"
231+
# headers = "server: ngx_openresty"
232+
except:
233+
print("[!] %s 不可达" % url)
234+
sys.exit()
235+
236+
rules = []
237+
if " && " in rule:
238+
for i in rule.split(" && "):
239+
rules.append(i)
240+
else:
241+
rules = [rule]
242+
243+
flag = 0
244+
245+
for i in rules:
246+
if rule_verify(i,title=title,header=headers,body=body,type=type):
247+
print("[*] 规则 %s 匹配成功" % i)
248+
flag += 1
249+
else:
250+
print("[*] 规则 %s 匹配失败" % i)
251+
if flag == len(rules):
252+
print("[*] 恭喜,规则完全匹配!")
253+
else:
254+
print("[*] 很抱歉,规则不完全匹配!")
255+
if input("是否需要输出目标相应页面(是:y/Y,否:会车):").lower() == "y":
256+
print("[*] Body部分:\n%s\n" % body)
257+
258+
print("[*] Header部分:\n")
259+
for i in headers:
260+
print("%s: %s" % (i,headers[i]))
261+
262+
print("[*] Title部分:\n%s\n" % title)
263+
264+
if sys.argv[1] == "--addrule":
265+
name = input("请输入产品名称:")
266+
rule = input("请输入指纹规则(不要转义!):")
267+
type = "reg" if input("请输入指纹类型(str/reg):") == "reg" else "str" # 默认是str,即关键字匹配的形式
268+
finger_rules = get_finger_rules()
269+
for i in range(len(finger_rules)):
270+
if finger_rules[i]["name"] == name and finger_rules[i]["rule"] == rule:
271+
print("[*] 规则重复,请确认后再添加")
272+
sys.exit()
273+
token = random_str(9)
274+
new_rule = {
275+
"name": name,
276+
"rule": rule,
277+
"type": type,
278+
"hit": 0,
279+
"example": "",
280+
"token": token
281+
}
282+
finger_rules.append(new_rule)
283+
update_finger_rules(finger_rules)
284+
print("[*] 规则添加成功,token:" + token)

‎data/AppInfo.json

+40,770
Large diffs are not rendered by default.

‎data/FingerRule.json

+83,634
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.