forked from adysec/nuclei_poc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4-remove_duplicated.py
171 lines (151 loc) · 5.25 KB
/
4-remove_duplicated.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
import os
import shutil
import hashlib
category_map = {
"wordpress": ["wp", "wordpress"],
"xss": ["xss"],
"sql_injection": ["sqli", "sql_injection","sql"],
"local_file_inclusion": ["lfi","local_file_inclusion"],
"remote_code_execution": ["rce"],
"cross_site_request_forgery": ["csrf"],
"xml_external_entity": ["xxe"],
"cve": ["cve"],
"cnvd":["cnvd"],
"cnnvd":["cnnvd"],
"open_redirect": ["redirect", "open_redirect"],
"ssrf": ["ssrf", "server_side_request_forgery"],
"subdomain_takeover": ["subdomain_takeover", "takeover"],
"template_injection": ["template_injection", "ssti"],
"crlf_injection": ["crlf_injection", "crlf"],
"directory_listing": ["directory_listing", "traversal"],
"exposed": ["exposed", "disclosure", "sensitive", "exposure"],
"adobe": ["adobe","aem",],
"coldfusion": ["coldfusion", "cfm"],
"drupal": ["drupal"],
"joomla": ["joomla"],
"magento": ["magento"],
"php": ["php"],
"airflow": ["airflow"],
"aws": ["aws", "amazon", "ec2", "s3", "lambda", "cloudfront", "cloudfront"],
"apache": ["apache"],
"cpanel": ["cpanel"],
"docker": ["docker", "container", "kubernetes"],
"git": ["git"],
"jenkins": ["jenkins"],
"cisco": ["cisco"],
"api": ["api"],
"upload": ["upload"],
"sensitive": ["sensitive"],
"debug": ["debug"],
"backup": ["backup"],
"auth": ["auth","login","signin","sign_in","sign-in","oauth","sso","register","signup","sign_up","sign-up","password","pwd","passwd","secret","token","credential","cred","jwt","cookie","session","remember","keycloak","key",],
"atlassian": ["atlassian", "jira", "confluence", "bitbucket", "bamboo"],
"config": ["config", "conf", "configuration"],
"mysql": ["mysql", "mariadb"],
"sql": ["sql", "database", "db"],
"default": ["default"],
"detect": ["detect"],
"extract": ["extract"],
"fuzz": ["fuzz"],
"graphql": ["graphql"],
"http": ["http"],
"social": ["social","social_media","facebook","twitter","instagram","linkedin",],
"favicon": ["favicon"],
"python": ["python", "flask", "django"],
"ftp": ["ftp"],
"gcloud": ["gcloud", "google_cloud", "gcp"],
"google": ["google"],
"graphite": ["graphite"],
"header": ["header"],
"injection": ["injection"],
"ibm": ["ibm"],
"search": ["search"],
"ldap": ["ldap"],
"microsoft": ["microsoft", "ms"],
"mongodb": ["mongodb", "mongo"],
"netlify": ["netlify"],
"oracle": ["oracle"],
"java": ["java","jsp","jsf","j2ee","j2se","j2me","jvm","jre","jdk","jboss","tomcat","glassfish","wildfly","jetty","websphere","weblogic","spring","struts","hibernate","mybatis","shiro",],
"javascript": ["javascript", "js"],
"elk": ["elk", "elasticsearch", "kibana", "logstash"],
"kafka": ["kafka"],
"kong": ["kong"],
"laravel": ["laravel"],
"nginx": ["nginx"],
"nodejs": ["nodejs", "node", "express", "npm"],
"perl": ["perl"],
"postgres": ["postgres", "postgresql"],
"rabbitmq": ["rabbitmq"],
"redis": ["redis"],
"ruby": ["ruby", "rails"],
"samba": ["samba"],
"sharepoint": ["sharepoint"],
"smtp": ["smtp"],
"sap": ["sap"],
"shopify": ["shopify"],
"ssh": ["ssh"],
"vmware": ["vmware"],
"web": ["web"],
}
def get_all_yaml_files(dir_path):
all_yaml_files = {}
for dirpath, dirs, files in os.walk(dir_path):
dirs[:] = [d for d in dirs if d != ".git" and d != "projectdiscovery__nuclei-templates"]
for filename in files:
if filename.endswith(".yml") or filename.endswith(".yaml"):
all_yaml_files[filename] = os.path.join(dirpath, filename)
return all_yaml_files
def categorize_file(file_name, category_map):
categories = []
for category, keywords in category_map.items():
if any(keyword in file_name.lower() for keyword in keywords):
categories.append(category)
return (
categories if categories else ["other"]
)
def file_hash(file_path):
hasher = hashlib.md5()
with open(file_path, "rb") as f:
buf = f.read()
hasher.update(buf)
return hasher.hexdigest()
def copy_file_to_categories(
file_path, base_dir, category_map, category_counts, file_hashes
):
categories = categorize_file(os.path.basename(file_path), category_map)
file_hash_value = file_hash(file_path)
for category in categories:
target_dir = os.path.join(base_dir, category)
os.makedirs(target_dir, exist_ok=True)
if file_hash_value not in file_hashes.get(category, set()):
shutil.copy(
file_path, os.path.join(target_dir, os.path.basename(file_path))
)
category_counts[category] = category_counts.get(category, 0) + 1
file_hashes.setdefault(category, set()).add(file_hash_value)
def get_file_size(file_path):
return os.path.getsize(file_path)
community_path = "clone-templates"
source_of_truth = "clone-templates/projectdiscovery/nuclei-templates"
output_path = "poc"
community = get_all_yaml_files(community_path)
nucleiTemplates = get_all_yaml_files(source_of_truth)
common_templates = set(community.keys()) & set(nucleiTemplates.keys())
category_counts = {}
file_hashes = {}
for template, community_file in community.items():
if template in common_templates and get_file_size(community_file) == get_file_size(
nucleiTemplates[template]
):
os.remove(community_file)
continue
copy_file_to_categories(
community_file, output_path, category_map, category_counts, file_hashes
)
print("各类文件数量:")
all = 0
for category, count in category_counts.items():
all = all + count
print(f"{category}: {count}")
print(f"all: {all}")
os.system('rm -rf clone-templates')