-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulate_scans.py
More file actions
73 lines (66 loc) · 2.47 KB
/
Copy pathsimulate_scans.py
File metadata and controls
73 lines (66 loc) · 2.47 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import asyncio
import httpx
import json
import random
API_URL = "http://127.0.0.1:8000/api/v1/scan_infrastructure"
# Mock Infrastructure representing a Graph of AWS and Azure resources
MOCK_INFRASTRUCTURE_SCANS = [
{
"infrastructure": [
{
"id": "vpc-0abc123",
"type": "aws_vpc",
"properties": {"is_default": False},
"attached_to": []
},
{
"id": "s3-customer-data-prod",
"type": "aws_s3_bucket",
"properties": {"public_read": True, "encryption": "none"},
"attached_to": ["role-data-admin"]
},
{
"id": "role-data-admin",
"type": "aws_iam_role",
"properties": {"admin_access": True},
"attached_to": ["vpc-0abc123"]
}
]
},
{
"infrastructure": [
{
"id": "vnet-azure-prod",
"type": "azure_virtual_network",
"properties": {"region": "eastus"},
"attached_to": []
},
{
"id": "vm-jumpbox-01",
"type": "azure_virtual_machine",
"properties": {"ssh_open_to_internet": True, "os": "ubuntu"},
"attached_to": ["vnet-azure-prod"]
}
]
}
]
async def simulate_infrastructure_scans():
print("Starting Zero-Trust Auto-Scanner Simulator...")
async with httpx.AsyncClient() as client:
while True:
# Pick a random infrastructure state
payload = random.choice(MOCK_INFRASTRUCTURE_SCANS)
cloud_type = "AWS" if "aws" in payload["infrastructure"][0]["type"] else "Azure"
print(f"\n[SCAN INITIATED] Scanning {cloud_type} Infrastructure Code...")
try:
response = await client.post(API_URL, json=payload, timeout=10.0)
if response.status_code == 200:
print(f"Scan Complete. Vulnerabilities Found: {response.json().get('vulnerabilities_found')}")
else:
print(f"Error: {response.status_code}")
except Exception as e:
print(f"Connection failed (is the backend running?): {e}")
# Wait 15 seconds before the next scan
await asyncio.sleep(15)
if __name__ == "__main__":
asyncio.run(simulate_infrastructure_scans())