arthepsy / ssh-audit

SSH server auditing (banner, key exchange, encryption, mac, compression, compatibility, security, etc)
MIT License
2.96k stars 269 forks source link

AttributeError: 'str' object has no attribute 'decode' #14

Closed Rogdham closed 7 years ago

Rogdham commented 7 years ago

When using Python3, the following line raises an AttributeError:

payload = str(payload).decode('utf-8')

For example:

$ ./ssh-audit.py -1 github.com
Traceback (most recent call last):
  File "./ssh-audit.py", line 1685, in <module>
    audit(conf)
  File "./ssh-audit.py", line 1654, in audit
    payload = str(payload).decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'

I am using release 1.6.0 (76509a1011fa4da6644ec2a1627dc58853569378).

I am not sure if it is the only place where there is a problem with Python3 compatibility, might be worth a full check.

arthepsy commented 7 years ago

Thanks for the report!

This bug got introduced when I encountered that SSH.Socket.recv returned wrapped Exception not bytes and "fixed" it by fast commit, which wrapped returned result with str. In hindsight, that's incorrect, of course.

Overall, the code is being tested automatically with Python 2.6, 2.7, 3.3, 3.4, 3.5 via Travis CI (https://travis-ci.org/arthepsy/ssh-audit) and before each commit I verify it also manually, both by running py.test locally and checking some remote hosts. This bug slipped in, because this part of the code isn't being automatically testet jet and manual test didn't reveal that. I fixed that. Currently the test coverage is ~70%, but it's going to get close to 100% very soon. Tests are the part I'm currently working on the most.

I don't think there are more Python 3 incompatibilities, because when I introduce any 2/3 compatible code, I verify it with small scripts beforehand. But if You notice any incompatibilities at all, please let me know!

Can You verify that 6b76e68d0dab0701a833ee85663161278ef2b5d0 fixes the issue?

Rogdham commented 7 years ago

Seems to fix the issue for me :+1:

Thank you @arthepsy for your fast reply!