-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrade_me.sh
executable file
·876 lines (799 loc) · 27.5 KB
/
grade_me.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
#!/bin/bash
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#> Config
PROMPT_OFFSET=1
TITLE_LENGTH=80
# CHARACTER * N (BASH)
# https://stackoverflow.com/a/17030976
PROMPT_OFFSET=$(printf "%0.s " $(seq 1 ${PROMPT_OFFSET}))
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#> Bash Color (printable)
red="\x1b[38;5;196m"
green="\x1b[38;5;82m"
blue="\x1b[38;5;75m"
orange="\x1b[38;5;214m"
blink="\x1b[5m"
reset="\x1b[0m"
SUCCESS="[${green}+${reset}] "
FAILED="[${red}-${reset}] "
UL="\xe2\x95\x94"
HO="\xe2\x95\x90"
UR="\xe2\x95\x97"
VE="\xe2\x95\x91"
LL="\xe2\x95\x9a"
LR="\xe2\x95\x9d"
HEART="${blink}\xe2\x99\xa5${reset}"
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#> Utils
function check_root()
{
if [ ${EUID} != 0 ]; then
p_error "Run as root."
fi
}
function p_error()
{
printf "[${PROMPT_OFFSET}${red}ERROR${PROMPT_OFFSET}${reset}] $*\n"
exit
}
function p_info()
{
printf "[${PROMPT_OFFSET}${blue}INFO${PROMPT_OFFSET}${reset}] $*\n"
}
function p_warn()
{
printf "[${PROMPT_OFFSET}${orange}WARN${PROMPT_OFFSET}${reset}] $*\n"
}
function usage()
{
[ ! -z "${1}" ] && p_warn "$1"
printf "Usage : ${0} -u LOGIN [-m MONITORING_PATH]\n"
printf "\t-h : show this help\n"
printf "\t-u : the login of the student\n"
printf "\t-m : the path of the monitoring \n"
exit
}
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#> Crontab check
function check_cron_schedule()
{
crontab_line=$(sudo crontab -l 2>/dev/null | grep "${MONITORING_PATH}")
minute=$(echo "${crontab_line}" | cut -d' ' -f1)
hour=$(echo "${crontab_line}" | cut -d' ' -f2)
day_m=$(echo "${crontab_line}" | cut -d' ' -f3)
month=$(echo "${crontab_line}" | cut -d' ' -f4)
day_w=$(echo "${crontab_line}" | cut -d' ' -f5)
cron_4=1
[ "${minute}" != "*/10" ] && cron_4=0
[ "${hour}" != "*" ] && cron_4=0
[ "${day_m}" != "*" ] && cron_4=0
[ "${month}" != "*" ] && cron_4=0
[ "${day_w}" != "*" ] && cron_4=0
}
function check_have_cron()
{
# /var/spool/cron/crontabs/${LOGIN}
crontab=$(sudo crontab -l 2>/dev/null | grep -v '^#')
is_monitoring=$(echo "${crontab}" | cut -d' ' -f6-)
is_monitoring=$(echo "${is_monitoring}" | grep -o "${MONITORING_PATH}")
[ ! -z "${crontab}" ] && cron_1=1 || cron_1=0
[ ! -z "${is_monitoring}" ] && cron_2=1 || cron_2=0
[ -f "${is_monitoring/*sh /}" ] && cron_3=1 || cron_3=0
}
function check_crontab()
{
check_have_cron
check_cron_schedule
}
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#> basic check
function check_lvm()
{
number_of_lvm=$(lsblk | grep "lvm" | wc -l)
is_crypted=$(lsblk | grep "crypt" | wc -l)
[ ${number_of_lvm} -ge 2 ] && lvm_1=1 || lvm_1=0
[ ${is_crypted} -ge 1 ] && lvm_2=1 || lvm_2=0
}
function check_ssh()
{
is_installed=$(sudo systemctl list-units 2>/dev/null | grep -o ssh)
ssh_port=$(sed -nE 's|^Port\s*([0-9]*).*|\1|p' /etc/ssh/sshd_config 2>/dev/null)
prohibit_root=$(sed -nE 's|^PermitRootLogin\s*(no).*|\1|p' /etc/ssh/sshd_config 2>/dev/null)
[ ${is_installed} ] && ssh_1=1 || ssh_1=0
[ "${ssh_port}" == 4242 ] && ssh_2=1 || ssh_2=0
[ ${prohibit_root} ] && ssh_3=1 || ssh_3=0
}
function check_ufw()
{
is_installed=$(sudo which ufw 2>/dev/null)
is_enabled=$(sudo ufw status 2>/dev/null | sed -nE 's|Status: (active)|\1|p')
rule_1=$(sudo ufw status 2>/dev/null | sed -znE 's|.*4242.*(ALLOW).*|\1|p')
rule_2=$(sudo ufw status 2>/dev/null | sed -znE 's|.*4242/(udp).*ALLOW.*|\1|p')
[ ${is_installed} ] && ufw_1=1 || ufw_1=0
[ ${is_enabled} ] && ufw_2=1 || ufw_2=0
[ "${rule_1}" == "ALLOW" ] && ufw_3=1 || ufw_3=0
[ "${rule_2}" == "udp" ] && ufw_4=0 || ufw_4=1
}
function check_hostname()
{
hostname="${LOGIN}42"
hosts=$(sed -nE 's|127.0.0.1\t([a-z0-9\-]{1,63})|\1|p' /etc/hosts)
[ "${hostname}" == $(hostname) ] && hostname_1=1 || hostname_1=0
if [ "${hosts}" == "localhost" ]; then
hosts2=$(sed -nE 's|127.0.1.1\t([a-z0-9\-]{1,63})|\1|p' /etc/hosts)
[ "${hosts2}" == ${hostname} ] && hostname_2=1 || hostname_2=0
else
[ "${hosts}" == ${hostname} ] && hostname_2=1 || hostname_2=0
fi
}
function check_pam_and_sec()
{
is_in_common=$(grep -v '^#' /etc/pam.d/common-password 2>/dev/null | \
grep "pam_pwquality\|pam_cracklib" | \
sed -nE "s|.*?${1}\s*?=\s*?([0-9-]*).*|\1|p" 2>/dev/null | \
tail -n1)
if [ -z ${is_in_common} ]; then
is_in_security=$(grep -v '^#' /etc/security/pwquality.conf 2>/dev/null | \
sed -nE "s|.*?${1}\s*?=\s*?([0-9-]*).*|\1|p" 2>/dev/null)
if [ -z ${is_in_security} ]; then
return 0
else
return ${is_in_security}
fi
else
return ${is_in_common}
fi
}
function check_strong_password_user()
{
rule_username_usercheck_1=$(grep -v "^#" /etc/pam.d/common-password | sed -nE 's|(usercheck\s*?=\s*?0)|\1|p')
rule_username_usercheck_2=$(grep -v "^#" /etc/security/pwquality.conf 2>/dev/null \ |
sed -nE 's|(usercheck\s*?=\s*?0)|\1|p' 2>/dev/null)
rule_username_rejectuser_1=$(grep -v "^#" /etc/pam.d/common-password | grep -o 'reject_username')
if [ "${rule_username_usercheck_1}" ] || [ "${rule_username_usercheck_2}" ]; then
pwquality_16=0
if [ "${rule_username_rejectuser_1}" ]; then
pwquali2>/dev/nullty_16=1
fi
else
pwquality_16=1
fi
}
function check_strong_password()
{
rule_user_max=$(sudo grep "${LOGIN}" /etc/shadow | cut -d":" -f5)
rule_user_min=$(sudo grep "${LOGIN}" /etc/shadow | cut -d":" -f4)
rule_user_warn=$(sudo grep "${LOGIN}" /etc/shadow | cut -d":" -f6)
rule_root_max=$(sudo grep "root" /etc/shadow | cut -d":" -f5)
rule_root_min=$(sudo grep "root" /etc/shadow | cut -d":" -f4)
rule_root_warn=$(sudo grep "root" /etc/shadow | cut -d":" -f6)
rule_new_max=$(sed -nE "s|PASS_MAX_DAYS.*(30).*|\1|p" /etc/login.defs 2>/dev/null)
rule_new_min=$(sed -nE "s|PASS_MIN_DAYS.*(2).*|\1|p" /etc/login.defs 2>/dev/null)
rule_new_warn=$(sed -nE "s|PASS_WARN_AGE.*(7).*|\1|p" /etc/login.defs 2>/dev/null)
check_pam_and_sec "minlen"
rule_min_char=${?}
check_pam_and_sec "ucredit"
rule_upper=${?}
check_pam_and_sec "lcredit"
rule_lower=${?}
check_pam_and_sec "dcredit"
rule_digit=${?}
check_pam_and_sec "maxrepeat"
rule_maxrepeat=${?}
check_strong_password_user
check_pam_and_sec "difok"
rule_diff_old=${?}
is_in_common=$(grep -v '^#' /etc/pam.d/common-password 2>/dev/null | sed -nE "s|.*?(enforce_for_root).*|\1|p" 2>/dev/null)
if [ -z ${is_in_common} ]; then
is_in_security=$(grep -v '^#' /etc/security/pwquality.conf 2>/dev/null | sed -nE "s|.*?(enforce_for_root).*|\1|p" 2>/dev/null)
if [ -z "${is_in_security}" ]; then
rule_force_root="0"
else
rule_force_root=${is_in_security}
fi
else
rule_force_root=${is_in_common}
fi
if [ -f "/usr/lib/x86_64-linux-gnu/security/pam_pwquality.so" ] || \
[ -f "/usr/lib/x86_64-linux-gnu/security/pam_cracklib.so" ]; then
pwquality_1=1
else
pwquality_1=0
fi
[ "${rule_user_max}" == 30 ] && pwquality_2=1 || pwquality_2=0
[ "${rule_user_min}" == 2 ] && pwquality_3=1 || pwquality_3=0
[ "${rule_user_warn}" == 7 ] && pwquality_4=1 || pwquality_4=0
[ "${rule_root_max}" == 30 ] && pwquality_5=1 || pwquality_5=0
[ "${rule_root_min}" == 2 ] && pwquality_6=1 || pwquality_6=0
[ "${rule_root_warn}" == 7 ] && pwquality_7=1 || pwquality_7=0
[ "${rule_new_max}" == 30 ] && pwquality_8=1 || pwquality_8=0
[ "${rule_new_min}" == 2 ] && pwquality_9=1 || pwquality_9=0
[ "${rule_new_warn}" == 7 ] && pwquality_10=1 || pwquality_10=0
[ "${rule_min_char}" == 10 ] && pwquality_11=1 || pwquality_11=0
[ "${rule_upper}" == 255 ] && pwquality_12=1 || pwquality_12=0
[ "${rule_lower}" == 255 ] && pwquality_13=1 || pwquality_13=0
[ "${rule_digit}" == 255 ] && pwquality_14=1 || pwquality_14=0
[ "${rule_maxrepeat}" == 3 ] && pwquality_15=1 || pwquality_15=0
[ "${rule_diff_old}" == 7 ] && pwquality_17=1 || pwquality_17=0
[ "${rule_force_root}" == "enforce_for_root" ] && pwquality_18=1 || pwquality_18=0
}
function check_strict_sudo()
{
passwd_tries=$(sudo sed -nE 's|^Default.*passwd_tries=(3).*|\1|p' /etc/sudoers 2>/dev/null)
passwd_tries_2=$(sudo sed -nE 's|^Default.*(passwd_tries=).*|\1|p' /etc/sudoers 2>/dev/null)
passwd_message=$(sudo sed -nE 's|^Default.*badpass_message="(.+)".*|\1|p' /etc/sudoers 2>/dev/null)
passwd_message_2=$(sudo sed -nE 's|^Default.*(insults).*|\1|p' /etc/sudoers 2>/dev/null)
passwd_input=$(sudo sed -nE 's|^Default.*(log_input).*|\1|p' /etc/sudoers 2>/dev/null)
passwd_output=$(sudo sed -nE 's|^Default.*(log_output).*|\1|p' /etc/sudoers 2>/dev/null)
log_path="/var/log/sudo/sudo.log"
passwd_log=$(sudo sed -nE "s|^Default.*logfile=\"?(${log_path})\"?.*|\1|p" /etc/sudoers 2>/dev/null)
passwd_tty=$(sudo sed -nE 's|^Default.*(requiretty).*|\1|p' /etc/sudoers 2>/dev/null)
restricted_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
passwd_secure_path=$(sudo sed -nE "s|^Default.*(secure_path=\"?.+\"?).*|\1|p" /etc/sudoers 2>/dev/null)
if [ "${passwd_tries}" ]; then
sudo_1=1
elif [ ! "${passwd_tries_2}" ]; then
sudo_1=1
else
sudo_1=0
fi
if [ "${passwd_message}" ]; then
sudo_2=1
elif [ "${passwd_message_2}" ]; then
sudo_2=1
else
sudo_2=0
fi
[ "${passwd_input}" ] && sudo_3=1 || sudo_3=0
[ "${passwd_output}" ] && sudo_4=1 || sudo_4=0
[ "${passwd_log}" ] && sudo_5=1 || sudo_5=0
[ "${passwd_tty}" ] && sudo_6=1 || sudo_6=0
[ "${passwd_secure_path}" ] && sudo_7=1 || sudo_7=0
}
function check_username()
{
username=$(cat /etc/passwd | grep -o ${LOGIN} | uniq)
have_sudo=$(id ${LOGIN} 2>/dev/null | grep -o sudo)
have_user42=$(id ${LOGIN} 2>/dev/null | grep -o user42)
[ "${username}" == "${LOGIN}" ] && username_1=1 || username_1=0
[ "${have_sudo}" ] && username_2=1 || username_2=0
[ "${have_user42}" ] && username_3=1 || username_3=0
}
function check_c()
{
s=$(./.s)
r=$(echo ${s} | grep -o "${LOGIN}")
[ ! -z "${r}" ] && coa_1=1 || coa_1=0
}
function check_mandatory()
{
check_c
check_lvm
check_ssh
check_ufw
check_hostname
check_strong_password
check_strict_sudo
check_username
}
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#> make the report according to result
function echo_deep_section()
{
vertical_offset=$(printf "%0.s${HO}" $(seq 1 ${TITLE_LENGTH}))
center_off=$(( ${TITLE_LENGTH} - ${#1}))
center_splited=$(( ${center_off} / 2 ))
if [ $(( ${center_off} % 2)) == 0 ]; then
CL=$(printf "%0.s " $(seq 1 ${center_splited}))
CR=$(printf "%0.s " $(seq 1 ${center_splited}))
else
CL=$(printf "%0.s " $(seq 1 ${center_splited}))
CR=$(printf "%0.s " $(seq 1 ${center_splited}) 1)
fi
printf "${red}${UL}${vertical_offset}${UR}\n" >> deepthought
printf "${VE}${CL}${reset}${1}${red}${CR}${VE}\n" >> deepthought
printf "${LL}${vertical_offset}${LR}${reset}\n" >> deepthought
}
function echo_deep_part()
{
printf "${green}${1}${reset}:\n" >> deepthought
}
function echo_deep()
{
printf "\t${blink}${orange}WARNING${reset}: ${1}\n" >> deepthought
}
function report_lvm_crypted()
{
echo_deep_part "LVM_CRYPTED"
if [ "${lvm_1}" == 0 ]; then
echo_deep "your virtual machine don't have at least 2 LVM partition"
fi
if [ "${lvm_2}" == 0 ]; then
echo_deep "your virtual machine don't use crypted LVM"
fi
}
function report_ssh()
{
echo_deep_part "SSH_SERVER"
if [ "${ssh_1}" == 0 ]; then
echo_deep "openssh-server is not installed"
fi
if [ "${ssh_2}" == 0 ]; then
echo_deep "wrong port, ${ssh_port} instead of 4242"
fi
if [ "${ssh_3}" == 0 ]; then
echo_deep "you don't prevent root to login from ssh"
fi
}
function report_ufw()
{
echo_deep_part "FIREWALL"
if [ "${ufw_1}" == 0 ]; then
echo_deep "ufw is not installed"
fi
if [ "${ufw_2}" == 0 ]; then
echo_deep "ufw is not enabled"
fi
if [ "${ufw_3}" == 0 ]; then
echo_deep "ufw don't have a rule for 4242"
fi
if [ "${ufw_4}" == 0 ]; then
echo_deep "SSH use tcp, not udp"
fi
}
function report_hostname()
{
echo_deep_part "HOSTNAME"
if [ "${hostname_1}" == 0 ]; then
echo_deep "the command hostname ($(hostname)) don't return ${LOGIN}42"
fi
if [ "${hostname_2}" == 0 ]; then
echo_deep "your hosts file is not configured properly"
fi
}
function report_strong_password()
{
echo_deep_part "STRONG_PASSWORD"
if [ "${pwquality_1}" == 0 ]; then
echo_deep "the 'libpam-pwquality' package is not installed"
fi
if [ "${pwquality_2}" == 0 ]; then
echo_deep "wrong current user password expiration"
fi
if [ "${pwquality_3}" == 0 ]; then
echo_deep "wrong current user minimum day with a password"
fi
if [ "${pwquality_4}" == 0 ]; then
echo_deep "wrong current user day before warning"
fi
if [ "${pwquality_5}" == 0 ]; then
echo_deep "wrong root password expiration"
fi
if [ "${pwquality_6}" == 0 ]; then
echo_deep "wrong root minimum day with a password"
fi
if [ "${pwquality_7}" == 0 ]; then
echo_deep "wrong root day before warning"
fi
if [ "${pwquality_8}" == 0 ]; then
echo_deep "wrong new user password expiration"
fi
if [ "${pwquality_9}" == 0 ]; then
echo_deep "wrong new user minimum day with a password"
fi
if [ "${pwquality_10}" == 0 ]; then
echo_deep "wrong new user day before warning"
fi
if [ "${pwquality_11}" == 0 ]; then
echo_deep "wrong minimum length for a password"
fi
if [ "${pwquality_12}" == 0 ]; then
echo_deep "wrong minimum upper character for a password"
fi
if [ "${pwquality_13}" == 0 ]; then
echo_deep "wrong minimum lower character for a password"
fi
if [ "${pwquality_14}" == 0 ]; then
echo_deep "wrong minimum digit character for a password"
fi
if [ "${pwquality_15}" == 0 ]; then
echo_deep "wrong max consecutive character in a password"
fi
if [ "${pwquality_16}" == 0 ]; then
echo_deep "password can't have the username in it"
fi
if [ "${pwquality_17}" == 0 ]; then
echo_deep "password can't have more than 7 character that is in the old one"
fi
if [ "${pwquality_18}" == 0 ]; then
echo_deep "password policy must be applied to root"
fi
}
function report_strict_sudo()
{
echo_deep_part "STRICT_SUDO"
if [ "${sudo_1}" == 0 ]; then
echo_deep "wrong sudo max tries"
fi
if [ "${sudo_2}" == 0 ]; then
echo_deep "you don't have set message or is empty"
fi
if [ "${sudo_3}" == 0 ]; then
echo_deep "you don't store input sudo log"
fi
if [ "${sudo_4}" == 0 ]; then
echo_deep "you don't store output sudo log"
fi
if [ "${sudo_5}" == 0 ]; then
echo_deep "you don't store sudo log in the correct folder"
fi
if [ "${sudo_6}" == 0 ]; then
echo_deep "you don't activate TTY"
fi
if [ "${sudo_7}" == 0 ]; then
echo_deep "you don't have set the secure_path"
fi
}
function report_username()
{
echo_deep_part "USER/GROUPS"
if [ "${username_1}" == 0 ]; then
echo_deep "your user don't exist or don't have the correct name"
fi
if [ "${username_2}" == 0 ]; then
echo_deep "your user don't belong to sudo group"
fi
if [ "${username_3}" == 0 ]; then
echo_deep "your user don't belong to user42 group"
fi
}
function report_crontab()
{
echo_deep_part "CRON_TAB"
if [ "${cron_1}" == 0 ]; then
echo_deep "your crontab doesn't have any jobs"
fi
if [ "${cron_2}" == 0 ]; then
echo_deep "your crontab doesn't execute a 'monitoring' scripts"
fi
if [ "${cron_3}" == 0 ]; then
echo_deep "your script in the crontab doesn't exists"
fi
if [ "${cron_4}" == 0 ]; then
echo_deep "your schedule is not in the correct format"
fi
}
function report_check_part()
{
[ "${lvm_1}" == 1 ] && \
[ "${lvm_2}" == 1 ] && lvm_success=1
[ "${ssh_1}" == 1 ] && \
[ "${ssh_2}" == 1 ] && \
[ "${ssh_3}" == 1 ] && ssh_success=1
[ "${ufw_1}" == 1 ] && \
[ "${ufw_2}" == 1 ] && \
[ "${ufw_3}" == 1 ] && \
[ "${ufw_4}" == 1 ] && ufw_success=1
[ "${hostname_1}" == 1 ] && \
[ "${hostname_2}" == 1 ] && hostname_success=1
[ "${pwquality_1}" == 1 ] && \
[ "${pwquality_2}" == 1 ] && \
[ "${pwquality_3}" == 1 ] && \
[ "${pwquality_4}" == 1 ] && \
[ "${pwquality_5}" == 1 ] && \
[ "${pwquality_6}" == 1 ] && \
[ "${pwquality_7}" == 1 ] && \
[ "${pwquality_8}" == 1 ] && \
[ "${pwquality_9}" == 1 ] && \
[ "${pwquality_10}" == 1 ] && \
[ "${pwquality_11}" == 1 ] && \
[ "${pwquality_12}" == 1 ] && \
[ "${pwquality_13}" == 1 ] && \
[ "${pwquality_14}" == 1 ] && \
[ "${pwquality_15}" == 1 ] && \
[ "${pwquality_16}" == 1 ] && \
[ "${pwquality_17}" == 1 ] && \
[ "${pwquality_18}" == 1 ] && pwquality_success=1
[ "${sudo_1}" == 1 ] && \
[ "${sudo_2}" == 1 ] && \
[ "${sudo_3}" == 1 ] && \
[ "${sudo_4}" == 1 ] && \
[ "${sudo_5}" == 1 ] && \
[ "${sudo_6}" == 1 ] && \
[ "${sudo_7}" == 1 ] && sudo_success=1
[ "${username_1}" == 1 ] && \
[ "${username_2}" == 1 ] && \
[ "${username_3}" == 1 ] && username_success=1
[ "${cron_1}" == 1 ] && \
[ "${cron_2}" == 1 ] && \
[ "${cron_3}" == 1 ] && \
[ "${cron_4}" == 1 ] && cron_success=1
}
function report_check_section()
{
[ "${lvm_success}" == "1" ] && \
[ "${ssh_success}" == "1" ] && \
[ "${ufw_success}" == "1" ] && \
[ "${hostname_success}" == "1" ] && \
[ "${pwquality_success}" == "1" ] && \
[ "${sudo_success}" == "1" ] && \
[ "${username_success}" == "1" ] && mandatory_succes=1
[ "${cron_success}" == "1" ] && monitoring_success=1
}
function report_c()
{
[ "${coa_1}" == 1 ] && echo_deep_section "COALITIONS :)"
[ "${coa_1}" == 1 ] && echo_deep_part "COA"
[ "${coa_1}" == 1 ] && echo_deep "You have choosen the BEST coalitions ${HEART}"
}
function make_report()
{
tabs 4
[ -f deepthought ] && rm deepthought
report_check_part
report_check_section
[ "${mandatory_succes}" == "1" ] || echo_deep_section "MANDATORY"
[ "${lvm_success}" == "1" ] || report_lvm_crypted
[ "${ssh_success}" == "1" ] || report_ssh
[ "${ufw_success}" == "1" ] || report_ufw
[ "${hostname_success}" == "1" ] || report_hostname
[ "${pwquality_success}" == "1" ] || report_strong_password
[ "${sudo_success}" == "1" ] || report_strict_sudo
[ "${username_success}" == "1" ] || report_username
report_c
if [ ! -z ${MONITORING_PATH} ]; then
[ "${monitoring_succes}" == "1" ] || echo_deep_section "MONITORING"
[ "${cron_success}" == "1" ] || report_crontab
fi
}
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#> print result
function print_subpart()
{
printf "[${PROMPT_OFFSET}${red}ERRO${PROMPT_OFFSET}${reset}] $*\n"
}
function print_subpart_title()
{
printf "${green}$*${reset}:\t"
}
function print_title()
{
vertical_offset=$(printf "%0.s${HO}" $(seq 1 ${TITLE_LENGTH}))
center_off=$(( ${TITLE_LENGTH} - ${#1}))
center_splited=$(( ${center_off} / 2 ))
if [ $(( ${center_off} % 2)) == 0 ]; then
CL=$(printf "%0.s " $(seq 1 ${center_splited}))
CR=$(printf "%0.s " $(seq 1 ${center_splited}))
else
CL=$(printf "%0.s " $(seq 1 ${center_splited}))
CR=$(printf "%0.s " $(seq 1 ${center_splited}) 1)
fi
printf "${blue}${UL}${vertical_offset}${UR}\n"
printf "${VE}${CL}${reset}${1}${blue}${CR}${VE}\n"
printf "${LL}${vertical_offset}${LR}${reset}\n\n"
}
function print_lvm_crypted()
{
print_subpart_title "LVM_CRYPTED"
[ ${lvm_1} == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ ${lvm_2} == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
printf "\n"
[ ${lvm_1} == 1 ] || print_subpart "your virtual machine don't have at least 2 LVM partition"
[ ${lvm_2} == 1 ] || print_subpart "your virtual machine don't use crypted LVM"
printf "\n"
}
function print_ssh()
{
print_subpart_title "SSH_SERVER"
[ ${ssh_1} == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ ${ssh_2} == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ ${ssh_3} == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
printf "\n"
[ ${ssh_1} == 1 ] || print_subpart "openssh-server is not installed"
[ ${ssh_2} == 1 ] || print_subpart "wrong port, ${ssh_port} instead of 4242"
[ ${ssh_3} == 1 ] || print_subpart "you don't prevent root to login from ssh"
printf "\n"
}
function print_ufw()
{
print_subpart_title "FIREWALL"
[ ${ufw_1} == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ ${ufw_2} == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ ${ufw_3} == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ ${ufw_4} == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
printf "\n"
[ ${ufw_1} == 1 ] || print_subpart "ufw is not installed"
[ ${ufw_2} == 1 ] || print_subpart "ufw is not enabled"
[ ${ufw_3} == 1 ] || print_subpart "ufw don't have a rule for 4242"
[ ${ufw_4} == 1 ] || print_subpart "SSH use tcp, not udp"
printf "\n"
}
function print_hostname()
{
print_subpart_title "HOSTNAME"
[ ${hostname_1} == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ ${hostname_2} == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
printf "\n"
[ ${hostname_1} == 1 ] || print_subpart "the command hostname ($(hostname)) don't return ${LOGIN}42"
[ ${hostname_2} == 1 ] || print_subpart "your hosts file is not configured properly"
printf "\n"
}
function print_strong_password()
{
print_subpart_title "STRONG PASSWORD"
[ "${pwquality_1}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_2}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_3}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_4}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_5}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_6}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_7}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_8}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_9}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_10}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_11}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_12}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_13}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_14}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_15}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_16}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_17}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${pwquality_18}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
printf "\n"
[ "${pwquality_1}" == 1 ] || print_subpart "the 'libpam-pwquality' package is not installed"
[ "${pwquality_2}" == 1 ] || print_subpart "wrong current user password expiration"
[ "${pwquality_3}" == 1 ] || print_subpart "wrong current user minimum day with a password"
[ "${pwquality_4}" == 1 ] || print_subpart "wrong current user day before warning"
[ "${pwquality_5}" == 1 ] || print_subpart "wrong root password expiration"
[ "${pwquality_6}" == 1 ] || print_subpart "wrong root minimum day with a password"
[ "${pwquality_7}" == 1 ] || print_subpart "wrong root day before warning"
[ "${pwquality_8}" == 1 ] || print_subpart "wrong new user password expiration"
[ "${pwquality_9}" == 1 ] || print_subpart "wrong new user minimum day with a password"
[ "${pwquality_10}" == 1 ] || print_subpart "wrong new user day before warning"
[ "${pwquality_11}" == 1 ] || print_subpart "wrong minimum length for a password"
[ "${pwquality_12}" == 1 ] || print_subpart "wrong minimum upper character for a password"
[ "${pwquality_13}" == 1 ] || print_subpart "wrong minimum lower character for a password"
[ "${pwquality_14}" == 1 ] || print_subpart "wrong minimum digit character for a password"
[ "${pwquality_15}" == 1 ] || print_subpart "wrong max consecutive character in a password"
[ "${pwquality_16}" == 1 ] || print_subpart "password can't have the username in it"
[ "${pwquality_17}" == 1 ] || print_subpart "password can't have more than 7 character that is in the old one"
[ "${pwquality_18}" == 1 ] || print_subpart "password policy must be applied to root"
printf "\n"
}
function print_strict_sudo()
{
print_subpart_title "STRICT SUDO"
[ "${sudo_1}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${sudo_2}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${sudo_3}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${sudo_4}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${sudo_5}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${sudo_6}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${sudo_7}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
printf "\n"
[ "${sudo_1}" == 1 ] || print_subpart "wrong sudo max tries"
[ "${sudo_2}" == 1 ] || print_subpart "you don't have set message or is empty"
[ "${sudo_3}" == 1 ] || print_subpart "you don't store input sudo log"
[ "${sudo_4}" == 1 ] || print_subpart "you don't store output sudo log"
[ "${sudo_5}" == 1 ] || print_subpart "you don't store sudo log in the correct folder"
[ "${sudo_6}" == 1 ] || print_subpart "you don't activate TTY"
[ "${sudo_7}" == 1 ] || print_subpart "you don't have set the secure_path"
printf "\n"
}
function print_username()
{
print_subpart_title "USERNAME / GROUPS"
[ "${username_1}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${username_2}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${username_3}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
printf "\n"
[ "${username_1}" == 1 ] || print_subpart "your user don't exist or don't have the correct name"
[ "${username_2}" == 1 ] || print_subpart "your user don't belong to sudo group"
[ "${username_3}" == 1 ] || print_subpart "your user don't belong to user42 group"
printf "\n"
}
function print_mandatory()
{
if [ -z "${MONITORING_PATH}" ]; then
p_warn "Monitoring path not specified"
printf "\n"
fi
print_lvm_crypted
print_ssh
print_ufw
print_hostname
print_strong_password
print_strict_sudo
print_username
print_c
}
function print_cron()
{
print_subpart_title "CRONTAB SETTINGS"
[ "${cron_1}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${cron_2}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${cron_3}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
[ "${cron_4}" == 1 ] && printf "${SUCCESS}" || printf "${FAILED}"
printf "\n"
[ "${cron_1}" == 1 ] || print_subpart "your crontab doesn't have any jobs"
[ "${cron_2}" == 1 ] || print_subpart "your crontab doesn't execute a 'monitoring' scripts"
[ "${cron_3}" == 1 ] || print_subpart "your script in the crontab doesn't exists"
[ "${cron_4}" == 1 ] || print_subpart "your schedule is not in the correct format"
printf "\n"
}
function print_c()
{
[ "${coa_1}" == 1 ] && print_subpart_title "COALITION"
[ "${coa_1}" == 1 ] && printf "${SUCCESS}\n"
[ "${coa_1}" == 1 ] && print_subpart "You have choosen the BEST coalition ${HEART}\n"
}
function print_crontab()
{
print_cron
}
function print_result()
{
print_mandatory
[ -z ${MONITORING_PATH} ] || print_crontab
}
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
#> Main
function basic_config()
{
if [ -z ${LOGIN} ]; then
usage "Login (-u) is require"
else
print_title "Welcome ${LOGIN}."
fi
}
function check()
{
check_mandatory
[ -z ${MONITORING_PATH} ] || check_crontab
}
function main()
{
tabs 20
check_root
clear
basic_config
check
print_result
make_report
}
while [ "$1" != "" ]; do
case $1 in
-u)
shift
if [ -z ${1} ]; then
usage "-u must be followed by your login"
else
LOGIN="${1}"
fi
;;
-m)
shift
if [ -z ${1} ]; then
usage "-m must be followed by the path of the monitoring script"
elif [ ! -f ${1} ]; then
p_error "Wrong monitoring path"
else
MONITORING_PATH=$(realpath ${1})
fi
;;
-h)
usage
;;
*)
usage "Wrong args"
;;
esac
shift
done
main
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#==#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#