forked from golismero/openvas_lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_legacy.py
More file actions
69 lines (59 loc) · 1.58 KB
/
example_legacy.py
File metadata and controls
69 lines (59 loc) · 1.58 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
#!/usr/bin/env python
from __future__ import print_function
from openvas_lib import VulnscanManager, VulnscanException
from threading import Semaphore
from functools import partial
from xml.etree import ElementTree
import base64
import datetime
import os
import sys, re
import subprocess
import time
import random
def my_print_status(i):
print(str(i)),
sys.stdout.flush()
def write_report(manager, report_id, ip):
result_dir = os.path.dirname(os.path.abspath(__file__)) + "/results"
try:
report = manager.get_report_html(report_id)
except Exception as e:
print(e)
return
else:
fout = open(result_dir + "/html/" + ip + ".html", "wb")
fout.write(base64.b64decode(report.find("report").text))
fout.close()
try:
report = manager.get_report_xml(report_id)
except Exception as e:
print(e)
return
else:
fout = open(result_dir + "/xml/" + ip + ".xml", "wb")
fout.write(ElementTree.tostring(report, encoding='utf-8', method='xml'))
fout.close()
def run(manager, ip):
Sem = Semaphore(0)
scan_id, target_id = manager.launch_scan(
target=ip,
profile="Full and fast",
callback_end=partial(lambda x: x.release(), Sem),
callback_progress=my_print_status
)
Sem.acquire()
report_id = manager.get_report_id(scan_id)
write_report(manager, report_id, ip)
manager.delete_scan(scan_id)
manager.delete_target(target_id)
if __name__ == '__main__':
try:
openvas_ip = sys.argv[1]
admin_name = sys.argv[2]
admin_password = sys.argv[3]
ip = sys.argv[4]
manager = VulnscanManager(openvas_ip, admin_name, admin_password)
run(manager, ip)
except Exception as e:
print(e)