-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcwe.py
More file actions
229 lines (212 loc) · 9.14 KB
/
Copy pathcwe.py
File metadata and controls
229 lines (212 loc) · 9.14 KB
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
import json
from collections import defaultdict
# CWE→OWASP mapping for A01–A06 (you can expand this further)
CWE_TO_OWASP = {
# A01: Broken Access Control
22: "A01:2021 - Broken Access Control",
23: "A01:2021 - Broken Access Control",
35: "A01:2021 - Broken Access Control",
59: "A01:2021 - Broken Access Control",
200: "A01:2021 - Broken Access Control",
201: "A01:2021 - Broken Access Control",
219: "A01:2021 - Broken Access Control",
264: "A01:2021 - Broken Access Control",
275: "A01:2021 - Broken Access Control",
276: "A01:2021 - Broken Access Control",
284: "A01:2021 - Broken Access Control",
285: "A01:2021 - Broken Access Control",
352: "A01:2021 - Broken Access Control",
359: "A01:2021 - Broken Access Control",
377: "A01:2021 - Broken Access Control",
402: "A01:2021 - Broken Access Control",
425: "A01:2021 - Broken Access Control",
441: "A01:2021 - Broken Access Control",
497: "A01:2021 - Broken Access Control",
538: "A01:2021 - Broken Access Control",
540: "A01:2021 - Broken Access Control",
548: "A01:2021 - Broken Access Control",
552: "A01:2021 - Broken Access Control",
566: "A01:2021 - Broken Access Control",
601: "A01:2021 - Broken Access Control",
639: "A01:2021 - Broken Access Control",
651: "A01:2021 - Broken Access Control",
668: "A01:2021 - Broken Access Control",
706: "A01:2021 - Broken Access Control",
862: "A01:2021 - Broken Access Control",
863: "A01:2021 - Broken Access Control",
913: "A01:2021 - Broken Access Control",
922: "A01:2021 - Broken Access Control",
1275: "A01:2021 - Broken Access Control",
# A02: Cryptographic Failures
261: "A02:2021 - Cryptographic Failures",
296: "A02:2021 - Cryptographic Failures",
310: "A02:2021 - Cryptographic Failures",
319: "A02:2021 - Cryptographic Failures",
321: "A02:2021 - Cryptographic Failures",
322: "A02:2021 - Cryptographic Failures",
323: "A02:2021 - Cryptographic Failures",
324: "A02:2021 - Cryptographic Failures",
325: "A02:2021 - Cryptographic Failures",
326: "A02:2021 - Cryptographic Failures",
327: "A02:2021 - Cryptographic Failures",
328: "A02:2021 - Cryptographic Failures",
329: "A02:2021 - Cryptographic Failures",
330: "A02:2021 - Cryptographic Failures",
331: "A02:2021 - Cryptographic Failures",
335: "A02:2021 - Cryptographic Failures",
336: "A02:2021 - Cryptographic Failures",
337: "A02:2021 - Cryptographic Failures",
338: "A02:2021 - Cryptographic Failures",
340: "A02:2021 - Cryptographic Failures",
347: "A02:2021 - Cryptographic Failures",
523: "A02:2021 - Cryptographic Failures",
757: "A02:2021 - Cryptographic Failures",
759: "A02:2021 - Cryptographic Failures",
760: "A02:2021 - Cryptographic Failures",
780: "A02:2021 - Cryptographic Failures",
916: "A02:2021 - Cryptographic Failures",
# A03: Injection
20: "A03:2021 - Injection",
74: "A03:2021 - Injection",
75: "A03:2021 - Injection",
77: "A03:2021 - Injection",
78: "A03:2021 - Injection",
79: "A03:2021 - Injection",
80: "A03:2021 - Injection",
83: "A03:2021 - Injection",
87: "A03:2021 - Injection",
88: "A03:2021 - Injection",
89: "A03:2021 - Injection",
90: "A03:2021 - Injection",
91: "A03:2021 - Injection",
93: "A03:2021 - Injection",
94: "A03:2021 - Injection",
95: "A03:2021 - Injection",
96: "A03:2021 - Injection",
97: "A03:2021 - Injection",
98: "A03:2021 - Injection",
99: "A03:2021 - Injection",
113: "A03:2021 - Injection",
116: "A03:2021 - Injection",
138: "A03:2021 - Injection",
184: "A03:2021 - Injection",
470: "A03:2021 - Injection",
471: "A03:2021 - Injection",
564: "A03:2021 - Injection",
610: "A03:2021 - Injection",
643: "A03:2021 - Injection",
644: "A03:2021 - Injection",
652: "A03:2021 - Injection",
917: "A03:2021 - Injection",
# A04: Insecure Design
73: "A04:2021 - Insecure Design",
183: "A04:2021 - Insecure Design",
209: "A04:2021 - Insecure Design",
213: "A04:2021 - Insecure Design",
266: "A04:2021 - Insecure Design",
269: "A04:2021 - Insecure Design",
280: "A04:2021 - Insecure Design",
311: "A04:2021 - Insecure Design",
312: "A04:2021 - Insecure Design",
419: "A04:2021 - Insecure Design",
434: "A04:2021 - Insecure Design",
444: "A04:2021 - Insecure Design",
451: "A04:2021 - Insecure Design",
501: "A04:2021 - Insecure Design",
522: "A04:2021 - Insecure Design",
602: "A04:2021 - Insecure Design",
653: "A04:2021 - Insecure Design",
657: "A04:2021 - Insecure Design",
799: "A04:2021 - Insecure Design",
807: "A04:2021 - Insecure Design",
840: "A04:2021 - Insecure Design",
841: "A04:2021 - Insecure Design",
927: "A04:2021 - Insecure Design",
1021: "A04:2021 - Insecure Design",
1173: "A04:2021 - Insecure Design",
# A05: Security Misconfiguration
2: "A05:2021 - Security Misconfiguration",
11: "A05:2021 - Security Misconfiguration",
13: "A05:2021 - Security Misconfiguration",
15: "A05:2021 - Security Misconfiguration",
16: "A05:2021 - Security Misconfiguration",
260: "A05:2021 - Security Misconfiguration",
611: "A05:2021 - Security Misconfiguration",
614: "A05:2021 - Security Misconfiguration",
776: "A05:2021 - Security Misconfiguration",
942: "A05:2021 - Security Misconfiguration",
1004: "A05:2021 - Security Misconfiguration",
1032: "A05:2021 - Security Misconfiguration",
# A06: Vulnerable and Outdated Components
937: "A06:2021 - Vulnerable and Outdated Components",
1035: "A06:2021 - Vulnerable and Outdated Components",
1104: "A06:2021 - Vulnerable and Outdated Components",
# A07: Identification and Authentication Failures
255: "A07:2021 - Identification and Authentication Failures",
259: "A07:2021 - Identification and Authentication Failures",
287: "A07:2021 - Identification and Authentication Failures",
288: "A07:2021 - Identification and Authentication Failures",
290: "A07:2021 - Identification and Authentication Failures",
294: "A07:2021 - Identification and Authentication Failures",
295: "A07:2021 - Identification and Authentication Failures",
297: "A07:2021 - Identification and Authentication Failures",
300: "A07:2021 - Identification and Authentication Failures",
302: "A07:2021 - Identification and Authentication Failures",
304: "A07:2021 - Identification and Authentication Failures",
306: "A07:2021 - Identification and Authentication Failures",
307: "A07:2021 - Identification and Authentication Failures",
346: "A07:2021 - Identification and Authentication Failures",
384: "A07:2021 - Identification and Authentication Failures",
521: "A07:2021 - Identification and Authentication Failures",
613: "A07:2021 - Identification and Authentication Failures",
620: "A07:2021 - Identification and Authentication Failures",
640: "A07:2021 - Identification and Authentication Failures",
798: "A07:2021 - Identification and Authentication Failures",
940: "A07:2021 - Identification and Authentication Failures",
1216: "A07:2021 - Identification and Authentication Failures",
# A08: Software and Data Integrity Failures
345: "A08:2021 - Software and Data Integrity Failures",
353: "A08:2021 - Software and Data Integrity Failures",
426: "A08:2021 - Software and Data Integrity Failures",
494: "A08:2021 - Software and Data Integrity Failures",
502: "A08:2021 - Software and Data Integrity Failures",
565: "A08:2021 - Software and Data Integrity Failures",
784: "A08:2021 - Software and Data Integrity Failures",
829: "A08:2021 - Software and Data Integrity Failures",
830: "A08:2021 - Software and Data Integrity Failures",
915: "A08:2021 - Software and Data Integrity Failures",
}
def map_cwe_to_owasp(cwe_ids):
owasp_set = set()
for cwe in cwe_ids:
try:
cwe_num = int(cwe.replace("CWE-", ""))
if cwe_num in CWE_TO_OWASP:
owasp_set.add(CWE_TO_OWASP[cwe_num])
except ValueError:
continue
return list(owasp_set)
def process_nvd_file(input_path, output_path):
with open(input_path, "r") as f:
data = json.load(f)
results = []
for entry in data["vulnerabilities"]:
cve_id = entry.get("cve", {}).get("id", "UNKNOWN")
cwe_ids = []
# Extract CWE IDs from weaknesses
for problem in entry.get("cve", {}).get("weaknesses", []):
for desc in problem.get("description", []):
cwe_id = desc.get("value")
if cwe_id and cwe_id != "NVD-CWE-noinfo":
cwe_ids.append(cwe_id)
mapped_owasp = map_cwe_to_owasp(cwe_ids)
results.append({
"cve_id": cve_id,
"cwe_ids": cwe_ids,
"owasp_categories": mapped_owasp
})
with open(output_path, "w") as f:
json.dump(results, f, indent=2)
print(f"Wrote {len(results)} CVE entries with OWASP mapping to {output_path}")
# Run it like this:
process_nvd_file("nvdcve-2.0-2025.json", "mapped_output_2025.json")