Advertisement
skip420

login.py

Sep 10th, 2018
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.83 KB | None | 0 0
  1. import requests
  2. import time
  3. import os
  4. import sys
  5. import glob
  6. import pickle
  7.  
  8.  
  9. registerUrl = 'http://epay.info/faucets/Bitcoin/'
  10. dashboardUrl = 'http://epay.info/faucets/Bitcoin/'
  11. claimUrl = 'http://5minbitcoin.com/index.php?cmd=claim'
  12. captchaUrl = 'http://www.google.com/recaptcha/api.js'
  13. payoutUrl = 'http://epay.info/withdrawal/'
  14. ProxyTestPayload = 'http://secure.gaug.es/track.js'
  15.  
  16. def Login(BitcoinAddress):
  17.     # Load the proxy list file
  18.     ProxyList = [line.rstrip('\n') for line in open(sys.argv[2])]
  19.  
  20.     # Debug
  21.     print 'Loaded main proxy list...'
  22.  
  23.     # Load filenames of all files in the directory that end with  *.proxy
  24.     P = glob.glob('./*.proxy*')
  25.  
  26.     # Load proxy server info from each of those files into a list
  27.     RegProxies = []
  28.     for x in range(len(P)):
  29.         f = open(P[x], 'r')
  30.         RegProxies.append(f.read())
  31.         f.close()
  32.  
  33.     # Find a proxy server from the Proxy list file which is not in the list of files ending with *.proxy
  34.     if(len(P) > 0):
  35.       Px = []
  36.       for x in range(len(P)):
  37.           for y in range(len(ProxyList)):
  38.               if(P[x] == ProxyList[y]):
  39.                 pass
  40.               else:
  41.                 # An unused proxy has been found - add it to a canidates list of proxies
  42.                 Px.append(ProxyList[y])
  43.  
  44.       # Searched through the entire list, just take the first unused proxy from the top of the list
  45.       Proxy = Px[0]
  46.  
  47.       # Debug line
  48.       print 'Selected non-used proxy from the proxy list'
  49.       print Proxy
  50.  
  51.       # Remove that proxy from the ProxyList array and rewrite the proxy file
  52.       ProxyList.remove(Px[0])
  53.  
  54.       f = open(sys.argv[2], 'w')
  55.       for x in range(len(ProxyList)):
  56.           f.write(ProxyList[x] + '\n')
  57.       f.close()
  58.  
  59.  
  60.     else:
  61.         # There are no proxy files in the directory, use the first proxy server from the Proxy List
  62.         Proxy = ProxyList[0]
  63.  
  64.         # Remove the Current Proxy from the List and rewrite the proxy list file
  65.         del ProxyList[0]
  66.  
  67.         f = open(sys.argv[2], 'w')
  68.         for x in range(len(ProxyList)):
  69.             f.write(ProxyList[x] + '\n')
  70.         f.close()
  71.  
  72.  
  73.     # Test the proxy server to see if it's usable
  74.     if(CheckProxy(Proxy, ProxyTestPayload) == 'down'):
  75.        # The proxy is down remove that Proxy address from the Proxy list file
  76.  
  77.        # Debug line
  78.        print 'Current proxy is down ... trying the next one'
  79.  
  80.        # Proxy check failed - exit to release a file-lock so other instances can access the proxy list file
  81.        return
  82.  
  83.     else:
  84.        # Change the proxy format string to something directly useable with requests instead of the ProxyCheck function
  85.        SimpleProxyFormat = Proxy
  86.        Proxy = {'http': 'http://' + Proxy,}
  87.        print 'using proxy: ' + str(Proxy)
  88.  
  89.        # First Request is to get cookies from the Index page
  90.        s = requests.session()
  91.  
  92.        print 'getting initial cookies...'
  93.  
  94.        try:
  95.            s.get(dashboardUrl, headers=s.headers.update({'User-Agent': randomUA()}), proxies=Proxy, timeout=30)
  96.            if(CheckIdiotProxyResponse == 'idiot'):
  97.              # Can't even get initial cookies - unstable proxy - find another one
  98.              return
  99.  
  100.        except:
  101.              # Can't connect - find another proxy
  102.              return
  103.  
  104.        try:
  105.            print 'registering bitcoin wallet address...'
  106.            # Submit the Bitcoin Address to login
  107.            s.post(registerUrl, data = {'bitcoin': BitcoinAddress}, headers=s.headers.update({'User-Agent': randomUA()}), proxies=Proxy, timeout=30)
  108.  
  109.            if(CheckIdiotProxyResponse == 'idiot'):
  110.              # Got an idiot response - try another proxy
  111.              return
  112.  
  113.        except:
  114.               # Connection error - try another proxy
  115.               return
  116.  
  117.        print 'getting captcha image'
  118.        # Get the Claim Page to update any cookies
  119.        try:
  120.            s.get(claimUrl, headers=s.headers.update({'User-Agent': randomUA()}), proxies=Proxy, timeout=30)
  121.            Captcha = s.get(captchaUrl)
  122.            imageData = Captcha.content
  123.  
  124.            print 'saving captcha image...'
  125.            # Write the Captcha image to the disk
  126.            f = open('Captcha_' + BitcoinAddress + '.jpg', 'w')
  127.            f.write(imageData)
  128.            f.close()
  129.  
  130.            # Check the File's MIME data to see if we actually got JPG image
  131.  
  132.            m = magic.open(magic.MAGIC_MIME)
  133.            m.load()
  134.            MIMEtype = m.file('Captcha_' + BitcoinAddress + '.jpg')
  135.            if(MIMEtype.find('text/html') > -1):
  136.              # it's not an image - probably another proxy died in someway
  137.              print 'proxy returned non JPG data'
  138.              return
  139.  
  140.        except:
  141.              # couldn't get the Captcha image - just exit
  142.              return
  143.  
  144.        # Generate the webcontent to solve the captcha
  145.        #f = open(BitcoinAddress + '.htm', 'w')
  146.        #t = open('CaptchaInputTemplate.html', 'r')
  147.        #template = t.read()
  148.        #t.close()
  149.        #HTMLdata = template.replace('THISBITCOINADDRESS', BitcoinAddress)
  150.  
  151.        #f.write(HTMLdata)
  152.        #f.close()
  153.  
  154.        # Save Proxy address
  155.        print 'Saveing Proxy info'
  156.        f = open(BitcoinAddress + '.proxy', 'w')
  157.        f.write(SimpleProxyFormat)
  158.        f.close()
  159.  
  160.        print 'Saving HTTP header'
  161.        # Save session headers
  162.        f = open(BitcoinAddress + '.headers', 'w')
  163.        f.write(str(s.headers))
  164.        f.close()
  165.  
  166.        print 'Saving Cookies'
  167.        save_cookies(s.cookies, BitcoinAddress + '.cookie')
  168.  
  169. def CheckProxy(server, testLink):
  170.     try:
  171.        # Download the test file without a proxy
  172.        t = requests.get(ProxyTestPayload)
  173.        source = t.content
  174.  
  175.        ProxyServer = {'http': 'http://' + server,}
  176.        r = requests.get(testLink, proxies=ProxyServer, timeout=5)
  177.        test = r.content
  178.  
  179.        if(source == test):
  180.          return 'up'
  181.        else:
  182.          # it's up but it's down... get it? hahaah - probably just got a proxy Error page
  183.          return 'down'
  184.  
  185.     except:
  186.        return 'down'
  187.  
  188. def save_cookies(requests_cookiejar, filename):
  189.     with open(filename, 'wb') as f:
  190.         pickle.dump(requests_cookiejar, f)
  191.  
  192. def randomUA():
  193.     UserAgents = ['Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0']
  194.     return UserAgents[0]
  195.  
  196. def CheckIdiotProxyResponse(responseData):
  197.     Rejected = ['Attention Required!', 'Access Denied', 'No DNS records', 'DNS resolving failed', 'ERROR', 'Privoxy']
  198.     for y in range(len(Rejected) -1):
  199.         if(responseData.find(Rejected[y]) > -1):
  200.           # The proxy is rejecting the request - better try a new one
  201.           return 'idiot'
  202.  
  203. # If the proxy file exists, don't try to login with another proxy
  204. try:
  205.    f = open(sys.argv[1] + '.proxy', 'r')
  206.    f.close()
  207. except:
  208.    # File error -  yea, it doesn't exist
  209.    Login(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement