From 350824a8cb13234fb8e7bde71bd4d3ab71c7134d Mon Sep 17 00:00:00 2001 From: Caleb Stewart Date: Sun, 18 Jul 2021 13:48:12 -0400 Subject: [PATCH 1/2] Ignored extra results from ipv6 getpeername --- pwncat/channel/socket.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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) From 4e38393632c281e9d2945b0da972fa4207875d13 Mon Sep 17 00:00:00 2001 From: Caleb Stewart Date: Sun, 18 Jul 2021 13:54:09 -0400 Subject: [PATCH 2/2] Added changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index faec69e..e69e591 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