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
75a7b122
Commit
75a7b122
authored
Mar 29, 2012
by
Luke Macken
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'std-payloads' of
https://github.com/mgedmin/pyrasite
into mgedmin-std-payloads
parents
0c0165e5
016e2d80
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
5 deletions
+35
-5
pyrasite/main.py
pyrasite/main.py
+35
-5
No files found.
pyrasite/main.py
View file @
75a7b122
...
@@ -47,17 +47,41 @@ def ptrace_check():
...
@@ -47,17 +47,41 @@ def ptrace_check():
print
(
""
)
print
(
""
)
def
get_payload_dir
():
return
os
.
path
.
join
(
os
.
path
.
dirname
(
pyrasite
.
__file__
),
'payloads'
)
def
list_payloads
():
return
sorted
(
fn
for
fn
in
os
.
listdir
(
get_payload_dir
())
if
fn
.
endswith
(
'.py'
)
and
not
fn
.
startswith
(
'_'
))
def
expand_payload
(
payload
):
"""If a standard payload with this name exists, return its full path.
Otherwise return the input value unchanged.
"""
if
os
.
path
.
sep
not
in
payload
:
fn
=
os
.
path
.
join
(
get_payload_dir
(),
payload
)
if
os
.
path
.
isfile
(
fn
):
return
fn
return
payload
def
main
():
def
main
():
ptrace_check
()
ptrace_check
()
parser
=
argparse
.
ArgumentParser
(
parser
=
argparse
.
ArgumentParser
(
description
=
'pyrasite - inject code into a running python process'
,
description
=
'pyrasite - inject code into a running python process'
,
epilog
=
"For updates, visit https://github.com/lmacken/pyrasite"
)
epilog
=
"For updates, visit https://github.com/lmacken/pyrasite"
)
parser
.
add_argument
(
'pid'
,
parser
.
add_argument
(
'pid'
,
nargs
=
'?'
,
help
=
"The ID of the process to inject code into"
)
help
=
"The ID of the process to inject code into"
)
parser
.
add_argument
(
'
filename
'
,
parser
.
add_argument
(
'
payload'
,
nargs
=
'?'
,
default
=
'
'
,
help
=
"The Python script to be executed inside the"
help
=
"The Python script to be executed inside the"
" running process, also referred to as 'payload'"
)
" running process. Can be one of the standard"
" payloads (see --list-payloads) or a filname."
)
parser
.
add_argument
(
'-l'
,
'--list-payloads'
,
help
=
'List standard payloads'
,
default
=
False
,
action
=
'store_const'
,
const
=
True
)
parser
.
add_argument
(
'--gdb-prefix'
,
dest
=
'gdb_prefix'
,
parser
.
add_argument
(
'--gdb-prefix'
,
dest
=
'gdb_prefix'
,
help
=
'GDB prefix (if specified during installation)'
,
help
=
'GDB prefix (if specified during installation)'
,
default
=
""
)
default
=
""
)
...
@@ -70,19 +94,25 @@ def main():
...
@@ -70,19 +94,25 @@ def main():
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
if
args
.
list_payloads
:
print
(
"Available payloads:"
)
for
payload
in
list_payloads
():
print
(
" %s"
%
payload
)
sys
.
exit
()
try
:
try
:
pid
=
int
(
args
.
pid
)
pid
=
int
(
args
.
pid
)
except
ValueError
:
except
ValueError
:
print
(
"Error: The first argument must be a pid"
)
print
(
"Error: The first argument must be a pid"
)
sys
.
exit
(
2
)
sys
.
exit
(
2
)
filename
=
args
.
filename
filename
=
expand_payload
(
args
.
payload
)
if
filename
:
if
filename
:
if
not
os
.
path
.
exists
(
filename
):
if
not
os
.
path
.
exists
(
filename
):
print
(
"Error: Invalid path or file doesn't exist"
)
print
(
"Error: Invalid path or file doesn't exist"
)
sys
.
exit
(
3
)
sys
.
exit
(
3
)
else
:
else
:
print
(
"Error: The second argument must be a filename"
)
print
(
"Error: The second argument must be a filename
or a payload name
"
)
sys
.
exit
(
4
)
sys
.
exit
(
4
)
pyrasite
.
inject
(
pid
,
filename
,
verbose
=
args
.
verbose
,
pyrasite
.
inject
(
pid
,
filename
,
verbose
=
args
.
verbose
,
...
...
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