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

Error connecting to a Tryhackme machine via SSH with a private key #185

Closed
connornguyxn opened this issue Aug 22, 2021 · 1 comment · Fixed by #194
Closed

Error connecting to a Tryhackme machine via SSH with a private key #185

connornguyxn opened this issue Aug 22, 2021 · 1 comment · Fixed by #194
Assignees
Labels
bug Something isn't working

Comments

@connornguyxn
Copy link

connornguyxn commented Aug 22, 2021

Bug Description

Got this error when connecting to TryHackMe's GamingServer room.

pwncat version

└─$ pwncat --version
0.4.3

Target System (aka "victim")

TryHackMe - GamingServer
https://tryhackme.com/room/gamingserver

Steps to Reproduce

Steps to reproduce the behavior:

  1. Connect to the box via SSH using a private key:
pwncat -i ssh.key john@gaming.thm
  1. Enter the RSA private key passphrase
  2. Error:
└─$ pwncat -i ssh.key john@gaming.thm
[14:24:26] Welcome to pwncat 🐈!
RSA Private Key Passphrase: *******                                                                 
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/pwncat-0.4.3-py3.9.egg/pwncat/channel/ssh.py", line 64, in __init__
    key = paramiko.RSAKey.from_private_key(identity)
  File "/usr/lib/python3/dist-packages/paramiko/pkey.py", line 256, in from_private_key
    key = cls(file_obj=file_obj, password=password)
  File "/usr/lib/python3/dist-packages/paramiko/rsakey.py", line 52, in __init__
    self._from_private_key(file_obj, password)
  File "/usr/lib/python3/dist-packages/paramiko/rsakey.py", line 179, in _from_private_key
    data = self._read_private_key("RSA", file_obj, password)
  File "/usr/lib/python3/dist-packages/paramiko/pkey.py", line 334, in _read_private_key
    data = self._read_private_key_pem(lines, end, password)
  File "/usr/lib/python3/dist-packages/paramiko/pkey.py", line 386, in _read_private_key_pem
    raise PasswordRequiredException("Private key file is encrypted")
paramiko.ssh_exception.PasswordRequiredException: Private key file is encrypted

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/pwncat", line 33, in <module>
    sys.exit(load_entry_point('pwncat==0.4.3', 'console_scripts', 'pwncat')())
  File "/usr/local/lib/python3.9/dist-packages/pwncat-0.4.3-py3.9.egg/pwncat/__main__.py", line 272, in main
    manager.create_session(
  File "/usr/local/lib/python3.9/dist-packages/pwncat-0.4.3-py3.9.egg/pwncat/manager.py", line 665, in create_session
    session = Session(self, platform, channel, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pwncat-0.4.3-py3.9.egg/pwncat/manager.py", line 80, in __init__
    channel = pwncat.channel.create(**kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pwncat-0.4.3-py3.9.egg/pwncat/channel/__init__.py", line 592, in create
    channel = find(prot)(**kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pwncat-0.4.3-py3.9.egg/pwncat/channel/ssh.py", line 68, in __init__
    key = paramiko.RSAKey.from_private_key_file(identity, password)
  File "/usr/lib/python3/dist-packages/paramiko/pkey.py", line 235, in from_private_key_file
    key = cls(filename=filename, password=password)
  File "/usr/lib/python3/dist-packages/paramiko/rsakey.py", line 55, in __init__
    self._from_private_key_file(filename, password)
  File "/usr/lib/python3/dist-packages/paramiko/rsakey.py", line 175, in _from_private_key_file
    data = self._read_private_key_file("RSA", filename, password)
  File "/usr/lib/python3/dist-packages/paramiko/pkey.py", line 307, in _read_private_key_file
    with open(filename, "r") as f:
TypeError: expected str, bytes or os.PathLike object, not TextIOWrapper

Expected Behavior

Pwncat should be able to connect to the machine.
The private key and passphrase are correct and normal SSH works just fine.

Screenshots

Screenshot_2021-08-22_14-25-27

Thank you.

@connornguyxn connornguyxn added the bug Something isn't working label Aug 22, 2021
@connornguyxn connornguyxn changed the title Error connecting to a Tryhackme machine via SSH using a private key Error connecting to a Tryhackme machine via SSH with a private key Aug 22, 2021
@calebstewart
Copy link
Owner

Apologies for not getting back to you. I've fixed this in the above pull request, and will be merging in a few minutes. I've tested with the mentioned Try hack me machine, and it seems to be working for me. Feel free to reopen or post again if something is still wonky. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants