-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.py
More file actions
68 lines (55 loc) · 2.25 KB
/
Client.py
File metadata and controls
68 lines (55 loc) · 2.25 KB
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
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.common.exceptions import *
import subprocess
import signal
import csv
import random
websites = []
with open('/app/domains.csv', mode='r', newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
websites.append("https://" + row['Domain'])
# SOCKS5 Proxy Configuration
SOCKS_PROXY_PORT = "9050"
chrome_options = Options()
# Set up the SOCKS5 proxy
chrome_options.add_argument('--proxy-server=socks5://127.0.0.1:' + SOCKS_PROXY_PORT)
# Add additional arguments
chrome_options.page_load_strategy = 'normal'
chrome_options.add_argument("--headless=new")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--edge-skip-compat-layer-relaunch')
chrome_options.add_argument('--remote-debugging-port=9222')
service = webdriver.ChromeService(log_output=subprocess.STDOUT)
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.set_page_load_timeout(90)
index = 0
for website in websites:
# Visit websites
try:
# Starts tcpdump capture
tcpdump = subprocess.Popen(["tcpdump", "-i", "any", "-w", "/app/pcap/traffic-" + str(index) + ".pcap"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# Visits website and prints website
driver.get(website)
print(f"Visited: {website} - Title: {driver.title}", flush=True)
# Ends tcpdump capture
tcpdump.send_signal(signal.SIGINT)
tcpdump.wait()
# Increases traffic file index
index += 1
# Catches any webdriver or connection exceptions
except WebDriverException as e:
print("Exception occurred: ", e)
#if "Message: unknown error: net::ERR_SOCKS_CONNECTION_FAILED" in str(e):
#subprocess.run(["bash", "/app/restart_tor.sh"])
except Exception as e:
print("Exception occured: ", e)
# Shutdown webdriver
driver.quit()
# Shutdown OpenVPN
subprocess.Popen(['echo', 'signal', 'SIGTERM', '|nc', '127.0.0.1', '999'])