Repository navigation
Expand file tree
/
Copy pathsynthetic_traffic.py
More file actions
56 lines (48 loc) · 1.43 KB
/
Copy pathsynthetic_traffic.py
File metadata and controls
56 lines (48 loc) · 1.43 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
import httpx
import random
import time
import asyncio
BASE_URL = "http://localhost"
NORMAL_ENDPOINTS = [
("GET", "/products"),
("GET", "/products/1"),
("POST", "/auth/login"),
]
ATTACK_ENDPOINTS = [
("GET", "/products?id=1' OR '1'='1"),
("GET", "/products/../../../etc/passwd"),
("GET", "/admin"),
("GET", "/products?id=1; DROP TABLE products--"),
]
ATTACK_HEADERS = [
{"User-Agent": "sqlmap/1.0"},
{"User-Agent": "nikto/2.1"},
{"User-Agent": "nmap scripting engine"},
]
async def send_normal(client):
method, path = random.choice(NORMAL_ENDPOINTS)
try:
await client.request(method, f"{BASE_URL}{path}", timeout=3)
except:
pass
async def send_attack(client):
method, path = random.choice(ATTACK_ENDPOINTS)
headers = random.choice(ATTACK_HEADERS) if random.random() > 0.5 else {}
try:
await client.request(method, f"{BASE_URL}{path}", headers=headers, timeout=3)
except:
pass
async def main():
async with httpx.AsyncClient(verify=False) as client:
print("Generando tráfico... Ctrl+C para parar")
i = 0
while True:
if random.random() > 0.3: # 70% normal, 30% ataque
await send_normal(client)
else:
await send_attack(client)
i += 1
if i % 50 == 0:
print(f"{i} requests enviados")
await asyncio.sleep(0.1)
asyncio.run(main())