TheGroundZero / openvasreporting

OpenVAS Reporting: Convert OpenVAS XML report files to reports
Other
131 stars 45 forks source link

AttributeError errors when running #9

Closed beercity closed 3 years ago

beercity commented 4 years ago

Running into issues, I am seeing the following error when running

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/user/openvasreporting/openvasreporting/__main__.py", line 17, in <module>
    main()
  File "/home/user/openvasreporting/openvasreporting/openvasreporting.py", line 33, in main
    convert(config)
  File "/home/user/openvasreporting/openvasreporting/openvasreporting.py", line 87, in convert
    openvas_info = openvas_parser(config.input_files, config.min_level)
  File "/home/user/openvasreporting/openvasreporting/libs/parser.py", line 150, in openvas_parser
    vuln_cves = nvt_tmp.find("./cve").text
AttributeError: 'NoneType' object has no attribute 'text'

I am using the current version of the reporting tool. The XML was generated using Greenbone Security Manager version 6.0.0

beercity commented 4 years ago

I can provide a copy of the XML upon request. I have tested this under a few different linux systems with the same results.

TheGroundZero commented 4 years ago

What version of OpenVAS did you use?

If possible, a (redacted) copy of the XML would be useful.

beercity commented 4 years ago

To be honest I am not sure how to get the OpenVAS version out of Greenbone. I am using GSM on a fresh install from about a week ago. If you can provide me with a email contact I can send you a XML

TheGroundZero commented 4 years ago

If I'm not mistaken, you can use 2406013+TheGroundZero@users.noreply.github.com as email address.
If not, add me on Twitter (@DezeStijn).

Friday, I should be able to run an OpenVAS scan on a test environment again. So I can compare my output with yours.

davidem commented 4 years ago

After fixing #10, I'm left with the same issue. Running the Virtual Appliance version of GSM, v6.0.0, downloaded about 2 weeks ago

TheGroundZero commented 4 years ago

I'll run some test scans in my own environment in one of the coming days as I don't have any proper reports currently.
I also noticed I was running an older version of Greenbone Security Manager in my dedicated VM, so will update that one to 6.0.0 and test a local install within a linux VM.

TheGroundZero commented 4 years ago

I'm sorry it took so long to come back to this.

I ran a scan of a small lab environment earlier today and created an xlsx report from the XML report.
I did not get any errors at all.

Fresh copy from this repo in a new VM.
Greenbone Security Assistant Version 7.0.3
Results export in XML (not Anonymous XML!)

Are you using Python3?
Did you install all packages in requirements.txt using pip3?

rrivas12 commented 4 years ago

@TheGroundZero Same issue with Greenbone Security Assistant 9.0.0 and openvas 7.0

openvasreporting# python3 -m openvasreporting -i .xml -f xlsx 2020-02-25 17:16:05 | DEBUG | root | ================================================================================ 2020-02-25 17:16:05 | DEBUG | root | ================================================================================ 2020-02-25 17:16:05 | DEBUG | root | -------------------------------------------------------------------------------- 2020-02-25 17:16:05 | DEBUG | root | - ClearBudget Invalid '.htaccess' Unauthorized Access Vulnerability 2020-02-25 17:16:05 | DEBUG | root | -------------------------------------------------------------------------------- 2020-02-25 17:16:05 | DEBUG | root | vuln_id: 1.3.6.1.4.1.25623.1.0.100010 2020-02-25 17:16:05 | DEBUG | root | vuln_cvss: 5.0 2020-02-25 17:16:05 | DEBUG | root | vuln_level: medium 2020-02-25 17:16:05 | DEBUG | root | min_level: none 2020-02-25 17:16:05 | DEBUG | root | vuln_host: 10.249.67.13 port: 443/tcp 2020-02-25 17:16:05 | DEBUG | root | vuln_tags: {'cvss_base_vector': 'AV:N/AC:L/Au:N/C:P/I:N/A:N', 'summary': 'ClearBudget is prone to an unauthorized-access vulnerability because\n it fails to properly restrict access to certain directories.', 'insight': '', 'affected': 'ClearBudget 0.6.1 is vulnerable, other versions may also be affected.', 'impact': 'An attacker can exploit this vulnerability to gain access to\n database contents. Information harvested can lead to further attacks.', 'solution': 'The vendor released an update to address this issue. Please', 'vuldetect': '', 'solution_type': 'VendorFix'} 2020-02-25 17:16:05 | DEBUG | root | vuln_threat: medium 2020-02-25 17:16:05 | DEBUG | root | * vuln_family: Web application abuses Traceback (most recent call last): File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/usr/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/user/openvasreporting/openvasreporting/main.py", line 17, in main() File "/home/user/openvasreporting/openvasreporting/openvasreporting.py", line 33, in main convert(config) File "/home/user/openvasreporting/openvasreporting/openvasreporting.py", line 87, in convert openvas_info = openvas_parser(config.input_files, config.min_level) File "/home/user/openvasreporting/openvasreporting/libs/parser.py", line 150, in openvas_parser vuln_cves = nvt_tmp.find("./cve").text AttributeError: 'NoneType' object has no attribute 'text'

