VPC Flow Port Scanning
Description
Detects potential port scanning activity by alerting when a single source address communicates with 10 or more distinct destination ports on the same target within 60 minutes. Common ports (80, 443, 53, etc.) are excluded to reduce noise.
Query · python
from ipaddress import ip_address
COMMON_PORTS = {80, 123, 443, 445, 53, 853, 2049}
def rule(event):
if event.get("flowDirection") != "egress":
return False
src_addr = event.get("srcAddr", "")
if not src_addr or src_addr == "null":
return False
if event.get("dstPort") in COMMON_PORTS:
return False
return True
def title(event):
src = event.get("srcAddr", "Unknown")
dst = event.get("dstAddr", "Unknown")
return f"Port Scanning Detected from [{src}] to [{dst}]"
def dedup(event):
src = event.get("srcAddr", "")
dst = event.get("dstAddr", "")
vpc = event.get("vpcId", "")
region = event.get("region", "")
subnet = event.get("subNetId", "")
return f"{src}:{dst}:{vpc}:{region}:{subnet}"
def unique(event):
port = event.get("dstPort")
return str(port) if port is not None else None
def severity(event):
try:
src = ip_address(event.get("srcAddr", ""))
if src.is_private:
return "HIGH"
except ValueError:
pass
return "DEFAULT"
Analyst notes
- Query VPC Flow logs for all egress traffic from srcAddr in the 1 hour around this alert to identify the full sequence of dstPort values targeted on dstAddr within vpcId
- Check if srcAddr is associated with known vulnerability scanners, corporate IT tooling, or threat intelligence feeds
- Find other alerts involving srcAddr or vpcId in the past 7 days to determine if this is part of ongoing reconnaissance