Gallopsled / Gallopsled/pwntools

Listening on UDP needs 2 packets before it returns with recvuntil

Open
#1,713 4 comments 0 reactions 0 assignees View on GitHub
backport-required bug
Dominant language
Python
Stars
13.7k
Forks
1.9k
Avg merge
6d 23h
Merged PRs (30d)
3

Description

Thanks for contributing to Pwntools!

I made a DNS packet script that sends dns packets to a DNS server both written with pwntools.

When i called listen with udp it requires 2 packets before it can be captured.

poc code
terminal 1:
```py

l = listen(port=53, fam='ipv4',typ='udp')
print(l.recvuntil(b"test")
```

terminal 2:
```py
r = remote("localhost", 53, typ="udp",fam="ipv4")
r.send("test")
r.send("test")
```

The first send triggers the got connection and the second returns the recvuntil
ran with `sudo python3 t1.py DEBUG LOG_FILE=l1.txt`
`sudo python3 t2.py DEBUG LOG_FILE=l2.txt`

content of l1.txt
```
================================================================================
= Started at 2020-10-28T15:31:11 =
= sys.argv = [ =
= 't1.py', =
= ] =
================================================================================
================================================================================
= Started at 2020-10-28T15:31:11 =
= sys.argv = [ =
= 't1.py', =
= ] =
================================================================================
2020-10-28T15:31:11:INFO:pwnlib.tubes.listen.listen.140625667422288:Trying to bind to 0.0.0.0 on port 53
2020-10-28T15:31:11:INFO:pwnlib.tubes.listen.listen.140625667422288:Trying to bind to 0.0.0.0 on port 53: Trying 0.0.0.0
2020-10-28T15:31:11:INFO:pwnlib.tubes.listen.listen.140625667422288:Trying to bind to 0.0.0.0 on port 53: Done
================================================================================
= Started at 2020-10-28T15:31:11 =
= sys.argv = [ =
= 't1.py', =
= ] =
================================================================================
2020-10-28T15:31:11:INFO:pwnlib.tubes.listen.listen.140625667422288:Waiting for connections on 0.0.0.0:53
================================================================================
= Started at 2020-10-28T15:31:11 =
= sys.argv = [ =
= 't1.py', =
= ] =
================================================================================
2020-10-28T15:31:44:INFO:pwnlib.tubes.listen.listen.140625667422288:Waiting for connections on 0.0.0.0:53: Got connection from 127.0.0.1 on port 55530
2020-10-28T15:31:44:DEBUG:pwnlib.tubes.listen.listen.140625667422288:Received 0x4 bytes:
2020-10-28T15:31:44:DEBUG:pwnlib.tubes.listen.listen.140625667422288:b'test'
```

Contents of l2.txt
```
================================================================================
= Started at 2020-10-28T15:31:44 =
= sys.argv = [ =
= 't2.py', =
= ] =
================================================================================
================================================================================
= Started at 2020-10-28T15:31:44 =
= sys.argv = [ =
= 't2.py', =
= ] =
================================================================================
2020-10-28T15:31:44:INFO:pwnlib.tubes.remote.remote.139748061849680:Opening connection to localhost on port 53
2020-10-28T15:31:44:INFO:pwnlib.tubes.remote.remote.139748061849680:Opening connection to localhost on port 53: Trying 127.0.0.1
2020-10-28T15:31:44:INFO:pwnlib.tubes.remote.remote.139748061849680:Opening connection to localhost on port 53: Done
2020-10-28T15:31:44:DEBUG:pwnlib.tubes.remote.remote.139748061849680:Sent 0x4 bytes:
2020-10-28T15:31:44:DEBUG:pwnlib.tubes.remote.remote.139748061849680:b'test'
2020-10-28T15:31:44:DEBUG:pwnlib.tubes.remote.remote.139748061849680:Sent 0x4 bytes:
2020-10-28T15:31:44:DEBUG:pwnlib.tubes.remote.remote.139748061849680:b'test'

```

I have the latest version.
```
sudo python3 -m pip install --upgrade pwntools
Requirement already up-to-date: pwntools in /usr/local/lib/python3.8/dist-packages (4.2.2)
```
And it also happens in the docker container.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.