BitFlipp3r commented 4 years ago

Hi,

I had a similar error:

Traceback (most recent call last):
  File "C:..\WPy64-3680\python-3.6.8.amd64\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\..\WPy64-3680\python-3.6.8.amd64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\..\openvasreporting\openvasreporting\__main__.py", line 17, in <module>
    main()
  File "C:\..\openvasreporting\openvasreporting\openvasreporting.py", line 33, in main
    convert(config)
  File "C:\..\openvasreporting\openvasreporting\openvasreporting.py", line 87, in convert
    openvas_info = openvas_parser(config.input_files, config.min_level)
  File "C:\..\openvasreporting\openvasreporting\libs\parser.py", line 61, in openvas_parser
    logging.debug("= {}".format(root.find("./task/name").text))  # DEBUG
AttributeError: 'NoneType' object has no attribute 'text'

Could fix it by using "XML" as export format instead of "anonymous XML".

TheGroundZero commented 4 years ago

@beercity , your error seems to be about a NVT not having a CVE.

vuln_cves = nvt_tmp.find("./cve").text
AttributeError: 'NoneType' object has no attribute 'text'

This is the related code section:

# --------------------
#
# VULN_CVES
vuln_cves = nvt_tmp.find("./cve").text
if vuln_cves:
    if vuln_cves.lower() == "nocve":
        vuln_cves = []
    else:
        vuln_cves = [vuln_cves.lower()]

logging.debug("* vuln_cves:\t{}".format(vuln_cves))  # DEBUG

From the looks of it, nvt_tmp.find("./cve") returns null, aka None.
As such, resulting in None.text, which fails.

Can you test the following modification?

# --------------------
#
# VULN_CVES
vuln_cves = nvt_tmp.find("./cve")
if vuln_cves is None or vuln_cves.text.lower() == "nocve":
    vuln_cves = []
else:
    vuln_cves = [vuln_cves.text.lower()]

logging.debug("* vuln_cves:\t{}".format(vuln_cves))  # DEBUG

@BitFlipp3r, yours is about a task missing it's name.
This may indeed be related to the XML being anonymised.

logging.debug("= {}".format(root.find("./task/name").text))  # DEBUG
AttributeError: 'NoneType' object has no attribute 'text'
beercity commented 4 years ago

Thanks for the suggestion. No change though. Issue persists.

cadeath commented 4 years ago

Thanks for the suggestion. No change though. Issue persists.

are you using Docker?

cadeath commented 4 years ago

I have not fix the error but what I did were

  1. use the XML, not the Anonymous XML
  2. download the docx template using the repo
  3. and run command with

-i [xml] -f docx -t [template.docx]

rux616 commented 4 years ago

