-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
768b24e
commit 11fa0d8
Showing
1,656 changed files
with
27,374 additions
and
858 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ addons: | |
apt: | ||
packages: | ||
- gcc-multilib | ||
- gcc-4.6-arm-linux-gnueabihf | ||
cache: | ||
- pip | ||
- directories: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,8 @@ | ||
# Promote useful stuff to toplevel | ||
from .toplevel import * | ||
|
||
log = getLogger('pwnlib.exploit') | ||
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: | ||
context.log_file = args['LOG_FILE'] | ||
# 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.install_default_handler() | ||
|
||
closure() | ||
del closure | ||
log = pwnlib.log.getLogger('pwnlib.exploit') | ||
args = pwnlib.args.args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
version = __version__ | ||
|
||
__all__ = [ | ||
'args', | ||
'asm', | ||
'atexception', | ||
'atexit', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#!/usr/bin/env python2 | ||
""" | ||
""" | ||
import collections | ||
import logging | ||
import os | ||
import string | ||
import sys | ||
from .context import context | ||
from . import term | ||
|
||
term_mode = False | ||
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_multiply(v): | ||
context.defaults['multiply'] = int(v, 0) | ||
|
||
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, | ||
'MULTIPLY': set_multiply, | ||
'TIMEOUT': set_timeout | ||
} | ||
|
||
def initialize(): | ||
global args, term_mode | ||
|
||
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() |
Oops, something went wrong.