-
-
Save attacker34/69fd2a219791301184cc8b1c457824be to your computer and use it in GitHub Desktop.
Quick script to scan for AWS (S3 Buckets) and retrieves bunch of info out of it
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
import subprocess | |
import argparse | |
import re | |
import sys | |
import requests | |
def do_dig(domain): | |
command = "dig {} | grep IN".format(domain) | |
try: | |
output = subprocess.check_output(command, shell=True, stdin=subprocess.PIPE, stderr=subprocess.STDOUT) | |
return re.findall(r"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b", output) | |
except: | |
return [] | |
def do_nslookup(ip): | |
command = "nslookup {}".format(ip) | |
try: | |
output = subprocess.check_output(command, shell=True, stdin=subprocess.PIPE, stderr=subprocess.STDOUT) | |
return output.split('name =')[1].split('\n')[0][1:-1] | |
except: | |
return None | |
def look_up(domain): | |
ip_candidates = do_dig(domain) | |
for ip in ip_candidates: | |
res = do_nslookup(ip) | |
if res and 'amazonaws.com' in res and 's3' in res: | |
region = res.replace(domain, '').split('.')[0].replace('s3-website-', '') | |
tmp_domain = "{}.s3.amazonaws.com".format(domain) | |
req = requests.get("http://{}".format(tmp_domain)) | |
print "[!] {} === {}.{}".format(domain, domain, res) | |
print "[!] Check: aws s3 ls s3://{}/ --no-sign-request --region {}".format(domain, region) | |
print "[!] Check: {} in your browser, status_code: {}".format(tmp_domain, req.status_code) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='AWS Scan') | |
parser.add_argument('-d', action="store", dest="domain", default=None, help="Domain to look for (eg. flaws.cloud)") | |
parser.add_argument('-f', action="store", dest="file", default=None, help="File to load (eg. domains.txt)") | |
params = parser.parse_args() | |
if not params.file and not params.domain: | |
parser.print_help() | |
sys.exit(-1) | |
domains = [] | |
# domain parameter | |
if params.domain: | |
domains.append(params.domain) | |
# file parameter | |
if params.file: | |
with open(params.file) as f: | |
lines = f.readlines() | |
for line in lines: | |
domains.append(line.rstrip()) | |
for domain in domains: | |
look_up(domain) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment