-
Notifications
You must be signed in to change notification settings - Fork 3
/
status_v2.py
124 lines (98 loc) · 3.92 KB
/
status_v2.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
#!/usr/bin/python
import sys
import getopt
import os
import requests
import urllib3
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import json
smart_check_url = ''
smart_check_userid = ''
smart_check_password = ''
scan_id = ''
output = 'status'
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def init(argv):
try:
opts, args = getopt.getopt(argv, "h:v",
["smart_check_url=", "smart_check_userid=", "smart_check_password=", "scan_id=",
"output="])
except getopt.GetoptError as error:
print('Error Not enough Arguments')
print(str(error))
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('scans.py -i <inputfile> -o <outputfile>')
sys.exit()
elif opt in ("--smart_check_url"):
global smart_check_url
smart_check_url = arg
elif opt in ("--smart_check_userid"):
global smart_check_userid
smart_check_userid = arg
elif opt in ("--smart_check_password"):
global smart_check_password
smart_check_password = arg
elif opt in ("--scan_id"):
global scan_id
scan_id = arg
elif opt in ("--output"):
global output
output = arg
def get_token(userid, password):
# print("----- Generating Token ----- "+userid)
payload = {'user': {'userID': userid, 'password': password}}
r = requests.post('https://' + smart_check_url + '/api/sessions', json=payload, verify=False)
z = json.loads(r.text)
return z
def get_scan(token, id):
# print("----- Get Scan Data for "+id+" -----")
headers = {
'authorization': "Bearer " + token,
'content-type': "application/json",
}
r = requests.get('https://' + smart_check_url + '/api/scans/' + id, headers=headers, verify=False)
x = json.loads(r.text)
if output == "status":
print(x['status'])
if output == "malware" and "malware" in x['findings']:
if (x['findings']['malware'] > 0):
print('malware_found')
# sys.exit(os.EX_SOFTWARE)
else:
print('no-malware')
if output == "contents" and "contents" in x['findings']:
try:
if (x['findings']['contents']['total']['high'] > 0):
print(str(x['findings']['contents']['total']['high']) + ' Secret stored found in image!')
# print('Critical Vulnerabilities Found')
# sys.exit(os.EX_SOFTWARE)
else:
print('No Secrets found in image')
except Exception as e:
pass
if output == "vulnerability" and "high" in x['findings']['vulnerabilities']['total']:
try:
if (x['findings']['vulnerabilities']['total']['high'] > 0):
print(str(x['findings']['vulnerabilities']['total']['high']) + ' High Vulnerabilities Found!')
# print('Critical Vulnerabilities Found')
# sys.exit(os.EX_SOFTWARE)
else:
print('No High Vulnerabilities')
except Exception as e:
pass
try:
if (x['findings']['vulnerabilities']['total']['critical'] > 0):
print(
str(x['findings']['vulnerabilities']['total']['critical']) + ' Critical Vulnerabilities Found!')
# print('Critical Vulnerabilities Found')
# sys.exit(os.EX_SOFTWARE)
else:
print('No Critical Vulnerabilities')
except Exception as e:
pass
init(sys.argv[1:])
token = get_token(smart_check_userid, smart_check_password)
# print(token)
get_scan(token['token'], scan_id)