Last active
April 4, 2016 11:04
-
-
Save minhoryang/26f19fd23efc0759d09a to your computer and use it in GitHub Desktop.
Sign-in Multiple AWS Accounts and Get Credentials (NEED TO TYPE CAPTCHA)
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
from boto import config, connect_iam | |
config.add_section('Credentials') | |
prefix = "--------" | |
username = "student" | |
password = "" | |
for i in range(0, 111): | |
idx = "{0:03}".format(i) | |
cred = open(idx) | |
config.set('Credentials', 'aws_access_key_id', cred.readline().strip()) | |
config.set('Credentials', 'aws_secret_access_key', cred.readline().strip()) | |
iam = connect_iam() | |
iam.create_account_alias(prefix + "-" + idx) | |
iam.create_user(username) | |
iam.create_login_profile(username, password) |
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
from selenium import webdriver | |
from time import sleep # XXX : I really hate to use it... | |
def create(prefix="--------", idx="000", addr="Seoul", phone="821000000000"): | |
b = webdriver.Chrome() | |
b.get("https://portal.aws.amazon.com/gp/aws/developer/registration/index.html") | |
b.find_element_by_id("ap_email").send_keys(prefix + "+" + idx + "@gmail.com") | |
b.find_element_by_id("ap_signin_create_radio").click() | |
b.find_element_by_id("signInSubmit-input").click() | |
b.find_element_by_id("ap_customer_name").send_keys(prefix + "+" + idx) | |
b.find_element_by_id("ap_email_check").send_keys(prefix + "+" + idx + "@gmail.com") | |
b.find_element_by_id("ap_password").send_keys(prefix + "+" + idx) | |
b.find_element_by_id("ap_password_check").send_keys(prefix + "+" + idx) | |
b.find_element_by_name("guess").send_keys(input()) | |
try: | |
b.find_element_by_id("continue-input").click() | |
finally: | |
input("next page?") | |
b.find_element_by_name("fullName").send_keys(prefix + "+" + idx) | |
b.find_element_by_css_selector(".control-select").send_keys("ko") | |
b.find_element_by_name("addressLine1").send_keys(addr) | |
b.find_element_by_name("city").send_keys(addr) | |
b.find_element_by_name("state").send_keys(addr) | |
b.find_element_by_name("postalCode").send_keys(addr) | |
b.find_element_by_name("phoneNumber").send_keys(phone) | |
b.find_element_by_css_selector(".display-inline-block") | |
b.find_element_by_name("guess").send_keys(input(idx+"\n")) | |
b.find_element_by_name("agreementAccepted").click() | |
b.find_element_by_css_selector(".a-button-text").click() | |
input() | |
b.close() | |
def first_login(b, idx, prefix): | |
b.find_element_by_name("password").send_keys(prefix + "+" + idx) | |
b.find_element_by_name("guess").click() | |
sleep(4) | |
b.find_element_by_name("guess").send_keys(input()) | |
b.find_element_by_id("signInSubmit-input").click() | |
def iam(prefix="--------", idx="000"): | |
b = webdriver.Chrome() | |
b.get("https://console.aws.amazon.com") | |
b.find_element_by_name("email").send_keys(prefix + "+" + idx + "@gmail.com") | |
first_login(b, idx, prefix) | |
while len(b.find_elements_by_id("message_error")): | |
first_login(b, idx, prefix) | |
sleep(1) | |
while len(b.find_elements_by_id("message_warning")): | |
first_login(b, idx, prefix) | |
b.find_element_by_id("nav-usernameMenu").click() | |
sleep(1) | |
b.find_element_by_id("aws-security-credentials").click() | |
sleep(1) | |
b.find_element_by_id("continue").click() | |
b.find_elements_by_css_selector(".accordion-toggle")[2].click() | |
b.find_element_by_css_selector(".root_key .create").click() | |
sleep(1) | |
b.find_element_by_css_selector(".showCredentials").click() | |
sleep(1) | |
f = open(idx, "w") | |
for i in b.find_elements_by_css_selector(".attrValue"): | |
f.write(i.text + "\n") | |
f.close() | |
b.close() | |
if __name__ == "__main__": | |
for i in range(0,111): | |
print("{0:03}".format(i)) | |
create("{0:03}".format(i)) | |
iam("{0:03}".format(i)) |
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
from selenium import webdriver | |
from selenium.common.exceptions import NoSuchElementException | |
from selenium.webdriver.support.ui import Select | |
from time import sleep # XXX : I really hate to use it... | |
def first_login(b, idx, prefix, time): | |
sleep(time) | |
b.find_element_by_name("password").send_keys(prefix + "+" + idx) | |
sleep(time) | |
try: | |
b.find_element_by_name("guess").click() | |
b.find_element_by_name("guess").send_keys(input("CAPTCHA - ")) | |
except NoSuchElementException: | |
pass | |
sleep(time) | |
b.find_element_by_id("signInSubmit-input").click() | |
def signout(prefix="--------", idx="000", time=.5): | |
chrome_options = webdriver.ChromeOptions() | |
chrome_options.add_argument("--incognito") | |
b = webdriver.Chrome(chrome_options=chrome_options) | |
b.get("https://console.aws.amazon.com") | |
sleep(time) | |
b.find_element_by_name("email").send_keys(prefix + "+" + idx + "@gmail.com") | |
sleep(time) | |
first_login(b, idx, prefix, time) | |
while len(b.find_elements_by_id("message_warning")): | |
first_login(b, idx, prefix, time) | |
while len(b.find_elements_by_id("message_error")): | |
first_login(b, idx, prefix, time) | |
sleep(time) | |
b.get("https://console.aws.amazon.com/billing/home?region=us-west-2#/paymentmethods") | |
sleep(time) | |
b.find_element_by_css_selector(".payment-methods-add-btn").click() | |
sleep(time) | |
b.find_element_by_css_selector(".payment-methods-group-container:nth-child(1) input").send_keys("0000000000000000") | |
sleep(time) | |
b.find_element_by_css_selector(".payment-methods-group-container:nth-child(2) input").send_keys("AAAAA AA AAA") | |
sleep(time) | |
b.find_element_by_css_selector(".expiration-month select").send_keys("00") | |
sleep(time) | |
b.find_element_by_css_selector(".expiration-year select").send_keys("0000") | |
sleep(time) | |
b.find_element_by_css_selector(".payment-method-add-card-btns button").click() | |
sleep(time) | |
for idx, item in enumerate( | |
b.find_elements_by_css_selector(".payment-methods-address-form:nth-child(2) input")): | |
sleep(time) | |
if idx == 1: | |
item.send_keys("AAAAA AA AAA") | |
elif idx == 2: | |
item.send_keys("BBBB BB B BBB") | |
elif idx == 4: | |
item.send_keys("CCCCC") | |
elif idx == 5: | |
item.send_keys("Seoul") | |
elif idx == 6: | |
item.send_keys("DDDDDD") | |
elif idx == 7: | |
item.send_keys("EEEEEE") | |
sleep(time) | |
Select(b.find_element_by_css_selector(".payment-methods-address-form:nth-child(2) select")).select_by_visible_text("대한민국") | |
sleep(time) | |
b.find_element_by_css_selector(".payment-methods-complete-card-btns button").click() | |
sleep(time) | |
sleep(time) | |
sleep(time) | |
sleep(time) | |
sleep(time) | |
sleep(time) | |
sleep(time) | |
b.close() | |
if __name__ == "__main__": | |
for i in range(int(input()),111): | |
print("{0:03}".format(i)) | |
signout(idx="{0:03}".format(i)) |
If we answered the given captcha too fast, they block it.
That's why I used to use time.sleep()
maybe I typed 450+ CAPTCHAes.... OMG
이러고도 student로 EC2에 접속하려고 하면 문제가 생겨요.
root 어카운트로 접속해서 EC2에 접속한 다음 약관을 하나 더 봐야 했던 기억이 있어요!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
really hate to do it.... :(