daily pastebin goal
58%
SHARE
TWEET

Report Fags

Alexa84 Sep 3rd, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from splinter import Browser    # handles GUI browser emulations
  2. from random import randint      # generates random integers
  3. import time                     # handles time delays
  4. import threading                # handles multithread processing
  5. import random                   # handles random events & number generations
  6. import argparse                 # handles command line arguments
  7.  
  8.  
  9. # global variables
  10. botsFile = 'bots.txt'
  11. targetsFile = 'targets.txt'
  12. proxiesFile = 'proxies.txt'
  13. bots = []
  14. targets = {}
  15. proxies = {}
  16. numOfActiveThreads = 0
  17. numOfMaxThreads = 1
  18. numBotsAccessedSinceIPSwitch = 0
  19. isUsingHomeNetwork = False
  20. isUsingProxies = False
  21. numAccountsAttemptedToReport = 0
  22. numAccountsSuccessfullyReported = 0
  23.  
  24.  
  25.  
  26. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  27. #
  28. #         Preprocessing - acquire the set of proxies ( ip -> port )
  29. #
  30. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  31.  
  32. def importProxies():
  33.    
  34.     # open the file containing the bots' information
  35.    with open(proxiesFile, 'r') as pFile:
  36.        
  37.        # read in all the set of bot information until EOF
  38.        while True:
  39.            
  40.            # acquire the IP and Port into a list [IP, Port]
  41.            IPAndPort = pFile.readline().rstrip().split()
  42.            
  43.            # if EOF then break out
  44.            if len(IPAndPort) == 0:
  45.                break
  46.            
  47.            # if two entries were not extracted then skip
  48.            if len(IPAndPort) != 2:
  49.                print "not found"
  50.                continue
  51.        
  52.            # add the entry into the dictionary of proxies
  53.            proxies[IPAndPort[0]] = IPAndPort[1]
  54.  
  55.  
  56.  
  57.  
  58. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  59. #
  60. #         Preprocessing - acquire the bots' usernames, passwords, and emails
  61. #
  62. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  63.  
  64. def importBots():
  65.  
  66.     # open the file containing the bots' information
  67.    with open(botsFile, 'r') as bFile:
  68.        
  69.        # read in all the set of bot information until EOF
  70.        while True:
  71.            
  72.            # acquire the username of the bot
  73.            username = bFile.readline().rstrip()
  74.  
  75.            # if EOF then break out
  76.            if not username:
  77.                break
  78.            
  79.            # if it encounters a comment then skip ahead
  80.            if username[0] == '#':
  81.                continue
  82.            
  83.            # read in 3 lines at once (username, password, email)
  84.            # the username is already read above ^
  85.            password = bFile.readline().rstrip()
  86.            email = bFile.readline().rstrip()
  87.            
  88.            # if any of the fields are empty then break out of the while loop (EOF)
  89.            if (not username) or (not password) or (not email):
  90.                break
  91.            
  92.            # add the entry into the bot info list as a list
  93.            bots.append([username, password, email])
  94.  
  95.  
  96.  
  97. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  98. #
  99. #         Preprocessing - acquire the targets' profile URLs & tweet URLs to report
  100. #
  101. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  102.  
  103. def importTargets():
  104.    
  105.     # open the file containing the bots' information
  106.    with open(targetsFile, 'r') as tFile:
  107.        
  108.        # read in all the set of bot information until EOF
  109.        while True:
  110.            
  111.            # acquire the target URL
  112.            targetURL = tFile.readline().rstrip()
  113.            
  114.            # if EOF then break out
  115.            if not targetURL:
  116.                break
  117.            
  118.            # if it encounters a comment then skip ahead
  119.            if targetURL[0] == '#':
  120.                continue
  121.        
  122.            targets[targetURL] = []
  123.            
  124.            # loop through and get all tweet URLs that need to be reported that are associated with the current account
  125.            while True:
  126.                tweetURL = tFile.readline().rstrip()
  127.                
  128.                # if it encounters a comment then we are done acquiring all the tweet URLs
  129.                # break out
  130.                if tweetURL[0] == '#':
  131.                    break
  132.                
  133.                # add the tweet URL into the dictionary
  134.                targets[targetURL].append(tweetURL)
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  142. #
  143. #       Reports all targets
  144. #
  145. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  146.  
  147. # INPUT: bot username, password, & email
  148. # OUTPUT: boolean (true for success, false for error)
  149. def reportProfiles(username, password, email, proxySettings):
  150.    global numAccountsAttemptedToReport
  151.    global numAccountsSuccessfullyReported
  152.    
  153.  
  154.    # error handling for overall browser creation
  155.    try:
  156.  
  157.        # create a new instance of a graphical browser (firefox)
  158.        # automatically terminates the browser at the end of the code block
  159.        with Browser('firefox', profile_preferences= proxySettings) as browser:
  160.            
  161.            # maximize the window size
  162.            browser.driver.maximize_window()
  163.            
  164.            browser.visit("https://mobile.twitter.com/login")
  165.            
  166.            # if the login page was not loaded successfully then throw an error
  167.            if not "https://mobile.twitter.com/login" in browser.url:
  168.                print "Error: failed to load the login page."
  169.                return False
  170.                
  171.            # log into the account
  172.            browser.find_by_id('session[username_or_email]').fill(username)
  173.            browser.find_by_id('session[password]').fill(password)
  174.            browser.find_by_id('signupbutton').click()
  175.            
  176.  
  177.            # if the log in requires extra information then provide it
  178.            if "https://mobile.twitter.com/account/login_challenge" in browser.url:
  179.                print "Providing extra login information."
  180.                browser.fill("challenge_response", email)
  181.                browser.find_by_id("email_challenge_submit").click()
  182.  
  183.  
  184.            # if the log in failed, then through an error
  185.            if "https://twitter.com/login/error" in browser.url:
  186.                print "Error: the email and password combination is incorrect for user %s." % (username)
  187.                return False
  188.            
  189.            # if the account is locked
  190.            if browser.is_text_present("locked"):
  191.                print "Bot " + username + " has been locked. :["
  192.                return False
  193.            
  194.            
  195.            # keep track of the number of profiles attempted to report
  196.            numAccountsAttemptedToReport = numAccountsAttemptedToReport + len(targets)
  197.            
  198.            # navigate to the profile that needs reporting
  199.            for targetURL, tweetsURL in targets.iteritems():
  200.                
  201.                # error handling for individual reporting
  202.                try:
  203.                    # go to the profile to report
  204.                    browser.visit(targetURL)
  205.            
  206.                    # if the account is suspended, then move onto the next one.
  207.                    if "https://twitter.com/account/suspended" in browser.url:
  208.                        print "SUSPENDED: " + targetURL
  209.                        continue
  210.  
  211.                    # navigate to the full profile view
  212.                    browser.click_link_by_partial_text("full profile")
  213.                    
  214.                    # click the gear icon (user options) & then select the report tab
  215.                    if not browser.is_element_present_by_css('.user-dropdown'):
  216.                        print "User dropdown not found"
  217.                        continue
  218.                            
  219.                    browser.find_by_css('.user-dropdown').click()
  220.  
  221.  
  222.                    if not browser.is_element_present_by_css('li.report-text button[type="button"]'):
  223.                        print "Report option not found"
  224.                        continue
  225.            
  226.                    browser.find_by_css('li.report-text button[type="button"]').click()
  227.  
  228.  
  229.                    # navigate through the iframe that pops up while selecting the report options/types
  230.                    with browser.get_iframe('new-report-flow-frame') as iFrame:
  231.                        if iFrame.is_element_present_by_css("input[type='radio'][value='abuse']"):
  232.                            iFrame.find_by_css("input[type='radio'][value='abuse']").check()
  233.                        else:
  234.                            print "abuse radio not found"
  235.                            continue
  236.                    
  237.                    browser.find_by_css('.new-report-flow-next-button').click()
  238.                    with browser.get_iframe('new-report-flow-frame') as iFrame:
  239.                        if iFrame.is_element_present_by_css("input[type='radio'][value='harassment']"):
  240.                            iFrame.find_by_css("input[type='radio'][value='harassment']").check()
  241.                        else:
  242.                            print "harassment radio not found"
  243.                            continue
  244.                    
  245.                    browser.find_by_css('.new-report-flow-next-button').click()
  246.                    with browser.get_iframe('new-report-flow-frame') as iFrame:
  247.                        if iFrame.is_element_present_by_css("input[type='radio'][value='Someone_else']"):
  248.                            iFrame.find_by_css("input[type='radio'][value='Someone_else']").check()
  249.                        else:
  250.                            print "someone else radio not found"
  251.                            continue
  252.  
  253.                    browser.find_by_css('.new-report-flow-next-button').click()
  254.                    
  255.  
  256.                    # select one of the three harassment options at random
  257.                    harassmentReportOptions = [
  258.                                               'input[type="radio"][value="disrespectful_or_offensive"]',
  259.                                               'input[type="radio"][value="harassed"]',
  260.                                               'input[type="radio"][value="violence"]'
  261.                                               ]
  262.                    randomHarassmentReportOption = harassmentReportOptions[randint(0,2)]
  263.  
  264.                    # complete the reporting process with a random harassment option
  265.                    with browser.get_iframe('new-report-flow-frame') as iFrame:
  266.                        if iFrame.is_element_present_by_css(randomHarassmentReportOption):
  267.                            iFrame.find_by_css(randomHarassmentReportOption).check()
  268.                        else:
  269.                            print randomHarassmentReportOption + "radio not found"
  270.                            continue
  271.                                
  272.                    # finish the reporting process
  273.                    browser.find_by_css('.new-report-flow-next-button').click()
  274.                    numAccountsSuccessfullyReported = numAccountsSuccessfullyReported + 1
  275.  
  276.  
  277.                # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  278.                #    Report all tweets belonging to the current target
  279.                # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  280.    #            print tweetsURL
  281.    #            for tweetURL in tweetsURL:
  282.    #                browser.visit(tweetURL)
  283.    #                
  284.    #                with browser.get_iframe('tweet-post-iframe') as iFrame:
  285.    #                
  286.    #                    time.sleep(5)
  287.    #                #iFrame.find_by_name('ProfileTweet-actionButton').click()
  288.    #                    browser.find_by_css('.dropdown').find_by_css('.ProfileTweet-actionButton').click()
  289.    #
  290.    #                #iFrame.find_by_css('.dropdown.ProfileTweet-actionButton').click()
  291.    #                #browser.find_element_by_class_name('ProfileTweet-actionButton u-textUserColorHover dropdown-toggle js-dropdown-toggle').click()
  292.    #                
  293.    #                
  294.    #                
  295.    #                time.sleep(1000)
  296.    #                
  297.    #                # navigate through the iframe that pops up while selecting the report options/types
  298.    #                with browser.get_iframe('new-report-flow-frame') as iFrame:
  299.    #                    iFrame.find_by_css("input[type='radio'][value='abuse']").check()
  300.    #                browser.find_by_css('.new-report-flow-next-button').click()
  301.    #                with browser.get_iframe('new-report-flow-frame') as iFrame:
  302.    #                    iFrame.find_by_css("input[type='radio'][value='harassment']").check()
  303.    #                browser.find_by_css('.new-report-flow-next-button').click()
  304.    #                with browser.get_iframe('new-report-flow-frame') as iFrame:
  305.    #                    iFrame.find_by_css("input[type='radio'][value='Someone_else']").check()
  306.    #                browser.find_by_css('.new-report-flow-next-button').click()
  307.  
  308.                        
  309.                # this error will be thrown whenever there is an error in the browser emulation
  310.                # during the reporting process
  311.                except:
  312.                    #################################################################################### introduce a break here ?
  313.                    print "Error: something went wrong while reporting %s" % (targetURL)
  314.  
  315.        # success - the browser did not crash.. everything should have gone smoothly
  316.        return True
  317.  
  318.    except:
  319.        print "Error: something caused the browser to crash."
  320.        return False
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  329. #
  330. #        Describes the way a new thread is created & behaves
  331. #
  332. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  333.  
  334. class newThread (threading.Thread):
  335.    
  336.    def __init__(self, threadID, name, counter, username, password, email, proxySettings):
  337.        threading.Thread.__init__(self)
  338.        self.threadID = threadID
  339.        self.name = name
  340.        self.counter = counter
  341.        self.username = username
  342.        self.password = password
  343.        self.email = email
  344.        self.proxySettings = proxySettings
  345.    
  346.    def run(self):
  347.        global numOfActiveThreads
  348.        global numBotsAccessedSinceIPSwitch
  349.        
  350.        print "Starting " + self.name
  351.        numBotsAccessedSinceIPSwitch = numBotsAccessedSinceIPSwitch + 1
  352.        outcome = reportProfiles(self.username, self.password, self.email, self.proxySettings)
  353.        
  354.        # check if the bot had any issues with reporting the list of targets
  355.        if outcome == False:
  356.            print "Error: bot %s has some issues while reporting the targets." % (self.username)
  357.        else:
  358.            print "Bot %s successfully reported the targets." % (self.username)
  359.        
  360.        numOfActiveThreads = numOfActiveThreads - 1
  361.        print "Exiting " + self.name
  362.  
  363.  
  364.  
  365. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  366. #
  367. #        Handles the main execution & flow of the script
  368. #
  369. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  370.  
  371. def main():
  372.    global numOfActiveThreads
  373.    global numOfMaxThreads
  374.    global numBotsAccessedSinceIPSwitch
  375.    global isUsingProxies
  376.    global isUsingHomeNetwork
  377.  
  378.  
  379.    # parse the optional command line arguments
  380.    argumentParser = argparse.ArgumentParser()
  381.    argumentParser.add_argument("-t", help = "sets the maximum number of active threads at once.", type = int)
  382.    argumentParser.add_argument("-x", help = "enables the use of home network", action = "store_true")
  383.    argumentParser.add_argument("-p", help = "enables the use of proxies", action = "store_true")
  384.    optionalArgs = argumentParser.parse_args()
  385.    
  386.    
  387.    # if the optional flag -t was enabled then set the maximum number of active threads
  388.    if optionalArgs.t:
  389.        numOfMaxThreads = optionalArgs.t
  390.    
  391.    
  392.    # if the optional flag -h was enabled then enable special handling for home networks
  393.    # note: we are negating the value because we are storing the -h value as false when enabled (blame the library)
  394.    if optionalArgs.x:
  395.        isUsingHomeNetwork = optionalArgs.x
  396.  
  397.    
  398.    # if the optional flag -p was enabled then enable the use of proxies
  399.    if optionalArgs.p:
  400.        
  401.        importProxies()
  402.        isUsingProxies = True
  403.  
  404.        # check if any proxies were successfully imported
  405.        if len(proxies) < 1:
  406.            print "Error: No proxies found."
  407.            return False
  408.  
  409.  
  410.    # import the bots & targets
  411.    importBots()
  412.    importTargets()
  413.  
  414.  
  415.    # shuffle the list of bots (access them in random order)
  416.    random.shuffle(bots)
  417.  
  418.    # go through every bot entry & report all targets with each one
  419.    i = 0
  420.    for botInfo in bots:
  421.        
  422.        # extract the bot's information
  423.         username = botInfo[0]
  424.         password = botInfo[1]
  425.         email = botInfo[2]
  426.        
  427.        
  428.         # if the optional flag -p was enabled then set the proxy settings
  429.         if optionalArgs.p:
  430.            
  431.            
  432.             # get a random proxy (IP & Port) from the dictionary
  433.             IP = random.sample(proxies, 1)[0]
  434.             Port = int(proxies[IP])
  435.  
  436.            
  437.             # set the proxy settings
  438.             proxySettings = {
  439.                                 'network.proxy.type': 1,
  440.                                 'network.proxy.https': IP,
  441.                                 'network.proxy.https_port': Port,
  442.                                 'network.proxy.ssl': IP,
  443.                                 'network.proxy.ssl_port':Port,
  444.                                 'network.proxy.socks': IP,
  445.                                 'network.proxy.socks_port':Port,
  446.                                 'network.proxy.ftp': IP,
  447.                                 'network.proxy.ftp_port':Port
  448.                                 }
  449.         # otherwise set the proxy settings to nil.. you better make sure your VPN is enabled :-]
  450.         else:
  451.             proxySettings = None
  452.    
  453.    
  454.         # Attempt to prevent the overuse of the same IP if a home network is being used w/out proxies
  455.         # using the same IP can cause twitter to lock out accounts & require phone verifications
  456.         if not isUsingProxies and isUsingHomeNetwork and numBotsAccessedSinceIPSwitch >= 25:
  457.             print   (
  458.                      "\n*\n*\n*\n*\n*\n"
  459.                      + str(numAccountsSuccessfullyReported) + " out of " + str(numAccountsAttemptedToReport) + " accounts successfully reported.\n"
  460.                      + str(numBotsAccessedSinceIPSwitch)
  461.                      + " bots have been accessed since the last switch.\nPlease wait a few moments for the bots to finish up their actions.\nThen change your IP & hit ENTER to continue.\n*\n*\n*\n*\n*\n"
  462.                      )
  463.             raw_input()
  464.             numBotsAccessedSinceIPSwitch = 0
  465.    
  466.    
  467.         # start a new thread
  468.         thread = newThread( i, "Bot[#" + str(i) + "]", i, username, password, email, proxySettings)
  469.         thread.start()
  470.        
  471.         numOfActiveThreads = numOfActiveThreads + 1
  472.         i = i + 1
  473.  
  474.  
  475.         while numOfActiveThreads >= numOfMaxThreads:
  476.             print "number of active bots: {0}.. going to sleep for {1} seconds.".format(numOfActiveThreads, 30)
  477.             time.sleep(30)
  478.  
  479.  
  480.  
  481.  
  482. # execute the script
  483. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top