Skip to content

Commit

Permalink
Merge branch 'stable' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Arusekk committed Oct 29, 2023
2 parents e9f73bf + 0c1121d commit 8cf3ecd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ The table below shows which release corresponds to each branch, and what date th

## 4.11.1 (`stable`)

- [#2271][2271] FIX: Generated shebang with path to python invalid if path contains spaces
- [#2272][2272] Fix `tube.clean_and_log` not logging buffered data
- [#2281][2281] FIX: Getting right amount of data for search fix

[2271]: https://github.com/Gallopsled/pwntools/pull/2271
[2272]: https://github.com/Gallopsled/pwntools/pull/2272
[2281]: https://github.com/Gallopsled/pwntools/pull/2281

## 4.11.0
Expand Down
30 changes: 18 additions & 12 deletions examples/clean_and_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@
"""

from pwn import *
from multiprocessing import Process

os.system('''((
echo prefix sometext ;
echo prefix someothertext ;
echo here comes the flag ;
echo LostInTheInterTubes
) | nc -l 1337) &
''')
def submit_data():
with context.quiet:
with listen(1337) as io:
io.wait_for_connection()
io.sendline(b'prefix sometext')
io.sendline(b'prefix someothertext')
io.sendline(b'here comes the flag')
io.sendline(b'LostInTheInterTubes')

r = remote('localhost', 1337)
atexit.register(r.clean_and_log)
if __name__ == '__main__':
p = Process(target=submit_data)
p.start()

while True:
line = r.recvline()
print(re.findall(r'^prefix (\S+)$', line)[0])
r = remote('localhost', 1337)
atexit.register(r.clean_and_log)

while True:
line = r.recvline()
print(re.findall(br'^prefix (\S+)$', line)[0])
4 changes: 3 additions & 1 deletion pwnlib/timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def __enter__(self):
self.obj._stop = min(self.obj._stop, self.old_stop)

self.obj._timeout = self.timeout
self.obj.timeout_change()
def __exit__(self, *a):
self.obj._timeout = self.old_timeout
self.obj._stop = self.old_stop
self.obj.timeout_change()

class _local_handler(object):
def __init__(self, obj, timeout):
Expand Down Expand Up @@ -157,7 +159,7 @@ def _get_timeout_seconds(self, value):
else:
value = float(value)

if value is value < 0:
if value < 0:
raise AttributeError("timeout: Timeout cannot be negative")

if value > self.maximum:
Expand Down
7 changes: 6 additions & 1 deletion pwnlib/tubes/tube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,8 +1034,13 @@ def clean_and_log(self, timeout = 0.05):
b'hooray_data'
>>> context.clear()
"""
cached_data = self.buffer.get()
if cached_data and not self.isEnabledFor(logging.DEBUG):
with context.local(log_level='debug'):
self.debug('Received %#x bytes:' % len(cached_data))
self.maybe_hexdump(cached_data, level=logging.DEBUG)
with context.local(log_level='debug'):
return self.clean(timeout)
return cached_data + self.clean(timeout)

def connect_input(self, other):
"""connect_input(other)
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
import os
os.execve({argv0!r}, {argv!r}, os.environ)
'''
script = script.format(executable=sys.executable,
script = script.format(executable='/bin/env ' * (' ' in sys.executable) + sys.executable,
argv=command,
argv0=which(command[0]))
script = script.lstrip()
Expand Down

0 comments on commit 8cf3ecd

Please sign in to comment.