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

LookupError: unknown encoding: idna #152

Closed
kastahl opened this issue Oct 13, 2022 · 15 comments
Closed

LookupError: unknown encoding: idna #152

kastahl opened this issue Oct 13, 2022 · 15 comments

Comments

@kastahl
Copy link

kastahl commented Oct 13, 2022

I get an exception when scanning some targets using targets file. When scanning these targets manually, it works fine.

I'm using the ssh-audit.exe in Version 2.5 on a Windows 10 VM.
For me it looks like to be an issue of missing import: import encodings.idna

An exception occurred while scanning 10.2xx.xx.xx:22:
Traceback (most recent call last):
File "ssh-audit.py", line 1017, in target_worker_thread
File "ssh-audit.py", line 842, in audit
File "ssh_socket.py", line 155, in connect
File "ssh_socket.py", line 85, in _resolve
File "socket.py", line 953, in getaddrinfo
LookupError: unknown encoding: idna


An exception occurred while scanning 10.2xx.xxx.xx:22:
Traceback (most recent call last):
File "ssh-audit.py", line 1017, in target_worker_thread
File "ssh-audit.py", line 842, in audit
File "ssh_socket.py", line 155, in connect
File "ssh_socket.py", line 85, in _resolve
File "socket.py", line 953, in getaddrinfo
LookupError: unknown encoding: idna


An exception occurred while scanning 10.2xx.xxx.xx:22:
Traceback (most recent call last):
File "ssh-audit.py", line 1017, in target_worker_thread
File "ssh-audit.py", line 842, in audit
File "ssh_socket.py", line 155, in connect
File "ssh_socket.py", line 85, in _resolve
File "socket.py", line 953, in getaddrinfo
LookupError: unknown encoding: idna


An exception occurred while scanning 10.2xx.xx.xx:22:
Traceback (most recent call last):
File "ssh-audit.py", line 1017, in target_worker_thread
File "ssh-audit.py", line 842, in audit
File "ssh_socket.py", line 155, in connect
File "ssh_socket.py", line 85, in _resolve
File "socket.py", line 953, in getaddrinfo
LookupError: unknown encoding: idna


An exception occurred while scanning 10.2xx.xxx.xx:22:
Traceback (most recent call last):
File "ssh-audit.py", line 1017, in target_worker_thread
File "ssh-audit.py", line 842, in audit
File "ssh_socket.py", line 155, in connect
File "ssh_socket.py", line 85, in _resolve
File "socket.py", line 953, in getaddrinfo
LookupError: unknown encoding: idna

@thecliguy
Copy link
Contributor

@kastahl I have done some debugging and it looks like this problem is very specfic to the executable version of ssh-audit for Windows which is built using pyinstaller.

Please can you tell me, how many targets do you have in your targets file?

@kastahl
Copy link
Author

kastahl commented Oct 14, 2022

@kastahl I have done some debugging and it looks like this problem is very specfic to the executable version of ssh-audit for Windows which is built using pyinstaller.

Please can you tell me, how many targets do you have in your targets file?

@thecliguy There are just 9 targets in the targets file. The first 4 targets will be processed.

@thecliguy
Copy link
Contributor

@kastahl Are all 9 targets scanned successfully if you use the parameter --threads=1?

EG:

C:\temp\ssh-audit.exe --targets=hosts.txt --threads=1

@kastahl
Copy link
Author

kastahl commented Oct 14, 2022

--threads=1

@thecliguy That works and all targets will be processed now. :)

@thecliguy
Copy link
Contributor

@kastahl Thanks for testing, much appreciated.

This confirms my suspicion that the problem relates to multithreading and appears only to affect the Windows executable version of ssh-audit.

Please leave this ticket open because although we now have a workaround (which is to avoid multiple threads), there is still a bug that needs to be fixed properly.

@jtesta
Copy link
Owner

jtesta commented Oct 15, 2022 via email

@jtesta
Copy link
Owner

jtesta commented Mar 24, 2023

Looks like this is related to the following CPython bug: python/cpython#73474

Someone in that thread suggested a workaround. I'll give that a try.

@jtesta
Copy link
Owner

jtesta commented Apr 25, 2023

@kastahl : I checked in a fix for this issue. A new release will be coming soon with it included!

I'll keep this issue open as a reminder to ping you once the release is complete.

@thecliguy
Copy link
Contributor

@jtesta : I've just read #152... When the workaround is invoked, a warning is printed advising that: "...Multi-threaded scanning can be enabled by installing the idna module (pip install idna)".

This problem is only known to occur with the executable version of ssh-audit for Windows which is built using pyinstaller...

My understanding is that all dependencies including the Python interpreter are bundled within the Windows executable. Therefore, a Windows user doesn't need Python to be installed. So on that basis, I don't think the advice of installing the idna module is applicable or actionable when dealing with the Windows executable because it doesn't interact with a locally installed copy of Python.

jtesta added a commit that referenced this issue Apr 27, 2023
…n v3.9 to v3.11 may have fixed the root cause. (#152)
@jtesta
Copy link
Owner

jtesta commented Apr 27, 2023

@thecliguy: I thought the problem happened in both the packaged executable as well as with the unpackaged source files. But when I went back and tried to reproduce both cases, I could no longer trigger the crash. I've since upgraded my build machine from Python v3.9 to v3.11, and I suspect that this addressed the root cause (!). Hence, I've commented out the workaround that I applied to the source tree.

If anyone notices this same crash using the latest commit in master, please chime in!

@oam7575
Copy link

oam7575 commented May 15, 2023

I have just carried out some basic testing with a variety of different python versions. Details below

Windows 10 22H2
ssh-audit master
command : "python.exe h:\GIT\ssh-audit\ssh-audit.py -T h:\GIT\ssh-audit\test.txt --threads=4"
text file contains 2x hosts with 2x formats for each host.
1x will succeed and 1x will fail for each ( deliberate incorrect port number )

  • Python 3.6.2 - Appears OK - No Errors
  • Python 3.7.0 - Appears OK - No Errors
  • Python 3.8.0 - Appears OK - No Errors
  • Python 3.9.13 - Appears OK - No Errors
  • Python 3.10.11 - Appears OK - No Errors
  • Python 3.11.3 - Appears OK - No Errors

@jtesta
Copy link
Owner

jtesta commented Jun 19, 2023

@oam7575 : thanks for doing all this testing! Does the precompiled Windows executable have any trouble on your system?

@jtesta
Copy link
Owner

jtesta commented Jun 21, 2023

@kastahl : I think this issue is fixed in the Windows executable released in v2.9.0. If you're able to test it on your system, that would be a big help! Thanks!

@kastahl
Copy link
Author

kastahl commented Jun 26, 2023

@jtesta I will try to test it in the next days. Will give feedback asap.

@jtesta
Copy link
Owner

jtesta commented Aug 25, 2023

@kastahl: Well, I suppose I'll close this issue, since v2.9.0 has been out for nearly 4 months, and no one has reported any problems with it. If you do run into the problem again, though, please re-open this issue.

Thanks for reporting it!

@jtesta jtesta closed this as completed Aug 25, 2023
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

4 participants