forked from gotr00t0day/spyhunt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
200 lines (170 loc) · 7.59 KB
/
install.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import platform
import subprocess
import os
from shutil import which
from colorama import Fore, init
init(autoreset=True)
def run_command(cmd):
try:
print(f"{Fore.CYAN}Running command: {cmd}{Fore.RESET}")
output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True)
print(f"{Fore.GREEN}Command output: {output.strip()}{Fore.RESET}")
return output
except subprocess.CalledProcessError as e:
print(f"{Fore.RED}Failed to run command: {cmd}")
print(f"Error: {e.output}")
return None
def detect_package_manager():
package_managers = [
("apt", "apt"),
("dnf", "dnf"),
("yum", "yum"),
("pacman", "pacman"),
("zypper", "zypper"),
("apk", "apk")
]
for pm, cmd in package_managers:
if which(cmd):
return pm
return None
def install_package(package, manager):
if manager == "apt":
return run_command(f"sudo apt install -y {package}")
elif manager == "dnf" or manager == "yum":
return run_command(f"sudo {manager} install -y {package}")
elif manager == "pacman":
return run_command(f"sudo pacman -S --noconfirm {package}")
elif manager == "zypper":
return run_command(f"sudo zypper install -y {package}")
elif manager == "apk":
return run_command(f"sudo apk add {package}")
elif manager == "brew":
return run_command(f"brew install {package}")
elif manager == "pip":
return run_command(f"pip3 install {package}")
elif manager == "npm":
return run_command(f"sudo npm install -g {package}")
elif manager == "go":
return run_command(f"go install {package}")
def install_tool(name, install_cmd, check_cmd=None):
if check_cmd is None:
check_cmd = name
if not which(check_cmd):
print(f"{Fore.YELLOW}Installing {name}...{Fore.RESET}")
result = install_cmd()
if result is not None:
print(f"{Fore.GREEN}{name} installed successfully{Fore.RESET}")
else:
print(f"{Fore.RED}Failed to install {name}{Fore.RESET}")
else:
print(f"{Fore.GREEN}Found {name}{Fore.RESET}")
def install_go_tool(tool, package):
print(f"{Fore.YELLOW}Installing {tool}...{Fore.RESET}")
if run_command(f"go install {package}") is not None:
go_path = run_command("go env GOPATH").strip()
bin_path = os.path.join(go_path, "bin", tool)
if os.path.exists(bin_path):
run_command(f"sudo mv {bin_path} /usr/local/bin/")
print(f"{Fore.GREEN}{tool} installed successfully{Fore.RESET}")
else:
print(f"{Fore.RED}Failed to find {tool} in GOPATH{Fore.RESET}")
else:
print(f"{Fore.RED}Failed to install {tool}{Fore.RESET}")
def check_wsl():
if platform.system() == "Linux":
with open('/proc/version', 'r') as f:
return 'microsoft' in f.read().lower()
return False
def update_upgrade_system(package_manager):
print(f"{Fore.YELLOW}Updating and upgrading the system...{Fore.RESET}")
if package_manager == "apt":
run_command("sudo apt update && sudo apt upgrade -y")
elif package_manager in ["dnf", "yum"]:
run_command(f"sudo {package_manager} update -y")
elif package_manager == "pacman":
run_command("sudo pacman -Syu --noconfirm")
elif package_manager == "zypper":
run_command("sudo zypper update -y")
elif package_manager == "apk":
run_command("sudo apk update && sudo apk upgrade")
print(f"{Fore.GREEN}System updated and upgraded successfully{Fore.RESET}")
def ensure_pip_installed(package_manager):
if not which("pip3") and not which("pip"):
print(f"{Fore.YELLOW}pip is not installed. Installing pip...{Fore.RESET}")
if platform.system() == "Linux":
if package_manager == "apt":
run_command("sudo apt install -y python3-pip")
elif package_manager in ["dnf", "yum"]:
run_command(f"sudo {package_manager} install -y python3-pip")
elif package_manager == "pacman":
run_command("sudo pacman -S --noconfirm python-pip")
elif package_manager == "zypper":
run_command("sudo zypper install -y python3-pip")
elif package_manager == "apk":
run_command("sudo apk add py3-pip")
elif platform.system() == "Darwin":
run_command("brew install python") # This will install pip as well
print(f"{Fore.GREEN}pip installed successfully{Fore.RESET}")
else:
print(f"{Fore.GREEN}pip is already installed{Fore.RESET}")
def main():
system = platform.system()
is_wsl = check_wsl()
if is_wsl:
print(f"{Fore.YELLOW}Detected Windows Subsystem for Linux (WSL){Fore.RESET}")
if system == "Linux":
package_manager = detect_package_manager()
if package_manager is None:
print(f"{Fore.RED}Unable to detect package manager. Please install packages manually.{Fore.RESET}")
return
print(f"{Fore.GREEN}Detected package manager: {package_manager}{Fore.RESET}")
if is_wsl:
update_upgrade_system(package_manager)
elif system == "Darwin": # macOS
package_manager = "brew"
if not which("brew"):
print(f"{Fore.RED}Homebrew is required for macOS. Please install it first.{Fore.RESET}")
return
else:
print(f"{Fore.RED}Unsupported operating system: {system}{Fore.RESET}")
return
ensure_pip_installed(package_manager)
home = os.path.expanduser("~")
# Install colorama
install_tool("colorama", lambda: install_package("colorama", "pip"))
# Install golang
install_tool("go", lambda: install_package("golang", package_manager))
# Install nodejs and npm
install_tool("node", lambda: install_package("nodejs", package_manager))
install_tool("npm", lambda: install_package("npm", package_manager))
# Install broken-link-checker
install_tool("blc", lambda: install_package("broken-link-checker", "npm"))
# Install nuclei
install_go_tool("nuclei", "github.com/projectdiscovery/nuclei/v2/cmd/nuclei@latest")
# Clone nuclei-templates
if not os.path.exists(os.path.join(home, "nuclei-templates")):
run_command(f"git clone https://github.com/projectdiscovery/nuclei-templates.git {home}/nuclei-templates")
# Install other tools
tools = [
("dnsx", "github.com/projectdiscovery/dnsx/cmd/dnsx@latest"),
("subfinder", "github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest"),
("waybackurls", "github.com/tomnomnom/waybackurls@latest"),
("httprobe", "github.com/tomnomnom/httprobe@latest"),
("httpx", "github.com/projectdiscovery/httpx/cmd/httpx@latest"),
("anew", "github.com/tomnomnom/anew@latest"),
("gau", "github.com/lc/gau/v2/cmd/gau@latest"),
("gauplus", "github.com/bp0lr/gauplus@latest"),
("hakrawler", "github.com/hakluke/hakrawler@latest"),
("assetfinder", "github.com/tomnomnom/assetfinder@latest"),
("asnmap", "github.com/projectdiscovery/asnmap/cmd/asnmap@latest"),
]
for tool, go_package in tools:
install_go_tool(tool, go_package)
# Install jq
install_tool("jq", lambda: install_package("jq", package_manager))
# Install shodan
install_tool("shodan", lambda: install_package("shodan", "pip"))
# Install paramspider
install_tool("paramspider", lambda: run_command("git clone https://github.com/devanshbatham/paramspider && cd paramspider && python3 setup.py install"))
if __name__ == "__main__":
main()