Gonna pile on and say that I'm getting this error as well, but for "tags":

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/dan/src/github.com/TheGroundZero/openvasreporting/openvasreporting/__main__.py", line 17, in <module>
    main()
  File "/home/dan/src/github.com/TheGroundZero/openvasreporting/openvasreporting/openvasreporting.py", line 33, in main
    convert(config)
  File "/home/dan/src/github.com/TheGroundZero/openvasreporting/openvasreporting/openvasreporting.py", line 87, in convert
    openvas_info = openvas_parser(config.input_files, config.min_level)
  File "/home/dan/src/github.com/TheGroundZero/openvasreporting/openvasreporting/libs/parser.py", line 121, in openvas_parser
    vuln_tags_text = re.sub(r"(\r\n)+", "\r\n", nvt_tmp.find("./tags").text)
AttributeError: 'NoneType' object has no attribute 'text'

Local OS Info: OS: Ubuntu 18.04 on WSL2 Python: v3.6.9

OpenVAS Reporting Info: Install: Run from repo Version: commit 1d7e1c7 Command: python3 -m openvasreporting -i /mnt/c/Users/dan/Downloads/report-9aaa71bc-2009-4527-a862-8f513098aca6.xml

GVM Info: OS: Docker via a Google Container-Optimized OS instance GVM release: GVM-10 Source Edition Filetype: Filtered Report from "CVE" scanner in XML format Specific component versions:

I'm running a private fork of https://github.com/bug-c/openvas-docker that is updated to be based from Debian Buster and has a few additional apt packages installed.

Edit: It looks like it's the scanner type that I attempted to generate a report for: CVE. If I run openvasreporting on a report generated from an OpenVAS scanner, it works.

dimazarno commented 4 years ago

I have not fix the error but what I did were

  1. use the XML, not the Anonymous XML
  2. download the docx template using the repo
  3. and run command with

-i [xml] -f docx -t [template.docx]

which repo?

TheGroundZero commented 4 years ago

I have not fix the error but what I did were

  1. use the XML, not the Anonymous XML
  2. download the docx template using the repo
  3. and run command with

-i [xml] -f docx -t [template.docx]

which repo?

This one? i.e. https://github.com/TheGroundZero/openvasreporting

Docx template: https://github.com/TheGroundZero/openvasreporting/blob/master/openvasreporting/src/openvas-template.docx

cadeath commented 4 years ago

I have not fix the error but what I did were

  1. use the XML, not the Anonymous XML
  2. download the docx template using the repo
  3. and run command with

-i [xml] -f docx -t [template.docx]

which repo?

This one? i.e. https://github.com/TheGroundZero/openvasreporting

Docx template: https://github.com/TheGroundZero/openvasreporting/blob/master/openvasreporting/src/openvas-template.docx

Sorry for the late reply. YES! It worked on me.

linuxtoxa commented 4 years ago

Hello! But not for me, i have the same error as without template.

