forked from ericsherlock/pentools-install
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpentools_install
More file actions
executable file
·163 lines (137 loc) · 4.17 KB
/
Copy pathpentools_install
File metadata and controls
executable file
·163 lines (137 loc) · 4.17 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
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
#! /bin/bash
set -euo pipefail
LOGFILE="install_log"
usage () {
echo "Usage: $0"
}
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOGFILE"
}
exit_func () {
case "$1" in
1) log "Exit 1 --> Wrong Number of Arguments."; exit 1 ;;
2) log "Exit 2 --> Error Within Install Kali Tools Method."; exit 2 ;;
3) log "Exit 3 --> Missing required file: $2"; exit 3 ;;
4) log "Exit 4 --> Must be run as root."; exit 4 ;;
5) log "Exit 5 --> Required command not found: $2"; exit 5 ;;
*) log "Exit $1 --> Unknown error."; exit "$1" ;;
esac
}
check_root() {
if [ "$EUID" -ne 0 && "$ans" != [bB]*]; then
exit_func 4
fi
}
check_command() {
command -v "$1" >/dev/null 2>&1 || exit_func 5 "$1"
}
check_file() {
[ -f "$1" ] || exit_func 3 "$1"
}
check_requirements() {
check_command "cut"
check_command "tee"
check_command "date"
check_command "eval"
check_command "grep"
check_command "awk"
check_command "printf"
check_command "read"
check_command "mkdir"
check_command "mv"
check_command "cd"
check_command "cat"
check_command "head"
check_command "tail"
check_command "sort"
check_command "uniq"
check_command "basename"
check_command "dirname"
check_command "tr"
check_command "sed"
# Check for package managers
if ! command -v dnf >/dev/null && ! command -v apt-get >/dev/null && ! command -v brew >/dev/null; then
log "Neither dnf, apt-get, nor brew found. Exiting."
exit 1
fi
# Check for pip and git
check_command "pip" || check_command "pip3"
check_command "git"
}
confirm_install() {
read -p "Proceed with installing tools? [y/N]: " confirm
case "$confirm" in
[yY]*) ;;
*) log "Installation cancelled by user."; exit 0 ;;
esac
}
install_pentest_tools () {
local mode="$1"
local toolfile=""
local toolname=""
local installcmd=""
local eval_res=0
# # Create directory and move files
# local path
# path=$(pwd)
# log "Creating directory 'pentesting-tools' in current directory"
# mkdir -p "$path/pentesting-tools"
# for f in rhtoolfile apttoolfile brewtoolfile; do
# [ -f "$f" ] && cp "$f" "$path/pentesting-tools/" || true
# done
# cd "$path/pentesting-tools/"
# Select toolfile based on mode
if [ "$mode" -eq 1 ]; then
toolfile="rhtoolfile"
elif [ "$mode" -eq 2 ]; then
toolfile="apttoolfile"
elif [ "$mode" -eq 3 ]; then
toolfile="brewtoolfile"
else
exit_func 2
fi
check_file "$toolfile"
# Install tools from toolfiles
while IFS= read -r line || [ -n "$line" ]; do
# Skip empty lines and comments
[[ -z "$line" || "$line" =~ ^# ]] && continue
toolname=$(cut -f1 -d" " <<< "$line")
installcmd=$(cut -d" " -f3- <<< "$line")
log "----------------------------------------------------------------------------------------------"
log "Installing: $toolname"
log "----------------------------------------------------------------------------------------------"
if [[ "$installcmd" == "exit"* ]]; then
log "Reached end of tool list."
break
fi
if [[ "$installcmd" == "" ]]; then
log "No install command found for $toolname. Skipping."
continue
fi
if ! eval "$installcmd"; then
log "Error installing: $toolname"
log "Try running the command manually: $installcmd"
log "Please look in the $LOGFILE file to find out more..."
else
log "$toolname : Installed Successfully!"
fi
done < "$toolfile"
}
main() {
read -p "Which Repository Do You Use? (d=dnf, a=apt-get, b=brew): " ans
case $ans in
[dD]* ) install_pentest_tools 1 ;;
[aA]* ) install_pentest_tools 2 ;;
[bB]* ) install_pentest_tools 3 ;;
* ) log "Please Enter Either [Dd] [Bb] or [Aa]"; exit 1 ;;
esac
check_root
check_requirements
if [ "$#" -ne 0 ]; then
usage
exit_func 1
fi
log "Starting Pentest Tools Installer"
confirm_install
}
main "$@"