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