diff --git a/facebook/__main__.py b/facebook/__main__.py index e1faa43..6904fdd 100644 --- a/facebook/__main__.py +++ b/facebook/__main__.py @@ -18,7 +18,7 @@ if __name__ == "__main__": url_other_pictures = [] # Fylls eventuellt på test = False write = True - mode = 'all' + mode = 'few' pwd = None proxieservers = 'mullvad' container = 'container' # Todo ska den här bort? @@ -107,6 +107,7 @@ if __name__ == "__main__": print('Write:', write) # Hämta en användare att kolla upp + print('userdoc[_key]', userdoc['_key']) user = User(str(userdoc['_key']).strip(), mode, other_pictures=url_other_pictures) if "url_other_pictures" in globals(): @@ -126,9 +127,12 @@ if __name__ == "__main__": if lookups == "leak_lookups": id = user.username - check_profile_status(profile, user) - if profile.blocked: - profile = blocked_profile(profile, proxieservers=proxieservers) + while True: + check_profile_status(profile, user) + if profile.blocked: + profile = blocked_profile(profile, proxieservers=proxieservers) + else: + break profile.open(url_bas + "/" + user.username) url = profile.browser.state.url.strip("/").strip("?_rdr") if "php?" not in url: @@ -145,6 +149,7 @@ if __name__ == "__main__": profile.users_checked += 1 # Hämta reaktioner för den första användaren + print(user.username) if any([not check_for_user(user.username, mode=mode), mode == "force"]): try: while True: diff --git a/facebook/arangodb.py b/facebook/arangodb.py index e1fa92a..77d6735 100644 --- a/facebook/arangodb.py +++ b/facebook/arangodb.py @@ -9,30 +9,38 @@ from arango import ArangoClient from config import * +if __name__ == '__main__.py': + for i in range(0, 6, 1): + if i == 5: + exit() + try: + # Om scriptet körs på Macbook finns lösenordet i en fil + with open("../password_arango.txt") as f: + pwd = f.readline() + except FileNotFoundError: + if 'pwd' not in globals(): + pwd = getpass(f'Lösenord för {user_arango}: ') -for i in range(0, 6, 1): - if i == 5: - exit() - try: - # Om scriptet körs på Macbook finns lösenordet i en fil - with open("../password_arango.txt") as f: - pwd = f.readline() - except FileNotFoundError: - if 'pwd' not in globals(): - pwd = getpass(f'Lösenord för {user_arango}: ') - - try: - db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd) - db.collection('members').random() # För att testa löseordet/kopplingen. - break - except: - print("Fel lösenord.") - sleep(1) + try: + db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd) + db.collection('members').random() # För att testa löseordet/kopplingen. + break + except: + print("Fel lösenord.") + sleep(1) +else: + db = None # Om db importeras separat. from helpers import now, _print, nowstamp, sleep_ from classes import Profile +def arango_connect(pwd, username='Lasse', db_arango = 'facebook', host_arango='http://192.168.1.20', port_arango='8529'): + return ArangoClient(hosts=f'{host_arango}:{port_arango}').db( + db_arango, username=username, password=pwd, + ) + + def checked_members(): cursor = db.aql.execute( """ @@ -78,6 +86,7 @@ def report_blocked(profile): def get_profile(db=db, collection='mullvad'): """ Hämtar profil från profiles """ + collection = f'profiles_{collection}' while True: cursor = db.aql.execute( @@ -86,7 +95,7 @@ def get_profile(db=db, collection='mullvad'): FILTER doc.in_use < @inuse RETURN doc """, - bind_vars={"inuse": nowstamp() - 1200, '@col': f'profiles_{collection}'} + bind_vars={"inuse": nowstamp() - 1200, '@col': collection} ) profiles = [profile for profile in cursor] @@ -114,7 +123,9 @@ def remove_profile(profile, proxieservers='mullvad'): """ Tar bort en blockerad profil från databasen. """ _print(profile, None, f"Tar bort {profile.name}.") - db.collection(f'profiles_{proxieservers}').delete( + collection = f'profiles_{proxieservers}' + + db.collection(collection).delete( profile.doc["_key"], silent=True, ignore_missing=True ) _print(profile, profile.container, f"{profile.name} blockerad och borttagen {now()}.") @@ -122,13 +133,9 @@ def remove_profile(profile, proxieservers='mullvad'): # TODO #2 Bättre funktion för backup av databasen -def arango_connect(pwd): - return ArangoClient(hosts=host_arango).db( - db_arango, username=user_arango, password=pwd - ) - def check_for_user(username, mode=''): + print(username) """ Checks if a user exist in db and if it's checked """ checked = False if db.collection("members").has(username): @@ -229,7 +236,7 @@ def write_stats(continuous=False): # Hur många konton per säljare som finns kvar cursor = db.aql.execute( ''' - for doc in profiles + for doc in profiles_mullvad filter has(doc, "vendor") COLLECT vendor = doc.vendor WITH COUNT INTO length RETURN { @@ -268,7 +275,7 @@ def blocked_profile(profile, proxieservers): def new_profile(container, proxieservers): """ Hämtar en ny profil. """ - profile = Profile(get_profile(proxieservers=proxieservers), container, proxieservers) + profile = Profile(get_profile(collection=proxieservers), container, proxieservers) _print(profile, None, f'Hämtade profilen {profile.name}. Login = {profile.logged_in}.') if profile.logged_in == False: profile.accept_cookies() @@ -312,4 +319,4 @@ def find_id(): -db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd) +#db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd) diff --git a/facebook/classes.py b/facebook/classes.py index fddc632..4b64e5a 100644 --- a/facebook/classes.py +++ b/facebook/classes.py @@ -135,8 +135,8 @@ class Profile: # Starta browser user_agent = self.useragent self.browser = RoboBrowser( - session=session, user_agent=user_agent, history=False, parser="lxml" - ) + session=session, user_agent=user_agent, history=False, parser="lxml", timeout=20 + ) #TODO Kolla timeout på den här # TODO Ta bort gamla metoden om nya (hämta från doc) fungerar # try: diff --git a/facebook/config.py b/facebook/config.py index c84e19e..faadfca 100644 --- a/facebook/config.py +++ b/facebook/config.py @@ -7,10 +7,9 @@ def set_pwd(_pwd=None): # Info för arangodb user_arango = "Lasse" -pwd_arango = "4c071768bedc259288361c07aafd8535fca546086fada4e7b5de4e2bb26b0e70fa8d348c998b90d032a5b8f3fdbae1881b843021e3475198e6fb45f58d8dc450bd52f77d" db_arango = "facebook" -host_arango = 'http://192.168.0.4:8529' -#host_arango = "http://arango.lasseedfast.se" +host_arango = 'http://192.168.1.20' +port_arango = '8529' # Andra uppgifter url_bas = "https://mbasic.facebook.com" diff --git a/facebook/gephi.py b/facebook/gephi.py index 1b0c704..05803f4 100644 --- a/facebook/gephi.py +++ b/facebook/gephi.py @@ -6,10 +6,12 @@ from sys import argv import networkx as nx import pandas as pd from numpy.core.numeric import NaN +from getpass import getpass +import arangodb locale.setlocale(locale.LC_TIME, "en_US") -from arangodb import db + def nodes_from_list( @@ -240,6 +242,9 @@ def common_friends(d, n=2): return l +pwd = getpass('Password for Lasse: ') +db = arangodb.arango_connect(pwd) + if __name__ == "__main__": diff --git a/facebook/proxytest.py b/facebook/proxytest.py new file mode 100644 index 0000000..cc94728 --- /dev/null +++ b/facebook/proxytest.py @@ -0,0 +1,24 @@ +import re +from time import sleep +from getpass import getpass + +from bs4 import BeautifulSoup +from arango import ArangoClient +import requests +from urllib.parse import urlencode + + + +def check_ip(): + """ + Checks the current IP. + """ + url = f'https://mrkoll.se/resultat?n={46706111785}' + proxies = {'https': 'http://sgz2bkt7:TtLyyPGKMmjabg7R_country-Sweden@proxy.proxy-cheap.com:31112'} + ip = requests.get(url, proxies=proxies).text + + return ip + +print(check_ip()) + + diff --git a/facebook/scrapers.py b/facebook/scrapers.py index 0f46bfc..5260666 100644 --- a/facebook/scrapers.py +++ b/facebook/scrapers.py @@ -157,7 +157,7 @@ def profile_picture_reactions(profile, user, first_user=False, mode="all"): if first_user == False: if mode == "single" and user.reactions > 30: break - elif all([any[mode == "few", mode == "solo"], user.reactions > 80, pic != url_pics[-1]]): + elif all([any([mode == "few", mode == "solo"]), user.reactions > 80, pic != url_pics[-1]]): # Kolla den sista bilder check_picture(url_bas + url_pics[-1], user, profile) user.checked_pictures.append(url_bas + pic) diff --git a/facebook/search_leak.py b/facebook/search_leak.py new file mode 100644 index 0000000..314820f --- /dev/null +++ b/facebook/search_leak.py @@ -0,0 +1,104 @@ +""" +Skript för att söka i FB-läckan. +""" + +import re +import paramiko +import arangodb +from getpass import getpass +from sshtunnel import open_tunnel +import paramiko +from termcolor import cprint + +def search(db, attribute, value): + """ + Search for attribute in db. + Returns list of matching documents. + """ + + if '%' in value or '_' in value: + match = 'like' + else: + match = '==' + + cursor = db.aql.execute( + f""" + FOR doc IN leak + FILTER doc.@attribute {match} @value + RETURN doc + """, + bind_vars={"attribute": attribute, "value": value}, + ) + return [doc for doc in cursor] + +pwd_key = getpass(f"Password key: ") + +with open_tunnel( + ("studio-garda.asuscomm.com", 2200), + ssh_username="Lasse", + ssh_pkey=paramiko.RSAKey.from_private_key_file( + "/Users/Lasse/.ssh/id_rsa", password=pwd_key + ), + ssh_private_key_password=pwd_key, + remote_bind_address=("127.0.0.1", 8529), +) as server: + # server.start() + port_arango = server.local_bind_port + + db = arangodb.arango_connect( + "gruel-ADOBE-foolish-winy-borax", + username="Leak", + host_arango="http://127.0.0.1", + port_arango=port_arango, + ) + + cprint("\n\nVad vill du söka efter?", attrs=['bold']) + print("1 - Telefonnummer") + print("2 - Facebook-ID") + print('3 - Namn') + print("4 - Arbete") + print('5 - Bostadsort') + print("6 - Födelseort") + print("7 - Epost") + + # Få input för attribut + attribute = input("\n>>> ") + attributes = { + "1": ("telefonnummer", "phone"), + "2": ("Facebook-ID", "_key"), + "3": ("namn", "full_name"), + "4": ("arbete", "work"), + "5": ('bostadsort', "lives_in"), + "6": ('födelseort', 'from'), + "7": ('epost', 'email') + } + + # Bestäm n- eller t-form och få input för värde. + if attribute in ['5', '6', '7']: + genus = 'n' + else: + genus = 't' + + cprint(f"\nVilke{genus} {attributes[attribute][0]}? ", attrs=['bold']) + cprint('Använd % för att ersätta flera okända tecken, _ för att ersätta ett.', attrs=['dark']) + value = input('\n>>> ') + + if attribute == '1': # telefonnummer + value = ''.join(re.findall(r'\d+', value)) + if value[0] == '0': + value = f'46{value[1:]}' + elif attribute == '3': # namn + value = value.upper() + + # Sök i databasen. + result = search(db, attributes[attribute][1], value) + + # Presentera reultaten #TODO hur vill man få dem? Spara ner? + for i in result: + print('\n', i['full_name']) + for key, value in i.items(): + print(f'{key}: {value}') + print(f'https://facebook.com/{i["_key"]}') + + print(f'\nAntal träffar: {len(result)}\n') + diff --git a/facebook/stats.py b/facebook/stats.py index bcf653f..60764f2 100644 --- a/facebook/stats.py +++ b/facebook/stats.py @@ -59,7 +59,7 @@ def write_stats(db, continuous=False): break # Info för arangodb -user_arango = "Lasse" +user_arango = "Stats" db_arango = "facebook" host_arango = "http://192.168.0.4:8529"