Spaces:
Runtime error
Runtime error
Download bot.py from Ramiz404/Cyber_Toolkit_Bot: direct link, hf CLI and curl.
- Browser
- Download file 5.82 kB
-
https://huggingface.co/spaces/Ramiz404/Cyber_Toolkit_Bot/resolve/main/bot.py
- Command line
-
hf download hf://spaces/Ramiz404/Cyber_Toolkit_Bot/bot.py
-
curl -L -o bot.py https://huggingface.co/spaces/Ramiz404/Cyber_Toolkit_Bot/resolve/main/bot.py
5.82 kB
| import telebot | |
| import requests | |
| import socket | |
| import whois | |
| import os | |
| import subprocess | |
| from datetime import datetime | |
| # YOUT BOT TOKEN HERE | |
| TOKEN = '8657709560:AAEipMz944RDOlpT43haLJo6QB-2vqjUH2U' | |
| TOOLKIT_CORE = '/data/data/com.termux/files/home/Cyber-Toolkit/core' | |
| bot = telebot.TeleBot(TOKEN) | |
| def send_welcome(message): | |
| help_text = """ | |
| π‘οΈ *Cyber & Pentest Assistant Bot* π‘οΈ | |
| Commands: | |
| /geoip <ip> - Get Geo-Location of an IP | |
| /portscan <ip> - Scan common ports (1-100) | |
| /whois <domain> - Get WHOIS info for a domain | |
| /headers <url> - Check HTTP Security Headers | |
| /dns <domain> - Get DNS A records | |
| π¦ *Cyber-Toolkit Integration* | |
| /toolkit - List all tools in Cyber-Toolkit | |
| /run <tool_name> <args> - Run a specific tool (e.g., /run ip_lookup.py 8.8.8.8) | |
| """ | |
| bot.reply_to(message, help_text, parse_mode='Markdown') | |
| def list_toolkit(message): | |
| try: | |
| files = [f for f in os.listdir(TOOLKIT_CORE) if f.endswith('.py') and f != 'main.py'] | |
| files.sort() | |
| response = "π οΈ *Available Tools in Cyber-Toolkit:*\n\n" | |
| # Split into chunks if too long for Telegram | |
| chunk_size = 30 | |
| for i in range(0, len(files), chunk_size): | |
| chunk = files[i:i + chunk_size] | |
| bot.send_message(message.chat.id, "\n".join(chunk)) | |
| except Exception as e: | |
| bot.reply_to(message, f"β Error listing toolkit: {str(e)}") | |
| def run_tool(message): | |
| try: | |
| args = message.text.split() | |
| if len(args) < 2: | |
| bot.reply_to(message, "Usage: /run <tool_name> <args>") | |
| return | |
| tool_name = args[1] | |
| tool_args = args[2:] | |
| tool_path = os.path.join(TOOLKIT_CORE, tool_name) | |
| if not os.path.exists(tool_path): | |
| bot.reply_to(message, f"β Tool '{tool_name}' not found.") | |
| return | |
| bot.reply_to(message, f"π Running {tool_name}...") | |
| # Run the tool and capture output | |
| # Using a timeout to prevent infinite loops/long runs | |
| cmd = ['python3', tool_path] + tool_args | |
| result = subprocess.run(cmd, capture_output=True, text=True, timeout=60, cwd=TOOLKIT_CORE) | |
| output = result.stdout if result.stdout else "No output." | |
| if result.stderr: | |
| output += f"\n\n*Error Output:*\n{result.stderr}" | |
| # If output is too long, truncate it | |
| if len(output) > 4000: | |
| output = output[:4000] + "...(truncated)" | |
| bot.reply_to(message, f"π *Output for {tool_name}:*\n\n`{output}`", parse_mode='Markdown') | |
| except subprocess.TimeoutExpired: | |
| bot.reply_to(message, "β³ Execution timed out (60s).") | |
| except Exception as e: | |
| bot.reply_to(message, f"β Error: {str(e)}") | |
| def geoip_lookup(message): | |
| try: | |
| ip = message.text.split()[1] | |
| response = requests.get(f"http://ip-api.com/json/{ip}").json() | |
| if response['status'] == 'success': | |
| info = f"π *GeoIP Info for {ip}*\n\n" \ | |
| f"π Country: {response.get('country')}\n" \ | |
| f"ποΈ City: {response.get('city')}\n" \ | |
| f"π‘ ISP: {response.get('isp')}\n" \ | |
| f"π Lat/Lon: {response.get('lat')}, {response.get('lon')}" | |
| bot.reply_to(message, info, parse_mode='Markdown') | |
| else: | |
| bot.reply_to(message, "β Invalid IP or API error.") | |
| except IndexError: | |
| bot.reply_to(message, "Usage: /geoip <ip>") | |
| def port_scanner(message): | |
| try: | |
| target = message.text.split()[1] | |
| bot.reply_to(message, f"π Scanning ports 1-100 for {target}...") | |
| open_ports = [] | |
| for port in range(1, 101): | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| socket.setdefaulttimeout(1) | |
| result = s.connect_ex((target, port)) | |
| if result == 0: | |
| open_ports.append(port) | |
| s.close() | |
| if open_ports: | |
| bot.reply_to(message, f"β Open Ports: {', '.join(map(str, open_ports))}") | |
| else: | |
| bot.reply_to(message, "π« No open ports found in 1-100 range.") | |
| except Exception: | |
| bot.reply_to(message, "Usage: /portscan <ip>") | |
| def whois_lookup(message): | |
| try: | |
| domain = message.text.split()[1] | |
| w = whois.whois(domain) | |
| info = f"π *WHOIS Info for {domain}*\n\n" \ | |
| f"π’ Registrar: {w.registrar}\n" \ | |
| f"π Creation Date: {w.creation_date}\n" \ | |
| f"β³ Expiration: {w.expiration_date}\n" \ | |
| f"π§ Email: {w.emails}" | |
| bot.reply_to(message, info, parse_mode='Markdown') | |
| except Exception as e: | |
| bot.reply_to(message, f"β WHOIS lookup failed: {str(e)}") | |
| def check_headers(message): | |
| try: | |
| url = message.text.split()[1] | |
| if not url.startswith('http'): | |
| url = 'http://' + url | |
| res = requests.get(url, timeout=5) | |
| headers = res.headers | |
| security_headers = ['Content-Security-Policy', 'X-Frame-Options', 'X-Content-Type-Options', 'Strict-Transport-Security'] | |
| report = f"π‘οΈ *Security Headers for {url}*\n\n" | |
| for sh in security_headers: | |
| status = "β " if sh in headers else "β" | |
| report += f"{status} {sh}\n" | |
| bot.reply_to(message, report, parse_mode='Markdown') | |
| except Exception: | |
| bot.reply_to(message, "Usage: /headers <url>") | |
| print("Bot is running...") | |
| bot.infinity_polling() | |