forked from subgraph/Vega
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
47 lines (36 loc) · 1.18 KB
/
example.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
import subprocess as sp
import time
import shlex
import shutil
import os
from py4j.java_gateway import JavaGateway
from py4j.java_collections import ListConverter
target = "192.168.0.2"
result_path = "./results"
authentication = "admin:admin"
vega_path = "/path/to/vega/Vega"
#seconds to wait for Vega to start
wait_time = 10
# checking if xvfb exists
if(shutil.which("xvfb-run") == None):
raise MissingDependency('xvfb cannot be found. Please install xvfb to use the python interface of Vega.')
# run vega
cmd = "xvfb-run -a " + vega_path
#process gets a new group ID so it can be stopped (including all additional created processes) later
vega_process = sp.Popen(shlex.split(cmd), preexec_fn=os.setsid)
print("Started Vega from %s" % str(vega_path))
time.sleep(wait_time)
# init vega classes
gateway = JavaGateway()
scanex = gateway.entry_point.getMyScanExecutor()
alertExporter = gateway.entry_point.getAlertExporter()
# set values
scanex.setTarget(target)
alertExporter.setPath(result_path)
scanex.runScan()
alertExporter.exportAlertsOfLastScan()
try:
os.killpg(os.getpgif(process.pid), signatl.SIGTERM)
process.wait()
except Exception:
pass