Skip to content

Commit

Permalink
Merge pull request #10 from Ostorlab/domain_name
Browse files Browse the repository at this point in the history
Add domain name scanning support.
  • Loading branch information
3asm authored Mar 27, 2022
2 parents 6e4bcd8 + 151e3b0 commit cf28dce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
18 changes: 9 additions & 9 deletions agent/openvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

class OpenVas:
"""OpenVas wrapper to enable using openvas scanner from ostorlab agent class."""
def start_scan(self, ip: str) -> str:
def start_scan(self, target: str) -> str:
"""Start OpenVas scan on the ip provided.
Args:
ip: Target ip to scan.
target: Target ip to scan.
Returns:
OpenVas task identifier.
"""
Expand All @@ -33,27 +33,27 @@ def start_scan(self, ip: str) -> str:
with openvas_gmp.Gmp(connection, transform=transform) as gmp:
gmp.authenticate(GMP_USERNAME, GMP_PASSWORD)
logger.debug('Creating target')
target_id = self._create_target(gmp, ip, ALL_IANA_ASSIGNED_TCP_UDP)
target_id = self._create_target(gmp, target, ALL_IANA_ASSIGNED_TCP_UDP)
logger.debug('Creating task for target %s', target_id)
task_id = self._create_task(gmp, ip, target_id, GVMD_FULL_FAST_CONFIG, OPENVAS_SCANNER_ID,)
task_id = self._create_task(gmp, target, target_id, GVMD_FULL_FAST_CONFIG, OPENVAS_SCANNER_ID, )
logger.debug('Creating report for task %s', task_id)
report_id = self._start_task(gmp, task_id)
logger.info('Started scan of host %s. Corresponding report ID is %s', str(ip), str(report_id))
logger.info('Started scan of host %s. Corresponding report ID is %s', str(target), str(report_id))
return task_id

def _create_target(self, gmp: openvas_gmp.Gmp, ip: str, port_list_id: str) -> str:
def _create_target(self, gmp: openvas_gmp.Gmp, target: str, port_list_id: str) -> str:
"""Create gmp target https://docs.greenbone.net/API/GMP/gmp-21.04.html#command_create_target.
Args:
gmp: GMP object.
ip: Target ip to scan.
target: Target ip to scan.
port_list_id: ports to scan
Returns:
OpenVas target identifier.
"""
name = f'Testing Host {ip} {datetime.datetime.now()}'
response = gmp.create_target(name=name, hosts=[ip], port_list_id=port_list_id)
name = f'Testing Host {target} {datetime.datetime.now()}'
response = gmp.create_target(name=name, hosts=[target], port_list_id=port_list_id)
return response.get('id')

def _create_task(self, gmp: openvas_gmp.Gmp, ip: str, target_id: str, scan_config_id: str, scanner_id: str) -> str:
Expand Down
7 changes: 5 additions & 2 deletions agent/openvas_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ def start(self) -> None:
logger.info('starting openvas daemons')
subprocess.run(START_SCRIPT, check=True)
self._wait_vt_ready()
logger.info('vt is ready')

def process(self, message: m.Message) -> None:
logger.info('processing message')
logger.info('processing message from selector %s', message.selector)
openvas_wrapper = openvas.OpenVas()
task_id = openvas_wrapper.start_scan(message.data.get('host'))
target = message.data.get('name') or message.data.get('host')
logger.info('scanning target %s', target)
task_id = openvas_wrapper.start_scan(target)
openvas_wrapper.wait_task(task_id)
result = openvas_wrapper.get_results()
self._persist_results(result)
Expand Down
3 changes: 2 additions & 1 deletion ostorlab.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind: Agent
name: openvas
version: 0.0.2
version: 0.0.3
image: images/logo.png
description: |
This repository is an implementation of the OpenVas agent.
Expand Down Expand Up @@ -71,6 +71,7 @@ source: https://github.com/Ostorlab/agent_openvas
in_selectors:
- v3.asset.ip.v4
- v3.asset.ip.v6
- v3.asset.domain_name
out_selectors:
- v3.report.vulnerability
docker_file_path : Dockerfile
Expand Down

0 comments on commit cf28dce

Please sign in to comment.