Updated Whats_My_Name.py to use Playwright instead of selenium. Fixed some logic errors in the code. Updated web_accounts_list.json to the current version.

This commit is contained in:
AccentuSoft
2021-12-14 22:57:30 -05:00
parent 45320d2c56
commit c2cbf47fd9
2 changed files with 3897 additions and 3606 deletions

View File

@@ -6,16 +6,16 @@ class Whats_My_Name:
The file web_accounts_list.json is required for the resolution Whats_My_Name.
Find:true
Replace:true,\n "selenium" : false
Find: true
Replace: "True"
Find: false
Replace: "False"
Find: "valid" : true
Replace: "valid" : "True"
Find: "valid" : false
Replace: "valid" : "False"
"""
name = "Whats My Name"
description = "Find information about a persons social media accounts"
originTypes = {'Phrase', 'Person'}
resultTypes = {'Social Media Account'}
resultTypes = {'Website'}
parameters = {}
def resolution(self, entityJsonList, parameters):
@@ -23,9 +23,8 @@ class Whats_My_Name:
from concurrent.futures import as_completed
from pathlib import Path
import json
from seleniumwire import webdriver
from selenium.common.exceptions import SessionNotCreatedException
from selenium.common.exceptions import WebDriverException
from playwright.sync_api import sync_playwright
import re
from requests.exceptions import RequestException
import urllib3
@@ -33,65 +32,74 @@ class Whats_My_Name:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0',
}
futures = []
site_params = []
futures = {}
return_result = []
try:
fireFoxOptions = webdriver.FirefoxOptions()
fireFoxOptions.headless = True
driver = webdriver.Firefox(options=fireFoxOptions)
except SessionNotCreatedException:
return "Please install the latest version of Firefox from the official Firefox website"
except WebDriverException:
return "Please add geckodriver to your path."
for entity in entityJsonList:
uid = entity['uid']
social_field = entity[list(entity)[1]].strip()
directory = Path(__file__).parent.resolve()
file_location = directory / 'web_accounts_list.json'
file = open(file_location, 'r').read()
file = json.loads(file)
with sync_playwright() as p:
browser = p.firefox.launch()
context = browser.new_context(
viewport={'width': 1920, 'height': 1080},
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0'
)
page = context.new_page()
with FuturesSession(max_workers=15) as session:
for site in file['sites']:
original_uri = site['check_uri'].replace('{account}', social_field)
account_existence_code = str(site['account_existence_code'])
account_existence_string = site['account_existence_string']
use_selenium = site['selenium']
if site['valid'] == "True":
if use_selenium == "True":
for entity in entityJsonList:
uid = entity['uid']
# Most services do not care about capitalization.
# Some may redirect non-lowercase usernames, which could result in missed accounts.
social_field = entity[list(entity)[1]].strip().lower()
directory = Path(__file__).parent.resolve()
file_location = directory / 'web_accounts_list.json'
file = open(file_location, 'r').read()
file = json.loads(file)
with FuturesSession(max_workers=15) as session:
for site in file['sites']:
original_uri = site['check_uri'].replace('{account}', social_field)
account_existence_code = str(site['account_existence_code'])
account_existence_string = site['account_existence_string']
requires_javascript = site['requires_javascript']
if site['valid'] == "True":
account_existence_string = re.escape(str(account_existence_string))
account_existence_string = re.compile(account_existence_string)
driver.get(original_uri)
status_code = driver.requests[0].response.status_code
page_source = driver.page_source
if status_code == int(
account_existence_code) and account_existence_string != "" and len(
account_existence_string.findall(page_source)) > 0:
return_result.append([{'URL': original_uri,
'Entity Type': 'Website'},
{uid: {'Resolution': 'Whats My Name Report', 'Notes': ''}}])
else:
futures.append(session.get(original_uri,
headers=headers, timeout=10, allow_redirects=False))
site_params.append((account_existence_code, account_existence_string))
for future in as_completed(futures):
account_existence_code = site_params[futures.index(future)][0]
account_existence_string = site_params[futures.index(future)][1]
account_existence_string = re.escape(str(account_existence_string))
account_existence_string = re.compile(account_existence_string)
try:
first_response = future.result()
except RequestException:
continue
page_source = first_response.text
if first_response.status_code == int(account_existence_code) and account_existence_string != "" and len(
account_existence_string.findall(page_source)) > 0:
return_result.append([{'URL': first_response.url,
'Entity Type': 'Website'},
{uid: {'Resolution': 'Whats My Name Report', 'Notes': ''}}])
if requires_javascript == "True":
for _ in range(3):
try:
response = page.goto(original_uri, wait_until="networkidle", timeout=10000)
status_code = response.status
page_source = page.content()
if status_code == int(account_existence_code) and \
account_existence_string != "" and \
len(account_existence_string.findall(page_source)) > 0:
return_result.append([{'URL': original_uri,
'Entity Type': 'Website'},
{uid: {'Resolution': 'Whats My Name Account Match',
'Notes': ''}}])
break
except TimeoutError:
pass
else:
futures[session.get(original_uri, headers=headers,
timeout=10, allow_redirects=False)] = \
(account_existence_code, account_existence_string)
for future in as_completed(futures):
account_existence_code = futures[future][0]
account_existence_string = futures[future][1]
try:
first_response = future.result()
except RequestException:
continue
page_source = first_response.text
if first_response.status_code == int(account_existence_code) and \
account_existence_string != "" and \
len(account_existence_string.findall(page_source)) > 0:
return_result.append([{'URL': first_response.url,
'Entity Type': 'Website'},
{uid: {'Resolution': 'Whats My Name Account Match', 'Notes': ''}}])
page.close()
browser.close()
return return_result

File diff suppressed because it is too large Load Diff