-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattacker.py
More file actions
59 lines (46 loc) · 1.55 KB
/
Copy pathattacker.py
File metadata and controls
59 lines (46 loc) · 1.55 KB
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
import argparse
import threading
import time
import requests
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Simple HTTP traffic generator.")
parser.add_argument("target", help="Target URL (e.g. http://localhost:5000)")
parser.add_argument(
"--workers",
type=int,
default=50,
help="Number of concurrent attack threads to run (default: 50)",
)
parser.add_argument(
"--timeout",
type=float,
default=2.0,
help="Request timeout in seconds (default: 2.0)",
)
return parser.parse_args()
def attack(target: str, timeout: float, session: requests.Session) -> None:
while True:
try:
session.get(target, timeout=timeout)
except requests.RequestException:
# This script is intentionally fire-and-forget for load simulation.
continue
def main() -> None:
args = parse_args()
if args.workers < 1:
raise ValueError("--workers must be greater than 0")
print(f"Attack started against {args.target} with {args.workers} workers.")
session = requests.Session()
for worker_id in range(1, args.workers + 1):
thread = threading.Thread(
target=attack,
kwargs={"target": args.target, "timeout": args.timeout, "session": session},
daemon=True,
name=f"attacker-{worker_id}",
)
thread.start()
print(f"Worker {worker_id} online")
while True:
time.sleep(1)
if __name__ == "__main__":
main()