TheDoctor0 / openvas-docker-lite

OpenVAS docker container with custom automation script.
MIT License
28 stars 21 forks source link

get_tasks exit status 1 #6

Closed zenire closed 4 years ago

zenire commented 4 years ago

docker run --rm -v $(pwd):/reports/:rw thedoctor0/openvas-docker-lite python3 -u scan.py 192.168.1.0/24 returns

Starting OpenVAS...
Starting scan with settings:
* Target: 10.0.12.1
* Excluded hosts:
* Scan profile: Full and fast
* Alive tests: ICMP, TCP-ACK Service & ARP Ping
* Max hosts: 10
* Max checks: 3
* Report format: ARF
* Output file: openvas.report

Traceback (most recent call last):
  File "scan.py", line 318, in <module>
    start_scan(arguments)
  File "scan.py", line 235, in start_scan
    'output': "/reports/" + args.output})
  File "scan.py", line 171, in make_scan
    perform_cleanup()
  File "scan.py", line 81, in perform_cleanup
    existing_tasks: List = execute_command("<get_tasks/>", "//get_tasks_response/task")
  File "scan.py", line 71, in execute_command
    response: str = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True).decode().strip()
  File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command 'omp -u admin -w admin -h 127.0.0.1 -p 9390 --xml '<get_tasks/>'' returned non-zero exit status 1.
TheDoctor0 commented 4 years ago

Hello Peter. I just downloaded fresh build of image from DockerHub and cannot replicate this issue:

openvas

I added exception handling to execute_command function so it will show an actual error. Please wait for new build to finish, then pull an image and try one again.

zenire commented 4 years ago

Thank you for your quick response! It now doesn't go further than Starting OpenVAS....

Starting OpenVAS...

^CTraceback (most recent call last):
  File "scan.py", line 324, in <module>
    start_scan(arguments)
  File "scan.py", line 227, in start_scan
    subprocess.check_call(["/start"], shell=True, stdout=subprocess.DEVNULL)
  File "/usr/lib/python3.6/subprocess.py", line 306, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python3.6/subprocess.py", line 289, in call
    return p.wait(timeout=timeout)
  File "/usr/lib/python3.6/subprocess.py", line 1477, in wait
    (pid, sts) = self._try_wait(0)
  File "/usr/lib/python3.6/subprocess.py", line 1424, in _try_wait
    (pid, sts) = os.waitpid(self.pid, wait_flags)
KeyboardInterrupt
zenire commented 4 years ago

Looks like I'm impatient, ps aux returns openvasmd: Rebuilding. Will get back to you.

TheDoctor0 commented 4 years ago

KeyboardInterrupt It seems that you stopped it by yourself 😄

OpenVAS can take few minutes to start, because it needs to rebuild whole cache.

zenire commented 4 years ago
Starting OpenVAS...
Starting scan with settings:
* Target: 192.168.1.0/24
* Excluded hosts:
* Scan profile: Full and fast
* Alive tests: ICMP, TCP-ACK Service & ARP Ping
* Max hosts: 10
* Max checks: 3
* Report format: PDF
* Output file: openvas.report

Performed initial cleanup.
Created target with id: d4546b98-e1f1-4a51-a1c2-2d384abc1961.
Created task with id: e07af34d-81e6-4655-9222-d9736f62172e.
Started task.
Waiting for task to finish...
Task status: Requested 1%
Task status: Running 1%
Task status: Running 1%
Task status: Running 1%
Task status: Running 1%
Task status: Running 1%
Task status: Running 1%
Task status: Running 1%
Task status: Running 1%
Task status: Running 1%
[ERROR] Response: b'Failed to authenticate.\n'
TheDoctor0 commented 4 years ago

Oh, it was definitely my mistake to add exit(1) after error in execute_command in last commit. From time to time OpenVAS socket will return authentication error on task status check, but that's totally normal and in next check it should properly return status.

It seems that beside that everything else works fine now for you, so I'll just make a fast commit to ignore that authentication error.

zenire commented 4 years ago
Starting OpenVAS...
Starting scan with settings:
* Target: 192.168.1.0/24
* Excluded hosts:
* Scan profile: Full and fast
* Alive tests: ICMP, TCP-ACK Service & ARP Ping
* Max hosts: 10
* Max checks: 3
* Report format: PDF
* Output file: openvas.report

Performed initial cleanup.
Created target with id: 1278a5f2-ccb4-4bf7-b768-7463192315cc.
Created task with id: e048bbae-e405-46f0-8905-a8caa359d4c2.
Started task.
Waiting for task to finish...
Task status: Requested 1%
Task status: Running 1%
Task status: Running 1%
Traceback (most recent call last):
  File "scan.py", line 330, in <module>
    start_scan(arguments)
  File "scan.py", line 247, in start_scan
    'output': "/reports/" + args.output})
  File "scan.py", line 196, in make_scan
    report_id = process_task(task_id)
  File "scan.py", line 143, in process_task
    status = etree.XML(task).xpath("string(//status/text())")
  File "src/lxml/etree.pyx", line 3214, in lxml.etree.XML
  File "src/lxml/parser.pxi", line 1876, in lxml.etree._parseMemoryDocument
  File "src/lxml/parser.pxi", line 1757, in lxml.etree._parseDoc
  File "src/lxml/parser.pxi", line 1068, in lxml.etree._BaseParser._parseUnicodeDoc
  File "src/lxml/parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 711, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 640, in lxml.etree._raiseParseError
  File "<string>", line 1
lxml.etree.XMLSyntaxError: Document is empty, line 1, column 1
TheDoctor0 commented 4 years ago

This may be an error from OpenVAS itself or no hosts were alive in scanned network.

I just scanned a single host in my network (with report in PDF format) without any problem:

root@965d183b40b2:/# python3 -u scan.py 192.168.1.1 --format PDF
Starting OpenVAS...
Starting scan with settings:
* Target: 192.168.1.1
* Excluded hosts:
* Scan profile: Full and fast
* Alive tests: ICMP, TCP-ACK Service & ARP Ping
* Max hosts: 10
* Max checks: 3
* Report format: PDF
* Output file: openvas.report

Performed initial cleanup.
Created target with id: c6d9c8a4-46a7-4886-9a54-ca6ccda1b7df.
Created task with id: 2e334d48-016b-41a9-974b-15e00d356aa3.
Started task.
Waiting for task to finish...
Task status: Running 1%
Task status: Running 1%
Task status: Running 1%
Task status: Complete
Finished processing task.
Generated report.
Saved report to /reports/openvas.report.
Done!
root@965d183b40b2:/#
TheDoctor0 commented 4 years ago

@ZeNiRe, I assume that this issue can be closed?

zenire commented 4 years ago

It seems to work now, but I'm still getting the error "lxml.etree.XMLSyntaxError: Document is empty, line 1, column 1" periodically. Maybe we should enclose it in a try catch to not abort?

TheDoctor0 commented 4 years ago

That error implies that generated report is empty and that is possible in case of:

  1. All scanned hosts were offline.
  2. No vulnerabilities has been found. I use this image in large networks for quite a while now, so none of this scenarios occurred for me.

Yeah, I think it make sense to catch this error, print info about empty report and go on. I'll change it today or tomorrow.

zenire commented 4 years ago

I also experience it with hosts that are online but I will check again about the vulnerabilities. The strange thing is the error may occur on the first try, but the second one succeeds. I will try to gather some more information.

Thank you again!

zenire commented 4 years ago

This issue has not reoccured over the past few days.