-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·261 lines (221 loc) · 7.23 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·261 lines (221 loc) · 7.23 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash
# the package manager on Linux to use
LINUX_PACKAGE_MANAGER="apt-get"
# some function definitions
install_brew_packages() {
# Use brew to install macOS software packages
BREW_PACKAGES="python wget curl nmap sqlite3 cmake coreutils hydra gobuster" # gcc should be available by default
which brew &> /dev/null
if [ $? != 0 ]; then
printf "${RED}Could not find brew command.\\nPlease install Homebrew first.\\n"
exit 1
fi
if [ $QUIET != 1 ]; then
echo -e "${GREEN}[+] Updating Homebrew and upgrading installed packages to latest version.${SANE}"
fi
# as brew cannot be run with root privileges, we need to run it as the real user
if [ $QUIET != 1 ]; then
sudo -u $REAL_USER_NAME brew update
brew_fail_check
sudo -u $REAL_USER_NAME brew install ${BREW_PACKAGES}
sudo -u $REAL_USER_NAME brew upgrade ${BREW_PACKAGES}
brew_fail_check
sudo -u $REAL_USER_NAME brew cleanup
else
sudo -u $REAL_USER_NAME brew update >/dev/null
brew_fail_check
sudo -u $REAL_USER_NAME brew install ${BREW_PACKAGES} >/dev/null
sudo -u $REAL_USER_NAME brew upgrade ${BREW_PACKAGES} >/dev/null
brew_fail_check
sudo -u $REAL_USER_NAME brew cleanup >/dev/null
fi
brew_fail_check
}
brew_fail_check() {
if [ $? != 0 ]; then
printf "${RED}Installation of basic brew packages was not successful.\\n"
exit 1
fi
}
install_linux_packages() {
# Use ${LINUX_PACKAGE_MANAGER} to install Linux software packages
PACKAGES="python3 python3-pip nmap libssh-dev hydra wget curl sqlite3 libsqlite3-dev cmake gcc"
which ${LINUX_PACKAGE_MANAGER} &> /dev/null
if [ $? != 0 ]; then
printf "${RED}Could not find ${LINUX_PACKAGE_MANAGER} command.\\nPlease check your package mannager installation first.\\n"
exit 1
fi
if [ $QUIET != 1 ]; then
sudo ${LINUX_PACKAGE_MANAGER} update
else
sudo ${LINUX_PACKAGE_MANAGER} update >/dev/null
fi
if [ $? != 0 ]; then
printf "${RED}Installation of ${LINUX_PACKAGE_MANAGER} packages was not successful.\\n"
exit 1
fi
if [ ${QUIET} != 1 ]; then
sudo ${LINUX_PACKAGE_MANAGER} -y install ${PACKAGES}
else
sudo ${LINUX_PACKAGE_MANAGER} -y install ${PACKAGES} >/dev/null
fi
if [ $? != 0 ]; then
printf "${RED}Installation of ${LINUX_PACKAGE_MANAGER} packages was not successful.\\n"
exit 1
fi
}
install_linux_gobuster() {
if [ $QUIET != 1 ]; then
sudo ${LINUX_PACKAGE_MANAGER} install -y gobuster
else
sudo ${LINUX_PACKAGE_MANAGER} install -y gobuster 1>/dev/null
fi
if [ $? != 0 ]; then
# check that gobuster is not already installed
which gobuster &> /dev/null
if [ $? == 0 ]; then
return
fi
# otherwise install it
echo -e "${CYAN}Info: Installing gobuster directly via go${SANE}"
# install go if it is not already installed
which go &> /dev/null
if [ $? != 0 ]; then
if [ $QUIET != 1 ]; then
sudo ${LINUX_PACKAGE_MANAGER} install -y golang-go
else
sudo ${LINUX_PACKAGE_MANAGER} install -y golang-go 1>/dev/null
fi
if [ $? != 0 ]; then
printf "${RED}Installation of gobuster was not successfull.\\n"
exit 1
fi
fi
# use go to install gobuster
sudo go get github.com/OJ/gobuster
if [ $? != 0 ]; then
printf "${RED}Installation of gobuster was not successfull.\\n"
exit 1
fi
GOBUSTER_BIN="${HOME}/go/bin/gobuster"
sudo ln -s $GOBUSTER_BIN /usr/bin/gobuster
fi
}
#####################
#### Entry Point ####
#####################
# Process command line arguments
QUIET=0
if [ $# -gt 0 ]; then
if [ $1 == "-q" ]; then
QUIET=1
elif [ $1 == "-v" ]; then
QUIET=0
fi
fi
# colors (from: https://stackoverflow.com/a/5947802)
GREEN="\033[0;32m"
SANE="\033[0m"
RED="\033[1;31m"
BLUE="\033[1;34m"
CYAN="\033[1;36m"
# cd into AVAIN directory
PREV_CWD=$(pwd)
cd "$(dirname "${BASH_SOURCE[0]}")"
# store real user name if sudo was used
REAL_USER_NAME=$(who am i | cut -d" " -f1)
# store version info
KERNEL_VERSION=$(uname -v)
IS_DEBIAN=$(grep -q "Debian" <<< "${KERNEL_VERSION}"; echo $?)
echo -e "${GREEN}[+] Started installation of AVAIN (this may take some time)${SANE}"
echo -e "${GREEN}[+] Installing basic software packages${SANE}"
KERNEL=$(uname)
if [ "${KERNEL}" == "Darwin" ]; then
echo -e "${GREEN}[+] Identified OS as: macOS --> using packet manager: brew${SANE}"
install_brew_packages
elif [ "${KERNEL}" == "Linux" ]; then
echo -e "${GREEN}[+] Identified OS as: Linux --> using packet manager: ${LINUX_PACKAGE_MANAGER}${SANE}"
install_linux_packages
install_linux_gobuster
else
printf "${RED}Could not identify running OS.\\nPlease install AVAIN manually.\\n"
exit 1
fi
QPRINT="--quiet"
if [ $QUIET != 1 ]; then
echo ""
QPRINT=""
fi
echo -e "${GREEN}[+] Installing basic python packages${SANE}"
which pip3 &> /dev/null
if [ $? != 0 ]; then
printf "${RED}Could not find pip3.\\nPlease install it first or install python packages manually\\n"
exit 1
fi
pip3 install ${QPRINT} -r requirements.txt
if [ $? != 0 ]; then
printf "${RED}Could not install python packages with pip3.\\n"
exit 1
fi
if [ $QUIET != 1 ]; then
echo ""
fi
echo -e "${GREEN}[+] Setting up git submodules${SANE}"
git submodule ${QPRINT} init
if [ $? != 0 ]; then
printf "${RED}Could not initialize git submodules.\\n"
exit 1
fi
git submodule ${QPRINT} update
if [ $? != 0 ]; then
printf "${RED}Could not update git submodules.\\n"
exit 1
fi
if [ $QUIET != 1 ]; then
echo ""
fi
# Download & setup basic resources
echo -e "${GREEN}[+] Downloading required basic resources"
cd modules
if [ $QUIET != 1 ]; then
./module_updater.py
else
./module_updater.py >/dev/null
fi
cd ..
if [ $QUIET != 1 ]; then
echo ""
fi
echo -e "${GREEN}[+] Started building the individual modules${SANE}"
CWD=$(pwd)
find modules -name avain_build.sh -print0 | while IFS= read -r -d "" file; do
cd "$(dirname ${file})"
echo -e "${GREEN}[+] Executing build script ${BLUE}${file}${SANE}"
if [ $QUIET != 1 ]; then
source avain_build.sh
else
source avain_build.sh >/dev/null
fi
if [ $? != 0 ]; then
printf "${RED}Could not successfully build module in %s\\n\\n" "$(dirname "${file}")\\n"
exit 1
fi
cd "${CWD}"
done
# Create executable AVAIN script and link it
echo ""
echo -e "${GREEN}[+] Created symlink as /usr/local/bin/avain"
chmod +x avain.py
AVAIN_DIR=$(pwd -P)
ln -sf "${AVAIN_DIR}/avain.py" /usr/local/bin/avain
# Change AVAIN directory and file ownership to actual user if installation is run as root via sudo
EUID_=$(id -u)
UID_=$(who | awk '{print $1; exit}' | xargs id -u)
if [ "${EUID_}" = 0 ] && [ "${EUID_}" != "${UID_}" ]; then
echo -e "${GREEN}[+] Setting proper file permissions for files in AVAIN directory"
GID_=$(id -g ${UID_})
chown -R "${UID_}:${GID_}" .
fi
# cd into original directory
cd "${PREV_CWD}"
echo -e "${CYAN}[+] That's it. Installation was successful${SANE}"