Giter VIP home page Giter VIP logo

pyrasite's Introduction

http://pyrasite.com/logo.png

pyrasite

https://api.travis-ci.org/lmacken/pyrasite.png?branch=develop https://coveralls.io/repos/lmacken/pyrasite/badge.png?branch=develop https://pypip.in/v/pyrasite/badge.png https://pypip.in/d/pyrasite/badge.png

Tools for injecting arbitrary code into running Python processes.

homepage:http://pyrasite.com
documentation:http://pyrasite.rtfd.org
download:http://pypi.python.org/pypi/pyrasite
source:http://github.com/lmacken/pyrasite
screenshots:http://readthedocs.org/docs/pyrasite/en/latest/GUI.html
mailing list:https://fedorahosted.org/mailman/listinfo/pyrasite
jenkins:http://ci.csh.rit.edu/view/Pyrasite
irc:#pyrasite on Freenode

Requirements

  • gdb (version 7.3+ (or RHEL5+))

On OS X you will need to have a codesigned gdb - see https://sourceware.org/gdb/wiki/BuildingOnDarwin if you get errors while running with --verbose which mention codesigning.

Compatibility

Pyrasite works with Python 2.4 and newer. Injection works between versions as well, so you can run Pyrasite under Python 3 and inject into 2, and vice versa.

pyrasite-gui

The graphical interface can be found here: https://github.com/lmacken/pyrasite-gui

http://lewk.org/img/pyrasite/pyrasite-info-thumb.png

Authors

Created by Luke Macken with the help of David Malcolm and many other contributors. Logo by Adam Saunders.

Licenses

Code

https://www.gnu.org/graphics/gplv3-127x51.png

Logo

https://creativecommons.org/images/deed/nolaw.png

pyrasite's People

Contributors

abeutot avatar cpennington avatar crogers avatar deanf avatar dustymabe avatar jwilk avatar lmacken avatar mgedmin avatar msabramo avatar ogrisel avatar qalthos avatar ralphbean avatar ryazwinski avatar sei-eschwartz avatar timgates42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyrasite's Issues

pyrasite-shell configuration to work with PID on Cygwin

I have Python 2.7 installed on Cygwin and I want easily drop into a shell and execute commands in my python application, but the tool "pyrasite-shell" is not working properly.

I'm not sure if it sees correctly PID. When I run the below command, dollar sign ($) prompt disappears and I don't get access to the python interpreter who should show such a thing ">>>".
pyrasite-shell <PID>

Short information about this program:
Pyrasite is a library and a set of tools for injecting code into running Python programs.
Requirements: gdb (version 7.3+)
I installed the required package and then I gave the following command:
pip install pyrasite

I launched then the first Cygwin terminal and executed:
python myscript.py

I checked then on the second:

ps aux | grep python
ps aux
top

I received:

I     734     725     734       5680  pty1      197609 13:51:51 /usr/bin/python2.7


      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
      724       1     724       3272  ?         197609 13:51:46 /usr/bin/mintty
      715     714     715       8612  pty0      197609 13:51:43 /usr/bin/bash
      725     724     725       9608  pty1      197609 13:51:46 /usr/bin/bash
      714       1     714      10004  ?         197609 13:51:43 /usr/bin/mintty
I     734     725     734       5680  pty1      197609 13:51:51 /usr/bin/python2.7
      737     715     737       7444  pty0      197609 13:52:53 /usr/bin/ps


  PID UŻYTK.    PR  NI    WIRT    REZ  %CPU  %PAM     CZAS+ S KOMENDA
  714 USR        8   0    7,7m  17,6m   0,0   0,4   0:00.23 S /usr/bin/mintty +
  715 USR        8   0    5,6m   7,7m   0,0   0,2   0:00.06 S  `- -bash
  738 USR        8   0   11,6m  11,8m   6,7   0,3   0:01.96 R      `- top
  724 USR        8   0    7,6m  17,1m   0,0   0,4   0:00.24 S /usr/bin/mintty +
  725 USR        8   0    5,6m   7,7m   0,0   0,2   0:00.06 S  `- -bash
  734 USR        8   0   33,8m  37,4m   0,0   0,9   0:04.65 S      `- python d+

Then:
pyrasite-shell 734
and nothing happens, I can enter any PID and the effect will be the same

ipc.connect hang forever

I'm trying to hook on a old python process using pyrasite-shell , and it does not work, it hangs forever and when I finally CTRL+C I got the following stack-trace :

admin@x:~$ sudo pyrasite-shell 476 

^CTraceback (most recent call last):
  File "/usr/local/bin/pyrasite-shell", line 11, in <module>
    sys.exit(shell())
  File "/usr/local/lib/python2.7/dist-packages/pyrasite/tools/shell.py", line 30, in shell
    ipc.connect()
  File "/usr/local/lib/python2.7/dist-packages/pyrasite/ipc.py", line 95, in connect
    self.wait()
  File "/usr/local/lib/python2.7/dist-packages/pyrasite/ipc.py", line 151, in wait
    (clientsocket, address) = self.server_sock.accept()
  File "/usr/lib/python2.7/socket.py", line 202, in accept
    sock, addr = self._sock.accept()
KeyboardInterrupt

on a similar but "recently" launched process , I can get a shell

pyrasite-shell error: socket.gaierror: [Errno -2] Name or service not known

OS: ubuntu 16.04
Python: 2.7.15

pyrasite-memory-viewer PID works fine
pyrasite PID helloworld.py works fine

But when executing pyrasite-shell PID I got this error:

Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/envs/workenv/bin/pyrasite-shell", line 11, in <module>
    sys.exit(shell())
  File "/home/ubuntu/anaconda3/envs/workenv/lib/python2.7/site-packages/pyrasite/tools/shell.py", line 30, in shell
    ipc.connect()
  File "/home/ubuntu/anaconda3/envs/workenv/lib/python2.7/site-packages/pyrasite/ipc.py", line 93, in connect
    self.listen()
  File "/home/ubuntu/anaconda3/envs/workenv/lib/python2.7/site-packages/pyrasite/ipc.py", line 100, in listen
    socket.SOCK_STREAM, 0, 0):
socket.gaierror: [Errno -2] Name or service not known

Thanks in advance.

Support fifos as payload for pyrasite cli tool

Code in a fifo is not executed while the exit code doesn't complain.

# pyrasite 23079 <(echo "import resource; resource.setrlimit(resource.RLIMIT_NOFILE, (10, 10))"); echo $?
0
# grep files /proc/23079/limits 
Max open files            1024                 4096                 files   
# echo "import resource; resource.setrlimit(resource.RLIMIT_NOFILE, (10, 10))" > /tmp/payload
# pyrasite 23079 /tmp/payload
# grep files /proc/23079/limits 
Max open files            10                   10                   files  

pyrasite-memory-viewer does not work

I cloned master, easy_install'ed it into ~/py-lib, tried pyrasite-memory-viewer somepid and got this:

ImportError: No module named urwid

After easy_installing urwid I re-ran that command and got

Traceback (most recent call last):
  File "/home/mg/bin/pyrasite-memory-viewer", line 9, in <module>
    load_entry_point('pyrasite==2.0beta9', 'console_scripts', 'pyrasite-memory-viewer')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 305, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2245, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1955, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/home/mg/py-lib/pyrasite-2.0beta9-py2.7.egg/pyrasite/tools/memory_viewer.py", line 34, in <module>
    from pyrasite.inspect import ObjectInspector
ImportError: No module named inspect

pyrasite-shell does not work on Ubuntu 18.04.1

nothing happens when I try to attach to a running python process with pyrasite-shell.

when running pyrasite --verbose <PID> hello.py I get:

b'0x00007f02ce561ff7 in ?? ()\n'
b'\nwarning: Could not load vsyscall page because no executable was specified\nNo symbol table is loaded.  Use the "file" command.\nNo symbol table is loaded.  Use the "file" command.\nNo symbol table is loaded.  Use the "file" command.\n'

Cannot use pyrasite-shell as root (if target is non-root)

If the target application is running as non-root, attempting to attach to it as root yields a Permission denied error in the target, and pyrasite-shell just hangs.

Maybe the best approach is to setuid to the target uid at startup?

Improve our thread graph

We should figure out a way to better distinguish the different threads in the sparkline, allowing people to easily see the corresponding thread stack.

It would also be nice to distinguish between system and user time for each thread as well.

Gui Exception when process dies

When connected to a process, the thread refreshing information throws an exception if the process is killed preventing the gui from updating information even if connected to another process.

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in bootstrap_inner
self.run()
File "/usr/lib/python2.7/site-packages/pyrasite-2.0beta2-py2.7.egg/pyrasite/tools/gui.py", line 886, in run
self.process.get_cpu_percent(interval=POLL_INTERVAL))
File "/usr/lib/python2.7/site-packages/psutil/__init
.py", line 332, in get_cpu_percent
pt2 = self._platform_impl.get_cpu_times()
File "/usr/lib/python2.7/site-packages/psutil/_pslinux.py", line 250, in wrapper
raise NoSuchProcess(self.pid, self._process_name)
NoSuchProcess: process no longer exists (pid=3336)

[Mac OSX]Use the pyrasite always remain on ipc.connect

(g)dreampuf@HX:~/hub/fortest/hello$ pyrasite-shell 35548
^CTraceback (most recent call last):
  File "/Users/dreampuf/.virtualenvs/g/bin/pyrasite-shell", line 8, in <module>
    load_entry_point('pyrasite==2.0', 'console_scripts', 'pyrasite-shell')()
  File "/Users/dreampuf/.virtualenvs/g/lib/python2.7/site-packages/pyrasite/tools/shell.py", line 30, in shell
    ipc.connect()
  File "/Users/dreampuf/.virtualenvs/g/lib/python2.7/site-packages/pyrasite/ipc.py", line 95, in connect
    self.wait()
  File "/Users/dreampuf/.virtualenvs/g/lib/python2.7/site-packages/pyrasite/ipc.py", line 151, in wait
    (clientsocket, address) = self.server_sock.accept()
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 202, in accept
    sock, addr = self._sock.accept()
KeyboardInterrupt

Did I need the special code insert the remote process? or other version of gdb (I could not find the version 7.2 on homebrew)

(g)dreampuf@HX:~/hub/fortest/hello$ gdb --version
GNU gdb 6.3.50-20050815 (Apple version gdb-1824) (Thu Nov 15 10:42:43 UTC 2012)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".

PyrasiteMemoryViewer TagMarkupException

root@MyServer:/root# pidof python
11361
root@MyServer:/root# pyrasite-memory-viewer 11361
loaded line 50968, 50969 objs, 6.1 / 6.1 MiB read in 0.9s
checked 50968 / 50969 collapsed 852
set parents 50116 / 50117
collapsed in 0.3s
set parents 50116 / 50117
No symbol table is loaded. Use the "file" command.
Traceback (most recent call last):
File "/usr/local/bin/pyrasite-memory-viewer", line 9, in
load_entry_point('pyrasite==2.0', 'console_scripts', 'pyrasite-memory-viewer')()
File "/usr/local/lib/python2.7/dist-packages/pyrasite-2.0-py2.7.egg/pyrasite/tools/memory_viewer.py", line 153, in main
PyrasiteMemoryViewer(pid=pid, objects=objects).main()
File "/usr/local/lib/python2.7/dist-packages/pyrasite-2.0-py2.7.egg/pyrasite/tools/memory_viewer.py", line 130, in main
self.view, self.exit_view = self.setup_view()
File "/usr/local/lib/python2.7/dist-packages/pyrasite-2.0-py2.7.egg/pyrasite/tools/memory_viewer.py", line 99, in setup_view
self.object_buttons[2].set_state(True)
File "/usr/lib/python2.7/dist-packages/urwid/wimp.py", line 384, in set_state
self.__super.set_state(state, do_callback)
File "/usr/lib/python2.7/dist-packages/urwid/wimp.py", line 224, in set_state
self._emit('change', state)
File "/usr/lib/python2.7/dist-packages/urwid/widget.py", line 214, in _emit
signals.emit_signal(self, name, self, _args)
File "/usr/lib/python2.7/dist-packages/urwid/signals.py", line 126, in emit
result |= bool(callback(_args_copy))
File "/usr/local/lib/python2.7/dist-packages/pyrasite-2.0-py2.7.egg/pyrasite/tools/memory_viewer.py", line 71, in display_object
self.object_output.set_text(value)
File "/usr/lib/python2.7/dist-packages/urwid/widget.py", line 511, in set_text
self._text, self._attrib = decompose_tagmarkup(markup)
File "/usr/lib/python2.7/dist-packages/urwid/util.py", line 374, in decompose_tagmarkup
tl, al = _tagmarkup_recurse(tm, None)
File "/usr/lib/python2.7/dist-packages/urwid/util.py", line 415, in _tagmarkup_recurse
raise TagMarkupException, "Invalid markup element: %r" % tm
urwid.util.TagMarkupException: Invalid markup element: None

The socket timeout is unusually short (5s). Increase, or make it configurable?

PyrasiteIPC appears to hardcode the socket timeout to 5 seconds, which is very low.

My first attempt at using Pyrasite was to execute some diagnostic code, which took longer than 5 seconds to execute, resulting in a timeout and disconnection. I had to read and modify my copy of the source in order to remove the timeout and make it usable.

To avoid surprising newcomers with this, I think it would be a good idea to increase the default timeout to 30 seconds (or more, or disable it?). Many invocations one might want to run with Pyrasite probably take more than 5 seconds to execute.

In addition, it's probably a good idea to expose a --timeout option to make the timeout user-configurable, for users that don't want the default.

PyImport_GetModuleDict when trying to use pyrasite

I get the follow exception on the pyrasited process:

Fatal Python error: PyImport_GetModuleDict: no module dictionary!

Current thread 0x00007fdac71ed700 (most recent call first):
  File ".../lib/python3.4/site-packages/zmq/sugar/context.py", line 44 in __del__
Aborted (core dumped)

This is in python 3.4.3, with trying to use pyrasite on a py.test run which hangs at the end of the test run.

Pyrasite freezes everytime I run

I installed in archlinux using the PKGBUILD in the pkgs/arch folder. If I run pyrasite-gui, the gui freezes when I click in any program on the left list. Basically the same thing happens if I run using pyrasite-shell - I get no output at all and I've to kill the process. Using just pyrasite nothing happens.

Bugs while trying to dump objects with meliae

I hit these tracebacks while bouncing between a couple of processes over and over.

Traceback (most recent call last):
  File "pyrasite/tools/gui.py", line 573, in selection_cb
    self.dump_objects(proc)
  File "pyrasite/tools/gui.py", line 632, in dump_objects
    map(intify, line.split()[1:]))
  File "/usr/lib64/python2.7/site-packages/gi/overrides/Gtk.py", line 935, in append
    self.set_row(treeiter, row)
  File "/usr/lib64/python2.7/site-packages/gi/overrides/Gtk.py", line 791, in set_row
    raise ValueError('row sequence has the incorrect number of elements')
ValueError: row sequence has the incorrect number of elements

Traceback (most recent call last):
  File "pyrasite/tools/gui.py", line 301, in obj_selection_cb
    addy = model.get_value(treeiter, 0)
  File "/usr/lib64/python2.7/site-packages/gi/overrides/Gtk.py", line 977, in get_value
    return self._decode_value(treeiter, column, value)
  File "/usr/lib64/python2.7/site-packages/gi/overrides/Gtk.py", line 803, in _decode_value
    value = value.decode('UTF-8')
AttributeError: 'NoneType' object has no attribute 'decode'

No response when using pyrasite-shell

Hey Luke/Pyrasite crew, I'm trying to attach a shell to a twisted process, and all i'm getting is a hung shell. So I SIGINT and rerun with a --verbose, like: pyrasite --verbose 14129 dump_modules.py and I see:

[Thread debugging using libthread_db enabled]
[New Thread 0x7fd91ed28700 (LWP 15516)]
[New Thread 0x7fd91f529700 (LWP 15515)]
[New Thread 0x7fd91fd2a700 (LWP 15514)]
[New Thread 0x7fd924a8b700 (LWP 14332)]
[New Thread 0x7fd92528c700 (LWP 14133)]
[New Thread 0x7fd925a8d700 (LWP 14130)]
0x00007fd92a82a163 in epoll_wait () from /lib/libc.so.6
$1 = PyGILState_UNLOCKED
$2 = 0


warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7fff075fe000

Waiting at an epoll, as one would expect from a Twisted process running on Debian:

# uname -a
Linux graybles 2.6.32-042stab079.6 #1 SMP Mon Aug 26 19:47:50 MSK 2013 x86_64 GNU/Linux

Also, I'm using the pip-installable versions of all relevant libraries. Let me know if there's anything else I can provide. And of course, thanks for making pyrasite as it is very awesome. :)

pyrasite-memory-viewer: IOError: [Errno 2] File not found: '/tmp/pyrasite-23216-objects.json'

# pyrasite-memory-viewer 23216
Traceback (most recent call last):
  File "/usr/local/bin/pyrasite-memory-viewer", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/pyrasite/tools/memory_viewer.py", line 150, in main
    objects = loader.load(filename)
  File "/usr/lib/python2.7/dist-packages/meliae/loader.py", line 529, in load
    source, cleanup = files.open_file(source)
  File "/usr/lib/python2.7/dist-packages/meliae/files.py", line 32, in open_file
    source = open(filename, 'rb')
IOError: [Errno 2] File not found: '/tmp/pyrasite-23216-objects.json'

Afterwards the python process is not running anymore. :-(

Python segfaults after pyrasite tries to connect

I'm using the standard OS X Python version, and when I run pyrasite --verbose 7407 helloworld.py it appears to hang, until I press any key in the window which is running the Python process - at which point the Python process segfaults and I get the following errors from pyrasite:

0x00007fff8c8c83fa in select$DARWIN_EXTSN () from /usr/lib/system/libsystem_kernel.dylib
[Inferior 1 (process 7407) exited normally]


warning: `/BinaryCache/coreTLS/coreTLS-35.40.1~1/Objects/coretls.build/coretls.build/Objects-normal/x86_64/system_coretls_vers.o': can't open to read symbols: No such file or directory.

warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_ciphersuites.a"

warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a"

warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a"

warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_stream_parser.a"
The program being debugged exited while in a function called from GDB.
Evaluation of the expression containing the function
(PyGILState_Ensure) will be abandoned.
You can't do that without a process to debug.
History has not yet reached $1.

Any idea what I'm doing wrong?

Make the callgraph more configurable

Right now, upon selecting a process from the gui, we simply trace the call graph for 1 second, and then spit out an image. Ideally we should make this configurable from the interface.

Execute code in main thread?

pyrasite execute code in a new thread of the remote process. Can I execute code in main thread of the remote process?(some code must be executed in main thread)
Thanks.

Handle PyGILState_LOCKED race conditions.

======================================================================
FAIL: test_multithreaded_injection (tests.test_code_injection.TestCodeInjection)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/lmacken/code/github.com/pyrasite/tests/test_code_injection.py", line 50, in test_multithreaded_injection
    "Multi-threaded code injection failed"
AssertionError: AssertionError: Multi-threaded code injection failed
-------------------- >> begin captured stdout << ---------------------
b'[Thread debugging using libthread_db enabled]\nUsing host libthread_db library "/lib64/libthread_db.so.1".\nPyEval_EvalF
rameEx (f=<optimized out>, throwflag=<optimized out>) at /usr/src/debug/Python-2.7.2/Python/ceval.c:2966\n2966\t
  while (STACK_LEVEL() > b->b_level) {\n$1 = PyGILState_LOCKED\n$2 = -1\n'

pyrasite-gui run with error,

I install th pyrasite with ubuntu14.
Pyrasite can work correctly.
But pyrasite-gui does not work.
I have done this:
apt-get install python-dbg python-pycallgraph python-gobject-dev gir1.2-webkit-3.0 python-meliae python-psutil.
echo 0 > /proc/sys/kernel/yama/ptrace_scope
pip install pyrasite pyrasite-gui

the error infomation:
tx-deepocean@tx-deepocean:/etc/apt/sources.list.d$ pyrasite-gui

(pyrasite-gui:12517): Gtk-CRITICAL **: gtk_box_pack: assertion 'gtk_widget_get_parent (child) == NULL' failed
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pyrasite_gui/gui.py", line 599, in selection_cb
self.generate_description(title)
File "/usr/local/lib/python2.7/dist-packages/pyrasite_gui/gui.py", line 469, in generate_description
""" % (self.proc.title, p.status, p.getcwd(), ' '.join(p.cmdline),
AttributeError: 'Process' object has no attribute 'getcwd'
/usr/lib/python2.7/dist-packages/gi/overrides/GLib.py:523: Warning: g_object_ref: assertion 'object->ref_count > 0' failed
super(MainLoop, self).run()
/usr/lib/python2.7/dist-packages/gi/overrides/GLib.py:523: Warning: g_object_unref: assertion 'object->ref_count > 0' failed
super(MainLoop, self).run()

What is the wrong?
Thank you.

pyrasite cannot inject

Hi am not able to reproduce the simple example from website asciinema animation.
I start a CPython instance, get the PID via os.getpid() then try both to run pyrasite-shell passing the PID as argument, or run pyrasite passing the PID and a simple module with just print("fubar") in it.

In both case the pyrasite script I start hangs.

I am running on a x86_64 Linux system with kernel 5.4.42 and glibc 2.30, the issue happens with both python 2.7.18 and 3.8.3 .

Is pyrasite reported working on modern Linux systems?

pyrasite-shell segmentation fault on Raspberry Pi

Would be cool if you could get pyrasite-shell working on Raspberry Pi. I have an odd hang in python 3.4 that I'm trying to debug there. But when I try and attach pyrasite-shell to the process the process dies with "segmentation fault", even when I create a simple interactive "python" process and try and attach to that. Weirdly, when I run the interactive python process in gdb it doesn't crash, but then pyrasite_shell never attaches either, it just hangs. Using raspberry pi Raspbian:

No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 8.0 (jessie)
Release:        8.0
Codename:       jessie

pyrasite-shell getting permission denied in debugged process

Hello:

I'm seeing the following in the ouput of the debugged process when trying to run pyrasite-shell on it:

Traceback (most recent call last):
File "<string>", line 1, in <module>
IOError: [Errno 13] Permission denied: '/tmp/tmplzhk39'

And that file does not exist. My usage is just:

sudo pyrasite-shell <pid>

Normal pyrasite seems to work, at least this does:

sudo pyrasite <pid> hellowworld.py

Any thoughts?

pyrasite-shell causes segmentation fault in Python 3

Using $pyrasite-shell <PID> in python 3 causes the running process (<PID>) to face a segmentation fault. The only exception is when both the running process and pyrasite-shell are executed with sudo. Any solutions or workaround?

b'...' output from --verbose in Python 3

e.g.

~/.local/bin/pyrasite --verbose 4093 reverse_python_shell.py         
b'[New LWP 4097]\n[New LWP 4096]\n[New LWP 4095]\n[Thread debugging using libthread_db enabled]\nUsing host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".\n0x00007f9df52689a3 in epoll_wait () at ../sysdeps/unix/syscall-template.S:81\n$1 = 1\n[New Thread 0x7f9ddffff700 (LWP 4122)]\n$2 = 0\n$3 = 15550096\n'
b'81\t../sysdeps/unix/syscall-template.S: No such file or directory.\n'

Can it work with Pyinstaller (Linux)?

I tried writing a very simple Python program (using Ubuntu, Python 2.7) and I can apply pyrasite-shell without problem on it. However, when I use pyinstaller (with the -F option for simple file) and then try to apply pyrasite-shell on that process, this produces a segmentation fault - it looks like a GIL issue. Is there any way around this?

Traceback trying --help

--- ~ » pyrasite-shell --help
Traceback (most recent call last):
  File "/usr/bin/pyrasite-shell", line 9, in <module>
    load_entry_point('pyrasite==2.0', 'console_scripts', 'pyrasite-shell')()
  File "/usr/lib/python2.7/site-packages/pyrasite/tools/shell.py", line 29, in shell
    ipc = pyrasite.PyrasiteIPC(int(sys.argv[1]), 'ReversePythonShell')
ValueError: invalid literal for int() with base 10: '--help'

pyrasite-shell hangs on Arch Linux

It works pretty well on Ubuntu 18.04. However, when I run pyrasite-shell <pid> on Arch Linux, I got the following errors:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
0x00007f9e956f3197 in select () from /usr/lib/libc.so.6

'PyGILState_Ensure' has unknown return type; cast the call to its declared return type
'PyRun_SimpleString' has unknown return type; cast the call to its declared return type
History has not yet reached $1.

^CTraceback (most recent call last):
  File "/usr/bin/pyrasite-shell", line 11, in <module>
    load_entry_point('pyrasite==2.0', 'console_scripts', 'pyrasite-shell')()
  File "/usr/lib/python2.7/site-packages/pyrasite/tools/shell.py", line 30, in shell
    ipc.connect()
  File "/usr/lib/python2.7/site-packages/pyrasite/ipc.py", line 95, in connect
    self.wait()
  File "/usr/lib/python2.7/site-packages/pyrasite/ipc.py", line 151, in wait
    (clientsocket, address) = self.server_sock.accept()
  File "/usr/lib/python2.7/socket.py", line 206, in accept
    sock, addr = self._sock.accept()
KeyboardInterrupt

May I know how to resolve this issue? Thanks.

Silent fail when GDB is not installed

When gdb is not installed, pyrasite will not give an error, warning or message, but it won't do anything as well. It would be good to have this as a message like when ptrace is disabled.

Error running pyrasite on windows

On Windows7x64 with python 3.6, I installed pyrasite 2.0, gdb, and set gdb as environment variable.

  • Command c:\Python36\Scripts\pyrasite.exe --verbose 1772 helloworld.py returns:

b'' b'Excess command line arguments ignored. (PyRun_SimpleString(import sys; sys.pat h.insert(0, "C:\\Python36\\lib\\site-packages\\pyrasite\\payloads"); sys.path.in sert(0, "C:\\Python36\\lib\\site-packages"); exec(open("C:\\Python36\\lib\\site- packages\\pyrasite\\payloads\\helloworld.py").read()))\' ...)\r\nPyGILState_Ensu re()\': No such file or directory.\r\nCan\'t attach to process.\r\nUndefined com mand: "". Try "help".\r\nUndefined command: "". Try "help".\r\nUndefined comma nd: "". Try "help".\r\n'

  • The same thing happens in a python script:

import pyrasite; pyrasite.inject(pid=1772, filename="c:\\Test\\helloworld.py", verbose=True)

generates:

b'' b'Excess command line arguments ignored. (PyRun_SimpleString(import sys; sys.path.insert(0, "c:\\Test"); sys.path.insert(0, "C:\\Python36\\lib\\site-packages"); exec(open("c:\\Test\\helloworld.py").read()))\' ...)\r\nPyGILState_Ensure()\': No such file or directory.\r\nCan\'t attach to process.\r\nUndefined command: "". Try "help".\r\nUndefined command: "". Try "help".\r\nUndefined command: "". Try "help".\r\n'

NameError: global name 'ipc_timeout' is not defined

When running with --output localterm, the ipc_timeout variable is undefined.

~/pyrasite-develop# pyrasite --output localterm --ipc-timeout 5 1 dump_stacks.py
Traceback (most recent call last):
  File "/usr/local/bin/pyrasite", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/pyrasite/main.py", line 137, in main
    timeout=ipc_timeout)
NameError: global name 'ipc_timeout' is not defined

The reference on line 137 needs to be args.ipc_timeout, not simply ipc_timeout.

Problem with 'python setup.py develop'

(pyrasite)threebean@marat ~/devel/pyrasite (git:develop:0)
 % python setup.py develop
running develop
running egg_info
writing requirements to pyrasite.egg-info/requires.txt
writing pyrasite.egg-info/PKG-INFO
writing top-level names to pyrasite.egg-info/top_level.txt
writing dependency_links to pyrasite.egg-info/dependency_links.txt
writing entry points to pyrasite.egg-info/entry_points.txt
reading manifest file 'pyrasite.egg-info/SOURCES.txt'
writing manifest file 'pyrasite.egg-info/SOURCES.txt'
running build_ext
Creating /home/threebean/.virtualenvs/pyrasite/lib/python2.7/site-packages/pyrasite.egg-link (link to .)
pyrasite 1.1 is already the active version in easy-install.pth
Installing pyrasite-gui script to /home/threebean/.virtualenvs/pyrasite/bin
Installing pyrasite-memory-viewer script to /home/threebean/.virtualenvs/pyrasite/bin
Installing pyrasite script to /home/threebean/.virtualenvs/pyrasite/bin

Installed /home/threebean/devel/pyrasite
Processing dependencies for pyrasite==1.1
Searching for meliae
Reading http://pypi.python.org/simple/meliae/
Reading https://launchpad.net/meliae
Reading https://launchpad.net/meliae/+download
Best match: meliae 0.4.0
Downloading http://launchpad.net/meliae/trunk/0.4/+download/meliae-0.4.0.tar.gz
Processing meliae-0.4.0.tar.gz
Running meliae-0.4.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-IuIszE/meliae-0.4.0/egg-dist-tmp-9LFMD7
We require Cython to be installed.
No eggs found in /tmp/easy_install-IuIszE/meliae-0.4.0/egg-dist-tmp-9LFMD7 (setup script problem?)
error: Could not find required distribution meliae

SIGSEGV from helloworld.py payload

Running pyrasite out of a virtualenv inside a privileged Docker container:

$ /…/pyrasite/bin/pyrasite --verbose 809 helloworld.py
[New LWP 1605]
[New LWP 1790]
[New LWP 1791]
[New LWP 1792]
[New LWP 1803]
[New LWP 1805]
[New LWP 1807]
[New LWP 1809]
[New LWP 1810]
[New LWP 1811]
[New LWP 1813]
[New LWP 1814]
[New LWP 1818]
[New LWP 1819]
[New LWP 1821]
[New LWP 1826]
[New LWP 1829]
[New LWP 1830]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/…/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007f9ee42bf6b3 in select () from /…/lib/x86_64-linux-gnu/libc.so.6

Thread 1 "debug_paster" received signal SIGSEGV, Segmentation fault.
0x00000000004d527c in ?? ()

Thread 9 "debug_paster" received signal SIG40, Real-time event 40.
[Switching to Thread 0x7f9eaffff700 (LWP 1809)]
0x00007f9ee42c65ac in epoll_pwait () from /…/lib/x86_64-linux-gnu/libc.so.6

The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on".
Evaluation of the expression containing the function
(PyGILState_Ensure) will be abandoned.
When the function is done executing, GDB will silently stop.
warning: Unable to restore previously selected frame.
The program received a signal in another thread while
making a function call from GDB.
Evaluation of the expression containing the function
(malloc) will be abandoned.
When the function is done executing, GDB will silently stop.
History has not yet reached $1.
Can't detach Thread 0x7f9ec61fd700 (LWP 1803): No such process

I can attach/detach with strace and gdb without issue inside the container, and thread apply all bt shows some meaningful information, but some symbols are missing. E.G.:

…
Thread 5 (Thread 0x7f6fd3fff700 (LWP 2367)):
#0  0x00007f6ff0aa36b3 in select () from /…/lib/x86_64-linux-gnu/libc.so.6
#1  0x00007f6ff0054d62 in floatsleep (secs=<optimized out>) at /…/python-2.7/Python-2.7.7-build/Python-2.7.7/Modules/timemodule.c:948
#2  time_sleep (self=<optimized out>, args=<optimized out>) at /…/python-2.7/Python-2.7.7-build/Python-2.7.7/Modules/timemodule.c:206
#3  0x00000000004af9a2 in ?? ()
#4  0x0000000000000000 in ?? ()

Thread 4 (Thread 0x7f6fd8834700 (LWP 2366)):
#0  0x00007f6ff0aa36b3 in select () from /…/lib/x86_64-linux-gnu/libc.so.6
#1  0x00007f6ff0054d62 in floatsleep (secs=<optimized out>) at /…/python-2.7/Python-2.7.7-build/Python-2.7.7/Modules/timemodule.c:948
#2  time_sleep (self=<optimized out>, args=<optimized out>) at /…/python-2.7/Python-2.7.7-build/Python-2.7.7/Modules/timemodule.c:206
#3  0x00000000004af9a2 in ?? ()
#4  0x0000000000000000 in ?? ()

Thread 3 (Thread 0x7f6fd9035700 (LWP 2365)):
#0  0x00007f6ff1490fd0 in sem_wait () from /…/lib/x86_64-linux-gnu/libpthread.so.0
#1  0x00000000004b59a3 in ?? ()
#2  0x00007f6ff07773c0 in ?? ()
#3  0x00000000004583a0 in ?? ()
#4  0x0000000000000001 in ?? ()
#5  0x00005651affa1d90 in ?? ()
#6  0x00007f6fd92c2cb0 in ?? ()
#7  0x000000000046fa9d in ?? ()
#8  0x00007f6fd40232b0 in ?? ()
#9  0x00000001f050fdf8 in ?? ()
#10 0x00007f6ff07773c0 in ?? ()
#11 0x00007f6fd2b551b8 in ?? ()
#12 0x00007f6fd40232b0 in ?? ()
#13 0x00000000004af9a2 in ?? ()
#14 0x0000000000000000 in ?? ()
…

Would that be the issue? If not, any idea how to debug this?

reverse_python_shell.py showing '[Errno 111] Connection refused' in other process

When injecting the reverse_python_shell.py payload on an Ubuntu 11.10 system (after doing the echo 0 to ptrace_scope), the process I am connecting to (a python interpreter sitting at the shell) shows the following error:

[Errno 111] Connection refused

No error is reported from the pyrasite process. Tests with the hello_world.py payload work, though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.