Exemplo n.º 1
0
def solve(file_path):
    """Solves an image-based captcha.

    Args:
        file_path (str): Path to the captcha that will be solved.

    Returns:
        The string from the solved captcha or an exception if any error has occured.

    """

    # Instantiates the 2Captcha's solver
    solver = TwoCaptcha(CAPTCHA_KEY)

    # Tries to perform the following block
    try:
        # Solves the captcha
        result = solver.normal(file_path)

        # Returns the solved captcha
        return result['code']

    # If an exception has been raised
    except Exception as e:
        # Returns the exception
        return e
Exemplo n.º 2
0
    def incorrect_captcha_report(self, captcha_service, captcha_id):
        """Function to send report to specific captcha solving service
        Used in case of captcha was incorrectly solved.
        """

        try:
            if captcha_service == "DBC":
                dbc_token = config['DBC_TOKEN']
                client = deathbycaptcha.HttpClient(None, None, dbc_token)
                client.report(captcha_id)
            elif captcha_service == "2Captcha":
                api_key = config['2CAPTCHA']
                solver = TwoCaptcha(api_key)
                solver.report(captcha_id, False)
            is_reported = True
        except:
            is_reported = False
        finally:
            self.incorrect_captcha_retries -= 1
            print(self.incorrect_captcha_retries)
            error_msg = {
                "error_type": "CAPTCHA_INCORRECTLY_SOLVED",
                "captcha_service": captcha_service,
                "is_reported": is_reported
            }

            if self.incorrect_captcha_retries == 0:
                self.errors.append(error_msg)
                self.logger.error(error_msg)
            else:
                self.logger.warning(error_msg)
Exemplo n.º 3
0
    def harverstor(self, apikey, sitekey, url):

        try:

            twoCaptcha = TwoCaptcha(apikey)
            recaptcha_token = twoCaptcha.solve_captcha(site_key=sitekey,
                                                       page_url=url)

            token = {
                "time": datetime.now().strftime('%y %m %d %I:%M%p'),
                "token": recaptcha_token,
                "claimed": False
            }

            self.tokens.append(token)

            with open('tokens.json', 'w') as outfile:
                json.dump(self.tokens, outfile)

            print(self.tokens)

        except Exception:

            traceback.print_exc()

            print("Unable to fetch tokens, restarting...")

            self.harverstor(url, apikey, sitekey)
Exemplo n.º 4
0
def solve(site_key, url):
    """Solves a re-captcha v2.

    Args:
        site_key (str): Site's captcha key.
        url (str): Site's URL.

    Returns:
        The string from the solved captcha or an exception if any error has occured.

    """

    # Instantiates the 2Captcha's solver
    solver = TwoCaptcha(CAPTCHA_KEY)

    # Tries to perform the following block
    try:
        # Solves the captcha
        result = solver.recaptcha(sitekey=site_key, url=url)

        # Returns the solved captcha
        return result['code']

    # If an exception has been raised
    except Exception as e:
        # Returns the exception
        return e
Exemplo n.º 5
0
 def __init__(self):
     config = {
         "apiKey": TWOCAPTCHA_API_KEY,
         "recaptchaTimeout": 120,
         "pollingInterval": 10,
     }
     self.solver = TwoCaptcha(**config)
Exemplo n.º 6
0
def add_captcha(sitekey, apikey):
    file = open(get_local_directory() + "/resources/captcha_tokens.txt", "a")
    site_url = 'http://www.supremenewyork.com'
    twoCaptcha = TwoCaptcha(apikey)
    file.write(
        twoCaptcha.solve_recaptcha(site_url=site_url, site_key=sitekey) + "|" +
        str(time.time()) + "\n")
    file.close()
Exemplo n.º 7
0
 def _get_client(api_token):
     solver = TwoCaptcha(api_token)
     try:
         balance = solver.balance()
         if not balance:
             raise InvalidOrNoBalanceApiToken('No balance left on the token.')
     except ApiException as msg:
         raise InvalidOrNoBalanceApiToken(msg) from None
     return solver
Exemplo n.º 8
0
def captcha_response(img_name, captcha_api_key):
    api_key = os.getenv('APIKEY_2CAPTCHA', f'{captcha_api_key}')
    solver = TwoCaptcha(api_key)
    try:
        result = solver.normal(f'{img_name}')
        #os.remove(os.getcwd() + f'./{img_name}')
        return result['code']
    except:
        #os.remove(os.getcwd() + f'./{img_name}')
        return False
Exemplo n.º 9
0
    def generateToken(self):
        print("Generating Token.....")
        captcha = TwoCaptcha('a464e17395843472cfcf29502f14be1f')
        token = captcha.solve_captcha(
            site_key="6Lc_ilIUAAAAANld5QNB-AiX_HdommM2dxwxku3Q",
            page_url=self.URL)

        print("Token Generated !!")

        return token
Exemplo n.º 10
0
 def twocaptcha(self, sitekey, url):
     sys.path.append(
         os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
     api_key = os.getenv('APIKEY_2CAPTCHA', 'xxxxx')
     solver = TwoCaptcha(api_key)
     try:
         result = solver.recaptcha(sitekey=sitekey, url=url)
     except Exception as e:
         sys.exit(e)
     else:
         return str(result['code'])
Exemplo n.º 11
0
def captcha_text(captcha_image):
    """
    return free number from sms-activate
    :return: str(ExAmPlE)"""
    api_key = os.getenv('YOUR_API_KEY')
    solver = TwoCaptcha(api_key)
    try:
        result = solver.normal(captcha_image)
    except Exception as e:
        result = ''
        print(e)
    return result
Exemplo n.º 12
0
def get_captcha(img):
    api_key = "483852b189a89e09da6919178ae88526"
    solver = TwoCaptcha(api_key, defaultTimeout=100, pollingInterval=5)
    try:
        result = solver.normal(img, caseSensitive=1)

    except Exception as e:
        print(e)

    else:
        print(result)
        return result['code']
Exemplo n.º 13
0
 def bypass_captcha(self, captcha_tag):
     # Bypassing ReCaptcha
     sitekey = captcha_tag['data-sitekey']
     url = self.driver.current_url
     solver = TwoCaptcha(self.CAPTCHA_KEY)
     result = solver.recaptcha(sitekey=sitekey, url=url, version=2)
     print(result['code'])
     self.driver.execute_script(
         'document.getElementById("g-recaptcha-response").innerHTML="{}";'.
         format(result['code']))
     sleep(3)
     self.driver.execute_script('submitForm()')
     sleep(10)
Exemplo n.º 14
0
def get_g_token(api_key, url) -> str:
    solver = TwoCaptcha(api_key)
    try:
        result = solver.solve_captcha(
            site_key='6LeCeskbAAAAAE-5ns6vBXkLrcly-kgyq6uAriBR', page_url=url)

    except Exception as e:
        print(e)
        exit(-1)
        return ""
    else:
        print('solved: ' + str(result))
        return result
Exemplo n.º 15
0
def get_recaptcha_response(api_key: str) -> str:
    """
    Solve the recaptcha  and return the response. This takes a minute or two.

    NOTE: This is configured to use 2Captcha as the captcha solving service. If
    you want to use a different service you'll have to modify this function.
    """
    solver = TwoCaptcha(apiKey=api_key)
    balance = solver.balance()
    print(f"2Captcha current balance: ${balance}...")
    if balance < 0.1:
        warnings.warn(f"2Captcha balance is running low")
    r = solver.recaptcha(sitekey=config.RECAPTCHA_SITE_KEY, url=config.WEBSITE_URL)
    return r["code"]
Exemplo n.º 16
0
def captcha_solver(captcha):
    try:
        if not captcha_type:  # Ручной ввод
            print(captcha.get_url())
            captcha.try_again(input("Код с картинки => "))
            logging.info("Каптча решена успешно")
        else:
            solver = TwoCaptcha(rucaptcha_token)
            code = solver.normal(
                b64encode(captcha.get_image()).decode("utf-8"))
            captcha.try_again(code['code'])
            logging.info("Каптча решена успешно")
    except:
        logging.warning("Каптча не решена")
Exemplo n.º 17
0
 def twocaptcha(self, sitekey):
     sys.path.append(
         os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
     api_key = os.getenv('APIKEY_2CAPTCHA',
                         ' 791a83d1333d48429227d52e1a153ea3')
     solver = TwoCaptcha(api_key)
     try:
         result = solver.recaptcha(
             sitekey=sitekey,
             url=
             'https://www.nakedcph.com/xx/904/nike-dunk-hi-retro-prm-fcfs-raffle'
         )
     except Exception as e:
         sys.exit(e)
     return str(result['code'])
Exemplo n.º 18
0
def get_and_solve(driver, two_captcha_api_key, url):
    """Get and solve captcha element."""
    recaptcha_element = driver.find_element(By.CLASS_NAME, "g-recaptcha")
    sitekey = recaptcha_element.get_attribute("data-sitekey")

    solver = TwoCaptcha(two_captcha_api_key)
    try:
        result = solver.recaptcha(sitekey=sitekey, url=url)

    except Exception as e:
        print(e)
    else:
        driver.execute_script(
            "document.getElementById('g-recaptcha-response').innerHTML='" +
            result["code"] + "';")
        time.sleep(3)
Exemplo n.º 19
0
    async def resolve(self, site_key, url):
        solver = TwoCaptcha(self._credential)
        logger.info(
            'Resolving captcha.'
        )
        try:
            solvedcaptcha = solver.recaptcha(site_key, url)
        except ApiException as error:
            raise CaptchaResolverException(
                f'Erro ao tentar resolver captcha: {error}'
            )

        logger.info(
            'Captcha resolved.'
        )

        return solvedcaptcha['code']
Exemplo n.º 20
0
def click_i_m_not_robot(driver):
    url = driver.current_url
    data_sitekey = None
    page_source = driver.page_source
    print("Done page source")
    data_sitekeys = findall('data-sitekey="(.*?)"', page_source)
    if data_sitekeys:
        data_sitekey = data_sitekeys[0]
        print("Multiple data sitekey selected the first one")
    else:
        elments = driver.find_elements_by_xpath(
            '//iframe[contains(@role,"presentation")]')
        print("in ifrmae")
        if elments:
            for elm in elments:
                if elm.is_displayed():
                    src = elm.get_attribute('src')
                    data_sitekey = findall('k=(.*?)&', src)[0]
                    print(f"Data_stirekey is {data_sitekey}")
                    break
        else:
            print("Did not find iframe")

    if data_sitekey is not None:
        print("Datakey is not none")
        print(f"Datakey {data_sitekey}")
        solver = TwoCaptcha(API_KEY)
        print("Solving captcha...")
        success_id = solver.recaptcha(data_sitekey, url)
        print("Solved...\nSending Captcha")
        driver.execute_script(
            'document.querySelector(".g-recaptcha-response").style.display="block";'
        )
        sleep(5)
        driver.execute_script(
            'document.querySelector(".g-recaptcha-response").innerText="%s";' %
            success_id["code"])
        print("Sent!")
        sleep(3)
        if driver.find_elements_by_xpath('//div[@data-callback]'):
            data_callback = driver.find_element_by_xpath(
                '//div[@data-callback]').get_attribute('data-callback')
            driver.execute_script(data_callback + "();")
    else:
        print("Data_sitekey is none")
Exemplo n.º 21
0
def solve(count) -> str:
    catpchakey = config['2capthcaKey']; solver = TwoCaptcha(catpchakey)
    print(f"{color.YELLOW}[{count}] Waiting for captcha to be resolved. {color.RESET_ALL}")

    try:
        result = solver.funcaptcha(sitekey="E5554D43-23CC-1982-971D-6A2262A2CA24", url=f"https://www.twitch.tv/", version="v3", score=0.1)

    except Exception as err:
        if "ERROR_ZERO_BALANCE" in str(err):
            print(f"{color.RED}[-]{color.RESET_ALL} Error: [2CAPTCHA] api balance is {color.RED}ZERO{color.RESET_ALL}")
            quit()
        print(f"{color.RED}[-]{color.RESET_ALL} CAPTCHA API ERROR: {err}")
        return False

    else:
        print(f"{color.GREEN}[{count}] Captcha resolved successfully. {color.RESET_ALL}")
        #print(f"{str(result['code'])}")
        return str(result["code"])
Exemplo n.º 22
0
class TwoCaptchaRecaptchaV2Solver(BaseRecaptchaSolver):
    def __init__(self):
        config = {
            "apiKey": TWOCAPTCHA_API_KEY,
            "recaptchaTimeout": 120,
            "pollingInterval": 10,
        }
        self.solver = TwoCaptcha(**config)

    def solve(self, url, sitekey):
        captcha_response = self.solver.recaptcha(url=url, sitekey=sitekey)
        return captcha_response["code"]
Exemplo n.º 23
0
    async def make_login(self):
        log.info(msg="Spider captcha detected")
        two_captcha = TwoCaptcha(
            **{
                'apiKey': CAPTCHA['2CAPTCHA_API_KEY'],
                'defaultTimeout': 60,
                'recaptchaTimeout': 200,
                'pollingInterval': 7
            })
        captcha_handler = CaptchaHandler(captcha_resolver=two_captcha)
        log.info(
            msg=f"Solving captcha - {self.login_data['site_key_captcha']}")

        captcha_result = await captcha_handler.broker_captcha(
            site_key=self.login_data["site_key_captcha"],
            site_url=self.login_data['captcha_url'])
        log.info(msg=f"Captcha solved: {captcha_result}")
        self.login_params["captcha"] = captcha_result

        await self.login_password(self.login_data['init_url'])
        await self.authorize()
        await self.auth_login()
Exemplo n.º 24
0
from selenium import webdriver
from twocaptcha import TwoCaptcha
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys

opts = Options()
opts.headless = True  # True or False - Decide if you want a GUI for the browser
opts.add_argument(
    "user-agent=Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
)  # This user-agent makes sure you do not get banned from the website
browser = webdriver.Chrome(ChromeDriverManager().install(),
                           chrome_options=opts)
browser.minimize_window()
solver = TwoCaptcha('PUT API')  # 2captcha.com API key needs to be put here
TEXT = 'Put your text message over here'  # Message you want to send people
name = "dajkatal"  # Put the name you want on the site


def register():
    try:
        browser.get('http://www.chatiw.com?old=interface')
        time.sleep(5)
        browser.find_element_by_id('input1').send_keys(name)  # Set name
        browser.find_element_by_xpath(
            '//*[@id="age_list"]/option[2]').click()  # Set age to 18
        browser.find_element_by_xpath(
            '//*[@id="start_form"]/div[5]/div/input[2]').click()  # Set female
        browser.find_element_by_id('submit_btn').click()  # Submit
        time.sleep(5)
Exemplo n.º 25
0
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from twocaptcha import TwoCaptcha

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = TwoCaptcha(api_key)

try:
    result = solver.text('If tomorrow is Saturday, what day is today?')

except Exception as e:
    sys.exit(e)

else:
    print(result)
    sys.exit('solved: ' + str(result))
Exemplo n.º 26
0
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from twocaptcha import TwoCaptcha

# in this example we store the API key inside environment variables that can be set like:
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
# you can just set the API key directly to it's value like:
# api_key="1abc234de56fab7c89012d34e56fa7b8"

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = TwoCaptcha(api_key)

try:
    result = solver.normal('./images/normal.jpg')

except Exception as e:
    sys.exit(e)

else:
    sys.exit('result: ' + str(result))
Exemplo n.º 27
0
    ["Aranea", "Serket"],
    ["Horuss", "Zahhak"],
    ["Kurloz", "Makara"],
    ["Cronos", "Ampora"],
    ["Meenah", "Peixes"],
    ["Callie", "Ohpeee"],
    ["Lord", "English"],
    ["Doc", "Scratch"],
    ["Harryanderson", "Egbert"],
    ["Vriska", "Maryamlalonde"],
    ["Vrissy", "Maryamlalonde"],
    ["Tavros", "Crocker"],
    ["Yiffanylongstocking", "Lalondeharley"],
]

solver = TwoCaptcha(apiKey=apikey)

fake = Faker()
Faker.seed()

html2text = HTML2Text()
html2text.ignore_links = True


def contact(fake, solver, sitekey, url, story, html2text, testing=True):
    print("Getting key...")

    key = "[KEY]"
    if not testing:
        key_req = requests.post(
            "https://www.doitwithoutdues.com/api/form/FormSubmissionKey", data={}
Exemplo n.º 28
0
import sys
import os
from base64 import b64encode

sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from twocaptcha import TwoCaptcha

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = TwoCaptcha(api_key)

with open('./images/grid_2.jpg', 'rb') as f:
    b64 = b64encode(f.read()).decode('utf-8')

try:
    result = solver.grid(b64,
                         hintText='Select all images with an Orange',
                         rows=3,
                         cols=3)

except Exception as e:
    sys.exit(e)

else:
    sys.exit('solved: ' + str(result))
        # Password recovery pick
        wait.until(
            EC.element_to_be_clickable((
                By.XPATH,
                '/html/body/div/div/div[2]/div/main/div/div/div/form/div[3]/div/div[2]/div/div[1]/span'
            ))).click()

        recovery = wait.until(
            EC.element_to_be_clickable((
                By.XPATH,
                '/html/body/div/div/div[2]/div/main/div/div/div/form/div[3]/div/div[1]/div[2]/span/input'
            )))
        type_me(recovery, recoveryname)

        solver = TwoCaptcha(captcha_config.key)

        img = wait.until(
            EC.visibility_of_element_located(
                (By.CLASS_NAME, 'captcha__image')))
        src = img.get_attribute('src')
        img = requests.get(src)
        with open('captcha.jpg', 'wb') as f:
            f.write(img.content)

        try:
            result = solver.normal('captcha.jpg')  # change to your image path

            finalResult = str(result['code'])
            os.remove('captcha.jpg')
            sleep(1)
Exemplo n.º 30
0
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from twocaptcha import TwoCaptcha

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = TwoCaptcha(api_key, defaultTimeout=120, pollingInterval=5)

try:
    result = solver.canvas(
        './images/canvas.jpg',
        previousId=0,
        canSkip=0,
        lang='en',
        hintImg='./images/canvas_hint.jpg',
        hintText='Draw around apple',
        #    callback='http://127.0.0.1/test/'
    )

except Exception as e:
    sys.exit(e)

else:
    sys.exit('sent: ' + str(result))