Skip to content

Commit af62ec6

Browse files
committed
Update OWASP config and version
1 parent 464d999 commit af62ec6

File tree

1 file changed

+31
-48
lines changed

1 file changed

+31
-48
lines changed

bin/container/owaspctl.sh

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/bin/bash
22
LSDIR='/usr/local/lsws'
33
OWASP_DIR="${LSDIR}/conf/owasp"
4+
CRS_DIR='owasp-modsecurity-crs'
45
RULE_FILE='modsec_includes.conf'
56
LS_HTTPD_CONF="${LSDIR}/conf/httpd_config.xml"
67
OLS_HTTPD_CONF="${LSDIR}/conf/httpd_config.conf"
78
EPACE=' '
8-
OWASP_V='3.3.4'
9+
OWASP_V='4.2.0'
910

1011
echow(){
1112
FLAG=${1}
@@ -90,7 +91,7 @@ enable_ls_modsec(){
9091
<censorshipRuleSet>\n\
9192
<name>ModSec</name>\n\
9293
<enabled>1</enabled>\n\
93-
<ruleSet>include ${OWASP_DIR}/modsec_includes.conf</ruleSet>\n\
94+
<ruleSet>include ${OWASP_DIR}/${RULE_FILE}</ruleSet>\n\
9495
</censorshipRuleSet>=" ${LS_HTTPD_CONF}
9596
fi
9697
}
@@ -146,68 +147,50 @@ install_unzip(){
146147
fi
147148
}
148149

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+
149160
install_owasp(){
150161
cd ${OWASP_DIR}
151162
echo 'Download OWASP rules'
152163
wget -q https://github.com/coreruleset/coreruleset/archive/refs/tags/v${OWASP_V}.zip
153164
unzip -qq v${OWASP_V}.zip
154165
rm -f v${OWASP_V}.zip
155-
mv coreruleset-* owasp-modsecurity-crs
166+
mv coreruleset-* ${CRS_DIR}
156167
}
157168

158169
configure_owasp(){
159170
echo 'Config OWASP rules.'
160171
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
204174
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
207177
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}
208190
}
209191

210192
main_owasp(){
193+
backup_owasp
211194
mk_owasp_dir
212195
install_unzip
213196
install_owasp

0 commit comments

Comments
 (0)