Get Telegram notifications when requests are being made to your web server
Project description
Telegram HTTP notification script
This script will notify you of any or selected HTTP requests made to your server, using the Telegram API.
Rationale
During a phishing assignment I was tasked with writing a script similar to this one, to keep track of people that clicked on our link, downloaded our malicious payload, and submitted a form with their personal details. I decided to make it more general-purpose and further maintain it here. :-)
How to set it up
TL;DR - basically 4 steps:
- Create your own Telegram bot
- Create a new (private) channel and add your bot to that channel
- Either hardcode your bot key, chat ID, and web server log file in this script, or use the script arguments.
- Consider running the script in a
screensession to run it in the background so that you can leave your shell.
Detailed explanation:
First, you will need to create your own Telegram bot, which is basically just an API key without any logic (unless you really want to create a full fledged bot). Once you've created your bot using the @BotFather it will also tell your the bot key (API key). You can either hardcode the bot key in this script, or provide it as an argument (-k) when running this script.
Second, create a Telegram (private) channel and write down the chat ID. If you have trouble finding the chat ID, you can use @username_to_id_bot and paste the invite link in there. It will tell you the channel's chat ID, which you can also hardcode into the script if you want, or provide it as an argument (-c) when running this script. Don't forget to also explicitely add the bot to the channel.
Third, either hardcode the web server's access.log file location as well, or provide it as an argument (-l) when running this script.
Finally, run the script. Consider running the script in a screen session to run it in the background so that you can leave your shell (e.g. screen -S thns bash thns.sh -m -s).
You can safely detach from the screen session by pressing CTRL+A+D.
Now you can safely logout and the script will remain in the background.
To attach again, login to your server again and run screen -r thns.
Usage
usage: thns [-h] [-c TELEGRAM_CHAT_ID] [-g] [-i IGNORE [IGNORE ...]]
[-k TELEGRAM_BOT_KEY] [-l LOG_FILE] [-m]
[-r MATCH_REQUESTS [MATCH_REQUESTS ...]] [-s] [-u]
Get Telegram notifications when requests are being made your web server
optional arguments:
-h, --help show this help message and exit
-c TELEGRAM_CHAT_ID, --chat-id TELEGRAM_CHAT_ID
Specify the Telegram chat ID to post to.
-g, --geo Include geographical information.
-i IGNORE [IGNORE ...], --ignore-ips IGNORE [IGNORE ...]
Ignore (multiple) IP addresses (e.g. 127.0.0.1 ::1).
-k TELEGRAM_BOT_KEY, --bot-key TELEGRAM_BOT_KEY
Specify the Telegram bot key.
-l LOG_FILE, --log-file LOG_FILE
Specify the (Nginx) log file.
-m, --map Post a map pointer.
-r MATCH_REQUESTS [MATCH_REQUESTS ...], --match-requests MATCH_REQUESTS [MATCH_REQUESTS ...]
Match (multiple) specific HTTP requests (e.g. /
/robots.txt).
-s, --silent Send Telegram messages silently.
-u, --user-agent Include the user agent string.
Example
Consider using screen to run it in the background. For example:
$ screen -S -d -m python3 -m thns -m -s -l /var/log/nginx/access.log -c "-1234567890123" -k "123456789:1234567890abcdefghijklmnopqrstuvwxyz" -i 127.0.0.1 ::1
Then watch your Telegram channel fill:
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
File details
Details for the file thns-0.0.2.tar.gz.
File metadata
- Download URL: thns-0.0.2.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.6.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a15566f1d4fb29c984cd1bd0fe2ea4b7db3d6732af0621515e88a8cef8f3273
|
|
| MD5 |
974286cf7c3e6c91e1a65b0c6eb8cd2a
|
|
| BLAKE2b-256 |
0add6065fa1860a138d4b1a4f4364dbab558be03ab93dec03f4734aa020d03d5
|