module to list ec2 public ips

This commit is contained in:
carnal0wnage
2019-05-30 13:44:05 -04:00
parent 1a712a8299
commit d9d25fa442
2 changed files with 47 additions and 2 deletions

View File

@@ -472,6 +472,45 @@ def describe_elastic_addresses():
except KeyboardInterrupt: except KeyboardInterrupt:
print("CTRL-C received, exiting...") print("CTRL-C received, exiting...")
def describe_publicips():
'''
Describe EC2 Public IPs (loop through all regions)
'''
try:
for region in regions:
try:
client = boto3.client('ec2', region_name=region)
response = client.describe_network_interfaces()
# print(response)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'UnauthorizedOperation':
print('{} : (UnauthorizedOperation) when calling describe_network_interfaces -- sure you have required ec2 permissions?' .format(AWS_ACCESS_KEY_ID))
sys.exit()
else:
print(e)
if response.get('NetworkInterfaces') is None:
print("{} likely does not have EC2 permissions\n" .format(AWS_ACCESS_KEY_ID))
elif len(response['NetworkInterfaces']) <= 0:
print("[-] DescribeNetworkInterfaces allowed for {} but no results [-]" .format(region))
else:
# print(response)
print("[+] Listing Public IPs for region: {} [+]" .format(region))
for r in response['NetworkInterfaces']:
if 'Association' in r:
pp.pprint(r['Association']['PublicIp'])
else:
#pp.pprint(r)
next
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'UnauthorizedOperation':
print('{} : (UnauthorizedOperation) when calling the describe_network_interfaces-- sure you have ec2 permissions?' .format(AWS_ACCESS_KEY_ID))
elif e.response['Error']['Code'] == 'SubscriptionRequiredException':
print('{} : Has permissions but isnt signed up for service - usually means you have a root account' .format(AWS_ACCESS_KEY_ID))
else:
print(e)
except KeyboardInterrupt:
print("CTRL-C received, exiting...")
def describe_network_interfaces(): def describe_network_interfaces():
''' '''
@@ -485,7 +524,7 @@ def describe_network_interfaces():
# print(response) # print(response)
except botocore.exceptions.ClientError as e: except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'UnauthorizedOperation': if e.response['Error']['Code'] == 'UnauthorizedOperation':
print('{} : (UnauthorizedOperation) when calling get_console_screenshot -- sure you have required ec2 permissions?' .format(AWS_ACCESS_KEY_ID)) print('{} : (UnauthorizedOperation) when calling describe_network_interfaces -- sure you have required ec2 permissions?' .format(AWS_ACCESS_KEY_ID))
sys.exit() sys.exit()
else: else:
print(e) print(e)
@@ -500,7 +539,7 @@ def describe_network_interfaces():
pp.pprint(r) pp.pprint(r)
except botocore.exceptions.ClientError as e: except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'UnauthorizedOperation': if e.response['Error']['Code'] == 'UnauthorizedOperation':
print('{} : (UnauthorizedOperation) when calling the DescribeInstances-- sure you have ec2 permissions?' .format(AWS_ACCESS_KEY_ID)) print('{} : (UnauthorizedOperation) when calling the describe_network_interfaces -- sure you have ec2 permissions?' .format(AWS_ACCESS_KEY_ID))
elif e.response['Error']['Code'] == 'SubscriptionRequiredException': elif e.response['Error']['Code'] == 'SubscriptionRequiredException':
print('{} : Has permissions but isnt signed up for service - usually means you have a root account' .format(AWS_ACCESS_KEY_ID)) print('{} : Has permissions but isnt signed up for service - usually means you have a root account' .format(AWS_ACCESS_KEY_ID))
else: else:

View File

@@ -79,6 +79,12 @@ def module_ec2_describe_network_interfaces():
''' '''
describe_network_interfaces() describe_network_interfaces()
def module_ec2_describe_publicips():
'''
This function is used to describe ec2 network interfaces.
python3 weirdAAL.py -m ec2_describe_publicips -t demo
'''
describe_publicips()
def module_ec2_describe_route_tables(): def module_ec2_describe_route_tables():
''' '''