A Telegram Remote Shell Bot with HOTP authentication.
Project description
TeleRemBash is a Telegram Remote Bash Bot for executing scripts on the remote system, baked with TOTP Authentication for easy and secure setup.
To keep things simple TeleRamBash allows a single Telegram user after a successful TOTP Authentication to execute a pre-defined (bash) script by sending a command to the Bot in a Telegram chat, like this:
/do some-script optional-param1
Usage
To install from pypi:
pip install telerembash
First create a configuration for your Telegram Bot instance by specifying the bot’s API_TOKEN and the Telegram username of the whitelisted user:
telerem init --api_token API_TOKEN --username USERNAME
this should create a telerem.config.yaml in the current directory and output a QR Code you can scan in your TOTP Authenticator App (i.e. Google Authenticator, andOTP, etc).
To see all available options, try:
telerem --help
you can edit telerem.config.yaml by hand or call telerem init multiple times, to tweak the config. Note the scripts_root in the config - this is the location (absolute or relative to the current working directory) of the directory containing the script your bot will execute.
To start the bot:
telerem start --config config.yaml
Once your bot is running, you should add it in a chat. It will ignore all your messages until it sees a
/auth <code>
command, where <code> is the code generated by your TOTP Authenticator.
And once you are successfully authenticated, you can execute a script with a Telegram message like this:
/do some-script-name param1 param2
The bot will reply to such a command by looking under scripts_root for a file with the name some-script-name or some-script-name.sh and executing it (with the provided optional parameters).
Run as a Service (WIP)
You can also create a systemd service or a daemon script for starting your bot as a daemon with:
telerem install --systemd | sudo bash # for systemd
telerem install --initd | sudo bash # otherwise
this will:
create a system user teleremd
setup a python venv under /home/teleremd/
create a service (either systemd or init.d):
systemd service unit /etc/systemd/system/teleremd.service
deamon script /etc/init.d/teleremd
populate the daemon configuration under /etc/teleremd.config.yaml
and finally:
sudo systemctl daemon-reload # for systemd
sudo systemctl start teleremd
NEWS
16.Jan.2021 - install as a systemd service (init.d still WIP)
15.Jan.2021 - README: Usage instructions
09.Jan.2021 - initial commit
LICENSE
MIT. See License File.
Resources
Telegram - Telegram BOT API
PyOTP - The Python One-Time Password Library
python-qrcode - QR code generator for text terminals
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
Hashes for telerembash-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2189ea057fc44b69fb31882cec96bbfa5608df972cb6bac519ba7fb5a7397e40 |
|
MD5 | 694d00e93ec86c6be0b5f0432c3f80d2 |
|
BLAKE2b-256 | a18b97ae0a6481599a5cc9ffe0bb5a98a6c96b791b9c61ea0166a58334608f5a |