From 7627d37386a80c2334087f58c48aa3049a3d0d46 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Tue, 23 Nov 2021 12:21:28 -0500 Subject: [PATCH 1/6] Add 2.3.90 WAZUH hotfix corrective function --- salt/common/tools/sbin/soup | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/salt/common/tools/sbin/soup b/salt/common/tools/sbin/soup index b497d9c24..8f1e77d7f 100755 --- a/salt/common/tools/sbin/soup +++ b/salt/common/tools/sbin/soup @@ -837,6 +837,21 @@ verify_latest_update_script() { fi } +apply_hotfix() { + if [[ "$INSTALLEDVERSION" == "2.3.90" && "$HOTFIXVERSION" == "WAZUH" ]] ; then + FILE="/nsm/wazuh/etc/ossec.conf" + echo "Detecting if ossec.conf needs corrected..." + WAZUHHEADER=$(head -1 $FILE | grep "xml version") + if [[ ! -z "$WAZUHHEADER" ]]; then + echo "$FILE has an XML header; removing" + sed -i 1d $FILE + else + echo "$FILE does not have an XML header, so no changes are necessary." + fi + fi +} + + main() { trap 'check_err $?' EXIT @@ -893,6 +908,7 @@ main() { if [ "$is_hotfix" == "true" ]; then echo "Applying $HOTFIXVERSION" copy_new_files + apply_hotfix echo "" update_version salt-call state.highstate -l info queue=True From 3c37bd61abd6b578faca6467dd629babccd05479 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Tue, 23 Nov 2021 12:46:59 -0500 Subject: [PATCH 2/6] Add debug logging --- salt/common/tools/sbin/soup | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/salt/common/tools/sbin/soup b/salt/common/tools/sbin/soup index 8f1e77d7f..ed2836de2 100755 --- a/salt/common/tools/sbin/soup +++ b/salt/common/tools/sbin/soup @@ -838,7 +838,7 @@ verify_latest_update_script() { } apply_hotfix() { - if [[ "$INSTALLEDVERSION" == "2.3.90" && "$HOTFIXVERSION" == "WAZUH" ]] ; then + if [[ "$INSTALLEDVERSION" == "2.3.90" && "$HOTFIXVERSION" == "WAZUH" ]]; then FILE="/nsm/wazuh/etc/ossec.conf" echo "Detecting if ossec.conf needs corrected..." WAZUHHEADER=$(head -1 $FILE | grep "xml version") @@ -848,6 +848,8 @@ apply_hotfix() { else echo "$FILE does not have an XML header, so no changes are necessary." fi + else + echo "Skipping ossec.conf check ($INSTALLEDVERSION/$HOTFIXVERSION)" fi } @@ -906,10 +908,10 @@ main() { set -e if [ "$is_hotfix" == "true" ]; then - echo "Applying $HOTFIXVERSION" + echo "Applying $HOTFIXVERSION hotfix" copy_new_files apply_hotfix - echo "" + echo "Hotfix applied" update_version salt-call state.highstate -l info queue=True else From 01ceded223b6595cef1c4989f4681255fc9346e7 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Tue, 23 Nov 2021 13:03:40 -0500 Subject: [PATCH 3/6] Handle CRs in hotfix --- salt/common/tools/sbin/soup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/common/tools/sbin/soup b/salt/common/tools/sbin/soup index ed2836de2..015d57ab6 100755 --- a/salt/common/tools/sbin/soup +++ b/salt/common/tools/sbin/soup @@ -838,7 +838,7 @@ verify_latest_update_script() { } apply_hotfix() { - if [[ "$INSTALLEDVERSION" == "2.3.90" && "$HOTFIXVERSION" == "WAZUH" ]]; then + if [[ "$INSTALLEDVERSION" == "2.3.90" && "$HOTFIXVERSION" =~ "WAZUH" ]]; then FILE="/nsm/wazuh/etc/ossec.conf" echo "Detecting if ossec.conf needs corrected..." WAZUHHEADER=$(head -1 $FILE | grep "xml version") From bd59d65f02b4e2b789ed3eaba02c53e6c0449fbd Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Tue, 23 Nov 2021 13:12:27 -0500 Subject: [PATCH 4/6] Strip trailing newlines from version and hotfix files --- salt/common/tools/sbin/soup | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/salt/common/tools/sbin/soup b/salt/common/tools/sbin/soup index 015d57ab6..b471e6eca 100755 --- a/salt/common/tools/sbin/soup +++ b/salt/common/tools/sbin/soup @@ -715,9 +715,9 @@ update_version() { upgrade_check() { # Let's make sure we actually need to update. - NEWVERSION=$(cat $UPDATE_DIR/VERSION) - HOTFIXVERSION=$(cat $UPDATE_DIR/HOTFIX) - [[ -f /etc/sohotfix ]] && CURRENTHOTFIX=$(cat /etc/sohotfix) + NEWVERSION=$(cat $UPDATE_DIR/VERSION | tr -d '\n') + HOTFIXVERSION=$(cat $UPDATE_DIR/HOTFIX | tr -d '\n') + [[ -f /etc/sohotfix ]] && CURRENTHOTFIX=$(cat /etc/sohotfix | tr -d '\n') if [ "$INSTALLEDVERSION" == "$NEWVERSION" ]; then echo "Checking to see if there are hotfixes needed" if [ "$HOTFIXVERSION" == "$CURRENTHOTFIX" ]; then @@ -838,7 +838,7 @@ verify_latest_update_script() { } apply_hotfix() { - if [[ "$INSTALLEDVERSION" == "2.3.90" && "$HOTFIXVERSION" =~ "WAZUH" ]]; then + if [[ "$INSTALLEDVERSION" == "2.3.90" && "$HOTFIXVERSION" == "WAZUH" ]] ; then FILE="/nsm/wazuh/etc/ossec.conf" echo "Detecting if ossec.conf needs corrected..." WAZUHHEADER=$(head -1 $FILE | grep "xml version") From 52ffa27eda73ee0026f413f1302fecd85b73f6f8 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Tue, 23 Nov 2021 13:22:47 -0500 Subject: [PATCH 5/6] Update hotfix file --- HOTFIX | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HOTFIX b/HOTFIX index f6989f3fe..0f3ca3c28 100644 --- a/HOTFIX +++ b/HOTFIX @@ -1 +1 @@ -WAZUH +WAZUH From 59fc122eecbf09385b7f195d8b3729a60acf3597 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Tue, 23 Nov 2021 13:29:04 -0500 Subject: [PATCH 6/6] Force restart of wazuh since conf file is changing --- salt/common/tools/sbin/soup | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/salt/common/tools/sbin/soup b/salt/common/tools/sbin/soup index b471e6eca..2aefc67bb 100755 --- a/salt/common/tools/sbin/soup +++ b/salt/common/tools/sbin/soup @@ -715,9 +715,9 @@ update_version() { upgrade_check() { # Let's make sure we actually need to update. - NEWVERSION=$(cat $UPDATE_DIR/VERSION | tr -d '\n') - HOTFIXVERSION=$(cat $UPDATE_DIR/HOTFIX | tr -d '\n') - [[ -f /etc/sohotfix ]] && CURRENTHOTFIX=$(cat /etc/sohotfix | tr -d '\n') + NEWVERSION=$(cat $UPDATE_DIR/VERSION) + HOTFIXVERSION=$(cat $UPDATE_DIR/HOTFIX) + [[ -f /etc/sohotfix ]] && CURRENTHOTFIX=$(cat /etc/sohotfix) if [ "$INSTALLEDVERSION" == "$NEWVERSION" ]; then echo "Checking to see if there are hotfixes needed" if [ "$HOTFIXVERSION" == "$CURRENTHOTFIX" ]; then @@ -845,6 +845,7 @@ apply_hotfix() { if [[ ! -z "$WAZUHHEADER" ]]; then echo "$FILE has an XML header; removing" sed -i 1d $FILE + so-wazuh-restart else echo "$FILE does not have an XML header, so no changes are necessary." fi