from utils import browser_manager from selenium.webdriver.common.by import By import time from selenium.webdriver.common.alert import Alert, Command from selenium.webdriver.common.keys import Keys import requests import os import urllib # recaptcha libraries import pydub import speech_recognition as sr from bs4 import BeautifulSoup from utils.global_vars import PROXY class QL_CreateAccount: def create_account(self): self.info = RandomNameGenerator(self.proxy).get_person_info() self.driver = browser_manager.start_browser() self.temp_mail = TempMail() self.temp_mail_address = self.temp_mail.get_new_temp_mail() self.sign_up() self.accept_eula() print("Account created!".format(self.info, self.temp_mail_address)) def sign_up(self): print("[+] Creating a new account for with mail [{}:{}]".format(self.info, self.temp_mail_address)) self.driver.get("https://www.qwiklabs.com/users/sign_up") time.sleep(1.5) #accept goddamn cookies browser_manager.clickButton(self.driver, By.XPATH, '/html/body/div[2]/div/button') time.sleep(2) browser_manager.inputText(self.driver, By.CSS_SELECTOR, "#user_first_name", self.info[0], after_delay=1.5) browser_manager.inputText(self.driver, By.CSS_SELECTOR, "#user_last_name", self.info[1], after_delay=1.5) browser_manager.inputText(self.driver, By.CSS_SELECTOR, "#user_email", self.temp_mail_address, after_delay=1.5) browser_manager.inputText(self.driver, By.CSS_SELECTOR, "#user_company_name", self.info[2], after_delay=1.5) browser_manager.inputText(self.driver, By.CSS_SELECTOR, "#user_password", "hellogoodbye", after_delay=1.5) browser_manager.inputText(self.driver, By.CSS_SELECTOR, "#user_password_confirmation", "hellogoodbye", after_delay=1.5) time.sleep(10) self.resolve_captcha('/html/body/div[1]/div[1]/div[2]/form[2]/div[8]/div/div/iframe', "recaptcha-checkbox", "/html/body/div[4]/div[4]", "recaptcha-audio-button") time.sleep(5) self.driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/form[2]/div[9]/button').click() def resolve_captcha(self, frame1_xpath, checkbox_classname, frame2_container_xpath, audio_id): # switch to recaptcha frame # frames = self.driver.find_elements_by_tag_name("iframe") # self.driver.switch_to.frame(frames[0]) self.driver.switch_to.frame(self.driver.find_element_by_xpath(frame1_xpath)) browser_manager.delay(self.driver) # click on checkbox to activate recaptcha self.driver.find_element_by_class_name(checkbox_classname).click() # switch to recaptcha audio control frame self.driver.switch_to.default_content() frame2_container = browser_manager.waitForElement(self.driver, By.XPATH, frame2_container_xpath) # Sometimes the captcha gets accepted right away if frame2_container is False: return frames = frame2_container.find_elements_by_tag_name("iframe") self.driver.switch_to.frame(frames[0]) browser_manager.delay(self.driver) # click on audio challenge self.driver.find_element_by_id(audio_id).click() # switch to recaptcha audio challenge frame self.driver.switch_to.default_content() frames = self.driver.find_elements_by_tag_name("iframe") self.driver.switch_to.frame(frames[-1]) browser_manager.delay(self.driver) # get the mp3 audio file src = self.driver.find_element_by_id("audio-source").get_attribute("src") print("[INFO] Audio src: %s" % src) # download the mp3 audio file from the source urllib.request.urlretrieve(src, os.path.normpath(os.getcwd() + "\\sample.mp3")) browser_manager.delay(self.driver) # load downloaded mp3 audio file as .wav try: sound = pydub.AudioSegment.from_mp3(os.path.normpath(os.getcwd() + "\\sample.mp3")) sound.export(os.path.normpath(os.getcwd() + "\\sample.wav"), format="wav") sample_audio = sr.AudioFile(os.path.normpath(os.getcwd() + "\\sample.wav")) except Exception: print("[ERR] Please run program as administrator or download ffmpeg manually, " "http://blog.gregzaal.com/how-to-install-ffmpeg-on-windows/") # translate audio to text with google voice recognition r = sr.Recognizer() with sample_audio as source: audio = r.record(source) key = r.recognize_google(audio) print("[INFO] Recaptcha Passcode: %s" % key) # key in results and submit self.driver.find_element_by_id("audio-response").send_keys(key.lower()) self.driver.find_element_by_id("audio-response").send_keys(Keys.ENTER) self.driver.switch_to.default_content() browser_manager.delay(self.driver) # self.driver.find_element_by_id("recaptcha-verify-button").click() # browser_manager.delay(self.driver) def accept_eula(self): self.driver.get(self.temp_mail.get_confirmation_link()) time.sleep(5) #insert password browser_manager.inputText(self.driver, By.CSS_SELECTOR, "#user_password", "hellogoodbye", after_delay=1.5) browser_manager.clickButton(self.driver, By.XPATH, "/html/body/div[2]/div[1]/div[2]/form/div[4]/button") time.sleep(10) browser_manager.clickButton(self.driver, By.XPATH, '/html/body/div[2]/div/button') time.sleep(2) self.resolve_captcha('/html/body/div[1]/form/div/div/div/div/div/iframe', "recaptcha-checkbox", "/html/body/div[4]/div[4]", "recaptcha-audio-button") time.sleep(5) browser_manager.clickButton(self.driver, By.XPATH, '/html/body/div[1]/form/input[5]') time.sleep(1000) class RandomNameGenerator(): def __init__(self): self.proxyDict = { "socks" : PROXY, "socksVersion" : 5 } def get_person_info(self): if PROXY: r = requests.get('https://randomuser.me/api', proxies=self.proxyDict) else: r = requests.get('https://randomuser.me/api') firstname = r.json()['results'][0]['name']['first'] lastname = r.json()['results'][0]['name']['last'] #use city as company company = r.json()['results'][0]['location']['city'] return (firstname, lastname, company) # get a temp mail from https://www.1secmail.com/api/ and handle it using requests class TempMail: def __init__(self): self.proxyDict = { "socks" : PROXY, "socksVersion" : 5 } # Open a new tab, head over to temp-mail.org, click the delete button and get a new temp mail def get_new_temp_mail(self): self.email = requests.get('https://www.1secmail.com/api/v1/?action=genRandomMailbox', proxies=self.proxyDict).json()[0] return self.email # Wait for qwiklabs confirmation email to arrive, click it def get_confirmation_link(self): arrived = False while arrived == False: print('Waiting for confirmation email') fetched_msg = requests.get('https://www.1secmail.com/api/v1/?action=getMessages&login=' + self.email.split('@')[0] + '&domain='+self.email.split('@')[1], proxies=self.proxyDict) arrived = fetched_msg.text != '[]' time.sleep(2) print('Email arrived') msg_id = fetched_msg.json()[0]['id'] email = requests.get('https://www.1secmail.com/api/v1/?action=readMessage&login=' + self.email.split('@')[0] + '&domain='+self.email.split('@')[1] + '&id=' + str(msg_id)) body = email.json()['body'] soup = BeautifulSoup(body, 'html.parser') a = "" for link in soup.find_all('a'): if 'confirmation' in link.get('href'): a = link.get('href') print("Here's the confirmation link " + a) return a