-
Notifications
You must be signed in to change notification settings - Fork 5
/
run.py
81 lines (59 loc) · 2.11 KB
/
run.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
#!/usr/bin/env python3
import argparse
import os
import time
from urllib.parse import urlparse
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
DOWNLOADS = "/downloads/"
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--certhash", help="server certificate hash")
return parser.parse_args()
requests = os.environ["REQUESTS"].split(" ")
f = open("/save.html", "w")
f.write('<html><head><meta charset="UTF-8"></head><body>')
for url in requests:
f.write('<a href="' + url + '" target="_blank" download>click me</a>')
f.write("</body></html>")
f.close()
server = urlparse(requests[0]).netloc
print("Got server " + server)
options = webdriver.ChromeOptions()
options.gpu = False
options.binary_location = "/usr/bin/google-chrome-beta"
options.add_argument("--no-sandbox")
options.add_argument("--enable-quic")
options.add_argument("--quic-version=80")
options.add_argument("--origin-to-force-quic-on=" + server)
options.add_argument("--log-net-log=/logs/chrome.json")
options.add_argument("--net-log-capture-mode=IncludeSensitive")
options.add_argument("--ignore-certificate-errors-spki-list=" + get_args().certhash)
options.add_argument("--headless=new")
options.add_experimental_option(
"prefs",
{
"download.default_directory": DOWNLOADS,
"download.prompt_for_download": False,
},
)
service = Service(
executable_path="/usr/bin/chromedriver"
)
driver = webdriver.Chrome(service=service, options=options)
driver.get("file:///save.html")
for el in driver.find_elements(By.TAG_NAME, "a"):
print("Downloading link " + el.get_attribute("href"))
el.click()
# While downloading, Chrome saves files to <filename>.crdownload.
# Once the download completes, they are moved to <filename>.
def check_files() -> bool:
files = os.listdir(DOWNLOADS)
if len(files) < len(requests):
return False
return len([f for f in files if ".crdownload" in f]) == 0
while not check_files():
time.sleep(0.01)
driver.close()