My Journey To Learn Python / Selenium & Create Powerful IM Bots

THREAD UPDATE

I decided it's best to switch over from Anti-Captcha to '2Captcha' service for now.

Today I learned A LOT about APIs and how to communicate with them.


How to install Python libraries:


2Captcha Python API Script: https://github.com/2captcha/2captcha-api-examples/blob/master/ReCaptcha v2 API Examples/Python Example/2captcha_python_api_example.py

^ Here's the script I'm playing around with at the moment.

I can't get it to work in Python yet, but I'll figure it out soon.

Postman API Tool: https://www.getpostman.com/

I've been using this API tool called Postman to play around with POST and GET.. and it seems I got it to work with 2Captcha!

szVO-tErT7KXu-0OYbcxCQ.png


Q8Bn6vQaQqG4rRCmuo4V1A.png


How To Find Google Captcha ID:

Each site that uses Recaptcha2 will have a unique Google 'captcha ID'.. if it doesn't appear in the source code the website is hiding it. To find it use Chrome inspect tool.. this image explains the process:

wJEndziMQVOPkDONaPSJZg.png


When you click Network and Preserve Log then refresh the page, it will give you a list of a whole bunch of scripts, and code and junk. Look for "anchor?k=" that following string is the code you want.

I should hopefully have this up and running in Python tomorrow.
 
Last edited:
Interesting journey mate, following. I agree python has a really nice syntax to get used to.
Do you plan to make money selling the bots or using them yourself?

I'll be using the bots myself to generate traffic.
 
So, how much it's easy for beginners to learn coding? Your advises are appreciated.
 
Hi, @apex1
Nice journey, keep it up! I think You should try to integrate Katalon Studio into your py+selenium setup, it should speed up alot of your workflow. Good luck you are motvating a lot of users to dig into programming ;)
Cheers,
Q
 
So, how much it's easy for beginners to learn coding? Your advises are appreciated.
If you only focus on a particular project like making bot it can takes months, but learning general programming on multiple environments web, server, etc. can take year. Of course It really depends on the time you can spend on the learning.
 
So, how much it's easy for beginners to learn coding? Your advises are appreciated.
If you only focus on a particular project like making bot it can takes months, but learning general programming on multiple environments web, server, etc. can take year. Of course It really depends on the time you can spend on the learning.
I think some of it too depends on what exactly you mean by "learning." If you mean an intuitive, in depth understanding of the language(s) I think you're in for a long haul. If you mean enough understanding of the concepts to be able to cobble together something useful while leaning on references and tutorials for syntax and structure, then that can be a fairly quick process (as @starbucksLover said depending on the time you can spend on learning.) I am pretty much a novice at this, but can still manage to write a functional website and small programs.
 
If you only focus on a particular project like making bot it can takes months, but learning general programming on multiple environments web, server, etc. can take year. Of course It really depends on the time you can spend on the learning.

months? years? its programming not flying bro . from my experience you can get familiar with the syntax of a particular language in about 2 weeks . how fast you learn depends on how much you practice , after not long you will end up with the most boring skill in the world .:)
 
months? years? its programming not flying bro . from my experience you can get familiar with the syntax of a particular language in about 2 weeks . how fast you learn depends on how much you practice , after not long you will end up with the most boring skill in the world .:)

I wouldn't say it's the most boring skill. You would have the skill of creating something out of nothing and then putting your creation to work so it could make money for you passively - I'd say it's pretty cool.
 
What? I thought selenium only had a driver for firefox, chrome, ssafari, opera and phantom?

http://www.seleniumhq.org/about/platforms.jsp

You're saying it uses chromium too?

Chromium is Chrome, you just need a bit tweaking for it to work:

Code:
https://stackoverflow.com/questions/24999318/selenium-use-chromium-instead-of-google-chrome
 
THREAD UPDATE:

The anti-captcha solution appears to be working now. I removed the proxy section of the script temporarily.

SkyRock Web 2.0 isn't the easiest target, they've used some tricks to harden their defenses against automated account creation. I wasn't able to fully create an account yet. The anti-captcha gets a solution code and tries to post it but nothing happens. I think SkyRock has the captcha loaded in an iframe, or through some kind of javascript so I can't post to it as easily.

Anyways, SkyRock isn't important.. I'm probably going to move on and start working on other target sites.

My next main priority is EMAIL ACCOUNT VERIFICATION.

I need to automate the clicking of the account validation link in the email. I'm thinking of maybe doing it through outlook or gmail accounts. Any suggestions?

Here's the updated code:

Code:
#IMPORT
from selenium import webdriver
driver = webdriver.Chrome("C:\\Program Files (X86)\\Google\\chromedriver.exe")
from time import sleep
import requests

#SET VARIABLES
username = "c_apex123"
password = "zz123;123Zzz"
email = "[email protected]"

#NAVIGATE
driver.get("https://skyrock.com/subscribe/")
driver.maximize_window()
sleep(2)

