Created
July 22, 2021 18:06
-
-
Save dgulinobw/0a140e1bdf5feead54fa90de44e959d8 to your computer and use it in GitHub Desktop.
Searches through AWS EC2 security groups for entries. Example: ./ec2_sg_scan.py 1.2.3.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import sys | |
import json | |
import boto3 | |
from pprint import pprint | |
from termcolor import colored | |
from botocore.exceptions import ClientError | |
find_str = sys.argv[1] | |
for region in ["us-east-1","us-east-2", "us-west-2"]: | |
ec2=boto3.client('ec2', region ) | |
sgs = ec2.describe_security_groups()["SecurityGroups"] | |
for sg in sgs: | |
if str(sg).count(find_str) > 0: | |
group_name = sg['GroupName'] | |
inbound = sg['IpPermissionsEgress'] | |
string = str(sg).replace(find_str, colored(find_str, 'green')) | |
region = colored(region, 'yellow') | |
group_name = colored(group_name, 'blue') | |
print("%s - %s: %s" % (region, group_name, string)) | |
#print("%s - %s" % (region, group_name)) #only security group names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment