def get_phantomjs_driver_with_proxy(self, proxy_info, scheme='http'): webdriver.DesiredCapabilities.PHANTOMJS[ 'phantomjs.page.settings.userAgent'] = self.ua webdriver.DesiredCapabilities.PHANTOMJS[ 'phantomjs.page.settings.resourceTimeout'] = '500000' if 'proxy_username' in proxy_info and 'proxy_password' in proxy_info: service_args = [ '--proxy=%s:%s' % (proxy_info['proxy_host'], proxy_info['proxy_port']), '--proxy-auth=%s:%s' % (proxy_info['proxy_username'], proxy_info['proxy_password']), '--proxy-type=%s' % (scheme), '--ignore-ssl-errors=true', '--ssl-protocol=any', ] else: service_args = [ '--proxy=%s:%s' % (proxy_info['proxy_host'], proxy_info['proxy_port']), '--proxy-type=%s' % (scheme), '--ignore-ssl-errors=true', '--ssl-protocol=any', ] browser = PhantomJS(service_args=service_args) browser.set_page_load_timeout('10') browser.implicitly_wait('10') self.logger.info('set proxy %s:%s source ip: %s type: %d', proxy_info['proxy_host'], proxy_info.get('proxy_username'), proxy_info['source_ip'], proxy_info['type']) return browser
def delete(self, user): ''' Delete the user on Github Enterprise ''' # Initialize the PhantomJS selenium driver driver = PhantomJS() driver.implicitly_wait(10) driver.set_window_size(1400, 850) # Login as the admin user driver.get('https://%s/login' % (self.ghe_host)) driver.find_element_by_name('login').send_keys(self.ghe_user) driver.find_element_by_name('password').send_keys(self.ghe_pass) driver.find_element_by_name('commit').click() # Check for two-factor auth code request if driver.current_url == 'https://%s/sessions/two-factor' % self.ghe_host: if self.ghe_totp: base = '.auth-form-body input' u = driver.find_element_by_css_selector('%s[name=utf8]' % base) t = driver.find_element_by_css_selector('%s[name=authenticity_token]' % base) otp = pyotp.TOTP(self.ghe_totp) driver.request('POST', 'https://%s/sessions/two-factor' % self.ghe_host, data={ 'utf8': u.get_attribute('value'), 'otp': otp.now(), 'authenticity_token': t.get_attribute('value') } ) else: print('Two-Factor authentication required.') sys.exit() # Retrieve the admin page for the designated user to be deleted driver.get('https://%s/stafftools/users/%s/admin' % (self.ghe_host, user)) # Ensure that we were able to access the requested admin page if 'Page not found' in driver.title or user.lower() not in driver.title.lower(): print('User not found, or insufficient access rights.') sys.exit() # Locate the necessary inputs to be able to delete a user base = '#confirm_deletion form input' u = driver.find_element_by_css_selector('%s[name=utf8]' % base) m = driver.find_element_by_css_selector('%s[name=_method]' % base) t = driver.find_element_by_css_selector('%s[name=authenticity_token]' % base) # Send the delete user request driver.request('POST', 'https://%s/stafftools/users/%s' % (self.ghe_host, user), data={ 'utf8': u.get_attribute('value'), '_method': m.get_attribute('value'), 'authenticity_token': t.get_attribute('value') } )
def mainprocess(captchakey, saveloc): user_agent = ( "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) " + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36" ) dcap = dict(DesiredCapabilities.PHANTOMJS) dcap["phantomjs.page.settings.userAgent"] = user_agent driver = PhantomJS(desired_capabilities=dcap, service_args=['--load-images=no']) #driver = webdriver.PhantomJS() driver.set_window_size(1600, 1200) driver.implicitly_wait(10) driver.get("https://club.pokemon.com/us/pokemon-trainer-club") driver.find_element_by_id("user-account-signup").click() delay = 5 # seconds try: myElem = WebDriverWait(driver, delay).until( EC.presence_of_element_located((By.ID, 'id_dob'))) except TimeoutException: logging.info("Loading took too much time!") elem = driver.find_element_by_name("dob") driver.execute_script( "var input = document.createElement('input'); input.type='text'; input.setAttribute('name', 'dob'); arguments[0].parentNode.replaceChild(input, arguments[0])", elem) randdate = datetime.date(randint(1975, 1990), randint(1, 12), randint(1, 28)) elem = driver.find_element_by_name("dob") elem.send_keys(datetime.datetime.strftime(randdate, '%Y-%m-%d')) driver.save_screenshot('bday4.png') time.sleep(1) delay = 5 # seconds try: myElem = WebDriverWait(driver, delay).until( EC.presence_of_element_located(( By.XPATH, '//*[@id="sign-up-theme"]/section/div/div/div[1]/form/div[2]/div/div/label' ))) except TimeoutException: logging.info("Loading took too much time!") myElem.click() time.sleep(1) delay = 5 # seconds try: myElem = WebDriverWait(driver, delay).until( EC.presence_of_element_located(( By.XPATH, '//*[@id="sign-up-theme"]/section/div/div/div[1]/form/div[2]/div/div/div/div/ul/li[168]' ))) except TimeoutException: logging.info("Loading took too much time!") myElem.click() driver.find_element_by_xpath( '//*[@id="sign-up-theme"]/section/div/div/div[1]/form/input[2]').click( ) randomemail = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) randompass = ''.join( random.SystemRandom().choice(string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation) for _ in range(10)) driver2 = PhantomJS(desired_capabilities=dcap, service_args=['--load-images=no']) driver2.set_window_size(1600, 1200) driver2.get("https://temp-mail.org/en/option/change/") driver2.find_element_by_name("mail").send_keys(randomemail) doms = Select(driver2.find_element_by_xpath('//*[@id="domain"]')) x = doms.options domain = str(x[0].text) time.sleep(3) driver2.find_element_by_id('postbut').click() driver2.get("https://temp-mail.org/en/option/refresh/") driver.save_screenshot('screenshot.png') driver.find_element_by_id('id_username').send_keys(randomemail) driver.find_element_by_id('check-availability-username').click() delay = 5 # seconds try: myElem = WebDriverWait(driver, delay).until( EC.presence_of_element_located( (By.XPATH, '//*[@id="username-suggestion"]/div/h3'))) if driver.find_element_by_xpath( '//*[@id="username-suggestion"]/div').find_element_by_tag_name( 'h3').text == 'Username is invalid.': logging.info('Username already in use exiting') exit() except TimeoutException: logging.info("Loading took too much time!") driver.find_element_by_id('id_password').send_keys(randompass) driver.find_element_by_id('id_confirm_password').send_keys(randompass) driver.find_element_by_id('id_email').send_keys(randomemail + domain) driver.find_element_by_id('id_confirm_email').send_keys(randomemail + domain) driver.find_element_by_id('id_screen_name').send_keys(randomemail) driver.find_element_by_id('check-availability-screen-name').click() delay = 5 # seconds try: myElem = WebDriverWait(driver, delay).until( EC.presence_of_element_located(( By.XPATH, '//*[@id="user-signup-create-account-form"]/fieldset[1]/div/div/div[1]/div/div[11]/div/div/h3' ))) if driver.find_element_by_xpath( '//*[@id="user-signup-create-account-form"]/fieldset[1]/div/div/div[1]/div/div[11]/div/div' ).find_element_by_tag_name( 'h3' ).text == 'This screen name already exists. Please try the following:': logging.info('Screen Name already in use exiting') exit() except TimeoutException: logging.info("Loading took too much time!") driver.find_element_by_id('id_terms').click() logging.info("Starting captcha solve") # AutoCapcha autocaptcha(captchakey, driver) driver.find_element_by_xpath( '//*[@id="user-signup-create-account-form"]/fieldset[2]/div/input' ).click() driver.close() logging.info("Waiting on Email") for z in range(0, 10): try: delay = 60 # seconds try: myElem = WebDriverWait(driver2, delay).until( EC.presence_of_element_located( (By.XPATH, '//*[@id="mails"]/tbody'))) except TimeoutException: if z == 9: logging.info("Can't Find the email sorries :(") exit() else: logging.info("No Email Yet " + str(z + 1) + "/10") driver2.refresh() except: continue myElem.click() time.sleep(5) elems = driver2.find_elements_by_tag_name('a') time.sleep(5) for elem in elems: test = str(elem.get_attribute("href")) if "https://club.pokemon.com/us/pokemon-trainer-club/activated/" in test: actions = ActionChains(driver2) actions.move_to_element(elem).perform() elem.click() break time.sleep(10) driver2.quit() logging.info("Account created saving details") with open(os.path.join(saveloc, 'accounts.txt'), "a") as myfile: myfile.write("\n" + randomemail + ' - ' + randompass) logging.info(randomemail + " account created")
def update(self, user, email): ''' Reset the users email address on Github Enterprise ''' # Initialize the PhantomJS selenium driver driver = PhantomJS() driver.implicitly_wait(10) driver.set_window_size(1400, 850) # Login as the admin user driver.get('https://%s/login' % (self.ghe_host)) driver.find_element_by_name('login').send_keys(self.ghe_user) driver.find_element_by_name('password').send_keys(self.ghe_pass) driver.find_element_by_name('commit').click() # Check for two-factor auth code request if driver.current_url == 'https://%s/sessions/two-factor' % self.ghe_host: if self.ghe_totp: base = '.auth-form-body input' u = driver.find_element_by_css_selector('%s[name=utf8]' % base) t = driver.find_element_by_css_selector( '%s[name=authenticity_token]' % base) otp = pyotp.TOTP(self.ghe_totp) driver.request( 'POST', 'https://%s/sessions/two-factor' % self.ghe_host, data={ 'utf8': u.get_attribute('value'), 'otp': otp.now(), 'authenticity_token': t.get_attribute('value') }) else: print('Two-Factor authentication required.') sys.exit() # Retrieve the email admin page for the designated user to be updated driver.get('https://%s/stafftools/users/%s/emails' % (self.ghe_host, user)) # Ensure that we were able to access the requested admin page if 'Page not found' in driver.title or user.lower( ) not in driver.title.lower(): print('User not found, or insufficient access rights.') sys.exit() # Locate the necessary inputs to be able to add an email address base = 'form[action="/stafftools/users/%s/emails"] input' % user u = driver.find_element_by_css_selector('%s[name=utf8]' % base) t = driver.find_element_by_css_selector('%s[name=authenticity_token]' % base) # Send the add email address request driver.request('POST', 'https://%s/stafftools/users/%s/emails' % (self.ghe_host, user), data={ 'utf8': u.get_attribute('value'), 'email': email, 'authenticity_token': t.get_attribute('value') }) # Send password reset to new email address base = 'form[action="/stafftools/users/%s/password/send_reset_email"] input' % user u = driver.find_element_by_css_selector('%s[name=utf8]' % base) t = driver.find_element_by_css_selector('%s[name=authenticity_token]' % base) m = driver.find_element_by_css_selector('%s[name=_method]' % base) driver.request( 'POST', 'https://%s/stafftools/users/%s/password/send_reset_email' % (self.ghe_host, user), data={ 'utf8': u.get_attribute('value'), 'email': email, 'authenticity_token': t.get_attribute('value'), '_method': m.get_attribute('value') }) # Get password reset link and display to console driver.get('https://%s/stafftools/users/%s/emails' % (self.ghe_host, user)) if email in driver.page_source: print('Email added and password reset email sent.') else: print( 'New email not showing up on user page; please check manually.' )