#FILL OUT FIELDS
driver.find_element_by_id("pseudo").send_keys(username)
driver.find_element_by_id("password").send_keys(password)
driver.find_element_by_id("email").send_keys(email)

#DROP DOWN SELECTION
driver.find_element_by_xpath("//select[@id='birthday']/option[@value='15']").click()
driver.find_element_by_xpath("//select[@id='birthmonth']/option[@value='1']").click()
driver.find_element_by_xpath("//select[@id='birthyear']/option[@value='1975']").click()

#CLICK RADIO BUTTON
driver.find_element_by_xpath("//INPUT[@id='sexe-man']").click()
sleep(3)

#CLICK SUBMIT BUTTON
driver.find_element_by_name("accept").click()

#ANTI CAPTCHA FUNCTIONALITY

API_KEY = 's8d97g87hdf9e8r9w97ds9f9s8g'  # Your 2captcha API KEY
site_key = '6LcTyP4SAAAAADBjv0TABENKwCOGOFe5H15-hd_4'  # site-key, read the 2captcha docs on how to get this
url = 'https://skyrock.com/subscribe/show/1/'  # example url

s = requests.Session()

# here we post site key to 2captcha to get captcha ID (and we parse it here too)
captcha_id = s.post("http://2captcha.com/in.php?key={}&method=userrecaptcha&googlekey={}&pageurl={}".format(API_KEY, site_key, url)).text.split('|')[1]
# then we parse gresponse from 2captcha response
recaptcha_answer = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY, captcha_id)).text
print("solving ref captcha...")
while 'CAPCHA_NOT_READY' in recaptcha_answer:
    sleep(5)
    recaptcha_answer = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY, captcha_id)).text
recaptcha_answer = recaptcha_answer.split('|')[1]

# we make the payload for the post data here, use something like mitmproxy or fiddler to see what is needed
payload = {
    'key': 'value',
    'gresponse': recaptcha_answer  # This is the response from 2captcha, which is needed for the post request to go through.
    }

# then send the post request to the url
response = s.post(url, payload)

# And that's all there is to it other than scraping data from the website, which is dynamic for every website.
sleep(30)

#END PROGRAM
driver.close()
 
So, how much it's easy for beginners to learn coding? Your advises are appreciated.

Depends a lot on your commitment and ability to learn new concepts. Programming is potentially one of the most difficult things you can learn to do IMO.

Hi, @apex1
Nice journey, keep it up! I think You should try to integrate Katalon Studio into your py+selenium setup, it should speed up alot of your workflow. Good luck you are motvating a lot of users to dig into programming ;)
Cheers,
Q

Thanks for the tip about Katalon Studio, it looks very interesting.

I'm going to do some more research on it in the coming days!

Btw I forgot to mention in the thread update above I should be working on learning Python 3-4 hours a day for the next week.
 
THREAD UPDATE:

The anti-captcha solution appears to be working now. I removed the proxy section of the script temporarily.

SkyRock Web 2.0 isn't the easiest target, they've used some tricks to harden their defenses against automated account creation. I wasn't able to fully create an account yet. The anti-captcha gets a solution code and tries to post it but nothing happens. I think SkyRock has the captcha loaded in an iframe, or through some kind of javascript so I can't post to it as easily.

Anyways, SkyRock isn't important.. I'm probably going to move on and start working on other target sites.

My next main priority is EMAIL ACCOUNT VERIFICATION.

I need to automate the clicking of the account validation link in the email. I'm thinking of maybe doing it through outlook or gmail accounts. Any suggestions?

Here's the updated code:

Code:
#IMPORT
from selenium import webdriver
driver = webdriver.Chrome("C:\\Program Files (X86)\\Google\\chromedriver.exe")
from time import sleep
import requests

#SET VARIABLES
username = "c_apex123"
password = "zz123;123Zzz"
email = "[email protected]"

#NAVIGATE
driver.get("https://skyrock.com/subscribe/")
driver.maximize_window()
sleep(2)

#FILL OUT FIELDS
driver.find_element_by_id("pseudo").send_keys(username)
driver.find_element_by_id("password").send_keys(password)
driver.find_element_by_id("email").send_keys(email)

#DROP DOWN SELECTION
driver.find_element_by_xpath("//select[@id='birthday']/option[@value='15']").click()
driver.find_element_by_xpath("//select[@id='birthmonth']/option[@value='1']").click()
driver.find_element_by_xpath("//select[@id='birthyear']/option[@value='1975']").click()

#CLICK RADIO BUTTON
driver.find_element_by_xpath("//INPUT[@id='sexe-man']").click()
sleep(3)

#CLICK SUBMIT BUTTON
driver.find_element_by_name("accept").click()

#ANTI CAPTCHA FUNCTIONALITY

