forked from keeganjk/smokescreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
waybackbrowser.py
161 lines (132 loc) · 3.67 KB
/
waybackbrowser.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Name: WayBackBrowser
Dev: MindoverclockR
Date Created: July 25, 2020
Last Modified: July 28, 2020
Editor: K4YT3X
Last Modified: July 25, 2020
Description: Browse randomly at random dates in the past (only to browser history)
"""
# built-in imports
import argparse
import contextlib
import datetime
import os
import pathlib
import platform
import random
import shlex
import subprocess
import time
BROWSER_PROCESS = None
def parse_arguments():
""" parse CLI arguments
"""
parser = argparse.ArgumentParser(
prog="waybackbrowser", formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"-s",
"--smoke",
type=pathlib.Path,
help="path to smokescreen html",
default=pathlib.Path(
os.path.join(os.path.dirname(__file__), 'index.htm')
),
)
parser.add_argument(
"-b",
"--browser",
type=pathlib.Path,
help="path to the browser executable",
default=browser_path()
)
parser.add_argument(
"--maximum", type=int, help="maximum times to offset", default=10
)
return parser.parse_args()
# operating system detection
def is_windows():
if (platform.system() == "Windows"):
return True
elif (platform.system() == "Linux"):
return False
else:
print("Unsupported OS, quitting...")
exit()
# set browser path according to os
def browser_path():
if (is_windows()):
return (
pathlib.Path(
"{}\\Google\\Chrome\\Application\\chrome.exe".format(
os.environ["PROGRAMFILES(X86)"]
)
)
)
else:
return (
pathlib.Path("chromium")
)
# change date to target_datetime
def change_date(target_datetime):
if (is_windows()):
os.system("date " + target_datetime.strftime("%m-%d-%y"))
else:
subprocess.run(shlex.split("sudo date -s '%s'" % target_datetime.isoformat()))
# re-sync date and time before and after execution
def resync_datetime():
if (is_windows()):
subprocess.run(["w32tm", "/resync"])
else:
subprocess.run(shlex.split("sudo ntpdate pool.ntp.org"))
def make_noise(
maximum_times: int, browser: pathlib.Path, smoke: pathlib.Path
):
""" start generating noise by opening URLs at random dates using the browser
Args:
maximum_times (int): maximum times to offset
browser (pathlib.Path): path to the browser executable
smoke (pathlib.Path): path to smokescreen html
"""
for i in range(maximum_times):
# go back 1 - 5 days randomly
time_delta = random.randint(1, 5)
random_date = datetime.date.today() - datetime.timedelta(days=time_delta)
# wait 15 - 30 secs randomly
sleep_time = random.randint(15, 30)
# print and change to the target system date
print("Selected random date: {}".format(random_date.strftime("%m-%d-%y")))
change_date(random_date)
# make BROWSER_PROCESS global so it can be killed outside of this function
global BROWSER_PROCESS
# open the browser as a subprocess for sleep_time, do not output errors to console
BROWSER_PROCESS = subprocess.Popen([browser, smoke], stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
time.sleep(sleep_time)
# kill browser
BROWSER_PROCESS.terminate()
def main():
# parse command line arguments
args = parse_arguments()
# synchronize current system time
resync_datetime()
# start to make noise
try:
make_noise(args.maximum, args.browser, args.smoke)
# kill browser on KeyboardInterrupt
except (KeyboardInterrupt, SystemExit):
print("Program interrupted, terminating the browser process")
with contextlib.suppress(Exception):
if (
isinstance(BROWSER_PROCESS, subprocess.Popen)
and BROWSER_PROCESS.poll() is None
):
BROWSER_PROCESS.terminate()
exit()
finally:
print("Execution completed, restoring system time")
resync_datetime()
if __name__ == "__main__":
main()