File size: 5,816 Bytes
d32d0a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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)

@bot.message_handler(commands=['start', 'help'])
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')

@bot.message_handler(commands=['toolkit'])
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)}")

@bot.message_handler(commands=['run'])
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)}")

@bot.message_handler(commands=['geoip'])
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>")

@bot.message_handler(commands=['portscan'])
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>")

@bot.message_handler(commands=['whois'])
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)}")

@bot.message_handler(commands=['headers'])
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()