From 96d98cf192cf1e9bc5d6bbeff5311e8961e58439 Mon Sep 17 00:00:00 2001 From: Leopold Date: Fri, 1 Nov 2024 21:36:30 +0800 Subject: [PATCH] fix fromsocket to deal with ipv6 socket (#2497) * fix fromsocket to deal with ipv6 socket * add remote.fromsocket ipv6 test and update CHANGELOG.md * skip fromsocket ipv6 test --- CHANGELOG.md | 6 ++++++ pwnlib/tubes/remote.py | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37b77a9fe..4c5c96021 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -129,6 +129,12 @@ The table below shows which release corresponds to each branch, and what date th [2435]: https://github.com/Gallopsled/pwntools/pull/2435 [2437]: https://github.com/Gallopsled/pwntools/pull/2437 +## 4.13.2 + +- [#2497][2497] Fix remote.fromsocket() to handle AF_INET6 socket + +[2497]: https://github.com/Gallopsled/pwntools/pull/2497 + ## 4.13.1 (`stable`) - [#2445][2445] Fix parsing the PLT on Windows diff --git a/pwnlib/tubes/remote.py b/pwnlib/tubes/remote.py index 58008194c..4c6d9dcd2 100644 --- a/pwnlib/tubes/remote.py +++ b/pwnlib/tubes/remote.py @@ -53,6 +53,13 @@ class remote(sock): >>> r = remote.fromsocket(s) >>> r.recvn(4) b'HTTP' + >>> s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) #doctest: +SKIP + >>> s.connect(('2606:4700:4700::1111', 80)) #doctest: +SKIP + >>> s.send(b'GET ' + b'\r\n'*2) #doctest: +SKIP + 8 + >>> r = remote.fromsocket(s) #doctest: +SKIP + >>> r.recvn(4) #doctest: +SKIP + b'HTTP' """ def __init__(self, host, port, @@ -139,7 +146,7 @@ def fromsocket(cls, socket): Instance of pwnlib.tubes.remote.remote. """ s = socket - host, port = s.getpeername() + host, port = s.getpeername()[:2] return remote(host, port, fam=s.family, typ=s.type, sock=s) class tcp(remote):