Skip to content

Commit dafd42b

Browse files
peace-makerArusekk
andauthored
Fix tube.clean_and_log not logging buffered data (#2272)
* Fix tube.clean_and_log not logging buffered data Only new data received after the `clean_and_log` call is printed while data already received and buffered earlier is not. Print the buffered data first before waiting for more so we don't miss anything. * Only show buffered data if DEBUG is off * Update CHANGELOG.md --------- Co-authored-by: Arusekk <[email protected]>
1 parent 3ff37a8 commit dafd42b

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ The table below shows which release corresponds to each branch, and what date th
9191

9292
## 4.11.1 (`stable`)
9393

94+
- [#2272][2272] Fix `tube.clean_and_log` not logging buffered data
9495
- [#2281][2281] FIX: Getting right amount of data for search fix
9596

97+
[2272]: https://github.com/Gallopsled/pwntools/pull/2272
9698
[2281]: https://github.com/Gallopsled/pwntools/pull/2281
9799

98100
## 4.11.0

examples/clean_and_log.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,24 @@
1111
"""
1212

1313
from pwn import *
14+
from multiprocessing import Process
1415

15-
os.system('''((
16-
echo prefix sometext ;
17-
echo prefix someothertext ;
18-
echo here comes the flag ;
19-
echo LostInTheInterTubes
20-
) | nc -l 1337) &
21-
''')
16+
def submit_data():
17+
with context.quiet:
18+
with listen(1337) as io:
19+
io.wait_for_connection()
20+
io.sendline(b'prefix sometext')
21+
io.sendline(b'prefix someothertext')
22+
io.sendline(b'here comes the flag')
23+
io.sendline(b'LostInTheInterTubes')
2224

23-
r = remote('localhost', 1337)
24-
atexit.register(r.clean_and_log)
25+
if __name__ == '__main__':
26+
p = Process(target=submit_data)
27+
p.start()
2528

26-
while True:
27-
line = r.recvline()
28-
print(re.findall(r'^prefix (\S+)$', line)[0])
29+
r = remote('localhost', 1337)
30+
atexit.register(r.clean_and_log)
31+
32+
while True:
33+
line = r.recvline()
34+
print(re.findall(br'^prefix (\S+)$', line)[0])

pwnlib/tubes/tube.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,13 @@ def clean_and_log(self, timeout = 0.05):
10341034
b'hooray_data'
10351035
>>> context.clear()
10361036
"""
1037+
cached_data = self.buffer.get()
1038+
if cached_data and not self.isEnabledFor(logging.DEBUG):
1039+
with context.local(log_level='debug'):
1040+
self.debug('Received %#x bytes:' % len(cached_data))
1041+
self.maybe_hexdump(cached_data, level=logging.DEBUG)
10371042
with context.local(log_level='debug'):
1038-
return self.clean(timeout)
1043+
return cached_data + self.clean(timeout)
10391044

10401045
def connect_input(self, other):
10411046
"""connect_input(other)

0 commit comments

Comments
 (0)