API_KEY = 's8d97g87hdf9e8r9w97ds9f9s8g'  # Your 2captcha API KEY
site_key = '6LcTyP4SAAAAADBjv0TABENKwCOGOFe5H15-hd_4'  # site-key, read the 2captcha docs on how to get this
url = 'https://skyrock.com/subscribe/show/1/'  # example url

s = requests.Session()

# here we post site key to 2captcha to get captcha ID (and we parse it here too)
captcha_id = s.post("http://2captcha.com/in.php?key={}&method=userrecaptcha&googlekey={}&pageurl={}".format(API_KEY, site_key, url)).text.split('|')[1]
# then we parse gresponse from 2captcha response
recaptcha_answer = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY, captcha_id)).text
print("solving ref captcha...")
while 'CAPCHA_NOT_READY' in recaptcha_answer:
    sleep(5)
    recaptcha_answer = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY, captcha_id)).text
recaptcha_answer = recaptcha_answer.split('|')[1]

# we make the payload for the post data here, use something like mitmproxy or fiddler to see what is needed
payload = {
    'key': 'value',
    'gresponse': recaptcha_answer  # This is the response from 2captcha, which is needed for the post request to go through.
    }

# then send the post request to the url
response = s.post(url, payload)

# And that's all there is to it other than scraping data from the website, which is dynamic for every website.
sleep(30)

#END PROGRAM
driver.close()

Code:
import imaplib
import verifier

from time import sleep

verificationUrls = []
mails = [
    ['[email protected]', 'PASSWORD'],
]

for email in mails:
    email, password = email
    mail = imaplib.IMAP4_SSL('imap.gmail.com',993)
    print('Attempting: {0}'.format(email))
    try:
        mail.login(email, password)
        print('Valid: {0}'.format(email))
    except Exception as e:
        print(e)
        #print('Invalid: {0}:{1}'.format(email, password))
        continue
    mail.list()
    mail.select("inbox")

    result, data = mail.uid('search', None, '(HEADER Subject "[reddit] reset your password")')
    iterData = data[0].decode('utf-8').split(' ')
    r, d = mail.uid('fetch', ','.join(iterData), '(RFC822)')

    for b in d:
        try:
            b = b[1].decode('utf-8')
        except:
            continue

        first = str(b).split('https://www.reddit.com/resetpassword/')[1].split('?')[0]
        second = str(b).split('A password reset has been requested for the reddit username: ')[1].split('\r\n')[0]
        verificationUrls.append([first, second])
   
    #mail.uid('STORE', ','.join(iterData) , '+FLAGS', '(\Deleted)')  
    #mail.expunge()

    print('Parsed: {0}'.format(email))

print('[+] Got {0} verification URLs'.format(len(verificationUrls)))

emailVerifier = verifier.main(verificationUrls)

This is a Reddit module I have ( only handles one email:pass at the moment but I'm sure you get the idea)

verifier.py
Code:
import asyncio
import aiohttp
import string
import random

async def verify(token, auth):

    password = 'k' + ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(8))

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0',
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Language': 'en-US,en;q=0.5',
        'Accept-Encoding': 'gzip, deflate, br',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'X-Requested-With': 'XMLHttpRequest',
        'Referer': 'https://www.reddit.com/',
        'Connection': 'keep-alive',
    }
    async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False), headers=headers) as session:
        async with session.post('https://www.reddit.com/api/resetpassword', data={ 'key': token, 'passwd': password, 'passwd2': password, 'id': '#chpass', 'renderstyle': 'html'}) as request:
            resp = await request.read()
            resp = resp.decode('utf-8')
            if 'password updated' in resp:
                print('[+] Verified Correctly, password is now {0} for {1}'.format(password, auth))
                print('{0}:{1}'.format(auth, password), file=open('new_accounts.txt', 'a'))
            else:
                print('[+] Failed setting {0} to {1}'.format(password, auth))

async def goGo(ids, tasks=[]):
    for token, auth in ids:
        if len(tasks) >= 150:
            await asyncio.gather(*tasks)
            tasks = []
        tasks.append(asyncio.ensure_future(verify(token, auth)))

    await asyncio.gather(*tasks)

def main(ids):
    loop = asyncio.new_event_loop()
    loop.run_until_complete(goGo(ids))

This code is stupidly fast but not using selenium as you'd want.
 
@MaxiPads123 awesome, thanks a bunch for that code! Much appreciated! I'll try to reverse-engineer it and learn from it.
 
I'll try to follow this journey and tag along maybe I'll learn a couple of things myself :D
 
@MaxiPads123 awesome, thanks a bunch for that code! Much appreciated! I'll try to reverse-engineer it and learn from it.

No problem! From what I remember the first code is the program you ran where the second snippet was a seperate file (see import verifier)
 
the module you are importing 'verifier' goes to the link to be verified and sets a new password its does not save the password at all ,it just prints it , the script signs in to gmail and searches for a mail with '[reddit] reset your password' as the subject opens the mail and gets the link and verifier does the rest .


you could use mechanize or requests they are a whole lot better and easier than aiohttp!
 
Back
Top