Python reverse bash shell
Project description
Deployment debugging with hacker’s tools.
Install
pip install reshell
Usage
On the host launch receiver with
$ nc -lvp 12345
On destination host launch reverse shell:
$ reshell 127.0.0.1:12345
(or with env variable instead of argument):
$ export RESHELL_TARGET=127.0.0.1:12345
$ reshell
TeamCity Command Line Build Step:
virtualenv .env
. .env/bin/activate
pip install reshell
reshell
Make sure you add env.RESHELL_TARGET to Build Parameters.
reshell will try to connect to it’s target every 10 seconds for 10 minutes. After 10 minutes it will exit.
Start from Python
Start reshell in a background daemon process:
from reshell import start_daemon
start_daemon('127.0.0.1:12345')
Terminology
Since not all developers are familiar with hacker’s technics, I’ll briefly describe what is this all about.
When you open terminal on your machine, it’s local shell.
When you run SSH to connect to remote machine, it’s remote shell.
When you listen on port on your machine and make remote machine to connect to you, it’s reverse shell.
Ethics
This tool is not usefull for actual hacking. Since you already have an ability to execute arbitrary code on remote machine, it won’t buy anything in terms of access. You just need a shell as an arbitrary code.
Reverse benefits
Reverse shells have some advantages over remote shells:
Bypass firewall - incoming connections are often blocked on unused ports. Whereas outgoing connections are usually allowed.
More secure - instead of inviting everyone to backdoor, reverse shell communicates with single host:port
Destination can be unknown - even inaccessible. It’s the host machine that must be accessible from the destination. Not the other way around.
Background (use case)
Imagine crazy environment. You can deploy Python application to cloudy remote host and have it running. But you don’t have SSH access and can’t debug it or see startup logs. Also you don’t know in advance what will be network address of the remote host.
But you have a dev machine in the same network, where you are free to run anything:
So you launch server on dev machine and deploy reverse shell through regular deployment process.
Once the application is deployed, it will connect to the server and turn itself into bash.
… You can poke around and figure out what’s wrong …
PROFIT!
Bonus (Pro tips)
nc is not the most convinient shell, you would want to use in day job. You won’t have access to shortcuts, such as up arrow, or Ctrl-P for previous command. It doesn’t expand tabs in-place, but does it after command is sent. For example you could write:
$ ls /us<TAB>loc<TAB>li
ls /usr/local/lib
Special caution should be taken when dealing with Keyboard Interrupt. If you press Ctrl+C inside nc session, it will be caught by nc process itself and though will not be sent to remote machine. Instead you can place a signal trap for SIGINT before launching nc:
$ trap '' INT
$ nc -lvp 12345
To send Ctrl+C to remote machine (to iterrupt current process) you can use combination Ctrl+V Ctrl+C Return. Ctrl+V says bash to send following symbol as-is, without processing it. Return is needed to actually send ^C command.
When finished, terminate remote session with:
$ exit
History
1.1.1 (2024-07-23)
Added Python launcher
1.0.2 (2017-06-22)
Updated README
0.1.0 (2015-02-30)
First release on PyPI.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file reshell-1.1.1.tar.gz
.
File metadata
- Download URL: reshell-1.1.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b2d1b1c6b32d96eb1ee224d3c4840a576f6e24cc8a19883b1c626217b6e80f8 |
|
MD5 | 0dbffa72369808c8436d56c874ba3585 |
|
BLAKE2b-256 | 22cb5cc6f17960f7788de8b98999f5d4778fd793f287e5b91d75ab63977b82f7 |
File details
Details for the file reshell-1.1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: reshell-1.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e8e12532d2c90c0edbdebd282049bdc5b801f74d9b11f7e87855a0c788f164d |
|
MD5 | 78dc66a55073fc942455413790ba0265 |
|
BLAKE2b-256 | 4585c75835b0b33aa5f6a5f601659a73de6bb3ca31a9e8df59694c5fb9b15fc6 |