1
0
mirror of https://github.com/calebstewart/pwncat.git synced 2024-11-24 01:25:37 +01:00

Fixed ChannelError constructor calls

There is a missing argument to the ChannelError constructor - ch (channel). Because of this, many explicitly passed error messages are simply rejected. There is a minor typo correction as well, 'writiers' -> 'writers'.
This commit is contained in:
Mitul16 2021-06-18 16:17:53 +05:30
parent 89ad889977
commit 6b8a956c54
4 changed files with 25 additions and 11 deletions

View File

@ -37,7 +37,17 @@ class Connect(Socket):
) as progress:
progress.add_task("connecting", total=1, start=False)
# Connect to the remote host
client = socket.create_connection((host, port))
# If we get an invalid host from the user, that cannot be resolved
# then we capture the GAI (getaddrinfo) exception and raise it as ChannelError
# so that it is handled properly by the parent methods
try:
client = socket.create_connection((host, port))
except socket.gaierror:
raise ChannelError(self, "invalid host provided")
except ConnectionRefusedError:
raise ChannelError(self, "connection refused, check your port")
progress.log(
f"connection to "

View File

@ -34,7 +34,7 @@ class Ssh(Channel):
port = 22
if not user or user is None:
raise ChannelError("you must specify a user")
raise ChannelError(self, "you must specify a user")
if password is None and identity is None:
password = prompt("Password: ", is_password=True)
@ -43,7 +43,7 @@ class Ssh(Channel):
# Connect to the remote host's ssh server
sock = socket.create_connection((host, port))
except Exception as exc:
raise ChannelError(str(exc))
raise ChannelError(self, str(exc))
# Create a paramiko SSH transport layer around the socket
t = paramiko.Transport(sock)
@ -51,7 +51,7 @@ class Ssh(Channel):
t.start_client()
except paramiko.SSHException:
sock.close()
raise ChannelError("ssh negotiation failed")
raise ChannelError(self, "ssh negotiation failed")
if identity is not None:
try:
@ -67,23 +67,23 @@ class Ssh(Channel):
try:
key = paramiko.RSAKey.from_private_key_file(identity, password)
except paramiko.ssh_exception.SSHException:
raise ChannelError("invalid private key or passphrase")
raise ChannelError(self, "invalid private key or passphrase")
# Attempt authentication
try:
t.auth_publickey(user, key)
except paramiko.ssh_exception.AuthenticationException as exc:
raise ChannelError(str(exc))
raise ChannelError(self, str(exc))
else:
try:
t.auth_password(user, password)
except paramiko.ssh_exception.AuthenticationException as exc:
raise ChannelError(str(exc))
raise ChannelError(self, str(exc))
if not t.is_authenticated():
t.close()
sock.close()
raise ChannelError("authentication failed")
raise ChannelError(self, "authentication failed")
# Open an interactive session
chan = t.open_session()

View File

@ -653,7 +653,11 @@ class Manager:
specified platform.
"""
session = Session(self, platform, channel, **kwargs)
try:
session = Session(self, platform, channel, **kwargs)
except ChannelError as exc:
self.log(f"[red]error:[/red] {exc}")
return None
# Increment the ``session_id`` variable upon adding a new session
# Session constructor will automatically grab the current

View File

@ -1249,7 +1249,7 @@ class Linux(Platform):
except MissingBinary:
pass
else:
raise PlatformError("no available gtfobins writiers")
raise PlatformError("no available gtfobins writers")
popen = self.Popen(
payload,
@ -1278,7 +1278,7 @@ class Linux(Platform):
except MissingBinary:
pass
else:
raise PlatformError("no available gtfobins writiers")
raise PlatformError("no available gtfobins writers")
popen = self.Popen(
payload,