Skip to content

Commit

Permalink
fix fromsocket to deal with ipv6 socket (#2497)
Browse files Browse the repository at this point in the history
* fix fromsocket to deal with ipv6 socket

* add remote.fromsocket ipv6 test and update CHANGELOG.md

* skip fromsocket ipv6 test
  • Loading branch information
leommxj authored Nov 1, 2024
1 parent 8926a3a commit 96d98cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion pwnlib/tubes/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 96d98cf

Please sign in to comment.