diff --git a/.gitignore b/.gitignore index 60ae234..dd9efd9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ +*.pyc +*.pyo +.DS_Store +.Rhistory +chromedriver chromedriver/ diff --git a/README.md b/README.md index e8ff0fa..0655303 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,35 @@ -# KelloggBot -Credit to SeanDaBlack for the basis of the script. - -req.py is selenium python bot. -sc.js is a the base of the ios shortcut [COMING SOON] - -# Setup - -On mac/pc: - -`pip install -r requirements.txt` - -You will probably need to go get the chrome driver to make selenium work, as they are version-specific. The one in the repo might not do it for you. Find your chrome version by going to **Chrome** >> **About Google Chrome**. - -This will open a tab that shows you your verison. Visit https://sites.google.com/chromium.org/driver/downloads and download the driver for your version. - -folder. Extract the downloaded zip file. Move the extracted chromedriver binary to this project folder - -`mv ~/Downloads/chromedriver .` - -It needs to be found in your `PATH` variable. - -`export PATH=$PATH:$(pwd)` - -`python req.py` to run. It will loop until you kill the job. `ctrl + c` in your terminal to give the pro lifes a break (optional). - -mac: - -You might also get a trust issue with the downloaded driver being unverified. To fix that, run - -`xattr -d com.apple.quarantine chromedriver` - -this just tells the OS it's safe to use this driver, and Selenium will start working. See https://timonweb.com/misc/fixing-error-chromedriver-cannot-be-opened-because-the-developer-cannot-be-verified-unable-to-launch-the-chrome-browser-on-mac-os/ for more info. +# KelloggBot +Credit to SeanDaBlack for the basis of the script. + +req.py is selenium python bot. +sc.js is a the base of the ios shortcut [COMING SOON] + +# Setup + +On mac/pc: + +`pip install -r requirements.txt` + +You will probably need to go get the chrome driver to make selenium work, as they are version-specific. The one in the repo might not do it for you. Find your chrome version by going to **Chrome** >> **About Google Chrome**. + +This will open a tab that shows you your verison. Visit https://sites.google.com/chromium.org/driver/downloads and download the driver for your version. + +folder. Extract the downloaded zip file. Move the extracted chromedriver binary to this project folder + +`mv ~/Downloads/chromedriver .` + +It needs to be found in your `PATH` variable. + +`export PATH=$PATH:$(pwd)` + +`python req.py` to run. It will loop until you kill the job. `ctrl + c` in your terminal to give the pro lifes a break (optional). + +mac: + +You might also get a trust issue with the downloaded driver being unverified. To fix that, run + +`xattr -d com.apple.quarantine chromedriver` + +this just tells the OS it's safe to use this driver, and Selenium will start working. See https://timonweb.com/misc/fixing-error-chromedriver-cannot-be-opened-because-the-developer-cannot-be-verified-unable-to-launch-the-chrome-browser-on-mac-os/ for more info. + +You will also need to install ffmpeg if it is not already installed: [Mac installation guide](https://superuser.com/a/624562) [Windows installation guide](https://www.wikihow.com/Install-FFmpeg-on-Windows) \ No newline at end of file diff --git a/captchaAudio/.gitignore b/captchaAudio/.gitignore new file mode 100644 index 0000000..94548af --- /dev/null +++ b/captchaAudio/.gitignore @@ -0,0 +1,3 @@ +* +*/ +!.gitignore diff --git a/constants/classNames.py b/constants/classNames.py new file mode 100644 index 0000000..c74800d --- /dev/null +++ b/constants/classNames.py @@ -0,0 +1,2 @@ +CAPTCHA_BOX = 'recapBorderAccessible' +AUDIO_ERROR_MESSAGE = 'rc-audiochallenge-error-message' diff --git a/constants/elementIds.py b/constants/elementIds.py index b0e0870..8776c27 100644 --- a/constants/elementIds.py +++ b/constants/elementIds.py @@ -9,3 +9,7 @@ RELATIVE_WORKER_LABEL = '227:_select' ESSENTIAL_FUNCTIONS_LABEL = '231:_select' GENDER_LABEL = '235:_select' +RECAPTCHA_AUDIO_BUTTON = 'recaptcha-audio-button' +RECAPTCHA_ANCHOR = 'recaptcha-anchor' +AUDIO_SOURCE = 'audio-source' +AUDIO_RESPONSE = 'audio-response' diff --git a/constants/fileNames.py b/constants/fileNames.py new file mode 100644 index 0000000..3888fd0 --- /dev/null +++ b/constants/fileNames.py @@ -0,0 +1,2 @@ +CAPTCHA_MP3_FILENAME = 'captchaAudio/1.mp3' +CAPTCHA_WAV_FILENAME = 'captchaAudio/2.wav' diff --git a/main.py b/main.py index f1c7eee..ebff83a 100644 --- a/main.py +++ b/main.py @@ -1,26 +1,113 @@ +import requests import functools import os +import subprocess import random import sys import time +import speech_recognition as sr from faker import Faker from selenium import webdriver from selenium.webdriver.support.ui import Select +from selenium.webdriver.common.keys import Keys from constants.common import * +from constants.fileNames import * +from constants.classNames import * from constants.elementIds import * from constants.email import * from constants.location import * from constants.urls import * from constants.xPaths import * +os.environ["PATH"] += ":/usr/local/bin" # Adds /usr/local/bin to my path which is where my ffmpeg is stored + fake = Faker() chromedriver_location = CHROMEDRIVER_PATH # Change default in module for print to flush # https://stackoverflow.com/questions/230751/how-can-i-flush-the-output-of-the-print-function-unbuffer-python-output#:~:text=Changing%20the%20default%20in%20one%20module%20to%20flush%3DTrue print = functools.partial(print, flush=True) +r = sr.Recognizer() + +def audioToText(mp3Path): + # deletes old file + try: + os.remove(CAPTCHA_WAV_FILENAME) + except FileNotFoundError: + pass + # convert wav to mp3 + subprocess.run(f"ffmpeg -i {mp3Path} {CAPTCHA_WAV_FILENAME}", shell=True, timeout=5) + + with sr.AudioFile(CAPTCHA_WAV_FILENAME) as source: + audio_text = r.listen(source) + try: + text = r.recognize_google(audio_text) + print('Converting audio transcripts into text ...') + return(text) + except Exception as e: + print(e) + print('Sorry.. run again...') + +def saveFile(content,filename): + with open(filename, "wb") as handle: + for data in content.iter_content(): + handle.write(data) +# END TEST + +def solveCaptcha(driver): + # Logic to click through the reCaptcha to the Audio Challenge, download the challenge mp3 file, run it through the audioToText function, and send answer + googleClass = driver.find_elements_by_class_name(CAPTCHA_BOX)[0] + time.sleep(2) + outeriframe = googleClass.find_element_by_tag_name('iframe') + time.sleep(1) + outeriframe.click() + time.sleep(2) + allIframesLen = driver.find_elements_by_tag_name('iframe') + time.sleep(1) + audioBtnFound = False + audioBtnIndex = -1 + for index in range(len(allIframesLen)): + driver.switch_to.default_content() + iframe = driver.find_elements_by_tag_name('iframe')[index] + driver.switch_to.frame(iframe) + driver.implicitly_wait(2) + try: + audioBtn = driver.find_element_by_id(RECAPTCHA_AUDIO_BUTTON) or driver.find_element_by_id(RECAPTCHA_ANCHOR) + audioBtn.click() + audioBtnFound = True + audioBtnIndex = index + break + except Exception as e: + pass + if audioBtnFound: + try: + while True: + href = driver.find_element_by_id(AUDIO_SOURCE).get_attribute('src') + response = requests.get(href, stream=True) + saveFile(response, CAPTCHA_MP3_FILENAME) + response = audioToText(CAPTCHA_MP3_FILENAME) + print(response) + driver.switch_to.default_content() + iframe = driver.find_elements_by_tag_name('iframe')[audioBtnIndex] + driver.switch_to.frame(iframe) + inputbtn = driver.find_element_by_id(AUDIO_RESPONSE) + inputbtn.send_keys(response) + inputbtn.send_keys(Keys.ENTER) + time.sleep(2) + errorMsg = driver.find_elements_by_class_name(AUDIO_ERROR_MESSAGE)[0] + if errorMsg.text == "" or errorMsg.value_of_css_property('display') == 'none': + print("reCaptcha defeated!") + break + except Exception as e: + print(e) + print('Oops, something happened. Check above this message for errors or check the chrome window to see if captcha locked you out...') + else: + print('Button not found. This should not happen.') + + time.sleep(2) + driver.switch_to.default_content() def start_driver(random_city): driver = webdriver.Chrome(chromedriver_location) @@ -66,6 +153,7 @@ def generate_account(driver): time.sleep(1.5) driver.find_element_by_xpath(ACCEPT_BUTTON).click() time.sleep(2) + solveCaptcha(driver) driver.find_element_by_xpath(CREATE_ACCOUNT_BUTTON).click() time.sleep(1.5) diff --git a/requirements.txt b/requirements.txt index f32abf4..f670805 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ idna==3.2 requests==2.26.0 selenium==3.141.0 urllib3==1.26.6 -Faker==9.9.1 \ No newline at end of file +Faker==9.9.1 +speechrecognition==3.8.1 \ No newline at end of file