Skip to content

Commit

Permalink
Merge branch 'dev' into template_detect_files
Browse files Browse the repository at this point in the history
  • Loading branch information
peace-maker authored Dec 7, 2023
2 parents fb78115 + b1e2b56 commit 46d6fc0
Show file tree
Hide file tree
Showing 21 changed files with 505 additions and 493 deletions.
3 changes: 3 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ build:
tools:
python: "3"

sphinx:
configuration: docs/source/conf.py

python:
install:
- requirements: docs/requirements.txt
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,20 @@ The table below shows which release corresponds to each branch, and what date th

## 4.13.0 (`dev`)

- [#2242][2242] Term module revamp: activating special handling of terminal only when necessary
- [#2277][2277] elf: Resolve more relocations into GOT entries
- [#2281][2281] FIX: Getting right amount of data for search fix
- [#2293][2293] Add x86 CET status to checksec output
- [#1763][1763] Allow to add to the existing environment in `process` instead of replacing it
- [#2307][2307] Fix `pwn libcdb file` crashing if "/bin/sh" string was not found
- [#2309][2309] Detect challenge binary and libc in `pwn template`

[2242]: https://github.com/Gallopsled/pwntools/pull/2242
[2277]: https://github.com/Gallopsled/pwntools/pull/2277
[2281]: https://github.com/Gallopsled/pwntools/pull/2281
[2293]: https://github.com/Gallopsled/pwntools/pull/2293
[1763]: https://github.com/Gallopsled/pwntools/pull/1763
[2307]: https://github.com/Gallopsled/pwntools/pull/2307
[2309]: https://github.com/Gallopsled/pwntools/pull/2309

## 4.12.0 (`beta`)
Expand Down
8 changes: 3 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def __setattr__(self, name, value):

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -265,8 +265,8 @@ def __setattr__(self, name, value):
u'2016, Gallopsled et al.', 'manual'),
]

intersphinx_mapping = {'python': ('https://docs.python.org/3.8', None),
'paramiko': ('https://paramiko-docs.readthedocs.org/en/2.1/', None)}
intersphinx_mapping = {'python': ('https://docs.python.org/3/', None),
'paramiko': ('https://docs.paramiko.org/en/2.1/', None)}

# The name of an image file (relative to this directory) to place at the top of
# the title page.
Expand Down Expand Up @@ -382,8 +382,6 @@ def linkcode_resolve(domain, info):
html_theme_path = [alabaster.get_path()]
html_theme_options = { 'nosidebar' : True }

# otherwise, readthedocs.org uses their theme by default, so no need to specify it


# -- Customization to Sphinx autodoc generation --------------------------------------------
import sphinx.ext.autodoc
Expand Down
2 changes: 1 addition & 1 deletion examples/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

from pwn import *

opts = [string.letters[x] for x in range(10)]
opts = [string.ascii_letters[x] for x in range(12)]
print('You choose "%s"' % opts[options('Pick one:', opts)])
10 changes: 7 additions & 3 deletions pwnlib/commandline/libcdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ def translate_offset(offs, args, exe):
return offs

def collect_synthetic_symbols(exe):
available_symbols = ['str_bin_sh']
exe.symbols['str_bin_sh'] = next(exe.search(b'/bin/sh\x00'))

available_symbols = []
try:
exe.symbols['str_bin_sh'] = next(exe.search(b'/bin/sh\x00'))
available_symbols.append('str_bin_sh')
except StopIteration:
pass

libc_start_main_return = exe.libc_start_main_return
if libc_start_main_return > 0:
exe.symbols['__libc_start_main_ret'] = libc_start_main_return
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ def arch(self, arch):
try:
defaults = self.architectures[arch]
except KeyError:
raise AttributeError('AttributeError: arch must be one of %r' % sorted(self.architectures))
raise AttributeError('AttributeError: arch (%r) must be one of %r' % (arch, sorted(self.architectures)))

for k,v in defaults.items():
if k not in self._tls:
Expand Down
Binary file added pwnlib/data/elf/test-x32
Binary file not shown.
Binary file added pwnlib/data/elf/test-x32-pie
Binary file not shown.
Binary file added pwnlib/data/elf/test-x32-relro
Binary file not shown.
Binary file added pwnlib/data/elf/test-x32-relro-pie
Binary file not shown.
1 change: 1 addition & 0 deletions pwnlib/elf/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def _describe(self, *a, **kw):
def get_machine_arch(self):
return {
('EM_X86_64', 64): 'amd64',
('EM_X86_64', 32): 'amd64', # x32 ABI
('EM_386', 32): 'i386',
('EM_486', 32): 'i386',
('EM_ARM', 32): 'arm',
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def emit(self, record):

# we enrich the `Progress` object to keep track of the spinner
if not hasattr(progress, '_spinner_handle'):
spinner_handle = term.output('')
spinner_handle = term.output('[x] ')
msg_handle = term.output(msg)
stop = threading.Event()
def spin():
Expand Down
94 changes: 94 additions & 0 deletions pwnlib/py2compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"""
Compatibility layer with python 2, allowing us to write normal code.
Beware, some monkey-patching is done.
"""

import os
import shutil
import sys
try:
import fcntl
import termios
except ImportError:
pass

from collections import namedtuple
from struct import Struct

def py2_monkey_patch(module):
def decorator(f):
if sys.version_info < (3,):
f.__module__ = module.__name__
setattr(module, f.__name__, f)
return decorator

# python3 -c 'import shutil,inspect; print(inspect.getsource(shutil.get_terminal_size))'
@py2_monkey_patch(shutil)
def get_terminal_size(fallback=(80, 24)):
"""Get the size of the terminal window.
For each of the two dimensions, the environment variable, COLUMNS
and LINES respectively, is checked. If the variable is defined and
the value is a positive integer, it is used.
When COLUMNS or LINES is not defined, which is the common case,
the terminal connected to sys.__stdout__ is queried
by invoking os.get_terminal_size.
If the terminal size cannot be successfully queried, either because
the system doesn't support querying, or because we are not
connected to a terminal, the value given in fallback parameter
is used. Fallback defaults to (80, 24) which is the default
size used by many terminal emulators.
The value returned is a named tuple of type os.terminal_size.
"""
# columns, lines are the working values
try:
columns = int(os.environ['COLUMNS'])
except (KeyError, ValueError):
columns = 0

try:
lines = int(os.environ['LINES'])
except (KeyError, ValueError):
lines = 0

# only query if necessary
if columns <= 0 or lines <= 0:
try:
size = os.get_terminal_size(sys.__stdout__.fileno())
except (AttributeError, ValueError, IOError):
# stdout is None, closed, detached, or not a terminal, or
# os.get_terminal_size() is unsupported
size = os.terminal_size(fallback)
if columns <= 0:
columns = size.columns
if lines <= 0:
lines = size.lines

return os.terminal_size((columns, lines))

@py2_monkey_patch(os)
class terminal_size(tuple):
@property
def columns(self):
return self[0]

@property
def lines(self):
return self[1]

def __repr__(self):
return 'os.terminal_size(columns=%r, lines=%r)' % self

terminal_size = namedtuple('terminal_size', 'columns lines')

termsize = Struct('HHHH')

@py2_monkey_patch(os)
def get_terminal_size(fd): # pylint: disable=function-redefined
arr = b'\0' * termsize.size
arr = fcntl.ioctl(fd, termios.TIOCGWINSZ, arr)
lines, columns, xpixel, ypixel = termsize.unpack(arr)
return os.terminal_size((columns, lines))
5 changes: 3 additions & 2 deletions pwnlib/term/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from pwnlib.term import text

# Re-exports (XXX: Are these needed?)
output = term.output
width = term.width
term.update_geometry()
width = term.width
height = term.height
output = term.output
getkey = key.get
Keymap = keymap.Keymap

Expand Down
6 changes: 5 additions & 1 deletion pwnlib/term/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from pwnlib.term import keyconsts as kc
from pwnlib.term import termcap
from pwnlib.term import term

__all__ = ['getch', 'getraw', 'get', 'unget']

Expand All @@ -25,7 +26,10 @@ def getch(timeout = 0):
try:
rfds, _wfds, _xfds = select.select([_fd], [], [], timeout)
if rfds:
c = os.read(_fd, 1)
with term.rlock:
rfds, _wfds, _xfds = select.select([_fd], [], [], 0)
if not rfds: continue
c = os.read(_fd, 1)
return ord(c) if c else None
else:
return None
Expand Down
17 changes: 12 additions & 5 deletions pwnlib/term/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import division
from __future__ import print_function

import io
import six
import sys

Expand Down Expand Up @@ -406,17 +407,20 @@ def readline(_size=-1, prompt='', float=True, priority=10):
history.insert(0, buffer)
return force_to_bytes(buffer)
except KeyboardInterrupt:
control_c()
do_raise = False
try:
control_c()
except KeyboardInterrupt:
do_raise = True
if do_raise:
raise
finally:
line = buffer_left + buffer_right + '\n'
buffer_handle.update(line)
buffer_handle.freeze()
buffer_handle = None
if prompt_handle:
prompt_handle.freeze()
prompt_handle = None
if suggest_handle:
suggest_handle.freeze()
suggest_handle = None
if shutdown_hook:
shutdown_hook()
Expand Down Expand Up @@ -484,7 +488,10 @@ class Wrapper:
def __init__(self, fd):
self._fd = fd
def readline(self, size = None):
return readline(size)
r = readline(size)
if isinstance(self._fd, io.TextIOWrapper):
r = r.decode(encoding=self._fd.encoding, errors=self._fd.errors)
return r
def __getattr__(self, k):
return getattr(self._fd, k)
sys.stdin = Wrapper(sys.stdin)
Expand Down
Loading

0 comments on commit 46d6fc0

Please sign in to comment.