Remote vanilla PDB (over TCP sockets) done right: no extras, proper handling around connection failures and CI.

Overview

Overview

docs Documentation Status
tests
Travis-CI Build Status AppVeyor Build Status Requirements Status
Coverage Status Coverage Status
package

Remote vanilla PDB (over TCP sockets) done right: no extras, proper handling around connection failures and CI. Based on pdbx.

  • Free software: BSD 2-Clause License

Installation

pip install remote-pdb

Usage

To open a remote PDB on first available port:

from remote_pdb import set_trace
set_trace() # you'll see the port number in the logs

To use some specific host/port:

from remote_pdb import RemotePdb
RemotePdb('127.0.0.1', 4444).set_trace()

To connect just run telnet 127.0.0.1 4444. When you are finished debugging, either exit the debugger, or press Control-], then Control-d.

Alternately, one can connect with NetCat: nc -C 127.0.0.1 4444 or Socat: socat readline tcp:127.0.0.1:4444 (for line editing and history support). When finished debugging, either exit the debugger, or press Control-c.

Note that newer Ubuntu disabled readline support in socat, so if you get unknown device/address "readline" try using rlwrap like this:

rlwrap socat - tcp:127.0.0.1:4444

Using in containers

If you want to connect from the host to remote-pdb running inside the container you should make sure that:

  • The port you will use is mapped (eg: -p 4444:4444).
  • The host is set to 0.0.0.0 (localhost` or ``127.0.0.1 will not work because Docker doesn't map the port on the local interface).

Integration with breakpoint() in Python 3.7+

If you are using Python 3.7 one can use the new breakpoint() built in to invoke remote PDB. In this case the following environment variable must be set:

PYTHONBREAKPOINT=remote_pdb.set_trace

The debugger can then be invoked as follows, without any imports:

breakpoint()

As the breakpoint() function does not take any arguments, environment variables can be used to specify the host and port that the server should listen to. For example, to run script.py in such a way as to make telnet 127.0.0.1 4444 the correct way of connecting, one would run:

PYTHONBREAKPOINT=remote_pdb.set_trace REMOTE_PDB_HOST=127.0.0.1 REMOTE_PDB_PORT=4444 python script.py

If REMOTE_PDB_HOST is omitted then a default value of 127.0.0.1 will be used. If REMOTE_PDB_PORT is omitted then the first available port will be used. The connection information will be logged to the console, as with calls to remote_pdb.set_trace().

To quiet the output, set REMOTE_PDB_QUIET=1, this will prevent RemotePdb from producing any output -- you'll probably want to specify REMOTE_PDB_PORT as well since the randomized port won't be printed.

Note about OS X

In certain scenarios (backgrounded processes) OS X will prevent readline to be imported (and readline is a dependency of pdb). A workaround (run this early):

import signal
signal.signal(signal.SIGTTOU, signal.SIG_IGN)

See #9 and cpython#14892.

Requirements

Python 2.6, 2.7, 3.2, 3.3 and PyPy are supported.

Similar projects

Comments
  • Setting process group consumes I/O from debugger.

    Setting process group consumes I/O from debugger.

    First, thanks for writing remote_pdb! It works very well to set breaks in child processes in normal circumstances.

    There seems to be a communication problem when the main python program is under control of a program such as entr or when the main program is launched from ipython and sets it's own process group.

    Could you please take a look at the question I posted a couple of days ago on SO? It's rather long so I won't repost the contents here.

    http://stackoverflow.com/questions/43823564/python-3-debug-child-process-running-under-control-of-entr

    Thanks, Mike Ellis

    opened by Michael-F-Ellis 12
  • autocompletion and [TAB] action does not work on linux

    autocompletion and [TAB] action does not work on linux

    Hi,

    I started using remote-pdb a few days ago and i noticed that the [TAB] action does not work under linux. I am not sure if this is the case on other OSes too. After telnet'ing when i press [TAB] the cursor just moves forward with a tab space.

    i think it would be really cool if the TAB completion works via telnet.

    i hope this will be takes into account and implemented, i'll be happy to contribute with some of my time in case i can be helpful.

    Best,

    opened by mherkazandjian 6
  • Improve support for later Python versions

    Improve support for later Python versions

    Hi!

    This PR adds testing for newer Python versions, as well as a workaround for a CPython bug in Python 3.6.6 and up.

    It works for me locally, but there are a lot of tox environments and I have only run a subset of them. I'll fix any errors that come up, but if you have any concerns please do holler.

    Cheers, love the software,

    Matt

    opened by MatthewWilkes 5
  • set_trace call vs RemotePdb instance

    set_trace call vs RemotePdb instance

    Hi, I was looking at doing a similar change as a PR for pudb and was looking at your source.

    Going by your usage instructions - is there any reason to use the RemotePdb class when calling set_trace() with the same parameters seems to take care of that for you?

    Thanks!

    opened by chrisamow 2
  • Connection in Docker drops immediately

    Connection in Docker drops immediately

    I just started using remote-pdb and run into an issue. If I run the debugger inside a running Docker container I am not able to establish a persistent connection with the debugger from the host. If I start a shell inside the docker container and run nc -vv localhost 4444 I obtain the expected prompt:

    localhost (127.0.0.1:4444) open
    > [My code breakpoint info]
    (Pdb) 
    

    But if I run the same from the host, the connection is terminated immediately:

    $ nc -vv localhost 4444
    Notice: Real hostname for localhost [127.0.0.1] is workbox1
    localhost [127.0.0.1] 4444 (krb524) open
    Total received bytes: 0
    Total sent bytes: 0
    

    I'm mapping host port 4444 to guest:4444, and I tried other mappings to ensure that was not the problem, but I get the same result consistently.

    I am using Python 3.7's breakpoint() command. I have the following env variables read by Docker:

    PYTHONBREAKPOINT=remote_pdb.set_trace
    REMOTE_PDB_HOST=127.0.0.1
    REMOTE_PDB_PORT=4444
    

    My host is Arch linux (GNU netcat 0.7.1) and the guest is Alpine (nc part of Busybox 1.30.1). I can reproduce the same issue with socat and telnet.

    This is an increedibly useful tool and if I could use it from the host it would be so much more efficient. Any help is appreciated.

    opened by scossu 2
  • Jython Support

    Jython Support

    Could the project description include a brief statement about whether or not the debugger should function under Jython 2.7.2 ? I see Python 2.7 badge but I know Jython is a bit weird.

    opened by rripken 2
  • pdbpp

    pdbpp

    pdbpp==0.10.2 remote-pdb==2.0.0 Python==3.8.0

    The strangest thing. If I install pdbpp and remote-pdb, the first remote debugging session does not use pdbpp. Subsquent sessions it works.

    What could be going wrong here?

    opened by synic 2
  • Source code gets chopped off in a remote session

    Source code gets chopped off in a remote session

    I'm using this module together with pdbpp. This promises to offer the sticky option of pdbpp also for remote sessions.

    One problem however seems to be that the terminal size is for some reason fixed and this results in not all the code being shown.

    I'm posting this here just to start the conversation, it if possible this might be a pdbpp issue.

    opened by TheMeaningfulEngineer 2
  • Silent / quiet mode

    Silent / quiet mode

    cool tool!

    I'm playing around with curses right now and a remote debugger is exceptionally good for this -- the one thing that's a bit unfortunate is remote-pdb will always print output breaking the curses output:

    would you accept a PR which allows an option (and environment variable) to silence this?

    opened by asottile 2
  • log

    log "cry" messages to "remote_pdb" instead of the root logger

    By configuring "cry" messages to use the "remote_pdb" logger instead of the root logger, a consumer can suppress duplicate messages if the root logger is also configured to log to STDERR

    opened by terencehonles 1
  • Question: PyCharm Debugging with Remote-Pdb?

    Question: PyCharm Debugging with Remote-Pdb?

    Is it possible to attach the PyCharm debugger to a process waiting after executing "RemotePdb("0.0.0.0", 5005).set_trace()"?

    If so, how? I have tried every combination of remote, local, attach, run/debug config and anything else that I can find in the PyCharm UI but nothing seems cause it to connect. What is the PyCharm equivilent of "nc -C 127.0.0.1 5005"?

    opened by MarkDHarris 1
  • Can't send Up arrow or navigate history?

    Can't send Up arrow or navigate history?

    Hi Ionel, Thanks so much for making pyremotepdb, I use it as an alternate to GUI debuggers as I usually need to debug other processes over the network.

    I was just wondering if it's a known issue (or limitation of telnet/nc) that one cannot use the Up arrow keyboard shortcut to reload the last run command. Indeed none of the arrow keys work, simple keyboard shortcuts don't work in my case. (all on Linux, kubuntu 18, etc). I'm not intimately familiar with how stdin works so perhaps this is a limitation that can't be overcome? Would be a shame, I'd love to have remotepdb work just like pdb.

    cheers,

    opened by jorxster 4
  • Add unixsocket support

    Add unixsocket support

    use case:

    >>> import remote_pdb as rpdb
    >>> rpdb.set_trace('./t.sock')
    >>> rpdb.set_trace('t.sock', unixsocket=True)
    >>> rpdb.set_trace(unixsocket='t.sock')
    

    invalid:

    >>> import remote_pdb as rpdb
    >>> rpdb.set_trace('t.sock')
    socket.gaierror: [Errno -2] Name or service not known
    
    opened by heroesm 6
  • python -m remote_pdb equivalent of python -m pdb

    python -m remote_pdb equivalent of python -m pdb

    When invoked as a script, pdb will automatically enter post-mortem debugging if the program being debugged exits abnormally. After post-mortem debugging (or after normal exit of the program), pdb will restart the program. Automatic restarting preserves pdb’s state (such as breakpoints) and in most cases is more useful than quitting the debugger upon program’s exit.

    opened by graingert 0
Owner
Ionel Cristian Mărieș
Ionel Cristian Mărieș
Data Exfiltration without ever making a connection. Using TCP header space.

TCPwned PoC toy code to exfiltrate data without ever making a TCP connection. This will never show up in firewall logs, much less, actually be monitor

null 2 Nov 21, 2022
telnet implementation over TCP socket with python

This a P2P implementation of telnet. This program transfers data on TCP sockets as plain text

null 10 May 19, 2022
Synchronised text editor over TCP, for live editing with others.

SyncTEd Synchronised text editor over TCP, for live editing with others. Written in Python with PyGame. Run Install requirements: pip install -r requi

Marko Živić 1 May 13, 2022
Easy-to-setup bot, ChatOps project for handling telegram chat logging over docker-compose services, being runned as one of them.

Easy-to-setup bot, ChatOps project for handling telegram chat logging over docker-compose services, being runned as one of them.

Rashid 7 Aug 8, 2022
School Project using Python Sockets and Personal Encryption Method.

Python-Secure-File-Transfer School Project using Python Sockets and Personal Encryption Method. Installation Must have python3 installed on your syste

null 1 Dec 3, 2021
A Python module that allows you to create and use simple sockets.

EasySockets A Python module that allows you to create and use simple sockets. Installation The easysockets module can be installed using pip. pip inst

Matthias Wijnsma 2 Jan 16, 2022
Simple reverse backdoor utility, that uses sockets to communicate.

reverse_backdoor Simple reverse backdoor utility, that uses sockets to communicate. How to use Run rev_bd_listener.py using command below: $ python3 r

null 1 Dec 10, 2021
9SPY: a Windows RAT built in Python using sockets

9SPY ??‍?? 9SPY is a Windows RAT built in Python using sockets Features Features will be listed here soon, there are currenly 14 Information This is a

doop 12 Dec 1, 2022
Terminal based chat - networking project with sockets in python

Terminal based chat - networking project with sockets in python

null 2 Jan 24, 2022
Start a simple TCP Listener on a specified IP Address and Port Number and receive incoming connections.

About Start a simple TCP Listener on a specified IP Address and Port Number and receive incoming connections. Download Clone using git in terminal(git

AgentGeneric 5 Feb 24, 2022
A tool which is capable of scanning ports as TCP & UDP and detecting open and closed ones.

PortScanner Scan All Open Ports Of The Target IP. A tool which is capable of scanning ports as TCP & UDP and detecting open and closed ones. Clone fro

Msf Nmt 17 Nov 26, 2022
Passive TCP/IP Fingerprinting Tool. Run this on your server and find out what Operating Systems your clients are *really* using.

Passive TCP/IP Fingerprinting This is a passive TCP/IP fingerprinting tool. Run this on your server and find out what operating systems your clients a

Nikolai Tschacher 158 Dec 20, 2022
A Simplest TCP client and echo server

Простейшие TCP-клиент и эхо-сервер Цель работы Познакомиться с приемами работы с сетевыми сокетами в языке программирования Python. Задания для самост

Юля Нагубнева 1 Oct 25, 2021
NetMiaou is an crossplatform hacking tool that can do reverse shells, send files, create an http server or send and receive tcp packet

NetMiaou is an crossplatform hacking tool that can do reverse shells, send files, create an http server or send and receive tcp packet

TRIKKSS 5 Oct 5, 2022
GlokyPortScannar is a really fast tool to scan TCP ports implemented in Python.

GlokyPortScannar is a really fast tool to scan TCP ports implemented in Python. Installation: This program requires Python 3.9. Linux

gl0ky 5 Jun 25, 2022
This is the code repository for the USENIX Security 2021 paper, "Weaponizing Middleboxes for TCP Reflected Amplification".

weaponizing-censors Censors pose a threat to the entire Internet. In this work, we show that censoring middleboxes and firewalls can be weaponized by

UMD Breakerspace 119 Dec 31, 2022
PetrickScanner is a simple Python OOP TCP Port Scanner

PetrickScanner PetrickScanner is a simple Python OOP TCP Port Scanner Functions Python TCP Port Scanner DNS Resolver Random Scanner PLEASE ANY PROBLEM

null 11 Nov 30, 2021
Mini SCADA. Poll modbus devices by TCP/IP network.

Plans Add saving and loading devices and channels with files or db or someone else. Multitasking system for poll all devices Automatic optimization po

Efi_fi 1 Oct 25, 2021
Evaluation of TCP BBRv1 in wireless networks

The Network Simulator, Version 3 Table of Contents: An overview Building ns-3 Running ns-3 Getting access to the ns-3 documentation Working with the d

null 3 Nov 1, 2021