Advertisement
Guest User

Fbreport

a guest
Oct 17th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.91 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #-*- coding: utf-8 -*-
  3. #
  4. # Name: FacebookReport (v.0.1.0)
  5. # About: The script is an adaptation for Facebook of the TwitterReport.
  6. #    It accepts targets as a full url (e.g., https://facebook.com/username or https://facebook.com/profile.php?id=idNumber), a username or an idNumber
  7. #
  8. # Requirements:
  9. # - Python 2.7
  10. # - Python Requests Module (http://stackoverflow.com/questions/17309288/importerror-no-module-named-requests)
  11. # - Splinter (http://splinter.readthedocs.org/en/latest/install.html)
  12. #
  13. # Usage:  python FBReport.py -u YOUR_USER_NAME
  14. #
  15. # Linux/Unix:
  16. # - Linux Pip install instructions: http://pip.readthedocs.org/en/stable/installing/
  17. # - Requests module instructions: http://stackoverflow.com/questions/17309288/importerror-no-module-named-requests
  18. # - Splinter module instructions : http://splinter.readthedocs.org/en/latest/install.html
  19. #
  20. # Windows:
  21. # - Make sure pip is installed: http://pip.readthedocs.org/en/stable/installing/
  22. # - Open up cmd and run c:\python27\scripts\easy_install.exe request
  23. # - Get the zip : https://github.com/cobrateam/splinter/archive/master.zip unzip on your disk,
  24. # open a terminal (start menu -> type cmd -> launch cmd.exe)
  25. # go in the folder you unzip splinter (cd XXXX) launch 'python setup.py install'
  26. # - You may also need to open up cmd and run the following command: c:\python27\scripts\easy_install.exe request
  27. # if the requests module is not installed
  28. #
  29. # Need Help or Find a Bug?
  30. # - /join #OpParis - https://webchat.anonops.com/?channels=OpParis
  31. # Want to contribute?
  32. # - /join #OpParis-Dev - https://webchat.anonops.com/?channels=OpParis-Dev
  33.  
  34.  
  35. # TODO:
  36. # - define a server-side function to retrieve the next target
  37. # - detect exception conditions
  38. # - improve performances
  39. # - testing
  40.  
  41. import sys
  42. try:
  43.     from splinter import Browser
  44. except:
  45.     print "Please install Splinter."
  46.     print "* Unix/Linux Use: sudo pip install splinter"
  47.     print "* Windows: See script's comments"
  48.     print "* More Info: http://splinter.readthedocs.org/en/latest/install.html"
  49.     sys.exit()
  50. try:
  51.     import requests
  52. except:
  53.     print "Please install the requests module."
  54.     print "* Unix/Linux Use: pip install requests"
  55.     print "* Windows in CMD: c:\python27\scripts\easy_install.exe request"
  56.     print "* More Info: http://stackoverflow.com/questions/17309288/importerror-no-module-named-requests"
  57.     sys.exit()
  58.    
  59. import getopt, re, time
  60. from splinter.request_handler.status_code import HttpResponseError
  61. import getpass
  62.  
  63. # TODO Bot Variables
  64. #o="opparis"
  65. #op_srv="optools.anonops.com"
  66.  
  67. # TODO: Notifies target is offline
  68. # def updateTarget(o,t)
  69.  
  70. def main(argv):
  71.  
  72.     username = None
  73.     try:
  74.         opts, args = getopt.getopt(argv,"h:u:",["user="])
  75.     except getopt.GetoptError:
  76.         print 'Usage: python FBReport.py -u <Facebook username>'
  77.         sys.exit(2)
  78.  
  79.     for opt, arg in opts:
  80.         if opt == '-h':
  81.             print 'Usage: python FBReport.py -u <Facebook username>'
  82.             sys.exit()
  83.         elif opt in ("-u", "--user"):
  84.             username = arg
  85.             n = username
  86.  
  87.     if not username:
  88.         print 'Usage: python FBReport.py -u <Facebook username>'
  89.         sys.exit()
  90.  
  91.     password = getpass.getpass()
  92.  
  93. # comment this line if you want to use privoxy + tor:
  94.     with Browser() as browser:
  95. # uncomment this section if you want to use privoxy + tor:
  96. #    proxyIP = '127.0.0.1'
  97. #    proxyPort = 8118
  98. #
  99. #    proxy_settings = {'network.proxy.type': 1,
  100. #            'network.proxy.http': proxyIP,
  101. #            'network.proxy.http_port': proxyPort,
  102. #            'network.proxy.ssl': proxyIP,
  103. #            'network.proxy.ssl_port':proxyPort,
  104. #            'network.proxy.socks': proxyIP,
  105. #            'network.proxy.socks_port':proxyPort,
  106. #            'network.proxy.ftp': proxyIP,
  107. #            'network.proxy.ftp_port':proxyPort
  108. #            }
  109. #
  110. #    with Browser('firefox',profile_preferences=proxy_settings) as browser:
  111.         try:
  112.         #Login
  113.             browser.visit("https://facebook.com/login.php")
  114.             time.sleep(1)
  115.             browser.execute_script('document.getElementById("email").value="'+username+'"')
  116.             browser.execute_script('document.getElementById("pass").value="'+password+'"')
  117.             browser.find_by_name("login").first.click()
  118.             #time.sleep(1)
  119.  
  120.             if "https://www.facebook.com/login.php?login_attempt=" in browser.url:
  121.                 print "Facebook Login Failed!"
  122.                 sys.exit()
  123.  
  124.         except Exception, e:
  125.         print e
  126.             print "Unexpected error occured while trying the Facebook login. Please try running the script again."
  127.             sys.exit()
  128.  
  129.         while True:
  130.             try:
  131.                 #TODO Get target from target queue
  132.                 #t = requests.get(SERVICE URL)
  133.                 #tg = t.content
  134.                 if tg == "" or tg == "noassignment" or ("error" in tg) or ("What happened?" in tg) or ("CloudFlare" in tg) or ("Cloudflare" in tg) or ("Checking your browser" in tg):
  135.                     print "No current assignment"
  136.                     time.sleep(3)
  137.                 else:
  138.             #Prepare the user URL
  139.             if ("facebook.com" in tg):
  140.                 url=tg
  141.             else:
  142.                 url="https://facebook.com/"+tg
  143.  
  144.             browser.visit(url)
  145.             time.sleep(1)
  146.             msg=""
  147.                     if not browser.is_element_present_by_id('standard_error'):
  148.                         browser.execute_script('document.getElementsByClassName("_42ft _4jy0 _1yzl _p _4jy4 _517h _51sy")[0].click()')
  149.             time.sleep(1)
  150.  
  151.             browser.click_link_by_partial_href('/ajax/nfx/start_dialog?story_location=profile_someone_else&reportable_ent_token')
  152.             time.sleep(1)
  153.  
  154.             browser.find_by_name('answer')[1].click()
  155.             browser.execute_script('document.getElementsByClassName("_42ft _4jy0 layerConfirm _5xcs _5ipw uiOverlayButton _4jy3 _4jy1 selected _51sy")[0].click()')
  156.             time.sleep(1)          
  157.  
  158.             browser.find_by_name('answer')[2].click()
  159.             browser.execute_script('document.getElementsByClassName("_42ft _4jy0 layerConfirm _5xcs _5ipw uiOverlayButton _4jy3 _4jy1 selected _51sy")[0].click()')
  160.             time.sleep(1)
  161.  
  162.             browser.find_by_name('answer')[2].click()
  163.             browser.execute_script('document.getElementsByClassName("_42ft _4jy0 layerConfirm _5xcs _5ipw uiOverlayButton _4jy3 _4jy1 selected _51sy")[0].click()')
  164.             time.sleep(1)
  165.  
  166.             #Check if already reported,
  167.             if(len(browser.find_by_css("div._5dg3"))>0):
  168.                 msg = tg+'- Already reported'          
  169.             #Report!
  170.             elif(len(browser.find_by_css('a._16gh[ajaxify^="/ajax/feed/filter_action/nfx_action_execute?action_name=REPORT_CONTENT"]'))>0):        
  171.                 browser.execute_script('document.getElementsByClassName("_16gh")[0].click()')
  172.                 time.sleep(1)
  173.                 msg = tg+' - Reported'
  174.  
  175.                     elif browser.is_element_present_by_css('DETECT IF IT IS SUSPENDED'):
  176.                         msg =  tg+' - Suspended'
  177.                         #updatetarget(o,tg)
  178.                     elif browser.is_element_present_by_id('standard_error'):
  179.                         msg =  tg+' - Does not exist'
  180.                         #updatetarget(o,tg)
  181.                     else:
  182.                         msg = tg+' - Unknown'
  183.                         #updatetarget(o,tg)
  184.  
  185.                     print msg
  186.             except KeyboardInterrupt:
  187.                 print 'Quit by keyboard interrupt sequence!'
  188.                 break
  189.             except HttpResponseError, e:
  190.                 msg = 'HttpResponseError'
  191.                 print msg
  192.                 with open("log_Error.txt", "a") as log:
  193.                     log.write(msg+"\n")
  194.             except Exception, e:
  195.                 msg = 'CatchAllError'
  196.                 print msg
  197.         print e
  198.                 with open("log_Error.txt", "a") as log:
  199.                     log.write(msg+"\n")
  200.  
  201. if __name__ == "__main__":
  202.     try:
  203.         main(sys.argv[1:])
  204.     except KeyboardInterrupt:
  205.         sys.stdout.write('\nQuit by keyboard interrupt sequence!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement