Compare commits

...
847 Commits
Author SHA1 Message Date
Mathias Svensson 7aa9605629 3.0.0 release 2016-08-20 17:24:46 -07:00
Morten Brøns-Pedersen 757d7fe2c6 Merge pull request #667 from Idolf/issue-455
sh_string was broken in some cases, adds functionality to fix it. Fixes #455
2016-08-20 10:52:28 +02:00
Morten Brøns-Pedersen 9e724203b9 Merge pull request #650 from binjitsu/issue-591
Remove old inode-walking code in gdb module
2016-08-20 10:38:58 +02:00
Mathias Svensson 72207cf914 Fixed #455 2016-08-19 20:08:47 -07:00
Zach Riggle 824852bf33 Fix README links so they are valid, and work on pwntools.com (#653) 2016-08-18 13:14:42 -07:00
Zach Riggle b382849671 Add auto-update detection for new releases (#659) 2016-08-18 12:48:43 -07:00
Zach Riggle 0e814c91cc Merge pull request #669 from Idolf/issue-661
Adds some forgotten imports, fixes #661
2016-08-18 12:09:13 -07:00
Mathias Svensson d55a47a8fc Fixed a link in README.md (#670) 2016-08-18 11:58:17 -07:00
Zach Riggle 3b65f8775a Add coveralls.io build steps to .travis.yml (#655)
* Add coveralls.io build steps to .travis.yml

Fixes Gallopsled/pwntools#205

* Fix unit tests which fail under Coveralls

* Remove non-coverage "make doctest"

* Only report coverage for our code

* Add .coveragerc, ignore .coverage, shorten Travis script line

* Add Coveralls shield

* Fix spacing with badges and logo

* Add undocumented command-line tools to increase coverage
2016-08-18 11:22:41 -07:00
Zach Riggle fce5081c30 Make constgrep errors more verbose (#654) 2016-08-18 11:19:41 -07:00
Zach Riggle 39afc7998a Missed case where p_type needs to be converted to a string (#647) 2016-08-18 11:18:30 -07:00
Zach Riggle 1bfc56daa0 Actually enable the Thumb encoder (#646)
* Actually enable the Thumb encoder

* Fix thumb nop encoding NUL bytes
2016-08-18 11:14:47 -07:00
Zach Riggle 2d08e7cd99 Fix encoders.null typo (#645) 2016-08-18 11:14:10 -07:00
Mathias Svensson f7696f0388 Fixes #661 2016-08-18 11:07:47 -07:00
avarx 2947fb16dd Fix typo (#666) 2016-08-18 09:30:43 -07:00
Zach Riggle 9e57328d1b Add warning described in Gallopsled/pwntools#518 (#652) 2016-08-17 19:57:24 -07:00
Kristoffer Søholm 2198df5ea5 Merge pull request #664 from Gallopsled/fix-link
Fix install.html link.
2016-08-17 14:43:30 -07:00
Zach Riggle 40cc12ba95 Fix install.html link.
Fixes Gallopsled/pwntools#641
2016-08-17 13:31:27 -07:00
Zach Riggle 13f1815b7d Merge branch 'master' into issue-591 2016-08-17 12:04:43 -07:00
Zach Riggle 16846a80c6 Merge pull request #663 from Gallopsled/fix-link
Fix URL.  Fixes #662
2016-08-17 11:09:40 -07:00
Zach Riggle b29467dab6 Fix URL. Fixes Gallopsled/pwntools#662 2016-08-17 10:53:08 -07:00
Zach Riggle 969a9fe754 Remove old inode-walking code in gdb module
Fixes Gallopsled/pwntools#591
2016-07-26 15:03:04 +01:00
Mathias Svensson 23b0a019da Fixed a keyfile bug 2016-07-23 12:03:07 +02:00
Zach Riggle 99f9c80f15 Merge pull request #643 from PtxDK/patch-1
Update README.md
2016-07-18 17:53:46 +01:00
Kristoffer Søholm 3d5f859dd0 Merge pull request #638 from Idolf/remove-stale-files
Various stuff not merged correctly in #636.
2016-07-03 23:19:02 +02:00
Kristoffer Søholm 5c5e797cbf Merge pull request #637 from Idolf/remove-self-import
Builder imported itself
2016-07-03 23:04:43 +02:00
Patrick Krøll Brandt b2698f5513 Update README.md 2016-07-03 21:51:12 +02:00
Mathias Svensson 2baebf9e51 Use the pwntools twitter handle 2016-07-03 21:29:47 +02:00
Mathias Svensson 640051d41c Updated README.md based on the binjitsu-arm-syscall branch 2016-07-03 21:11:03 +02:00
Mathias Svensson 2f8de42cd8 Fixed IRC reference 2016-07-03 20:54:06 +02:00
Mathias Svensson ac8e053ca0 Removed binjitsu files not identified as stale in #636. 2016-07-02 23:09:57 +02:00
Mathias Svensson 741dffb47d Builder imported itself 2016-07-02 22:36:53 +02:00
Mathias Svensson ee77289111 Merge pull request #636 from binjitsu/pwntools-merge
Pwntools merge with Binjitsu
2016-07-02 21:10:42 +02:00
Zach Riggle 01cda51e3e Add date 2016-06-30 14:52:24 +02:00
Zach Riggle 2d72ccc30c Add commit count to changelog 2016-06-30 14:51:59 +02:00
Zach Riggle eee6ce3521 Add test for QEMU installation 2016-06-30 14:39:00 +02:00
Zach Riggle 7f933d3ffc Update QEMU static version 2016-06-30 14:38:16 +02:00
Zach Riggle 8680f2eeb6 Update Changelog for 3.0.0 release 2016-06-30 14:17:35 +02:00
Zach Riggle 06b81a3279 Remove Binjitsu fork info 2016-06-30 13:36:11 +02:00
Zach Riggle 33cdabf0ab Replace project name references 2016-06-30 02:28:42 +02:00
Zach Riggle c32ae58811 Replace domain names 2016-06-30 02:26:46 +02:00
Zach Riggle d4e42f86d0 Replace binjitsu/binjitsu with Gallopsled/pwntools 2016-06-30 02:26:22 +02:00
Zach Riggle bd6ef3f45e Merge remote-tracking branch 'gallopsled/master' into pwntools-merge 2016-06-30 02:24:01 +02:00
Zach Riggle a613d75abb Move logger functions to toplevel (add success) 2016-06-28 12:57:13 +02:00
Zach Riggle 2d8c8593de Modify ADB commands to specify host and port if they are provided via environment 2016-06-28 12:56:47 +02:00
Zach Riggle 054e3d50d5 Move logger functions to toplevel 2016-06-28 12:56:23 +02:00
Zach Riggle b06b544323 Clean up ADB partition code, enable enumeration and tab-completion 2016-06-21 06:29:17 +02:00
Zach Riggle 18d9646498 Do not return "." in listdir() 2016-06-21 06:22:01 +02:00
Zach Riggle e8d8f4c4cc Do not record one-time warnings if they are not actually emitted 2016-06-14 16:04:02 -07:00
Zach Riggle e18eef7fae Add --file option to checksec for checksec.sh compatibility 2016-06-09 19:12:08 -06:00
Zach Riggle 396efcf71a Extend process() display changes to "stopped" message 2016-06-07 15:54:44 -06:00
Zach Riggle ee485a68d5 Strip adb shell from the display 2016-06-07 15:52:28 -06:00
Zach Riggle c0bc668450 Add a few twiddly bits for better process logs 2016-06-07 15:51:10 -06:00
Zach Riggle 7c8806950b Wrap all property accessors with str() 2016-06-07 12:42:12 -06:00
Zach Riggle ba5815bba5 Convert absolute paths to relative paths 2016-06-07 11:36:08 -06:00
Zach Riggle 25016264e7 Fix listdir implementation for some phones lacking a -1 option for LS 2016-06-07 11:31:38 -06:00
Zach Riggle 4d83a0d017 Silence GDB license on attach 2016-05-29 19:08:37 -04:00
Zach Riggle 67fd986360 Support unauthorized devices; old devices dont support -t 2016-05-29 19:00:43 -04:00
Zach Riggle fc1a7e2d11 Add warning message to cyclic_find; fix two-space indentation 2016-05-29 13:19:58 -05:00
Zach Riggle 112a246881 Minor fix for OS X serialtube naming for certain adapters 2016-05-28 20:07:19 -05:00
Zach Riggle c0c91841a7 Fix install info 2016-05-25 14:00:21 -05:00
Zach Riggle 70df2fa5f3 Fix double-warning for GDB without ASLR 2016-05-24 17:51:45 -07:00
Zach Riggle aedbafd9d6 Add ASLR-disabled warning to GDB 2016-05-24 17:50:16 -07:00
Zach Riggle 51f62206f6 Add ASLR-disabled warning to SSH 2016-05-24 17:49:30 -07:00
Zach Riggle a9ac751b89 Add ASLR disabled warning message 2016-05-24 17:47:57 -07:00
Zach Riggle ab31b3091c Add context.verbose 2016-05-24 17:47:43 -07:00
Zach Riggle 322942f2d3 Fix elfpatch so it doesnt spew logging info 2016-05-21 22:15:25 -07:00
Zach Riggle 9967347d70 Rename Property.name to support ro.product.name 2016-05-17 22:36:22 -07:00
Zach Riggle 01ec1328f9 Refactor adb.partitions to provide an iterator 2016-05-17 21:48:15 -07:00
Zach Riggle 020469788a Add adb.address, fix adb.symbols, add adb.partitions 2016-05-17 21:41:43 -07:00
Zach Riggle 348456e290 Merge pull request #78 from Manouchehri/patch-2
libffi-dev is required.
2016-05-17 18:12:07 -07:00
David Manouchehri 01e5057b05 libffi-dev is required. 2016-05-18 01:04:43 +00:00
Zach Riggle c97da1524c Merge pull request #77 from Manouchehri/patch-1
Use Trusty for Dockerfile?
2016-05-17 17:50:00 -07:00
Zach Riggle ec506414ee Catch reconnect exception, fix listdir() 2016-05-17 20:22:11 -04:00
Zach Riggle 10eb718058 Allow pwnlib.adb.Property objects to be compared to strings 2016-05-17 19:56:02 -04:00
Zach Riggle c575c66895 Stringify device in argv 2016-05-17 19:46:54 -04:00
Zach Riggle a30ab0ca80 Add pwnlib.device.Device class 2016-05-17 19:46:02 -04:00
Zach Riggle a598103ca9 Add auto-transform support for Android ABIs 2016-05-17 19:30:05 -04:00
Zach Riggle d2a377cfbc Add "kick" option to adb.wait_for_device 2016-05-17 19:18:09 -04:00
Zach Riggle 3ab9063d43 Force TTY allocation for ADB shell 2016-05-17 19:18:09 -04:00
David Manouchehri 8958123e3e Use Trusty. 2016-05-17 22:31:06 +00:00
Zach Riggle c57aa1a507 Fix failing tests 2016-05-17 14:47:35 -07:00
Zach Riggle ffe2e7cf1f Pwndbg and its depenencies should not be in the Binjitsu dockerfile 2016-05-16 22:41:50 -07:00
Zach Riggle fdbd19fdd2 Add decorators for common MemLeak scenarios, make the class more robust / transparent. 2016-05-16 22:41:50 -07:00
Zach Riggle 30bfc92037 Add vsyscall to Corefile 2016-05-11 21:02:41 -07:00
Zach Riggle d84a1073d7 Add unit test for generating shared libraries 2016-05-11 20:46:01 -07:00
Zach Riggle 8d934d65e1 Make vdso detection better; add Mapping.data so you can do core.vdso.data 2016-05-11 20:44:36 -07:00
Zach Riggle a77aa1be73 Add adb.unlock_bootloader 2016-05-10 16:34:36 -07:00
Zach Riggle 176b0af30b Add support for older devices with last_kmsg 2016-05-10 11:43:44 -07:00
Zach Riggle 03e9546127 Remove double-serial-number 2016-05-09 22:48:57 -07:00
Zach Riggle 05672c3e14 Add adb.compile to build single source files or NDK projects 2016-05-09 22:26:00 -07:00
Zach Riggle 7a5760cd39 More robust "adb.push" 2016-05-09 16:58:20 -07:00
Zach Riggle 78584929d7 adb pull shows weird content for newer versions, rely on exit code 2016-05-09 16:53:10 -07:00
Zach Riggle 56ad2276f4 Add kallsyms 2016-05-09 13:51:56 -07:00
Zach Riggle d76b6c5560 Use specific commands for each device 2016-05-06 21:08:34 -07:00
Zach Riggle e59a44d8b3 Auto-detect default serial port on OSX 2016-05-06 21:08:25 -07:00
Zach Riggle 2f11018a1e Add adb.kernel.lastmsg 2016-05-06 18:54:32 -07:00
Zach Riggle 21fc7759e0 Actually use serialtube arguments 2016-05-06 18:53:46 -07:00
Zach Riggle d2933acba2 Make uart_enable() work for Shamu 2016-05-06 14:17:02 -07:00
Zach Riggle efa9c26842 Bulk removal of get_serialno() 2016-05-06 11:22:19 -07:00
Zach Riggle b61941835a Add documentation for ADB module 2016-05-05 14:53:59 -07:00
Zach Riggle c75bf4ad75 Clean up code, silence adb.kernel.cmdline 2016-05-05 14:31:59 -07:00
Zach Riggle 8138315fa6 Minor fixups 2016-05-05 14:27:12 -07:00
Zach Riggle f1e7715e6f Finish implementation of adb.kernel.symbols 2016-05-05 14:25:49 -07:00
Zach Riggle 544342b9fe Use log.debug instead of print 2016-05-05 14:21:48 -07:00
Zach Riggle 430bee44b7 Use fancy new context decorator 2016-05-05 14:20:43 -07:00
Zach Riggle 31c1070ac8 I have an instance of a class “Context” called “context” with a property that returns an object which is actually a Context Manager which can be used as a function decorator to modify the state of the object “context” while in the context of the decorated function. 2016-05-05 14:19:52 -07:00
Zach Riggle 59102739f5 Move enable_uart() into the Kernel object 2016-05-05 14:19:52 -07:00
Zach Riggle a02d3277ce Lots of changes for adb module to support direct access to properties, kernel data, and the ability to enable UART debugging 2016-05-05 14:19:52 -07:00
Zach Riggle 2f75eb6c3a Add context.device so that we can scope serial numbers 2016-05-05 14:19:52 -07:00
Zach Riggle 22c97ee762 Fix package URL for qemu-user-static on Travis 2016-05-04 13:03:39 -07:00
Zach Riggle 500a2720a5 Fix regression with vma=None 2016-05-04 01:08:02 -07:00
Zach Riggle 2fc9a83a50 Fix serial tubes 2016-05-04 00:11:27 -07:00
Zach Riggle b572a9da4a Simplify context.adb for the basic case 2016-05-04 00:11:27 -07:00
Zach Riggle 3db45f46e4 Add "shared" option for ELF-building functions to generate DSOs. 2016-05-03 13:24:24 -07:00
Zach Riggle 41383b3330 ArgumentParser object must be at global scope for documentation generation to work 2016-04-25 15:30:42 -05:00
Zach Riggle 1a3d81f8f1 Do not manually close the log file.
It should get cleaned up by gc anyway.
2016-04-25 15:24:24 -05:00
Zach Riggle 4e04c8bfb3 Add repr() for timeout maximum 2016-04-25 15:12:37 -05:00
Zach Riggle 94abecce80 A bit more documentation for context.proxy 2016-04-25 14:56:02 -05:00
Zach Riggle 7f733aa63b Modify elfdiff to copy the files to a single location so that the first two lines of objdump dont get compared. 2016-04-25 14:39:19 -05:00
Zach Riggle b26a2f21fc Default argument for fit() 2016-04-25 14:04:59 -05:00
Zach Riggle d91b05b43a Switch from error to a single warning. 2016-04-25 14:04:53 -05:00
Zach Riggle 9aff300cee Fix wget() keyword 2016-04-22 14:52:30 -07:00
Zach Riggle 806d506510 Enhancements to Corefile to expose vdso/vvar/exe 2016-04-22 12:56:46 -07:00
Zach Riggle f0010e4413 Switch _lookup_build_id to use compare; remove breakpoint 2016-04-22 11:25:42 -07:00
Zach Riggle 58c61897ba Take failure case with error message 2016-04-22 10:52:32 -07:00
Zach Riggle dc083ae7b9 Fix regression on searching for DT_NULL 2016-04-22 10:51:16 -07:00
Zach Riggle 7029b38cce Refactor and optimize the fast-path DynELF search 2016-04-22 10:36:41 -07:00
Zach Riggle cf19d35d14 Add helpful warning for DynELF without elf= 2016-04-22 10:08:50 -07:00
Zach Riggle c498ddcb6d Switch to exceptions 2016-04-22 10:04:36 -07:00
Zach Riggle 7253234fba Add handling for negative values, extend use of compare 2016-04-22 10:03:35 -07:00
Zach Riggle 7925b44582 Speed up DynELF leaking with field_compare
Also modify log.progress / log.waitfor update frequency.
2016-04-22 10:01:07 -07:00
Zach Riggle 494a078be9 Fix ADB port getenv() as integer 2016-04-21 14:37:48 -07:00
Zach Riggle 8ef546bc34 Only print the banner once per log file per execution 2016-04-21 14:23:06 -07:00
Zach Riggle 64416909bb Sort imports 2016-04-21 14:39:08 -05:00
Zach Riggle 1c6689eca4 Lower log verbosity and fix whitespace 2016-04-21 14:36:16 -05:00
Zach Riggle 4dfc571702 Add fast-path for fit() 2016-04-21 03:51:58 -07:00
Zach Riggle cb40e4b883 Update fit() doctests 2016-04-21 03:45:33 -07:00
Zach Riggle 12564a7e0d It appears that fit() has always been completely broken from my understanding of it. 2016-04-21 03:44:22 -07:00
Zach Riggle d51ad7f989 Various enhancements to DynELF and MemLeak for speed 2016-04-21 02:12:56 -07:00
Zach Riggle bbc91d6211 Add DynELF.stack and a few other improvements 2016-04-21 00:14:40 -07:00
Zach Riggle 21c10be67e Add MemLeak.p for pointer-width sizes 2016-04-21 00:14:40 -07:00
Zach Riggle ca43832880 Pass kwargs to gdb.debug 2016-04-21 00:14:40 -07:00
Zach Riggle c9dabb8606 Must re-root after restarting 2016-04-21 00:14:40 -07:00
Zach Riggle eb8f905449 Fix searching for gadget subsets, and add SYS_rt_sigreturn fallback
Fixes binjitsu/binjitsu#73
2016-04-20 17:11:44 -07:00
Peter Shih 1b9a4ca123 fix inconsistent logging level in tube.
(cherry picked from commit fe4086e710)
2016-04-20 18:24:59 -05:00
Zach Riggle 02e0c3804c Update QEMU url so testing works 2016-04-19 17:39:23 -05:00
Zach Riggle 50624322c4 Remove MIPS documentation, since Travis is on 12.04 and you cant build AArch64 binutils for it. 2016-04-19 17:07:54 -05:00
Zach Riggle 63d564810b Remove AArch64 documentation, since Travis is on 12.04 and you cant build AArch64 binutils for it. 2016-04-19 16:11:42 -05:00
Zach Riggle 03d8efaba2 Fix ELF.process() for non-Android 2016-04-19 14:01:14 -07:00
Zach Riggle c47538da1f Add dateutil to requirements 2016-04-19 13:52:51 -07:00
Zach Riggle 3192839ff8 Restore context clear, but move it inside the local scope.
The clear is necessary because vars(context) will only retrieve the set keys.  Any other context bits set later will not be correctly set to default values.
2016-04-19 14:59:43 -05:00
Zach Riggle abc646511a Simplify a few lines with getattr 2016-04-19 14:51:47 -05:00
Zach Riggle d3ab88364c Remove context clear which breaks things in interactive mode when there is no exception handler. 2016-04-19 14:49:23 -05:00
Zach Riggle 3d61ba339a Add docs for mips shellcode 2016-04-17 18:42:14 -07:00
Zach Riggle 84a1a540b0 Add docs for aarch64 shellcode 2016-04-17 18:41:34 -07:00
Zach Riggle efa8c77d3c adb: Multiple enhancements. Add push and pull. 2016-04-17 18:41:11 -07:00
Zach Riggle 734d3a17e6 gdb: Silence unlink errors, push binaries to Android devices. 2016-04-17 18:40:46 -07:00
Zach Riggle 378a32b390 Fix exception on extract=True for make_elf_from_assembly 2016-04-17 18:40:22 -07:00
Zach Riggle 6bf0989e2f ELF supports ADB 2016-04-17 18:39:45 -07:00
Zach Riggle 158f6d7758 run_in_new_terminal supports argv in addition to strings 2016-04-17 18:39:35 -07:00
Zach Riggle 38047c15c6 Android constants are the same as Linux constants 2016-04-17 17:21:57 -07:00
Zach Riggle 56fbd583e6 Change log levels of ADB commands, better Android support in GDB 2016-04-15 14:40:12 -07:00
Zach Riggle 2d8e5f0050 Fix pid_by_name so that the results are actually sorted, and do not return any zombie processes. 2016-04-15 11:44:37 -07:00
Zach Riggle 1b865681fc Add Android examples, cut down verbosity of adb calls. 2016-04-14 12:19:32 -07:00
Zach Riggle bcc57b3138 Add adb module, lots of refactoring GDB module to be more clean and support Android gdb.attach(). 2016-04-14 11:56:04 -07:00
Zach Riggle 87a612282d Add aarch64 sh for Android 2016-04-14 11:52:05 -07:00
Zach Riggle 215ddafc65 Add aarch64 sh 2016-04-14 11:51:38 -07:00
Zach Riggle 474d96eb52 Use shorthand 2016-04-13 15:40:01 -05:00
Zach Riggle b868c12d63 Update PLT parsing for Thumb mode entries 2016-04-13 15:38:23 -05:00
Zach Riggle d9f120e617 Add host / port support to Binjitsu 2016-04-13 15:22:21 -05:00
Zach Riggle 2c788f4f55 Fix ptrace vararg 2016-04-13 15:22:12 -05:00
Zach Riggle 2d3eb7204d Fixes for Android AArch64 debugging 2016-04-13 12:51:50 -05:00
Zach Riggle 4e2d5f096a Fix typo 2016-04-12 18:37:39 -05:00
Zach Riggle b60218a4d7 First pass support for debugging Android binaries natively. 2016-04-12 16:44:41 -05:00
Zach Riggle 51dd430ad0 Always have context.native return False for Android and CGC 2016-04-12 16:44:27 -05:00
Zach Riggle 60e5a80790 Make run_in_new_terminal work on OSX under tmux 2016-04-12 16:44:03 -05:00
Zach Riggle d4f10b0d6e Don't look for QEMU if running natively. 2016-04-12 16:43:47 -05:00
Zach Riggle 95d4b8e09d Add missing log object 2016-04-12 16:43:32 -05:00
Zach Riggle 0af33f3a6f Simplify process.core since I just learned about the gcore command line tool. 2016-04-04 20:11:54 -07:00
Zach Riggle 68207adbe4 Write the GDB script to the terminal when debugging is enabled 2016-04-04 16:20:52 -07:00
Pi-Hsun Shih 999ad63200 Fix pack when sign=True and word_size='all'
(cherry picked from commit 17caf96582)
2016-03-28 12:10:59 -04:00
Zach Riggle b45ef8dfbd Dont always try to prefix binutils with 'g'.
Fixes Gallopsled/pwntools#607
2016-03-28 12:00:51 -04:00
Zach Riggle 320e0dd80b Fix Gallopsled/pwntools#609 2016-03-28 11:56:58 -04:00
Zach Riggle c1e3d26d29 Add Unicorn, dependencies, tabs->spaces 2016-03-25 18:21:31 -04:00
Zach Riggle 73ddedebb4 Fix doctests for SFTP 2016-03-25 14:24:23 -07:00
martian 7f236f5064 Added support for generating a Dash docset.
Dash docsets can be read by various applications:

Dash         OS X, iOS         https://kapeli.com
Zeal         Linux, Windows    https://zealdocs.org
Velocity     Windows           http://velocity.silverlakesoftware.com
LovelyDocs   Android           http://lovelydocs.io
dasht        POSIX             https://github.com/sunaku/dasht
Helm Dash    emacs             https://github.com/areina/helm-dash

(cherry picked from commit dc37b0b5b2)
2016-03-25 15:57:20 -04:00
Zach Riggle 80ebf7109a Fix binjitsu/binjitsu#69 2016-03-25 13:29:12 -04:00
Morten Brøns-Pedersen 36ccc2bc81 bugfix: ui.yesno() now correctly handles <enter>
This bug happened because we no longer disable input processing in the terminal.
In particular `\r` is now translated to `\n`.  The fix is to interpret both `\r`
and `\n` as <enter> in `term/key.py`.

(cherry picked from commit 383f245082)
2016-03-25 13:21:04 -04:00
Morten Brøns-Pedersen 72416c4705 bugfix: don't call shutdown(2) when calling tubes.sock.close()
This can be a problem since sockets inherited by children will see the
`shutdown(2)` call as well.

(cherry picked from commit 77bfc16341)
2016-03-25 13:20:19 -04:00
Sam Brown 8f2878d0ab corrected util.twiddling.bits implementation to handle 0 validly
(cherry picked from commit 6449e14e9e)
2016-03-25 13:14:39 -04:00
Morten Brøns-Pedersen 10487c23ac added fiddling.bits(0) as a doctest
(cherry picked from commit 10c3f079c5)
2016-03-25 13:13:49 -04:00
Mathias Svensson a18c23cf2d Fix annoying setup.py behaviour.
When installing pwntools, setup.py required a very new version of
requests -- even though we never used any new features.

This is a problem, since the required version is much never than what is
in e.g. ubuntu's package repo. While this by itself is not much of a
problem, it is a problem if one installs python-pip from the distro's
repo as well, since python-pip will try to use the newest version of the
requests library, which caused pip to break.

The solution: Do not force such a new version of python, instead live
with a much older version.

(cherry picked from commit f91299986e)
2016-03-25 13:10:31 -04:00
Sam Brown 714f27fee9 added mailing list link to README.md
(cherry picked from commit 126e2857ad)
2016-03-25 13:08:35 -04:00
peter50216 9942ae157f Don't depend on python dict.item() order.
(cherry picked from commit 3564b9e014)
2016-03-25 13:07:12 -04:00
peter50216 36ead5ac57 Fix inconsistency between error message and code.
Code says context.bits should be > 0, but error message says >= 0.
Since 0 bit architecture doesn't make sense at all, make them all be > 0.
(cherry picked from commit def9400d48)
2016-03-25 13:03:20 -04:00
Morten Brøns-Pedersen 18049ddddb example of gdb.attach
(cherry picked from commit 883ddb30b5)
2016-03-23 13:29:02 -04:00
peter50216 6f74c7f13e Don't depend on python dict.item() order.
(cherry picked from commit 3564b9e014)
2016-03-23 13:27:58 -04:00
Zach Riggle 17b48f7186 Catch corner case in process.leak 2016-03-22 10:27:38 -07:00
Zach Riggle a518a60388 Open in binary mode 2016-03-21 18:05:07 -07:00
Zach Riggle 78e394bd6d Add documentation to process.leak and another option 2016-03-21 18:04:51 -07:00
Zach Riggle 282b853c2a Add process.leak() function for testing leaks 2016-03-21 18:01:06 -07:00
Zach Riggle aa64f71075 Add aliases for connect_remote and listen_remote 2016-03-17 16:42:08 -04:00
Zach Riggle 354213c475 Learn full path to the executable for ssh.process 2016-03-17 16:14:19 -04:00
Zach Riggle d22f6c457f Remove argparse requirement. Fixes Gallopsled/pwntools#598. 2016-03-16 12:58:42 -04:00
Zach Riggle 03baaa3807 Update Docs badge 2016-03-16 12:55:29 -04:00
Zach Riggle a5df5ee6a0 More trying to fix ReadTheDocs build 2016-03-16 07:00:43 -07:00
Zach Riggle c5b3d343ad Fix build for readthedocs.org which dies on terminal stuff. 2016-03-16 06:59:36 -07:00
Zach Riggle 1413caf401 Merge pull request #71 from kbeckmann/master
Import pwnlib.util.safeeval in constgrep
2016-03-16 09:45:37 -04:00
Zach Riggle 09a637eabe Fix more docs links 2016-03-16 06:45:16 -07:00
Zach Riggle bb95c6fbbd Fix docs link 2016-03-16 06:44:26 -07:00
Zach Riggle b0cb09ae67 Complete fix in 0ce1ebb for Gallopsled/pwntools#601 2016-03-16 06:42:39 -07:00
Zach Riggle 669c963290 Fix typo in Dockerfile 2016-03-16 06:15:59 -07:00
Konrad Beckmann 0e0cb7c0e3 Import pwnlib.util.safeeval in constgrep 2016-03-16 10:59:58 +01:00
Zach Riggle bc20216579 Add ASAN/MSAN/UBSAN to checksec 2016-03-15 16:11:21 -07:00
Zach Riggle 0ce1ebbd81 Fixes Gallopsled/pwntools#601 2016-03-14 18:36:33 -04:00
Zach Riggle d3074011d6 Update Dockerfile 2016-03-10 15:59:55 -05:00
Zach Riggle 03b8eb8694 Update Dockerfile 2016-03-10 15:58:25 -05:00
Zach Riggle 3b383ece1c Extract list of data elements from Buffer when unget()'ing a Buffer. Fixes #596
(cherry picked from commit fde04c737b)
2016-03-03 15:51:18 -05:00
Zach Riggle 524a76b925 Skip $PATH resolution for which() when a path component is detected. Also remove carriage returns from ssh.interactive() output. 2016-02-19 23:22:58 -05:00
Zach Riggle 541734a097 Simplify coredump_filter code in case the process dies between the two statements 2016-01-28 13:49:06 -05:00
Zach Riggle cf203cc91e Enable compression for SSH 2016-01-28 00:27:38 -05:00
Zach Riggle b52b970a28 Update ssh.process to match process for usage of setuid 2016-01-28 00:27:25 -05:00
Zach Riggle b36c78805f Add process.corefile; improve process.libs; update process.setuid 2016-01-28 00:26:54 -05:00
Zach Riggle 54584e09c0 Merge pull request #66 from PankajKataria/master
Fix typo
2016-01-24 17:29:39 -05:00
Zach Riggle 2314322369 Add tcp and udb helper classes for remote 2016-01-22 23:29:02 -05:00
Zach Riggle 0ef6a9a383 Add context.device 2016-01-22 23:15:53 -05:00
Zach Riggle 131eefaf05 Add context.noptrace option 2016-01-22 23:14:00 -05:00
Zach Riggle 63ca4f51b1 Ensure coredumps contain *everything* 2016-01-04 18:08:00 -05:00
Zach Riggle e806bf73f6 Fix Corefile parsing verbosity, and make elf.string() bail when reads fail. 2015-12-29 15:09:35 -05:00
Zach Riggle 2cf84db4ca Handle Corefiles with no environment variables 2015-12-29 13:09:59 -05:00
Zach Riggle cb5f04de6b Fix presentation of env on log line when env={} 2015-12-29 12:49:52 -05:00
Zach Riggle c8228729f1 Allow empty environments via SSH 2015-12-29 12:31:40 -05:00
Pankaj Kataria 098888da2f Fix typo
Fix typo
2015-12-27 08:28:06 +05:30
Zach Riggle c250f00abe Fix XOR shellcode and tests for arm and aarch64 2015-12-26 13:13:59 -08:00
Zach Riggle 02ffc4034e Simplify aarch64 by one instruction 2015-12-26 15:10:43 -05:00
Pankaj Kataria 00047af206 Corrected description of download_dir function 2015-12-26 23:22:35 +05:30
Zach Riggle 5a60b591be Fix IRC link 2015-12-21 17:19:22 -05:00
Zach Riggle e54cd0ddf7 Merge branch 'ssh-agent' 2015-12-21 17:02:44 -05:00
Zach Riggle 8eec3e2d12 Disable use of ssh-agent by default 2015-12-21 16:59:44 -05:00
Zach Riggle 1738218f81 Don't be too aggressive with ssh.process() status messages 2015-12-12 02:38:14 -05:00
Zach Riggle e3c1aad702 Fix bug for NT_FILE and environment variable addresses 2015-12-12 02:37:35 -05:00
Zach Riggle df7f08a5ed Fix corefile support for mappings without NT_FILE 2015-12-11 19:19:15 -05:00
Zach Riggle 44548b0a72 Better error handling for ssh.process(), and less verbose log messages 2015-12-11 17:55:24 -05:00
Zach Riggle 5512ecf450 Add warning message for when the corefile isn't loaded 2015-12-11 16:00:26 -05:00
Zach Riggle 8b969da149 Fix regression when parsing some functions like __libc_start_main@@GLIBC_2.0 2015-12-11 15:58:19 -05:00
Zach Riggle 176e45d9f6 Assume that core files are desired 2015-12-11 15:48:09 -05:00
Zach Riggle 594f35e4f7 Enhance corefile parsing to extract environment variable addresses 2015-12-11 15:48:09 -05:00
Zach Riggle ea2493bd56 Do not dump GDB traffic when debugging is verbose 2015-12-11 04:10:37 -05:00
Zach Riggle 3ef1e1a7d5 Further enhancements to Core 2015-12-11 04:10:37 -05:00
Zach Riggle e978986a84 Add support for extracting register state from core files 2015-12-11 04:10:37 -05:00
Zach Riggle faf3e42861 Merge branch 'socks5' 2015-12-11 04:07:30 -05:00
Zach Riggle 32cff88c56 Update .executable to be the original binary, so that .libs and .libc works for process() and ssh_channel() 2015-12-10 22:00:02 -05:00
Zach Riggle f32069589d Convert ssh_channel.exe ==> ssh_channel.executable to be the same as process.executable 2015-12-10 21:46:13 -05:00
Zach Riggle 926231b4ed Fix test 2015-12-08 12:39:45 -05:00
Zach Riggle f08e2c8731 Move output to stdout 2015-12-08 10:24:54 -05:00
Zach Riggle ee1ca61d37 Silence log output in unit test 2015-12-08 10:24:46 -05:00
Zach Riggle 42d08b43fc logging 2015-12-07 17:28:45 -05:00
Zach Riggle ab692c1569 Add logging and socks to the toplevel 2015-12-07 17:23:34 -05:00
Zach Riggle 7640c3fa9f Simplify context setup 2015-12-07 17:23:18 -05:00
Zach Riggle 3db5c4d0ce Add support for SOCKS proxies 2015-12-07 17:15:25 -05:00
Zach Riggle 3bcf57bcd3 Add unit test for aslr==0 to set unlimited stack size 2015-12-07 17:06:23 -05:00
Zach Riggle 714bc320c4 Fix argument for tube.p64 2015-12-03 13:26:57 -05:00
Zach Riggle 24c32f541d Fix log message for ssh.interactive() 2015-12-03 13:26:45 -05:00
Zach Riggle f8753f2f5b Add **kw to run_shellcode 2015-12-03 13:26:20 -05:00
Zach Riggle 507deae10f Add KB,MB,GB globals 2015-12-03 13:25:37 -05:00
Zach Riggle d4dbdb58df Fix "execute" argument to gdb.debug variants 2015-12-03 13:25:12 -05:00
Zach Riggle 59ae1a999a Add ssh.which and other minor bugfixes in ssh 2015-11-30 09:50:42 -05:00
Zach Riggle 1582064bed Add .libc to process and ssh.process; also convert DynELF.libc to a property 2015-11-23 13:10:29 -08:00
Zach Riggle 506be041b7 Add nosetuid to ssh.process 2015-11-20 20:08:44 -08:00
Zach Riggle 8699c98a6f Add signed and unsigned 2015-11-20 20:05:36 -08:00
Zach Riggle 1bcc4626e3 Add option to disable setuid 2015-11-20 23:04:57 -05:00
Zach Riggle d6e4c7d76d Add log.hexdump 2015-11-15 00:16:14 -05:00
Zach Riggle ee8a96c39d Re-add cyclic hexdump to hexdump() 2015-11-15 00:15:57 -05:00
Zach Riggle 49dd666026 Fix dealarm_shell issue where "which" doesnt sent a new line if the binary is missing 2015-11-15 00:15:41 -05:00
Zach Riggle 675155abc8 Convert len => length 2015-11-12 14:58:05 -05:00
Zach Riggle 8d4b1f84f8 Add context.aslr and options to disable ASLR via process() and ssh.process() 2015-11-10 16:26:25 -05:00
Zach Riggle 8ffb0dfacf Enhance error messages 2015-11-09 14:36:48 -05:00
Zach Riggle aff7b8e3a3 Simplify a few lines of code 2015-11-09 14:36:11 -05:00
Zach Riggle 438c9a303b Add tube.sendlines method 2015-11-09 13:10:50 -05:00
Zach Riggle f0f4180fd4 Fix test failure introduced by bc6cc93 2015-11-07 23:15:59 -05:00
Zach Riggle aad6e9ae9b Add support for setting log colors from ~/.pwn.conf 2015-11-07 23:12:37 -05:00
Zach Riggle bc6cc93537 Add option to skip setting TTY raw mode. Use os.environ for process() so that preexec_fn can use it. 2015-11-07 20:06:00 -05:00
Zach Riggle 89a60e71b8 Remove termcap did_init, since it breaks terminals 2015-11-07 16:20:25 -05:00
Zach Riggle 6c6b16bb16 Simplify PTY slave logic 2015-11-07 16:08:21 -05:00
Zach Riggle b1575e6a0f Fix infinite recursion on accessing self.proc in close() 2015-11-07 16:04:00 -05:00
Zach Riggle 4c38d29ac3 Gate termcap.get with an initialization flag 2015-11-07 15:48:14 -05:00
Zach Riggle 232ebd5e6d Update docs/requirements.txt to install all requirements. 2015-11-07 15:43:36 -05:00
Zach Riggle f79b447378 Remove CLA 2015-11-07 15:31:14 -05:00
Zach Riggle 45ea91fa8e Fix syscall stubs using "from" as a variable name. 2015-11-07 15:31:14 -05:00
Zach Riggle 55a47c95b9 Fix documentation errors. 2015-11-07 15:31:14 -05:00
Zach Riggle dbd334673d Fix behavior with getpass() by making stdin also be a raw TTY 2015-11-07 15:31:14 -05:00
Zach Riggle 73d8e06a4b Detect gdbserver in the working directory 2015-11-03 19:16:36 -05:00
Zach Riggle 6f248e8a5e Add context.mask 2015-11-03 17:05:18 -05:00
Zach Riggle d90566d30a Add wait alias for wait_for_close 2015-11-03 16:42:51 -05:00
Zach Riggle 6db7b8cfbf Fix term mode. Broken since 11fa0d8d6d 2015-11-03 16:38:58 -05:00
Zach Riggle aa323a40df Ensure self.cwd is always set; simplifies some logic 2015-11-03 16:29:04 -05:00
Zach Riggle 8fc7e64ff5 Default working directory is "." 2015-11-03 16:27:36 -05:00
Zach Riggle 2264290a6f Don't print e.g. '\x04' * 0x1 2015-10-30 16:27:55 -04:00
Zach Riggle 170d4999eb Update Android sh scripts to properly set arg0 since it is expected. 2015-10-29 19:39:27 -04:00
Zach Riggle 3520393b62 Add Android includes 2015-10-29 19:37:53 -04:00
Zach Riggle 88ff1f3533 Update Thumb execve to properly support string arrays 2015-10-29 19:37:14 -04:00
Zach Riggle e5223e4bd1 Update ARM execve to properly support string arrays 2015-10-29 19:31:53 -04:00
Ryan afdb7a4449 Update about.rst 2015-10-27 15:04:31 -04:00
Zach Riggle d3814a3d39 Add Android OS 2015-10-27 15:02:30 -04:00
Zach Riggle 515af41f85 Update Android sh path 2015-10-27 15:02:25 -04:00
Zach Riggle c66b809006 Add Android templates and headers as symlinks 2015-10-25 23:48:26 -04:00
Zach Riggle c2339b62f1 Fix asm regression 2015-10-25 19:35:57 -04:00
Zach Riggle e7a72e086b Add default arguments for mmap 2015-10-25 19:31:00 -04:00
Zach Riggle 1bed4850b0 Dont send cd command if there's no change 2015-10-25 19:29:58 -04:00
Zach Riggle 4993b4ada7 Simplify header layout 2015-10-25 19:29:41 -04:00
Zach Riggle 2c8652bf91 Detect whether gdbserver is installed 2015-10-25 19:18:05 -04:00
Zach Riggle 2219f183c2 Fix ARM push. There is no push-immediate. 2015-10-25 18:36:02 -04:00
Zach Riggle 278ebee345 Add sublime-settings [skip ci] 2015-10-25 16:51:38 -04:00
Zach Riggle 81de47c025 Add errno command-line helper 2015-10-25 16:40:24 -04:00
Zach Riggle e1b93c77f5 Merge pull request #61 from jaybosamiya/patch-1
Fix typos
2015-10-15 17:34:02 -04:00
Jay Bosamiya 77383048fb Fix typo
"Data" is, by itself plural. "Datas" is not a word.
2015-10-16 01:59:24 +05:30
Jay Bosamiya fb3c55af06 Fix typos
I'm pretty sure it shouldn't be "he" there.
2015-10-16 01:58:00 +05:30
Zach Riggle d7a0bafc5f Permit dot access to symbol names, add elf.sym alias for elf.symbols 2015-10-14 13:22:31 -04:00
Zach Riggle 11fa0d8d6d This contains a large merge from the Samurai internal repo.
Changes:

- `pwn/init` initialization code simplified, and some was moved to `pwnlib/args`
- `scramble` script added to `pwnlib.commandline`; support for encoders added to relevant scripts
- Added shellcode encoders for several architectures
- Added CGC architecture shellcode and constants
- Added Shellcraft templates for every syscall
- Added `xor_key` helper for generating a 4-byte XOR key for a data stream
- Added `getdents` for use with the relevant shellcraft scripts
- Add ELF loaders for all architectures
- Lots of MIPS and AArch64 shellcode
2015-10-12 02:13:13 -04:00
Morten Brøns-Pedersen 768b24e192 added __neq__ method to pwnlib.term.key
(cherry picked from commit 31d06cb807)
2015-10-06 18:09:25 -04:00
Morten Brøns-Pedersen 42d8f59e11 import completer with pwnlib.term and update no-available-completions-text 2015-10-06 18:09:09 -04:00
Morten Brøns-Pedersen c734802900 fix before and after keywords for term.output() 2015-10-06 18:08:58 -04:00
Zach Riggle b4945667c7 Clean up code from 442873e 2015-10-06 18:08:09 -04:00
antoniob 442873e5be close file descriptors in process.close() and avoid leaving zombie processes around
(cherry picked from commit fa2e11391e)
2015-10-06 18:06:10 -04:00
Zach Riggle 29eefaac2b Revert disable-randomization change from 3b9614a535 2015-10-06 18:05:57 -04:00
Zach Riggle c5a92cdfb6 Simplify use if int() 2015-09-21 14:14:40 -04:00
Zach Riggle 4c61ed3b0b Fix #59 2015-09-15 15:11:26 -04:00
Zach Riggle 88d1643804 Fix ssh.run() environment variables 2015-09-01 14:50:44 -04:00
Zach Riggle f12253e34d Add dockerfile 2015-08-31 03:53:31 -04:00
Zach Riggle 783cc096a6 Fix which() precedence 2015-08-30 23:29:46 -04:00
Zach Riggle 549541b6ea Handle EINTR on select 2015-08-30 23:21:30 -04:00
Zach Riggle a2916b7d01 Add live demo 2015-08-30 22:55:00 -04:00
Zach Riggle a6a5cfeb9c Add i686 alias 2015-08-30 15:01:05 -04:00
Zach Riggle c18f8a202d Sockets should be set to non-blocking for spawned processes 2015-08-25 16:54:30 -04:00
Zach Riggle 59a309d6ac Fix UDP socket buffering 2015-08-25 16:47:16 -04:00
Zach Riggle a676adbc52 Update ELF 2015-08-23 16:51:12 -04:00
Zach Riggle e08aebe9fd Remove shippable, since its crap 2015-08-22 15:41:17 -04:00
Zach Riggle f968120997 Only request ptrace_scope when required 2015-08-22 15:40:05 -04:00
Zach Riggle b03d83dfe7 Add elf.functions 2015-08-14 18:20:01 -04:00
Zach Riggle f9c7ea87fa process() now handles empty environments 2015-08-14 17:58:08 -04:00
Zach Riggle 1a389ca2b8 Update binutils.rst 2015-07-30 13:34:27 -04:00
Zach Riggle ecbe0e9fa9 Update binutils.rst 2015-07-30 13:34:16 -04:00
Zach Riggle 76d78a0e7e Install QEMU 2.3 instead of 2.1 2015-07-29 08:03:01 -04:00
Zach Riggle 3f8d4cc37c Add aarch64 binutils 2015-07-29 07:52:19 -04:00
Zach Riggle e7ef1c1029 Merge pull request #55 from eQu1NoX/MAIN-arm
Integration test for ARM
2015-07-15 12:11:09 -04:00
eQuiNoX__ e6752fbd30 Correct tests that depend on 0x900000 vs 0x0 2015-07-15 13:14:59 +02:00
eQuiNoX__ de393e4afa Integration test for ARM 2015-07-15 12:40:44 +02:00
Zach Riggle f92ea95299 Rebuild the ARM constants with __ARM_EABI__ and __KERNEL__ 2015-07-14 16:33:20 -04:00
Zach Riggle ee4028c10a Merge pull request #54 from eQu1NoX/MAIN2
MIPS integration tests for SROP
2015-07-14 08:17:17 -04:00
eQuiNoX__ 69ee58343e Trivial correction 2015-07-14 14:06:43 +02:00
eQuiNoX__ dca6232d97 Mips integration tests 2015-07-14 13:54:55 +02:00
Zach Riggle 8c1565ae3e Update README.md 2015-07-13 20:12:02 -04:00
Zach Riggle d1a70dc0fb Add screenshot 2015-07-13 20:10:35 -04:00
Zach Riggle 48a1cc72b0 Create README.md 2015-07-13 20:07:09 -04:00
Zach Riggle c29aebdb77 Add docstrings to QEMU functions 2015-07-13 16:28:48 -04:00
Zach Riggle ae888803b6 Add qemu-XXX-static binaries to Travis 2015-07-13 15:24:01 -04:00
Zach Riggle 4386b8d82a Merge pull request #49 from eQu1NoX/MAIN2
Adding in Aarch64 support.
2015-07-10 23:23:59 -07:00
eQuiNoX__ a44ba4fa16 Adding in doctests 2015-07-09 16:25:58 +02:00
Zubin Mithra 9ac4e8d9cb Adding in Aarch64 support.
This commit adds in Aarch64 SROP support. PoC that calls mprotect
can be viewed at

https://bitbucket.org/eQu1NoX/pwntest-arm64/src/a7936795d47c\?at\=master
2015-07-09 15:42:18 +02:00
Zach Riggle 9559a99854 Fix doctests in ELF 2015-07-06 22:50:57 -07:00
Zach Riggle 1897045707 Merge remote-tracking branch 'nemopwn/master' 2015-07-06 21:54:57 -07:00
Zach Riggle 973efff68b Merge pull request #48 from binjitsu/asm-large-pages
Fix large page sizes on AMD64
2015-07-06 18:15:27 -07:00
Zach Riggle dd58f40991 Fix large page sizes on AMD64 2015-07-06 21:10:18 -04:00
Zach Riggle 0f710677d3 Touch README to force Travis rebuild 2015-07-06 14:50:20 -07:00
Zach Riggle 6d2ccdcf93 Merge remote-tracking branch 'gallopsled/master' 2015-07-06 14:47:22 -07:00
nemo 5d1e3500f0 Two changes:
- Add .ropeproject to .gitignore
- Make documentation of class ELF display normally
2015-07-06 16:15:47 +08:00
Zach Riggle 37c55233ed Merge pull request #45 from eQu1NoX/MAIN2
Test for amd64
2015-07-02 14:02:44 -07:00
eQuiNoX__ 1f289e3dbd The following changes were made :-
- test for amd64 added in
- sigreturn template for amd64 added in. sigreturn template for i386 modified
- read.asm added for amd64
2015-07-02 19:01:57 +02:00
Zach Riggle d66c273e60 Merge pull request #44 from eQu1NoX/MAIN2
Add in support for mips, mipsel + doctests
2015-06-29 12:27:26 -07:00
eQuiNoX__ ed7b459be9 Following changes were made :-
- Add support for MIPS and MIPSel
- Change format to offset:register in srop.py
- Correct doctests in srop.py
- Change usage in rop.py
2015-06-29 16:11:19 +02:00
Zach Riggle e544cd43b8 Fix test 2015-06-25 12:54:56 -04:00
Zach Riggle cfdfaff37e Fix SigReturnFrame.get_frame docstring [skip ci] 2015-06-25 12:37:55 -04:00
Zach Riggle 38e9f4274d Fix code-blocks [skip ci] 2015-06-25 12:36:29 -04:00
Zach Riggle 88d79af9c9 Update FormatStr doctest formatting 2015-06-25 00:01:38 -04:00
thetlk e675c2068e Enhance FormatString support, and add doctests 2015-06-24 23:42:03 -04:00
Zach Riggle 4cecbac380 Re-enable teset with workaround for Shippable 2015-06-24 16:24:06 -04:00
Zach Riggle b4f8877660 Skip test which fails on Shippable 2015-06-24 16:03:44 -04:00
Zach Riggle 1f5fde3302 Fix listen(fam=socket.AF_INET6) 2015-06-22 23:50:14 -04:00
Zach Riggle 9e17e76054 Simplify test 2015-06-22 23:21:51 -04:00
Zach Riggle 4f5be7144b Fix process(..., stdout=PIPE) and add tests 2015-06-22 23:19:24 -04:00
Zach Riggle 51d8a89d4b Shippable needs apt-get update to find gcc-multilib 2015-06-22 11:58:28 -04:00
Zach Riggle 523344b64e Add gcc-multilib to Travis and Shippable requirements 2015-06-22 11:53:57 -04:00
Zach Riggle 7486c79a67 Update .travis_install.sh 2015-06-22 09:27:47 -04:00
Zach Riggle 3a565a8171 Fix docstring [skip ci] 2015-06-21 15:40:43 -04:00
Zach Riggle 6b82b6b7dc Fix docstring [skip ci] 2015-06-21 15:39:27 -04:00
Zach Riggle c4dd91c5de Fix docstring [skip ci] 2015-06-21 15:38:14 -04:00
Zach Riggle 4b33859132 Add XOR encoder module for docs 2015-06-21 15:37:44 -04:00
Zach Riggle 6aff977171 Fix assembly for arches which want __start 2015-06-21 15:28:21 -04:00
Zach Riggle 6141e7d465 Add shellcode encoders and API 2015-06-21 15:26:55 -04:00
Zach Riggle 71845f6198 Remove unnecessary gadgets in the example 2015-06-21 15:22:49 -04:00
Zach Riggle d00cae41a6 Make stack and code rwx for generated ELFs 2015-06-21 15:22:33 -04:00
Zach Riggle 1327f2b33b :) 2015-06-19 23:43:04 -04:00
Zach Riggle b6ea53696b Fix setregs 2015-06-18 17:23:55 -04:00
Zach Riggle be1e13389a Make disassembly colors better for operators 2015-06-18 17:18:25 -04:00
Zach Riggle 6e562b2bdb Make shifting easier to read 2015-06-18 17:13:32 -04:00
Zach Riggle dd7c0acae1 Make xor easier to read 2015-06-18 16:50:57 -04:00
Zach Riggle b10f109967 Make not easier to read 2015-06-18 16:46:11 -04:00
Zach Riggle 63da39ea18 Make neg easier to read 2015-06-18 16:42:21 -04:00
Zach Riggle 8b459a066e Update doctests 2015-06-18 16:33:03 -04:00
Zach Riggle 1187e544de Optimize i386 mov for a few special cases 2015-06-18 16:19:08 -04:00
Zach Riggle 49e2c52b0b Fix doctests 2015-06-17 13:04:22 -07:00
Zach Riggle fc0c7a0f69 Revert changes to make_elf. Fixes #33 2015-06-17 12:28:28 -07:00
Zach Riggle d7b957c9c1 Merge pull request #32 from thetlk/master
import pwnlib after sys.path's change
2015-06-17 15:03:53 -04:00
thetlk dad217f9ed import pwnlib after sys.path's change 2015-06-17 16:47:11 +02:00
Zach Riggle ba6eba4b13 Fix doctest 2015-06-17 07:32:09 -04:00
Zach Riggle 4f1745fbdf Restore compact size to generated ELFs 2015-06-17 07:32:09 -04:00
Zach Riggle b218776573 Switch syscall over to getregs 2015-06-17 06:20:01 -04:00
Zach Riggle e867643192 Collapse constant values in regsort, since "mov reg,reg" is at most only as expensive as "mov reg,value" and usually cheaper 2015-06-17 05:58:44 -04:00
Zach Riggle 275a3a09d4 Restore compact size to generated ELFs 2015-06-17 05:45:09 -04:00
Zach Riggle 6f0a62e751 Honor -o option in asm; mark output as executable if output format is ELF 2015-06-17 05:32:35 -04:00
Zach Riggle 70645b432b Make pushstr work for things not-a-string but which can go through packing.flat(). This makes push more simple. 2015-06-17 05:31:55 -04:00
Zach Riggle 4ea3a4932e Slightly better cdq 2015-06-17 04:59:00 -04:00
Zach Riggle 8d1f57a345 Add cdq optimization to setregs 2015-06-17 04:59:00 -04:00
Zach Riggle c00e2b1863 Add correct ipv6 address, allow accept to time out 2015-06-17 04:59:00 -04:00
Zach Riggle 2aac79c9ad Honor -o option in shellcraft; mark output as executable if output format is ELF 2015-06-17 04:59:00 -04:00
Zach Riggle 8121a95bc5 Better colorizing, which can be disabled 2015-06-17 03:45:27 -04:00
Zach Riggle 797d416a47 Add support for conditional instruction printing 2015-06-17 03:18:38 -04:00
Zach Riggle 4ad2cb87a9 Remove debug print 2015-06-17 03:17:50 -04:00
Zach Riggle 400f208ca2 Fix output of the GasLexer to parse templates better 2015-06-17 03:16:45 -04:00
Zach Riggle 800f85fe7a Add Pygments to requirements 2015-06-17 03:09:37 -04:00
Zach Riggle 30dcc6af05 Use Pygments to colorize assembly if possible 2015-06-17 03:08:50 -04:00
Zach Riggle 2078c1dca6 Add TextMate / Sublime Text language bundles 2015-06-17 02:43:10 -04:00
Zach Riggle 966cc482fd Add cat doctest 2015-06-16 23:26:33 -04:00
Zach Riggle 98f27f80d8 Fix ROP doctests 2015-06-16 20:07:55 -04:00
Zach Riggle 3c2b2b22c9 Add ROP doctest 2015-06-16 19:15:32 -04:00
Zach Riggle c03c90c204 Add i386 SROP integration test 2015-06-16 17:56:56 -04:00
Zach Riggle 4265424956 Pass kwargs down to ELF.from_bytes 2015-06-16 16:19:28 -04:00
Zach Riggle 085efbc6b4 Defer deletion of temporary files 2015-06-16 16:19:20 -04:00
Zach Riggle 1d5fe92e04 Fix VMA for make_elf 2015-06-16 16:07:10 -04:00
Zach Riggle 8ba3d52955 Add ROP.from_blob for kokjo :D 2015-06-16 15:41:25 -04:00
Zach Riggle 24c1f2d04a Add documentation for checksec 2015-06-15 23:59:25 -04:00
Zach Riggle 1e59b54c4e Add shellcraft --run 2015-06-15 23:57:58 -04:00
Zach Riggle e21f8a0a24 Don't execute binaries which are not dynamically linked 2015-06-15 23:57:45 -04:00
Zach Riggle 58b6ce5ec4 Add asm --run and --infile 2015-06-15 23:56:17 -04:00
Zach Riggle e54c16c5e9 Dont emit CRLF since it shows empty lines 2015-06-15 23:11:26 -04:00
Zach Riggle ac4524607a Dont emit CRLF since it shows empty lines 2015-06-15 23:09:31 -04:00
Zach Riggle 757f60acb0 Unlink GDB temporary files. Fixes #519 2015-06-15 17:29:27 -04:00
Zach Riggle b57beda046 Fix missing imports, simplify runner module 2015-06-15 17:22:05 -04:00
Zach Riggle 1ac87052c2 Add powerpc and powerpc64 register names so you can "li r0,0" 2015-06-15 14:23:54 -04:00
Zach Riggle 502de0c92f Add missing constants 2015-06-15 14:17:18 -04:00
Zach Riggle 2093ca4632 Dont bail on various architectures 2015-06-15 14:16:51 -04:00
Zach Riggle 86e422de0c Update TESTING.md 2015-06-15 09:32:11 -04:00
Zach Riggle af5ba55325 Merge remote-tracking branch 'gallopsled/master' into integration 2015-06-15 09:07:34 -04:00
Zach Riggle 405d9cc2af Import iters 2015-06-15 09:01:32 -04:00
Zach Riggle 1631d2265e Fix tests 2015-06-15 08:57:41 -04:00
Zach Riggle 77cc76769c Merge with gallopsled/master 2015-06-15 08:54:50 -04:00
Zach Riggle 31f05f4c7f Emit nicer assembly comments 2015-06-15 08:38:35 -04:00
Zach Riggle 24f49a46cf Add echo example 2015-06-15 08:37:52 -04:00
Zach Riggle 28307ec699 Update TESTING.md 2015-06-15 08:17:46 -04:00
Zach Riggle c50f224b6b Update TESTING.md 2015-06-15 08:14:39 -04:00
Zach Riggle 3a63c0804d Feed results of unpack() through int() so it doesnt return long() 2015-06-15 08:12:45 -04:00
Zach Riggle 1d5825c844 Fix whitespace, 2015-06-15 08:10:55 -04:00
Zach Riggle 709d834945 Fix whitespace, add amd64 version 2015-06-15 08:08:57 -04:00
Zach Riggle f3b0645568 Fix simple case of regsort. Add i386.setregs 2015-06-15 08:05:53 -04:00
Zach Riggle 640d0261fd Add register sorting and dependency resolution module 2015-06-15 07:59:55 -04:00
Zach Riggle 89dd56a2a3 Use LocalContext for ABI 2015-06-15 02:35:55 -04:00
Zach Riggle e45ee3053e Automatically set arch for shellcraft; update i386 exit; add amd64 exit 2015-06-15 02:32:24 -04:00
Zach Riggle 65a60a6170 Automatically set arch for shellcraft; update i386 exit; add amd64 exit 2015-06-15 02:32:07 -04:00
Zach Riggle 63c5d4fb60 Add doctest for i386.linux.exit 2015-06-15 02:21:01 -04:00
Zach Riggle 6c27af5e16 Update __init__.py 2015-06-14 20:49:37 -04:00
Zach Riggle 931d18f836 Update license from pwntools 2015-06-14 20:47:35 -04:00
Zach Riggle 41350f51cf TESTING 2015-06-14 20:46:37 -04:00
Zach Riggle 75b230c052 Enable @LocalContext for ELF.from_XXXX 2015-06-14 20:38:20 -04:00
Zach Riggle 24a70eb8ff Add better tests and ELF.from_bytes 2015-06-14 18:59:26 -04:00
Zach Riggle 918115302c Add make_elf_from_assembly and ELF.from_assembly 2015-06-14 18:53:03 -04:00
Zach Riggle af92658f42 Add context.clear(...) arguments 2015-06-14 17:18:33 -04:00
Zach Riggle ee35d10303 Add TESTING.md 2015-06-14 17:11:51 -04:00
Zach Riggle 3b0cf3cbaf Nope time is bad, not installed on Travis 2015-06-14 16:44:41 -04:00
Zach Riggle 7292806e08 Explicitly time the run 2015-06-14 16:43:12 -04:00
Zach Riggle f263f9e10d Update docstring 2015-06-14 16:38:47 -04:00
Zach Riggle cfa0d50339 Silence Sphinx warning 2015-06-14 16:38:28 -04:00
Zach Riggle 7cf6360dbb Add runner.rst to index.rst 2015-06-14 16:36:06 -04:00
Zach Riggle 32fef0cf05 Add missing link 2015-06-14 16:32:23 -04:00
Zach Riggle 95b1adebbf Fix Sphinx warnings 2015-06-14 16:30:01 -04:00
Zach Riggle df3a746768 Fix docs 2015-06-14 16:29:39 -04:00
Zach Riggle 11bfb24506 Add testexample link 2015-06-14 16:26:14 -04:00
Zach Riggle ddaa95d6dd Fix testexample 2015-06-14 16:24:02 -04:00
Zach Riggle 77e8ab1d84 No shippable caching 2015-06-14 16:23:23 -04:00
Zach Riggle e9497169f1 Remove set -ex 2015-06-14 16:21:16 -04:00
Zach Riggle 9f552c94cb Fix testexample 2015-06-14 16:20:30 -04:00
Zach Riggle 0cdb715e7c Fix runner banner 2015-06-14 16:14:01 -04:00
Zach Riggle 9a5b4e09af Fix SROP banner 2015-06-14 16:13:52 -04:00
Zach Riggle bac6a9f543 Fix testexample module 2015-06-14 16:13:39 -04:00
Zach Riggle b901ff3b1e Add shippable configuration 2015-06-14 16:12:04 -04:00
Zach Riggle de47ac9cf5 Add Shippable badge 2015-06-14 16:07:10 -04:00
Zach Riggle 72e9b3135e Fix Shippable build since it really doesnt have terminfo 2015-06-14 15:55:52 -04:00
Zach Riggle 7413dffac7 Add test example modules 2015-06-14 15:54:56 -04:00
Zach Riggle 7b4a415a90 Skip failing SROP tests 2015-06-14 15:45:18 -04:00
Zach Riggle 465f5875b7 Fix SROP tests 2015-06-14 15:28:47 -04:00
Zach Riggle a50cd85791 Fix Shippable builds 2015-06-14 15:28:08 -04:00
Zach Riggle 1541b20c19 Run install before SSH setup 2015-06-14 15:26:00 -04:00
Zach Riggle 54551eb072 Fix doctest 2015-06-14 15:25:18 -04:00
Zach Riggle a45da211db Move srop module 2015-06-14 15:25:08 -04:00
Zach Riggle 5bfde777bf Fix naming 2015-06-14 15:14:13 -04:00
Zach Riggle 6e0ee86cb9 Import ALL THE THINGS 2015-06-14 15:12:50 -04:00
Zach Riggle b78b91180f Add runner module, for shellcode unit tests 2015-06-14 15:08:04 -04:00
Zach Riggle 77326199e4 Fast path for LocalContext 2015-06-14 14:59:57 -04:00
Zach Riggle 287bcae4c4 Merge pull request #25 from eQu1NoX/master
ARM srop support
2015-06-11 06:58:30 -04:00
Zach Riggle 6148801e95 Fix feature regression in cyclic_find which permits integer lookups 2015-06-11 06:58:01 -04:00
Zubin Mithra f23c297d7b moving integ to different branch
Add information about various ARM coprocessors that might be present.

Correct typo

Add in comments

Change how magic numbers and offsets are stored

Use namedtuple

Renaming variables

srop.py doc modified

ARM sp check added in

Cleanup
2015-06-11 12:38:51 +02:00
Zach Riggle a4c5492772 Enable maximum number of bytes to read 2015-06-11 03:45:15 -04:00
Zach Riggle 01365128dc Fix feature regression in cyclic_find which permits integer lookups 2015-06-11 03:45:09 -04:00
Zach Riggle cbcf23c70d Fail disassembly gracefully 2015-06-10 17:32:53 -04:00
Zach Riggle 1bc94ccc58 Fix doctests 2015-06-10 16:18:40 -04:00
Zach Riggle 347ab75af5 Add parens so ARM doesnt shit itself 2015-06-10 15:36:04 -04:00
Zach Riggle 72768d8b4a Fix doctest 2015-06-10 15:28:07 -04:00
Zach Riggle d3a3359c77 Save pretty name of things passed through constants.eval 2015-06-10 15:27:29 -04:00
Zach Riggle c3b006ef50 Add docs 2015-06-09 12:53:18 -04:00
Zach Riggle 14093c2d54 Fix doctest 2015-06-09 12:51:37 -04:00
Zach Riggle c21426e3a0 Don't modify original representation 2015-06-09 12:49:21 -04:00
Zach Riggle 6034b2b312 Enable disassembly with stripping the offsets and columns 2015-06-09 12:45:06 -04:00
Zach Riggle ff5f634a76 Add sockaddr changes from upstream 2015-06-09 12:04:08 -04:00
Zach Riggle af9fe4c0d2 Merge pull request #26 from binjitsu/constants
Use complex constants
2015-06-08 14:17:28 -04:00
Zach Riggle 9b9ae29a71 Fix arm shellcode 2015-06-08 14:01:03 -04:00
Zach Riggle 62b3964225 Fix thumb shellcode 2015-06-08 13:56:42 -04:00
Zach Riggle cec172ee9b Use complex constants 2015-06-07 02:35:28 -04:00
Zubin Mithra b349eaff6f Add in ARM support for SROP 2015-06-06 12:24:41 +02:00
Zubin Mithra dfa96abb09 Merge branch 'master' of http://github.com/binjitsu/binjitsu 2015-06-06 03:40:16 +02:00
Zach Riggle 8922d369e9 Allow lookups of libraries running under qemu-user by walking /etc/qemu-binfmt 2015-06-01 12:59:36 -07:00
Zach Riggle 043232336f Added docs for ELF.libc 2015-06-01 12:40:08 -07:00
Zach Riggle ffa321103b Add automatic extraction of libc.so 2015-06-01 12:39:01 -07:00
Zach Riggle 4ac5bce80e Enable .libs detection for alternate-architecture libraries when run via qemu-user. 2015-06-01 12:35:44 -07:00
Zach Riggle 9cf7e8f7e7 More more more verbose 2015-05-29 14:38:47 -04:00
Zach Riggle b7731b32e5 Verbose logging for Shippable troubleshooting 2015-05-29 14:37:14 -04:00
Zach Riggle eec0b68b52 Update docs [skip ci] 2015-05-29 14:34:45 -04:00
Zach Riggle e1331055ae Detect if current user is travis, for Shippable 2015-05-29 14:33:28 -04:00
Zach Riggle 2b909824b8 Compress debug send/recv output if it's the same byte 2015-05-28 17:56:06 -04:00
eQuiNoX__ f9d080141f Commit code that sets the esp to the next gadget 2015-05-27 12:38:31 +02:00
Zach Riggle 00d9460422 Show a better error message when connecting to an unknown host 2015-05-25 16:15:27 -04:00
Zach Riggle 525f35c143 Fix/optimize dealarm 2015-05-22 20:50:01 -04:00
Zach Riggle b36bd7ace5 Add dealarm_shell 2015-05-22 20:46:19 -04:00
Zach Riggle ce458c7fc0 Update docstring [skip ci] 2015-05-20 23:31:16 -04:00
Zach Riggle 329ef332b4 Fix docstring 2015-05-20 23:28:26 -04:00
Zach Riggle 5c0d5132e2 Add DynELF.libc() function 2015-05-20 23:23:55 -04:00
Zach Riggle 06fc1eecd5 Make Call() pretty printing... prettier 2015-05-20 23:21:09 -04:00
Zach Riggle 79c718aa43 Update docstring 2015-05-20 22:59:53 -04:00
Zach Riggle d99f7160bf Integrate new ROP building tools 2015-05-20 22:41:13 -04:00
Zach Riggle de4f14c5d2 Fix up call(0x1234,..) and .migrate 2015-05-20 21:52:19 -04:00
Zach Riggle b064c45d5e Add "cat" shellcode 2015-05-20 21:48:00 -04:00
Zach Riggle 5064a75f1f Fix str() and dump() 2015-05-18 13:25:13 -04:00
Zach Riggle 2e4692ff22 Add log.info since it wont show up otherwise 2015-05-17 10:05:39 -04:00
Zach Riggle 3b9614a535 WIPWIPWIP 2015-05-16 07:55:49 -04:00
Zach Riggle 4acd9bc928 WIPWIPWIP 2015-05-16 00:21:54 -04:00
Zach Riggle da475754fe Enable flat(-1) 2015-05-15 18:35:54 -04:00
Zach Riggle e2ddcf2471 Dont lose any more work 2015-05-15 15:13:22 -04:00
Zach Riggle 40dae903cc Example for context and cleanliness 2015-05-13 18:13:48 -04:00
Zach Riggle eecafc6ed6 Add @LocalContext decorator 2015-05-13 18:02:43 -04:00
eQuiNoX__ 32e85f5791 We dont store the registers inside srop; we just call get_registers when we need them 2015-05-13 22:33:40 +02:00
eQuiNoX__ e58a661375 The following changes were made :-
- changed usage of "self.arch to with context.local..."
2015-05-13 22:29:26 +02:00
eQuiNoX__ 9eadd74bed get_regpos_mapping removed 2015-05-13 22:07:53 +02:00
eQuiNoX__ 525650bc5b The following changes were made :-
- rop.py does not import _registers_* anymore; instead imports get_registers from srop.py
- rop.py now has a self.arch that is set to context.arch inside __init__
- (_registers_32, _registers_64) => (_registers_i386, _registers_amd64)
- get_registers and get_regpos_mapping added in
- _initialize_values now handles all archs
- get_stackpointer_index changed to get_spindex; made cleaner
- get_frame made cleaner
2015-05-13 22:06:57 +02:00
Zach Riggle d3e73d231b Merge pull request #16 from eQu1NoX/master
Initial set of commits integrating SROP with ROP
2015-05-13 00:19:22 -04:00
eQuiNoX__ d7933badf2 Add in the skeleton of integrating SROP with ROP
So now we can populate the accumulator register with the sigreturn syscall number

rop.py now finds "int 0x80" instructions.

Adding in more to srop skeleton; integrating with finding int 0x80 instruction

The following changes were made :-
- s/find/index correction for list
- required imports added in
- None as argument removed

Now generates srop frames whenever function cannot be resolved

Add in code that pivots only if the gadget is not a "pop"

dump is now modified to print out the register information from srop

Uses constants.linux.i386 for syscall numbers now

Added in some exception handling code

Rely on constants to get us the right syscall number based on context.arch

The following changes were made :-
- getattr when getting syscall_number now returns None by default
- ropgadget now looks for syscall and sysenter
- added in getattr("syscall") and getattr("sysenter")

rop.search now returns a namedtuple

The following changes were made :-
1. self.int80, self.syscall and self.sysenter now return namedtuples.
2. We have functions self.raw_address and self.raw_data to specify
   how the raw values that are added in, need to be interpreted so that
   the chain can be built accordingly.

Added in a function _get_syscall_inst that returns the address of a syscall instruction

Checking if travis builds it properly/

The following changes were made :-
- Change the body of _get_syscall_inst, make it cleaner
- Add in a self._syscall_instruction that caches the address of
  a syscall instruction that was found

Removed raw_address and raw_data; modified srop implementation to use raw()

Cleanup getattr

Now the stack pointer is modified so that we can continue constructing the ROP chain if rop.base is specified

No need of enumerate; removed

doctest for rop-srop integration added in
2015-05-13 03:53:03 +02:00
Zach Riggle e4d44c54d8 Detect fortify-source 2015-05-12 02:08:35 -04:00
Zach Riggle c5ec095b7f Fix debugging of thumb shellcode 2015-05-09 15:42:06 -07:00
Zach Riggle 476e8991ca Fix debugging of thumb shellcode 2015-05-09 15:37:58 -07:00
Zach Riggle 6e4f616c44 Allow debugging of thumb shellcode 2015-05-09 15:34:33 -07:00
Zach Riggle ffc44ece88 Fix write-ups link
Closes #15
2015-04-28 17:20:35 -04:00
Zach Riggle 40db24653c Merge pull request #13 from eQu1NoX/master
Adding in doctests + renaming x86/x64 to i386/amd64
2015-04-27 11:24:49 -04:00
Zubin Mithra 9908afd495 Adding in docs for sphinx
Dropping the doctest ifmain statements

Correct underline in rst

Add testsetup to srop.rst

Now uses packing.pack instead of struct.pack

Added in context.arch information to srop.rst and srop.py doctest

Added "context.clear()" to the doctest

Cleaned up _reg_pos_mapping up a bit

Corrected reference link

Replace "print repr()" with "unpack_many"

Added in import to srop.rst
2015-04-27 10:24:26 +02:00
eQuiNoX__ f81993c303 The following changes were made :-
1. Added in doctests for i386 and amd64.
2. Renamed x86/x64 to i386/amd64.
2015-04-26 13:56:41 +02:00
Zach Riggle 3b9e9bf3a0 Merge pull request #9 from eQu1NoX/master
Initial commit adding in SROP support for x86 and x64
2015-04-25 13:32:17 -04:00
Zach Riggle ebef41df05 Fix the architecture for mips646 ELFs 2015-04-25 10:26:33 -07:00
eQuiNoX__ 9f5c2e77b8 Renamed the registers a bit, made the example a bit more complete 2015-04-25 08:15:16 +02:00
eQuiNoX__ 116491c54c Rename registers, add references 2015-04-25 08:09:04 +02:00
eQuiNoX__ 285a370378 Add comments for the SigreturnFrame class 2015-04-25 07:41:53 +02:00
Zubin Mithra 9da1c64513 Removed unused imports 2015-04-24 20:54:56 +02:00
Zubin Mithra 8845115b1f Initial commit for adding in SROP support for x86 and x64 2015-04-24 20:50:26 +02:00
Zach Riggle 6f22a11559 Make ELF work with mips64 binaries 2015-04-24 06:00:09 -07:00
Zach Riggle b7ce1b4ccd Fix mips64 2015-04-24 05:27:23 -07:00
Zach Riggle 19f4009b6e Switch from single-arg "arch" to local context 2015-04-24 04:05:29 -07:00
Zach Riggle 17b0d4efe6 Remove redundant info from checksec, realign fields 2015-04-23 21:49:04 -07:00
Zach Riggle 2077846087 Fix newlines at EOF 2015-04-21 02:43:08 -07:00
Zach Riggle b43be94aaa Add undocumented flag to prevent ASLR from being disabled 2015-04-18 19:58:35 -04:00
Zach Riggle 8a671ac1a7 Switch to GitLab since they have a 10GB quota. Add error handling :) 2015-04-17 01:22:44 -04:00
Zach Riggle c503c9c7d5 Respect timeout for wget 2015-04-16 14:27:47 -04:00
Zach Riggle ad05fda608 Add missing architectures 2015-04-16 01:18:07 -04:00
Zach Riggle 402e324725 Fix unknown architectures throwing exceptions on GOT/PLT failure. Hide RWX comment if NX is disabled. 2015-04-16 01:08:01 -04:00
Zach Riggle d81e63f03d Remove unneeded fields 2015-04-16 00:25:55 -04:00
Zach Riggle fcd04a5c91 Add code for libcdb lookups 2015-04-16 00:14:49 -04:00
Zach Riggle 9d9b880954 i386 vs x86 fixup 2015-04-15 23:52:32 -04:00
Zach Riggle 38097d724f Add .buildid property to ELF 2015-04-15 20:58:13 -04:00
Zach Riggle 230cdafe31 ASM => ELF 2015-04-11 15:38:13 -07:00
Zach Riggle 27b7f15c9c Fix VMA for ASM 2015-04-11 15:38:13 -07:00
Zach Riggle 33ca18f931 Tell user if there are RWX segments 2015-04-09 21:05:14 -04:00
Zach Riggle 5f8ae0ef2d Allow passing in an ELF object or just a path 2015-04-09 20:52:38 -04:00
Zach Riggle 821b08240a Enable passing arguments to the marshalled function; use the same naming scheme as subprocess and pwnlib.tubes.process 2015-04-06 04:34:22 -04:00
Zach Riggle 40ea374001 Enable marshalling simple functions to the remote Python instance 2015-04-05 23:41:53 -04:00
Zach Riggle 7399918a54 By default, recv an ~= infinite number of lines 2015-04-05 23:41:42 -04:00
Zach Riggle 367af48420 Evidently whatever android-ndk uses to build binaries zeroes out sh_info for rel.plt 2015-04-02 17:56:55 -04:00
Zach Riggle 3745f6fd03 Round up mmap size; optionally skip loop after recv 2015-03-31 08:23:35 -04:00
Zach Riggle f643bf8722 Remove ~5 bytes from stager 2015-03-31 07:51:48 -04:00
Zach Riggle 580b16230e Add connect doctest 2015-03-31 07:51:39 -04:00
Zach Riggle ee9ffb7491 Revert "Enable is_register for all architectures"
This reverts commit 475c1d407f.
2015-03-31 06:08:52 -04:00
Zach Riggle 2aa6c1f015 Try to remove "Remote debugging from host" line 2015-03-31 06:07:02 -04:00
Zach Riggle 90b8e50d07 Fix argument order for gdb.debug to mimick gdb.attach 2015-03-31 05:23:13 -04:00
Zach Riggle 2faeefeaf0 Fix bug in gdb.debug which breaks "execute" argument 2015-03-31 05:17:19 -04:00
Zach Riggle 24e70378ca Enable using gdbserver for debug_shellcode; add run_elf helper 2015-03-30 14:39:03 -04:00
Zach Riggle b7364fe8ac Add context.native helper to determine if the target can be run without QEMU 2015-03-30 14:32:15 -04:00
Zach Riggle 475c1d407f Enable is_register for all architectures 2015-03-30 14:26:43 -04:00
Zach Riggle c9f0ec84d1 Output to ELF for shellcraft 2015-03-30 14:08:31 -04:00
Zach Riggle 8b1a3e73a1 Merge pull request #6 from cebrusfs/master
Use MOV and SYSCALL templates in acceptloop_ipv4 and mprotect_all
2015-03-29 18:13:13 -04:00
Zach Riggle c472d573f7 Update CONTRIBUTING.md 2015-03-29 17:59:56 -04:00
Zach Riggle 10ed1a2a68 Update CONTRIBUTING.md 2015-03-29 17:59:48 -04:00
Zach Riggle 8ec7faf879 Update CONTRIBUTING.md 2015-03-29 17:59:41 -04:00
Zach Riggle 6278f9a94e Linux setup should install openssh server 2015-03-26 17:23:47 -04:00
Zach Riggle 25900adf72 Fix push() templates 2015-03-26 17:22:36 -04:00
Zach Riggle 09d053be0f Update CONTRIBUTING.md 2015-03-25 15:44:10 -04:00
MengHuan Yu 9536b17e5a Fix the coding style in 2 shellcraft examples
Use 4 space indent in 'i386/linux/acceptloop_ipv4.asm' and
'i386/linux/mprotect_all.asm'

BUG=None
TEST=None
2015-03-26 01:41:50 +08:00
MengHuan Yu 2aeda2c993 Use PUSH template in acceptloop_ipv4
BUG=None
TEST=confirmed the behavior by strace.
2015-03-26 01:36:21 +08:00
MengHuan Yu 17c3a27861 Use MOV and SYSCALL templates in some shellcode
In this commit, I only fix 'i386/linux/acceptloop_ipv4.asm' and
'i386/linux/mprotect_all.asm'.

BUG=None
TEST=confirmed the behavior is still the same under
gdb and strace.
2015-03-25 23:48:20 +08:00
Zach Riggle 36f1fc32e0 Ensure textual levels e.g. "debug" are translated to logging.DEBUG 2015-03-24 14:29:03 -04:00
Zach Riggle 0a6f1e540e Update README.md 2015-03-23 02:39:22 -04:00
Zach Riggle 2caafc879f Update README.md 2015-03-23 02:39:01 -04:00
Zach Riggle f30f2093b0 Less than, not shift 2015-03-22 23:22:47 -07:00
Zach Riggle fadfa11214 *Actually* Add mapping for i686 / 32-bit Linux 2015-03-22 23:18:35 -07:00
Zach Riggle 030407d8e7 Don't close e.g. stdin if dup'ing to it 2015-03-22 23:18:12 -07:00
Zach Riggle 0c513cb06b Mark .text area as RWX so that self-modifying code can be tested 2015-03-22 22:22:36 -07:00
Zach Riggle 2e0d7b8671 Fix output redirection based on filenames 2015-03-22 17:03:02 -07:00
Zach Riggle 5004787cb9 Add mapping for i686 / 32-bit Linux 2015-03-22 14:58:58 -07:00
Zach Riggle 1a55837bff Update .travis_install.sh 2015-03-22 06:07:39 -04:00
Zach Riggle c8c9e5d1ea Update .travis_install.sh 2015-03-22 06:07:19 -04:00
Zach Riggle 989e7694d8 Fix push and pushstr for ARM 2015-03-21 17:12:45 -04:00
Zach Riggle f753382a4d Merge remote-tracking branch 'remotes/fhare/master' 2015-03-21 16:44:10 -04:00
Zach Riggle e5b3baae84 Keep link to binary in the cache 2015-03-21 16:32:32 -04:00
Zach Riggle 1e8bf3e0e9 Remove share directory 2015-03-20 17:17:46 -04:00
Zach Riggle 3fe3502b30 Superficial changes to test CI build time 2015-03-20 17:09:57 -04:00
Zach Riggle 9905ba6605 Try absolute path 2015-03-20 17:09:08 -04:00
Zach Riggle 827d4e5f09 Superficial changes to test CI build time 2015-03-20 17:06:02 -04:00
Zach Riggle f8a64a69c1 Superficial changes to test CI build time 2015-03-20 17:03:15 -04:00
Zach Riggle 50451ceda6 Attempt caching site-packages so we dont rebuild capstone 2015-03-20 17:00:34 -04:00
Zach Riggle 1aff50166a Enable caching of binutils 2015-03-20 16:55:49 -04:00
Zach Riggle a8d02b5108 Enable caching of pip dependencies 2015-03-20 16:07:40 -04:00
Zach Riggle a46e7fdc06 Use container-based Travis CI so that it builds faster 2015-03-20 16:00:25 -04:00
Zach Riggle 50ac72d8eb Use setsid instead of setpgrp to capture output to /dev/tty 2015-03-19 17:15:37 -04:00
fhare eb8a166659 Add syscall shellcode for arm. 2015-03-18 20:11:23 +01:00
fhare 16c7954e0a Add register validation and constant substitution in mov shellcode for arm. 2015-03-18 20:11:23 +01:00
Zach Riggle f0c4d5814a No isort 2015-03-18 14:33:07 -04:00
Zach Riggle d2f0cec56d Maybe now travis will be happy? 2015-03-17 23:19:16 -04:00
Zach Riggle 2b163fb7fb Sort imports 2015-03-17 19:01:34 -04:00
Zach Riggle b9c581b78c Revert i386 mov changes temporarily 2015-03-17 12:12:06 -07:00
Zach Riggle 290f17a408 Add optimization for values which are negatable 2015-03-18 14:49:49 -04:00
Zach Riggle f22537027f Fix bug in __repr__ and make mov recursive 2015-03-18 14:49:44 -04:00
Zach Riggle 9e2901e70f Merge remote-tracking branch 'gallopsled/master'
Conflicts:
	README.md
	pwn/toplevel.py
	pwnlib/__init__.py
	pwnlib/commandline/shellcraft.py
	pwnlib/shellcraft/__init__.py
	pwnlib/tubes/ssh.py
	pwnlib/util/iters.py
2015-03-16 21:38:57 -07:00
Zach Riggle d38deb5ae7 Fix imports 2015-03-16 20:13:07 -07:00
Zach Riggle 8e14c3d488 Add context.binary helper 2015-03-16 20:09:49 -07:00
Zach Riggle 19fb739d24 Fix architectures, add more architectures, add better detection for GOT and PLT 2015-03-16 19:09:07 -07:00
Zach Riggle 7a1d62f2fb Fix bug in pause() 2015-03-16 15:19:58 -07:00
Zach Riggle 6d806cede3 Add tube.flat 2015-03-16 15:19:45 -07:00
Zach Riggle 1fc1406895 Fix leak.raw 2015-03-15 05:32:15 -07:00
Zach Riggle 008b013542 Add packing shortcuts 2015-03-14 19:35:49 -07:00
Zach Riggle e485e5bc93 Add missing architecture constants 2015-03-13 10:44:55 -07:00
Zach Riggle 4fa6cc0649 Remove link info, put arch on one line 2015-03-12 00:52:06 -07:00
Zach Riggle c825e43ff2 Add linked/static, remove RUNPATH and RPATH if they're OK since it has never been useful 2015-03-12 00:49:44 -07:00
Zach Riggle 506815533a Streamline checksec 2015-03-12 00:24:28 -07:00
Zach Riggle b9951de394 Add documentation to ELF fields 2015-03-12 00:23:14 -07:00
Zach Riggle ca8f0b2f80 Add more info to checksec, and add bits as a property 2015-03-12 00:22:07 -07:00
Zach Riggle a39b9ef25b Add endianness info to checksec script 2015-03-12 00:17:22 -07:00
Zach Riggle 3cfbf0793d Add endianess to ELF 2015-03-12 00:16:41 -07:00
Zach Riggle fced987465 Add checksec command-line script 2015-03-12 00:12:42 -07:00
Zach Riggle 2530b1c586 Make isort happy 2015-03-12 00:02:17 -07:00
Zach Riggle 477d0f54bf Fix arguments 2015-03-12 00:02:17 -07:00
Zach Riggle acc4f64a4b Add asm debugging 2015-03-12 00:02:17 -07:00
Zach Riggle f7c3dae4e1 Add shellcraft debugging 2015-03-12 00:02:17 -07:00
Zach Riggle 38e4ada7ce Rework a bunch of the shellcode for readability. 2015-03-12 00:02:12 -07:00
Zach Riggle 8afb2b6d89 .sendline() should be call-able by itself 2015-03-11 20:30:18 -07:00
Zach Riggle 81c9565e4c Don't wait forever for the PID to show up, handle if there's an issue 2015-03-11 20:29:18 -07:00
Zach Riggle 15f1aeaafe Logging hack for tube sub-classes defined outside of pwnlib 2015-03-09 23:40:35 -07:00
Zach Riggle 820936ccbd Update README.md 2015-02-26 19:08:07 -05:00
Zach Riggle 6499a63bfb Add logo with text 2015-02-26 05:01:58 -05:00
Zach Riggle c2c3aec1c8 Update LICENSE-binjitsu.txt 2015-02-26 04:46:01 -05:00
Zach Riggle 70c34aab2a Update LICENSE-binjitsu.txt 2015-02-26 04:44:51 -05:00
Zach Riggle 3be0ee96a7 Add logo CC BY 2015-02-26 04:43:54 -05:00
Zach Riggle 1e062ac52b Merge branch 'pwntools' 2015-02-25 14:47:18 -05:00
Zach Riggle fb6b046d8d Merge commit '850efb5' 2015-02-25 14:42:32 -05:00
Jonas Rudloff 0874e1908f fixed nbuckets -> nbucket in dynelf.py for sysv hash lookups
(cherry picked from commit c50d32d700)
2015-02-25 12:05:45 -05:00
Jonas Rudloff cbe13129db fixes bug in memleak.py
(cherry picked from commit 4a7d4fcff7)
2015-02-25 12:05:39 -05:00
Kenny 980d391b1f Fix #469 - verify search_results has items before using
(cherry picked from commit 8bd50f958c)
2015-02-25 12:05:35 -05:00
Zach Riggle 9d1756e99b More useful message on Administratively Prohibited 2015-02-24 16:34:06 -05:00
Zach Riggle cb163e7662 Add install message [skipci] 2015-02-21 12:27:22 -08:00
Zach Riggle fdae85c991 Check for Python development headers 2015-02-21 12:25:46 -08:00
Zach Riggle f171539d83 Include error number 2015-02-21 11:42:47 -08:00
Zach Riggle 44f881b742 Handle when there's no known_hosts or config for SSH 2015-02-21 11:28:18 -08:00
Zach Riggle cc6ca79a45 Add tox 2015-02-21 11:24:31 -08:00
Zach Riggle 9332812af1 tox.ini 2015-02-21 10:27:15 -08:00
Zach Riggle 3f23a8a63a Add missing linker flag 2015-02-21 10:12:27 -08:00
Zach Riggle 35ef86b189 Update ssh.process to use sh_string instead of creating a temporary file 2015-02-21 08:36:46 -08:00
Zach Riggle 5962bca201 Require tox 2015-02-21 08:13:53 -08:00
Zach Riggle 0c8935fc8c make clean should rmeove all temporary files 2015-02-20 16:32:01 -08:00
Zach Riggle 5e1447f8b4 When an exception is thrown on teardown, _run_handlers doesn't exist anymore 2015-02-20 16:27:35 -08:00
Zach Riggle 9ec1ea0852 Add useragents to packaged files; require recent pip 2015-02-20 16:26:40 -08:00
Zach Riggle b54d2dfa47 Pretty please? 2015-02-20 13:50:51 -08:00
Zach Riggle 547e8df98a Fix doctests 2015-02-20 13:39:12 -08:00
Zach Riggle ef74b64e86 Update test suite instructions 2015-02-20 13:30:51 -08:00
Zach Riggle 886e49bd1c Fix architectures between GDB and QEMU; auto-set endianness 2015-02-20 10:06:33 -08:00
Zach Riggle 42486c7a76 Add missing newlines to script 2015-02-19 17:51:32 -08:00
Zach Riggle 57eaede85b Add format argument 2015-02-19 17:50:52 -08:00
Zach Riggle 0ad8649599 Make default arguments a bit more explicit 2015-02-13 11:01:57 -08:00
Zach Riggle 8c183ac0e3 Fix regression which would cause ././binary to be invoked 2015-02-13 11:00:17 -08:00
Zach Riggle c0002895c8 Add an example for dup2ing 0 to 2 because subprocess tries to protect you from this 2015-02-13 10:57:55 -08:00
Zach Riggle a92260d9e5 Add preexec_fn 2015-02-13 10:46:40 -08:00
Zach Riggle b7743546b6 Fix log statements 2015-02-12 21:26:50 -08:00
Zach Riggle 75d260cd77 Add better documentation 2015-02-12 19:40:18 -08:00
Zach Riggle fc4abbf395 Add documentation for process and add shell=True doctest 2015-02-12 19:29:16 -08:00
Zach Riggle a5c8aa31a5 Default arg update 2015-02-12 19:13:16 -08:00
Zach Riggle 9e90e0485c Add file descriptors and documentation to ssh.process 2015-02-12 19:09:28 -08:00
Zach Riggle 1a1afabb23 Better fix for interactive() on raw TTYs 2015-02-12 10:24:35 -08:00
Zach Riggle 37ea0e8882 Remove extra print [skip ci] 2015-02-12 10:24:35 -08:00
Zach Riggle f3237586a5 Add warning message for no gdb-multiarch 2015-02-12 11:18:46 -05:00
Zach Riggle 324ef12b29 Revert PPA link; 2015-02-12 10:50:51 -05:00
Zach Riggle 3b659cc8ec Version fail 2015-02-12 10:48:22 -05:00
Zach Riggle 99aa19f332 Slightly better error message 2015-02-12 10:47:46 -05:00
Zach Riggle c623661f06 --upgrade 2015-02-12 10:47:00 -05:00
Zach Riggle 1d165fbde4 Evidently old versions of Git dont like Cloudflare 2015-02-12 10:37:41 -05:00
Zach Riggle a7816bde40 Change URLs to binjit.su, version to "master" 2015-02-12 10:06:55 -05:00
Zach Riggle de8de2d187 Add unit test for make_elf 2015-02-12 04:39:51 -08:00
Zach Riggle 3df64b6c80 Fix parsing ~/.ssh/config. Removes need for ssh_agent for tests. 2015-02-12 04:36:07 -08:00
Zach Riggle 84fc6a37e3 Use .string since it's easier to compare to Python 2015-02-12 03:52:51 -08:00
Zach Riggle a2fb187c2a Import everything from asm in __all__ 2015-02-12 03:25:15 -08:00
Zach Riggle 8a915a59e7 Fix gdb.attach(arch=...) and add gdb.debug_shellcode 2015-02-12 03:19:51 -08:00
Zach Riggle ea88f746a1 Fix pidof for sockets 2015-02-12 03:17:22 -08:00
Zach Riggle 33c47c159c Enable xor on integers, use default packing 2015-02-12 03:16:56 -08:00
Zach Riggle 0d544d96c8 Add message to ssh setup. Required because ssh-agent env vars must persist in parent shell. 2015-02-12 02:44:43 -08:00
Zach Riggle b9ac583e8a Fix CRLF in ssh.ssh_channel.interactive() when tty=True 2015-02-12 02:38:22 -08:00
Zach Riggle 7e46c36965 Only show build state for Master branch 2015-02-09 05:07:45 -05:00
Zach Riggle 0c9d345c37 Don't change anything at all if shell=True 2015-02-06 05:32:36 -08:00
Zach Riggle b28299a96e Style 2015-02-06 05:32:19 -08:00
Zach Riggle f6dab8cb94 Documentation on pty and tty.setraw 2015-02-06 05:30:33 -08:00
Zach Riggle ab3e58be59 Style, typos 2015-02-06 05:27:17 -08:00
Zach Riggle 068a5915b8 Clean up process tube and add member documentation 2015-02-06 05:02:48 -08:00
Zach Riggle 48ccd3dbe6 Make set_working_directory a bit faster 2015-02-05 20:24:09 -08:00
Zach Riggle 4f1bae8748 Less verbose 2015-02-05 20:18:24 -08:00
Zach Riggle 5ed9d4e2a9 Make the interfaces to process() and ssh.process() a bit more robust and fault-tolerant 2015-02-05 19:53:15 -08:00
Zach Riggle 87d12970f6 Update docs about Capstone.
It builds itself for 3.0.1+ and no longer has dependencies outside of the pip-intallable stuff
2015-02-05 09:07:07 -08:00
Zach Riggle 131e669246 Remove outdated script 2015-02-05 08:53:18 -08:00
Zach Riggle 41f003464b Merge pull request #1 from binjitsu/web-doctests
Make doctests cleaner
2015-02-05 11:52:28 -05:00
Zach Riggle b436d4a99a isort requirement 2015-02-05 04:49:50 -08:00
Zach Riggle b689dc6141 Add MIT license badge [noci] 2015-02-05 04:48:28 -08:00
Zach Riggle 9047360dd6 Add align_up alias 2015-02-05 04:48:28 -08:00
Zach Riggle 339c71abbd sorted imports with isort 2015-02-05 04:48:25 -08:00
Zach Riggle c1308f454f Enhancements to packing to allow auto-detection of sign, as well as unpack bytearray objects
(cherry picked from commit 6a3e2591c29d5a176136b1e1e16b63de5b64160c)

Conflicts:
	pwnlib/util/packing.py
2015-02-05 02:47:57 -08:00
Zach Riggle 2ec8647d10 Wait for close on unit test 2015-02-05 01:56:03 -08:00
Zach Riggle 96f07f950c Actually save the keys 2015-02-05 01:29:57 -08:00
Zach Riggle acaaf2bf98 Enforce SSH keys for IP 2015-02-05 01:15:22 -08:00
Zach Riggle 5e4fa7c03d Enhance test for process tube 2015-02-05 00:15:25 -08:00
Zach Riggle 1a69412209 Handle IOError, and ensure Ctrl+C sent to parent process does not propagate to child
(cherry picked from commit 99cae63745)

Conflicts:
	pwnlib/tubes/process.py
2015-02-05 00:10:54 -08:00
Zach Riggle d194dfd8ce Set stdout to be a PTY on spawned processes so that stdout is not buffered.
(cherry picked from commit 1273bfa1fb)

Conflicts:
	pwnlib/tubes/process.py
2015-02-04 23:58:28 -08:00
Zach Riggle 2c5ea17ddb Merge remote-tracking branch 'origin/capstone3'
Conflicts:
	docs/source/install.rst
2015-02-04 23:52:51 -08:00
Zach Riggle 9d25c526e9 Add --address to disasm 2015-02-02 21:46:25 -08:00
Zach Riggle 34c4843bbf Make gadget loading faster by saving the original addresses and fixing up at runtime 2015-02-02 21:46:11 -08:00
Zach Riggle 4616f9f107 Fix indentation of docstrings 2015-02-02 04:22:55 -08:00
Zach Riggle 12fe3d310a Fix download_file regression and fix spinners 2015-02-02 04:22:37 -08:00
Zach Riggle 24661aa6e7 Fix isEnabledFor 2015-02-02 03:22:32 -08:00
Zach Riggle 1b5c6162d1 Merge branch 'ssh-upgrades' 2015-02-02 03:01:02 -08:00
Zach Riggle e17e9c8b43 Fix issue where "tar -C /tmp" will fail if /tmp is not +r (enumeratable) 2015-02-02 02:56:37 -08:00
Zach Riggle a9e535eef6 Revamp download_dir (did it ever work?) and add "download" alias 2015-02-02 02:56:37 -08:00
Zach Riggle dfe78552c3 Add upload and put aliases/helpers 2015-02-02 02:56:37 -08:00
Zach Riggle 16dadb3376 Rewrite the upload functionality 2015-02-02 02:56:33 -08:00
Zach Riggle 054b7a5b17 Allow ~/foo in ssh.upload_dir 2015-02-02 00:47:41 -08:00
Zach Riggle 3eccae29d8 Only print checksec info once per ELF 2015-02-01 21:10:45 -08:00
Zach Riggle 37e29db87a Clean up SSH cache to only use SHA256. Additionally ssh.libs() now returns the original binary as well. Currently, the address is set to zero. 2015-02-01 21:09:21 -08:00
Zach Riggle dc84e7150a More reverting 2015-02-01 00:21:13 -08:00
Zach Riggle f6e90df62a Revert "Rename "pwn" to "binjitsu""
This reverts commit 8bbaa14afe.
2015-01-31 23:58:16 -08:00
Zach Riggle a96ffc80a2 Fix mis-reporting of NX when there is no GNU_STACK segment 2015-01-31 23:31:49 -08:00
Zach Riggle dae43bb581 Make doctests not spew stuff 2015-01-31 22:47:23 -08:00
Zach Riggle b399f2a439 Merge branch 'threading-event-wait' 2015-01-31 22:45:26 -08:00
Zach Riggle 6730a63432 Add --upgrade 2015-01-31 20:49:43 -08:00
Zach Riggle 8bbaa14afe Rename "pwn" to "binjitsu" 2015-01-31 20:37:58 -08:00
Zach Riggle 7bc5a9cc31 args => argv 2015-01-29 21:15:24 -08:00
Zach Riggle 1844b85ae6 Enable debugging ssh channels. Enrich information with pid and args. Add documentation 2015-01-29 19:51:32 -08:00
Zach Riggle ff19108e02 Revert default log level back to 1; handle isEnabledFor in accordance with context 2015-01-29 19:51:32 -08:00
Zach Riggle 5e58b94d7a Update install docs 2015-01-29 19:51:32 -08:00
Zach Riggle 9a5bccd837 Remove versioned stuff 2015-01-29 19:42:35 -05:00
Zach Riggle 7865ec93b0 Wake up Travis 2015-01-29 19:42:01 -05:00
Zach Riggle de68ff6734 Update installation instructions 2015-01-29 18:43:36 -05:00
Zach Riggle d26a5a7012 Fix quoting style from repr 2015-01-29 18:41:15 -05:00
Zach Riggle 5f167c657f Fix indentation 2015-01-29 05:08:31 -08:00
Zach Riggle 67faf896f1 Make unhex() a bit more forgiving 2015-01-29 05:06:29 -08:00
Zach Riggle 073a179d29 Don't log twice for clean_and_log. 2015-01-28 22:52:12 -08:00
Zach Riggle 65847258fd Always print security info 2015-01-28 20:54:08 -08:00
Zach Riggle b6a98274c0 Update docs 2015-01-28 20:54:00 -08:00
Zach Riggle da9ee7bd9d Fix hostname 2015-01-28 19:33:14 -08:00
Zach Riggle 47160d7398 Expressly disable tty for upload_data 2015-01-28 17:39:01 -08:00
Zach Riggle 5974be5c01 Fix SSH doctests 2015-01-28 17:38:59 -08:00
Zach Riggle edf68d3ffb Dont spawn a tty for this "sh" example 2015-01-28 16:33:36 -08:00
Zach Riggle dddc0ee163 Restore pep237 2015-01-28 16:32:10 -08:00
Zach Riggle 27e96868b8 Unbreak the build while sphinx fixes their issues.
https://bitbucket.org/birkenfeld/sphinx-contrib/issue/93/
2015-01-28 16:26:19 -08:00
Zach Riggle efce85666d Print the actual command used if debugging 2015-01-28 16:26:15 -08:00
Zach Riggle cdbba52548 Disable echoing of control characters 2015-01-27 22:58:17 -08:00
Zach Riggle 2cc92df291 Use tty by default, and run "stty raw" by default except for when doing a shell (process==None).
Add a doctest for sftp vs non-sftp uploads.
Remove extra output from script generated by ssh.process if not run directly.
2015-01-27 22:46:16 -08:00
Zach Riggle f3a0a4f781 Change magic log number to -1 2015-01-27 22:44:53 -08:00
Zach Riggle b5d33ff064 Don't eat Ctrl+C with all the exceptions 2015-01-27 15:00:30 -08:00
Zach Riggle 7e829db170 Fix path names for sftpclient and make script executable 2015-01-27 14:58:54 -08:00
Zach Riggle 504c502c22 Merge branch 'sftpclient' 2015-01-27 12:17:27 -08:00
Zach Riggle 3324062013 Update ssh object to use sftp first; expose _wd as cwd; optional caching 2015-01-27 12:17:11 -08:00
Zach Riggle 3a767b45dd Unfuck progress 2015-01-26 23:19:55 -08:00
Zach Riggle ebb349c700 Merge branch 'commandline-context-pwntools'
Conflicts:
	pwnlib/commandline/disasm.py
	pwnlib/commandline/shellcraft.py
2015-01-26 22:54:00 -08:00
Zach Riggle 9991348963 Use "from pwn import *" in command-line utilities, and shovel all the context information through a single handler 2015-01-26 22:53:10 -08:00
Zach Riggle b010daa438 Set permissions on temporary working directory 2015-01-26 22:24:14 -08:00
Zach Riggle 73a494cfd0 Clean up import name duplication, add pwnlib.version 2015-01-25 22:02:33 -08:00
Zach Riggle 3c2074cdeb Rename ssh.run to ssh.system 2015-01-25 21:53:27 -08:00
Zach Riggle 16f7021065 Merge branch 'ssh-process-execve-binjitsu' 2015-01-25 21:51:26 -08:00
Zach Riggle bd137c7a4c Add a more robust interface to SSH commands which doesn't require hacky shell escaping if Python is available on the remote host. This interface follows the same style as pwnlib.tubes.process.process 2015-01-25 21:51:08 -08:00
Zach Riggle 4137fac99b Merge branch 'commandline-context-pwntools'
Conflicts:
	pwnlib/commandline/shellcraft.py
2015-01-25 21:40:09 -08:00
Zach Riggle 57de045db5 Use "from pwn import *" in command-line utilities, and shovel all the context information through a single handler 2015-01-25 21:38:23 -08:00
Zach Riggle 5046f18b90 Merge branch 'shellcraft-speedup' 2015-01-25 21:29:05 -08:00
Zach Riggle dcd3df3f10 Sort templates 2015-01-25 21:24:49 -08:00
Zach Riggle ceec814588 Speed up shellcraft loading and clean up code a bit 2015-01-25 21:21:16 -08:00
Zach Riggle a4860f3167 Watch all branches 2015-01-25 18:15:37 -08:00
Zach Riggle c762eec46c Make doctests cleaner 2015-01-25 18:14:44 -08:00
Zach Riggle 380eda7234 Update log statement 2015-01-25 18:08:22 -08:00
Zach Riggle f02cc65624 Merge branch 'elf-data-property' 2015-01-24 17:20:21 -08:00
Zach Riggle 32ecc909a3 Add .data property 2015-01-24 17:19:56 -08:00
Zach Riggle ec64ebe3c7 Merge branch 'ssh-revamp-localhost-only' 2015-01-24 01:21:04 -08:00
Zach Riggle fb7d604927 Update self.host to the resolved host 2015-01-24 01:20:05 -08:00
Zach Riggle 93a95d16f1 Restrict demouser for Travis to localhost only. Change host name from localhost to example.pwnme. Add support for getting the hostname and identityfile from ssh_config.
Conflicts:
	pwnlib/tubes/ssh.py
2015-01-24 01:19:55 -08:00
Zach Riggle 9de8211e58 Fix logging in tests 2015-01-23 23:35:45 -08:00
Zach Riggle 33d7e4ea30 mips -> tradmips 2015-01-22 04:48:30 -08:00
Zach Riggle 99acaf7471 Make nosetests work 2015-01-15 02:54:57 -05:00
Zach Riggle e48c08baa4 Change default fd back to stdout 2015-01-15 02:23:56 -05:00
Zach Riggle b4e89ab373 Fix dependency for travis 2015-01-15 02:20:22 -05:00
Zach Riggle 806f2a3e7d Merge remote-tracking branch 'upstream/fix-stager' 2015-01-15 02:13:49 -05:00
Zach Riggle c709e7e753 Merge branch 'StevenVanAcker/patch-1' 2015-01-15 02:13:31 -05:00
Zach Riggle 88a83cad71 The great rebranding 2015-01-15 02:03:57 -05:00
Zach Riggle b41a4057c3 Merge branch 'tubes-are-loggers' 2015-01-12 16:23:23 -05:00
Zach Riggle 49244fe1dc Merge branch 'log-level-one' 2015-01-12 16:23:03 -05:00
Zach Riggle 1c06dca971 Merge branch 'connect-gethostbyname' 2015-01-12 16:22:11 -05:00
Zach Riggle 85379b292d Merge branch 'context-logfile' 2015-01-12 16:22:07 -05:00
Zach Riggle 88195d8c56 Merge branch 'issue-338' 2015-01-12 16:22:03 -05:00
Zach Riggle 1c52cd0390 Implement "wrap" word_size 2015-01-12 12:50:04 -05:00
Zach Riggle bc270113b6 Enable use of hostnames for connect shellcode. 2015-01-12 12:26:12 -05:00
Zach Riggle 139937114b Stupid doctests 2015-01-12 12:17:19 -05:00
Zach Riggle 2f22025cea Set level to 1 instead 2015-01-12 12:17:19 -05:00
Zach Riggle 8f13445b73 Fix doctest formatting 2015-01-12 12:17:03 -05:00
Zach Riggle f297cf60ba Defer adding a handler and setting the root logger level 2015-01-12 12:17:03 -05:00
Zach Riggle 19866979bc Get rid of reliance on /dev/null; flush logfile when changing log files 2015-01-12 12:16:19 -05:00
Zach Riggle 372490b4e9 Add doctest 2015-01-12 12:16:19 -05:00
Zach Riggle 9f244268ca Re-add handler, should work after #419 is resolved. 2015-01-12 12:16:19 -05:00
Zach Riggle d3929505c4 Remove handler to check Travis result 2015-01-12 12:16:19 -05:00
Zach Riggle a4f21971d1 Skip emitting and formatting records sent to the LogFile if it's /dev/null, which is also the default value 2015-01-12 12:16:19 -05:00
Zach Riggle 4d31a89a67 Enable per-thread logfiles via context, and retargetting the logfile at runtime 2015-01-12 12:16:19 -05:00
Zach Riggle ca47f5ce27 Tubes are Loggers 2015-01-12 12:15:53 -05:00
Zach Riggle 7e02110bc5 Invert the lookup on logging verbosity, using 1 as a sentinel value for "not set" 2015-01-12 12:15:53 -05:00
Zach Riggle 69073530fd Invert the lookup on logging verbosity, using 1 as a sentinel value for "not set" 2015-01-12 12:15:20 -05:00
Zach Riggle 8943102479 Set logLevel to 1 2015-01-12 12:14:48 -05:00
Zach Riggle 37a46e052a Enable direct calls to pack() without endianness specified to pack negative numbers as positive numbers. Fixes #338. 2015-01-12 02:09:39 -05:00
3348 changed files with 49316 additions and 5304 deletions

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
[run]
branch = True
omit =
*/constants/*
source =
pwn
pwnlib
~/.pwntools-cache/
+4 -1
View File
@@ -3,6 +3,7 @@
*.pyc
*~
*.swp
.ropeproject
*.pdf
*/auto/*
*/bin/*
@@ -10,4 +11,6 @@ docs/build
build
MANIFEST
dist
pwntools.egg-info
*.egg-info
*.core
.coverage
+7
View File
@@ -0,0 +1,7 @@
{
"default_encoding": "UTF-8",
"ensure_newline_at_eof_on_save": true,
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
}
+14 -7
View File
@@ -1,5 +1,10 @@
sudo: false
language: python
addons:
apt:
packages:
- gcc-multilib
- gcc-4.6-arm-linux-gnueabihf
cache:
- pip
- directories:
@@ -8,16 +13,18 @@ cache:
- /home/travis/virtualenv/python2.7.9/bin/
python:
- "2.7"
after_success:
- coveralls
before_install:
- source .travis_ssh_setup.sh
- source .travis_install.sh
- source .travis_ssh_setup.sh
install:
- pip install -e .
- pip install -r docs/requirements.txt
before_script:
- python -c 'from pwn import *; print pwnlib.term.term_mode' NOTERM
- python -c 'from pwn import *; print pwnlib.term.term_mode' NOTERM
- python -c 'from pwn import *; print pwnlib.term.term_mode' NOTERM
- python -c 'from pwn import *; print pwnlib.term.term_mode' NOTERM
script: PWNLIB_NOTERM=1 make -C docs doctest
- PWNLIB_NOTERM=1 python -c 'from pwn import *; print pwnlib.term.term_mode'
- PWNLIB_NOTERM=1 python -c 'from pwn import *; print pwnlib.term.term_mode'
- PWNLIB_NOTERM=1 python -c 'from pwn import *; print pwnlib.term.term_mode'
- PWNLIB_NOTERM=1 python -c 'from pwn import *; print pwnlib.term.term_mode'
script:
- PWNLIB_NOTERM=1 coverage run -m sphinx -b doctest docs/source docs/build/doctest
+33 -7
View File
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
#!/usr/bin/env bash -e
local_deb_extract()
{
wget $1
ar vx *.deb
tar xvf data.tar.gz
rm -f *.tar.gz *deb*
tar xvf data.tar.*
rm -f *.tar.* *deb*
}
get_binutils()
@@ -14,20 +14,37 @@ get_binutils()
local_deb_extract "${BINUTILS_PREFIX}${1}${BINUTILS_SUFFIX}"
}
get_qemu()
{
echo "Installing qemu"
QEMU_URL='https://mirrors.kernel.org/ubuntu/pool/universe/q/qemu/qemu-user-static_2.6%2bdfsg-3ubuntu1_amd64.deb'
local_deb_extract "$QEMU_URL"
}
setup_travis()
{
export PATH=$PWD/usr/bin:$PATH
export LD_LIBRARY_PATH=$PWD/usr/lib
if [ ! -d usr/bin ];
if [ ! -d usr/bin ];
then
# Install our custom binutils
which arm-linux-as || get_binutils arm
which mips-linux-as || get_binutils mips
which powerpc-linux-as || get_binutils powerpc
which aarch64-linux-as || get_binutils aarch64
# Install the multiarch binutils
local_deb_extract http://mirrors.mit.edu/ubuntu/ubuntu/pool/universe/b/binutils/binutils-multiarch_2.22-6ubuntu1_amd64.deb
rm -rf usr/share
fi
if ! (which qemu-arm-static && qemu-arm-static -version | grep 2.6.0); then
get_qemu
fi
# Get rid of files we don't want cached
rm -rf usr/share
pushd usr/lib
ln -sf libbfd-2.22-multiarch.so libbfd-2.22.so
ln -sf libopcodes-2.22-multiarch.so libopcodes-2.22.so
@@ -36,11 +53,13 @@ setup_travis()
which arm-linux-gnu-as
which mips-linux-gnu-as
which powerpc-linux-gnu-as
which aarch64-linux-gnu-as
which qemu-arm-static
}
setup_linux()
{
sudo apt-get install software-properties-common pwgen
sudo apt-get install -y software-properties-common openssh-server libncurses5-dev libncursesw5-dev
sudo apt-add-repository --yes ppa:pwntools/binutils
sudo apt-get update
sudo apt-get install binutils-arm-linux-gnu binutils-mips-linux-gnu binutils-powerpc-linux-gnu
@@ -53,10 +72,17 @@ setup_osx()
brew install capstone
}
if [[ "$TRAVIS" ]]; then
if [[ "$USER" == "travis" ]]; then
setup_travis
elif [[ "$USER" == "shippable" ]]; then
sudo apt-get update
sudo apt-get install openssh-server gcc-multilib
sudo /usr/sbin/sshd -f /etc/ssh/sshd_config &
setup_travis
elif [[ "$(uname)" == "Darwin" ]]; then
setup_osx
elif [[ "$(uname)" == "Linux" ]]; then
setup_linux
fi
dpkg -l
+6 -5
View File
@@ -2,12 +2,14 @@
#
# Install a demo user for SSH purposes
#
# All of the "conditional sudo" is to do container-based builds on
# Travis which are much, much faster.
U=travis
H=/home/$U
USUDO()
{
if [ "$TRAVIS" ];
if [[ "$USER" == "travis" ]];
then
$*
else
@@ -16,7 +18,7 @@ fi
}
if [ "$TRAVIS" ];
if [[ "$USER" == "travis" ]];
then
rm -f ~/.ssh/*
else
@@ -44,10 +46,9 @@ EOF
cat >> ~/.ssh/config <<EOF
Host example.pwnme
User travis
User $U
HostName 127.0.0.1
IdentityFile ~/.ssh/$U
EOF
ssh-keyscan -t rsa example.pwnme >>~/.ssh/known_hosts
ssh -o "StrictHostKeyChecking no" -v [email protected] id
ssh -o "StrictHostKeyChecking no" -vvvv [email protected] id
+99
View File
@@ -3,6 +3,105 @@
This changelog only includes added major features and changes. Bugfixes and
minor changes are omitted.
## 3.0.0 (August 20 2016)
This was a large release (1305 commits since 2.2.0) with a lot of bugfixes and changes. The Binjitsu project, a fork of Pwntools, was merged back into Pwntools. As such, its features are now available here.
As always, the best source of information on specific features is the comprehensive docs at https://pwntools.readthedocs.org.
This list of changes is non-complete, but covers all of the significant changes which were appropriately documented.
#### Android
Android support via a new `adb` module, `context.device`, `context.adb_host`, and `context.adb_port`.
#### Assembly and Shellcode
- Assembly module enhancements for making ELF modules from assembly or pre-assembled shellcode. See `asm.make_elf` and `asm.make_elf_from_assembly`.
- `asm` and `shellcraft` command-line tools support flags for the new shellcode encoders
- `asm` and `shellcraft` command-line tools support `--debug` flag for automatically launching GDB on the result
- Added MIPS, PowerPC, and AArch64 support to the `shellcraft` module
- Added Cyber Grand Challenge (CGC) support to the `shellcraft` module
- Added syscall wrappers for every Linux syscall for all supported architectures to the `shellcraft` module
+ e.g. `shellcraft.<arch>.gettimeofday`
- (e.g. `shellcraft.i386.linux.`)
- Added in-memory ELF loaders for most supported architectures
+ Only supports statically-linked binaries
+ `shellcraft.<arch>.linux.loader`
#### Context Module
- Added `context.aslr` which controls ASLR on launched processes. This works with both `process()` and `ssh.process()`, and can be specified per-process with the `aslr=` keyword argument.
- Added `context.binary` which automatically sets all `context` variables from an ELF file.
- Added `context.device`, `context.adb`, `context.adb_port`, and `context.adb_host` for connecting to Android devices.
- Added `context.kernel` setting for SigReturn-Oriented-Programming (SROP).
- Added `context.log_file` setting for sending logs to a file. This can be set with the `LOG_FILE` magic command-line option.
- Added `context.noptrace` setting for disabling actions which require `ptrace` support. This is useful for turning all `gdb.debug` and `gdb.attach` options into no-ops, and can be set via the `NOPTRACE` magic command-line option.
- Added `context.proxy` which hooks all connections and sends them to a SOCKS4/SOCKS5. This can be set via the `PROXY` magic command-line option.
- Added `context.randomize` to control randommization of settings like XOR keys and register ordering (default off).
- Added `context.termianl` for setting how to launch commands in a new terminal.
#### DynELF and MemLeak Module
- Added a `DynELF().libc` property which attempt to find the remote libc and download the ELF from LibcDB.
- Added a `DynELF().stack` property which leaks the `__environ` pointer from libc, making it easy to leak stack addresses.
- Added `MemLeak.String` and `MemLeak.NoNewlines` and other related helpers for handling special leakers which cannot e.g. handle newlines in the leaked addresses and which leak a C string (e.g. auto-append a `'\x00'`).
- Enhancements for leaking speed via `MemLeak.compare` to avoid leaking an entire field if we can tell from a partial leak that it does not match what we are searching for.
#### Encoders Module
- Added a `pwnlib.encoders` module for assembled-shellcode encoders/decoders
- Includes position-indepentent basic XOR encoders
- Includes position-independent delta encoders
- Includes non-position-independent alphanumeric encoders for Intel
- Includes position-independent alphanumeric encoders for ARM/Thumb
#### ELF Module
- Added a `Core` object which can parse core-files, in order to extract / search for memory contents, and extract register states (e.g. `Core('./corefile').eax`).
#### Format Strings
- Added a basic `fmtstr` module for assisting with Format String exploitation
#### GDB Module
- Added support for debugging Android devices when `context.os=='android'`
- Added helpers for debugging shellcode snippets with `gdb.debug_assembly()` and `gdb.debug_shellcode()`
#### ROP Module
- Added support for SigReturn via `pwnlib.rop.srop`
+ Occurs automatically when syscalls are invoked and a function cannot be found
+ SigReturn frames can be constructed manually with `SigreturnFrame()` objects
- Added functional doctests for ROP and SROP
#### Tubes Process Module
- `process()` has many new options, check out the documentation
+ `aslr` controls ASLR
+ `setuid` can disable the effect of setuid, allowing core dumps (useful for extracting crash state via the new `Core()` object)
+ TTY echo and control characters can be enabled via `raw` argument
- `stdout` and `stderr` are now PTYs by default
+ `stdin` can be set to a PTY also via setting `stdin=process.PTY`
#### Tubes SSH Module
- Massive enhancements all over
- `ssh` objects now have a `ssh.process()` method which avoids the need to handle shell expansion via the old `ssh.run()` method
- Files are downloaded via SFTP if available
- New `download` and `upload` methods auto-detect whether the target is a file or directory and acts accordingly
- Added `listen()` method alias for `listen_remote()`
- Added `remote()` method alias for `connect_remote()`
#### Utilities
- Added `fit()` method to combine the functionality of `flat()` with the functionality of `cyclic()`
- Added `negative()` method to negate the value of an integer via two's complement, with respect to the current integer size (`context.bytes`).
- Added `xor_key()` method to generate an XOR key which avoids undesirable bytes over a given input.
- Added a multi-threaded `bruteforce()` implementation, `mbruteforce()`.
- Added `dealarm_shell()` helper to remove the effects of `alarm()` after you've popped a shell.
## 2.2.0
This was a large release with a lot of bugfixes and changes. Only the most significant
+4 -12
View File
@@ -1,7 +1,5 @@
# Contributing
We love pull requests!
Github has a great guide for contributing to open source projects:
- [Contributing to a project](https://guides.github.com/activities/forking/)
@@ -11,7 +9,7 @@ Github has a great guide for contributing to open source projects:
- [Making a Pull Request](https://guides.github.com/activities/forking/#making-a-pull-request)
- [Huzzah!](https://guides.github.com/activities/forking/#huzzah)
## Pwntools Specifics
## pwntools Specifics
In general, we like to keep things documented. You should add documentation to any new functionality, and update it for any changed functionality. Our docstrings use the [Google Style Python Docstrings](https://sphinxcontrib-napoleon.readthedocs.org/en/latest/example_google.html#example-google).
@@ -25,14 +23,8 @@ Once you do the pull-request Travis CI will run the test-suite on it. Once it
passes one of the core developers will look at your pull request, possibly
comment on it and then hopefully merge it into master.
## Test Suite
## Automated Testing
To run the test suite, you should be running Ubuntu 12.04 or 14.04, and run the following commands. **Be aware** that this will add a user to your machine, and create a public key for SSH login!
Pull requests against Pwntools require at a minimum that no tests have been broken, and ideally each pull request will include new tests to ensure that all of the functionality works as intended.
```sh
bash .travis_install.sh
bash .travis_ssh_setup.sh
cd docs
pip install -r requirements.txt
make doctest
```
You can find more information on testing in [TESTING.md](TESTING.md).
+21 -19
View File
@@ -1,14 +1,16 @@
![pwntools logo](docs/source/logo.png?raw=true)
# pwntools - CTF toolkit
![pwntools logo](https://github.com/Gallopsled/pwntools/blob/master/docs/source/logo.png?raw=true)
[![Docs latest](https://readthedocs.org/projects/pwntools/badge/)](https://pwntools.readthedocs.org/en/latest)
[![Docs latest](https://readthedocs.org/projects/pwntools/badge/?version=latest)](https://pwntools.readthedocs.org/)
[![Docs 2.2.0](https://readthedocs.org/projects/pwntools/badge/?version=2.2.0)](https://pwntools.readthedocs.org/en/2.2.0)
[![PyPI](https://img.shields.io/pypi/v/pwntools.svg?style=flat)](https://pypi.python.org/pypi/pwntools/)
[![Gittip](https://img.shields.io/gittip/gallopsled.svg?style=flat)](https://www.gittip.com/gallopsled/)
[![Travis](https://travis-ci.org/Gallopsled/pwntools.svg)](https://travis-ci.org/Gallopsled/pwntools)
[![Twitter](https://img.shields.io/badge/twitter-Gallopsled-4099FF.svg?style=flat)](https://twitter.com/Gallopsled)
[![Travis](https://travis-ci.org/Gallopsled/pwntools.svg?branch=master)](https://travis-ci.org/Gallopsled/pwntools)
[![Coveralls](https://img.shields.io/coveralls/Gallopsled/pwntools/master.svg)](https://coveralls.io/github/Gallopsled/pwntools?branch=master)
[![Twitter](https://img.shields.io/badge/twitter-pwntools-4099FF.svg?style=flat)](https://twitter.com/pwntools)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](http://choosealicense.com/licenses/mit/)
This is the CTF framework used by Gallopsled in every CTF.
pwntools is a CTF framework and exploit development library. Written in Python, it is designed for rapid prototyping and development, and intended to make exploit writing as simple as possible.
```python
from pwn import *
@@ -20,32 +22,32 @@ r.send(asm(shellcraft.sh()))
r.interactive()
```
However we have made command-line frontends for some of the functionality
in `pwnlib`. These are:
# Try It Now!
* `asm`/`disasm`: Small wrapper for various assemblers.
* `constgrep`: Tool for finding constants defined in header files.
* `cyclic`: De Bruijn sequence generator and lookup tool.
* `hex`/`unhex`: Command line tools for doing common hexing/unhexing operations.
* `shellcraft`: Frontend to our shellcode.
* `phd`: Replacement for `hexdump` with colors.
You can now do a live demo of Pwntools, [right in your browser](http://demo.pwntools.com). Alternately, you can SSH to the same host, and log in as user `zerocool` with [this private key][key] (password `i_promise_not_to_be_evil`).
It will drop you into a clean, Docker-ized container. There is nothing of value on the VPS, so please don't be evil.
[key]: https://gist.githubusercontent.com/zachriggle/efa2e0080ae6de2e8344/raw/4b503e9db54f009d97477d03d4ba5678471f8ff0/id_rsa
# Documentation
Our documentation is available at [pwntools.readthedocs.org](https://pwntools.readthedocs.org/en/latest/)
Our documentation is available at [pwntools.readthedocs.org](https://pwntools.readthedocs.org/)
To get you started, we've provided some example solutions for past CTF challenges in our [write-ups repository](https://github.com/Gallopsled/pwntools-write-ups).
# Installation
pwntools is best supported on Ubuntu 12.04 and 14.04, but most functionality should work on any Posix-like distribution (Debian, Arch, FreeBSD, OSX, etc.).
pwntools is best supported on 64-bit Ubuntu 12.04 and 14.04, but most functionality should work on any Posix-like distribution (Debian, Arch, FreeBSD, OSX, etc.). Python 2.7 is required.
Most of the functionality of pwntools is self-contained and Python-only. You should be able to get running quickly with
```sh
pip install pwntools
apt-get update
apt-get install python2.7 python-pip python-dev git libssl-dev
pip install --upgrade git+https://github.com/Gallopsled/pwntools.git
```
However, some of the features (ROP generation and assembling/disassembling foreign architectures) require non-Python dependencies. For more information, see the [complete installation instructions here](https://pwntools.readthedocs.org/en/latest/install.html).
However, some of the features (assembling/disassembling foreign architectures) require non-Python dependencies. For more information, see the [complete installation instructions here](https://pwntools.readthedocs.org/en/latest/install.html).
# Contribution
@@ -53,7 +55,7 @@ However, some of the features (ROP generation and assembling/disassembling forei
See [CONTRIBUTING.md](CONTRIBUTING.md)
# Contact
If you have any questions not worthy of a [bug report](https://github.com/Gallopsled/pwntools/issues), feel free to join us
If you have any questions not worthy of a [bug report](https://github.com/Gallopsled/pwntools/issues), feel free to ping us
at [`#pwntools` on Freenode](irc://irc.freenode.net/pwntools) and ask away.
Click [here](https://kiwiirc.com/client/irc.freenode.net/pwntools) to connect.
There is also a [mailing list](https://groups.google.com/forum/#!forum/pwntools-users) for higher latency discussion.
+41
View File
@@ -0,0 +1,41 @@
# Testing
Pwntools makes extensive use of unit tests and integration tests to ensure everything is in working order, and no regressions occur.
## Test Suite
To run the test suite, it is beste to use Ubuntu 12.04 or 14.04, and run the following commands. **Be aware** that this will add a user to the machine, and create a public key for SSH login!
```sh
bash .travis_install.sh
bash .travis_ssh_setup.sh
pip install -e .
pip install -r docs/requirements.txt
cd docs
PWNLIB_NOTERM=1 make clean doctest
```
## New Tests
To add a new test to an existing module, just add an inline doctest. If the test needs access to an external module, add the import statement to the `testsetup` block in the corresponding file in `docs/source/<module>.rst`.
To add an entirely new module, create a new `module.rst` and add it to the list in `index.rst`. The best way to see if your tests are actually being run is to add an intentionally-failing test like:
```py
>>> assert False
```
## Example Test Module
The module `pwnlib.testexample` exists to demonstrate how everything is tied together. The only files which were modified to add this example module and run its tests automatically are:
- `pwnlib/testexample.py`
- `docs/source/testexample.rst`
- `docs/source/index.rst`
## Shellcode and ROP
These are both less easy to test, as they require actually executing code, or loading real binaries. In order to make the process simpler, the `runner` library was created to wrap common tasks. For an example of testing shellcode with these helpers, see [exit.asm](pwnlib/shellcraft/templates/i386/linux/exit.asm).
Additionally, for loading ELF files on-the-fly, the helpers `ELF.from_bytes` and `ELF.from_assembly` are available.
+4
View File
@@ -44,6 +44,10 @@ help:
clean:
-rm -rf $(BUILDDIR)/*
-rm -rf /tmp/user/pwn*
-rm -rf $(HOME)/.pwntools-cache
-rm -rf /tmp/pwn* 2>/dev/null || true
-rm -rf build
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+54 -54
View File
@@ -26,68 +26,68 @@ sys.path.append(os.path.abspath(os.path.join('..', 'pwnlib')))
import version
def main(args):
"""Generate a Dash docset from Sphinx source files."""
"""Generate a Dash docset from Sphinx source files."""
srcdir = args.srcdir
dstdir = args.dstdir
name = args.name
srcdir = args.srcdir
dstdir = args.dstdir
name = args.name
if not os.path.exists(dstdir):
os.makedirs(dstdir)
if not os.path.exists(dstdir):
os.makedirs(dstdir)
# Generate HTML without indices.
sphinx.build_main([ "sphinx-build", "-b", "html", "-d", os.path.join(dstdir, "doctrees"), \
"-t", "dash", srcdir, os.path.join(dstdir, "html") ])
# Generate HTML without indices.
sphinx.build_main([ "sphinx-build", "-b", "html", "-d", os.path.join(dstdir, "doctrees"), \
"-t", "dash", srcdir, os.path.join(dstdir, "html") ])
# Convert to docset.
try:
doc2dash.__main__.main.main( \
[ os.path.join(dstdir, "html"), "-d", dstdir, "-n", name, \
"-f", "-I", "index.html"], "doc2dash", False)
except SystemExit,e:
pass
# Convert to docset.
try:
doc2dash.__main__.main.main( \
[ os.path.join(dstdir, "html"), "-d", dstdir, "-n", name, \
"-f", "-I", "index.html"], "doc2dash", False)
except SystemExit,e:
pass
# Insert a link to the online version.
online = args.online
if online is not None and online != "":
url = online.replace("@VERSION", args.version)
with open(os.path.join(dstdir, name+".docset", "Contents", "Info.plist"), "r+") as f_info:
pl = f_info.read()
pl = pl.replace("</dict>", \
"\t<key>DashDocSetFallbackURL</key>\n\t<string>%s</string>\n</dict>" % url)
f_info.seek(0)
f_info.write(pl)
f_info.truncate()
# Insert a link to the online version.
online = args.online
if online is not None and online != "":
url = online.replace("@VERSION", args.version)
with open(os.path.join(dstdir, name+".docset", "Contents", "Info.plist"), "r+") as f_info:
pl = f_info.read()
pl = pl.replace("</dict>", \
"\t<key>DashDocSetFallbackURL</key>\n\t<string>%s</string>\n</dict>" % url)
f_info.seek(0)
f_info.write(pl)
f_info.truncate()
# Modify the CSS to hide the menu included in the HTML.
with open(os.path.join(dstdir, name+".docset", "Contents", "Resources", "Documents", "_static", "css", "theme.css"), "r+") as f_css:
css = f_css.read()
css = css.replace( \
'@media screen and (max-width: 768px){.wy-body-for-nav{background:#fcfcfc}.wy-nav-top{display:block}',\
'@media screen {.wy-body-for-nav{background:#fcfcfc}' )
css = css.replace( \
'@media screen and (max-width: 480px)', \
'@media screen ')
f_css.seek(0)
f_css.write(css)
f_css.truncate()
# Modify the CSS to hide the menu included in the HTML.
with open(os.path.join(dstdir, name+".docset", "Contents", "Resources", "Documents", "_static", "css", "theme.css"), "r+") as f_css:
css = f_css.read()
css = css.replace( \
'@media screen and (max-width: 768px){.wy-body-for-nav{background:#fcfcfc}.wy-nav-top{display:block}',\
'@media screen {.wy-body-for-nav{background:#fcfcfc}' )
css = css.replace( \
'@media screen and (max-width: 480px)', \
'@media screen ')
f_css.seek(0)
f_css.write(css)
f_css.truncate()
# Modify the index
db_conn = sqlite3.connect(os.path.join(dstdir, name+".docset", "Contents", "Resources", "docSet.dsidx"))
try:
db_conn.execute('INSERT INTO "searchIndex" ("name","type","path") VALUES ' \
'("1 Contents", "Guide", "index.html"), ' \
'("2 About pwntools", "Guide", "about.html"), ' \
'("3 Installation", "Guide", "install.html"), ' \
'("4 Getting Started", "Guide", "intro.html"), ' \
'("5 Globals (pwn)", "Guide", "globals.html"), ' \
'("6 Command Line Tools", "Guide", "commandline.html")')
db_conn.execute('DELETE FROM "searchIndex" WHERE "type" = "Module" AND ("name" = "pwn" OR "name" = "pwnlib")')
db_conn.commit()
finally:
db_conn.close()
# Modify the index
db_conn = sqlite3.connect(os.path.join(dstdir, name+".docset", "Contents", "Resources", "docSet.dsidx"))
try:
db_conn.execute('INSERT INTO "searchIndex" ("name","type","path") VALUES ' \
'("1 Contents", "Guide", "index.html"), ' \
'("2 About pwntools", "Guide", "about.html"), ' \
'("3 Installation", "Guide", "install.html"), ' \
'("4 Getting Started", "Guide", "intro.html"), ' \
'("5 Globals (pwn)", "Guide", "globals.html"), ' \
'("6 Command Line Tools", "Guide", "commandline.html")')
db_conn.execute('DELETE FROM "searchIndex" WHERE "type" = "Module" AND ("name" = "pwn" OR "name" = "pwnlib")')
db_conn.commit()
finally:
db_conn.close()
return 0
return 0
parser = argparse.ArgumentParser()
parser.add_argument("--name", help="docset name", default="pwntools")
+12 -4
View File
@@ -1,8 +1,16 @@
paramiko
argparse
mako
pyelftools
sphinxcontrib-napoleon
sphinxcontrib-autoprogram
isort
paramiko>=1.15.2
mako>=1.0.0
pyelftools>=0.2.3
capstone
ropgadget>=5.3
pyserial>=2.7
requests>=2.5.1
pip>=6.0.8
tox>=1.8.1
pygments>=2.0
sphinx_rtd_theme
doc2dash
coveralls
+9
View File
@@ -0,0 +1,9 @@
.. testsetup:: *
from pwn import *
:mod:`pwnlib.adb` --- Android Debug Bridge
=====================================================
.. automodule:: pwnlib.adb
:members:
+1 -1
View File
@@ -1,7 +1,7 @@
.. testsetup:: *
import tempfile
import os
import subprocess
from pwnlib.context import context
from pwnlib.asm import *
from pwnlib import shellcraft
+12
View File
@@ -17,6 +17,9 @@ pwntools comes with a handful of useful command-line utilities which serve as wr
.. autoprogram:: pwnlib.commandline.asm:parser
:prog: asm
.. autoprogram:: pwnlib.commandline.checksec:parser
:prog: checksec
.. autoprogram:: pwnlib.commandline.constgrep:p
:prog: constgrep
@@ -32,12 +35,21 @@ pwntools comes with a handful of useful command-line utilities which serve as wr
.. autoprogram:: pwnlib.commandline.elfpatch:p
:prog: elfpatch
.. autoprogram:: pwnlib.commandline.errno:parser
:prog: errno
.. autoprogram:: pwnlib.commandline.hex:parser
:prog: hex
.. autoprogram:: pwnlib.commandline.phd:parser
:prog: phd
.. autoprogram:: pwnlib.commandline.pwnstrip:p
:prog: pwnstrip
.. autoprogram:: pwnlib.commandline.scramble:parser
:prog: scramble
.. autoprogram:: pwnlib.commandline.shellcraft:p
:prog: shellcraft
+12 -7
View File
@@ -22,6 +22,8 @@ build_dash = tags.has('dash')
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('../..'))
import pwnlib
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
@@ -43,12 +45,16 @@ extensions = [
]
doctest_global_setup = '''
import pwnlib, sys
import sys, os
os.environ['PWNLIB_NOTERM'] = '1'
os.environ['PWNLIB_RANDOMIZE'] = '0'
import pwnlib
pwnlib.context.context.reset_local()
pwnlib.context.ContextType.defaults['log_level'] = 'ERROR'
pwnlib.context.ContextType.defaults['randomize'] = False
pwnlib.term.text.when = 'never'
pwnlib.log.install_default_handler()
pwnlib.log.console.stream = sys.stdout
pwnlib.log.rootlogger.setLevel(1)
'''
autodoc_member_order = 'alphabetical'
@@ -69,14 +75,13 @@ master_doc = 'index'
# General information about the project.
project = u'pwntools'
copyright = u'2014, Gallopsled et al'
copyright = u'2015, Zach Riggle'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
import pwnlib
release = pwnlib.__version__
version = release.rsplit('.', 1)[0]
@@ -212,7 +217,7 @@ latex_elements = {
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'pwntools.tex', u'pwntools Documentation',
u'Gallopsled et al', 'manual'),
u'2015, Zach Riggle', 'manual'),
]
intersphinx_mapping = {'python': ('https://docs.python.org/2.7', None),
@@ -245,7 +250,7 @@ intersphinx_mapping = {'python': ('https://docs.python.org/2.7', None),
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'pwntools', u'pwntools Documentation',
[u'Gallopsled et al'], 1)
[u'2015, Zach Riggle'], 1)
]
# If true, show URL addresses after external links.
@@ -259,7 +264,7 @@ man_pages = [
# dir menu entry, description, category)
texinfo_documents = [
('index', 'pwntools', u'pwntools Documentation',
u'Gallopsled et al', 'pwntools', 'One line description of project.',
u'', 'pwntools', 'CTF exploit writing toolkit.',
'Miscellaneous'),
]
+3 -4
View File
@@ -1,9 +1,8 @@
.. testsetup:: *
import pwnlib
from pwnlib.context import context
import threading, logging
from pwn import *
import logging
log = pwnlib.log.getLogger('pwnlib.context')
:mod:`pwnlib.context` --- Setting runtime variables
=====================================================
+25
View File
@@ -0,0 +1,25 @@
.. testsetup:: *
from pwn import *
:mod:`pwnlib.encoders` --- Encoding Shellcode
===============================================
.. automodule:: pwnlib.encoders
:members:
.. automodule:: pwnlib.encoders.encoder
:members:
.. automodule:: pwnlib.encoders.amd64
:members:
.. automodule:: pwnlib.encoders.arm
:members:
.. automodule:: pwnlib.encoders.i386
:members:
.. automodule:: pwnlib.encoders.i386.xor
:members:
+10
View File
@@ -0,0 +1,10 @@
.. testsetup:: *
from pwn import *
import tempfile
:mod:`pwnlib.fmtstr` --- Format string bug exploitation tools
=============================================================
.. automodule:: pwnlib.fmtstr
:members:
+10
View File
@@ -28,19 +28,24 @@ Each of the ``pwntools`` modules is documented here.
:maxdepth: 1
:glob:
adb
asm
atexception
atexit
constants
context
dynelf
encoders
elf
exception
fmtstr
gdb
log
memleak
replacements
rop
rop/*
runner
shellcraft
shellcraft/*
term
@@ -51,6 +56,11 @@ Each of the ``pwntools`` modules is documented here.
useragents
util/*
.. toctree::
:hidden:
testexample
.. only:: not dash
Indices and tables
+7 -6
View File
@@ -20,21 +20,22 @@ following system libraries installed.
Released Version
-----------------
Pwntools is available as a ``pip`` package.
pwntools is available as a ``pip`` package.
.. code-block:: bash
$ apt-get install python2.7 python2.7-dev python-pip
$ pip install pwntools
$ pip install --upgrade git+https://github.com/Gallopsled/pwntools.git
Latest Version
Development
--------------
Alternatively if you prefer to use the latest version from the
repository, pip can install directly from github.
If you are hacking on Pwntools locally, you'll want to do something like this:
.. code-block:: bash
$ pip install git+https://github.com/Gallopsled/pwntools#egg=pwntools
$ git clone https://github.com/Gallopsled/pwntools
$ cd pwntools
$ pip install -e .
.. _Ubuntu: https://launchpad.net/~pwntools/+archive/ubuntu/binutils
+1 -3
View File
@@ -58,8 +58,6 @@ OSes, ``binutils`` is simple to build by hand.
gpg --keyserver keys.gnupg.net --recv-keys 4AE55E93
gpg --verify binutils-$V.tar.gz.sig
rm -rf binutils-*
tar xf binutils-$V.tar.gz
mkdir binutils-build
@@ -79,6 +77,6 @@ OSes, ``binutils`` is simple to build by hand.
MAKE=gmake
hash gmake || MAKE=make
$MAKE -j
$MAKE -j clean all
sudo $MAKE install
+3 -3
View File
@@ -67,7 +67,7 @@ actually **interact** with processes.
There's even an SSH module for when you've got to SSH into a box to perform
a local/setuid exploit with :mod:`pwnlib.tubes.ssh`. You can quickly spawn
processes and grab the output, or spawn a process and interact iwth it like
processes and grab the output, or spawn a process and interact with it like
a ``process`` tube.
::
@@ -170,14 +170,14 @@ But if you do, it's easy to suss out!
5: eb f9 jmp 0x0
However, you shouldn't even need to write your own shellcode most of the
time! Pwntools comes with the :mod:`pwnlib.shellcraft` module, which is
time! pwntools comes with the :mod:`pwnlib.shellcraft` module, which is
loaded with useful time-saving shellcodes.
Let's say that we want to `setreuid(getuid(), getuid())` followed by `dup`ing
file descriptor 4 to `stdin`, `stdout`, and `stderr`, and then pop a shell!
>>> asm(shellcraft.setreuid() + shellcraft.dupsh(4)).encode('hex')
'6a3158cd8089c389d96a4658cd806a045b6a0359496a3f58cd8075f86a68682f2f2f73682f62696e89e331c96a0b5899cd80'
'6a3158cd8089c36a465889d9cd806a045b6a0359496a3f58cd8075f86a68682f2f2f73682f62696e6a0b5889e331c999cd80'
Misc Tools
+8 -5
View File
@@ -1,11 +1,14 @@
.. testsetup:: *
from pwnlib.elf import *
from pwnlib.rop import *
from pwnlib.util.misc import which
from pwn import *
:mod:`pwnlib.rop` --- Return Oriented Programming
=================================================
.. automodule:: pwnlib.rop
:members:
Submodules
----------
.. toctree::
:glob:
rop/*
+9
View File
@@ -0,0 +1,9 @@
.. testsetup:: *
from pwn import *
:mod:`pwnlib.rop.rop` --- Return Oriented Programming
==========================================================
.. automodule:: pwnlib.rop.rop
:members:
+9
View File
@@ -0,0 +1,9 @@
.. testsetup:: *
from pwn import *
:mod:`pwnlib.rop.srop` --- Sigreturn Oriented Programming
==========================================================
.. automodule:: pwnlib.rop.srop
:members:
+9
View File
@@ -0,0 +1,9 @@
.. testsetup:: *
from pwn import *
:mod:`pwnlib.runner` --- Running Shellcode
===========================================
.. automodule:: pwnlib.runner
:members:
+1
View File
@@ -1,6 +1,7 @@
.. testsetup:: *
from pwn import *
context.clear(arch='amd64')
:mod:`pwnlib.shellcraft.amd64` --- Shellcode for AMD64
===========================================================
+1
View File
@@ -1,6 +1,7 @@
.. testsetup:: *
from pwn import *
context.clear(arch='arm')
:mod:`pwnlib.shellcraft.arm` --- Shellcode for ARM
===========================================================
+1
View File
@@ -1,6 +1,7 @@
.. testsetup:: *
from pwn import *
context.clear(arch='i386')
:mod:`pwnlib.shellcraft.i386` --- Shellcode for Intel 80386
===========================================================
+1
View File
@@ -1,6 +1,7 @@
.. testsetup:: *
from pwn import *
context.clear(arch='thumb')
:mod:`pwnlib.shellcraft.thumb` --- Shellcode for Thumb Mode
===========================================================
+10
View File
@@ -0,0 +1,10 @@
.. testsetup:: *
import os
from pwnlib.testexample import add
:mod:`pwnlib.testexample` --- Example Test Module
==================================================
.. automodule:: pwnlib.testexample
:members:
+1 -1
View File
@@ -5,7 +5,7 @@
import time
:mod:`pwnlib.timeout` --- Timeout handling
========================================
============================================
.. automodule:: pwnlib.timeout
:members:
+1 -1
View File
@@ -8,5 +8,5 @@
.. automodule:: pwnlib.tubes.process
.. autoclass:: pwnlib.tubes.process.process
:members: kill, poll, communicate
:members:
:show-inheritance:
+22
View File
@@ -0,0 +1,22 @@
from pwn import *
# Tell pwntools that the target is an Android device
context.os='android'
context.arch='aarch64' # or 'arm'
# Optionally, set the remote ADB server address
context.adb_host='172.16.110.1'
# Wait for a device to become available
print adb.wait_for_device()
# Who am I?
print adb.process('id').recvall().strip()
# Interactive sessions!
io = adb.shell()
io.sendline('echo Hello, world; exit')
print io.recvall().replace('\r\n', '\n').strip()
# Debugging!
gdb.debug('sh').interactive()
+1
View File
@@ -3,6 +3,7 @@ Example showing the interface to `pwnlib.asm.asm` and `pwnlib.shellcraft`.
"""
from pwn import *
context(arch='i386', os='linux')
shellcode = shellcraft.i386_to_amd64()
-1
View File
@@ -26,4 +26,3 @@ atexit.register(r.clean_and_log)
while True:
line = r.recvline()
print re.findall('^prefix (\S+)$', line)[0]
+1
View File
@@ -4,6 +4,7 @@ Script to generate README.md
from pwn import *
out = '''# Examples
While these examples should all work, they are not very representative of
the pwntools project.
+2 -2
View File
@@ -5,8 +5,8 @@ off some proof-of-concepts.
"""
from pwn import *
from pwnlib.term.completer import LongestPrefixCompleter, \
PathCompleter
from pwnlib.term.completer import LongestPrefixCompleter
from pwnlib.term.completer import PathCompleter
c1 = LongestPrefixCompleter([
'foobar',
+2 -1
View File
@@ -3,9 +3,10 @@ Simple example showing how to use the remote
gdb debugging features available in pwntools.
"""
from pwn import *
import getpass
from pwn import *
s = ssh(getpass.getuser(), '127.0.0.1', port = 22, keyfile = "~/.ssh/id_rsa")
c = gdb.ssh_gdb(s, '/bin/sh', execute = '''
p/x $pc
+58
View File
@@ -0,0 +1,58 @@
############################################################
# Dockerfile to build Pwntools container
# Based on Ubuntu
############################################################
FROM ubuntu:trusty
MAINTAINER Maintainer Zach Riggle
RUN apt-get update && apt-get install -y software-properties-common
RUN apt-add-repository --yes ppa:pwntools/binutils
RUN apt-get update
RUN apt-get install -y \
binutils \
binutils-aarch64-linux-gnu \
binutils-arm-linux-gnueabihf \
curl \
gdb \
gdbserver \
gdb-multiarch \
git \
libc6-i386 \
libc6-arm64-cross \
libc6-armhf-cross \
libc6-dev-i386 \
libffi-dev \
libglib2.0-dev \
libncurses5-dev \
libncursesw5-dev \
ltrace \
python-dev \
python-pip \
python3-pip \
python2.7 \
qemu \
qemu-user-static \
strace \
tmux \
wget
RUN pip install --upgrade ipython
RUN useradd -m zerocool
RUN usermod -U zerocool
RUN mkdir -p /etc/qemu-binfmt
RUN ln -s /usr/aarch64-linux-gnu /etc/qemu-binfmt/aarch64
RUN ln -s /usr/arm-linux-gnueabihf /etc/qemu-binfmt/arm
RUN pip install --upgrade pip pycparser psutil python-ptrace
RUN pip3 install --upgrade pip pycparser psutil python-ptrace
RUN pip install --upgrade git+https://github.com/Gallopsled/pwntools.git
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN chown -R zerocool.zerocool /home/zerocool
RUN chsh -s /bin/bash zerocool
+19
View File
@@ -0,0 +1,19 @@
# Pwntools Mako Assembly Syntax Highlighting
This should work for TextMate and anything that's compatible (e.g. Sublime Text).
![screenshot](screenshot.png)
## Installation
### Sublime Text
Copy the `tmLanguage` files into the `Packages/User` folder in your Sublime Text configuration folder.
These folders are located at the paths shown below. Replace `2` with `3` if you're a ST3 user.
- OS X: `~/Library/Application Support/Sublime Text 2`
- Windows: `%APPDATA%\Sublime Text 2`
- Linux: `~/.config/sublime-text-2`
Open a `.asm` file, and choose `View > Syntax > Open All ... > Pwntools ...`.
+209
View File
@@ -0,0 +1,209 @@
# [PackageDev] target_format: plist, ext: tmLanguage
---
name: Pwntools Mako ASM
scopeName: source.pwntools
fileTypes: ['.asm']
uuid: 19bbf78d-4ad8-4385-bb20-5bde8df453bf
patterns:
- comment: x86 instruction
name: support.function.mnemonic.x86.all
match: \b(?i)(v)?(aaa|aad|aam|aas|adc|add|addpd|addps|addsd|addss|addsubpd|addsubps|aesdec|aesdeclast|aesenc|aesenclast|aesimc|aeskeygenassist|and|andpd|andps|andnpd|andnps|arpl|blendpd|bmi|blendps|blendvpd|blendvps|bound|bsf|bsr|bswap|bt|btc|btr|bts|cbw|cwde|cdqe|clc|cld|cflush|clts|cmc|cmov(n?e|ge?|ae?|le?|be?|n?o|n?z)|cmp|cmppd|cmpps|cmps|cnpsb|cmpsw|cmpsd|cmpsq|cmpss|cmpxchg|cmpxchg8b|cmpxchg16b|comisd|comiss|cpuid|crc32|cvtdq2pd|cvtdq2ps|cvtpd2dq|cvtpd2pi|cvtpd2ps|cvtpi2pd|cvtpi2ps|cvtps2dq|cvtps2pd|cvtps2pi|cvtsd2si|cvtsd2ss|cvts2sd|cvtsi2ss|cvtss2sd|cvtss2si|cvttpd2dq|cvtpd2pi|cvttps2dq|cvttps2pi|cvttps2dq|cvttps2pi|cvttsd2si|cvttss2si|cwd|cdq|cqo|daa|das|dec|div|divpd|divps|divsd|divss|dppd|dpps|emms|enter|extractps|f2xm1|fabs|fadd|faddp|fiadd|fbld|fbstp|fchs|fclex|fnclex|fcmov(n?e|ge?|ae?|le?|be?|n?o|n?z)|fcom|fcmop|fcompp|fcomi|fcomip|fucomi|fucomip|fcos|fdecstp|fdiv|fdivp|fidiv|fdivr|fdivrp|fidivr|ffree|ficom|ficomp|fild|fincstp|finit|fnint|fist|fistp|fisttp|fld|fld1|fldl2t|fldl2e|fldpi|fldlg2|fldln2|fldz|fldcw|fldenv|fmul|fmulp|fimul|fnop|fpatan|fprem|fprem1|fptan|frndint|frstor|fsave|fnsave|fscale|fsin|fsincos|fsqrt|fst|fstp|fstcw|fnstcw|fstenv|fnstenv|fsts(w?)|fnstsw|fsub|fsubp|fisub|fsubr|fsubrp|fisubr|ftst|fucom|fucomp|fucompp|fxam|fxch|fxrstor|fxsave|fxtract|fyl2x|fyl2xp1|haddpd|haddps|husbpd|hsubps|idiv|imul|in|inc|ins|insb|insw|insd|insertps|int|into|invd|invplg|invpcid|iret|iretd|iretq|lahf|lar|lddqu|ldmxcsr|lds|les|lfs|lgs|lss|lea|leave|lfence|lgdt|lidt|llgdt|lmsw|lock|lods|lodsb|lodsw|lodsd|lodsq|lsl|ltr|maskmovdqu|maskmovq|maxpd|maxps|maxsd|maxss|mfence|minpd|minps|minsd|minss|monitor|mov|movapd|movaps|movbe|movd|movq|movddup|movdqa|movdqu|movq2q|movhlps|movhpd|movhps|movlhps|movlpd|movlps|movmskpd|movmskps|movntdqa|movntdq|movnti|movntpd|movntps|movntq|movq|movq2dq|movs|movsb|movsw|movsd|movsq|movsd|movshdup|movsldup|movss|movsx|movsxd|movupd|movups|movzx|mpsadbw|mul|mulpd|mulps|mulsd|mulss|mwait|neg|not|or|orpd|orps|out|outs|outsb|outsw|outsd|pabsb|pabsw|pabsd|packsswb|packssdw|packusdw|packuswbpaddb|paddw|paddd|paddq|paddsb|paddsw|paddusb|paddusw|palignr|pand|pandn|pause|pavgb|pavgw|pblendvb|pblendw|pclmulqdq|pcmpeqb|pcmpeqw|pcmpeqd|pcmpeqq|pcmpestri|pcmpestrm|pcmptb|pcmptgw|pcmpgtd|pcmpgtq|pcmpistri|pcmpisrm|pdep|pext|pextrb|pextrd|pextrq|pextrw|phaddw|phaddd|phaddsw|phinposuw|phsubw|phsubd|phsubsw|pinsrb|pinsrd|pinsrq|pinsrw|pmaddubsw|pmadddwd|pmaxsb|pmaxsd|pmaxsw|pmaxsw|pmaxub|pmaxud|pmaxuw|pminsb|pminsd|pminsw|pminub|pminud|pminuw|pmovmskb|pmovsx|pmovzx|pmuldq|pmulhrsw|pmulhuw|pmulhw|pmulld|pmullw|pmuludw|pop|popa|popad|popcnt|popf|popfd|popfq|por|prefetch|psadbw|pshufb|pshufd|pshufhw|pshuflw|pshufw|psignb|psignw|psignd|pslldq|psllw|pslld|psllq|psraw|psrad|psrldq|psrlw|psrld|psrlq|psubb|psubw|psubd|psubq|psubsb|psubsw|psubusb|psubusw|test|ptest|punpckhbw|punpckhwd|punpckhdq|punpckhddq|punpcklbw|punpcklwd|punpckldq|punpckldqd|push|pusha|pushad|pushf|pushfd|pxor|prcl|rcr|rol|ror|rcpps|rcpss|rdfsbase|rdgsbase|rdmsr|rdpmc|rdrand|rdtsc|rdtscp|rep|repe|repz|repne|repnz|roundpd|roundps|roundsd|roundss|rsm|rsqrps|rsqrtss|sahf|sal|sar|shl|shr|sbb|scas|scasb|scasw|scasd|set(n?e|ge?|ae?|le?|be?|n?o|n?z)|sfence|sgdt|shld|shrd|shufpd|shufps|sidt|sldt|smsw|sqrtpd|sqrtps|sqrtsd|sqrtss|stc|std|stmxcsr|stos|stosb|stosw|stosd|stosq|str|sub|subpd|subps|subsd|subss|swapgs|syscall|sysenter|sysexit|sysret|teset|ucomisd|ucomiss|ud2|unpckhpd|unpckhps|unpcklpd|unpcklps|vbroadcast|vcvtph2ps|vcvtp2sph|verr|verw|vextractf128|vinsertf128|vmaskmov|vpermilpd|vpermilps|vperm2f128|vtestpd|vzeroall|vzeroupper|wait|fwait|wbinvd|wrfsbase|wrgsbase|wrmsr|xadd|xchg|xgetbv|xlat|xlatb|xor|xorpd|xorps|xrstor|xsave|xsaveopt|xsetbv|lzcnt|extrq|insertq|movntsd|movntss|vfmaddpd|vfmaddps|vfmaddsd|vfmaddss|vfmaddsubbpd|vfmaddsubps|vfmsubaddpd|vfmsubaddps|vfmsubpd|vfmsubps|vfmsubsd|vfnmaddpd|vfnmaddps|vfnmaddsd|vfnmaddss|vfnmsubpd|vfnmusbps|vfnmusbsd|vfnmusbss|vbroadcastss|vbroadcastsd|vbroadcastf128|vmaskmovps|vmaskmovpd|cvt|xor|cli|sti|hlt|nop|lock|wait|enter|leave|ret|loop(n?e|n?z)?|call|j(mp|n?e|n?ge?|n?ae?|le?|be?|n?o|n?z|n?c|n?p|n?b))\b
- comment: ARM instruction
name: support.function.mnemonic.arm.arithmetic
match: >
(?x)\b((?i)
( (bf(c|i)|(u|s)bfx|(u|s)xta?(h|b)?)
| (v(add|cvt|sub|mov|trn|cmp|div|qdmulh|mrs|mul|ld1|qadd|qshrun|st[1234]|addw|mull|mlal|rshrn|swp|qmovun)|qmovun)(\.([isup]?8|[isupf]?16|[isuf]?32|[isu]?64))*
| (mul|mla|mull|smlabb)
| (mov(w|t))
| rev(8|16)?
| (pld|adr|adrl|vswp)
| bkpt
)?(?-i))?\b
- comment: ARM instruction
name: support.function.mnemonic.arm.memory
match: >
(?x)\b((?i)(
swi|svc|wfi|
dmb | clrex | dsb | isb |
v(ldr|str|push|pop) |
(push|pop) |
(st|ld)(
p |
r(ex|s?(h|b)|d)? |
m(
(f|e)(d|a) |
(d|i)(b|a)
)?
) |
b(l|x|lx|lr|r)? |
(i|e)?ret|
b\.(eq|ne|hs|cs|lo|cc|mi|pl|vs|vc|hi|ls|ge|lt|gt|le|al|nv)+ |
(c|t)?bn?z|
)+(ne|eq|cs|hs|cc|lo|mi|pl|vs|vc|hi|ls|lt|le|gt|ge|al)?(?-i))\b
- comment: ARM instruction
name: meta.preprocessor.c.include
match: >
\b((?i)(def(b|w|s)|equ|(include|get)(\s+([a-zA-Z_]+[0-9a-zA-Z_]*|[0-9]+[a-zA-Z_]+[0-9a-zA-Z_]*?)\.s)?)?(?-i))\b
- comment: ARM instruction
name: comment.nop
match: >
\b((?i)nop(ne|eq|cs|hs|cc|lo|mi|pl|vs|vc|hi|ls|lt|le|gt|ge|al)?(?-i))?\b
- comment: Comment Block
begin: /\*
end: \*/
name: comment.block
- comment: Directive
name: keyword.control.directive
match: \.(?i)(globl|global|macro|endm|purgem|if|elseif|else|endif|section|text|arm|align|balign|irp|rept|endr|req|unreq|error|short|func|endfunc|hidden|type|fpu|arch|code|altmacro|object_arch|word|int|string)(?-i)\b
- comment: ARM register
name: storage.other.register.arm
match: \b((?i)\$?([xw][0-9]|[xw]1[0-9]||[xw]2[0-9]|[wx]30|wzr|xzr|wsp|fpsr|fpcr|[rcp]1[0-5]|[rcp][0-9]|a[1-4]|v[1-8]|sl|sb|fp|ip|sp|lr|(c|s)psr(_c)?|pc|[sd]3[0-1]|[sd][12][0-9]|[sd][0-9]|fpsid|fpscr|fpexc|q3[0-1]|q2[0-9]|q1[0-9]|q[0-9]|APSR_nzcv|sy)!?(?-i))?\b
- comment: x86 register
name: storage.other.register.x86
match: \b((?i)(al|ah|ax|eax|rax|bl|bh|bx|ebx|rbx|cl|ch|cx|ecx|rcx|dl|dh|dx|edx|rdx|sil|si|esi|rsi|di|di|edi|rdi|bpl|bp|ebp|rbp|sp|esp|rsp|cs|ds|ss|es|fs|gs|ip|eip|rip|flags|eflags|rflags|r8|r9|r10|r11|r12|r13|r14|r15|r8d|r9d|r10d|r11d|r12d|r13d|r14d|r15d|r8w|r9w|r10w|r11w|r12w|r13w|r14w|r15w|r8l|r9l|r10l|r11l|r12l|r13l|r14l|r15l|st0|st1|st2|st3|st4|st5|st6|st7|mm0|mm1|mm2|mm3|mm4|mm5|mm6|mm7|xmm0|xmm1|xmm2|xmm3|xmm4|xmm5|xmm6|xmm7|xmm8|xmm9|xmm10|xmm11|xmm12|xmm13|xmm14|xmm15|xmm16|xmm17|xmm18|xmm19|xmm20|xmm21|xmm22|xmm23|xmm24|xmm25|xmm26|xmm27|xmm28|xmm29|xmm30|xmm31|ymm0|ymm1|ymm2|ymm3|ymm4|ymm5|ymm6|ymm7|ymm8|ymm9|ymm10|ymm11|ymm12|ymm13|ymm14|ymm15|ymm16|ymm17|ymm18|ymm19|ymm20|ymm21|ymm22|ymm23|ymm24|ymm25|ymm26|ymm27|ymm28|ymm29|ymm30|ymm31|zmm0|zmm1|zmm2|zmm3|zmm4|zmm5|zmm6|zmm7|zmm8|zmm9|zmm10|zmm11|zmm12|zmm13|zmm14|zmm15|zmm16|zmm17|zmm18|zmm19|zmm20|zmm21|zmm22|zmm23|zmm24|zmm25|zmm26|zmm27|zmm28|zmm29|zmm30|zmm31|cr0|cr2|cr3|cr4|gdtr|ldtr|idtr|dr0|dr1|dr2|dr3|dr4|dr5|dr6|dr7|msr)!?(?-i))?\b
- comment: SPARC register
name: storage.other.register.sparc
match: \b((?i)\$?([gloi][0-9])!?(?-i))?\b
- comment: MIPS register
name: storage.other.register.mips
match: \b((?i)\$?(r[0-3][0-9]|v[0-2]|a[0-4]|t[0-8]|s[0-9]|t([89]|10|k[0-2]))!?(?-i))?\b
- comment: Numeric Hex
name: constant.numeric.hex
match: (\b|\s+)(\#)?-?(0x|&amp;)[0-9a-fA-F_]+\b
- comment: Numeric Literal
name: constant.numeric.literal
match: (\b|\s+)\#-?[0-9a-zA-Z_]+\b
- comment: Numeric Decimal
name: constant.numeric.dec
match: (\b|\s+)[0-9]+\b
- comment: Label
name: entity.name.tag
match: ([\w${}]+[:])
- comment: Inline Python
name: pwntools.raw.block.python
begin: (<%\s)
end: (%>)
beginCaptures:
'1': {name: 'keyword.control'}
endCaptures:
'1': {name: 'keyword.control'}
patterns:
- {include: source.python}
- comment: Inline Docstring
begin: (<%(\S+)>)
end: (</%(\2)>)
beginCaptures:
'1': {name: 'keyword.control'}
endCaptures:
'1': {name: 'keyword.control'}
patterns:
- {include: comment.block}
- comment: Mako Tag
name: source.mako.tag
begin: (<%\w+\s)
end: (/>)
beginCaptures:
'1': {name: 'keyword.control'}
endCaptures:
'1': {name: 'keyword.control'}
patterns:
- {include: comment.block}
- comment: Mako Substitution
name: source.mako.expression
begin: (\${)
end: (})
beginCaptures:
'1': {name: 'keyword.control'}
endCaptures:
'1': {name: 'keyword.control'}
patterns:
- {include: source.python}
- comment: Mako Comment
match: (^##(.*)$)
name: comment.line.mako
- comment: Mako Directive
begin: ^\s*(%)(\s*((endfor)|(endif)|(endwhile)))?
end: $
beginCaptures:
'1': {name: 'keyword.control'}
'2': {name: 'keyword.control'}
patterns:
- {include: source.python}
name: source.doc.python.mako.controlline
# <key>begin</key>
# <string>^(#)</string>
# <key>beginCaptures</key>
# <dict>
# <key>1</key>
# <dict>
# <key>name</key>
# <string>keyword.control</string>
# </dict>
# </dict>
# <key>end</key>
# <string>$</string>
# <key>name</key>
# <string>source.python.mako.line</string>
# <key>patterns</key>
# <array>
# <dict>
# <key>include</key>
# <string>comment.block</string>
# </dict>
# </array>
# </dict>
# <key>begin</key>
# <string>^\s*(%)(\s*((endfor)|(endif)|(endwhile)))?</string>
# <key>beginCaptures</key>
# <dict>
# <key>1</key>
# <dict>
# <key>name</key>
# <string>keyword.control</string>
# </dict>
# <key>2</key>
# <dict>
# <key>name</key>
# <string>keyword.control</string>
# </dict>
# </dict>
# <key>begin</key>
# <string>(&lt;%\s)</string>
# <key>captures</key>
# <dict>
# <key>1</key>
# <dict>
# <key>name</key>
# <string>keyword.control</string>
# </dict>
# </dict>
# <key>end</key>
# <string>(%&gt;)</string>
# <key>name</key>
# <string>source.mako.substitution</string>
# <key>patterns</key>
# <array>
# <dict>
# <key>include</key>
# <string>source.python</string>
# </dict>
# </array>
# match: "(
# (bf(c|i)|(u|s)bfx|(u|s)xta?(h|b)?) |
# (v(add|cvt|sub|mov|trn|cmp|div|qdmulh|mrs|mul|ld1|qadd|qshrun|st[1234]|addw|mull|mlal|rshrn|swp|qmovun)|qmovun)(\.([isup]?8|[isupf]?16|[isuf]?32|[isu]?64))* |
# (and|m(rs|sr)|eor|sub|rsb|add|adc|sbc|rsc|tst|teq|cmp|cmn|orr|mov|bic|mvn |
# (neg) |
# (lsr|lsl|ror|asr)
# )s? |
# (mul|mla|mull|smlabb) |
# (mov(w|t)) |
# rev(8|16)? |
# (pld|adr|adrl|vswp)
# )
+337
View File
@@ -0,0 +1,337 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>.asm</string>
</array>
<key>name</key>
<string>Pwntools Mako ASM</string>
<key>patterns</key>
<array>
<dict>
<key>comment</key>
<string>x86 instruction</string>
<key>match</key>
<string>\b(?i)(v)?(aaa|aad|aam|aas|adc|add|addpd|addps|addsd|addss|addsubpd|addsubps|aesdec|aesdeclast|aesenc|aesenclast|aesimc|aeskeygenassist|and|andpd|andps|andnpd|andnps|arpl|blendpd|bmi|blendps|blendvpd|blendvps|bound|bsf|bsr|bswap|bt|btc|btr|bts|cbw|cwde|cdqe|clc|cld|cflush|clts|cmc|cmov(n?e|ge?|ae?|le?|be?|n?o|n?z)|cmp|cmppd|cmpps|cmps|cnpsb|cmpsw|cmpsd|cmpsq|cmpss|cmpxchg|cmpxchg8b|cmpxchg16b|comisd|comiss|cpuid|crc32|cvtdq2pd|cvtdq2ps|cvtpd2dq|cvtpd2pi|cvtpd2ps|cvtpi2pd|cvtpi2ps|cvtps2dq|cvtps2pd|cvtps2pi|cvtsd2si|cvtsd2ss|cvts2sd|cvtsi2ss|cvtss2sd|cvtss2si|cvttpd2dq|cvtpd2pi|cvttps2dq|cvttps2pi|cvttps2dq|cvttps2pi|cvttsd2si|cvttss2si|cwd|cdq|cqo|daa|das|dec|div|divpd|divps|divsd|divss|dppd|dpps|emms|enter|extractps|f2xm1|fabs|fadd|faddp|fiadd|fbld|fbstp|fchs|fclex|fnclex|fcmov(n?e|ge?|ae?|le?|be?|n?o|n?z)|fcom|fcmop|fcompp|fcomi|fcomip|fucomi|fucomip|fcos|fdecstp|fdiv|fdivp|fidiv|fdivr|fdivrp|fidivr|ffree|ficom|ficomp|fild|fincstp|finit|fnint|fist|fistp|fisttp|fld|fld1|fldl2t|fldl2e|fldpi|fldlg2|fldln2|fldz|fldcw|fldenv|fmul|fmulp|fimul|fnop|fpatan|fprem|fprem1|fptan|frndint|frstor|fsave|fnsave|fscale|fsin|fsincos|fsqrt|fst|fstp|fstcw|fnstcw|fstenv|fnstenv|fsts(w?)|fnstsw|fsub|fsubp|fisub|fsubr|fsubrp|fisubr|ftst|fucom|fucomp|fucompp|fxam|fxch|fxrstor|fxsave|fxtract|fyl2x|fyl2xp1|haddpd|haddps|husbpd|hsubps|idiv|imul|in|inc|ins|insb|insw|insd|insertps|int|into|invd|invplg|invpcid|iret|iretd|iretq|lahf|lar|lddqu|ldmxcsr|lds|les|lfs|lgs|lss|lea|leave|lfence|lgdt|lidt|llgdt|lmsw|lock|lods|lodsb|lodsw|lodsd|lodsq|lsl|ltr|maskmovdqu|maskmovq|maxpd|maxps|maxsd|maxss|mfence|minpd|minps|minsd|minss|monitor|mov|movapd|movaps|movbe|movd|movq|movddup|movdqa|movdqu|movq2q|movhlps|movhpd|movhps|movlhps|movlpd|movlps|movmskpd|movmskps|movntdqa|movntdq|movnti|movntpd|movntps|movntq|movq|movq2dq|movs|movsb|movsw|movsd|movsq|movsd|movshdup|movsldup|movss|movsx|movsxd|movupd|movups|movzx|mpsadbw|mul|mulpd|mulps|mulsd|mulss|mwait|neg|not|or|orpd|orps|out|outs|outsb|outsw|outsd|pabsb|pabsw|pabsd|packsswb|packssdw|packusdw|packuswbpaddb|paddw|paddd|paddq|paddsb|paddsw|paddusb|paddusw|palignr|pand|pandn|pause|pavgb|pavgw|pblendvb|pblendw|pclmulqdq|pcmpeqb|pcmpeqw|pcmpeqd|pcmpeqq|pcmpestri|pcmpestrm|pcmptb|pcmptgw|pcmpgtd|pcmpgtq|pcmpistri|pcmpisrm|pdep|pext|pextrb|pextrd|pextrq|pextrw|phaddw|phaddd|phaddsw|phinposuw|phsubw|phsubd|phsubsw|pinsrb|pinsrd|pinsrq|pinsrw|pmaddubsw|pmadddwd|pmaxsb|pmaxsd|pmaxsw|pmaxsw|pmaxub|pmaxud|pmaxuw|pminsb|pminsd|pminsw|pminub|pminud|pminuw|pmovmskb|pmovsx|pmovzx|pmuldq|pmulhrsw|pmulhuw|pmulhw|pmulld|pmullw|pmuludw|pop|popa|popad|popcnt|popf|popfd|popfq|por|prefetch|psadbw|pshufb|pshufd|pshufhw|pshuflw|pshufw|psignb|psignw|psignd|pslldq|psllw|pslld|psllq|psraw|psrad|psrldq|psrlw|psrld|psrlq|psubb|psubw|psubd|psubq|psubsb|psubsw|psubusb|psubusw|test|ptest|punpckhbw|punpckhwd|punpckhdq|punpckhddq|punpcklbw|punpcklwd|punpckldq|punpckldqd|push|pusha|pushad|pushf|pushfd|pxor|prcl|rcr|rol|ror|rcpps|rcpss|rdfsbase|rdgsbase|rdmsr|rdpmc|rdrand|rdtsc|rdtscp|rep|repe|repz|repne|repnz|roundpd|roundps|roundsd|roundss|rsm|rsqrps|rsqrtss|sahf|sal|sar|shl|shr|sbb|scas|scasb|scasw|scasd|set(n?e|ge?|ae?|le?|be?|n?o|n?z)|sfence|sgdt|shld|shrd|shufpd|shufps|sidt|sldt|smsw|sqrtpd|sqrtps|sqrtsd|sqrtss|stc|std|stmxcsr|stos|stosb|stosw|stosd|stosq|str|sub|subpd|subps|subsd|subss|swapgs|syscall|sysenter|sysexit|sysret|teset|ucomisd|ucomiss|ud2|unpckhpd|unpckhps|unpcklpd|unpcklps|vbroadcast|vcvtph2ps|vcvtp2sph|verr|verw|vextractf128|vinsertf128|vmaskmov|vpermilpd|vpermilps|vperm2f128|vtestpd|vzeroall|vzeroupper|wait|fwait|wbinvd|wrfsbase|wrgsbase|wrmsr|xadd|xchg|xgetbv|xlat|xlatb|xor|xorpd|xorps|xrstor|xsave|xsaveopt|xsetbv|lzcnt|extrq|insertq|movntsd|movntss|vfmaddpd|vfmaddps|vfmaddsd|vfmaddss|vfmaddsubbpd|vfmaddsubps|vfmsubaddpd|vfmsubaddps|vfmsubpd|vfmsubps|vfmsubsd|vfnmaddpd|vfnmaddps|vfnmaddsd|vfnmaddss|vfnmsubpd|vfnmusbps|vfnmusbsd|vfnmusbss|vbroadcastss|vbroadcastsd|vbroadcastf128|vmaskmovps|vmaskmovpd|cvt|xor|cli|sti|hlt|nop|lock|wait|enter|leave|ret|loop(n?e|n?z)?|call|j(mp|n?e|n?ge?|n?ae?|le?|be?|n?o|n?z|n?c|n?p|n?b))\b</string>
<key>name</key>
<string>support.function.mnemonic.x86.all</string>
</dict>
<dict>
<key>comment</key>
<string>ARM instruction</string>
<key>match</key>
<string>(?x)\b((?i) ( (bf(c|i)|(u|s)bfx|(u|s)xta?(h|b)?)
| (v(add|cvt|sub|mov|trn|cmp|div|qdmulh|mrs|mul|ld1|qadd|qshrun|st[1234]|addw|mull|mlal|rshrn|swp|qmovun)|qmovun)(\.([isup]?8|[isupf]?16|[isuf]?32|[isu]?64))*
| (mul|mla|mull|smlabb)
| (mov(w|t))
| rev(8|16)?
| (pld|adr|adrl|vswp)
| bkpt
)?(?-i))?\b
</string>
<key>name</key>
<string>support.function.mnemonic.arm.arithmetic</string>
</dict>
<dict>
<key>comment</key>
<string>ARM instruction</string>
<key>match</key>
<string>(?x)\b((?i)(
swi|svc|wfi|
dmb | clrex | dsb | isb |
v(ldr|str|push|pop) |
(push|pop) |
(st|ld)(
p |
r(ex|s?(h|b)|d)? |
m(
(f|e)(d|a) |
(d|i)(b|a)
)?
) |
b(l|x|lx|lr|r)? |
(i|e)?ret|
b\.(eq|ne|hs|cs|lo|cc|mi|pl|vs|vc|hi|ls|ge|lt|gt|le|al|nv)+ |
(c|t)?bn?z|
)+(ne|eq|cs|hs|cc|lo|mi|pl|vs|vc|hi|ls|lt|le|gt|ge|al)?(?-i))\b
</string>
<key>name</key>
<string>support.function.mnemonic.arm.memory</string>
</dict>
<dict>
<key>comment</key>
<string>ARM instruction</string>
<key>match</key>
<string>\b((?i)(def(b|w|s)|equ|(include|get)(\s+([a-zA-Z_]+[0-9a-zA-Z_]*|[0-9]+[a-zA-Z_]+[0-9a-zA-Z_]*?)\.s)?)?(?-i))\b
</string>
<key>name</key>
<string>meta.preprocessor.c.include</string>
</dict>
<dict>
<key>comment</key>
<string>ARM instruction</string>
<key>match</key>
<string>\b((?i)nop(ne|eq|cs|hs|cc|lo|mi|pl|vs|vc|hi|ls|lt|le|gt|ge|al)?(?-i))?\b
</string>
<key>name</key>
<string>comment.nop</string>
</dict>
<dict>
<key>begin</key>
<string>/\*</string>
<key>comment</key>
<string>Comment Block</string>
<key>end</key>
<string>\*/</string>
<key>name</key>
<string>comment.block</string>
</dict>
<dict>
<key>comment</key>
<string>Directive</string>
<key>match</key>
<string>\.(?i)(globl|global|macro|endm|purgem|if|elseif|else|endif|section|text|arm|align|balign|irp|rept|endr|req|unreq|error|short|func|endfunc|hidden|type|fpu|arch|code|altmacro|object_arch|word|int|string)(?-i)\b</string>
<key>name</key>
<string>keyword.control.directive</string>
</dict>
<dict>
<key>comment</key>
<string>ARM register</string>
<key>match</key>
<string>\b((?i)\$?([xw][0-9]|[xw]1[0-9]||[xw]2[0-9]|[wx]30|wzr|xzr|wsp|fpsr|fpcr|[rcp]1[0-5]|[rcp][0-9]|a[1-4]|v[1-8]|sl|sb|fp|ip|sp|lr|(c|s)psr(_c)?|pc|[sd]3[0-1]|[sd][12][0-9]|[sd][0-9]|fpsid|fpscr|fpexc|q3[0-1]|q2[0-9]|q1[0-9]|q[0-9]|APSR_nzcv|sy)!?(?-i))?\b</string>
<key>name</key>
<string>storage.other.register.arm</string>
</dict>
<dict>
<key>comment</key>
<string>x86 register</string>
<key>match</key>
<string>\b((?i)(al|ah|ax|eax|rax|bl|bh|bx|ebx|rbx|cl|ch|cx|ecx|rcx|dl|dh|dx|edx|rdx|sil|si|esi|rsi|di|di|edi|rdi|bpl|bp|ebp|rbp|sp|esp|rsp|cs|ds|ss|es|fs|gs|ip|eip|rip|flags|eflags|rflags|r8|r9|r10|r11|r12|r13|r14|r15|r8d|r9d|r10d|r11d|r12d|r13d|r14d|r15d|r8w|r9w|r10w|r11w|r12w|r13w|r14w|r15w|r8l|r9l|r10l|r11l|r12l|r13l|r14l|r15l|st0|st1|st2|st3|st4|st5|st6|st7|mm0|mm1|mm2|mm3|mm4|mm5|mm6|mm7|xmm0|xmm1|xmm2|xmm3|xmm4|xmm5|xmm6|xmm7|xmm8|xmm9|xmm10|xmm11|xmm12|xmm13|xmm14|xmm15|xmm16|xmm17|xmm18|xmm19|xmm20|xmm21|xmm22|xmm23|xmm24|xmm25|xmm26|xmm27|xmm28|xmm29|xmm30|xmm31|ymm0|ymm1|ymm2|ymm3|ymm4|ymm5|ymm6|ymm7|ymm8|ymm9|ymm10|ymm11|ymm12|ymm13|ymm14|ymm15|ymm16|ymm17|ymm18|ymm19|ymm20|ymm21|ymm22|ymm23|ymm24|ymm25|ymm26|ymm27|ymm28|ymm29|ymm30|ymm31|zmm0|zmm1|zmm2|zmm3|zmm4|zmm5|zmm6|zmm7|zmm8|zmm9|zmm10|zmm11|zmm12|zmm13|zmm14|zmm15|zmm16|zmm17|zmm18|zmm19|zmm20|zmm21|zmm22|zmm23|zmm24|zmm25|zmm26|zmm27|zmm28|zmm29|zmm30|zmm31|cr0|cr2|cr3|cr4|gdtr|ldtr|idtr|dr0|dr1|dr2|dr3|dr4|dr5|dr6|dr7|msr)!?(?-i))?\b</string>
<key>name</key>
<string>storage.other.register.x86</string>
</dict>
<dict>
<key>comment</key>
<string>SPARC register</string>
<key>match</key>
<string>\b((?i)\$?([gloi][0-9])!?(?-i))?\b</string>
<key>name</key>
<string>storage.other.register.sparc</string>
</dict>
<dict>
<key>comment</key>
<string>MIPS register</string>
<key>match</key>
<string>\b((?i)\$?(r[0-3][0-9]|v[0-2]|a[0-4]|t[0-8]|s[0-9]|t([89]|10|k[0-2]))!?(?-i))?\b</string>
<key>name</key>
<string>storage.other.register.mips</string>
</dict>
<dict>
<key>comment</key>
<string>Numeric Hex</string>
<key>match</key>
<string>(\b|\s+)(\#)?-?(0x|&amp;amp;)[0-9a-fA-F_]+\b</string>
<key>name</key>
<string>constant.numeric.hex</string>
</dict>
<dict>
<key>comment</key>
<string>Numeric Literal</string>
<key>match</key>
<string>(\b|\s+)\#-?[0-9a-zA-Z_]+\b</string>
<key>name</key>
<string>constant.numeric.literal</string>
</dict>
<dict>
<key>comment</key>
<string>Numeric Decimal</string>
<key>match</key>
<string>(\b|\s+)[0-9]+\b</string>
<key>name</key>
<string>constant.numeric.dec</string>
</dict>
<dict>
<key>comment</key>
<string>Label</string>
<key>match</key>
<string>([\w${}]+[:])</string>
<key>name</key>
<string>entity.name.tag</string>
</dict>
<dict>
<key>begin</key>
<string>(&lt;%\s)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control</string>
</dict>
</dict>
<key>comment</key>
<string>Inline Python</string>
<key>end</key>
<string>(%&gt;)</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control</string>
</dict>
</dict>
<key>name</key>
<string>pwntools.raw.block.python</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>source.python</string>
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>(&lt;%(\S+)&gt;)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control</string>
</dict>
</dict>
<key>comment</key>
<string>Inline Docstring</string>
<key>end</key>
<string>(&lt;/%(\2)&gt;)</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>comment.block</string>
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>(&lt;%\w+\s)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control</string>
</dict>
</dict>
<key>comment</key>
<string>Mako Tag</string>
<key>end</key>
<string>(/&gt;)</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control</string>
</dict>
</dict>
<key>name</key>
<string>source.mako.tag</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>comment.block</string>
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>(\${)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control</string>
</dict>
</dict>
<key>comment</key>
<string>Mako Substitution</string>
<key>end</key>
<string>(})</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control</string>
</dict>
</dict>
<key>name</key>
<string>source.mako.expression</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>source.python</string>
</dict>
</array>
</dict>
<dict>
<key>comment</key>
<string>Mako Comment</string>
<key>match</key>
<string>(^##(.*)$)</string>
<key>name</key>
<string>comment.line.mako</string>
</dict>
<dict>
<key>begin</key>
<string>^\s*(%)(\s*((endfor)|(endif)|(endwhile)))?</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.control</string>
</dict>
</dict>
<key>comment</key>
<string>Mako Directive</string>
<key>end</key>
<string>$</string>
<key>name</key>
<string>source.doc.python.mako.controlline</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>source.python</string>
</dict>
</array>
</dict>
</array>
<key>scopeName</key>
<string>source.pwntools</string>
<key>uuid</key>
<string>19bbf78d-4ad8-4385-bb20-5bde8df453bf</string>
</dict>
</plist>
Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

+10 -113
View File
@@ -1,119 +1,16 @@
# Promote useful stuff to toplevel
from .toplevel import *
pwnlib.args.initialize()
pwnlib.log.install_default_handler()
# look for special args in argv
def closure():
term_mode = True
import sys
if not hasattr(sys, 'argv'):
return
import string, collections
global args
args = collections.defaultdict(str)
def isident(s):
first = string.uppercase + '_'
body = string.digits + first
if not s:
return False
if s[0] not in first:
return False
if not all(c in body for c in s[1:]):
return False
return True
def asbool(s):
if s.lower() == 'true':
return True
elif s.lower() == 'false':
return False
elif s.isdigit():
return bool(int(s))
else:
raise ValueError('must be integer or boolean')
# parse environtment variables
for k, v in os.environ.items():
if not k.startswith('PWNLIB_'):
continue
k = k[7:]
if k == 'DEBUG':
if asbool(v):
context.log_level = 'DEBUG'
elif k == 'SILENT':
if asbool(v):
context.log_level = 'ERROR'
elif k == 'NOTERM':
if asbool(v):
term_mode = False
elif isident(k):
args[k] = v
# parse command line
# save a copy of argv for the log file header (see below)
argv = sys.argv[:]
for arg in argv:
if arg == 'DEBUG':
sys.argv.remove(arg)
context.log_level = 'DEBUG'
elif arg == 'SILENT':
sys.argv.remove(arg)
context.log_level = 'ERROR'
elif arg == 'NOTERM':
term_mode = False
elif arg.find('=') > 0:
k, v = arg.split('=', 1)
if not isident(k):
continue
sys.argv.remove(arg)
args[k] = v
if 'LOG_LEVEL' in args:
context.log_level = args['LOG_LEVEL']
if 'LOG_FILE' in args:
# install a file logger
import logging, time
modes = ('w', 'wb', 'a', 'ab')
filename = args['LOG_FILE']
mode = 'a'
# check if mode was specified as "[filename],[mode]"
if ',' in filename:
filename_, mode_ = filename.rsplit(',', 1)
if mode in modes:
filename = filename_
mode = mode_
# ISO 8601
dfmt = '%Y-%m-%dT%H:%M:%S'
# write a "header" to the file, which makes it easier to find the start
# of a session
with open(filename, mode) as fd:
lines = [
'=' * 78,
' Started at %s ' % time.strftime(dfmt),
' sys.argv = [',
]
for arg in argv:
lines.append(' %r,' % arg)
lines.append(' ]')
lines.append('=' * 78)
for line in lines:
fd.write('=%s=\n' % line.ljust(78))
# if the mode was 'w' or 'wb' we need to change it to 'a'/'ab' now so
# the logging module wont overwrite the header
mode = mode.replace('w', 'a')
# create a formatter and a handler and install them for the pwnlib root
# logger (i.e. 'pwnlib')
handler = logging.FileHandler(filename, mode)
fmt = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
formatter = logging.Formatter(fmt, dfmt)
handler.setFormatter(formatter)
logging.root.addHandler(handler)
# put the terminal in rawmode unless NOTERM was specified
if term_mode:
term.init()
# install a log handler and turn logging all the way up
import pwnlib.log as log
import logging
log.rootlogger.setLevel(logging.DEBUG)
log.install_default_handler()
log = pwnlib.log.getLogger('pwnlib.exploit')
args = pwnlib.args.args
closure()
del closure
if not platform.architecture()[0].startswith('64'):
"""Determines if the current Python interpreter is supported by Pwntools.
log = getLogger('pwnlib.exploit')
See Gallopsled/pwntools#518 for more information."""
log.warn_once('Pwntools does not support 32-bit Python. Use a 64-bit release.')
pwnlib.update.check_automatically()
+21 -10
View File
@@ -1,9 +1,11 @@
# Promote these modules, so that "from pwn import *" will let you access them
# Get all the modules from pwnlib
import collections
import logging
import math
import operator
import os
import re
import socks
import string
import struct
import subprocess
@@ -13,30 +15,29 @@ import threading
import time
import pwnlib
# Get all the modules from pwnlib
from pwnlib import *
# Promote functions from these modules to toplevel
from pwnlib.asm import asm
from pwnlib.asm import cpp
from pwnlib.asm import disasm
from pwnlib.asm import *
from pwnlib.context import Thread
from pwnlib.context import context
from pwnlib.dynelf import DynELF
from pwnlib.encoders import *
from pwnlib.elf import Core
from pwnlib.elf import ELF
from pwnlib.elf import load
from pwnlib.encoders import *
from pwnlib.exception import PwnlibException
from pwnlib.fmtstr import FmtStr
from pwnlib.fmtstr import FmtStr, fmtstr_payload
from pwnlib.log import getLogger
from pwnlib.memleak import MemLeak
from pwnlib.regsort import *
from pwnlib.replacements import *
from pwnlib.rop import ROP
from pwnlib.rop.srop import SigreturnFrame
from pwnlib.runner import *
from pwnlib.timeout import Timeout
from pwnlib.tubes.listen import listen
from pwnlib.tubes.process import process
from pwnlib.tubes.remote import remote
from pwnlib.tubes.remote import remote, tcp, udp
from pwnlib.tubes.serialtube import serialtube
from pwnlib.tubes.ssh import ssh
from pwnlib.tubes.tube import tube
@@ -48,6 +49,7 @@ from pwnlib.util import proc
from pwnlib.util import safeeval
from pwnlib.util.cyclic import *
from pwnlib.util.fiddling import *
from pwnlib.util.getdents import *
from pwnlib.util.hashes import *
from pwnlib.util.lists import *
from pwnlib.util.misc import *
@@ -56,6 +58,8 @@ from pwnlib.util.proc import pidof
from pwnlib.util.splash import *
from pwnlib.util.web import *
# Promote these modules, so that "from pwn import *" will let you access them
try:
import cPickle as pickle
except ImportError:
@@ -65,3 +69,10 @@ try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
error = log.error
warning = log.warning
warn = log.warning
info = log.info
debug = log.debug
success = log.success
+6 -1
View File
@@ -5,6 +5,7 @@ from .version import __version__
version = __version__
__all__ = [
'args',
'asm',
'atexception',
'atexit',
@@ -12,6 +13,7 @@ __all__ = [
'constants',
'context',
'dynelf',
'encoders',
'elf',
'exception',
'fmtstr',
@@ -23,12 +25,15 @@ __all__ = [
'regsort',
'replacements',
'rop',
'runner',
'shellcraft',
'term',
'tubes',
'ui',
'useragents',
'util'
'util',
'adb',
'update',
]
for module in __all__:
+106
View File
@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*-
from .context import LocalContext
from .context import context
class ABI(object):
"""
Encapsulates information about a calling convention.
"""
#: List or registers which should be filled with arguments before
#: spilling onto the stack.
register_arguments = []
#: Minimum alignment of the stack.
#: The value used is min(context.bytes, stack_alignment)
#: This is necessary as Windows x64 frames must be 32-byte aligned.
#: "Alignment" is considered with respect to the last argument on the stack.
arg_alignment = 1
#: Minimum number of stack slots used by a function call
#: This is necessary as Windows x64 requires using 4 slots on the stack
stack_minimum = 0
#: Indicates that this ABI returns to the next address on the slot
returns = True
def __init__(self, regs, align, minimum):
self.register_arguments = regs
self.arg_alignment = align
self.stack_minimum = minimum
@staticmethod
@LocalContext
def default():
return {
(32, 'i386', 'linux'): linux_i386,
(64, 'amd64', 'linux'): linux_amd64,
(32, 'arm', 'linux'): linux_arm,
(32, 'thumb', 'linux'): linux_arm,
(32, 'mips', 'linux'): linux_mips,
(32, 'i386', 'windows'): windows_i386,
(64, 'amd64', 'windows'): windows_amd64,
}[(context.bits, context.arch, context.os)]
@staticmethod
@LocalContext
def syscall():
return {
(32, 'i386', 'linux'): linux_i386_syscall,
(64, 'amd64', 'linux'): linux_amd64_syscall,
(32, 'arm', 'linux'): linux_arm_syscall,
(32, 'thumb', 'linux'): linux_arm_syscall,
(32, 'mips', 'linux'): linux_mips_syscall,
}[(context.bits, context.arch, context.os)]
@staticmethod
@LocalContext
def sigreturn():
return {
(32, 'i386', 'linux'): linux_i386_sigreturn,
(64, 'amd64', 'linux'): linux_amd64_sigreturn,
(32, 'arm', 'linux'): linux_arm_sigreturn,
(32, 'thumb', 'linux'): linux_arm_sigreturn,
}[(context.bits, context.arch, context.os)]
class SyscallABI(ABI):
"""
The syscall ABI treats the syscall number as the zeroth argument,
which must be loaded into the specified register.
"""
def __init__(self, register_arguments, *a, **kw):
super(SyscallABI, self).__init__(register_arguments, *a, **kw)
self.syscall_register = register_arguments[0]
class SigreturnABI(SyscallABI):
"""
The sigreturn ABI is similar to the syscall ABI, except that
both PC and SP are loaded from the stack. Because of this, there
is no 'return' slot necessary on the stack.
"""
returns = False
linux_i386 = ABI([], 4, 0)
linux_amd64 = ABI(['rdi','rsi','rdx','rcx','r8','r9'], 8, 0)
linux_arm = ABI(['r0', 'r1', 'r2', 'r3'], 8, 0)
linux_aarch64 = ABI(['x0', 'x1', 'x2', 'x3'], 16, 0)
linux_mips = ABI(['$a0','$a1','$a2','$a3'], 4, 0)
linux_i386_syscall = SyscallABI(['eax', 'ebx', 'ecx', 'edx', 'esi', 'edi', 'ebp'], 4, 0)
linux_amd64_syscall = SyscallABI(['rax','rdi', 'rsi', 'rdx', 'r10', 'r8', 'r9'], 8, 0)
linux_arm_syscall = SyscallABI(['r7', 'r0', 'r1', 'r2', 'r3', 'r4', 'r5', 'r6'], 4, 0)
linux_aarch64_syscall = SyscallABI(['x8', 'x0', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6'], 16, 0)
linux_mips_syscall = ABI(['$v0', '$a0','$a1','$a2','$a3'], 4, 0)
linux_i386_sigreturn = SigreturnABI(['eax'], 4, 0)
linux_amd64_sigreturn = SigreturnABI(['rax'], 4, 0)
linux_arm_sigreturn = SigreturnABI(['r7'], 4, 0)
windows_i386 = ABI([], 4, 0)
windows_amd64 = ABI(['rcx','rdx','r8','r9'], 32, 32)
# Fake ABIs used by SROP
linux_i386_srop = ABI(['eax'], 4, 0)
linux_amd64_srop = ABI(['rax'], 4, 0)
linux_arm_srop = ABI(['r7'], 4, 0)
+723
View File
@@ -0,0 +1,723 @@
"""Provides utilities for interacting with Android devices via the Android Debug Bridge.
"""
import glob
import os
import platform
import re
import shutil
import tempfile
import time
import dateutil.parser
from . import atexit
from . import tubes
from .context import context
from .context import LocalContext
from .device import Device
from .log import getLogger
from .util import misc
log = getLogger(__name__)
def adb(argv, *a, **kw):
"""Returns the output of an ADB subcommand."""
if isinstance(argv, (str, unicode)):
argv = [argv]
log.debug("$ " + ' '.join(context.adb + argv))
return tubes.process.process(context.adb + argv, *a, **kw).recvall()
def root():
"""Restarts adbd as root."""
log.info("Enabling root on %s" % context.device)
with context.quiet:
reply = adb('root')
if 'already running as root' in reply:
return
elif not reply or 'restarting adbd as root' in reply:
with context.quiet:
wait_for_device()
else:
log.error("Could not run as root:\n%s" % reply)
def reboot(wait=True):
"""Reboots the device."""
log.info('Rebooting device %s' % context.device)
with context.quiet:
adb('reboot')
if wait:
wait_for_device()
def reboot_bootloader():
"""Reboots the device to the bootloader."""
log.info('Rebooting %s to bootloader' % context.device)
with context.quiet:
adb('reboot-bootloader')
class AdbDevice(Device):
"""Encapsulates information about a connected device."""
def __init__(self, serial, type, port, product='unknown', model='unknown', device='unknown'):
self.serial = serial
self.type = type
self.port = port
self.product = product
self.model = model.replace('_', ' ')
self.device = device
if product == 'unknown':
return
with context.local(device=serial):
abi = str(properties.ro.product.cpu.abi)
context.clear()
context.arch = str(abi)
self.arch = context.arch
self.bits = context.bits
self.endian = context.endian
def __str__(self):
return self.serial
def __repr__(self):
fields = ['serial', 'type', 'port', 'product', 'model', 'device']
return '%s(%s)' % (self.__class__.__name__,
', '.join(('%s=%r' % (field, getattr(self, field)) for field in fields)))
@staticmethod
def from_adb_output(line):
fields = line.split()
"""
Example output:
ZX1G22LM7G device usb:336789504X product:shamu model:Nexus_6 device:shamu features:cmd,shell_v2
84B5T15A29020449 device usb:336855040X product:angler model:Nexus_6P device:angler
0062741b0e54b353 unauthorized usb:337641472X
"""
# The last few fields need to be split at colons.
split = lambda x: x.split(':')[-1]
fields[3:] = list(map(split, fields[3:]))
return AdbDevice(*fields[:6])
@context.quiet
def devices(serial=None):
"""Returns a list of ``Device`` objects corresponding to the connected devices."""
lines = adb(['devices', '-l'])
result = []
for line in lines.splitlines():
# Skip the first 'List of devices attached' line, and the final empty line.
if 'List of devices' in line or not line.strip():
continue
device = AdbDevice.from_adb_output(line)
if device.serial == serial:
return device
result.append(device)
return tuple(result)
@LocalContext
def wait_for_device(kick=False):
"""Waits for a device to be connected."""
with log.waitfor("Waiting for device to come online") as w:
with context.quiet:
if kick:
try:
adb(['reconnect'])
except Exception:
pass
adb('wait-for-device')
for device in devices():
if context.device == device:
return device
break
else:
log.error("Could not find any devices")
with context.local(device=device):
# There may be multiple devices, so context.device is
# insufficient. Pick the first device reported.
w.success('%s (%s %s %s)' % (device,
product(),
build(),
_build_date()))
return context.device
def disable_verity():
"""Disables dm-verity on the device."""
with log.waitfor("Disabling dm-verity on %s" % context.device) as w:
root()
with context.quiet:
reply = adb('disable-verity')
if 'Verity already disabled' in reply:
return
elif 'Now reboot your device' in reply:
reboot(wait=True)
else:
log.error("Could not disable verity:\n%s" % reply)
def remount():
"""Remounts the filesystem as writable."""
with log.waitfor("Remounting filesystem on %s" % context.device) as w:
disable_verity()
root()
with context.quiet:
reply = adb('remount')
if 'remount succeeded' not in reply:
log.error("Could not remount filesystem:\n%s" % reply)
def unroot():
"""Restarts adbd as AID_SHELL."""
log.info("Unrooting %s" % context.device)
with context.quiet:
reply = adb('unroot')
if 'restarting adbd as non root' not in reply:
log.error("Could not run as root:\n%s" % reply)
def pull(remote_path, local_path=None):
"""Download a file from the device.
Arguments:
remote_path(str): Path or directory of the file on the device.
local_path(str): Path to save the file to.
Uses the file's name by default.
"""
if local_path is None:
local_path = os.path.basename(remote_path)
msg = "Pulling %r from %r" % (remote_path, local_path)
if context.log_level == 'debug':
msg += ' (%s)' % context.device
result = ''
with log.waitfor(msg) as w:
with context.quiet:
args = context.adb + ['pull', remote_path, local_path]
io = tubes.process.process(args)
result = io.recvall()
if 0 != io.poll(block=True):
log.error(result)
return result
def push(local_path, remote_path):
"""Upload a file to the device.
Arguments:
local_path(str): Path to the local file to push.
remote_path(str): Path or directory to store the file on the device.
"""
msg = "Pushing %r to %r" % (local_path, remote_path)
if context.log_level == 'debug':
msg += ' (%s)' % context.device
with log.waitfor(msg) as w:
with context.quiet:
args = context.adb + ['push', local_path, remote_path]
io = tubes.process.process(args)
result = io.recvall()
if 0 != io.poll(block=True):
log.error(result)
return result
@context.quiet
def read(path, target=None):
"""Download a file from the device, and extract its contents.
Arguments:
path(str): Path to the file on the device.
target(str): Optional, location to store the file.
Uses a temporary file by default.
"""
with tempfile.NamedTemporaryFile() as temp:
target = target or temp.name
pull(path, target)
result = misc.read(target)
return result
@context.quiet
def write(path, data=''):
"""Create a file on the device with the provided contents.
Arguments:
path(str): Path to the file on the device
data(str): Contents to store in the file
"""
with tempfile.NamedTemporaryFile() as temp:
misc.write(temp.name, data)
push(temp.name, path)
def process(argv, *a, **kw):
"""Execute a process on the device.
See ``pwnlib.tubes.process.process`` documentation for more info.
Returns:
A ``process`` tube.
"""
argv = argv or []
if isinstance(argv, (str, unicode)):
argv = [argv]
display = argv
argv = context.adb + ['shell'] + argv
kw.setdefault('display', display)
kw.setdefault('where', 'Android')
return tubes.process.process(argv, *a, **kw)
def interactive(**kw):
"""Spawns an interactive shell."""
return shell(**kw).interactive()
def shell(**kw):
"""Returns an interactive shell."""
return process([], **kw)
@context.quiet
def which(name):
"""Retrieves the full path to a binary in ``PATH`` on the device"""
return process(['which', name]).recvall().strip()
def whoami():
return process(['whoami']).recvall().strip()
def forward(port):
"""Sets up a port to forward to the device."""
tcp_port = 'tcp:%s' % port
start_forwarding = adb(['forward', tcp_port, tcp_port])
atexit.register(lambda: adb(['forward', '--remove', tcp_port]))
@context.quiet
def logcat(stream=False):
"""Reads the system log file.
By default, causes logcat to exit after reading the file.
Arguments:
stream(bool): If ``True``, the contents are streamed rather than
read in a one-shot manner. Default is ``False``.
Returns:
If ``stream`` is ``False``, returns a string containing the log data.
Otherwise, it returns a ``tube`` connected to the log output.
"""
if stream:
return process(['logcat'])
else:
return adb(['logcat', '-d'])
def pidof(name):
"""Returns a list of PIDs for the named process."""
with context.quiet:
io = process(['pidof', name])
data = io.recvall().split()
return list(map(int, data))
def proc_exe(pid):
"""Returns the full path of the executable for the provided PID."""
with context.quiet:
io = process(['readlink','-e','/proc/%d/exe' % pid])
data = io.recvall().strip()
return data
def getprop(name=None):
"""Reads a properties from the system property store.
Arguments:
name(str): Optional, read a single property.
Returns:
If ``name`` is not specified, a ``dict`` of all properties is returned.
Otherwise, a string is returned with the contents of the named property.
"""
with context.quiet:
if name:
return process(['getprop', name]).recvall().strip()
result = process(['getprop']).recvall()
expr = r'\[([^\]]+)\]: \[(.*)\]'
props = {}
for line in result.splitlines():
if not line.startswith('['):
continue
name, value = re.search(expr, line).groups()
if value.isdigit():
value = int(value)
props[name] = value
return props
def setprop(name, value):
"""Writes a property to the system property store."""
return process(['setprop', name, value]).recvall().strip()
def listdir(directory='/'):
"""Returns a list containing the entries in the provided directory.
Note:
Because ``adb shell`` is used to retrieve the listing, shell
environment variable expansion and globbing are in effect.
"""
io = process(['find', directory, '-maxdepth', '1', '-print0'])
data = io.recvall()
paths = filter(len, data.split('\x00'))
relpaths = [os.path.relpath(path, directory) for path in paths]
if '.' in relpaths:
relpaths.remove('.')
return relpaths
def fastboot(args, *a, **kw):
"""Executes a fastboot command.
Returns:
The command output.
"""
serial = context.device
if not serial:
log.error("Unknown device")
return tubes.process.process(['fastboot', '-s', serial] + list(args), **kw).recvall()
def fingerprint():
"""Returns the device build fingerprint."""
return str(properties.ro.build.fingerprint)
def product():
"""Returns the device product identifier."""
return str(properties.ro.build.product)
def build():
"""Returns the Build ID of the device."""
return str(properties.ro.build.id)
def unlock_bootloader():
"""Unlocks the bootloader of the device.
Note:
This requires physical interaction with the device.
"""
adb(['reboot-bootloader'])
fastboot(['oem', 'unlock'])
fastboot(['continue'])
class Kernel(object):
_kallsyms = None
@property
def address(self):
return self.symbols['_text']
@property
@context.quiet
def symbols(self):
"""Returns a dictionary of kernel symbols"""
result = {}
for line in self.kallsyms.splitlines():
fields = line.split()
address = int(fields[0], 16)
name = fields[-1]
result[name] = address
return result
@property
@context.quiet
def kallsyms(self):
"""Returns the raw output of kallsyms"""
if not self._kallsyms:
self._kallsyms = {}
root()
write('/proc/sys/kernel/kptr_restrict', '1')
self._kallsyms = read('/proc/kallsyms')
return self._kallsyms
@property
@context.quiet
def version(self):
"""Returns the kernel version of the device."""
root()
return read('/proc/version').strip()
@property
@context.quiet
def cmdline(self):
root()
return read('/proc/cmdline').strip()
@property
@context.quiet
def lastmsg(self):
root()
if 'last_kmsg' in listdir('/proc'):
return read('/proc/last_kmsg')
if 'console-ramoops' in listdir('/sys/fs/pstore/'):
return read('/sys/fs/pstore/console-ramoops')
def enable_uart(self):
"""Reboots the device with kernel logging to the UART enabled."""
model = str(properties.ro.product.model)
known_commands = {
'Nexus 4': None,
'Nexus 5': None,
'Nexus 6': 'oem config console enable',
'Nexus 5X': None,
'Nexus 6P': 'oem uart enable',
'Nexus 7': 'oem uart-on',
}
with log.waitfor('Enabling kernel UART') as w:
if model not in known_commands:
log.error("Device UART is unsupported.")
command = known_commands[model]
if command is None:
w.success('Always enabled')
return
# Check the current commandline, it may already be enabled.
if any(s.startswith('console=tty') for s in self.cmdline.split()):
w.success("Already enabled")
return
# Need to be root
with context.local(device=context.device):
# Save off the command line before rebooting to the bootloader
cmdline = kernel.cmdline
reboot_bootloader()
# Wait for device to come online
while context.device not in fastboot(['devices',' -l']):
time.sleep(0.5)
# Try the 'new' way
fastboot(command.split())
fastboot(['continue'])
wait_for_device()
kernel = Kernel()
class Property(object):
def __init__(self, name=None):
self.__dict__['_name'] = name
def __str__(self):
return getprop(self._name).strip()
def __repr__(self):
return repr(str(self))
def __getattr__(self, attr):
if self._name:
attr = '%s.%s' % (self._name, attr)
return Property(attr)
def __setattr__(self, attr, value):
if attr in self.__dict__:
return super(Property, self).__setattr__(attr, value)
if self._name:
attr = '%s.%s' % (self._name, attr)
setprop(attr, value)
properties = Property()
def _build_date():
"""Returns the build date in the form YYYY-MM-DD as a string"""
as_string = getprop('ro.build.date')
as_datetime = dateutil.parser.parse(as_string)
return as_datetime.strftime('%Y-%b-%d')
def find_ndk_project_root(source):
'''Given a directory path, find the topmost project root.
tl;dr "foo/bar/jni/baz.cpp" ==> "foo/bar"
'''
ndk_directory = os.path.abspath(source)
while ndk_directory != '/':
if os.path.exists(os.path.join(ndk_directory, 'jni')):
break
ndk_directory = os.path.dirname(ndk_directory)
else:
return None
return ndk_directory
_android_mk_template = '''
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := poc
LOCAL_SRC_FILES := %(local_src_files)s
include $(BUILD_EXECUTABLE)
'''.lstrip()
_application_mk_template = '''
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
APP_ABI:= %(app_abi)s
APP_PLATFORM:=%(app_platform)s
'''.lstrip()
def _generate_ndk_project(file_list, abi='arm-v7a', platform_version=21):
# Create our project root
root = tempfile.mkdtemp()
if not isinstance(file_list, (list, tuple)):
file_list = [file_list]
# Copy over the source file(s)
jni_directory = os.path.join(root, 'jni')
os.mkdir(jni_directory)
for file in file_list:
shutil.copy(file, jni_directory)
# Create the directories
# Populate Android.mk
local_src_files = ' '.join(list(map(os.path.basename, file_list)))
Android_mk = os.path.join(jni_directory, 'Android.mk')
with open(Android_mk, 'w+') as f:
f.write(_android_mk_template % locals())
# Populate Application.mk
app_abi = abi
app_platform = 'android-%s' % platform_version
Application_mk = os.path.join(jni_directory, 'Application.mk')
with open(Application_mk, 'w+') as f:
f.write(_application_mk_template % locals())
return root
def compile(source):
"""Compile a source file or project with the Android NDK."""
# Ensure that we can find the NDK.
ndk = os.environ.get('NDK', None)
if ndk is None:
log.error('$NDK must be set to the Android NDK directory')
ndk_build = os.path.join(ndk, 'ndk-build')
# Determine whether the source is an NDK project or a single source file.
project = find_ndk_project_root(source)
if not project:
project = _generate_ndk_project(source,
str(properties.ro.product.cpu.abi),
str(properties.ro.build.version.sdk))
# Remove any output files
lib = os.path.join(project, 'libs')
if os.path.exists(lib):
shutil.rmtree(lib)
# Build the project
io = tubes.process.process(ndk_build, cwd=os.path.join(project, 'jni'))
result = io.recvall()
if 0 != io.poll():
log.error("Build failed:\n%s" % result)
# Find all of the output files
output = glob.glob(os.path.join(lib, '*', '*'))
return output[0]
class Partition(object):
def __init__(self, path, name, blocks=0):
self.path = path
self.name = name
self.blocks = blocks
self.size = blocks * 1024
@property
def data(self):
with log.waitfor('Fetching %r partition (%s)' % (self.name, self.path)):
return read(self.path)
class Partitions(object):
@property
@context.quiet
def by_name_dir(self):
cmd = ['shell','find /dev/block/platform -type d -name by-name']
return adb(cmd).strip()
@context.quiet
def __dir__(self):
return list(self)
@context.quiet
def __iter__(self):
root()
# Find all named partitions
for name in listdir(self.by_name_dir):
yield name
@context.quiet
def __getattr__(self, attr):
for name in self:
if name == attr:
break
else:
raise AttributeError("No partition %r" % attr)
path = os.path.join(self.by_name_dir, name)
# Find the actual path of the device
devpath = process(['readlink', '-n', path]).recvall()
devname = os.path.basename(devpath)
# Get the size of the partition
for line in read('/proc/partitions').splitlines():
if not line.strip():
continue
major, minor, blocks, name = line.split(None, 4)
if devname == name:
break
else:
log.error("Could not find size of partition %r" % name)
return Partition(devpath, attr, int(blocks))
partitions = Partitions()
+121
View File
@@ -0,0 +1,121 @@
#!/usr/bin/env python2
"""
"""
import collections
import logging
import os
import string
import sys
from . import term
from .context import context
term_mode = True
args = collections.defaultdict(str)
env_prefix = 'PWNLIB_'
def isident(s):
"""
Helper function to check whether a string is a valid identifier,
as passed in on the command-line.
"""
first = string.uppercase + '_'
body = string.digits + first
if not s:
return False
if s[0] not in first:
return False
if not all(c in body for c in s[1:]):
return False
return True
def asbool(s):
"""
Convert a string to its boolean value
"""
if s.lower() == 'true':
return True
elif s.lower() == 'false':
return False
elif s.isdigit():
return bool(int(s))
else:
raise ValueError('must be integer or boolean: %r' % s)
def set_log_level(x):
with context.local(log_level=x):
context.defaults['log_level']=context.log_level
def set_log_file(x):
context.log_file=x
def set_log_level_error(x):
set_log_level('error')
def set_log_level_debug(x):
set_log_level('debug')
def set_noterm(v):
if asbool(v):
global term_mode
term_mode = False
def set_timeout(v):
context.defaults['timeout'] = int(v)
def set_randomize(v):
context.defaults['randomize'] = asbool(v)
def set_aslr(v):
context.defaults['aslr'] = not asbool(v)
def set_noptrace(v):
context.defaults['noptrace'] = asbool(v)
hooks = {
'LOG_LEVEL': set_log_level,
'LOG_FILE': set_log_file,
'DEBUG': set_log_level_debug,
'NOTERM': set_noterm,
'SILENT': set_log_level_error,
'RANDOMIZE': set_randomize,
'TIMEOUT': set_timeout,
'NOASLR': set_aslr,
'NOPTRACE': set_noptrace,
}
def initialize():
global args, term_mode
# Hack for readthedocs.org
if 'READTHEDOCS' in os.environ:
os.environ['PWNLIB_NOTERM'] = '1'
for k, v in os.environ.items():
if not k.startswith(env_prefix):
continue
k = k[len(env_prefix):]
if k in hooks:
hooks[k](v)
elif isident(k):
args[k] = v
argv = sys.argv[:]
for arg in sys.argv[:]:
orig = arg
value = 'True'
if '=' in arg:
arg, value = arg.split('=')
if arg in hooks:
sys.argv.remove(orig)
hooks[arg](value)
elif isident(arg):
sys.argv.remove(orig)
args[arg] = value
if term_mode:
term.init()
+273 -176
View File
@@ -28,7 +28,7 @@ Assembly
in the :mod:`shellcraft` module.
>>> asm(shellcraft.sh())
'jhh///sh/bin\x89\xe31\xc9j\x0bX\x99\xcd\x80'
'jhh///sh/binj\x0bX\x89\xe31\xc9\x99\xcd\x80'
Disassembly
------------------------
@@ -53,17 +53,21 @@ from glob import glob
from os import environ
from os import path
from . import atexit
from . import shellcraft
from .context import LocalContext
from .context import context
from .log import getLogger
log = getLogger(__name__)
__all__ = ['asm', 'cpp', 'disasm', 'make_elf']
__all__ = ['asm', 'cpp', 'disasm', 'make_elf', 'make_elf_from_assembly']
_basedir = path.split(__file__)[0]
_incdir = path.join(_basedir, 'data', 'includes')
def which_binutils(util, **kwargs):
@LocalContext
def which_binutils(util):
"""
Finds a binutils in the PATH somewhere.
Expects that the utility is prefixed with the architecture name.
@@ -83,49 +87,55 @@ def which_binutils(util, **kwargs):
...
Exception: Could not find 'as' installed for ContextType(arch = 'msp430')
"""
with context.local(**kwargs):
arch = context.arch
bits = context.bits
arch = context.arch
bits = context.bits
# Fix up pwntools vs Debian triplet naming, and account
# for 'thumb' being its own pwntools architecture.
arches = [arch] + {
'thumb': ['arm', 'aarch64'],
'i386': ['x86_64', 'amd64'],
'amd64': ['x86_64', 'i386'],
}.get(arch, [])
# Fix up pwntools vs Debian triplet naming, and account
# for 'thumb' being its own pwntools architecture.
arches = [arch] + {
'thumb': ['arm', 'aarch64'],
'i386': ['x86_64', 'amd64'],
'i686': ['x86_64', 'amd64'],
'amd64': ['x86_64', 'i386'],
}.get(arch, [])
# If one of the candidate architectures matches the native
# architecture, use that as a last resort.
machine = platform.machine()
try:
with context.local(arch = machine):
if context.arch in arches:
arches.append(None)
except AttributeError:
log.warn_once("Your local binutils won't be used because architecture %r is not supported." % machine)
# If one of the candidate architectures matches the native
# architecture, use that as a last resort.
machine = platform.machine()
machine = 'i386' if machine == 'i686' else machine
try:
with context.local(arch = machine):
if context.arch in arches:
arches.append(None)
except AttributeError:
log.warn_once("Your local binutils won't be used because architecture %r is not supported." % machine)
for arch in arches:
# hack for homebrew-installed binutils on mac
for gutil in ['g'+util, util]:
# e.g. objdump
if arch is None: pattern = gutil
utils = [util]
# e.g. aarch64-linux-gnu-objdump
else: pattern = '%s*linux*-%s' % (arch,gutil)
# hack for homebrew-installed binutils on mac
if platform.system() == 'Darwin':
utils = ['g'+util, util]
for dir in environ['PATH'].split(':'):
res = sorted(glob(path.join(dir, pattern)))
if res:
return res[0]
for arch in arches:
for gutil in utils:
# e.g. objdump
if arch is None: pattern = gutil
locals()['context'] = context
log.warning("""
# e.g. aarch64-linux-gnu-objdump
else: pattern = '%s*linux*-%s' % (arch,gutil)
for dir in environ['PATH'].split(':'):
res = sorted(glob(path.join(dir, pattern)))
if res:
return res[0]
locals()['context'] = context
log.warning("""
Could not find %(util)r installed for %(context)s
Try installing binutils for this architecture:
https://pwntools.readthedocs.org/en/latest/install/binutils.html
https://pwntools.readthedocs.org/en/latest/install/binutils.html
""".strip() % locals())
raise Exception('Could not find %(util)r installed for %(context)s' % locals())
raise Exception('Could not find %(util)r installed for %(context)s' % locals())
checked_assembler_version = defaultdict(lambda: False)
@@ -204,11 +214,7 @@ def _objdump():
def _include_header():
os = context.os
arch = context.arch
if os == 'freebsd':
include = 'freebsd.h'
elif os == 'linux':
include = 'linux/%s.h' % arch
include = '%s/%s.h' % (os, arch)
if not include or not path.exists(path.join(_incdir, include)):
log.warn_once("Could not find system include headers for %s-%s" % (arch,os))
@@ -218,7 +224,11 @@ def _include_header():
def _arch_header():
prefix = ['.section .shellcode,"ax"']
prefix = ['.section .shellcode,"awx"',
'.global _start',
'.global __start',
'_start:',
'__start:']
headers = {
'i386' : ['.intel_syntax noprefix'],
'amd64' : ['.intel_syntax noprefix'],
@@ -229,7 +239,8 @@ def _arch_header():
'.arch armv7-a',
'.thumb'],
'mips' : ['.set mips2',
'.set noreorder'],
'.set noreorder',
],
}
return '\n'.join(prefix + headers.get(context.arch, [])) + '\n'
@@ -304,7 +315,8 @@ def _run(cmd, stdin = None):
return stdout
def cpp(shellcode, **kwargs):
@LocalContext
def cpp(shellcode):
r"""cpp(shellcode, ...) -> str
Runs CPP over the given shellcode.
@@ -324,37 +336,79 @@ def cpp(shellcode, **kwargs):
>>> cpp("mov al, SYS_setresuid", arch = "i386", os = "linux")
'mov al, 164\n'
>>> cpp("weee SYS_setresuid", arch = "arm", os = "linux")
'weee (0x900000+164)\n'
'weee (0+164)\n'
>>> cpp("SYS_setresuid", arch = "thumb", os = "linux")
'(0+164)\n'
>>> cpp("SYS_setresuid", os = "freebsd")
'311\n'
"""
arch = context.arch
os = context.os
code = _include_header() + shellcode
cmd = [
'cpp',
'-C',
'-nostdinc',
'-undef',
'-P',
'-I' + _incdir,
'/dev/stdin'
]
return _run(cmd, code).strip('\n').rstrip() + '\n'
with context.local(**kwargs):
arch = context.arch
os = context.os
code = _include_header() + shellcode
cmd = [
'cpp',
'-C',
'-nostdinc',
'-undef',
'-P',
'-I' + _incdir,
'/dev/stdin'
]
return _run(cmd, code).strip('\n').rstrip() + '\n'
@LocalContext
def make_elf_from_assembly(assembly, vma = None, extract=False, shared = False):
r"""
Builds an ELF file with the specified assembly as its
executable code.
elf_template = '''
.global _start
.global __start
.text
_start:
__start:
'''
Arguments:
def make_elf(data, vma = None, strip=True, **kwargs):
assembly(str): Assembly
vma(int): Load address of the binary
extract(bool): Whether to return the data extracted from the file created,
or the path to it.
Returns:
The path to the assembled ELF (extract=False), or the data
of the assembled ELF.
Example:
>>> context.clear()
>>> context.arch = 'amd64'
>>> sc = 'push rbp; mov rbp, rsp;'
>>> sc += shellcraft.echo('Hello\n')
>>> sc += 'mov rsp, rbp; pop rbp; ret'
>>> solib = make_elf_from_assembly(sc, shared=1)
>>> subprocess.check_output(['echo', 'World'], env={'LD_PRELOAD': solib})
'Hello\nWorld\n'
"""
if shared and vma:
log.error("Cannot specify a VMA for a shared library.")
if vma is None:
if shared:
vma = 0
else:
vma = 0x10000000
if context.arch == 'thumb':
to_thumb = shellcraft.arm.to_thumb()
if not assembly.startswith(to_thumb):
assembly = to_thumb + assembly
path = asm(assembly, vma = vma, extract = extract, shared = shared)
if not extract:
os.chmod(path, 0755)
return path
@LocalContext
def make_elf(data, vma = None, strip=True, extract=True, shared=False):
r"""
Builds an ELF file with the specified binary data as its
executable code.
@@ -383,45 +437,69 @@ def make_elf(data, vma = None, strip=True, **kwargs):
>>> p.recvline()
'Hello\n'
"""
with context.local(**kwargs):
assembler = _assembler()
linker = _linker()
code = elf_template
code += '.string "%s"' % ''.join('\\x%02x' % c for c in bytearray(data))
code += '\n'
retval = None
log.debug(code)
if shared and vma:
log.error("Cannot specify a VMA for a shared library.")
tmpdir = tempfile.mkdtemp(prefix = 'pwn-asm-')
step1 = path.join(tmpdir, 'step1-asm')
step2 = path.join(tmpdir, 'step2-obj')
step3 = path.join(tmpdir, 'step3-elf')
if context.arch == 'thumb':
to_thumb = asm(shellcraft.arm.to_thumb(), arch='arm')
try:
with open(step1, 'wb+') as f:
f.write(code)
if not data.startswith(to_thumb):
data = to_thumb + data
_run(assembler + ['-o', step2, step1])
load_addr = []
if vma is not None:
load_addr = ['-Ttext-segment=%#x' % vma]
assembler = _assembler()
linker = _linker()
code = _arch_header()
code += '.string "%s"' % ''.join('\\x%02x' % ord(c) for c in data)
code += '\n'
_run(linker + load_addr + ['-N', '-o', step3, step2])
log.debug("Building ELF:\n" + code)
if strip:
_run([which_binutils('objcopy'), '-Sg', step3])
_run([which_binutils('strip'), '--strip-unneeded', step3])
tmpdir = tempfile.mkdtemp(prefix = 'pwn-asm-')
step1 = path.join(tmpdir, 'step1-asm')
step2 = path.join(tmpdir, 'step2-obj')
step3 = path.join(tmpdir, 'step3-elf')
try:
with open(step1, 'wb+') as f:
f.write(code)
_run(assembler + ['-o', step2, step1])
linker_options = ['-z', 'execstack']
if vma:
linker_options += ['--section-start=.shellcode=%#x' % vma,
'--entry=%#x' % vma]
elif shared:
linker_options += ['-shared', '-init=_start']
linker_options += ['-o', step3, step2]
_run(linker + linker_options)
if strip:
_run([which_binutils('objcopy'), '-Sg', step3])
_run([which_binutils('strip'), '--strip-unneeded', step3])
if not extract:
os.chmod(step3, 0755)
retval = step3
with open(step3, 'r') as f:
return f.read()
except Exception:
log.exception("An error occurred while building an ELF:\n%s" % code)
else:
shutil.rmtree(tmpdir)
with open(step3, 'r') as f:
retval = f.read()
except Exception:
log.exception("An error occurred while building an ELF:\n%s" % code)
else:
atexit.register(lambda: shutil.rmtree(tmpdir))
def asm(shellcode, vma = 0, **kwargs):
r"""asm(code, vma = 0, ...) -> str
return retval
@LocalContext
def asm(shellcode, vma = 0, extract = True, shared = False):
r"""asm(code, vma = 0, extract = True, ...) -> str
Runs :func:`cpp` over a given shellcode and then assembles it into bytes.
@@ -434,6 +512,9 @@ def asm(shellcode, vma = 0, **kwargs):
Arguments:
shellcode(str): Assembler code to assemble.
vma(int): Virtual memory address of the beginning of assembly
extract(bool): Extract the raw assembly bytes from the assembled
file. If ``False``, returns the path to an ELF file
with the assembly embedded.
Kwargs:
Any arguments/properties that can be set on ``context``
@@ -448,63 +529,74 @@ def asm(shellcode, vma = 0, **kwargs):
'\xb8\x17\x00\x00\x00'
>>> asm("mov rax, SYS_select", arch = 'amd64', os = 'linux')
'H\xc7\xc0\x17\x00\x00\x00'
>>> asm("ldr r0, =SYS_select", arch = 'arm', os = 'linux', bits=32)
'\x04\x00\x1f\xe5R\x00\x90\x00'
>>> asm("mov r0, #SYS_select", arch = 'arm', os = 'linux', bits=32)
'R\x00\xa0\xe3'
"""
result = ''
with context.local(**kwargs):
assembler = _assembler()
linker = _linker()
objcopy = _objcopy() + ['-j', '.shellcode', '-Obinary']
code = ''
code += _arch_header()
code += cpp(shellcode)
assembler = _assembler()
linker = _linker()
objcopy = _objcopy() + ['-j', '.shellcode', '-Obinary']
code = ''
code += _arch_header()
code += cpp(shellcode)
log.debug('Assembling\n%s' % code)
log.debug('Assembling\n%s' % code)
tmpdir = tempfile.mkdtemp(prefix = 'pwn-asm-')
step1 = path.join(tmpdir, 'step1')
step2 = path.join(tmpdir, 'step2')
step3 = path.join(tmpdir, 'step3')
step4 = path.join(tmpdir, 'step4')
tmpdir = tempfile.mkdtemp(prefix = 'pwn-asm-')
step1 = path.join(tmpdir, 'step1')
step2 = path.join(tmpdir, 'step2')
step3 = path.join(tmpdir, 'step3')
step4 = path.join(tmpdir, 'step4')
try:
with open(step1, 'w') as fd:
fd.write(code)
try:
with open(step1, 'w') as fd:
fd.write(code)
_run(assembler + ['-o', step2, step1])
_run(assembler + ['-o', step2, step1])
if not vma:
shutil.copy(step2, step3)
if not vma:
shutil.copy(step2, step3)
if vma or not extract:
ldflags = ['-z', 'execstack', '-o', step3, step2]
if vma:
_run(linker + ['--section-start=.shellcode=%#x' % vma,
'--entry=%#x' % vma,
'-o', step3, step2])
ldflags += ['--section-start=.shellcode=%#x' % vma,
'--entry=%#x' % vma,
'-z', 'max-page-size=4096',
'-z', 'common-page-size=4096']
elif shared:
ldflags += ['-shared', '-init=_start']
_run(linker + ldflags)
elif file(step2,'rb').read(4) == '\x7fELF':
# Sanity check for seeing if the output has relocations
relocs = subprocess.check_output(
[which_binutils('readelf'), '-r', step2]
).strip()
if len(relocs.split('\n')) > 1:
log.error('Shellcode contains relocations:\n%s' % relocs)
else:
shutil.copy(step2, step3)
_run(objcopy + [step3, step4])
with open(step4) as fd:
result = fd.read()
except Exception:
log.exception("An error occurred while assembling:\n%s" % code)
elif file(step2,'rb').read(4) == '\x7fELF':
# Sanity check for seeing if the output has relocations
relocs = subprocess.check_output(
[which_binutils('readelf'), '-r', step2]
).strip()
if extract and len(relocs.split('\n')) > 1:
log.error('Shellcode contains relocations:\n%s' % relocs)
else:
shutil.rmtree(tmpdir)
return result
shutil.copy(step2, step3)
def disasm(data, vma = 0, byte = True, offset = True, **kwargs):
if not extract:
return step3
_run(objcopy + [step3, step4])
with open(step4) as fd:
result = fd.read()
except Exception:
lines = '\n'.join('%4i: %s' % (i+1,line) for (i,line) in enumerate(code.splitlines()))
log.exception("An error occurred while assembling:\n%s" % lines)
else:
atexit.register(lambda: shutil.rmtree(tmpdir))
return result
@LocalContext
def disasm(data, vma = 0, byte = True, offset = True, instructions = True):
"""disasm(data, ...) -> str
Disassembles a bytestring into human readable assembler.
@@ -547,53 +639,57 @@ def disasm(data, vma = 0, byte = True, offset = True, **kwargs):
"""
result = ''
with context.local(**kwargs):
arch = context.arch
os = context.os
arch = context.arch
os = context.os
tmpdir = tempfile.mkdtemp(prefix = 'pwn-disasm-')
step1 = path.join(tmpdir, 'step1')
step2 = path.join(tmpdir, 'step2')
tmpdir = tempfile.mkdtemp(prefix = 'pwn-disasm-')
step1 = path.join(tmpdir, 'step1')
step2 = path.join(tmpdir, 'step2')
bfdarch = _bfdarch()
bfdname = _bfdname()
objdump = _objdump() + ['-d', '--adjust-vma', str(vma), '-b', bfdname]
objcopy = _objcopy() + [
'-I', 'binary',
'-O', bfdname,
'-B', bfdarch,
'--set-section-flags', '.data=code',
'--rename-section', '.data=.text',
]
bfdarch = _bfdarch()
bfdname = _bfdname()
objdump = _objdump() + ['-d', '--adjust-vma', str(vma), '-b', bfdname]
objcopy = _objcopy() + [
'-I', 'binary',
'-O', bfdname,
'-B', bfdarch,
'--set-section-flags', '.data=code',
'--rename-section', '.data=.text',
]
if arch == 'thumb':
objcopy += ['--prefix-symbol=$t.']
else:
objcopy += ['-w', '-N', '*']
if arch == 'thumb':
objcopy += ['--prefix-symbol=$t.']
else:
objcopy += ['-w', '-N', '*']
try:
try:
with open(step1, 'w') as fd:
fd.write(data)
with open(step1, 'w') as fd:
fd.write(data)
res = _run(objcopy + [step1, step2])
res = _run(objcopy + [step1, step2])
output0 = subprocess.check_output(objdump + [step2])
output1 = output0.split('<.text>:\n')
output0 = subprocess.check_output(objdump + [step2])
output1 = output0.split('<.text>:\n')
if len(output1) != 2:
log.error('Could not find .text in objdump output:\n%s' % output0)
if len(output1) != 2:
log.error('Could not find .text in objdump output:\n%s' % output0)
result = output1[1].strip('\n').rstrip().expandtabs()
except Exception:
log.exception("An error occurred while disassembling:\n%s" % data)
else:
atexit.register(lambda: shutil.rmtree(tmpdir))
result = output1[1].strip('\n').rstrip().expandtabs()
except Exception:
log.exception("An error occurred while disassembling:\n%s" % data)
else:
shutil.rmtree(tmpdir)
lines = []
pattern = '^( *[0-9a-f]+: *)((?:[0-9a-f]+ )+ *)(.*)'
for line in result.splitlines():
o, b, i = re.search(pattern, line).groups()
try:
o, b, i = re.search(pattern, line).groups()
except:
lines.append(line)
continue
line = ''
@@ -601,7 +697,8 @@ def disasm(data, vma = 0, byte = True, offset = True, **kwargs):
line += o
if byte:
line += b
line += i
if instructions:
line += i
lines.append(line)
return '\n'.join(lines)
+7 -8
View File
@@ -71,25 +71,23 @@ def _run_handlers():
If a handler raises an exception, it will be printed but nothing else
happens, i.e. other handlers will be run.
"""
context.clear()
for _ident, (func, args, kwargs, ctx) in \
sorted(_handlers.items(), reverse = True):
try:
with context.local(**ctx):
with context.local():
context.clear()
context.update(**ctx)
func(*args, **kwargs)
except SystemExit:
pass
except:
except Exception:
# extract the current exception and rewind the traceback to where it
# originated
typ, val, tb = sys.exc_info()
traceback.print_exception(typ, val, tb.tb_next)
# we rely on the existing excepthook to print exceptions
if hasattr(sys, 'excepthook'):
_oldhook = sys.excepthook
else:
_oldhook = None
_oldhook = getattr(sys, 'excepthook', None)
def _newhook(typ, val, tb):
"""_newhook(typ, val, tb)
@@ -99,6 +97,7 @@ def _newhook(typ, val, tb):
"""
if _oldhook:
_oldhook(typ, val, tb)
_run_handlers()
if _run_handlers:
_run_handlers()
sys.excepthook = _newhook
+1 -1
View File
@@ -83,7 +83,7 @@ def _run_handlers():
func(*args, **kwargs)
except SystemExit:
pass
except:
except Exception:
# extract the current exception and rewind the traceback to where it
# originated
typ, val, tb = sys.exc_info()
+1
View File
@@ -0,0 +1 @@
# empty
+59 -3
View File
@@ -20,7 +20,7 @@ parser.add_argument(
parser.add_argument(
"-f", "--format",
help="Output format (defaults to hex for ttys, otherwise raw)",
choices=['raw', 'hex', 'string']
choices=['raw', 'hex', 'string', 'elf']
)
parser.add_argument(
@@ -40,6 +40,28 @@ parser.add_argument(
help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
)
parser.add_argument(
'-v', '--avoid',
action='append',
help = 'Encode the shellcode to avoid the listed bytes (provided as hex; default: 000a)'
)
parser.add_argument(
'-n', '--newline',
dest='avoid',
action='append_const',
const='\n',
help = 'Encode the shellcode to avoid newlines'
)
parser.add_argument(
'-z', '--zero',
dest='avoid',
action='append_const',
const='\x00',
help = 'Encode the shellcode to avoid NULL bytes'
)
parser.add_argument(
'-d',
@@ -48,21 +70,55 @@ parser.add_argument(
action='store_true'
)
parser.add_argument(
'-e',
'--encoder',
help="Specific encoder to use"
)
parser.add_argument(
'-i',
'--infile',
help="Specify input file",
default=sys.stdin,
type=file
)
parser.add_argument(
'-r',
'--run',
help="Run output",
action='store_true'
)
def main():
args = parser.parse_args()
tty = args.output.isatty()
data = '\n'.join(args.lines) or sys.stdin.read()
data = '\n'.join(args.lines) or args.infile.read()
output = asm(data.replace(';', '\n'))
fmt = args.format or ('hex' if tty else 'raw')
formatters = {'r':str, 'h':enhex, 's':repr}
if args.avoid:
output = encode(output, args.avoid)
if args.debug:
proc = gdb.debug_shellcode(output, arch=context.arch)
proc.interactive()
sys.exit(0)
args.output.write(formatters[fmt[0]](output))
if args.run:
proc = run_shellcode(output)
proc.interactive()
sys.exit(0)
if fmt[0] == 'e':
args.output.write(make_elf(output))
try: os.fchmod(args.output.fileno(), 0700)
except OSError: pass
else:
args.output.write(formatters[fmt[0]](output))
if tty and fmt is not 'raw':
args.output.write('\n')
+17 -2
View File
@@ -10,16 +10,31 @@ parser = argparse.ArgumentParser(
description = 'Check binary security settings'
)
parser.add_argument(
'elf',
nargs='+',
nargs='*',
type=file,
help='Files to check'
)
parser.add_argument(
'--file',
nargs='*',
dest='elf2',
metavar='elf',
type=file,
help='File to check (for compatibility with checksec.sh)'
)
def main():
args = parser.parse_args()
for f in args.elf:
files = args.elf or args.elf2 or []
if not files:
parser.print_usage()
return
for f in files:
e = ELF(f.name)
if __name__ == '__main__': main()
+4 -1
View File
@@ -1,4 +1,7 @@
from pwn import *
import sys
import pwnlib
from pwnlib.context import context
pwnlib.log.console.stream = sys.stderr
+15 -24
View File
@@ -4,13 +4,8 @@ import argparse
import os
import re
import pwnlib.log
from pwnlib import asm
from pwnlib import constants
from pwnlib.context import context
from pwnlib.util import safeeval
pwnlib.log.install_default_handler()
from pwn import *
from . import common
p = argparse.ArgumentParser(
description = "Looking up constants from header files.\n\nExample: constgrep -c freebsd -m ^PROT_ '3 + 4'",
@@ -20,7 +15,7 @@ p = argparse.ArgumentParser(
group = p.add_mutually_exclusive_group()
group.add_argument(
'-e', '--exact',
metavar = '<constant name>',
metavar = 'constant',
# nargs = 1,
default = None,
help = 'Do an exact match for a constant instead of searching for a regex',
@@ -53,33 +48,26 @@ p.add_argument(
p.add_argument(
'-c', '--context',
metavar = '<opt>',
choices = context.oses + list(context.architectures),
default = ['i386','linux'],
metavar = 'arch_or_os',
action = 'append',
help = 'The os/architecture to find constants for (default: linux/i386), choose from: %s' % \
', '.join(sorted(context.oses + context.architectures.keys()))
type = common.context_arg,
choices = common.choices,
help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
)
def main():
args = p.parse_args()
# Find the architecture and os from the list of contexts
for arch in args.context[::-1]:
if arch in context.architectures: break
for os in args.context[::-1]:
if os in context.oses: break
if args.exact:
# This is the simple case
print asm.cpp(args.exact, os = os, arch = arch).strip()
print cpp(args.exact).strip()
else:
# New we search in the right module.
# But first: We find the right module
if os == 'freebsd':
if context.os == 'freebsd':
mod = constants.freebsd
else:
mod = getattr(getattr(constants, os), arch)
mod = getattr(getattr(constants, context.os), context.arch)
# Compile the given regex, for optimized lookup
if args.case_insensitive:
@@ -89,7 +77,10 @@ def main():
# Evaluate the given constant
if args.constant:
constant = safeeval.expr(args.constant)
try:
constant = safeeval.expr(args.constant)
except:
log.error("Could not evaluate constant %r" % args.constant)
else:
constant = None
@@ -122,7 +113,7 @@ def main():
# Output all matching constants
for _, k in sorted(out):
print '#define %s %s' % (k.ljust(maxlen), asm.cpp(k, os = os, arch = arch).strip())
print '#define %s %s' % (k.ljust(maxlen), cpp(k).strip())
# If we are in match_mode, then try to find a combination of
# constants that yield the exact given value
+18 -14
View File
@@ -3,14 +3,9 @@ import argparse
import string
import sys
from pwnlib.log import getLogger
from pwnlib.log import install_default_handler
from pwnlib.util import cyclic
from pwnlib.util import packing
from pwn import *
install_default_handler()
log = getLogger('pwnlib.commandline.cyclic')
from . import common
parser = argparse.ArgumentParser(
description = "Cyclic pattern creator/finder"
@@ -31,11 +26,20 @@ parser.add_argument(
help = 'Size of the unique subsequences (defaults to 4).'
)
parser.add_argument(
'-c', '--context',
metavar = 'context',
action = 'append',
type = common.context_arg,
choices = common.choices,
help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
)
group = parser.add_mutually_exclusive_group(required = True)
group.add_argument(
'-l', '-o', '--offset', '--lookup',
dest = 'lookup',
metavar = '<lookup value>',
metavar = 'lookup_value',
help = 'Do a lookup instead printing the alphabet',
)
@@ -54,10 +58,10 @@ def main():
if args.lookup:
pat = args.lookup
if pat.startswith('0x'):
pat = packing.pack(int(pat[2:], 16), subsize*8, 'little', False)
elif pat.isdigit():
pat = packing.pack(int(pat, 10), subsize*8, 'little', False)
try:
pat = packing.pack(int(pat, 0), subsize*8)
except ValueError:
pass
if len(pat) != subsize:
log.critical('Subpattern must be %d bytes' % subsize)
@@ -67,7 +71,7 @@ def main():
log.critical('Pattern contains characters not present in the alphabet')
sys.exit(1)
offset = cyclic.cyclic_find(pat, alphabet, subsize)
offset = cyclic_find(pat, alphabet, subsize)
if offset == -1:
log.critical('Given pattern does not exist in cyclic pattern')
@@ -76,7 +80,7 @@ def main():
print offset
else:
want = args.count
result = cyclic.cyclic(want, alphabet, subsize)
result = cyclic(want, alphabet, subsize)
got = len(result)
if got < want:
log.failure("Alphabet too small (max length = %i)" % got)
+57 -13
View File
@@ -1,14 +1,11 @@
#!/usr/bin/env python2
import argparse
import string
import sys
from string import hexdigits
from string import whitespace
import pwnlib.log
from pwnlib import asm
from pwnlib.context import context
from pwn import *
pwnlib.log.install_default_handler()
from . import common
parser = argparse.ArgumentParser(
description = 'Disassemble bytes into text format'
@@ -23,25 +20,72 @@ parser.add_argument(
parser.add_argument(
'-c', '--context',
metavar = '<opt>',
choices = context.architectures,
default = 'i386',
help = 'The architecture of the shellcode (default: i386), choose from:\n%s' % ', '.join(context.architectures)
metavar = 'arch_or_os',
action = 'append',
type = common.context_arg,
choices = common.choices,
help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
)
parser.add_argument(
"-a","--address",
metavar='address',
help="Base address",
type=str,
default='0'
)
parser.add_argument(
'--color',
help="Color output",
action='store_true',
default=sys.stdout.isatty()
)
parser.add_argument(
'--no-color',
help="Disable color output",
action='store_false',
dest='color'
)
def main():
args = parser.parse_args()
if len(args.hex) > 0:
dat = ''.join(args.hex)
dat = dat.translate(None, whitespace)
if not set(hexdigits) >= set(dat):
dat = dat.translate(None, string.whitespace)
if not set(string.hexdigits) >= set(dat):
print "This is not a hex string"
exit(-1)
dat = dat.decode('hex')
else:
dat = sys.stdin.read()
print asm.disasm(dat, arch = args.context)
if args.color:
from pygments import highlight
from pygments.formatters import TerminalFormatter
from pwnlib.lexer import PwntoolsLexer
offsets = disasm(dat, vma=safeeval.const(args.address), instructions=False, byte=False)
bytes = disasm(dat, vma=safeeval.const(args.address), instructions=False, offset=False)
instrs = disasm(dat, vma=safeeval.const(args.address), byte=False, offset=False)
# instrs = highlight(instrs, PwntoolsLexer(), TerminalFormatter())
split = lambda x: x.splitlines()
for o,b,i in zip(*list(map(split, (offsets, bytes, instrs)))):
b = b.replace('00', text.red('00'))
b = b.replace('0a', text.red('0a'))
i = highlight(i.strip(), PwntoolsLexer(), TerminalFormatter()).strip()
i = i.replace(',',', ')
print o,b,i
return
print disasm(dat, vma=safeeval.const(args.address))
if __name__ == '__main__': main()
+27 -4
View File
@@ -1,13 +1,16 @@
#!/usr/bin/env python2
import shutil
from argparse import ArgumentParser
from subprocess import CalledProcessError
from subprocess import check_output
from tempfile import NamedTemporaryFile
from pwn import *
def dump(x):
def dump(objdump, path):
n = NamedTemporaryFile(delete=False)
o = check_output(['objdump','-d','-x','-s',x])
o = check_output([objdump,'-d','-x','-s',path])
n.write(o)
n.flush()
return n.name
@@ -17,13 +20,33 @@ def diff(a,b):
except CalledProcessError as e:
return e.output
p = ArgumentParser()
p.add_argument('a')
p.add_argument('b')
def main():
a = p.parse_args()
print diff(dump(a.a), dump(a.b))
with context.silent:
x = ELF(a.a)
y = ELF(a.b)
if x.arch != y.arch:
log.error("Architectures are not the same: %s vs %s" % (x.arch, y.arch))
context.arch = x.arch
objdump = pwnlib.asm.which_binutils('objdump')
tmp = NamedTemporaryFile()
name = tmp.name
shutil.copy(x.path, name)
x = dump(objdump, name)
shutil.copy(y.path, name)
y = dump(objdump, name)
print diff(x, y)
if __name__ == '__main__': main()
+4 -6
View File
@@ -2,11 +2,7 @@
import argparse
import sys
import pwnlib.log
from pwnlib.elf import ELF
from pwnlib.util.fiddling import unhex
pwnlib.log.install_default_handler()
from pwn import *
p = argparse.ArgumentParser()
p.add_argument('elf',help="File to patch")
@@ -22,7 +18,9 @@ def main():
offset = int(a.offset, 16)
bytes = unhex(a.bytes)
elf = ELF(a.elf)
with context.silent:
elf = ELF(a.elf)
elf.write(offset, bytes)
sys.stdout.write(elf.get_data())
+43
View File
@@ -0,0 +1,43 @@
import argparse
import os
parser = argparse.ArgumentParser(
description = 'Prints out error messages'
)
parser.add_argument(
'error', help='Error message or value', type=str
)
def main():
args, unknown = parser.parse_known_args()
try:
value = int(args.error, 0)
if value < 0:
value = -value
if 0x100000000 - value < 0x200:
value = 0x100000000 - value
if value not in os.errno.errorcode:
print "No errno for %s" % value
return
name = os.errno.errorcode[value]
except ValueError:
name = args.error.upper()
if not hasattr(os.errno, name):
print "No errno for %s" % name
return
value = getattr(os.errno, name)
print '#define', name, value
print os.strerror(value)
if __name__ == '__main__': main()
+9 -39
View File
@@ -1,14 +1,9 @@
#!/usr/bin/env python2
import argparse
import os
import re
import sys
import pwnlib.log
import pwnlib.term.text as text
from pwnlib.util.fiddling import hexdump_iter
pwnlib.log.install_default_handler()
from pwn import *
parser = argparse.ArgumentParser(
description = 'Pwnlib HexDump'
@@ -31,9 +26,7 @@ parser.add_argument(
parser.add_argument(
"-l", "--highlight",
help="Byte sequence to highlight. Use '?' to match arbitrary bytes and "\
"'\\?' to match an actual question mark. Use '\\xXX' for non-"\
"printable bytes.",
help="Byte to highlight.",
nargs="*",
)
@@ -90,39 +83,16 @@ def main():
else:
infile.seek(skip, os.SEEK_CUR)
data = infile.read(count)
hl = []
if args.highlight:
def canon(hl):
out = []
i = 0
while i < len(hl):
c = hl[i]
if c == '\\' and len(hl) > i + 1:
c2 = hl[i + 1]
if c2 == 'x':
try:
b = chr(int(hl[i + 2: i + 4], 16))
except:
print 'Bad escape sequence:', hl[i:]
sys.exit(1)
out.append(b)
i += 3
elif c2 in '\\?':
out.append(c2)
i += 1
else:
out.append(c)
elif c == '?':
out.append(None)
else:
out.append(c)
i += 1
return out
highlight = map(canon, args.highlight)
else:
highlight = []
for hs in args.highlight:
for h in hs.split(','):
hl.append(asint(h))
try:
for line in hexdump_iter(infile, width, highlight = highlight, begin = offset + skip):
for line in hexdump_iter(data, width, highlight = hl, begin = offset + skip):
print line
except (KeyboardInterrupt, IOError):
pass
+53
View File
@@ -0,0 +1,53 @@
import argparse
from pwn import *
from . import common
p = argparse.ArgumentParser(
description = 'Strip binaries for CTF usage',
formatter_class = argparse.RawDescriptionHelpFormatter,
)
g = p.add_argument_group("actions")
g.add_argument('-b', '--build-id', help="Strip build ID", action='store_true')
g.add_argument('-p', '--patch', metavar='FUNCTION', help="Patch function", action='append')
p.add_argument('-o', '--output', type=file, default=sys.stdout)
p.add_argument('file', type=file)
def main():
args = p.parse_args()
if not (args.patch or args.build_id):
sys.stderr.write("Must specify at least one action\n")
sys.stderr.write(p.format_usage())
sys.exit(0)
elf = ELF(args.file.name)
context.clear(arch=elf.arch)
if args.build_id:
for offset in pwnlib.libcdb.get_build_id_offsets():
data = elf.read(elf.address + offset + 0xC, 4)
if data == 'GNU\x00':
elf.write(elf.address + offset + 0x10, read('/dev/urandom', 20))
for function in args.patch:
if function not in elf.symbols:
log.error("Could not find function %r" % function)
trap = asm(shellcraft.trap())
offset = elf.symbols[function]
elf.write(elf.address + offset, trap)
result = elf.data
if args.output.isatty():
result = enhex(result)
args.output.write(result)
if __name__ == '__main__':
main()
+103
View File
@@ -0,0 +1,103 @@
import argparse
import sys
from pwn import *
from . import common
parser = argparse.ArgumentParser(
description = 'Shellcode encoder'
)
parser.add_argument(
"-f", "--format",
help="Output format (defaults to hex for ttys, otherwise raw)",
choices=['raw', 'hex', 'string', 'elf']
)
parser.add_argument(
"-o","--output",
metavar='file',
help="Output file (defaults to stdout)",
type=argparse.FileType('w'),
default=sys.stdout
)
parser.add_argument(
'-c', '--context',
metavar = 'context',
action = 'append',
type = common.context_arg,
choices = common.choices,
help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
)
parser.add_argument(
'-p', '--alphanumeric',
action='store_true',
help = 'Encode the shellcode with an alphanumeric encoder'
)
parser.add_argument(
'-v', '--avoid',
action='append',
help = 'Encode the shellcode to avoid the listed bytes'
)
parser.add_argument(
'-n', '--newline',
dest='avoid',
action='append_const',
const='\n',
help = 'Encode the shellcode to avoid newlines'
)
parser.add_argument(
'-z', '--zero',
dest='avoid',
action='append_const',
const='\x00',
help = 'Encode the shellcode to avoid NULL bytes'
)
parser.add_argument(
'-d',
'--debug',
help='Debug the shellcode with GDB',
action='store_true'
)
def main():
args = parser.parse_args()
tty = args.output.isatty()
if sys.stdin.isatty():
parser.print_usage()
sys.exit(0)
data = sys.stdin.read()
output = data
fmt = args.format or ('hex' if tty else 'raw')
formatters = {'r':str, 'h':enhex, 's':repr}
if args.alphanumeric:
output = alphanumeric(output)
if args.avoid:
output = avoid(output, ''.join(args.avoid))
if args.debug:
proc = gdb.debug_shellcode(output, arch=context.arch)
proc.interactive()
sys.exit(0)
if fmt[0] == 'e':
sys.stdout.write(make_elf(output))
else:
args.output.write(formatters[fmt[0]](output))
if tty and fmt is not 'raw':
args.output.write('\n')
if __name__ == '__main__': main()
+142 -16
View File
@@ -67,6 +67,7 @@ p.add_argument(
'a', 'asm', 'assembly',
'p',
'i', 'hexii',
'e', 'elf',
'default'],
default = 'default',
help = 'Output format (default: hex), choose from {r}aw, {s}tring, {c}-style array, {h}ex string, hex{i}i, {a}ssembly code, {p}reprocssed code',
@@ -97,6 +98,85 @@ p.add_argument(
action='store_true'
)
p.add_argument(
'-b',
'--before',
help='Insert a debug trap before the code',
action='store_true'
)
p.add_argument(
'-a',
'--after',
help='Insert a debug trap after the code',
action='store_true'
)
p.add_argument(
'-v', '--avoid',
action='append',
help = 'Encode the shellcode to avoid the listed bytes'
)
p.add_argument(
'-n', '--newline',
dest='avoid',
action='append_const',
const='\n',
help = 'Encode the shellcode to avoid newlines'
)
p.add_argument(
'-z', '--zero',
dest='avoid',
action='append_const',
const='\x00',
help = 'Encode the shellcode to avoid NULL bytes'
)
p.add_argument(
'-r',
'--run',
help="Run output",
action='store_true'
)
p.add_argument(
'--color',
help="Color output",
action='store_true',
default=sys.stdout.isatty()
)
p.add_argument(
'--no-color',
help="Disable color output",
action='store_false',
dest='color'
)
p.add_argument(
'--syscalls',
help="List syscalls",
action='store_true'
)
p.add_argument(
'--address',
help="Load address",
default=None
)
def get_template(name):
func = shellcraft
for attr in name.split('.'):
func = getattr(func, attr)
return func
def is_not_a_syscall_template(name):
template_src = shellcraft._get_source(name)
return 'man 2' not in read(template_src)
def main():
# Banner must be added here so that it doesn't appear in the autodoc
# generation for command line tools
@@ -104,18 +184,15 @@ def main():
args = p.parse_args()
if not args.shellcode:
print '\n'.join(shellcraft.templates)
templates = shellcraft.templates
if not args.syscalls:
templates = filter(is_not_a_syscall_template, templates)
print '\n'.join(templates)
exit()
if args.format == 'default':
if sys.stdout.isatty():
args.format = 'hex'
else:
args.format = 'raw'
func = shellcraft
for attr in args.shellcode.split('.'):
func = getattr(func, attr)
func = get_template(args.shellcode)
if args.show:
# remove doctests
@@ -184,23 +261,72 @@ def main():
map(common.context_arg, args.shellcode.split('.'))
code = func(*args.args)
if args.before:
code = shellcraft.trap() + code
if args.after:
code = code + shellcraft.trap()
if args.format in ['a', 'asm', 'assembly']:
if args.color:
from pygments import highlight
from pygments.formatters import TerminalFormatter
from pwnlib.lexer import PwntoolsLexer
code = highlight(code, PwntoolsLexer(), TerminalFormatter())
print code
exit()
if args.format == 'p':
print cpp(code)
exit()
code = asm(code)
assembly = code
vma = args.address
if vma:
vma = eval(vma)
if args.format in ['e','elf']:
args.format = 'default'
try: os.fchmod(args.out.fileno(), 0700)
except OSError: pass
if not args.avoid:
code = read(make_elf_from_assembly(assembly, vma=vma))
else:
code = asm(assembly)
code = encode(code, args.avoid)
code = make_elf(code, vma=vma)
# code = read(make_elf(encode(asm(code), args.avoid)))
else:
code = encode(asm(assembly), args.avoid)
if args.format == 'default':
if args.out.isatty():
args.format = 'hex'
else:
args.format = 'raw'
arch = args.shellcode.split('.')[0]
if args.debug:
arch = args.shellcode.split('.')[0]
proc = gdb.debug_shellcode(code, arch=arch)
if not args.avoid:
proc = gdb.debug_assembly(assembly, arch=arch, vma=vma)
else:
proc = gdb.debug_shellcode(code, arch=arch, vma=vma)
proc.interactive()
sys.exit(0)
if args.run:
proc = run_shellcode(code, arch=arch)
proc.interactive()
sys.exit(0)
if args.format in ['s', 'str', 'string']:
code = _string(code)
code = _string(code) + '"\n'
elif args.format == 'c':
code = '{' + ', '.join(map(hex, bytearray(code))) + '}' + '\n'
elif args.format in ['h', 'hex']:
@@ -209,8 +335,8 @@ def main():
code = hexii(code) + '\n'
if not sys.stdin.isatty():
sys.stdout.write(sys.stdin.read())
args.out.write(sys.stdin.read())
sys.stdout.write(code)
args.out.write(code)
if __name__ == '__main__': main()
+10 -7
View File
@@ -46,6 +46,7 @@ from types import ModuleType
from ..context import context
from ..util import safeeval
from .constant import Constant
class ConstantsModule(ModuleType):
@@ -67,6 +68,8 @@ class ConstantsModule(ModuleType):
True
"""
Constant = Constant
possible_submodules = set(context.oses) | set(context.architectures)
def __init__(self, name, module):
@@ -122,14 +125,14 @@ class ConstantsModule(ModuleType):
Example:
>>> with context.local(arch = 'i386', os = 'linux'):
... print constants.eval('SYS_execve + PROT_WRITE')
13
... print 13 == constants.eval('SYS_execve + PROT_WRITE')
True
>>> with context.local(arch = 'amd64', os = 'linux'):
... print constants.eval('SYS_execve + PROT_WRITE')
61
... print 61 == constants.eval('SYS_execve + PROT_WRITE')
True
>>> with context.local(arch = 'amd64', os = 'linux'):
... print constants.eval('SYS_execve + PROT_WRITE')
61
... print 61 == constants.eval('SYS_execve + PROT_WRITE')
True
"""
if not isinstance(string, str):
return string
@@ -138,7 +141,7 @@ class ConstantsModule(ModuleType):
if key not in self._env_store:
self._env_store[key] = {key: getattr(self, key) for key in dir(self) if not key.endswith('__')}
return safeeval.values(string, self._env_store[key])
return Constant('(%s)' % string, safeeval.values(string, self._env_store[key]))
# To prevent garbage collection
+1
View File
@@ -0,0 +1 @@
linux
View File
Whitespace-only changes.
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+1
View File
@@ -0,0 +1 @@
thumb.py
+29
View File
@@ -0,0 +1,29 @@
from pwnlib.constants.constant import Constant
terminate = Constant('terminate', 1)
SYS_terminate = Constant('SYS_terminate', 1)
__NR_terminate = Constant('__NR_terminate', 1)
transmit = Constant('transmit', 2)
SYS_transmit = Constant('SYS_transmit', 2)
__NR_transmit = Constant('__NR_transmit', 2)
receive = Constant('receive', 3)
SYS_receive = Constant('SYS_receive', 3)
__NR_receive = Constant('__NR_receive', 3)
fdwait = Constant('fdwait', 4)
SYS_fdwait = Constant('SYS_fdwait', 4)
__NR_fdwait = Constant('__NR_fdwait', 4)
allocate = Constant('allocate', 5)
SYS_allocate = Constant('SYS_allocate', 5)
__NR_allocate = Constant('__NR_allocate', 5)
deallocate = Constant('deallocate', 6)
SYS_deallocate = Constant('SYS_deallocate', 6)
__NR_deallocate = Constant('__NR_deallocate', 6)
random = Constant('random', 7)
SYS_random = Constant('SYS_random', 7)
__NR_random = Constant('__NR_random', 7)
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+333 -19
View File
@@ -5,12 +5,30 @@ Implements context management so that nested/scoped contexts and threaded
contexts work properly and as expected.
"""
import collections
import functools
import logging
import os
import platform
import socket
import string
import subprocess
import sys
import threading
import time
import socks
from ..device import Device
from ..timeout import Timeout
_original_socket = socket.socket
class _devnull(object):
name = None
def write(self, *a, **kw): pass
def read(self, *a, **kw): return ''
def flush(self, *a, **kw): pass
def close(self, *a, **kw): pass
class _defaultdict(dict):
"""
@@ -305,20 +323,29 @@ class ContextType(object):
#: Default values for :class:`pwnlib.context.ContextType`
defaults = {
'adb_host': 'localhost',
'adb_port': 5037,
'arch': 'i386',
'aslr': True,
'binary': None,
'bits': 32,
'device': os.getenv('ANDROID_SERIAL', None) or None,
'endian': 'little',
'kernel': None,
'log_level': logging.INFO,
'log_file': _devnull(),
'randomize': False,
'newline': '\n',
'noptrace': False,
'os': 'linux',
'proxy': None,
'signed': False,
'timeout': Timeout.maximum,
'terminal': None,
'timeout': Timeout.maximum,
}
#: Valid values for :meth:`pwnlib.context.ContextType.os`
oses = sorted(('linux','freebsd','windows'))
oses = sorted(('linux','freebsd','windows','cgc','android'))
big_32 = {'endian': 'big', 'bits': 32}
big_64 = {'endian': 'big', 'bits': 64}
@@ -440,7 +467,7 @@ class ContextType(object):
v = sorted("%s = %r" % (k,v) for k,v in self._tls._current.items())
return '%s(%s)' % (self.__class__.__name__, ', '.join(v))
def local(self, **kwargs):
def local(self, function=None, **kwargs):
"""local(**kwargs) -> context manager
Create a context manager for use with the ``with`` statement.
@@ -479,13 +506,46 @@ class ContextType(object):
def __exit__(a, *b, **c):
self._tls.pop()
def __call__(self, function, *a, **kw):
@functools.wraps(function)
def inner(*a, **kw):
with self:
return function(*a, **kw)
return inner
return LocalContext()
def clear(self):
@property
def silent(self, function=None):
"""Disable all non-error logging within the enclosed scope.
"""
return self.local(function, log_level='error')
@property
def quiet(self, function=None):
"""Disables all non-error logging within the enclosed scope,
*unless* the debugging level is set to 'debug' or lower."""
level = 'error'
if context.log_level <= logging.DEBUG:
level = None
return self.local(function, log_level=level)
@property
def verbose(self):
"""Enable all logging within the enclosed scope.
"""
return self.local(log_level='debug')
def clear(self, *a, **kw):
"""
Clears the contents of the context.
All values are set to their defaults.
Arguments:
a: Arguments passed to ``update``
kw: Arguments passed to ``update``
Examples:
>>> # Default value
@@ -500,10 +560,27 @@ class ContextType(object):
"""
self._tls._current.clear()
if a or kw:
self.update(*a, **kw)
@property
def native(self):
if context.os in ('android', 'cgc'):
return False
arch = context.arch
with context.local(arch = platform.machine()):
platform_arch = context.arch
if arch in ('i386', 'amd64') and platform_arch in ('i386', 'amd64'):
return True
return arch == platform_arch
@_validator
def arch(self, arch):
"""
Target machine architecture.
Target binary architecture.
Allowed values are listed in :attr:`pwnlib.context.ContextType.architectures`.
@@ -565,17 +642,22 @@ class ContextType(object):
>>> vars(context) == {'arch': 'powerpc64', 'bits': 64, 'endian': 'big'}
True
"""
# Lowercase
arch = arch.lower()
# Attempt to perform convenience and legacy compatibility
# transformations.
# Attempt to perform convenience and legacy compatibility transformations.
# We have to make sure that x86_64 appears before x86 for this to work correctly.
transform = [('ppc', 'powerpc'), ('x86_64', 'amd64'), ('x86', 'i386')]
transform = [('ppc64', 'powerpc64'),
('ppc', 'powerpc'),
('x86_64', 'amd64'),
('x86', 'i386'),
('i686', 'i386'),
('armeabi', 'arm'),
('arm64', 'aarch64')]
for k, v in transform:
if arch.startswith(k):
arch = arch.replace(k,v,1)
arch = v
break
try:
defaults = ContextType.architectures[arch]
@@ -588,6 +670,33 @@ class ContextType(object):
return arch
@_validator
def aslr(self, aslr):
"""
ASLR settings for new processes.
If ``False``, attempt to disable ASLR in all processes which are
created via ``personality`` (``setarch -R``) and ``setrlimit``
(``ulimit -s unlimited``).
The ``setarch`` changes are lost if a ``setuid`` binary is executed.
"""
return bool(aslr)
@_validator
def kernel(self, arch):
"""
Target machine's kernel architecture.
Usually, this is the same as ``arch``, except when
running a 32-bit binary on a 64-bit kernel (e.g. i386-on-amd64).
Even then, this doesn't matter much -- only when the the segment
registers need to be known
"""
with context.local(arch=arch):
return context.arch
@_validator
def bits(self, bits):
"""
@@ -635,13 +744,14 @@ class ContextType(object):
# Cyclic imports... sorry Idolf.
from ..elf import ELF
e = ELF(binary)
if not isinstance(binary, ELF):
binary = ELF(binary)
self.arch = e.arch
self.bits = e.bits
self.endian = e.endian
self.arch = binary.arch
self.bits = binary.bits
self.endian = binary.endian
return e
return binary
@property
def bytes(self):
@@ -666,7 +776,6 @@ class ContextType(object):
def bytes(self, value):
self.bits = value*8
@_validator
def endian(self, endianness):
"""
@@ -741,6 +850,70 @@ class ContextType(object):
permitted = sorted(level_names)
raise AttributeError('log_level must be an integer or one of %r' % permitted)
@_validator
def log_file(self, value):
r"""
Sets the target file for all logging output.
Works in a similar fashion to :attr:`log_level`.
Examples:
>>> context.log_file = 'foo.txt' #doctest: +ELLIPSIS
>>> log.debug('Hello!') #doctest: +ELLIPSIS
>>> with context.local(log_level='ERROR'): #doctest: +ELLIPSIS
... log.info('Hello again!')
>>> with context.local(log_file='bar.txt'):
... log.debug('Hello from bar!')
>>> log.info('Hello from foo!')
>>> file('foo.txt').readlines()[-3] #doctest: +ELLIPSIS
'...:DEBUG:...:Hello!\n'
>>> file('foo.txt').readlines()[-2] #doctest: +ELLIPSIS
'...:INFO:...:Hello again!\n'
>>> file('foo.txt').readlines()[-1] #doctest: +ELLIPSIS
'...:INFO:...:Hello from foo!\n'
>>> file('bar.txt').readlines()[-1] #doctest: +ELLIPSIS
'...:DEBUG:...:Hello from bar!\n'
"""
if isinstance(value, (str,unicode)):
modes = ('w', 'wb', 'a', 'ab')
# check if mode was specified as "[value],[mode]"
if ',' not in value:
value += ',a'
filename, mode = value.rsplit(',', 1)
value = open(filename, mode)
elif not isinstance(value, (file)):
raise AttributeError('log_file must be a file')
# Is this the same file we already have open?
# If so, don't re-print the banner.
if self.log_file and not isinstance(self.log_file, _devnull):
a = os.fstat(value.fileno()).st_ino
b = os.fstat(self.log_file.fileno()).st_ino
if a == b:
return self.log_file
iso_8601 = '%Y-%m-%dT%H:%M:%S'
lines = [
'=' * 78,
' Started at %s ' % time.strftime(iso_8601),
' sys.argv = [',
]
for arg in sys.argv:
lines.append(' %r,' % arg)
lines.append(' ]')
lines.append('=' * 78)
for line in lines:
value.write('=%-78s=\n' % line)
value.flush()
return value
@property
def mask(self):
return (1 << self.bits) - 1
@_validator
def os(self, os):
@@ -757,16 +930,21 @@ class ContextType(object):
>>> context.os = 'foobar' #doctest: +ELLIPSIS
Traceback (most recent call last):
...
AttributeError: os must be one of ['freebsd', 'linux', 'windows']
AttributeError: os must be one of ['android', 'cgc', 'freebsd', 'linux', 'windows']
"""
os = os.lower()
if os not in ContextType.oses:
raise AttributeError("os must be one of %r" % sorted(ContextType.oses))
raise AttributeError("os must be one of %r" % ContextType.oses)
return os
@_validator
def randomize(self, r):
"""
Global flag that lots of things should be randomized.
"""
return bool(r)
@_validator
def signed(self, signed):
@@ -827,6 +1005,111 @@ class ContextType(object):
return [value]
return value
@property
def abi(self):
return self._abi
@_validator
def proxy(self, proxy):
"""
Default proxy for all socket connections.
Accepts either a string (hostname or IP address) for a SOCKS5 proxy on
the default port, **or** a ``tuple`` passed to ``socks.set_default_proxy``,
e.g. ``(socks.SOCKS4, 'localhost', 1234)``.
>>> context.proxy = 'localhost' #doctest: +ELLIPSIS
>>> r=remote('google.com', 80)
Traceback (most recent call last):
...
ProxyConnectionError: Error connecting to SOCKS5 proxy localhost:1080: [Errno 111] Connection refused
>>> context.proxy = None
>>> r=remote('google.com', 80, level='error')
"""
if not proxy:
socket.socket = _original_socket
return None
if isinstance(proxy, str):
proxy = (socks.SOCKS5, proxy)
if not isinstance(proxy, collections.Iterable):
raise AttributeError('proxy must be a string hostname, or tuple of arguments for socks.set_default_proxy')
socks.set_default_proxy(*proxy)
socket.socket = socks.socksocket
return proxy
@_validator
def noptrace(self, value):
"""Disable all actions which rely on ptrace.
This is useful for switching between local exploitation with a debugger,
and remote exploitation (without a debugger).
This option can be set with the ``NOPTRACE`` command-line argument.
"""
return bool(value)
@_validator
def adb_host(self, value):
"""Sets the target host which is used for ADB.
This is useful for Android exploitation.
The default value is inherited from ANDROID_ADB_SERVER_HOST, or set
to the default 'localhost'.
"""
return str(value)
@_validator
def adb_port(self, value):
"""Sets the target port which is used for ADB.
This is useful for Android exploitation.
The default value is inherited from ANDROID_ADB_SERVER_PORT, or set
to the default 5037.
"""
return int(value)
@_validator
def device(self, device):
"""Sets the device being operated on.
"""
if isinstance(device, Device):
self.arch = device.arch or self.arch
self.bits = device.bits or self.bits
self.endian = device.endian or self.endian
elif isinstance(device, str):
device = Device(device)
else:
raise AttributeError("device must be either a Device object or a serial number as a string")
return device
@property
def adb(self):
"""Returns an argument array for connecting to adb."""
command = ['adb']
if self.adb_host != self.defaults['adb_host']:
command += ['-H', self.adb_host]
if self.adb_port != self.defaults['adb_port']:
command += ['-P', str(self.adb_port)]
if self.device:
command += ['-s', str(self.device)]
return command
#*************************************************************************
# ALIASES
#*************************************************************************
@@ -909,3 +1192,34 @@ class ContextType(object):
#: Consider it a shorthand to passing ``os=`` and ``arch=`` to every single
#: function call.
context = ContextType()
# Inherit default ADB values
if 'ANDROID_ADB_SERVER_HOST' in os.environ:
context.adb_host = os.environ.get('ANDROID_ADB_SERVER_HOST')
if 'ANDROID_ADB_SERVER_PORT' in os.environ:
context.adb_port = int(os.getenv('ANDROID_ADB_SERVER_PORT'))
def LocalContext(function):
"""
Wraps the specied function on a context.local() block, using kwargs.
Example:
>>> @LocalContext
... def printArch():
... print(context.arch)
>>> printArch()
i386
>>> printArch(arch='arm')
arm
"""
@functools.wraps(function)
def setter(*a, **kw):
# Fast path to skip adding a Context frame
if not kw:
return function(*a)
with context.local(**{k:kw.pop(k) for k,v in kw.items() if isinstance(getattr(ContextType, k, None), property)}):
return function(*a, **kw)
return setter
+1
View File
@@ -0,0 +1 @@
linux
+1
View File
@@ -0,0 +1 @@
arm.h
+1
View File
@@ -0,0 +1 @@
arm.h
+1
View File
@@ -0,0 +1 @@
arm.h
+21
View File
@@ -0,0 +1,21 @@
#define allocate 5
#define SYS_allocate 5
#define __NR_allocate 5
#define deallocate 6
#define SYS_deallocate 6
#define __NR_deallocate 6
#define fdwait 4
#define SYS_fdwait 4
#define __NR_fdwait 4
#define random 7
#define SYS_random 7
#define __NR_random 7
#define receive 3
#define SYS_receive 3
#define __NR_receive 3
#define terminate 1
#define SYS_terminate 1
#define __NR_terminate 1
#define transmit 2
#define SYS_transmit 2
#define __NR_transmit 2
+1
View File
@@ -0,0 +1 @@
arm.h
+1
View File
@@ -0,0 +1 @@
arm.h
+1
View File
@@ -0,0 +1 @@
arm.h
Loaded 100 of 3348 files, more files were not shown because too many files have changed in this diff. Show more