Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,9 @@
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
import logging
|
| 4 |
-
import numpy as np
|
| 5 |
import asyncio
|
| 6 |
import aiohttp
|
| 7 |
-
import
|
| 8 |
-
import sys
|
| 9 |
-
import time
|
| 10 |
-
import threading
|
| 11 |
-
from fastapi import FastAPI, HTTPException, BackgroundTasks, WebSocket, WebSocketDisconnect
|
| 12 |
from fastapi.responses import HTMLResponse
|
| 13 |
from fastapi.staticfiles import StaticFiles
|
| 14 |
from pydantic import BaseModel, Field
|
|
@@ -21,26 +16,18 @@ from transformers import (
|
|
| 21 |
StoppingCriteria,
|
| 22 |
StoppingCriteriaList,
|
| 23 |
)
|
| 24 |
-
import
|
| 25 |
-
import
|
| 26 |
-
import
|
| 27 |
-
from
|
| 28 |
-
import
|
| 29 |
-
|
| 30 |
-
import win32api
|
| 31 |
-
import win32con
|
| 32 |
-
import win32gui
|
| 33 |
-
import win32process
|
| 34 |
-
import ctypes
|
| 35 |
-
from ctypes import wintypes
|
| 36 |
-
import pythoncom
|
| 37 |
-
import pygetwindow as gw
|
| 38 |
-
from selenium import webdriver
|
| 39 |
-
from selenium.webdriver.chrome.options import Options
|
| 40 |
-
from webdriver_manager.chrome import ChromeDriverManager
|
| 41 |
import warnings
|
| 42 |
warnings.filterwarnings("ignore")
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
# التهيئة الأساسية
|
| 45 |
os.environ["HF_HOME"] = "/tmp/hf_cache"
|
| 46 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/hf_cache/transformers"
|
|
@@ -61,26 +48,21 @@ logger = logging.getLogger(__name__)
|
|
| 61 |
# نماذج البيانات
|
| 62 |
class WindowsTask(BaseModel):
|
| 63 |
task_description: str = Field(..., min_length=5, max_length=2000)
|
| 64 |
-
task_type: str = "analysis"
|
| 65 |
game_name: Optional[str] = None
|
| 66 |
-
priority: str = "normal"
|
| 67 |
-
|
| 68 |
-
class SystemCommand(BaseModel):
|
| 69 |
-
command: str
|
| 70 |
-
args: List[str] = []
|
| 71 |
-
run_as_admin: bool = False
|
| 72 |
-
timeout: int = 30
|
| 73 |
|
| 74 |
-
class
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
|
| 79 |
-
class
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
| 84 |
|
| 85 |
# نموذج التوقف المخصص
|
| 86 |
class StopOnTokens(StoppingCriteria):
|
|
@@ -91,23 +73,20 @@ class StopOnTokens(StoppingCriteria):
|
|
| 91 |
return True
|
| 92 |
return False
|
| 93 |
|
| 94 |
-
# النظام الأساسي المتقدم لل
|
| 95 |
-
class
|
| 96 |
def __init__(self):
|
| 97 |
self.tokenizer = None
|
| 98 |
self.model = None
|
| 99 |
self.pipeline = None
|
| 100 |
self.is_loaded = False
|
| 101 |
-
self.
|
| 102 |
-
self.bot_threads = {}
|
| 103 |
-
self.system_monitor = None
|
| 104 |
self.load_models()
|
| 105 |
-
self.initialize_system_hooks()
|
| 106 |
|
| 107 |
def load_models(self):
|
| 108 |
"""تحميل النماذج المتخصصة"""
|
| 109 |
try:
|
| 110 |
-
logger.info("جارٍ تحميل النماذج المتخصصة
|
| 111 |
|
| 112 |
model_name = "microsoft/DialoGPT-medium"
|
| 113 |
self.tokenizer = AutoTokenizer.from_pretrained(
|
|
@@ -144,44 +123,6 @@ class WindowsAIController:
|
|
| 144 |
logger.error(f"فشل تحميل النماذج: {e}")
|
| 145 |
raise e
|
| 146 |
|
| 147 |
-
def initialize_system_hooks(self):
|
| 148 |
-
"""تهيئة خطاطف النظام"""
|
| 149 |
-
try:
|
| 150 |
-
# بدء مراقب النظام
|
| 151 |
-
self.system_monitor = SystemMonitor()
|
| 152 |
-
self.system_monitor.start()
|
| 153 |
-
|
| 154 |
-
# تهيئة خطاطف لوحة المفاتيح والفأرة
|
| 155 |
-
self.keyboard_listener = pynput.keyboard.Listener(
|
| 156 |
-
on_press=self.on_key_press,
|
| 157 |
-
on_release=self.on_key_release
|
| 158 |
-
)
|
| 159 |
-
self.keyboard_listener.start()
|
| 160 |
-
|
| 161 |
-
logger.info("تم تهيئة خطاطف النظام بنجاح")
|
| 162 |
-
except Exception as e:
|
| 163 |
-
logger.error(f"فشل تهيئة خطاطف النظام: {e}")
|
| 164 |
-
|
| 165 |
-
def on_key_press(self, key):
|
| 166 |
-
"""معالجة ضغطات المفاتيح"""
|
| 167 |
-
try:
|
| 168 |
-
key_str = str(key).replace("'", "")
|
| 169 |
-
# يمكن تسجيل الضغطات لأغراض البوتات
|
| 170 |
-
if hasattr(self, 'active_bot') and self.active_bot:
|
| 171 |
-
self.active_bot.handle_key_press(key_str)
|
| 172 |
-
except Exception as e:
|
| 173 |
-
logger.debug(f"خطأ في معالجة ضغط المفتاح: {e}")
|
| 174 |
-
|
| 175 |
-
def on_key_release(self, key):
|
| 176 |
-
"""معالجة تحرير المفاتيح"""
|
| 177 |
-
try:
|
| 178 |
-
key_str = str(key).replace("'", "")
|
| 179 |
-
# إيقاف البوت عند الضغط على Escape
|
| 180 |
-
if key == keyboard.Key.esc:
|
| 181 |
-
self.stop_all_bots()
|
| 182 |
-
except Exception as e:
|
| 183 |
-
logger.debug(f"خطأ في معالجة تحرير المفتاح: {e}")
|
| 184 |
-
|
| 185 |
def generate_ai_response(self, prompt: str, context: List[Dict] = None) -> str:
|
| 186 |
"""توليد رد الذكاء الاصطناعي"""
|
| 187 |
try:
|
|
@@ -217,689 +158,235 @@ class WindowsAIController:
|
|
| 217 |
logger.error(f"فشل توليد الرد: {e}")
|
| 218 |
return f"عذراً، حدث خطأ في معالجة طلبك: {str(e)}"
|
| 219 |
|
| 220 |
-
async def execute_windows_task(self, task: WindowsTask) -> Dict:
|
| 221 |
-
"""تنفيذ مهمة Windows متقدمة"""
|
| 222 |
-
try:
|
| 223 |
-
task_plan = self.analyze_task(task.task_description)
|
| 224 |
-
|
| 225 |
-
results = {
|
| 226 |
-
"task_id": f"task_{int(time.time())}",
|
| 227 |
-
"task_type": task.task_type,
|
| 228 |
-
"status": "running",
|
| 229 |
-
"steps": [],
|
| 230 |
-
"results": {},
|
| 231 |
-
"errors": []
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
# تنفيذ المهمة بناءً على النوع
|
| 235 |
-
if task.task_type == "analysis":
|
| 236 |
-
await self.perform_game_analysis(task, results)
|
| 237 |
-
elif task.task_type == "bot_creation":
|
| 238 |
-
await self.create_game_bot(task, results)
|
| 239 |
-
elif task.task_type == "software_install":
|
| 240 |
-
await self.install_required_software(task, results)
|
| 241 |
-
elif task.task_type == "hacking":
|
| 242 |
-
await self.perform_hacking_analysis(task, results)
|
| 243 |
-
elif task.task_type == "automation":
|
| 244 |
-
await self.create_automation_script(task, results)
|
| 245 |
-
|
| 246 |
-
results["status"] = "completed"
|
| 247 |
-
return results
|
| 248 |
-
|
| 249 |
-
except Exception as e:
|
| 250 |
-
logger.error(f"فشل تنفيذ المهمة: {e}")
|
| 251 |
-
return {"error": str(e), "status": "failed"}
|
| 252 |
-
|
| 253 |
def analyze_task(self, task_description: str) -> Dict:
|
| 254 |
-
"""تحليل المهمة و
|
| 255 |
analysis_prompt = f"""
|
| 256 |
-
قم بتحليل المهمة التالية و
|
| 257 |
{task_description}
|
| 258 |
|
| 259 |
-
قدم خطة تنفيذ
|
| 260 |
1. الأدوات المطلوبة
|
| 261 |
2. الخطوات التقنية
|
| 262 |
-
3. ال
|
| 263 |
-
4. ال
|
|
|
|
|
|
|
|
|
|
| 264 |
"""
|
| 265 |
|
| 266 |
plan = self.generate_ai_response(analysis_prompt)
|
| 267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
-
def
|
| 270 |
"""استخراج خطوات التنفيذ من الخطة"""
|
| 271 |
steps = []
|
| 272 |
lines = plan.split('\n')
|
| 273 |
|
| 274 |
for line in lines:
|
| 275 |
line = line.strip()
|
| 276 |
-
if any(marker in line for marker in ['1.', '2.', '3.', '4.', '5.', '- ', '• ']):
|
| 277 |
if len(line) > 10:
|
| 278 |
-
|
|
|
|
|
|
|
| 279 |
|
| 280 |
-
return steps[:
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
"""ت
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
game_info = await self.research_game(game_name)
|
| 291 |
-
results["results"]["game_info"] = game_info
|
| 292 |
-
|
| 293 |
-
# 2. تحليل عملية اللعبة
|
| 294 |
-
process_analysis = self.analyze_game_process(game_name)
|
| 295 |
-
results["results"]["process_analysis"] = process_analysis
|
| 296 |
-
|
| 297 |
-
# 3. فحص ملفات اللعبة
|
| 298 |
-
file_analysis = self.analyze_game_files(game_name)
|
| 299 |
-
results["results"]["file_analysis"] = file_analysis
|
| 300 |
-
|
| 301 |
-
# 4. تحليل الذاكرة
|
| 302 |
-
memory_analysis = await self.analyze_game_memory(game_name)
|
| 303 |
-
results["results"]["memory_analysis"] = memory_analysis
|
| 304 |
-
|
| 305 |
-
# 5. تحليل الشبكة
|
| 306 |
-
network_analysis = await self.analyze_network_traffic(game_name)
|
| 307 |
-
results["results"]["network_analysis"] = network_analysis
|
| 308 |
-
|
| 309 |
-
results["steps"].append("اكتمل تحليل اللعبة بنجاح")
|
| 310 |
-
|
| 311 |
-
except Exception as e:
|
| 312 |
-
results["errors"].append(f"خطأ في تحليل اللعبة: {str(e)}")
|
| 313 |
-
logger.error(f"فشل تحليل اللعبة: {e}")
|
| 314 |
-
|
| 315 |
-
async def create_game_bot(self, task: WindowsTask, results: Dict):
|
| 316 |
-
"""إنشاء بوت للعبة"""
|
| 317 |
-
try:
|
| 318 |
-
game_name = task.game_name or self.extract_game_name(task.task_description)
|
| 319 |
-
|
| 320 |
-
results["steps"].append("بدء بناء البوت...")
|
| 321 |
-
|
| 322 |
-
# 1. تحليل متطلبات البوت
|
| 323 |
-
bot_requirements = self.analyze_bot_requirements(task.task_description)
|
| 324 |
-
results["results"]["requirements"] = bot_requirements
|
| 325 |
-
|
| 326 |
-
# 2. إنشاء كود البوت
|
| 327 |
-
bot_code = self.generate_bot_code(game_name, bot_requirements)
|
| 328 |
-
results["results"]["bot_code"] = bot_code
|
| 329 |
-
|
| 330 |
-
# 3. تجميع البوت
|
| 331 |
-
bot_file = self.compile_bot(bot_code, game_name)
|
| 332 |
-
results["results"]["bot_file"] = bot_file
|
| 333 |
-
|
| 334 |
-
# 4. اختبار البوت
|
| 335 |
-
test_results = await self.test_bot(bot_file, game_name)
|
| 336 |
-
results["results"]["test_results"] = test_results
|
| 337 |
-
|
| 338 |
-
results["steps"].append("اكتمل بناء البوت بنجاح")
|
| 339 |
-
|
| 340 |
-
except Exception as e:
|
| 341 |
-
results["errors"].append(f"خطأ في بناء البوت: {str(e)}")
|
| 342 |
-
logger.error(f"فشل بناء البوت: {e}")
|
| 343 |
-
|
| 344 |
-
async def install_required_software(self, task: WindowsTask, results: Dict):
|
| 345 |
-
"""تثبيت البرامج المطلوبة"""
|
| 346 |
-
try:
|
| 347 |
-
software_list = self.extract_software_requirements(task.task_description)
|
| 348 |
-
|
| 349 |
-
results["steps"].append("بدء تثبيت البرامج...")
|
| 350 |
-
|
| 351 |
-
installed_software = []
|
| 352 |
-
for software in software_list:
|
| 353 |
-
try:
|
| 354 |
-
installation_result = await self.install_software(software)
|
| 355 |
-
installed_software.append({
|
| 356 |
-
"software": software,
|
| 357 |
-
"status": "installed",
|
| 358 |
-
"details": installation_result
|
| 359 |
-
})
|
| 360 |
-
except Exception as e:
|
| 361 |
-
installed_software.append({
|
| 362 |
-
"software": software,
|
| 363 |
-
"status": "failed",
|
| 364 |
-
"error": str(e)
|
| 365 |
-
})
|
| 366 |
-
|
| 367 |
-
results["results"]["installed_software"] = installed_software
|
| 368 |
-
results["steps"].append("اكتمل تثبيت البرامج")
|
| 369 |
-
|
| 370 |
-
except Exception as e:
|
| 371 |
-
results["errors"].append(f"خطأ في تثبيت البرامج: {str(e)}")
|
| 372 |
-
logger.error(f"فشل تثبيت البرامج: {e}")
|
| 373 |
-
|
| 374 |
-
def extract_game_name(self, description: str) -> str:
|
| 375 |
-
"""استخراج اسم اللعبة من الوصف"""
|
| 376 |
-
# تحليل الوصف للعثور على اسم اللعبة
|
| 377 |
-
words = description.lower().split()
|
| 378 |
-
game_keywords = ['game', 'لعبة', 'game:', 'لعبة:']
|
| 379 |
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
|
|
|
| 383 |
|
| 384 |
-
return
|
| 385 |
-
|
| 386 |
-
async def research_game(self, game_name: str) -> Dict:
|
| 387 |
-
"""البحث عن معلومات اللعبة"""
|
| 388 |
-
try:
|
| 389 |
-
research_prompt = f"""
|
| 390 |
-
ابحث عن المعلومات التقنية للعبة {game_name}:
|
| 391 |
-
- محرك اللعبة
|
| 392 |
-
- لغة البرمجة
|
| 393 |
-
- طرق الحماية
|
| 394 |
-
- نقاط الضعف المعروفة
|
| 395 |
-
- أدوات التعديل الشائعة
|
| 396 |
-
"""
|
| 397 |
-
|
| 398 |
-
info = self.generate_ai_response(research_prompt)
|
| 399 |
-
return {"game_name": game_name, "technical_info": info}
|
| 400 |
-
|
| 401 |
-
except Exception as e:
|
| 402 |
-
return {"error": str(e)}
|
| 403 |
|
| 404 |
-
def
|
| 405 |
-
"""ت
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
return {"error": str(e)}
|
| 425 |
-
|
| 426 |
-
def get_process_modules(self, pid: int) -> List[str]:
|
| 427 |
-
"""الحصول على وحدات العملية"""
|
| 428 |
-
try:
|
| 429 |
-
process = psutil.Process(pid)
|
| 430 |
-
modules = []
|
| 431 |
-
for lib in process.memory_maps():
|
| 432 |
-
modules.append(lib.path)
|
| 433 |
-
return modules[:20] # إرجاع أول 20 وحدة فقط
|
| 434 |
-
except:
|
| 435 |
-
return []
|
| 436 |
-
|
| 437 |
-
def analyze_game_files(self, game_name: str) -> Dict:
|
| 438 |
-
"""تحليل ملفات اللعبة"""
|
| 439 |
-
try:
|
| 440 |
-
common_paths = [
|
| 441 |
-
f"C:\\Program Files\\{game_name}",
|
| 442 |
-
f"C:\\Program Files (x86)\\{game_name}",
|
| 443 |
-
f"D:\\Games\\{game_name}",
|
| 444 |
-
os.path.expanduser(f"~\\Documents\\{game_name}")
|
| 445 |
-
]
|
| 446 |
-
|
| 447 |
-
game_files = {}
|
| 448 |
-
for path in common_paths:
|
| 449 |
-
if os.path.exists(path):
|
| 450 |
-
files = self.scan_game_directory(path)
|
| 451 |
-
game_files[path] = files
|
| 452 |
-
|
| 453 |
-
return {"scanned_paths": common_paths, "found_files": game_files}
|
| 454 |
-
|
| 455 |
-
except Exception as e:
|
| 456 |
-
return {"error": str(e)}
|
| 457 |
|
| 458 |
-
def
|
| 459 |
-
"""
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
"
|
| 463 |
-
"
|
| 464 |
-
|
| 465 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
}
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
important_files["log_files"].append(file_path)
|
| 481 |
-
|
| 482 |
-
return important_files
|
| 483 |
-
|
| 484 |
-
except Exception as e:
|
| 485 |
-
return {"error": str(e)}
|
| 486 |
-
|
| 487 |
-
async def analyze_game_memory(self, game_name: str) -> Dict:
|
| 488 |
-
"""تحليل ذاكرة اللعبة"""
|
| 489 |
-
try:
|
| 490 |
-
# هذا يتطلب صلاحيات متقدمة
|
| 491 |
-
analysis = {
|
| 492 |
-
"memory_regions": [],
|
| 493 |
-
"pointers_found": 0,
|
| 494 |
-
"patterns_detected": []
|
| 495 |
}
|
| 496 |
-
|
| 497 |
-
for proc in psutil.process_iter():
|
| 498 |
-
try:
|
| 499 |
-
if game_name.lower() in proc.name().lower():
|
| 500 |
-
# تحليل ذاكرة العملية
|
| 501 |
-
memory_info = self.advanced_memory_analysis(proc.pid)
|
| 502 |
-
analysis["memory_regions"].append({
|
| 503 |
-
"process": proc.name(),
|
| 504 |
-
"pid": proc.pid,
|
| 505 |
-
"analysis": memory_info
|
| 506 |
-
})
|
| 507 |
-
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
| 508 |
-
continue
|
| 509 |
-
|
| 510 |
-
return analysis
|
| 511 |
-
|
| 512 |
-
except Exception as e:
|
| 513 |
-
return {"error": str(e)}
|
| 514 |
|
| 515 |
-
def
|
| 516 |
-
"""ت
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
"status": "requires_admin_privileges",
|
| 520 |
-
"suggested_tools": ["Cheat Engine", "x64dbg", "Process Hacker"]
|
| 521 |
-
}
|
| 522 |
-
|
| 523 |
-
async def analyze_network_traffic(self, game_name: str) -> Dict:
|
| 524 |
-
"""تحليل حركة مرور الشبكة"""
|
| 525 |
-
try:
|
| 526 |
-
# استخدام أدوات تحليل الشبكة
|
| 527 |
-
analysis = {
|
| 528 |
-
"connections": [],
|
| 529 |
-
"packet_analysis": {},
|
| 530 |
-
"servers_detected": []
|
| 531 |
-
}
|
| 532 |
-
|
| 533 |
-
for proc in psutil.process_iter():
|
| 534 |
-
try:
|
| 535 |
-
if game_name.lower() in proc.name().lower():
|
| 536 |
-
connections = proc.connections()
|
| 537 |
-
for conn in connections:
|
| 538 |
-
if conn.status == 'ESTABLISHED':
|
| 539 |
-
analysis["connections"].append({
|
| 540 |
-
"local_address": f"{conn.laddr.ip}:{conn.laddr.port}",
|
| 541 |
-
"remote_address": f"{conn.raddr.ip}:{conn.raddr.port}" if conn.raddr else "N/A",
|
| 542 |
-
"status": conn.status
|
| 543 |
-
})
|
| 544 |
-
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
| 545 |
-
continue
|
| 546 |
-
|
| 547 |
-
return analysis
|
| 548 |
-
|
| 549 |
-
except Exception as e:
|
| 550 |
-
return {"error": str(e)}
|
| 551 |
-
|
| 552 |
-
def analyze_bot_requirements(self, description: str) -> Dict:
|
| 553 |
-
"""تحليل متطلبات البوت"""
|
| 554 |
-
analysis_prompt = f"""
|
| 555 |
-
قم بتحليل متطلبات البوت من الوصف التالي:
|
| 556 |
-
{description}
|
| 557 |
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
|
|
|
|
|
|
|
|
|
| 564 |
|
| 565 |
-
|
| 566 |
-
return {
|
| 567 |
-
"analysis": requirements,
|
| 568 |
-
"bot_type": self.extract_bot_type(description),
|
| 569 |
-
"features": self.extract_requested_features(description)
|
| 570 |
-
}
|
| 571 |
|
| 572 |
-
def
|
| 573 |
-
"""
|
| 574 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
|
| 576 |
-
if any(word in
|
| 577 |
return "farming"
|
| 578 |
-
elif any(word in
|
| 579 |
return "combat"
|
| 580 |
-
elif any(word in
|
| 581 |
-
return "trading"
|
| 582 |
-
elif any(word in description_lower for word in ['تعدين', 'mining', 'mine']):
|
| 583 |
return "mining"
|
|
|
|
|
|
|
| 584 |
else:
|
| 585 |
return "general"
|
| 586 |
|
| 587 |
-
def
|
| 588 |
-
"""استخراج
|
| 589 |
features = []
|
| 590 |
-
|
| 591 |
|
| 592 |
-
|
| 593 |
-
'تلقائي': '
|
| 594 |
-
'ذكي': '
|
| 595 |
-
'سريع': '
|
| 596 |
-
'آمن': '
|
| 597 |
-
'مخفي': '
|
| 598 |
-
'متقدم': '
|
| 599 |
}
|
| 600 |
|
| 601 |
-
for arabic, english in
|
| 602 |
-
if arabic in
|
| 603 |
features.append(english)
|
| 604 |
|
| 605 |
return features
|
| 606 |
|
| 607 |
-
def
|
| 608 |
-
"""ت
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
قم بإنشاء كود بوت متقدم للعبة {game_name} مع المتطلبات التالية:
|
| 612 |
-
{requirements}
|
| 613 |
-
|
| 614 |
-
المتطلبات:
|
| 615 |
-
- كود Python متقدم
|
| 616 |
-
- استخدام مكتبات مثل pyautogui, cv2, pynput
|
| 617 |
-
- تضمين التعليقات التوضيحية
|
| 618 |
-
- معالجة الأخطاء
|
| 619 |
-
- إمكانية التخصيص
|
| 620 |
-
"""
|
| 621 |
-
|
| 622 |
-
bot_code = self.generate_ai_response(code_prompt)
|
| 623 |
-
|
| 624 |
-
return {
|
| 625 |
-
"language": "python",
|
| 626 |
-
"code": bot_code,
|
| 627 |
-
"requirements": self.extract_code_requirements(bot_code),
|
| 628 |
-
"installation_commands": self.generate_installation_commands(bot_code)
|
| 629 |
-
}
|
| 630 |
-
|
| 631 |
-
except Exception as e:
|
| 632 |
-
return {"error": str(e)}
|
| 633 |
-
|
| 634 |
-
def extract_code_requirements(self, code: str) -> List[str]:
|
| 635 |
-
"""استخراج متطلبات الكود"""
|
| 636 |
-
requirements = []
|
| 637 |
-
|
| 638 |
-
if 'pyautogui' in code:
|
| 639 |
-
requirements.append('pyautogui')
|
| 640 |
-
if 'cv2' in code or 'opencv' in code:
|
| 641 |
-
requirements.append('opencv-python')
|
| 642 |
-
if 'pynput' in code:
|
| 643 |
-
requirements.append('pynput')
|
| 644 |
-
if 'psutil' in code:
|
| 645 |
-
requirements.append('psutil')
|
| 646 |
-
|
| 647 |
-
return list(set(requirements))
|
| 648 |
-
|
| 649 |
-
def generate_installation_commands(self, code: str) -> List[str]:
|
| 650 |
-
"""توليد أوامر التثبيت"""
|
| 651 |
-
requirements = self.extract_code_requirements(code)
|
| 652 |
-
commands = []
|
| 653 |
-
|
| 654 |
-
for req in requirements:
|
| 655 |
-
commands.append(f"pip install {req}")
|
| 656 |
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
def compile_bot(self, bot_code: Dict, game_name: str) -> Dict:
|
| 660 |
-
"""تجميع البوت"""
|
| 661 |
-
try:
|
| 662 |
-
# حفظ الكود في ملف
|
| 663 |
-
timestamp = int(time.time())
|
| 664 |
-
filename = f"bot_{game_name}_{timestamp}.py"
|
| 665 |
-
|
| 666 |
-
with open(filename, 'w', encoding='utf-8') as f:
|
| 667 |
-
f.write(bot_code["code"])
|
| 668 |
-
|
| 669 |
-
return {
|
| 670 |
-
"filename": filename,
|
| 671 |
-
"full_path": os.path.abspath(filename),
|
| 672 |
-
"size": os.path.getsize(filename),
|
| 673 |
-
"status": "compiled"
|
| 674 |
-
}
|
| 675 |
-
|
| 676 |
-
except Exception as e:
|
| 677 |
-
return {"error": str(e)}
|
| 678 |
-
|
| 679 |
-
async def test_bot(self, bot_file: Dict, game_name: str) -> Dict:
|
| 680 |
-
"""اختبار البوت"""
|
| 681 |
-
try:
|
| 682 |
-
test_results = {
|
| 683 |
-
"syntax_check": "passed",
|
| 684 |
-
"dependencies_check": "passed",
|
| 685 |
-
"performance_test": "not_run",
|
| 686 |
-
"security_scan": "basic"
|
| 687 |
-
}
|
| 688 |
-
|
| 689 |
-
# فحص بناء الجملة
|
| 690 |
-
try:
|
| 691 |
-
with open(bot_file["filename"], 'r') as f:
|
| 692 |
-
compile(f.read(), bot_file["filename"], 'exec')
|
| 693 |
-
except SyntaxError as e:
|
| 694 |
-
test_results["syntax_check"] = f"failed: {str(e)}"
|
| 695 |
-
|
| 696 |
-
return test_results
|
| 697 |
-
|
| 698 |
-
except Exception as e:
|
| 699 |
-
return {"error": str(e)}
|
| 700 |
-
|
| 701 |
-
def extract_software_requirements(self, description: str) -> List[str]:
|
| 702 |
-
"""استخراج متطلبات البرامج"""
|
| 703 |
-
software_keywords = {
|
| 704 |
-
'cheat engine': 'cheat-engine',
|
| 705 |
'wireshark': 'wireshark',
|
| 706 |
-
'process hacker': '
|
| 707 |
-
'python': 'python',
|
| 708 |
-
'visual studio': 'visualstudio',
|
| 709 |
-
'dnspy': 'dnspy',
|
| 710 |
'x64dbg': 'x64dbg',
|
| 711 |
'ollydbg': 'ollydbg',
|
| 712 |
-
'ida': 'ida
|
| 713 |
-
'ghidra': 'ghidra'
|
|
|
|
| 714 |
}
|
| 715 |
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
for keyword, package in software_keywords.items():
|
| 720 |
-
if keyword in description_lower:
|
| 721 |
-
found_software.append(package)
|
| 722 |
-
|
| 723 |
-
return found_software
|
| 724 |
-
|
| 725 |
-
async def install_software(self, software_name: str) -> Dict:
|
| 726 |
-
"""تثبيت برنامج"""
|
| 727 |
-
try:
|
| 728 |
-
# استخدام Chocolatey أو winget للتثبيت
|
| 729 |
-
install_commands = {
|
| 730 |
-
'cheat-engine': 'choco install cheat-engine -y',
|
| 731 |
-
'wireshark': 'choco install wireshark -y',
|
| 732 |
-
'processhacker': 'choco install processhacker -y',
|
| 733 |
-
'python': 'choco install python -y',
|
| 734 |
-
'visualstudio': 'choco install visualstudio2019community -y',
|
| 735 |
-
'dnspy': 'choco install dnspy -y',
|
| 736 |
-
'x64dbg': 'choco install x64dbg -y',
|
| 737 |
-
'ollydbg': 'choco install ollydbg -y',
|
| 738 |
-
'ida-free': 'choco install ida-free -y',
|
| 739 |
-
'ghidra': 'choco install ghidra -y'
|
| 740 |
-
}
|
| 741 |
-
|
| 742 |
-
if software_name in install_commands:
|
| 743 |
-
command = install_commands[software_name]
|
| 744 |
-
result = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=300)
|
| 745 |
-
|
| 746 |
-
return {
|
| 747 |
-
"command": command,
|
| 748 |
-
"return_code": result.returncode,
|
| 749 |
-
"output": result.stdout,
|
| 750 |
-
"error": result.stderr
|
| 751 |
-
}
|
| 752 |
-
else:
|
| 753 |
-
return {"error": f"لا يوجد أمر تثبيت معروف للبرنامج: {software_name}"}
|
| 754 |
-
|
| 755 |
-
except Exception as e:
|
| 756 |
-
return {"error": str(e)}
|
| 757 |
-
|
| 758 |
-
async def perform_hacking_analysis(self, task: WindowsTask, results: Dict):
|
| 759 |
-
"""تنفيذ تحليل الاختراق"""
|
| 760 |
-
try:
|
| 761 |
-
game_name = task.game_name or self.extract_game_name(task.task_description)
|
| 762 |
-
|
| 763 |
-
results["steps"].append("بدء تحليل الاختراق...")
|
| 764 |
-
|
| 765 |
-
# 1. تحليل الثغرات
|
| 766 |
-
vulnerability_scan = await self.scan_vulnerabilities(game_name)
|
| 767 |
-
results["results"]["vulnerabilities"] = vulnerability_scan
|
| 768 |
-
|
| 769 |
-
# 2. اختبار الاختراق
|
| 770 |
-
penetration_test = await self.perform_penetration_test(game_name)
|
| 771 |
-
results["results"]["penetration_test"] = penetration_test
|
| 772 |
-
|
| 773 |
-
# 3. بناء أدوات الاستغلال
|
| 774 |
-
exploit_tools = self.build_exploit_tools(game_name, vulnerability_scan)
|
| 775 |
-
results["results"]["exploit_tools"] = exploit_tools
|
| 776 |
-
|
| 777 |
-
results["steps"].append("اكتمل تحليل الاختراق")
|
| 778 |
-
|
| 779 |
-
except Exception as e:
|
| 780 |
-
results["errors"].append(f"خطأ في تحليل الاختراق: {str(e)}")
|
| 781 |
-
logger.error(f"فشل تحليل الاختراق: {e}")
|
| 782 |
-
|
| 783 |
-
async def create_automation_script(self, task: WindowsTask, results: Dict):
|
| 784 |
-
"""إنشاء سكريبت أتمتة"""
|
| 785 |
-
try:
|
| 786 |
-
results["steps"].append("بدء إنشاء سكريبت الأتمتة...")
|
| 787 |
-
|
| 788 |
-
# تحليل المهمة وإنشاء السكريبت
|
| 789 |
-
script_code = self.generate_automation_script(task.task_description)
|
| 790 |
-
results["results"]["script_code"] = script_code
|
| 791 |
-
|
| 792 |
-
# حفظ وتنفيذ السكريبت
|
| 793 |
-
script_file = self.save_automation_script(script_code)
|
| 794 |
-
results["results"]["script_file"] = script_file
|
| 795 |
-
|
| 796 |
-
results["steps"].append("اكتمل إنشاء سكريبت الأتمتة")
|
| 797 |
-
|
| 798 |
-
except Exception as e:
|
| 799 |
-
results["errors"].append(f"خطأ في إنشاء سكريبت الأتمتة: {str(e)}")
|
| 800 |
-
logger.error(f"فشل إنشاء سكريبت الأتمتة: {e}")
|
| 801 |
-
|
| 802 |
-
def generate_automation_script(self, task_description: str) -> Dict:
|
| 803 |
-
"""توليد سكريبت الأتمتة"""
|
| 804 |
-
prompt = f"""
|
| 805 |
-
قم بإنشاء سكريبت Python لأتمتة المهمة التالية:
|
| 806 |
-
{task_description}
|
| 807 |
-
|
| 808 |
-
المتطلبات:
|
| 809 |
-
- استخدام مكتبات Windows مثل pyautogui, psutil, win32api
|
| 810 |
-
- معالجة الأخطاء
|
| 811 |
-
- سجلات التنفيذ
|
| 812 |
-
- إمكانية التخصيص
|
| 813 |
-
"""
|
| 814 |
-
|
| 815 |
-
script_code = self.generate_ai_response(prompt)
|
| 816 |
|
| 817 |
-
return
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 821 |
}
|
|
|
|
| 822 |
|
| 823 |
-
def
|
| 824 |
-
"""ح
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
f.write(script_data["code"])
|
| 831 |
-
|
| 832 |
-
return {
|
| 833 |
-
"filename": filename,
|
| 834 |
-
"full_path": os.path.abspath(filename),
|
| 835 |
-
"status": "saved"
|
| 836 |
-
}
|
| 837 |
-
except Exception as e:
|
| 838 |
-
return {"error": str(e)}
|
| 839 |
-
|
| 840 |
-
def stop_all_bots(self):
|
| 841 |
-
"""إيقاف جميع البوتات النشطة"""
|
| 842 |
-
try:
|
| 843 |
-
for thread_name, thread in self.bot_threads.items():
|
| 844 |
-
if thread.is_alive():
|
| 845 |
-
thread.stop()
|
| 846 |
-
logger.info(f"تم إيقاف البوت: {thread_name}")
|
| 847 |
-
|
| 848 |
-
self.bot_threads = {}
|
| 849 |
-
except Exception as e:
|
| 850 |
-
logger.error(f"خطأ في إيقاف البوتات: {e}")
|
| 851 |
-
|
| 852 |
-
def get_system_info(self) -> Dict:
|
| 853 |
-
"""الحصول على معلومات النظام"""
|
| 854 |
-
try:
|
| 855 |
-
return {
|
| 856 |
-
"os": f"Windows {sys.getwindowsversion().major}",
|
| 857 |
-
"architecture": platform.architecture()[0],
|
| 858 |
-
"processor": platform.processor(),
|
| 859 |
-
"memory": f"{psutil.virtual_memory().total / 1024 / 1024 / 1024:.2f} GB",
|
| 860 |
-
"python_version": platform.python_version(),
|
| 861 |
-
"running_processes": len(psutil.pids()),
|
| 862 |
-
"active_bots": len(self.bot_threads)
|
| 863 |
-
}
|
| 864 |
-
except Exception as e:
|
| 865 |
-
return {"error": str(e)}
|
| 866 |
-
|
| 867 |
-
# فئة مراقب النظام
|
| 868 |
-
class SystemMonitor(threading.Thread):
|
| 869 |
-
def __init__(self):
|
| 870 |
-
super().__init__()
|
| 871 |
-
self.daemon = True
|
| 872 |
-
self.running = True
|
| 873 |
-
self.metrics = {
|
| 874 |
-
"cpu_usage": [],
|
| 875 |
-
"memory_usage": [],
|
| 876 |
-
"active_processes": [],
|
| 877 |
-
"network_activity": []
|
| 878 |
-
}
|
| 879 |
-
|
| 880 |
-
def run(self):
|
| 881 |
-
while self.running:
|
| 882 |
-
try:
|
| 883 |
-
# جمع مقاييس النظام
|
| 884 |
-
self.metrics["cpu_usage"].append(psutil.cpu_percent(interval=1))
|
| 885 |
-
self.metrics["memory_usage"].append(psutil.virtual_memory().percent)
|
| 886 |
-
self.metrics["active_processes"].append(len(psutil.pids()))
|
| 887 |
-
|
| 888 |
-
# الحفاظ على تاريخ محدود
|
| 889 |
-
for key in self.metrics:
|
| 890 |
-
if len(self.metrics[key]) > 60: # آخر 60 قراءة
|
| 891 |
-
self.metrics[key] = self.metrics[key][-60:]
|
| 892 |
-
|
| 893 |
-
time.sleep(5)
|
| 894 |
-
except Exception as e:
|
| 895 |
-
logger.error(f"خطأ في مراقب النظام: {e}")
|
| 896 |
-
time.sleep(10)
|
| 897 |
-
|
| 898 |
-
def stop(self):
|
| 899 |
-
self.running = False
|
| 900 |
|
| 901 |
# تهيئة النظام
|
| 902 |
-
|
| 903 |
|
| 904 |
# نقاط النهاية
|
| 905 |
@app.get("/", response_class=HTMLResponse)
|
|
@@ -908,157 +395,176 @@ async def read_root():
|
|
| 908 |
with open("static/index.html", "r", encoding="utf-8") as f:
|
| 909 |
return HTMLResponse(content=f.read())
|
| 910 |
|
| 911 |
-
@app.post("/api/
|
| 912 |
-
async def
|
| 913 |
-
"""ت
|
| 914 |
-
try:
|
| 915 |
-
results = await windows_ai.execute_windows_task(task)
|
| 916 |
-
return {"success": True, "data": results}
|
| 917 |
-
except Exception as e:
|
| 918 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 919 |
-
|
| 920 |
-
@app.post("/api/analyze-game")
|
| 921 |
-
async def analyze_game(request: GameAnalysisRequest):
|
| 922 |
-
"""تحليل لعبة محددة"""
|
| 923 |
try:
|
| 924 |
-
|
| 925 |
-
task_description=f"تحليل لعبة {request.game_name} بنوع {request.analysis_type}",
|
| 926 |
-
task_type="analysis",
|
| 927 |
-
game_name=request.game_name
|
| 928 |
-
)
|
| 929 |
|
| 930 |
-
|
| 931 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 932 |
except Exception as e:
|
| 933 |
raise HTTPException(status_code=500, detail=str(e))
|
| 934 |
|
| 935 |
-
@app.post("/api/
|
| 936 |
-
async def
|
| 937 |
-
"""
|
| 938 |
try:
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
game_name=request.game_name
|
| 943 |
-
)
|
| 944 |
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
async def run_system_command(command: SystemCommand):
|
| 952 |
-
"""تنفيذ أمر نظام"""
|
| 953 |
-
try:
|
| 954 |
-
if command.run_as_admin:
|
| 955 |
-
# تنفيذ كمسؤول (يتطلب UAC)
|
| 956 |
-
full_command = f"runas /user:Administrator {' '.join([command.command] + command.args)}"
|
| 957 |
-
else:
|
| 958 |
-
full_command = f"{command.command} {' '.join(command.args)}"
|
| 959 |
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
text=True,
|
| 965 |
-
timeout=command.timeout
|
| 966 |
-
)
|
| 967 |
|
| 968 |
return {
|
| 969 |
"success": True,
|
| 970 |
"data": {
|
| 971 |
-
"
|
| 972 |
-
"
|
| 973 |
-
"
|
| 974 |
-
"
|
| 975 |
}
|
| 976 |
}
|
| 977 |
except Exception as e:
|
| 978 |
raise HTTPException(status_code=500, detail=str(e))
|
| 979 |
|
| 980 |
-
@app.
|
| 981 |
-
async def
|
| 982 |
-
"""
|
| 983 |
-
try:
|
| 984 |
-
info = windows_ai.get_system_info()
|
| 985 |
-
return {"success": True, "data": info}
|
| 986 |
-
except Exception as e:
|
| 987 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 988 |
-
|
| 989 |
-
@app.get("/api/active-processes")
|
| 990 |
-
async def get_active_processes():
|
| 991 |
-
"""الحصول على العمليات النشطة"""
|
| 992 |
try:
|
| 993 |
-
|
| 994 |
-
|
| 995 |
-
|
| 996 |
-
processes.append(proc.info)
|
| 997 |
-
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
| 998 |
-
continue
|
| 999 |
|
| 1000 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1001 |
except Exception as e:
|
| 1002 |
raise HTTPException(status_code=500, detail=str(e))
|
| 1003 |
|
| 1004 |
-
@app.
|
| 1005 |
-
async def
|
| 1006 |
-
"""
|
| 1007 |
-
await websocket.accept()
|
| 1008 |
try:
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
"
|
|
|
|
|
|
|
| 1016 |
}
|
| 1017 |
-
|
| 1018 |
-
await websocket.send_json(system_data)
|
| 1019 |
-
await asyncio.sleep(2) # تحديث كل ثانيتين
|
| 1020 |
-
|
| 1021 |
-
except WebSocketDisconnect:
|
| 1022 |
-
logger.info("تم فصل اتصال WebSocket")
|
| 1023 |
-
except Exception as e:
|
| 1024 |
-
logger.error(f"خطأ في WebSocket: {e}")
|
| 1025 |
-
|
| 1026 |
-
@app.post("/api/stop-all-bots")
|
| 1027 |
-
async def stop_all_bots():
|
| 1028 |
-
"""إيقاف جميع البوتات النشطة"""
|
| 1029 |
-
try:
|
| 1030 |
-
windows_ai.stop_all_bots()
|
| 1031 |
-
return {"success": True, "message": "تم إيقاف جميع البوتات"}
|
| 1032 |
except Exception as e:
|
| 1033 |
raise HTTPException(status_code=500, detail=str(e))
|
| 1034 |
|
| 1035 |
-
@app.
|
| 1036 |
-
async def
|
| 1037 |
-
"""ال
|
| 1038 |
try:
|
| 1039 |
-
# ا
|
| 1040 |
-
|
| 1041 |
-
'wmic product get name,version',
|
| 1042 |
-
shell=True,
|
| 1043 |
-
capture_output=True,
|
| 1044 |
-
text=True
|
| 1045 |
-
)
|
| 1046 |
-
|
| 1047 |
-
software_list = []
|
| 1048 |
-
lines = result.stdout.split('\n')[1:] # تخطي العنوان
|
| 1049 |
-
for line in lines:
|
| 1050 |
-
if line.strip():
|
| 1051 |
-
parts = line.split(' ')
|
| 1052 |
-
if len(parts) >= 2:
|
| 1053 |
-
software_list.append({
|
| 1054 |
-
"name": parts[0].strip(),
|
| 1055 |
-
"version": parts[1].strip() if len(parts) > 1 else "Unknown"
|
| 1056 |
-
})
|
| 1057 |
|
| 1058 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1059 |
except Exception as e:
|
| 1060 |
raise HTTPException(status_code=500, detail=str(e))
|
| 1061 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1062 |
if __name__ == "__main__":
|
| 1063 |
import uvicorn
|
| 1064 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
import logging
|
|
|
|
| 4 |
import asyncio
|
| 5 |
import aiohttp
|
| 6 |
+
from fastapi import FastAPI, HTTPException, BackgroundTasks
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from fastapi.responses import HTMLResponse
|
| 8 |
from fastapi.staticfiles import StaticFiles
|
| 9 |
from pydantic import BaseModel, Field
|
|
|
|
| 16 |
StoppingCriteria,
|
| 17 |
StoppingCriteriaList,
|
| 18 |
)
|
| 19 |
+
import requests
|
| 20 |
+
import re
|
| 21 |
+
import time
|
| 22 |
+
from datetime import datetime
|
| 23 |
+
import hashlib
|
| 24 |
+
import nest_asyncio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
import warnings
|
| 26 |
warnings.filterwarnings("ignore")
|
| 27 |
|
| 28 |
+
# تطبيق nest-asyncio للتعامل مع الأحداث غير المتزامنة
|
| 29 |
+
nest_asyncio.apply()
|
| 30 |
+
|
| 31 |
# التهيئة الأساسية
|
| 32 |
os.environ["HF_HOME"] = "/tmp/hf_cache"
|
| 33 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/hf_cache/transformers"
|
|
|
|
| 48 |
# نماذج البيانات
|
| 49 |
class WindowsTask(BaseModel):
|
| 50 |
task_description: str = Field(..., min_length=5, max_length=2000)
|
| 51 |
+
task_type: str = "analysis"
|
| 52 |
game_name: Optional[str] = None
|
| 53 |
+
priority: str = "normal"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
class ClientCommand(BaseModel):
|
| 56 |
+
command_type: str # execute, analyze, create_bot, install, monitor
|
| 57 |
+
parameters: Dict[str, Any]
|
| 58 |
+
client_id: Optional[str] = None
|
| 59 |
|
| 60 |
+
class ClientResponse(BaseModel):
|
| 61 |
+
client_id: str
|
| 62 |
+
command_id: str
|
| 63 |
+
status: str
|
| 64 |
+
results: Dict[str, Any]
|
| 65 |
+
error: Optional[str] = None
|
| 66 |
|
| 67 |
# نموذج التوقف المخصص
|
| 68 |
class StopOnTokens(StoppingCriteria):
|
|
|
|
| 73 |
return True
|
| 74 |
return False
|
| 75 |
|
| 76 |
+
# النظام الأساسي المتقدم للذكاء الاصطناعي
|
| 77 |
+
class WindowsAIAdvisor:
|
| 78 |
def __init__(self):
|
| 79 |
self.tokenizer = None
|
| 80 |
self.model = None
|
| 81 |
self.pipeline = None
|
| 82 |
self.is_loaded = False
|
| 83 |
+
self.connected_clients = {}
|
|
|
|
|
|
|
| 84 |
self.load_models()
|
|
|
|
| 85 |
|
| 86 |
def load_models(self):
|
| 87 |
"""تحميل النماذج المتخصصة"""
|
| 88 |
try:
|
| 89 |
+
logger.info("جارٍ تحميل النماذج المتخصصة...")
|
| 90 |
|
| 91 |
model_name = "microsoft/DialoGPT-medium"
|
| 92 |
self.tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
| 123 |
logger.error(f"فشل تحميل النماذج: {e}")
|
| 124 |
raise e
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
def generate_ai_response(self, prompt: str, context: List[Dict] = None) -> str:
|
| 127 |
"""توليد رد الذكاء الاصطناعي"""
|
| 128 |
try:
|
|
|
|
| 158 |
logger.error(f"فشل توليد الرد: {e}")
|
| 159 |
return f"عذراً، حدث خطأ في معالجة طلبك: {str(e)}"
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
def analyze_task(self, task_description: str) -> Dict:
|
| 162 |
+
"""تحليل المهمة وإنشاء خطة تنفيذ"""
|
| 163 |
analysis_prompt = f"""
|
| 164 |
+
قم بتحليل المهمة التالية وإنشاء خطة تنفيذ مفصلة للعميل على Windows:
|
| 165 |
{task_description}
|
| 166 |
|
| 167 |
+
قدم خطة تنفيذ تشمل:
|
| 168 |
1. الأدوات المطلوبة
|
| 169 |
2. الخطوات التقنية
|
| 170 |
+
3. الأوامر المطلوبة
|
| 171 |
+
4. المخاطر المحتملة
|
| 172 |
+
5. البدائل
|
| 173 |
+
|
| 174 |
+
ركز على الجانب العملي والتنفيذي.
|
| 175 |
"""
|
| 176 |
|
| 177 |
plan = self.generate_ai_response(analysis_prompt)
|
| 178 |
+
|
| 179 |
+
return {
|
| 180 |
+
"plan": plan,
|
| 181 |
+
"steps": self.extract_execution_steps(plan),
|
| 182 |
+
"tools": self.extract_required_tools(plan),
|
| 183 |
+
"commands": self.generate_client_commands(plan, task_description)
|
| 184 |
+
}
|
| 185 |
|
| 186 |
+
def extract_execution_steps(self, plan: str) -> List[str]:
|
| 187 |
"""استخراج خطوات التنفيذ من الخطة"""
|
| 188 |
steps = []
|
| 189 |
lines = plan.split('\n')
|
| 190 |
|
| 191 |
for line in lines:
|
| 192 |
line = line.strip()
|
| 193 |
+
if any(marker in line for marker in ['1.', '2.', '3.', '4.', '5.', '- ', '• ', 'خطوة']):
|
| 194 |
if len(line) > 10:
|
| 195 |
+
# تنظيف الخطوة
|
| 196 |
+
clean_step = re.sub(r'^[0-9•\-\.,]+\s*', '', line)
|
| 197 |
+
steps.append(clean_step)
|
| 198 |
|
| 199 |
+
return steps[:15] # إرجاع أول 15 خطوة فقط
|
| 200 |
+
|
| 201 |
+
def extract_required_tools(self, plan: str) -> List[str]:
|
| 202 |
+
"""استخراج الأدوات المطلوبة"""
|
| 203 |
+
tools = []
|
| 204 |
+
common_tools = [
|
| 205 |
+
'cheat engine', 'wireshark', 'process hacker', 'process explorer',
|
| 206 |
+
'x64dbg', 'ollydbg', 'ida', 'ghidra', 'dnspy', 'reflector',
|
| 207 |
+
'python', 'visual studio', 'net reflector', 'api monitor'
|
| 208 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
+
plan_lower = plan.lower()
|
| 211 |
+
for tool in common_tools:
|
| 212 |
+
if tool in plan_lower:
|
| 213 |
+
tools.append(tool)
|
| 214 |
|
| 215 |
+
return tools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
+
def generate_client_commands(self, plan: str, task_description: str) -> List[Dict]:
|
| 218 |
+
"""توليد أوامر للعميل"""
|
| 219 |
+
commands = []
|
| 220 |
+
|
| 221 |
+
# تحليل نوع المهمة
|
| 222 |
+
task_lower = task_description.lower()
|
| 223 |
+
|
| 224 |
+
if any(word in task_lower for word in ['تحليل', 'analyze', 'فحص']):
|
| 225 |
+
commands.extend(self.generate_analysis_commands(task_description))
|
| 226 |
+
|
| 227 |
+
if any(word in task_lower for word in ['بوت', 'bot', 'أتمتة', 'automation']):
|
| 228 |
+
commands.extend(self.generate_bot_commands(task_description))
|
| 229 |
+
|
| 230 |
+
if any(word in task_lower for word in ['تثبيت', 'install', 'برنامج']):
|
| 231 |
+
commands.extend(self.generate_installation_commands(task_description))
|
| 232 |
+
|
| 233 |
+
if any(word in task_lower for word in ['اختراق', 'hack', 'exploit']):
|
| 234 |
+
commands.extend(self.generate_hacking_commands(task_description))
|
| 235 |
+
|
| 236 |
+
return commands
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
+
def generate_analysis_commands(self, task: str) -> List[Dict]:
|
| 239 |
+
"""توليد أوامر التحليل"""
|
| 240 |
+
return [
|
| 241 |
+
{
|
| 242 |
+
"command_type": "analyze",
|
| 243 |
+
"parameters": {
|
| 244 |
+
"task": task,
|
| 245 |
+
"analysis_type": "process_memory",
|
| 246 |
+
"depth": "deep"
|
| 247 |
+
},
|
| 248 |
+
"description": "تحليل عمليات وذاكرة النظام"
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"command_type": "analyze",
|
| 252 |
+
"parameters": {
|
| 253 |
+
"task": task,
|
| 254 |
+
"analysis_type": "game_files",
|
| 255 |
+
"depth": "standard"
|
| 256 |
+
},
|
| 257 |
+
"description": "فحص ملفات اللعبة"
|
| 258 |
}
|
| 259 |
+
]
|
| 260 |
+
|
| 261 |
+
def generate_bot_commands(self, task: str) -> List[Dict]:
|
| 262 |
+
"""توليد أوامر بناء البوتات"""
|
| 263 |
+
return [
|
| 264 |
+
{
|
| 265 |
+
"command_type": "create_bot",
|
| 266 |
+
"parameters": {
|
| 267 |
+
"task": task,
|
| 268 |
+
"bot_type": self.detect_bot_type(task),
|
| 269 |
+
"features": self.extract_bot_features(task)
|
| 270 |
+
},
|
| 271 |
+
"description": "بناء بوت متخصص"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
}
|
| 273 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
|
| 275 |
+
def generate_installation_commands(self, task: str) -> List[Dict]:
|
| 276 |
+
"""توليد أوامر التثبيت"""
|
| 277 |
+
tools = self.extract_tools_from_task(task)
|
| 278 |
+
commands = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
|
| 280 |
+
for tool in tools:
|
| 281 |
+
commands.append({
|
| 282 |
+
"command_type": "install",
|
| 283 |
+
"parameters": {
|
| 284 |
+
"tool_name": tool,
|
| 285 |
+
"silent_mode": True
|
| 286 |
+
},
|
| 287 |
+
"description": f"تثبيت {tool}"
|
| 288 |
+
})
|
| 289 |
|
| 290 |
+
return commands
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
+
def generate_hacking_commands(self, task: str) -> List[Dict]:
|
| 293 |
+
"""توليد أوامر الاختراق"""
|
| 294 |
+
return [
|
| 295 |
+
{
|
| 296 |
+
"command_type": "analyze",
|
| 297 |
+
"parameters": {
|
| 298 |
+
"task": task,
|
| 299 |
+
"analysis_type": "vulnerability_scan",
|
| 300 |
+
"depth": "deep"
|
| 301 |
+
},
|
| 302 |
+
"description": "مسح الثغرات الأمنية"
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
"command_type": "execute",
|
| 306 |
+
"parameters": {
|
| 307 |
+
"script_type": "exploit",
|
| 308 |
+
"task": task
|
| 309 |
+
},
|
| 310 |
+
"description": "تنفيذ استغلال الثغرات"
|
| 311 |
+
}
|
| 312 |
+
]
|
| 313 |
+
|
| 314 |
+
def detect_bot_type(self, task: str) -> str:
|
| 315 |
+
"""الكشف عن نوع البوت المطلوب"""
|
| 316 |
+
task_lower = task.lower()
|
| 317 |
|
| 318 |
+
if any(word in task_lower for word in ['مزرعة', 'farming', 'farm']):
|
| 319 |
return "farming"
|
| 320 |
+
elif any(word in task_lower for word in ['قتال', 'combat', 'battle']):
|
| 321 |
return "combat"
|
| 322 |
+
elif any(word in task_lower for word in ['تعدين', 'mining', 'mine']):
|
|
|
|
|
|
|
| 323 |
return "mining"
|
| 324 |
+
elif any(word in task_lower for word in ['تداول', 'trading', 'trade']):
|
| 325 |
+
return "trading"
|
| 326 |
else:
|
| 327 |
return "general"
|
| 328 |
|
| 329 |
+
def extract_bot_features(self, task: str) -> List[str]:
|
| 330 |
+
"""استخراج ميزات البوت المطلوبة"""
|
| 331 |
features = []
|
| 332 |
+
task_lower = task.lower()
|
| 333 |
|
| 334 |
+
feature_mapping = {
|
| 335 |
+
'تلقائي': 'auto_detect',
|
| 336 |
+
'ذكي': 'smart_detection',
|
| 337 |
+
'سريع': 'fast_execution',
|
| 338 |
+
'آمن': 'safe_mode',
|
| 339 |
+
'مخفي': 'stealth_mode',
|
| 340 |
+
'متقدم': 'advanced_features'
|
| 341 |
}
|
| 342 |
|
| 343 |
+
for arabic, english in feature_mapping.items():
|
| 344 |
+
if arabic in task_lower or english in task_lower:
|
| 345 |
features.append(english)
|
| 346 |
|
| 347 |
return features
|
| 348 |
|
| 349 |
+
def extract_tools_from_task(self, task: str) -> List[str]:
|
| 350 |
+
"""استخراج الأدوات المطلوبة من المهمة"""
|
| 351 |
+
tools = []
|
| 352 |
+
task_lower = task.lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
|
| 354 |
+
tool_mapping = {
|
| 355 |
+
'cheat engine': 'cheat_engine',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
'wireshark': 'wireshark',
|
| 357 |
+
'process hacker': 'process_hacker',
|
|
|
|
|
|
|
|
|
|
| 358 |
'x64dbg': 'x64dbg',
|
| 359 |
'ollydbg': 'ollydbg',
|
| 360 |
+
'ida': 'ida',
|
| 361 |
+
'ghidra': 'ghidra',
|
| 362 |
+
'python': 'python'
|
| 363 |
}
|
| 364 |
|
| 365 |
+
for tool_name, tool_id in tool_mapping.items():
|
| 366 |
+
if tool_name in task_lower:
|
| 367 |
+
tools.append(tool_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
|
| 369 |
+
return tools
|
| 370 |
+
|
| 371 |
+
def register_client(self, client_id: str, client_info: Dict):
|
| 372 |
+
"""تسجيل عميل جديد"""
|
| 373 |
+
self.connected_clients[client_id] = {
|
| 374 |
+
**client_info,
|
| 375 |
+
"last_seen": datetime.now(),
|
| 376 |
+
"status": "connected"
|
| 377 |
}
|
| 378 |
+
logger.info(f"تم تسجيل العميل: {client_id}")
|
| 379 |
|
| 380 |
+
def update_client_status(self, client_id: str, status: str):
|
| 381 |
+
"""تحديث حالة العميل"""
|
| 382 |
+
if client_id in self.connected_clients:
|
| 383 |
+
self.connected_clients[client_id].update({
|
| 384 |
+
"last_seen": datetime.now(),
|
| 385 |
+
"status": status
|
| 386 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
|
| 388 |
# تهيئة النظام
|
| 389 |
+
ai_advisor = WindowsAIAdvisor()
|
| 390 |
|
| 391 |
# نقاط النهاية
|
| 392 |
@app.get("/", response_class=HTMLResponse)
|
|
|
|
| 395 |
with open("static/index.html", "r", encoding="utf-8") as f:
|
| 396 |
return HTMLResponse(content=f.read())
|
| 397 |
|
| 398 |
+
@app.post("/api/analyze-task")
|
| 399 |
+
async def analyze_windows_task(task: WindowsTask):
|
| 400 |
+
"""تحليل المهمة وإنشاء خطة تنفيذ"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
try:
|
| 402 |
+
analysis = ai_advisor.analyze_task(task.task_description)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
|
| 404 |
+
return {
|
| 405 |
+
"success": True,
|
| 406 |
+
"data": {
|
| 407 |
+
"task_id": f"task_{int(time.time())}",
|
| 408 |
+
"analysis": analysis,
|
| 409 |
+
"generated_commands": analysis["commands"],
|
| 410 |
+
"execution_plan": analysis["plan"]
|
| 411 |
+
}
|
| 412 |
+
}
|
| 413 |
except Exception as e:
|
| 414 |
raise HTTPException(status_code=500, detail=str(e))
|
| 415 |
|
| 416 |
+
@app.post("/api/generate-bot")
|
| 417 |
+
async def generate_bot_script(task: WindowsTask):
|
| 418 |
+
"""توليد سكريبت بوت متخصص"""
|
| 419 |
try:
|
| 420 |
+
bot_prompt = f"""
|
| 421 |
+
قم بإنشاء سكريبت بوت متقدم للعبة للغرض التالي:
|
| 422 |
+
{task.task_description}
|
|
|
|
|
|
|
| 423 |
|
| 424 |
+
المتطلبات:
|
| 425 |
+
- استخدام لغة C++ أو C# لتجنب الاكتشاف
|
| 426 |
+
- تقنيات التخفي والتشويش
|
| 427 |
+
- معالجة الأخطاء
|
| 428 |
+
- إمكانية التخصيص
|
| 429 |
+
- تجنب أنظمة الحماية
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
|
| 431 |
+
قدم الكود كاملاً مع الشرح.
|
| 432 |
+
"""
|
| 433 |
+
|
| 434 |
+
bot_code = ai_advisor.generate_ai_response(bot_prompt)
|
|
|
|
|
|
|
|
|
|
| 435 |
|
| 436 |
return {
|
| 437 |
"success": True,
|
| 438 |
"data": {
|
| 439 |
+
"bot_script": bot_code,
|
| 440 |
+
"language": "cpp",
|
| 441 |
+
"features": ai_advisor.extract_bot_features(task.task_description),
|
| 442 |
+
"compilation_instructions": self.generate_compilation_instructions(bot_code)
|
| 443 |
}
|
| 444 |
}
|
| 445 |
except Exception as e:
|
| 446 |
raise HTTPException(status_code=500, detail=str(e))
|
| 447 |
|
| 448 |
+
@app.post("/api/generate-exploit")
|
| 449 |
+
async def generate_exploit_code(task: WindowsTask):
|
| 450 |
+
"""توليد كود استغلال متخصص"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
try:
|
| 452 |
+
exploit_prompt = f"""
|
| 453 |
+
قم بإنشاء كود استغلال متقدم للغرض التالي:
|
| 454 |
+
{task.task_description}
|
|
|
|
|
|
|
|
|
|
| 455 |
|
| 456 |
+
المتطلبات:
|
| 457 |
+
- استخدام تقنيات متقدمة
|
| 458 |
+
- تجنب الاكتشاف
|
| 459 |
+
- معالجة الذاكرة
|
| 460 |
+
- استغلال الثغرات
|
| 461 |
+
- كود آمن وقابل للتنفيذ
|
| 462 |
+
"""
|
| 463 |
+
|
| 464 |
+
exploit_code = ai_advisor.generate_ai_response(exploit_prompt)
|
| 465 |
+
|
| 466 |
+
return {
|
| 467 |
+
"success": True,
|
| 468 |
+
"data": {
|
| 469 |
+
"exploit_code": exploit_code,
|
| 470 |
+
"techniques_used": self.extract_exploit_techniques(exploit_code),
|
| 471 |
+
"risk_level": "high",
|
| 472 |
+
"instructions": "يتطلب خبرة متقدمة في التنفيذ"
|
| 473 |
+
}
|
| 474 |
+
}
|
| 475 |
except Exception as e:
|
| 476 |
raise HTTPException(status_code=500, detail=str(e))
|
| 477 |
|
| 478 |
+
@app.post("/api/client/register")
|
| 479 |
+
async def register_client(client_info: Dict):
|
| 480 |
+
"""تسجيل عميل جديد"""
|
|
|
|
| 481 |
try:
|
| 482 |
+
client_id = client_info.get("client_id", f"client_{int(time.time())}")
|
| 483 |
+
ai_advisor.register_client(client_id, client_info)
|
| 484 |
+
|
| 485 |
+
return {
|
| 486 |
+
"success": True,
|
| 487 |
+
"data": {
|
| 488 |
+
"client_id": client_id,
|
| 489 |
+
"status": "registered",
|
| 490 |
+
"server_time": datetime.now().isoformat()
|
| 491 |
}
|
| 492 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
except Exception as e:
|
| 494 |
raise HTTPException(status_code=500, detail=str(e))
|
| 495 |
|
| 496 |
+
@app.post("/api/client/command")
|
| 497 |
+
async def send_client_command(command: ClientCommand):
|
| 498 |
+
"""إرسال أمر للعميل"""
|
| 499 |
try:
|
| 500 |
+
# هنا يمكن حفظ الأمر في قاعدة بيانات pending commands
|
| 501 |
+
command_id = f"cmd_{int(time.time())}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
|
| 503 |
+
return {
|
| 504 |
+
"success": True,
|
| 505 |
+
"data": {
|
| 506 |
+
"command_id": command_id,
|
| 507 |
+
"command": command,
|
| 508 |
+
"status": "sent_to_client",
|
| 509 |
+
"timestamp": datetime.now().isoformat()
|
| 510 |
+
}
|
| 511 |
+
}
|
| 512 |
except Exception as e:
|
| 513 |
raise HTTPException(status_code=500, detail=str(e))
|
| 514 |
|
| 515 |
+
@app.get("/api/system/status")
|
| 516 |
+
async def get_system_status():
|
| 517 |
+
"""الحصول على حالة النظام"""
|
| 518 |
+
return {
|
| 519 |
+
"success": True,
|
| 520 |
+
"data": {
|
| 521 |
+
"ai_model_loaded": ai_advisor.is_loaded,
|
| 522 |
+
"connected_clients": len(ai_advisor.connected_clients),
|
| 523 |
+
"server_uptime": "running",
|
| 524 |
+
"timestamp": datetime.now().isoformat()
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
def generate_compilation_instructions(self, code: str) -> str:
|
| 529 |
+
"""توليد تعليمات التجميع"""
|
| 530 |
+
if "cpp" in code.lower() or "c++" in code.lower():
|
| 531 |
+
return """
|
| 532 |
+
تعليمات التجميع لـ C++:
|
| 533 |
+
1. احفظ الكود بامتداد .cpp
|
| 534 |
+
2. استخدم Microsoft Visual Studio
|
| 535 |
+
3. عطل تحذيرات الأمان مؤقتاً
|
| 536 |
+
4. جمّع كـ Release x64
|
| 537 |
+
5. شغّل الملف الناتج كمسؤول
|
| 538 |
+
"""
|
| 539 |
+
elif "c#" in code.lower() or "csharp" in code.lower():
|
| 540 |
+
return """
|
| 541 |
+
تعليمات التجميع لـ C#:
|
| 542 |
+
1. احفظ الكود بامتداد .cs
|
| 543 |
+
2. استخدم Visual Studio أو .NET SDK
|
| 544 |
+
3. جمّع باستخدام: csc /out:bot.exe script.cs
|
| 545 |
+
4. شغّل الملف الناتج
|
| 546 |
+
"""
|
| 547 |
+
else:
|
| 548 |
+
return "تعليمات التجميع: استخدم المترجم المناسب للغة المستخدمة"
|
| 549 |
+
|
| 550 |
+
def extract_exploit_techniques(self, code: str) -> List[str]:
|
| 551 |
+
"""استخراج تقنيات الاستغلال المستخدمة"""
|
| 552 |
+
techniques = []
|
| 553 |
+
code_lower = code.lower()
|
| 554 |
+
|
| 555 |
+
if "buffer" in code_lower and "overflow" in code_lower:
|
| 556 |
+
techniques.append("Buffer Overflow")
|
| 557 |
+
if "injection" in code_lower:
|
| 558 |
+
techniques.append("Code Injection")
|
| 559 |
+
if "dll" in code_lower:
|
| 560 |
+
techniques.append("DLL Injection")
|
| 561 |
+
if "hook" in code_lower:
|
| 562 |
+
techniques.append("API Hooking")
|
| 563 |
+
if "memory" in code_lower and "write" in code_lower:
|
| 564 |
+
techniques.append("Memory Writing")
|
| 565 |
+
|
| 566 |
+
return techniques
|
| 567 |
+
|
| 568 |
if __name__ == "__main__":
|
| 569 |
import uvicorn
|
| 570 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|