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
24b39a21
Commit
24b39a21
authored
Mar 13, 2012
by
Luke Macken
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15 from Qalthos/develop
Add Python 3 support
parents
7a9ec6dc
538e6025
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
24 additions
and
20 deletions
+24
-20
pyrasite/__init__.py
pyrasite/__init__.py
+4
-4
pyrasite/inject.py
pyrasite/inject.py
+2
-2
pyrasite/inspect.py
pyrasite/inspect.py
+1
-1
pyrasite/ipc.py
pyrasite/ipc.py
+5
-4
pyrasite/payloads/dump_stacks.py
pyrasite/payloads/dump_stacks.py
+1
-1
pyrasite/reverse.py
pyrasite/reverse.py
+6
-3
pyrasite/utils.py
pyrasite/utils.py
+5
-5
No files found.
pyrasite/__init__.py
View file @
24b39a21
from
inject
import
CodeInjector
from
inspect
import
ObjectInspector
from
ipc
import
PyrasiteIPC
from
reverse
import
ReverseConnection
,
ReversePythonConnection
from
.
inject
import
CodeInjector
from
.
inspect
import
ObjectInspector
from
.
ipc
import
PyrasiteIPC
from
.
reverse
import
ReverseConnection
,
ReversePythonConnection
__version__
=
'2.0beta'
__all__
=
(
'CodeInjector'
,
'ObjectInspector'
,
'PyrasiteIPC'
,
...
...
pyrasite/inject.py
View file @
24b39a21
...
...
@@ -31,7 +31,7 @@ Authors:
import
os
import
warnings
from
utils
import
run
from
.
utils
import
run
class
CodeInjector
(
object
):
...
...
@@ -56,7 +56,7 @@ class CodeInjector(object):
# Allow payloads to import modules alongside them
'PyRun_SimpleString("import sys; sys.path.insert(0,
\
\
"%s
\
\
");")'
%
os
.
path
.
dirname
(
self
.
filename
),
'PyRun_SimpleString("exec
file(
\
\
"%s
\
\
"
)")'
%
self
.
filename
,
'PyRun_SimpleString("exec
(open(
\
\
"%s
\
\
").read()
)")'
%
self
.
filename
,
'PyGILState_Release($1)'
,
]
run
(
'%sgdb -p %d -batch %s'
%
(
self
.
gdb_prefix
,
self
.
pid
,
...
...
pyrasite/inspect.py
View file @
24b39a21
...
...
@@ -15,7 +15,7 @@
#
# Copyright (C) 2011 Red Hat, Inc.
from
utils
import
run
from
.
utils
import
run
class
ObjectInspector
(
object
):
...
...
pyrasite/ipc.py
View file @
24b39a21
...
...
@@ -139,7 +139,8 @@ class PyrasiteIPC(object):
def
send
(
self
,
data
):
"""Send arbitrary data to the process via self.sock"""
header
=
''
header
=
b''
data
=
data
.
encode
(
'utf-8'
)
if
self
.
reliable
:
header
=
struct
.
pack
(
'<L'
,
len
(
data
))
self
.
sock
.
sendall
(
header
+
data
)
...
...
@@ -150,7 +151,7 @@ class PyrasiteIPC(object):
header_data
=
self
.
recv_bytes
(
4
)
if
len
(
header_data
)
==
4
:
msg_len
=
struct
.
unpack
(
'<L'
,
header_data
)[
0
]
data
=
self
.
recv_bytes
(
msg_len
)
data
=
self
.
recv_bytes
(
msg_len
)
.
decode
(
'utf-8'
)
if
len
(
data
)
==
msg_len
:
return
data
else
:
...
...
@@ -158,10 +159,10 @@ class PyrasiteIPC(object):
def
recv_bytes
(
self
,
n
):
"""Receive n bytes from a socket"""
data
=
''
data
=
b
''
while
len
(
data
)
<
n
:
chunk
=
self
.
sock
.
recv
(
n
-
len
(
data
))
if
chunk
==
''
:
if
not
chunk
:
break
data
+=
chunk
return
data
...
...
pyrasite/payloads/dump_stacks.py
View file @
24b39a21
import
sys
,
traceback
for
thread
,
frame
in
sys
.
_current_frames
().
ite
rite
ms
():
for
thread
,
frame
in
sys
.
_current_frames
().
items
():
print
(
'Thread 0x%x'
%
thread
)
traceback
.
print_stack
(
frame
)
print
pyrasite/reverse.py
View file @
24b39a21
...
...
@@ -23,7 +23,10 @@ import sys
import
socket
import
threading
from
StringIO
import
StringIO
if
sys
.
version_info
[
0
]
==
3
:
from
io
import
StringIO
else
:
from
StringIO
import
StringIO
from
pyrasite.ipc
import
PyrasiteIPC
...
...
@@ -74,7 +77,7 @@ class ReverseConnection(threading.Thread, PyrasiteIPC):
running
=
False
else
:
running
=
self
.
on_command
(
cmd
)
except
Exception
,
e
:
except
Exception
as
e
:
print
(
str
(
e
))
running
=
False
if
not
running
:
...
...
@@ -94,7 +97,7 @@ class ReversePythonConnection(ReverseConnection):
try
:
exec
(
cmd
)
output
=
buffer
.
getvalue
()
except
Exception
,
e
:
except
Exception
as
e
:
output
=
str
(
e
)
finally
:
sys
.
stdout
=
sys
.
__stdout__
...
...
pyrasite/utils.py
View file @
24b39a21
...
...
@@ -6,11 +6,11 @@ from __future__ import division
def
humanize_bytes
(
bytes
,
precision
=
1
):
"""Return a humanized string representation of a number of bytes."""
abbrevs
=
(
(
1
<<
50
L
,
'PB'
),
(
1
<<
40
L
,
'TB'
),
(
1
<<
30
L
,
'GB'
),
(
1
<<
20
L
,
'MB'
),
(
1
<<
10
L
,
'kB'
),
(
1
<<
50
,
'PB'
),
(
1
<<
40
,
'TB'
),
(
1
<<
30
,
'GB'
),
(
1
<<
20
,
'MB'
),
(
1
<<
10
,
'kB'
),
(
1
,
'bytes'
)
)
if
bytes
==
1
:
...
...
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