Browse Source

add search for taskname, headless parameter and user+pass from env

main
Markus Bergholz 3 months ago
parent
commit
0d987813ba
Signed by: m GPG Key ID: B45724801354B174
  1. 24
      Makefile
  2. 7
      README.md
  3. 14
      galaxy.yml
  4. 40
      plugins/modules/task.py
  5. 13
      tests/test.yml

24
Makefile

@ -0,0 +1,24 @@
.PHONY: help test
help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
build: ## build collection localy
ansible-galaxy collection build -f
install: ## install collection localy
ansible-galaxy collection install markuman*
remove: ## remove collection localy
rm -rf markuman* ~/.ansible/collections/ansible_collections/markuman/nessus
syntax: ## test compile
python -m py_compile plugins/modules/task.py
round: ## remove, build install
$(MAKE) syntax
$(MAKE) remove
$(MAKE) build
$(MAKE) install

7
README.md

@ -18,9 +18,14 @@ This is helpfull, because you can throw your (dynamic) inventory files on an exi
targets:
- 10.0.0.1
- 10.0.0.32
task: "183"
task: task_name
host: nessus.mydomain.tld
username: nessus_user
password: nessus_password
```
## install
* `ansible-galaxy collection install markuman.nessus`
* `pip3 install selenium --user`
* Gecko Driver https://github.com/mozilla/geckodriver/releases install to `~/.local/bin/`

14
galaxy.yml

@ -0,0 +1,14 @@
namespace: "markuman"
description: nessus collection
name: "nessus"
version: "0.0.1"
readme: "README.md"
authors:
- "Markus Bergholz <markuman+spambelongstogoogle@gmail.com>"
license:
- "GPL-3.0-or-later"
tags:
- nessus
- collection
repository: "https://git.osuv.de/m/nessus_collection"
issues: https://github.com/markuman/nessus_collection

40
plugins/modules/task.py

@ -23,12 +23,34 @@ from selenium import webdriver
import time
from selenium.webdriver.firefox.options import Options
from pathlib import Path
import requests
def wer_braucht_schon_eine_api(task, targets, username, password, host):
def wer_braucht_schon_eine_api(task, targets, username, password, host, headless):
post_data = {
'username': username,
'password': password
}
response = requests.post(f'https://{host}/session', data=post_data)
if response.status_code == 200:
token = response.json().get('token')
header = {
"X-Cookie":f"token={token}",
"Content-Type":"application/json"
}
response = requests.get(f'https://{host}/scans', headers=header)
if response.status_code == 200:
scans = response.json().get('scans')
for scan in scans:
if task == scan.get('name'):
task_id = scan.get('id')
options = Options()
options.headless = True
options.headless = headless
driver = webdriver.Firefox(str(Path.home()) + '/.local/bin/', options=options)
print ("Headless Firefox Initialized")
@ -46,7 +68,7 @@ def wer_braucht_schon_eine_api(task, targets, username, password, host):
time.sleep(5)
driver.get('https://{HOST}/#/scans/reports/{TASK}/config/settings/basic/general'.format(TASK=task, HOST=host))
driver.get(f'https://{host}/#/scans/reports/{task_id}/config/settings/basic/general')
time.sleep(5)
targets_element = "/html/body/section[3]/section[3]/section/form/div/div/div/div[1]/section/div[1]/div[1]/div[1]/div[5]/div/textarea"
@ -76,18 +98,20 @@ def main():
password = dict(required=False, type='str', no_log=True),
username = dict(required=False, type='str'),
task = dict(required=True, type='str'),
host = dict(required=True, type='str')
host = dict(required=True, type='str'),
headless = dict(required=False, type='bool', default=False)
)
)
raw_targets = module.params.get("targets")
password = module.params.get("password")
username = module.params.get("username")
targets = module.params.get("targets")
password = module.params.get("password") or os.environ.get('NESSUS_PASSWORD')
username = module.params.get("username") or os.environ.get('NESSUS_USERNAME')
task = module.params.get("task")
host = module.params.get("host")
headless = module.params.get("headless")
change = wer_braucht_schon_eine_api(task, ips, username, password, host)
change = wer_braucht_schon_eine_api(task, targets, username, password, host, headless)
module.exit_json(changed=change)

13
tests/test.yml

@ -0,0 +1,13 @@
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: update nessus task
markuman.nessus.task:
targets:
- 10.85.10.85
task: AnsibleTest
host: nessus.osuv.de
headless: no
Loading…
Cancel
Save