|
1 | 1 | #!/bin/bash |
2 | 2 | LSDIR='/usr/local/lsws' |
3 | 3 | OWASP_DIR="${LSDIR}/conf/owasp" |
| 4 | +CRS_DIR='owasp-modsecurity-crs' |
4 | 5 | RULE_FILE='modsec_includes.conf' |
5 | 6 | LS_HTTPD_CONF="${LSDIR}/conf/httpd_config.xml" |
6 | 7 | OLS_HTTPD_CONF="${LSDIR}/conf/httpd_config.conf" |
7 | 8 | EPACE=' ' |
8 | | -OWASP_V='3.3.4' |
| 9 | +OWASP_V='4.2.0' |
9 | 10 |
|
10 | 11 | echow(){ |
11 | 12 | FLAG=${1} |
@@ -90,7 +91,7 @@ enable_ls_modsec(){ |
90 | 91 | <censorshipRuleSet>\n\ |
91 | 92 | <name>ModSec</name>\n\ |
92 | 93 | <enabled>1</enabled>\n\ |
93 | | - <ruleSet>include ${OWASP_DIR}/modsec_includes.conf</ruleSet>\n\ |
| 94 | + <ruleSet>include ${OWASP_DIR}/${RULE_FILE}</ruleSet>\n\ |
94 | 95 | </censorshipRuleSet>=" ${LS_HTTPD_CONF} |
95 | 96 | fi |
96 | 97 | } |
@@ -146,68 +147,50 @@ install_unzip(){ |
146 | 147 | fi |
147 | 148 | } |
148 | 149 |
|
| 150 | +backup_owasp(){ |
| 151 | + if [ -d ${OWASP_DIR} ]; then |
| 152 | + echo "Detect ${OWASP_DIR} folder exist, move to ${OWASP_DIR}.$(date +%F).bk" |
| 153 | + if [ -d ${OWASP_DIR}.$(date +%F).bk ]; then |
| 154 | + rm -rf ${OWASP_DIR}.$(date +%F).bk |
| 155 | + fi |
| 156 | + mv ${OWASP_DIR} ${OWASP_DIR}.$(date +%F).bk |
| 157 | + fi |
| 158 | +} |
| 159 | + |
149 | 160 | install_owasp(){ |
150 | 161 | cd ${OWASP_DIR} |
151 | 162 | echo 'Download OWASP rules' |
152 | 163 | wget -q https://github.com/coreruleset/coreruleset/archive/refs/tags/v${OWASP_V}.zip |
153 | 164 | unzip -qq v${OWASP_V}.zip |
154 | 165 | rm -f v${OWASP_V}.zip |
155 | | - mv coreruleset-* owasp-modsecurity-crs |
| 166 | + mv coreruleset-* ${CRS_DIR} |
156 | 167 | } |
157 | 168 |
|
158 | 169 | configure_owasp(){ |
159 | 170 | echo 'Config OWASP rules.' |
160 | 171 | cd ${OWASP_DIR} |
161 | | - echo "include modsecurity.conf |
162 | | -include owasp-modsecurity-crs/crs-setup.conf |
163 | | -include owasp-modsecurity-crs/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf |
164 | | -include owasp-modsecurity-crs/rules/REQUEST-901-INITIALIZATION.conf |
165 | | -include owasp-modsecurity-crs/rules/REQUEST-903.9001-DRUPAL-EXCLUSION-RULES.conf |
166 | | -include owasp-modsecurity-crs/rules/REQUEST-903.9002-WORDPRESS-EXCLUSION-RULES.conf |
167 | | -include owasp-modsecurity-crs/rules/REQUEST-903.9003-NEXTCLOUD-EXCLUSION-RULES.conf |
168 | | -include owasp-modsecurity-crs/rules/REQUEST-903.9004-DOKUWIKI-EXCLUSION-RULES.conf |
169 | | -include owasp-modsecurity-crs/rules/REQUEST-903.9005-CPANEL-EXCLUSION-RULES.conf |
170 | | -include owasp-modsecurity-crs/rules/REQUEST-903.9006-XENFORO-EXCLUSION-RULES.conf |
171 | | -include owasp-modsecurity-crs/rules/REQUEST-905-COMMON-EXCEPTIONS.conf |
172 | | -include owasp-modsecurity-crs/rules/REQUEST-910-IP-REPUTATION.conf |
173 | | -include owasp-modsecurity-crs/rules/REQUEST-911-METHOD-ENFORCEMENT.conf |
174 | | -include owasp-modsecurity-crs/rules/REQUEST-912-DOS-PROTECTION.conf |
175 | | -include owasp-modsecurity-crs/rules/REQUEST-913-SCANNER-DETECTION.conf |
176 | | -include owasp-modsecurity-crs/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf |
177 | | -include owasp-modsecurity-crs/rules/REQUEST-921-PROTOCOL-ATTACK.conf |
178 | | -include owasp-modsecurity-crs/rules/REQUEST-930-APPLICATION-ATTACK-LFI.conf |
179 | | -include owasp-modsecurity-crs/rules/REQUEST-931-APPLICATION-ATTACK-RFI.conf |
180 | | -include owasp-modsecurity-crs/rules/REQUEST-932-APPLICATION-ATTACK-RCE.conf |
181 | | -include owasp-modsecurity-crs/rules/REQUEST-933-APPLICATION-ATTACK-PHP.conf |
182 | | -include owasp-modsecurity-crs/rules/REQUEST-934-APPLICATION-ATTACK-NODEJS.conf |
183 | | -include owasp-modsecurity-crs/rules/REQUEST-941-APPLICATION-ATTACK-XSS.conf |
184 | | -include owasp-modsecurity-crs/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf |
185 | | -include owasp-modsecurity-crs/rules/REQUEST-943-APPLICATION-ATTACK-SESSION-FIXATION.conf |
186 | | -include owasp-modsecurity-crs/rules/REQUEST-944-APPLICATION-ATTACK-JAVA.conf |
187 | | -include owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf |
188 | | -include owasp-modsecurity-crs/rules/RESPONSE-950-DATA-LEAKAGES.conf |
189 | | -include owasp-modsecurity-crs/rules/RESPONSE-951-DATA-LEAKAGES-SQL.conf |
190 | | -include owasp-modsecurity-crs/rules/RESPONSE-952-DATA-LEAKAGES-JAVA.conf |
191 | | -include owasp-modsecurity-crs/rules/RESPONSE-953-DATA-LEAKAGES-PHP.conf |
192 | | -include owasp-modsecurity-crs/rules/RESPONSE-954-DATA-LEAKAGES-IIS.conf |
193 | | -include owasp-modsecurity-crs/rules/RESPONSE-959-BLOCKING-EVALUATION.conf |
194 | | -include owasp-modsecurity-crs/rules/RESPONSE-980-CORRELATION.conf |
195 | | -include owasp-modsecurity-crs/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf">modsec_includes.conf |
196 | | - echo "SecRuleEngine On">modsecurity.conf |
197 | | - cd ${OWASP_DIR}/owasp-modsecurity-crs |
198 | | - if [ -f crs-setup.conf.example ]; then |
199 | | - mv crs-setup.conf.example crs-setup.conf |
200 | | - fi |
201 | | - cd ${OWASP_DIR}/owasp-modsecurity-crs/rules |
202 | | - if [ -f REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example ]; then |
203 | | - mv REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf |
| 172 | + if [ -f ${CRS_DIR}/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example ]; then |
| 173 | + mv ${CRS_DIR}/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example ${CRS_DIR}/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf |
204 | 174 | fi |
205 | | - if [ -f RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example ]; then |
206 | | - mv RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf |
| 175 | + if [ -f ${CRS_DIR}/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example ]; then |
| 176 | + mv ${CRS_DIR}/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example ${CRS_DIR}/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf |
207 | 177 | fi |
| 178 | + if [ -f ${RULE_FILE} ]; then |
| 179 | + mv ${RULE_FILE} ${RULE_FILE}.bk |
| 180 | + fi |
| 181 | + echo 'include modsecurity.conf' >> ${RULE_FILE} |
| 182 | + if [ -f ${CRS_DIR}/crs-setup.conf.example ]; then |
| 183 | + mv ${CRS_DIR}/crs-setup.conf.example ${CRS_DIR}/crs-setup.conf |
| 184 | + echo "include ${CRS_DIR}/crs-setup.conf" >> ${RULE_FILE} |
| 185 | + fi |
| 186 | + ALL_RULES="$(ls ${CRS_DIR}/rules/ | grep 'REQUEST-\|RESPONSE-')" |
| 187 | + echo "${ALL_RULES}" | while read LINE; do echo "include ${CRS_DIR}/rules/${LINE}" >> ${RULE_FILE}; done |
| 188 | + echo 'SecRuleEngine On' > modsecurity.conf |
| 189 | + chown -R lsadm ${OWASP_DIR} |
208 | 190 | } |
209 | 191 |
|
210 | 192 | main_owasp(){ |
| 193 | + backup_owasp |
211 | 194 | mk_owasp_dir |
212 | 195 | install_unzip |
213 | 196 | install_owasp |
|
0 commit comments