forked from dsto97/CWEParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
136 lines (94 loc) · 3.36 KB
/
main.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
import requests
import json
import time
import pandas as pd
import config
def library_creation(threat, threat_id, threat_desc,usecase):
api_endpoint = config.URL
#adds the API token from a seperate file
api_token = config.API_KEY
#CREATES THE LIBRARY
library_endpoint = api_endpoint + "/libraries"
library = "CURRENT_CWE_LIST"
library_ref = library.replace(" ","-")
library_data = json.dumps({
"ref" : library_ref,
"name" : library,
"desc" : ""
})
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"API-token": f"{api_token}"
}
response = requests.post(library_endpoint, headers=headers, data=library_data)
if response.status_code == 201:
print(response, "Library was created")
elif response.status_code == 400:
print(response, "Library was not created")
#time.sleep(2)
#CREATES THE RISK PATTERN
riskpattern_endpoint = api_endpoint + f"/libraries/{library_ref}/riskpatterns"
#print(riskpattern_endpoint)
riskpattern = "CWEs"
riskpattern_ref = riskpattern.replace(" ", "")
payload = json.dumps({
"ref": riskpattern_ref,
"name": riskpattern,
"desc": "",
#"tags": [
#"string",
#"string"
#]
})
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'API-token': api_token
}
response = requests.request("POST", riskpattern_endpoint, headers=headers, data=payload)
print(response, "Risk Pattern")
#print(response.text)
#CREATES THE USE CASE
usecase_endpoint = api_endpoint + f"/libraries/{library_ref}/riskpatterns/{riskpattern_ref}/usecases"
usecase_ref = usecase.replace(" ", "")
usecase_data = json.dumps({
"ref": usecase_ref,
"name": usecase,
"desc": ""
})
response = requests.post(usecase_endpoint, headers=headers, data=usecase_data)
print(response, "Use Case")
#time.sleep(2)
#CREATES THE THREATS
threat_endpoint = api_endpoint + f"/libraries/{library_ref}/riskpatterns/{riskpattern_ref}/usecases/{usecase_ref}/threats"
#print(threat_endpoint)
#threat_ref = threat.replace(" ", "-")
#the only values accepted for riskRating are "[The only risk rating acceptable values are: none, low, medium, high, very-high]"
threat_data = json.dumps({
"ref": f"CWE-{threat_id}",
"name": f"{threat}",
"desc": f"{threat_desc}",
"riskRating": {
"confidentiality": "high",
"integrity": "high",
"availability": "high",
"easeOfExploitation": "low"
}
})
response = requests.post(threat_endpoint, headers=headers, data=threat_data)
print(response, "Threat")
#print(response.text, "Threat Response")
print(f"Row {counter} Complete")
print("")
library_data = pd.read_excel(r"\\wsl.localhost\Ubuntu\home\jamesrabe\CWEParser_RABECO\output.xlsx", 'Sheet1') # Replace 'your_spreadsheet.csv' with the actual file name and path
counter = 1
for index, row in library_data.iterrows():
counter += 1
#create a spreadsheet with column headers and match those the variables in this script.
threat_id = str(row['id'])
threat = str(row['name'])
threat_desc = str(row['description'])
usecase = str(row['usecase'])
#reference = str(row['reference'])
library_creation(threat, threat_id, threat_desc,usecase)