-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
449 lines (398 loc) · 11.2 KB
/
install.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
#!/data/data/com.termux/files/usr/bin/bash -e
VERSION=2020011601 # Kali version variable
BASE_URL=https://kali.download/nethunter-images/current/rootfs
USERNAME=kali
function ctbanner() {
clear
echo -e """\t
\t⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣶⠖⠀⠀⠲⣶⣶⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
\t⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡿⠋⠀⠀⠀⠀⠀⠀⠙⢿⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀
\t⠀⠀⠀⠀⠀⠀⢀⣾⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣿⣷⡀⠀⠀⠀⠀⠀⠀
\t⠀⠀⠀⠀⠀⠀⣾⣿⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⣷⠀⠀⠀⠀⠀⠀
\t⠀⠀⠀⠀⠀⠀⣿⣿⣿⣇⣤⠶⠛⣛⣉⣙⡛⠛⢶⣄⣸⣿⣿⣿⠀⠀⠀⠀⠀⠀
\t⠀⠀⠀⠀⢀⣀⣿⣿⣿⡟⢁⣴⣿⣿⣿⣿⣿⣿⣦⡈⢿⣿⣿⣿⣀⡀⠀⠀⠀⠀
\t⠀⠀⢠⣴⣿⣿⣿⣿⡟⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡌⢿⣿⣿⣿⣿⣦⡄⠀⠀
\t⠀⣴⣿⣿⡿⠿⢛⣻⡇⢸⡟⠻⣿⣿⣿⣿⣿⡿⠟⢻⡇⣸⣛⡛⠿⣿⣿⣿⣦⠀
\t⢸⣿⡿⠋⠀⠀⢸⣿⣿⡜⢧⣄⣀⣉⡿⣿⣉⣀⣠⣼⢁⣿⣿⡇⠀⠀⠙⢿⣿⡆
\t⣿⣿⠁⠀⠀⠀⠈⣿⣿⡇⣿⡿⠛⣿⣵⣮⣿⡟⢻⡿⢨⣿⣿⠀⠀⠀⠀⠈⣿⣿
\t⢿⡟⠀⠀⠀⠀⠀⠘⣿⣷⣤⣄⡀⣿⣿⣿⣿⢁⣤⣶⣿⣿⠃⠀⠀⠀⠀⠀⣿⡟
\t⠘⠇⠀⠀⠀⠀⠀⠀⠈⠻⣿⣿⡇⢿⣿⣿⣿⢸⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠻⠃
\t⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⢩⣦⣘⡘⠋⣛⣸⡍⠁⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀
\t⠀⠀⠘⢿⣷⣤⣤⣄⣤⣤⣶⣿⣿⣿⡿⢿⣿⣿⣿⣷⣤⣤⣠⣤⣴⣾⡿⠁⠀⠀
\t⠀⠀⠀⠀⠉⠛⠿⠿⠿⡿⠿⠿⠛⠉⠀⠀⠉⠛⠿⠿⣿⠿⠿⠿⠛⠉⠀⠀⠀⠀
""" | lolcat
toilet -f ivrit ' CustoMUX Setup' | lolcat
echo
echo
echo
}
function clonerepo() {
ctbanner
echo Cloning sources... | lolcat
git clone https://github.com/Genplat/awesome-termux
}
function cpfiles() {
ctbanner
echo Copying files... | lolcat
mv awesome-termux custoMUX &> /dev/null
cd custoMUX &> /dev/null
rm ~/../usr/bin/login &> /dev/null
chmod +x * &> /dev/null
cp -r * ~/../usr/bin/ &> /dev/null
cd $HOME
}
function confprof() {
ctbanner
read -p "New username: " usernametermux
read -p "New password: " passwdtermux
echo $passwdtermux > ~/../usr/etc/passwdtermux
echo $usernametermux > ~/../usr/etc/usrtermux
}
function unsupported_arch() {
ctbanner
printf "${red}"
printf "[*] Unsupported Architecture\n\n"
printf "${reset}"
exit
}
function magisk_alert() {
printf "${blue}Do you have magisk installed? You can try our CustoMUX magisk module for a more easy installation and more tools!\n"
printf "${blue}Download at https://github.com/Genplat/CustoMUX\n"
printf "${blue}Wait 5s to install BASIC CustoMUX (awesome-termux) or Ctrl+C to cancell and install magisk module\n\n"
sleep 5
}
function installzsh_theme() {
echo Installing Powerlevel10k... | lolcat
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc
}
function ask() {
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
printf "${light_cyan}\n[?] "
read -p "$1 [$prompt] " REPLY
if [ -z "$REPLY" ]; then
REPLY=$default
fi
printf "${reset}"
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
function get_arch() {
ctbanner
echo "[*] Checking device architecture ..." | lolcat
case $(getprop ro.product.cpu.abi) in
arm64-v8a)
SYS_ARCH=arm64
;;
armeabi|armeabi-v7a)
SYS_ARCH=armhf
;;
*)
unsupported_arch
;;
esac
}
function set_strings() {
echo \
&& echo ""
####
if [[ ${SYS_ARCH} == "arm64" ]];
then
wimg="full"
elif [[ ${SYS_ARCH} == "armhf" ]];
then
ctbanner
echo "[!] NetHunter installation will be MINIMAL. Your arch doesn't support a full nethunter installation." | lolcat
sleep 3
wimg="minimal"
fi
####
CHROOT=kali-${SYS_ARCH}
IMAGE_NAME=kalifs-${SYS_ARCH}-${wimg}.tar.xz
SHA_NAME=kalifs-${SYS_ARCH}-${wimg}.sha512sum
}
function prepare_fs() {
unset KEEP_CHROOT
if [ -d ${CHROOT} ]; then
rm -rf ${CHROOT}
fi
}
function cleanup() {
echo "Limpiando archivos residuales..." | lolcat
if [ -f ${IMAGE_NAME} ]; then
if [ -f ${IMAGE_NAME} ]; then
rm -f ${IMAGE_NAME}
fi
if [ -f ${SHA_NAME} ]; then
rm -f ${SHA_NAME}
fi
fi
}
function check_dependencies() {
printf "\n[*] Installing packages...${reset}\n"
apt update -y && apt dist-upgrade
pkg i apt
dpkg --configure -a
rm /data/data/com.termux/files/usr/etc/profile.d/init-termux-properties.sh # This fix bugs
rm /data/data/com.termux/files/usr/etc/motd # This file bug some devices :/
pkg update -y
apt-get update -y || apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" dist-upgrade -y
dpkg --configure -a
apt install -y proot tar axel nano python python3 figlet toilet git zsh neovim wget curl zip
dpkg --configure -a
pip3 install lolcat
}
function get_url() {
ROOTFS_URL="${BASE_URL}/${IMAGE_NAME}"
SHA_URL="${BASE_URL}/${SHA_NAME}"
}
function get_rootfs() {
unset KEEP_IMAGE
if [ -f ${IMAGE_NAME} ]; then
rm -f ${IMAGE_NAME}
fi
printf "[*] Downloading rootfs...${reset}\n\n" | lolcat
get_url
wget ${EXTRA_ARGS} --continue "${ROOTFS_URL}" | lolcat
}
function get_sha() {
if [ -z $KEEP_IMAGE ]; then
printf "\n[*] Getting SHA ... ${reset}\n\n" | lolcat
get_url
if [ -f ${SHA_NAME} ]; then
rm -f ${SHA_NAME}
fi
wget ${EXTRA_ARGS} --continue "${SHA_URL}" | lolcat
fi
}
function verify_sha() {
if [ -z $KEEP_IMAGE ]; then
printf "\n[*] Verifying integrity of rootfs...${reset}\n\n" | lolcat
sha512sum -c $SHA_NAME || {
printf "Don't use unofficial nethunter rootfs.\n" | lolcat
}
fi
}
function extract_rootfs() {
printf "\n[*] Extracting rootfs...\n\n" | lolcat
proot --link2symlink tar -xf $IMAGE_NAME 2> /dev/null
}
function create_launcher() {
NH_LAUNCHER=${PREFIX}/bin/nethunter
NH_SHORTCUT=${PREFIX}/bin/nh
cat > $NH_LAUNCHER <<- EOF
#!/data/data/com.termux/files/usr/bin/bash -e
cd \${HOME}
## termux-exec sets LD_PRELOAD so let's unset it before continuing
unset LD_PRELOAD
## Workaround for Libreoffice, also needs to bind a fake /proc/version
if [ ! -f $CHROOT/root/.version ]; then
touch $CHROOT/root/.version
fi
## Default user is "kali"
user="$USERNAME"
home="/home/\$user"
start="sudo -u kali /bin/bash"
## NH can be launched as root with the "-r" cmd attribute
## Also check if user kali exists, if not start as root
if grep -q "kali" ${CHROOT}/etc/passwd; then
KALIUSR="1";
else
KALIUSR="0";
fi
if [[ \$KALIUSR == "0" || ("\$#" != "0" && ("\$1" == "-r" || "\$1" == "-R")) ]];then
user="root"
home="/\$user"
start="/bin/bash --login"
if [[ "\$#" != "0" && ("\$1" == "-r" || "\$1" == "-R") ]];then
shift
fi
fi
cmdline="proot \\
--link2symlink \\
-0 \\
-r $CHROOT \\
-b /dev \\
-b /proc \\
-b $CHROOT\$home:/dev/shm \\
-w \$home \\
/usr/bin/env -i \\
HOME=\$home \\
PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \\
TERM=\$TERM \\
LANG=C.UTF-8 \\
\$start"
cmd="\$@"
if [ "\$#" == "0" ];then
exec \$cmdline
else
\$cmdline -c "\$cmd"
fi
EOF
chmod 700 $NH_LAUNCHER
if [ -L ${NH_SHORTCUT} ]; then
rm -f ${NH_SHORTCUT}
fi
if [ ! -f ${NH_SHORTCUT} ]; then
ln -s ${NH_LAUNCHER} ${NH_SHORTCUT} >/dev/null
fi
}
function create_kex_launcher() {
KEX_LAUNCHER=${CHROOT}/usr/bin/kex
cat > $KEX_LAUNCHER <<- EOF
#!/bin/bash
function start-kex() {
if [ ! -f ~/.vnc/passwd ]; then
passwd-kex
fi
USR=\$(whoami)
if [ \$USR == "root" ]; then
SCREEN=":2"
else
SCREEN=":1"
fi
export HOME=\${HOME}; export USER=\${USR}; LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgcc_s.so.1 nohup vncserver \$SCREEN >/dev/null 2>&1 </dev/null
starting_kex=1
return 0
}
function stop-kex() {
vncserver -kill :1 | sed s/"Xtigervnc"/"NetHunter KeX"/
vncserver -kill :2 | sed s/"Xtigervnc"/"NetHunter KeX"/
return $?
}
function passwd-kex() {
vncpasswd
return $?
}
function status-kex() {
sessions=\$(vncserver -list | sed s/"TigerVNC"/"NetHunter KeX"/)
if [[ \$sessions == *"590"* ]]; then
printf "\n\${sessions}\n"
printf "\nYou can use the KeX client to connect to any of these displays.\n\n"
else
if [ ! -z \$starting_kex ]; then
printf '\nError starting the KeX server.\nPlease try "nethunter kex kill" or restart your termux session and try again.\n\n'
fi
fi
return 0
}
function kill-kex() {
pkill Xtigervnc
return \$?
}
case \$1 in
start)
start-kex
;;
stop)
stop-kex
;;
status)
status-kex
;;
passwd)
passwd-kex
;;
kill)
kill-kex
;;
*)
stop-kex
start-kex
status-kex
;;
esac
EOF
chmod 700 $KEX_LAUNCHER
}
function fix_profile_bash() {
## Prevent attempt to create links in read only filesystem
if [ -f ${CHROOT}/root/.bash_profile ]; then
sed -i '/if/,/fi/d' "${CHROOT}/root/.bash_profile"
fi
}
function fix_sudo() {
## fix sudo & su on start
chmod +s $CHROOT/usr/bin/sudo
chmod +s $CHROOT/usr/bin/su
echo "kali ALL=(ALL:ALL) ALL" > $CHROOT/etc/sudoers.d/kali
# https://bugzilla.redhat.com/show_bug.cgi?id=1773148
echo "Set disable_coredump false" > $CHROOT/etc/sudo.conf
}
function fix_uid() {
## Change kali uid and gid to match that of the termux user
USRID=$(id -u)
GRPID=$(id -g)
nh -r usermod -u $USRID kali 2>/dev/null
nh -r groupmod -g $GRPID kali 2>/dev/null
}
##################################
## Main ##
# Add some colours
red='\033[1;31m'
green='\033[1;32m'
yellow='\033[1;33m'
blue='\033[1;34m'
light_cyan='\033[1;96m'
reset='\033[0m'
EXTRA_ARGS=""
if [[ ! -z $1 ]]; then
EXTRA_ARGS=$1
if [[ $EXTRA_ARGS != "--no-check-certificate" ]]; then
EXTRA_ARGS=""
fi
fi
##############
# #
# INSTALL #
# By Genplat #
# #
##############
termux-setup-storage
sleep 3
magisk_alert
cd $HOME
check_dependencies
get_arch
set_strings
ctbanner
installzsh_theme
clonerepo
cpfiles
ctbanner
prepare_fs
ctbanner
get_rootfs
ctbanner
get_sha
ctbanner
verify_sha
ctbanner
extract_rootfs
confprof
ctbanner
create_launcher
ctbanner
cleanup
ctbanner
printf "\n[*] Configuring NetHunter for Termux ...\n" | lolcat
fix_profile_bash
fix_sudo
create_kex_launcher
fix_uid
echo "Installed! Clossing in 10s..." | lolcat
sleep 10
login