4elta / recon

automate the boring stuff!
GNU General Public License v3.0
8 stars 3 forks source link

ssh analyzer crashes with TypeError: expected string or bytes-like object, got 'NoneType' #51

Closed ikstream closed 1 year ago

ikstream commented 1 year ago

When running the ssh analyzer an `TypeError' exception is thrown.

python analyze.py -i /logs/recon ssh           

Vulnerabilities and/or deviations from the recommended settings (`/home/ikstream/docs/workspace/recon/config/recommendations/ssh/default.toml`):

Traceback (most recent call last):
  File "/recon/analyze.py", line 173, in <module>
    main()
  File "/recon/analyze.py", line 170, in main
    process(parser.parse_args())
  File "/recon/analyze.py", line 122, in process
    analyze_service(
  File "/recon/analyze.py", line 45, in analyze_service
    services = analyzer.analyze(files)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/recon/analyzers/ssh/__init__.py", line 40, in analyze
    services = self.parser.parse_files(files[self.parser_name])
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/recon/analyzers/__init__.py", line 24, in parse_files
    self.parse_file(path)
  File "/recon/analyzers/ssh/nmap.py", line 89, in parse_file
    service['protocol_version'] = self._parse_protocol_version(service_node.get('extrainfo'))
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/recon/analyzers/ssh/nmap.py", line 131, in _parse_protocol_version
    m = re.search(
        ^^^^^^^^^^
  File "/usr/lib/python3.11/re/__init__.py", line 176, in search
    return _compile(pattern, flags).search(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

This is caused by a missing extrainfo entry in the xml file. The scan seems to have failed to some extend as the ports section shows an error

<ports><port protocol="tcp" portid="22"><state state="open" reason="syn-ack" reason_ttl="128"/><service name="tcpwrapped" method="probed" conf="8"/><script id="ssh-hostkey" output="ERROR: Script execution failed (use -d to debug)"/><script id="ssh-auth-methods" output="ERROR: Script execution failed (use -d to debug)"/></port></ports>

lmk if you need the full xml file, i can provide it later today.

4elta commented 1 year ago

thanks for this issue report