Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nmap port not in output for hosts that are down - KeyError #46

Closed
marius-udubasa opened this issue Dec 3, 2019 · 4 comments
Closed

Comments

@marius-udubasa
Copy link

marius-udubasa commented Dec 3, 2019

It seems that the nmap output does not include the port information for hosts that are down:

<host><status state="down" reason="no-response" reason_ttl="0"/>
<address addr="192.168.4.2" addrtype="ipv4"/>
</host>

with a dict equivalent of

OrderedDict(
    [
        ('status', OrderedDict(
                        [
                            ('@state', 'down'), 
                            ('@reason', 'no-response'), 
                            ('@reason_ttl', '0')
                        ]
                    )
        ), 
        ('address', OrderedDict(
                        [
                            ('@addr', '192.168.4.2'), 
                            ('@addrtype', 'ipv4')
                        ]
                    )
        )
    ]
)

And for that reason the error:

# Nmap done at Mon Dec  2 17:40:43 2019 -- 512 IP addresses (103 hosts up) scanned in 2031.30 seconds
Traceback (most recent call last):
  File "/output_report.py", line 238, in <module>
    main()
  File "/output_report.py", line 229, in main
    parse_results(data)
  File "/output_report.py", line 113, in parse_results
    parse_host(h)
  File "/output_report.py", line 98, in parse_host
    if host['status']['@state'] == 'up' and 'port' in host['ports'].keys():
KeyError: 'ports'
sed: /shared/reports/report_2019.12.02-16.51.tex: No such file or directory

One quick fix I have found is to change the if statement on that line (line 98 now) to include a basic key check:

# vim +98 output_report.py

# old
    if host['status']['@state'] == 'up' and 'port' in host['ports'].keys():

# new
    if 'ports' in host.keys() and host['status']['@state'] == 'up' and 'port' in host['ports'].keys():

and then run again make build before make start

@marius-udubasa marius-udubasa changed the title nmap port not in output for hosts that are down nmap port not in output for hosts that are down - KeyError Dec 3, 2019
@nadinelyab
Copy link
Contributor

Hey @marius-udubasa,
Though your solution works, I don't think the reason you state for why this occurs is right. If you notice the second part of that if statement 'port' in host['ports'].keys() will only be executed if the first part is true, that is if host['status']['@state'] == 'up'. I am curious what the actual source of this error is in your particular case so if you wouldn't mind uploading the xml files you are getting I can figure out what the error is. Thanks!

@nadinelyab
Copy link
Contributor

Didn't meant to close the issue sorry

@nadinelyab nadinelyab reopened this Dec 3, 2019
@marius-udubasa
Copy link
Author

Hi, thanks for looking into this.
Sure. But is it ok if a send the xml files as a pm?

nadinelyab pushed a commit that referenced this issue Mar 10, 2020
… error when getting description from the cache. The entire vuln description object should be saved in the cache not just the string of the description. Also added all __pycache__ files to gitignore
@nadinelyab
Copy link
Contributor

Hey @marius-udubasa ,
Sorry for the delay in fixing this. It looks like you were right about the fix and the issue happens when a host is up but there are not open ports. Thanks for sending along your xml files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants