Commit 9e28293d authored by Dusty Mabe's avatar Dusty Mabe

main: Add in --output option that allows output to be redirected to a

the local terminal rather than stdout/stderr of attached process.
parent 0ae959ac
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
:: ::
usage: pyrasite [-h] [--gdb-prefix GDB_PREFIX] [--verbose] pid [filepath|payloadname] usage: pyrasite [-h] [--gdb-prefix GDB_PREFIX] [--verbose] [--output OUTPUT_TYPE] pid [filepath|payloadname]
pyrasite --list-payloads pyrasite --list-payloads
pyrasite - inject code into a running python process pyrasite - inject code into a running python process
...@@ -20,6 +20,13 @@ ...@@ -20,6 +20,13 @@
--gdb-prefix GDB_PREFIX --gdb-prefix GDB_PREFIX
GDB prefix (if specified during installation) GDB prefix (if specified during installation)
--verbose Verbose mode --verbose Verbose mode
--output OUTPUT_TYPE This option controls where the output from
the executed payload will be printed. If
the value is 'procstreams' (the default) then
the output is sent to the stdout/stderr of the
process. If the value is 'localterm' then the
output is piped back and printed on the local
terminal where pyrasite is being run.
--list-payloads List payloads that are delivered by pyrasite --list-payloads List payloads that are delivered by pyrasite
For updates, visit https://github.com/lmacken/pyrasite For updates, visit https://github.com/lmacken/pyrasite
......
...@@ -87,6 +87,11 @@ def main(): ...@@ -87,6 +87,11 @@ def main():
default="") default="")
parser.add_argument('--verbose', dest='verbose', help='Verbose mode', parser.add_argument('--verbose', dest='verbose', help='Verbose mode',
default=False, action='store_const', const=True) default=False, action='store_const', const=True)
parser.add_argument('--output', dest='output_type', default='procstreams',
action='store',
help="Set where output is to be printed. 'procstreams'"
" prints output in stdout/stderr of running process"
" and 'localterm' prints output in local terminal.")
if len(sys.argv) == 1: if len(sys.argv) == 1:
parser.print_help() parser.print_help()
...@@ -100,6 +105,11 @@ def main(): ...@@ -100,6 +105,11 @@ def main():
print(" %s" % payload) print(" %s" % payload)
sys.exit() sys.exit()
# Make sure the output type is valid (procstreams || localterm)
if args.output_type != 'procstreams' and args.output_type != 'localterm':
print("Error: --output arg must be 'procstreams' or 'localterm'")
sys.exit(5)
try: try:
pid = int(args.pid) pid = int(args.pid)
except ValueError: except ValueError:
...@@ -115,6 +125,24 @@ def main(): ...@@ -115,6 +125,24 @@ def main():
print("Error: The second argument must be a filename or a payload name") print("Error: The second argument must be a filename or a payload name")
sys.exit(4) sys.exit(4)
if args.output_type == 'localterm':
# Create new IPC connection to the process.
ipc = pyrasite.PyrasiteIPC(pid, 'ReversePythonConnection')
ipc.connect()
print("Pyrasite Shell %s" % pyrasite.__version__)
print("Connected to '%s'" % ipc.title)
# Read in the payload
fd = open(filename)
payload = fd.read()
fd.close
# Run the payload, print output, close ipc connection
print(ipc.cmd(payload))
ipc.close()
else:
pyrasite.inject(pid, filename, verbose=args.verbose, pyrasite.inject(pid, filename, verbose=args.verbose,
gdb_prefix=args.gdb_prefix) gdb_prefix=args.gdb_prefix)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment