Giter VIP home page Giter VIP logo

pyringe's People

Contributors

tehmillhouse 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

pyringe's Issues

Arch Linux not supported

Due to the lack of a a 'python-devel'-like package on Arch Linux, there are no symbols available unless you compile python yourself.

Ability to open PDB via injected code

It should technically already possible to inject a PDB session (with some caveats, as always), but it's sort of tedious (manually creating an IPC channel (usually a socket) to the debugger, wrapping it in a file-like object, and starting pdb with that as its I/O channel).

There should be a function wrapping all of this into a single command.

Pyringe falls over if something (GdbProxy?) reports a non-numeric version

$ python -m pyringe
Pyringe (Python 2.7.3) on linux2
For a list of debugger commands, try "help()". (python's help is available as pyhelp.)
==> pid:[None] #threads:[0] current thread:[None]
>>> attach(17014)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/repl.py", line 157, in Attach
    self.inferior.Reinit(pid)
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/inferior.py", line 464, in Reinit
    self.__init__(pid, auto_symfile_loading)
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/inferior.py", line 436, in __init__
    self.StartGdb()
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/inferior.py", line 482, in StartGdb
    self._gdb = GdbProxy()
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/inferior.py", line 133, in __init__
    gdb_version = GdbProxy.Version()
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/inferior.py", line 244, in Version
    major = int(version[0])
ValueError: invalid literal for int() with base 10: 'Red'
Traceback (most recent call last):
  File "/opt/python/current/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/opt/python/current/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/__main__.py", line 19, in <module>
    pyringe.interact()
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/__init__.py", line 25, in interact
    DebuggingConsole().interact()
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/repl.py", line 208, in interact
    prompt = self.StatusLine() + '\n' + sys.ps1
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/repl.py", line 133, in StatusLine
    self.inferior.StartGdb()
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/inferior.py", line 482, in StartGdb
    self._gdb = GdbProxy()
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/inferior.py", line 133, in __init__
    gdb_version = GdbProxy.Version()
  File "/home/dtdev/dtenv/lib/python2.7/site-packages/pyringe/inferior.py", line 244, in Version
    major = int(version[0])
ValueError: invalid literal for int() with base 10: 'Red'
(dtenv)[ dtdev@dtdev-centos ~ ]
$ 

attach failed with TimeoutError exception

I'm running pyringe to try to attach to one python process on Mac platform, and it fails all the time.

Using pyringe git HEAD code instead of PYPI package.
Gdb version: 8.1

Here is the trace:

Traceback (most recent call last):
File "", line 1, in
File "pyringe/repl.py", line 161, in Attach
self.inferior.Reinit(pid)
File "pyringe/inferior.py", line 484, in Reinit
self.init(pid, auto_symfile_loading, architecture=self.arch)
File "pyringe/inferior.py", line 456, in init
self.StartGdb()
File "pyringe/inferior.py", line 503, in StartGdb
self._gdb.Attach(self.position)
File "pyringe/inferior.py", line 200, in
return lambda *args, **kwargs: self._Execute(name, *args, **kwargs)
File "pyringe/inferior.py", line 342, in _Execute
result_string = self._Recv(timeout)
File "pyringe/inferior.py", line 429, in _Recv
raise TimeoutError()
TimeoutError
==> pid:[71164] #threads:[0] current thread:[None]

Fix 100% CPU when waiting for command completion.

When waiting for the gdb process to write its output, the current IPC mechanism ends up essentially in a busy waiting loop, causing high CPU usage.

Ideally, that IPC mechanism is to be replaced by a more generic version that can be reused by different parts of the debugger (cf. Issue #2)

Support for debugging other versions of cpython

The currently included libpython.py is taken directly from cpython 2.7.3's source tree. Supporting other versions of python would only require multiple versions of libpython being available and a way of finding out which version is run as the inferior.

Fall back to signal injection if symbol info is partial.

Depending on how stripped the python binary being used is, pendingcalls_to_do or pendingbusy may be unavailable. It'd be useful to fall back to injecting fake signals using Py_AddPendingCall(0,0) in such cases, even though it's more intrusive and less reliable.

Python 3 friendly?

Seeing a print 'some string' statement in the code I gather that pyringe is python 2 only. However, it would be nice to see this announced on the frontpage and on PyPI.

Cheers.

Investigate PyFrame_FastToLocals

According to revelation, PyFrame_FastToLocals not only copies f_fastlocals to f_locals, but also disables use of the fastlocals optimization. This might enable removing the limitations to setting locals in injected code.

Debug Symbols on Ubuntu

Having installed python2.7-dbg, the automatic loading of the symbol file isn't working:

Pyringe (Python 2.7.3) on linux2
For a list of debugger commands, try "help()". (python's help is available as pyhelp.)
==> pid:[None] #threads:[0] current thread:[None]
>>> attach(8298)
WARNING:root:Failed to automatically load symbol file, some functionality will be unavailable until symbol file is provided.
==> pid:[8298] #threads:[0] current thread:[None]

It seems that the default SYMBOL_FILE is relative to payload, and it seems to not be present. Changing the default to, say, the binary or shared object files installed by the python2.7-dbg package then fails to pass the sanity check.

Am I missing something obvious? Does the python (in our case, a daemon) have to have been invoked with python-dbg (we were under the impression that was not the case)?

Failed to automatically load symbol file

I get this output:

 % python -m pyringe         
Pyringe (Python 2.7.3) on linux2
For a list of debugger commands, try "help()". (python's help is available as pyhelp.)
==> pid:[None] #threads:[0] current thread:[None]
>>> attach(30375)
WARNING:root:Failed to automatically load symbol file, some functionality will be unavailable until symbol file is provided.
==> pid:[30375] #threads:[0] current thread:[None]
>>> threads()
PositionError: Not attached to any process.
WARNING:root:Failed to automatically load symbol file, some functionality will be unavailable until symbol file is provided.
==> pid:[30375] #threads:[0] current thread:[None]
>>> 

How can I get more info about why it failed? There is too less information to debug this.

attach(): AttributeError: 'module' object has no attribute 'poll'

When I try to attach to a Python process, I get the following traceback (OSX 10.9.2):

>>> attach(3938)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/cate2/instances/testenv/lib/python2.7/site-packages/pyringe/repl.py", line 157, in Attach
    self.inferior.Reinit(pid)
  File "/opt/cate2/instances/testenv/lib/python2.7/site-packages/pyringe/inferior.py", line 418, in Reinit
    self.__init__(pid, auto_symfile_loading)
  File "/opt/cate2/instances/testenv/lib/python2.7/site-packages/pyringe/inferior.py", line 390, in __init__
    self.StartGdb()
  File "/opt/cate2/instances/testenv/lib/python2.7/site-packages/pyringe/inferior.py", line 436, in StartGdb
    self._gdb = GdbProxy()
  File "/opt/cate2/instances/testenv/lib/python2.7/site-packages/pyringe/inferior.py", line 166, in __init__
    self._poller = select.poll()
AttributeError: 'module' object has no attribute 'poll'
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/opt/cate2/instances/testenv/lib/python2.7/site-packages/pyringe/__main__.py", line 19, in <module>
    pyringe.interact()
  File "/opt/cate2/instances/testenv/lib/python2.7/site-packages/pyringe/__init__.py", line 25, in interact
    DebuggingConsole().interact()
  File "/opt/cate2/instances/testenv/lib/python2.7/site-packages/pyringe/repl.py", line 208, in interact
    prompt = self.StatusLine() + '\n' + sys.ps1
  File "/opt/cate2/instances/testenv/lib/python2.7/site-packages/pyringe/repl.py", line 133, in StatusLine
    self.inferior.StartGdb()
  File "/opt/cate2/instances/testenv/lib/python2.7/site-packages/pyringe/inferior.py", line 436, in StartGdb
    self._gdb = GdbProxy()
  File "/opt/cate2/instances/testenv/lib/python2.7/site-packages/pyringe/inferior.py", line 166, in __init__
    self._poller = select.poll()
AttributeError: 'module' object has no attribute 'poll'

GDB is installed (6.3.50).

ModuleNotFoundError: No module named 'inferior'

  • OS: Ubuntu 19.04
  • Arch: Linux carrot 4.15.0-47-generic #50-Ubuntu SMP Wed Mar 13 10:44:52 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
➜ apt install gdb python-dbg python2.7-dbg
➜ pip install --no-cache-dir pyringe
Collecting pyringe
  Using cached https://files.pythonhosted.org/packages/7c/c6/6cef124c38227ece01350414c7866727179d17f64b88b8bf513386c0e4be/pyringe-1.0.2.tar.gz
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-jearzn7v/pyringe/setup.py'"'"'; __file__='"'"'/tmp/pip-install-jearzn7v/pyringe/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /tmp/pip-install-jearzn7v/pyringe/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-jearzn7v/pyringe/setup.py", line 18, in <module>
        import pyringe
      File "/tmp/pip-install-jearzn7v/pyringe/pyringe/__init__.py", line 17, in <module>
        import inferior
    ModuleNotFoundError: No module named 'inferior'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

However, installing via git repo worked fine, so it looks like it's an issue with the pip package and is due to missing dependencies / bad system setup:

➜ git clone https://github.com/google/pyringe.git
➜ cd pyringe
➜ python setup.py install
➜ python -m pyringe
Pyringe (Python 2.7.15) on linux2
For a list of debugger commands, try "help()". (python's help is available as pyhelp.)
==> pid:[None] #threads:[0] current thread:[None]
>>>

Immediate SyntaxError on attach

Attempting to attach to a process, I get this error:

In [3]: pyringe.interact()
Pyringe (Python 2.7.5) on linux2
For a list of debugger commands, try "help()". (python's help is available as pyhelp.)
==> pid:[None] #threads:[0] current thread:[None]
In : attach(26802)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pyringe/repl.py", line 157, in Attach
    self.inferior.Reinit(pid)
  File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 418, in Reinit
    self.__init__(pid, auto_symfile_loading)
  File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 390, in __init__
    self.StartGdb()
  File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 437, in StartGdb
    self._gdb.Attach(self.position)
  File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 181, in <lambda>
    return lambda *args, **kwargs: self._Execute(name, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 277, in _Execute
    result_string = self._Recv(timeout)
  File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 362, in _Recv
    raise ProxyError(exc_text)
ProxyError: Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyringe/payload/gdb_service.py", line 34, in <module>
    import libpython
  File "/usr/local/lib/python2.7/dist-packages/pyringe/payload/libpython.py", line 58
    Py_TPFLAGS_HEAPTYPE = (1L << 9)
                            ^
SyntaxError: invalid syntax

==> pid:[26802] #threads:[0] current thread:[None]

attach failed

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/repl.py", line 157, in Attach
    self.inferior.Reinit(pid)
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/inferior.py", line 480, in Reinit
    self.__init__(pid, auto_symfile_loading)
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/inferior.py", line 452, in __init__
    self.StartGdb()
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/inferior.py", line 499, in StartGdb
    self._gdb.Attach(self.position)
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/inferior.py", line 197, in <lambda>
    return lambda *args, **kwargs: self._Execute(name, *args, **kwargs)
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/inferior.py", line 339, in _Execute
    result_string = self._Recv(timeout)
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/inferior.py", line 424, in _Recv
    raise ProxyError(exc_text)
ProxyError: 
-----------------------------------
Error occurred within GdbService:
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/payload/gdb_service.py", line 652, in <module>
    serv.EvalLoop()
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/payload/gdb_service.py", line 274, in EvalLoop
    while self._AcceptRPC():
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/payload/gdb_service.py", line 293, in _AcceptRPC
    rpc_result = getattr(self, request['func'])(*request['args'])
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/payload/gdb_service.py", line 428, in Attach
    GdbCache.Refresh()
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/payload/gdb_service.py", line 66, in Refresh
    interp_head_name = GdbCache.FuzzySymbolLookup('interp_head')
  File "/home/yy/code/hzf/boss-be-v2/env/local/lib/python2.7/site-packages/pyringe/payload/gdb_service.py", line 101, in FuzzySymbolLookup
    return '\'%s\'' % mangled_name.group(1)
AttributeError: 'NoneType' object has no attribute 'group'
==> pid:[3779] #threads:[0] current thread:[None]
>>>  

gdb: unrecognised option '--nh'

I've received the following when trying to attach to a process:

For a list of debugger commands, try "help()". (python's help is available as pyhelp.)
==> pid:[None] #threads:[0] current thread:[None]
>>> attach(31043)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/repl.py", line 157, in Attach
    self.inferior.Reinit(pid)
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 418, in Reinit
    self.__init__(pid, auto_symfile_loading)
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 390, in __init__
    self.StartGdb()
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 437, in StartGdb
    self._gdb.Attach(self.position)
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 181, in <lambda>
    return lambda *args, **kwargs: self._Execute(name, *args, **kwargs)
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 277, in _Execute
    result_string = self._Recv(timeout)
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 362, in _Recv
    raise ProxyError(exc_text)
ProxyError: gdb: unrecognised option '--nh'
Use `gdb --help' for a complete list of options.

I assume there's some gdb version mismatch:

GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>.

syntax error in libpython.py

I have installed pyringe in my Ubuntu 14.04 which has GDB 7.7.1. Everything installed fine but when start it and attach the process id I get the following error.

File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/pyringe/repl.py", line 161, in Attach
self.inferior.Reinit(pid)
File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 484, in Reinit
self.init(pid, auto_symfile_loading, architecture=self.arch)
File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 456, in init
self.StartGdb()
File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 503, in StartGdb
self._gdb.Attach(self.position)
File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 200, in
return lambda _args, *_kwargs: self._Execute(name, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 342, in _Execute
result_string = self._Recv(timeout)
File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 427, in _Recv
raise ProxyError(exc_text)
ProxyError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pyringe/payload/gdb_service.py", line 34, in

*here it gives the syntax error **** in the libpython file
import libpython
File "/usr/local/lib/python2.7/dist-packages/pyringe/payload/libpython.py", line 58
Py_TPFLAGS_HEAPTYPE = (1L << 9)

Why am I getting that error ?

WindowsError: [Error 2] The system cannot find the file specified

When attempting to inject into either a process that runs on python, or a normal python.exe interpreter, I get the error:

  File "<console>", line 1, in <module>  
  File "C:\Python27\lib\site-packages\pyringe\repl.py", line 157, in Attach
    self.inferior.Reinit(pid)  
  File "C:\Python27\lib\site-packages\pyringe\inferior.py", line 480, in Reinit  
    self.__init__(pid, auto_symfile_loading)  
  File "C:\Python27\lib\site-packages\pyringe\inferior.py", line 452, in __init__  
    self.StartGdb()  
  File "C:\Python27\lib\site-packages\pyringe\inferior.py", line 498, in StartGdb  
    self._gdb = GdbProxy()  
  File "C:\Python27\lib\site-packages\pyringe\inferior.py", line 134, in __init__  
    gdb_version = GdbProxy.Version()  
  File "C:\Python27\lib\site-packages\pyringe\inferior.py", line 237, in Version  
    output = subprocess.check_output(['gdb', '--version']).split('\n')[0]  
  File "C:\Python27\lib\subprocess.py", line 212, in check_output  
    process = Popen(stdout=PIPE, *popenargs, **kwargs)  
  File "C:\Python27\lib\subprocess.py", line 390, in __init__  
    errread, errwrite)  
  File "C:\Python27\lib\subprocess.py", line 640, in _execute_child  
    startupinfo)  
WindowsError: [Error 2] The system cannot find the file specified  
WARNING:root:Inferior is not running.

I'm running Windows 10 on Python 2.7.13.

There's only one level of symbol file sanity

The debugger only differentiates between 'safe' and 'potentially unsafe' symbol files, and even when using symbol information deemed safe by the debugger, there may be problems. The debugger should have knowledge of finer granularity about which symbols (and by extension, which features) are available.

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.