Files
Christian Clauss 41702e89e6 Travis CI: Use flake8 to detect syntax errors (#1385)
* Travis CI: Use flake8 to detect syntax errors

Repeat #1305 on the Python 3 branch.  Also, remove the hardcoding of default values for dist and Py2.

https://flake8.pycqa.org/en/latest/user/error-codes.html

On the flake8 test selection, this PR does _not_ focus on "_style violations_" (the majority of flake8 error codes that [__psf/black__](https://github.com/psf/black) can autocorrect).  Instead these tests are focus on runtime safety and correctness:
* E9 tests are about Python syntax errors usually raised because flake8 can not build an Abstract Syntax Tree (AST).  Often these issues are a sign of unused code or code that has not been ported to Python 3.  These would be compile-time errors in a compiled language but in a dynamic language like Python they result in the script halting/crashing on the user.
* F63 tests are usually about the confusion between identity and equality in Python.  Use ==/!= to compare str, bytes, and int literals is the classic case.  These are areas where __a == b__ is True but __a is b__ is False (or vice versa).  Python >= 3.8 will raise SyntaxWarnings on these instances.
* F7 tests logic errors and syntax errors in type hints
* F82 tests are almost always _undefined names_ which are usually a sign of a typo, missing imports, or code that has not been ported to Python 3.  These also would be compile-time errors in a compiled language but in Python a __NameError__ is raised which will halt/crash the script on the user.

* Fail fast, exclude generated source files

* --select=E9,F63,F7

* 2to3 -f print -wn examples

* No more <> in python 3.
2019-12-09 21:58:15 +01:00

2.8 KiB

Examples

While these examples should all work, they are not very representative of the pwntools project.

We have a plan to create a separate repository with examples, primarily exploits. Until we do so, we recommend new users to look at https://docs.pwntools.com, as this is a better overview of our features.

In no particular order the docstrings for each example:

  • args.py
When not in lib-mode (import `pwn` rather than `pwnlib`) we parse the
commandline for variables definitions.  A variable definition has the form::

  <var>=<val>

where ``<var>`` contains only uppercase letters, digits and underscores and
doesn't start with a digit.

Try running this example with::

  $ python args.py RHOST=localhost RPORT=1337
  • asm.py
Example showing the interface to `pwnlib.asm.asm` and `pwnlib.shellcraft`.
  • attach.py
Example showing `pwnlib.gdb.attach()`
  • clean_and_log.py
Use case for `pwnlib.tubes.tube.clean_and_log`.

Sometimes you will have a solution to a challenge but you don't know what it
will look like when you get the flag.  Sometimes that will leave you with a
top-level exception, no flag, and angry team members.

Solution:
 1. Always run wireshark or tcpdump.  Always.
 2. Register <your socket>.clean or <your socket>.clean_and_log to run at exit.
  • indented.py
When running in term-mode (import `pwn` rather than `pwnlib`, stdout is a TTY
and not running in a REPL), we can do proper indentation where lines too long to
fit on a screen are split into multiple individually indented lines.

Too see the difference try running with::

  $ python indented.py

and

  $ python -i indented.py

Also notice that `pause()` can react on any key when in `term_mode`.
  • listen_uroboros.py
An example showing interconnection of sockets.  This script will wait for three
connections on port 1337, then connect them like a three-way Uroboros.
  • options.py
Example showing `pwnlib.ui.options()`
  • port_forward.py
A very simple port forwarder using `pwnlib.tubes.tube.connect_both()`.
  • readline_completers.py
Example showing pwnlib's readline implementation and a few completers.  This
part of pwnlib will probably see some major changes soon, but we wanted to show
off some proof-of-concepts.
  • remote.py
Example showing how to use the remote class.
  • remote_gdb_debugging.py
Simple example showing how to use the remote
gdb debugging features available in pwntools.
  • spinners.py
Just a lot of spinners!
  • splash.py
"Easteregg"
  • ssh.py
Example showing how to use the ssh class.
  • text.py
Example showing how to use `pwnlib.term.text`.

Try running with::

  $ TERM=xterm python text.py

and::

  $ TERM=xterm-256color python text.py
  • yesno.py
Example showing `pwnlib.ui.yesno()`