-
Notifications
You must be signed in to change notification settings - Fork 0
/
script3.txt
72 lines (61 loc) · 2.15 KB
/
script3.txt
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
import requests
import json
checkmarx_api_base_url = "https://checkmarx/api"
checkmarx_username = "YOUR_USERNAME"
checkmarx_password = "YOUR_PASSWORD"
checkmarx_project_id = "YOUR_PROJECT_ID"
checkmarx_team_id = "YOUR_TEAM_ID"
checkmarx_engine_config_id = "YOUR_ENGINE_CONFIG_ID"
checkmarx_scan_preset_id = "YOUR_SCAN_PRESET_ID"
def get_auth_token():
auth_url = checkmarx_api_base_url + "/auth/identity/connect/token"
headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
data = {
"grant_type": "password",
"username": checkmarx_username,
"password": checkmarx_password,
"scope": "sast_rest_api"
}
response = requests.post(auth_url, headers=headers, data=data)
if response.status_code == 200:
return json.loads(response.text)["access_token"]
else:
raise Exception("Failed to authenticate with Checkmarx API")
def initiate_scan(zip_path):
token = get_auth_token()
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + token
}
scan_url = checkmarx_api_base_url + "/sast/scans"
# Prepare the scan request body
scan_data = {
"projectId": checkmarx_project_id,
"teamId": checkmarx_team_id,
"engineConfigurationId": checkmarx_engine_config_id,
"isIncremental": False,
"isPublic": False,
"forceScan": True,
"comment": "",
"customFields": [],
"scanPresetId": checkmarx_scan_preset_id,
"sources": [
{
"type": "Zip",
"name": "source.zip",
"filename": zip_path,
"projectRelativePath": ""
}
]
}
# Send the scan request
response = requests.post(scan_url, headers=headers, json=scan_data)
if response.status_code == 201:
print("Scan initiated successfully.")
else:
print("Failed to initiate scan. Status code: {}".format(response.status_code))
if _name_ == "_main_":
zip_path = input("Enter the path to the zipped source code: ")
initiate_scan(zip_path)