-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPentestBoxSetup.sh
executable file
·141 lines (121 loc) · 5.45 KB
/
PentestBoxSetup.sh
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
#!/bin/bash
# MIT License
#
# Copyright (c) 2023 Anthony Hanel
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# This script installs various tools for a Linux-based penetration testing environment.
# Function to handle errors
error_handling() {
echo "Error: $1"
exit 1
}
# Function to install or update a repository
install_repo() {
local repo_name=$1
local clone_url=$2
local install_dir=$3
if [ -d "$install_dir" ]; then
echo "$repo_name already exists at $install_dir. Skipping clone."
else
echo "Cloning $repo_name..."
sudo git clone "$clone_url" "$install_dir" || error_handling "Failed to clone $repo_name"
fi
}
# Ensure the script is running as root
if [ "$EUID" -ne 0 ]; then
echo "This script requires root privileges. Please run with sudo."
exit 1
fi
# Update package lists
sudo apt update -y || error_handling "Failed to update package lists"
# Install required packages
sudo apt install -y software-properties-common apt-transport-https wget python3-pip python3-venv || error_handling "Failed to install required packages"
# Install pipx if not already installed
if ! command -v pipx &> /dev/null; then
echo "Installing pipx..."
python3 -m pip install --user pipx || error_handling "Failed to install pipx"
python3 -m pipx ensurepath || error_handling "Failed to configure pipx path"
else
echo "pipx is already installed."
fi
# Ensure pipx binaries are in PATH
USER_HOME=$(eval echo "~$SUDO_USER")
if [[ ":$PATH:" != *":$USER_HOME/.local/bin:"* ]]; then
echo "Adding pipx to PATH..."
export PATH="$USER_HOME/.local/bin:$PATH"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> $USER_HOME/.zshrc
source "$USER_HOME/.zshrc"
fi
echo $PATH
# Install AutoRecon via pipx
if ! command -v autorecon &> /dev/null; then
echo "Installing AutoRecon with pipx..."
sudo -E pipx install git+https://github.com/Tib3rius/AutoRecon.git || error_handling "Failed to install AutoRecon with pipx"
else
echo "AutoRecon is already installed. Attempting Upgrade..."
pipx upgrade autorecon || error_handling "Failed to upgrade AutoRecon"
fi
# Install Impacket via pipx
if ! command -v mimikatz.py &> /dev/null; then
echo "Installing Impacket with pipx..."
sudo -E pipx install impacket || error_handling "Failed to install Impacket with pipx"
else
echo "Impacket is already installed. Attempting Upgrade..."
pipx upgrade Impacket || error_handling "Failed to upgrade Impacket"
fi
# Clone necessary pentest tools
install_repo "GitTools" "https://github.com/internetwache/GitTools.git" "/opt/GitTools"
install_repo "git-dumper" "https://github.com/arthaud/git-dumper.git" "/opt/git-dumper"
# Install Visual Studio Code if not installed
if ! command -v code &> /dev/null; then
echo "Installing Visual Studio Code..."
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add - || error_handling "Failed to add Microsoft repository key"
sudo add-apt-repository -y "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" || error_handling "Failed to add Visual Studio Code repository"
sudo apt install -y code || error_handling "Failed to install Visual Studio Code"
else
echo "Visual Studio Code is already installed."
fi
# Install JWT-cracker via npm using pipx
if ! command -v jwt-cracker &> /dev/null; then
echo "Installing JWT-cracker..."
sudo -E pipx install jwt-cracker || error_handling "Failed to install JWT-cracker with pipx"
else
echo "JWT-cracker is already installed."
fi
# Uncompress rockyou.txt wordlist if not already uncompressed
if [ -f /usr/share/wordlists/rockyou.txt.gz ]; then
echo "Uncompressing rockyou.txt..."
sudo gzip -d /usr/share/wordlists/rockyou.txt.gz || error_handling "Failed to uncompress rockyou.txt"
else
echo "rockyou.txt is already uncompressed."
fi
# Ensure snapd is running
if ! systemctl is-active --quiet snapd.service; then
echo "Starting and enabling snapd service..."
sudo systemctl start snapd.service || error_handling "Failed to start snapd.service"
sudo systemctl enable snapd.service || error_handling "Failed to enable snapd.service"
sudo systemctl enable --now snapd apparmor || error_handling "Failed to enable snapd apparmor"
else
echo "snapd service is already running."
fi
# Clean up packages
echo "Cleaning up..."
sudo apt autoremove -y || error_handling "Failed to autoremove unused packages"
echo "Pentesting environment setup is complete."