-
Notifications
You must be signed in to change notification settings - Fork 0
/
vulnerabilities_email.py
70 lines (58 loc) · 2.15 KB
/
vulnerabilities_email.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
import smtplib
import matplotlib.pyplot as plt
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
import time
from openvas_lib import OMPv7
# Remove the redundant import statement
# import time
# Remove the redundant import statement
# from openvas_lib import OMPv7
# Remove the redundant import statement
# import smtplib
# Remove the redundant import statement
# from email.mime.multipart import MIMEMultipart
# Remove the redundant import statement
# from email.mime.base import MIMEBase
# Remove the redundant import statement
# from email import encoders
# Remove the redundant import statement
# import matplotlib.pyplot as plt
# Collect vulnerability data
# This will depend on the vulnerability scanner you're using
def get_vulnerabilities():
omp = OMPv7('localhost', 9390, 'username', 'password')
# Start a new scan
scan_id = omp.create_task('My Scan', 'daba56c8-73ec-11df-a475-002264764cea', target='localhost')
# Wait for the scan to finish
while omp.get_tasks(filter=f'id={scan_id}')[0].status != 'Done':
time.sleep(1)
# Get the results
results = omp.get_results(filter=f'task_id={scan_id}')
# Extract the vulnerabilities
vulnerabilities = [result.name for result in results if result.threat == 'High']
return vulnerabilities
vulnerabilities = get_vulnerabilities()
# This will depend on the vulnerability scanner you're using
# vulnerabilities = get_vulnerabilities()
# Create the dashboard
plt.figure(figsize=(10, 6))
plt.plot([len(v) for v in vulnerabilities])
plt.savefig('dashboard.png')
# Prepare the email
msg = MIMEMultipart()
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Subject'] = 'Daily Security Dashboard'
with open('dashboard.png', 'rb') as f:
part = MIMEBase('application', 'octet-stream')
part.set_payload(f.read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="dashboard.png"')
msg.attach(part)
# Send the email
smtp = smtplib.SMTP('[email protected]')
smtp.login('[email protected]', 'your_password')
smtp.send_message(msg)
smtp.quit()