You need to find every security group that allows 0.0.0.0/0 on any port other than 80 and 443. How do you write the check?
IntermediateScenarioAWS automation with boto3
Answer
Situation read → Port ranges and protocol -1 are the edge cases.
What I'd do →
- Paginate
describe_security_groups. - For each
IpPermissionsentry, checkIpRanges[].CidrIp == "0.0.0.0/0"andIpv6Ranges[].CidrIpv6 == "::/0". - Handle
IpProtocol == "-1"(all traffic, no port fields), and ranges (FromPorttoToPort) that include more than 80/443. - Check whether the SG is attached (
describe_network_interfaceswithgroup-idfilter) to prioritize.
allowed = {80, 443}
risky = proto == "-1" or not (lo == hi and lo in allowed)
Why → Rules like 0-65535 or protocol -1 are the most dangerous and the most commonly missed.
Interview tip → Mention IPv6; many audits forget ::/0.
More on AWS automation with boto3
You are asked to write a script that stops all dev EC2 instances at 8 PM and starts them at 8 AM. How do you build it?BeginnerA script that lists all S3 objects in a bucket reports 1,000 objects, but the console says there are 48,000. What happened, and how do you fix the script?BeginnerYou need to find and delete EBS snapshots older than 90 days, but some are used by AMIs and backup plans. How do you write it safely?IntermediateYour audit script hits `ThrottlingException` / `RequestLimitExceeded` when scanning large accounts. What do you change?AdvancedYou must audit 40 AWS accounts in an Organization from one script. How do you handle credentials?AdvancedA Lambda written in Python times out at 15 minutes while processing a big S3 prefix. What are your options?Advanced