forked from BitTheByte/Monitorizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.py
More file actions
124 lines (105 loc) · 3.86 KB
/
monitor.py
File metadata and controls
124 lines (105 loc) · 3.86 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
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
from monitorizer.core.main import Monitorizer
from monitorizer.ui.arguments import args
from monitorizer.core import flags
from modules.event.on import Events
from modules.nuclei.api import Nuclei
from modules.nuclei_fuzzing.api import NucleiFuzzing
from modules.subdominator.api import Subdominator
from modules.fuzzing.api import Fuzzing
import os
import subprocess
import signal
from datetime import datetime
from time import sleep
scanners = (
"subfinder",
"puredns"
)
monitorizer = Monitorizer()
signal.signal(signal.SIGINT, monitorizer.on_kill)
if not args.debug:
monitorizer.clear()
monitorizer.banner()
events = Events()
nuclei = Nuclei()
nuclei_fuzzing = NucleiFuzzing()
fuzzing = Fuzzing()
subdominator = Subdominator()
os.makedirs("./config", exist_ok=True)
os.makedirs("./config/thirdparty", exist_ok=True)
# subprocess.Popen("python3 ./install.py",shell=False)
try:
# Run the first command
install_tools = subprocess.run(
["python3", "./install.py"],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
print(f"Installation output: {install_tools.stdout.decode()}")
# Run the second command
git_submodules = subprocess.run(
["git", "submodule", "update", "--init", "--recursive"],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
print(f"Git submodule update output: {git_submodules.stdout.decode()}")
except subprocess.CalledProcessError as e:
# If either command fails, print an error message and exit with a non-zero status code
print(f"Error occurred: {e}")
if e.stdout:
print(f"Standard Output: {e.stdout.decode()}")
if e.stderr:
print(f"Standard Error: {e.stderr.decode()}")
if os.path.isfile(args.watch):
with open(args.watch, "r") as f:
_watch_list = {t.strip() for t in f.readlines()}
monitorizer.log(f"reading targets from file: {args.watch}")
else:
_watch_list = set()
monitorizer.error(f"unable to read {args.watch} is the file on the disk?")
monitorizer.exit()
monitorizer.set_config(args.config)
monitorizer.initialize()
monitorizer.self_check(scanners)
nuclei.start_continuous_scanner()
# nuclei_fuzzing.start_continuous_scanner()
subdominator.start_continuous_scanner()
fuzzing.start_continuous_scanner()
events.start_monitor()
def continuous_scan():
while True:
for target in _watch_list:
if not target:
continue
flags.status = "running"
flags.current_target = target
report_name = datetime.now().strftime("%Y%m%d_%s")
flags.report_name = report_name
monitorizer.log(f"Created new report target={target} name={report_name}")
events.scan_start(target)
current_scan = monitorizer.mutliscan(scanners, target)
events.scan_finish(target)
monitorizer.generate_report(target, current_scan, report_name)
new_domains = monitorizer.merge_scans(current_scan)
old_domains = monitorizer.merge_reports(target, exclude=[report_name])
new_domains.difference_update(old_domains)
if new_domains_filtered := {
domain: [
tool
for tool, subs in current_scan.items()
if domain in subs
]
for domain in new_domains
if domain
}:
events.discover(new_domains_filtered, report_name)
flags.status = "idle"
monitorizer.info(f"All targets scanned, sleeping for {flags.sleep_time} hour(s)")
sleep(60 * 60 * flags.sleep_time)
if __name__ == "__main__":
try:
continuous_scan()
except KeyboardInterrupt:
Monitorizer.on_kill()