diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d5cf0e..405e16a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and simply didn't have the time to go back and retroactively create one. ### Fixed - Possible exception due to _pre-registering_ of `session` with `manager` +- Fixed handling of `socket.getpeername` when `Socket` channel uses IPv6 ([#159](https://github.com/calebstewart/pwncat/issues/159)). ### Added - Added alternatives to `bash` to be used during _shell upgrade_ for a _better shell_ - Added a warning message when a `KeyboardInterrupt` is caught diff --git a/pwncat/channel/socket.py b/pwncat/channel/socket.py index 4017523..317754a 100644 --- a/pwncat/channel/socket.py +++ b/pwncat/channel/socket.py @@ -50,7 +50,11 @@ class Socket(Channel): if client is not None: # Report host and port number to base channel - host, port = client.getpeername() + host, port, *_ = client.getpeername() + + # Localhost is sometimes a IPv4 and sometimes IPv6 socket, just normalize the name + if host == "::1" or host == "127.0.0.1": + host = "localhost" if "host" not in kwargs: kwargs["host"] = host @@ -78,6 +82,10 @@ class Socket(Channel): self.client = client self.address = client.getpeername() + # Localhost is sometimes a IPv4 and sometimes IPv6 socket, just normalize the name + if self.address[0] == "::1" or self.address[0] == "127.0.0.1": + self.address = ("localhost", *self.address[1:]) + self.client.setblocking(False) fcntl.fcntl(self.client, fcntl.F_SETFL, os.O_NONBLOCK)