Automated installation of Nuclei on a MAC/Linux
Automated installation of Nuclei on a MAC
Here is the Python script to install Nuclei (a popular vulnerability scanner) on a MacBook. Nuclei is generally installed via the Go package manager (go get
), but if you're starting from scratch, the script will need to:
Check if Go is installed.
If not, install Go.
Install Nuclei using Go. Usage:
sudo python3 install_nuclei.py
<install>/<uninstall>
install_nuclei.py
import os
import subprocess
def is_command_available(command):
"""Check if a command is available in the system."""
try:
subprocess.run([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return True
except FileNotFoundError:
return False
def install_go():
"""Install Go using Homebrew."""
os.system("brew install go")
def uninstall_go():
"""Uninstall Go using Homebrew."""
os.system("brew uninstall go")
def install_nuclei():
"""Install Nuclei using Go."""
os.system("go install github.com/projectdiscovery/nuclei/v2/cmd/nuclei@latest")
def uninstall_nuclei():
"""Uninstall Nuclei."""
nuclei_path = os.path.expanduser("~/go/bin/nuclei")
if os.path.exists(nuclei_path):
os.remove(nuclei_path)
def append_to_shell_profile(line):
"""Append a line to the user's shell profile."""
profiles = ["~/.bashrc", "~/.bash_profile", "~/.zshrc"]
for profile in profiles:
profile_path = os.path.expanduser(profile)
if os.path.exists(profile_path):
with open(profile_path, 'a') as file:
file.write("\n" + line)
print(f"[*] Appended to {profile}")
def main():
action = input("Choose an action (install/uninstall): ").lower()
if action == "install":
# Check if Go is available
if not is_command_available("go"):
print("[*] Go is not installed. Installing Go...")
install_go()
else:
print("[*] Go is already installed.")
# Check if Nuclei is available
if not is_command_available("nuclei"):
print("[*] Nuclei is not installed. Installing Nuclei...")
install_nuclei()
if not is_command_available("nuclei"):
print("[*] Adding nuclei path to shell profile...")
append_to_shell_profile("export PATH=$PATH:~/go/bin")
else:
print("[*] Nuclei is already installed.")
elif action == "uninstall":
# Uninstall Nuclei
print("[*] Uninstalling Nuclei...")
uninstall_nuclei()
# Option to uninstall Go
if is_command_available("go"):
choice = input("Do you also want to uninstall Go? (yes/no): ").lower()
if choice == "yes":
print("[*] Uninstalling Go...")
uninstall_go()
else:
print("[*] Go is not installed, skipping uninstallation.")
else:
print("[!] Invalid action chosen.")
return
print("[*] Process complete!")
if __name__ == "__main__":
main()
Automated installation of Nuclei on a Linux (Ubuntu/Debian)
install_nuclei.sh
#!/bin/bash
# Ensure Go is installed
if ! command -v go > /dev/null 2>&1; then
echo "[*] Go is not installed. Installing Go..."
sudo apt update
sudo apt install -y golang-go
else
echo "[*] Go is already installed."
fi
# Update the PATH (in case Go is newly installed and the current session doesn't know the path yet)
export PATH=$PATH:/usr/local/go/bin:$(go env GOPATH)/bin
# Check if nuclei is installed
if ! command -v nuclei > /dev/null 2>&1; then
echo "[*] Nuclei is not installed. Installing Nuclei..."
# Install nuclei using go get for Go 1.15
GO111MODULE=on go get -v github.com/projectdiscovery/nuclei/v2/cmd/nuclei
else
echo "[*] Nuclei is already installed."
fi
# Check nuclei version
echo -n "[*] Nuclei version: "
nuclei -v
# Update nuclei templates
if [ ! -d "$HOME/nuclei-templates" ]; then
echo "[*] Nuclei templates are not found. Downloading templates..."
git clone https://github.com/projectdiscovery/nuclei-templates.git $HOME/nuclei-templates
else
echo "[*] Updating Nuclei templates..."
git -C $HOME/nuclei-templates pull
fi
# Print the version of nuclei templates
echo -n "[*] Nuclei templates version: "
cat $HOME/nuclei-templates/.git/HEAD
echo "[INFO] Process complete!"
PreviousCharacters allowed in a domain nameNextUpload local directory codes to a new GitHub repository
Last updated
Was this helpful?