calebstewart / pwncat

Fancy reverse and bind shell handler
https://pwncat.readthedocs.io
MIT License
2.58k stars 250 forks source link

module 'paramiko.pkey' has no attribute 'load_private_key_file' #273

Open Randark-JMT opened 11 months ago

Randark-JMT commented 11 months ago

Bug Description

When I try to log into ssh with my private key, the following error occurs

AttributeError: module 'paramiko.pkey' has no attribute 'load_private_key_file'

pwncat version

Provide the output of pwncat --version or a commit hash if working from a development branch.

$pwncat-cs --version
0.5.4

Target System (aka "victim")

Linux Hackthebox Clicker

Steps to Reproduce

โ””โ”€โ”€โ•ผ $pwncat-cs 
[12:34:56] Welcome to pwncat ๐Ÿˆ!                                                                                                                                                                                            __main__.py:164
(local) pwncat$ connect -i id_rsa
[12:35:01] connection failed: no port specified                                                                                                                                                                              manager.py:957
(local) pwncat$ connect -i id_rsa jack@10.10.11.232
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Traceback (most recent call last) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚ /usr/local/lib/python3.9/dist-packages/pwncat/commands/__init__.py:591 in run                                                                                                                                                           โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚    588 โ”‚   โ”‚   โ”‚   โ”‚   if line == "":                                                                                                                                                                                                   โ”‚
โ”‚    589 โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   continue                                                                                                                                                                                                     โ”‚
โ”‚    590 โ”‚   โ”‚   โ”‚   โ”‚                                                                                                                                                                                                                    โ”‚
โ”‚ โฑ  591 โ”‚   โ”‚   โ”‚   โ”‚   self.dispatch_line(line)                                                                                                                                                                                         โ”‚
โ”‚    592 โ”‚   โ”‚   โ”‚   # We used to catch only KeyboardException, but this prevents a                                                                                                                                                       โ”‚
โ”‚    593 โ”‚   โ”‚   โ”‚   # badly written command from completely killing our remote                                                                                                                                                           โ”‚
โ”‚    594 โ”‚   โ”‚   โ”‚   # connection.                                                                                                                                                                                                        โ”‚
โ”‚ /usr/local/lib/python3.9/dist-packages/pwncat/commands/__init__.py:672 in dispatch_line                                                                                                                                                 โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚    669 โ”‚   โ”‚   โ”‚   โ”‚   args = line                                                                                                                                                                                                      โ”‚
โ”‚    670 โ”‚   โ”‚   โ”‚                                                                                                                                                                                                                        โ”‚
โ”‚    671 โ”‚   โ”‚   โ”‚   # Run the command                                                                                                                                                                                                    โ”‚
โ”‚ โฑ  672 โ”‚   โ”‚   โ”‚   command.run(self.manager, args)                                                                                                                                                                                      โ”‚
โ”‚    673 โ”‚   โ”‚   โ”‚                                                                                                                                                                                                                        โ”‚
โ”‚    674 โ”‚   โ”‚   โ”‚   if prog_name:                                                                                                                                                                                                        โ”‚
โ”‚    675 โ”‚   โ”‚   โ”‚   โ”‚   command.parser.prog = prog_name                                                                                                                                                                                  โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚ /usr/local/lib/python3.9/dist-packages/pwncat/commands/connect.py:295 in run                                                                                                                                                            โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚   292 โ”‚   โ”‚   โ”‚   manager.target.log(f"connected via {used_implant.title(manager.target)}")                                                                                                                                             โ”‚
โ”‚   293 โ”‚   โ”‚   else:                                                                                                                                                                                                                     โ”‚
โ”‚   294 โ”‚   โ”‚   โ”‚   try:                                                                                                                                                                                                                  โ”‚
โ”‚ โฑ 295 โ”‚   โ”‚   โ”‚   โ”‚   manager.create_session(**query_args)                                                                                                                                                                              โ”‚
โ”‚   296 โ”‚   โ”‚   โ”‚   except (ChannelError, PlatformError) as exc:                                                                                                                                                                          โ”‚
โ”‚   297 โ”‚   โ”‚   โ”‚   โ”‚   manager.log(f"connection failed: {exc}")                                                                                                                                                                          โ”‚
โ”‚   298 โ”‚   โ”‚   โ”‚   except KeyboardInterrupt:                                                                                                                                                                                             โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚ /usr/local/lib/python3.9/dist-packages/pwncat/manager.py:1192 in create_session                                                                                                                                                         โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚   1189 โ”‚   โ”‚   โ”‚   PlatformError: construction of a platform around the channel failed                                                                                                                                                  โ”‚
โ”‚   1190 โ”‚   โ”‚   """                                                                                                                                                                                                                      โ”‚
โ”‚   1191 โ”‚   โ”‚                                                                                                                                                                                                                            โ”‚
โ”‚ โฑ 1192 โ”‚   โ”‚   session = Session(self, platform, channel, **kwargs)                                                                                                                                                                     โ”‚
โ”‚   1193 โ”‚   โ”‚                                                                                                                                                                                                                            โ”‚
โ”‚   1194 โ”‚   โ”‚   # Increment the ``session_id`` variable upon adding a new session                                                                                                                                                        โ”‚
โ”‚   1195 โ”‚   โ”‚   # Session constructor will automatically grab the current                                                                                                                                                                โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚ /usr/local/lib/python3.9/dist-packages/pwncat/manager.py:518 in __init__                                                                                                                                                                โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚    515 โ”‚   โ”‚   else:                                                                                                                                                                                                                    โ”‚
โ”‚    516 โ”‚   โ”‚   โ”‚   # If necessary, build a new channel                                                                                                                                                                                  โ”‚
โ”‚    517 โ”‚   โ”‚   โ”‚   if channel is None:                                                                                                                                                                                                  โ”‚
โ”‚ โฑ  518 โ”‚   โ”‚   โ”‚   โ”‚   channel = pwncat.channel.create(**kwargs)                                                                                                                                                                        โ”‚
โ”‚    519 โ”‚   โ”‚   โ”‚                                                                                                                                                                                                                        โ”‚
โ”‚    520 โ”‚   โ”‚   โ”‚   # This makes logging work during the constructor                                                                                                                                                                     โ”‚
โ”‚    521 โ”‚   โ”‚   โ”‚   self.platform = str(channel)                                                                                                                                                                                         โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚ /usr/local/lib/python3.9/dist-packages/pwncat/channel/__init__.py:602 in create                                                                                                                                                         โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚   599 โ”‚                                                                                                                                                                                                                                 โ”‚
โ”‚   600 โ”‚   for prot in protocols:                                                                                                                                                                                                        โ”‚
โ”‚   601 โ”‚   โ”‚   try:                                                                                                                                                                                                                      โ”‚
โ”‚ โฑ 602 โ”‚   โ”‚   โ”‚   channel = find(prot)(**kwargs)                                                                                                                                                                                        โ”‚
โ”‚   603 โ”‚   โ”‚   โ”‚   return channel                                                                                                                                                                                                        โ”‚
โ”‚   604 โ”‚   โ”‚   except ChannelError:                                                                                                                                                                                                      โ”‚
โ”‚   605 โ”‚   โ”‚   โ”‚   if len(protocols) == 1 or prot != "reconnect":                                                                                                                                                                        โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚ /usr/local/lib/python3.9/dist-packages/pwncat/channel/ssh.py:57 in __init__                                                                                                                                                             โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚    54 โ”‚   โ”‚   โ”‚   โ”‚   port=port,                                                                                                                                                                                                        โ”‚
โ”‚    55 โ”‚   โ”‚   โ”‚   โ”‚   username=user,                                                                                                                                                                                                    โ”‚
โ”‚    56 โ”‚   โ”‚   โ”‚   โ”‚   password=password,                                                                                                                                                                                                โ”‚
โ”‚ โฑ  57 โ”‚   โ”‚   โ”‚   โ”‚   pkey=load_private_key(identity),                                                                                                                                                                                  โ”‚
โ”‚    58 โ”‚   โ”‚   โ”‚   โ”‚   allow_agent=True,                                                                                                                                                                                                 โ”‚
โ”‚    59 โ”‚   โ”‚   โ”‚   โ”‚   look_for_keys=False,                                                                                                                                                                                              โ”‚
โ”‚    60 โ”‚   โ”‚   โ”‚   )                                                                                                                                                                                                                     โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚ /usr/local/lib/python3.9/dist-packages/pwncat/channel/ssh.py:132 in load_private_key                                                                                                                                                    โ”‚
โ”‚                                                                                                                                                                                                                                         โ”‚
โ”‚   129 โ”‚                                                                                                                                                                                                                                 โ”‚
โ”‚   130 โ”‚   try:                                                                                                                                                                                                                          โ”‚
โ”‚   131 โ”‚   โ”‚   if isinstance(identity, str):                                                                                                                                                                                             โ”‚
โ”‚ โฑ 132 โ”‚   โ”‚   โ”‚   return paramiko.pkey.load_private_key_file(                                                                                                                                                                           โ”‚
โ”‚   133 โ”‚   โ”‚   โ”‚   โ”‚   os.path.expanduser(identity), password=passphrase                                                                                                                                                                 โ”‚
โ”‚   134 โ”‚   โ”‚   โ”‚   )                                                                                                                                                                                                                     โ”‚
โ”‚   135                                                                                                                                                                                                                                   โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
AttributeError: module 'paramiko.pkey' has no attribute 'load_private_key_file'

Expected Behavior

pwncat should accept the private key and establish an ssh session

Screenshots

ๅ›พ็‰‡ ๅ›พ็‰‡

cpu0x00 commented 8 months ago

getting the same error

cpu0x00 commented 8 months ago

was able to solve it by changing line 57 in /usr/local/lib/python3.11/dist-packages/pwncat/channel/ssh.py removing the "pkey" option and replacing with key_filename however i hardcoded my key location, but i guess a simple edit could be made to get dynamically using the identity cli argument