Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyrasite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
pyrasite
Commits
e720e770
Commit
e720e770
authored
Sep 24, 2011
by
Kenny Shen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified main script to use argparse, additional flag for specifying prefixes to gdb
parent
e3373c06
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
13 deletions
+43
-13
README.rst
README.rst
+15
-1
pyrasite/inject.py
pyrasite/inject.py
+4
-2
pyrasite/main.py
pyrasite/main.py
+24
-10
No files found.
README.rst
View file @
e720e770
...
...
@@ -6,7 +6,7 @@ Injects code into a running Python process.
Requirements
~~~~~~~~~~~~
- gdb (https://www.gnu.org/s/gdb)
- gdb (https://www.gnu.org/s/gdb)
(version 7.3+)
Download
~~~~~~~~
...
...
@@ -113,6 +113,20 @@ Dumping modules, thread stacks, and forcing garbage collection
payloads/dump_modules.py
payloads/dump_stacks.py
payloads/force_garbage_collection.py
Additional installation notes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mac OS X
--------
If you don't want to override Apple's default gdb, install the latest version of gdb with a prefix (e.g. gnu)
::
$ ./configure --program-prefix=gnu
$ pyrasite <PID> payloads/reverse_python_shell.py --prefix="gnu"
Mailing List
~~~~~~~~~~~~
...
...
pyrasite/inject.py
View file @
e720e770
...
...
@@ -30,12 +30,14 @@ Authors:
import
os
,
subprocess
class
CodeInjector
(
object
):
def
__init__
(
self
,
pid
,
filename
,
verbose
=
False
):
def
__init__
(
self
,
pid
,
filename
,
verbose
=
False
,
gdb_prefix
=
""
):
self
.
pid
=
pid
self
.
filename
=
os
.
path
.
abspath
(
filename
)
self
.
verbose
=
verbose
self
.
gdb_prefix
=
gdb_prefix
def
inject
(
self
):
gdb_cmds
=
[
...
...
@@ -46,7 +48,7 @@ class CodeInjector(object):
'PyRun_SimpleString("execfile(
\
\
"%s
\
\
")")'
%
self
.
filename
,
'PyGILState_Release($1)'
,
]
self
.
_run
(
'
gdb -p %d -batch %s'
%
(
self
.
pid
,
self
.
_run
(
'
%sgdb -p %d -batch %s'
%
(
self
.
gdb_prefix
,
self
.
pid
,
' '
.
join
([
"-eval-command='call %s'"
%
cmd
for
cmd
in
gdb_cmds
])))
def
_run
(
self
,
cmd
):
...
...
pyrasite/main.py
View file @
e720e770
...
...
@@ -16,28 +16,42 @@
# Copyright (C) 2011 Red Hat, Inc.
import
os
,
sys
import
argparse
from
inject
import
CodeInjector
def
main
():
if
len
(
sys
.
argv
)
<
3
:
print
(
"Usage: %s <pid> <filename>"
%
sys
.
argv
[
0
])
print
(
"
\
n
pid:
\
t
The ID of the process to inject code into"
)
print
(
" filename:
\
t
The .py file to inject into the process
\
n
"
)
parser
=
argparse
.
ArgumentParser
(
description
=
'pyrasite - inject code into a running python process'
,
epilog
=
"For updates, visit https://github.com/lmacken/pyrasite"
)
parser
.
add_argument
(
'pid'
,
help
=
"The ID of the process to inject code into"
)
parser
.
add_argument
(
'filename'
,
default
=
None
,
nargs
=
'?'
,
help
=
"The second argument must be a filename"
)
parser
.
add_argument
(
'--gdb-prefix'
,
dest
=
'gdb_prefix'
,
help
=
'GDB prefix (if specified during installation)'
,
default
=
""
)
parser
.
add_argument
(
'--verbose'
,
dest
=
'verbose'
,
help
=
'Verbose mode'
,
default
=
False
,
action
=
'store_const'
,
const
=
True
)
if
len
(
sys
.
argv
)
==
1
:
parser
.
print_help
()
sys
.
exit
(
1
)
args
=
parser
.
parse_args
()
try
:
pid
=
int
(
sys
.
argv
[
1
]
)
pid
=
int
(
args
.
pid
)
except
ValueError
:
print
"Error: The first argument must be a pid"
sys
.
exit
(
2
)
filename
=
sys
.
argv
[
2
]
if
not
os
.
path
.
exists
(
filename
):
filename
=
args
.
filename
if
filename
:
if
not
os
.
path
.
exists
(
filename
):
print
"Error: Invalid path or file doesn't exist"
sys
.
exit
(
3
)
else
:
print
"Error: The second argument must be a filename"
sys
.
exit
(
3
)
sys
.
exit
(
4
)
injector
=
CodeInjector
(
pid
,
filename
,
verbose
=
'-v'
in
sys
.
argv
)
injector
=
CodeInjector
(
pid
,
filename
,
verbose
=
args
.
verbose
,
gdb_prefix
=
args
.
gdb_prefix
)
injector
.
inject
()
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment