From 490bcfff25d190ec8a3def56c5bfd6e00f3fcf63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Tue, 10 Oct 2023 15:05:20 +0200 Subject: [PATCH] Updated ossec.conf template to support macOS --- .../ansible-wazuh-agent/defaults/main.yml | 18 ++++++ .../ansible-wazuh-agent/handlers/main.yml | 3 + .../var-ossec-etc-ossec-agent.conf.j2 | 55 +++++++++++++++++-- 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml index 9e9b627f..399e94ce 100644 --- a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml @@ -40,6 +40,7 @@ authd_pass: '' wazuh_api_reachable_from_agent: yes wazuh_profile_centos: 'centos, centos7, centos7.6' wazuh_profile_ubuntu: 'ubuntu, ubuntu18, ubuntu18.04' +wazuh_profile_macos: 'darwin, darwin21, darwin21.1' wazuh_auto_restart: 'yes' wazuh_notify_time: '10' @@ -230,6 +231,11 @@ wazuh_agent_syscheck: checks: '' - dirs: /bin,/sbin,/boot checks: '' + macos_directories: + - dirs: /etc,/usr/bin,/usr/sbin + checks: '' + - dirs: /bin,/sbin + checks: '' win_directories: - dirs: '%WINDIR%' checks: 'recursion_level="0" restrict="regedit.exe$|system.ini$|win.ini$"' @@ -332,6 +338,17 @@ wazuh_agent_localfiles: command: netstat -tulpn | sed 's/\([[:alnum:]]\+\)\ \+[[:digit:]]\+\ \+[[:digit:]]\+\ \+\(.*\):\([[:digit:]]*\)\ \+\([0-9\.\:\*]\+\).\+\ \([[:digit:]]*\/[[:alnum:]\-]*\).*/\1 \2 == \3 == \4 \5/' | sort -k 4 -g | sed 's/ == \(.*\) ==/:\1/' | sed 1,2d alias: 'netstat listening ports' frequency: '360' + macos: + - format: 'full_command' + command: netstat -an | awk '{if ((/^(tcp|udp)/) && ($4 != "*.*") && ($5 == "*.*")) {print $1" "$4" "$5}}' | sort -u + alias: 'netstat listening ports' + frequency: '360' + - format: 'macos' + location: 'macos' + query: + type: 'trace,log,activity' + level: 'info' + value: (process == "sudo") or (process == "sessionlogoutd" and message contains "logout is complete.") or (process == "sshd") or (process == "tccd" and message contains "Update Access Record") or (message contains "SessionAgentNotificationCenter") or (process == "screensharingd" and message contains "Authentication") or (process == "securityd" and eventMessage contains "Session" and subsystem == "com.apple.securityd") windows: - format: 'eventlog' location: 'Application' @@ -355,6 +372,7 @@ wazuh_agent_active_response: ar_disabled: 'no' ca_store: "{{ wazuh_dir }}/etc/wpk_root.pem" ca_store_win: 'wpk_root.pem' + ca_store_macos: 'etc/wpk_root.pem' ca_verification: 'yes' ## Logging diff --git a/roles/wazuh/ansible-wazuh-agent/handlers/main.yml b/roles/wazuh/ansible-wazuh-agent/handlers/main.yml index 84f3ff45..f4770eb3 100644 --- a/roles/wazuh/ansible-wazuh-agent/handlers/main.yml +++ b/roles/wazuh/ansible-wazuh-agent/handlers/main.yml @@ -4,3 +4,6 @@ - name: Windows | Restart Wazuh Agent win_service: name=WazuhSvc start_mode=auto state=restarted + +- name: macOS | Restart Wazuh Agent + command: /Library/Ossec/bin/wazuh-control restart \ No newline at end of file diff --git a/roles/wazuh/ansible-wazuh-agent/templates/var-ossec-etc-ossec-agent.conf.j2 b/roles/wazuh/ansible-wazuh-agent/templates/var-ossec-etc-ossec-agent.conf.j2 index 8eef3d1d..dd40b21e 100644 --- a/roles/wazuh/ansible-wazuh-agent/templates/var-ossec-etc-ossec-agent.conf.j2 +++ b/roles/wazuh/ansible-wazuh-agent/templates/var-ossec-etc-ossec-agent.conf.j2 @@ -30,6 +30,9 @@ {{ wazuh_profile_ubuntu }} {% endif %} {% endif %} + {% if ansible_system == "Darwin" %} + {{ wazuh_profile_macos }} + {% endif %} {% if wazuh_notify_time is not none and wazuh_time_reconnect is not none %} {{ wazuh_notify_time }} {{ wazuh_time_reconnect }} @@ -91,7 +94,7 @@ {% if wazuh_agent_config.rootcheck is defined %} no - {% if ansible_system == "Linux" %} + {% if ansible_system == "Linux" or ansible_system == "Darwin" %} yes yes yes @@ -103,10 +106,14 @@ {{ wazuh_agent_config.rootcheck.frequency }} + {% if ansible_system == "Darwin" %} + etc/shared/rootkit_files.txt + etc/shared/rootkit_trojans.txt + {% else %} {{ wazuh_dir }}/etc/shared/rootkit_files.txt {{ wazuh_dir }}/etc/shared/rootkit_trojans.txt - yes {% endif %} + yes {% if ansible_os_family == "Windows" %} ./shared/win_applications_rcl.txt ./shared/win_malware_rcl.txt @@ -179,6 +186,7 @@ {% endif %} + {% if ansible_system != "Darwin" %} {{ wazuh_agent_config.cis_cat.disable }} {{ wazuh_agent_config.cis_cat.timeout }} @@ -193,6 +201,7 @@ {% endif %} {% if ansible_os_family == "Windows" %}{{ wazuh_agent_config.cis_cat.ciscat_path_win }}{% else %}{{ wazuh_agent_config.cis_cat.ciscat_path }}{% endif %} + {% endif %} @@ -249,13 +258,18 @@ no {{ wazuh_agent_config.syscheck.frequency }} - {% if ansible_system == "Linux" %} + {% if ansible_system == "Linux" or ansible_system == "Darwin" %} {{ wazuh_agent_config.syscheck.scan_on_start }} {% if wazuh_agent_config.syscheck.directories is defined and ansible_system == "Linux" %} {% for directory in wazuh_agent_config.syscheck.directories %} {{ directory.dirs }} {% endfor %} + {% elif ansible_system == "Darwin" %} + {% for directory in wazuh_agent_config.syscheck.macos_directories %} + {{ directory.dirs }} + {% endfor %} + {% endif %} {% endif %} {% endif %} @@ -267,7 +281,7 @@ {% endif %} - {% if wazuh_agent_config.syscheck.ignore is defined and ansible_system == "Linux" %} + {% if wazuh_agent_config.syscheck.ignore is defined and (ansible_system == "Linux" or ansible_system == "Darwin") %} {% for ignore in wazuh_agent_config.syscheck.ignore %} {{ ignore }} {% endfor %} @@ -286,7 +300,7 @@ {% endfor %} {% endif %} - {% if ansible_system == "Linux" %} + {% if ansible_system == "Linux" or ansible_system == "Darwin" %} {% for no_diff in wazuh_agent_config.syscheck.no_diff %} {{ no_diff }} @@ -363,6 +377,27 @@ {% endfor %} {% endif %} + {% if ansible_system == "Darwin" %} + {% for localfile in wazuh_agent_config.localfiles.macos %} + + + {{ localfile.format }} + {% if localfile.format == 'command' or localfile.format == 'full_command' %} + {{ localfile.command }} + {{ localfile.frequency }} + {% if localfile.alias is defined %} + {{ localfile.alias }} + {% endif %} + {% else %} + {{ localfile.location }} + {% if localfile.format == 'macos' %} + {{ localfile.query.value }} + {% endif %} + {% endif %} + + {% endfor %} + {% endif %} + {% if ansible_os_family == "Debian" %} {% for localfile in wazuh_agent_config.localfiles.debian %} @@ -439,7 +474,15 @@ {{ wazuh_agent_config.active_response.ar_disabled|default('no') }} - {% if ansible_os_family == "Windows" %}{{ wazuh_agent_config.active_response.ca_store_win }}{% else %}{{ wazuh_agent_config.active_response.ca_store }}{% endif %} + + {% if ansible_os_family == "Windows" %}{{ wazuh_agent_config.active_response.ca_store_win }} + {% else %} + {% if ansible_system == "Darwin" %}{{ wazuh_agent_config.active_response.ca_store_macos }} + {% else %} + {{ wazuh_agent_config.active_response.ca_store }} + {% endif %} + {% endif %} + {{ wazuh_agent_config.active_response.ca_verification }}