-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrecaptcha_solver.py
95 lines (78 loc) · 3.06 KB
/
recaptcha_solver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#system libraries
import os
import sys
import random
import time
#selenium libraries
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import UnexpectedAlertPresentException
from selenium.webdriver.chrome.options import Options
#recaptcha libraries
import speech_recognition as sr
import urllib
import pydub
def delay ():
time.sleep(random.randint(2,3))
try:
#create chrome driver
driver = webdriver.Chrome(ChromeDriverManager().install())
delay()
#go to website
driver.get("https://www.google.com/recaptcha/api2/demo")
except:
print("[-] Please update the chromedriver.exe in the webdriver folder according to your chrome version:https://chromedriver.chromium.org/downloads")
#switch to recaptcha frame
frames=driver.find_elements_by_tag_name("iframe")
driver.switch_to.frame(frames[0]);
delay()
#click on checkbox to activate recaptcha
driver.find_element_by_class_name("recaptcha-checkbox-border").click()
#switch to recaptcha audio control frame
driver.switch_to.default_content()
frames=driver.find_element_by_xpath("/html/body/div[2]/div[4]").find_elements_by_tag_name("iframe")
driver.switch_to.frame(frames[0])
delay()
#click on audio challenge
driver.find_element_by_id("recaptcha-audio-button").click()
#switch to recaptcha audio challenge frame
driver.switch_to.default_content()
frames= driver.find_elements_by_tag_name("iframe")
driver.switch_to.frame(frames[-1])
delay()
#click on the play button
driver.find_element_by_xpath("/html/body/div/div/div[3]/div/button").click()
#get the mp3 audio file
src = 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"))
delay()
#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:
print("[-] Please run program as administrator")
r= sr.Recognizer()
with sample_audio as source:
audio = r.record(source)
#translate audio to text with google voice recognition
key=r.recognize_google(audio)
print("[INFO] Recaptcha Passcode: %s"%key)
#key in results and submit
driver.find_element_by_id("audio-response").send_keys(key.lower())
driver.find_element_by_id("audio-response").send_keys(Keys.ENTER)
driver.switch_to.default_content()
delay()
driver.find_element_by_id("recaptcha-demo-submit").click()
delay()