-
Notifications
You must be signed in to change notification settings - Fork 63
/
helper1_4_1.sh
146 lines (123 loc) · 3.29 KB
/
helper1_4_1.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
#!/bin/sh
if [ -n "$nocolor" ] && [ "$nocolor" = "nocolor" ]; then
bldred=''
bldgrn=''
bldblu=''
bldylw=''
bldcyn=''
bldgry=''
txtrst=''
else
bldred='\033[1;31m'
bldgrn='\033[1;32m'
bldblu='\033[1;34m'
bldylw='\033[1;33m'
bldcyn='\033[1;36m'
bldgry='\033[1;37m'
txtrst='\033[0m'
fi
notScored="1.1.1, 1.1.12, 1.1.13, 1.1.31, 1.4.9, 1.4.10, 1.5.7, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8,
1.7.1, 1.7.6, 1.7.7, 2.1.11, 2.1.14"
level2="1.3.6, 1.5.7, 1.6.1, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8,
1.7.6, 1.7.7"
info () {
s_txt=""
if echo "$1" | grep -q "(Scored)"; then
s_txt="${bldcyn}[Scored]${txtrst}"
elif echo "$1" | grep -q "(Not Scored)"; then
s_txt="${bldcyn}[Not Scored]${txtrst}"
fi
level_txt=""
if [ ${#s_txt} -ne 0 ]; then
idx=$(echo "$1" | cut -d " " -f 1)
if echo "$level2" | grep -q "\<${idx}\>"; then
level_txt="${bldgry}[Level 2]${txtrst}"
else
level_txt="${bldgry}[Level 1]${txtrst}"
fi
fi
printf "%b\n" "${bldblu}[INFO]${txtrst}${level_txt}${s_txt} $1"
}
pass () {
s_txt=""
if echo "$1" | grep -q "(Scored)"; then
s_txt="${bldcyn}[Scored]${txtrst}"
elif echo "$1" | grep -q "(Not Scored)"; then
s_txt="${bldcyn}[Not Scored]${txtrst}"
fi
level_txt=""
if [ ${#s_txt} -ne 0 ]; then
idx=$(echo "$1" | cut -d " " -f 1)
if echo "$level2" | grep -q "\<${idx}\>"; then
level_txt="${bldgry}[Level 2]${txtrst}"
else
level_txt="${bldgry}[Level 1]${txtrst}"
fi
fi
printf "%b\n" "${bldgrn}[PASS]${txtrst}${level_txt}${s_txt} $1"
}
warn () {
s_txt=""
if echo "$1" | grep -q "(Scored)"; then
s_txt="${bldcyn}[Scored]${txtrst}"
elif echo "$1" | grep -q "(Not Scored)"; then
s_txt="${bldcyn}[Not Scored]${txtrst}"
fi
level_txt=""
if [ ${#s_txt} -ne 0 ]; then
idx=$(echo "$1" | cut -d " " -f 1)
if echo "$level2" | grep -q "\<${idx}\>"; then
level_txt="${bldgry}[Level 2]${txtrst}"
else
level_txt="${bldgry}[Level 1]${txtrst}"
fi
fi
printf "%b\n" "${bldred}[WARN]${txtrst}${level_txt}${s_txt} $1"
}
yell () {
printf "%b\n" "${bldylw}$1${txtrst}\n"
}
yell "# ------------------------------------------------------------------------------
# Kubernetes CIS benchmark
#
# NeuVector, Inc. (c) 2020-
#
# NeuVector delivers an application and network intelligent container security
# solution that automatically adapts to protect running containers. Don’t let
# security concerns slow down your CI/CD processes.
# ------------------------------------------------------------------------------"
#get a process command line from /proc
get_command_line_args() {
PROC="$1"
len=${#PROC}
if [ $len -gt 15 ]; then
ps aux|grep "$CMD "|grep -v "grep" |sed "s/.*$CMD \(.*\)/\1/g"
else
for PID in $(pgrep -n "$PROC")
do
tr "\0" " " < /proc/"$PID"/cmdline
done
fi
}
#get an argument value from command line
get_argument_value() {
CMD="$1"
OPTION="$2"
get_command_line_args "$CMD" |
sed \
-e 's/\-\-/\n--/g' \
|
grep "^${OPTION}" |
sed \
-e "s/^${OPTION}=//g"
}
#check whether an argument exist in command line
check_argument() {
CMD="$1"
OPTION="$2"
get_command_line_args "$CMD" |
sed \
-e 's/\-\-/\n--/g' \
|
grep "^${OPTION}"
}