python3 -m openvasreporting -i .xml -o docxreport -f docx -t "openvas-template.docx" 2020-05-22 10:56:18 | DEBUG | root | ================================================================================ 2020-05-22 10:56:18 | DEBUG | root | ================================================================================ 2020-05-22 10:56:18 | DEBUG | root | -------------------------------------------------------------------------------- 2020-05-22 10:56:18 | DEBUG | root | - SSL/TLS: Deprecated SSLv2 and SSLv3 Protocol Detection 2020-05-22 10:56:18 | DEBUG | root | -------------------------------------------------------------------------------- 2020-05-22 10:56:18 | DEBUG | root | vuln_id: 1.3.6.1.4.1.25623.1.0.111012 2020-05-22 10:56:18 | DEBUG | root | vuln_cvss: 4.3 2020-05-22 10:56:18 | DEBUG | root | vuln_level: medium 2020-05-22 10:56:18 | DEBUG | root | min_level: medium 2020-05-22 10:56:18 | DEBUG | root | vuln_host: 1.1.1.1 port: 443/tcp 2020-05-22 10:56:18 | DEBUG | root | vuln_tags: {'cvss_base_vector': 'AV:N/AC:M/Au:N/C:P/I:N/A:N', 'summary': 'It was possible to detect the usage of the\n deprecated SSLv2 and/or SSLv3 protocol on this system.', 'insight': 'The SSLv2 and SSLv3 protocols containing\n known cryptographic flaws like:\n - Padding Oracle On Downgraded Legacy Encryption (POODLE, CVE-2014-3566)\n - Decrypting RSA with Obsolete and Weakened eNcryption (DROWN, CVE-2016-0800)', 'affected': 'All services providing an encrypted communication\n using the SSLv2 and/or SSLv3 protocols.', 'impact': 'An attacker might be able to use the known\n cryptographic flaws to eavesdrop the connection between clients and the service\n to get access to sensitive data transferred within the secured connection.', 'solution': 'It is recommended to disable the deprecated\n SSLv2 and/or SSLv3 protocols in favor of the TLSv1+ protocols. Please see the\n references for more information.', 'vuldetect': 'Check the used protocols of the services\n provided by this system.', 'solution_type': 'Mitigation'} 2020-05-22 10:56:18 | DEBUG | root | vuln_threat: medium 2020-05-22 10:56:18 | DEBUG | root | * vuln_family: SSL and TLS Traceback (most recent call last): File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.8/runpy.py", line 86, in _run_code exec(code, run_globals) File "/home/user/Downloads/openvasreporting/openvasreporting/main.py", line 17, in main() File "/home/user/Downloads/openvasreporting/openvasreporting/openvasreporting.py", line 33, in main convert(config) File "/home/user/Downloads/openvasreporting/openvasreporting/openvasreporting.py", line 87, in convert openvas_info = openvas_parser(config.input_files, config.min_level) File "/home/user/Downloads/openvasreporting/openvasreporting/libs/parser.py", line 150, in openvas_parser vuln_cves = nvt_tmp.find("./cve").text AttributeError: 'NoneType' object has no attribute 'text'

@TheGroundZero Any ideas? GVM version https://hub.docker.com/r/securecompliance/gvm Thank you.

linuxtoxa commented 4 years ago
vuln_cves = nvt_tmp.find("./cve")
if vuln_cves is None or vuln_cves.text.lower() == "nocve":
  vuln_cves = []
else:
  vuln_cves = [vuln_cves.text.lower()]

logging.debug("* vuln_cves:\t{}".format(vuln_cves))  # DEBUG

With this patch

Traceback (most recent call last): File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.8/runpy.py", line 86, in _run_code exec(code, run_globals) File "/home/user/Downloads/openvasreporting/openvasreporting/main.py", line 17, in main() File "/home/user/Downloads/openvasreporting/openvasreporting/openvasreporting.py", line 33, in main convert(config) File "/home/user/Downloads/openvasreporting/openvasreporting/openvasreporting.py", line 87, in convert openvas_info = openvas_parser(config.input_files, config.min_level) File "/home/user/Downloads/openvasreporting/openvasreporting/libs/parser.py", line 169, in openvas_parser vuln_references = nvt_tmp.find("./xref").text AttributeError: 'NoneType' object has no attribute 'text'

TheGroundZero commented 4 years ago

Looks like both xref and cve are sometimes missing from the report output.

I made the (apparently incorrect) assumption that they'd always be present.
I'll have to add null/None checks at each of the params.

Will try to free up some time later today to do so.

linuxtoxa commented 4 years ago
168             # VULN_REFERENCES                                                   
169             vuln_references = nvt_tmp.find("./xref")                                                                                                                                                                                      
170             if vuln_references is None or vuln_references.lower() == "noxref":  
171                 vuln_references = []                                            
172             else:                                                               
173                 vuln_references = vuln_references.lower().replace("url:", "\n") 
174                                                                                 
175             logging.debug("* vuln_references:\t{}".format(vuln_references))  # DEBUG

You're right, I fixed it, and it worked. Thanks!

TheGroundZero commented 4 years ago

Made some changes to the code. Did so from the Github code editor, so changes are not tested.