From fe07c66d24ec3a2f40d33964b79389d82a77a55b Mon Sep 17 00:00:00 2001 From: Miguelangel Freitas Date: Tue, 29 Aug 2017 20:56:42 -0500 Subject: [PATCH] Add Windows registry keys to syscheck * Changing agent restart rules id. * Restart Windows agents after receiving agent.conf --- ansible-wazuh-agent/defaults/main.yml | 4 +++ .../var-ossec-etc-ossec-agent.conf.j2 | 35 +++++++++++++++++-- ansible-wazuh-manager/defaults/main.yml | 25 ++++++++++++- .../var-ossec-etc-shared-agent.conf.j2 | 16 ++++++--- .../var-ossec-rules-local_rules.xml.j2 | 29 ++++++++------- 5 files changed, 90 insertions(+), 19 deletions(-) diff --git a/ansible-wazuh-agent/defaults/main.yml b/ansible-wazuh-agent/defaults/main.yml index 79bd3c55..153f1633 100644 --- a/ansible-wazuh-agent/defaults/main.yml +++ b/ansible-wazuh-agent/defaults/main.yml @@ -40,6 +40,10 @@ wazuh_agent_config: checks: 'check_all="yes"' - dirs: /bin,/sbin checks: 'check_all="yes"' + windows_registry: + - key: 'HKEY_LOCAL_MACHINE\Software\Classes\batfile' + arch: 'both' + - key: 'HKEY_LOCAL_MACHINE\Software\Classes\Folder' rootcheck: frequency: 43200 openscap: diff --git a/ansible-wazuh-agent/templates/var-ossec-etc-ossec-agent.conf.j2 b/ansible-wazuh-agent/templates/var-ossec-etc-ossec-agent.conf.j2 index dd07aa6b..d50fd470 100644 --- a/ansible-wazuh-agent/templates/var-ossec-etc-ossec-agent.conf.j2 +++ b/ansible-wazuh-agent/templates/var-ossec-etc-ossec-agent.conf.j2 @@ -1,4 +1,4 @@ -#jinja2: lstrip_blocks: True +#jinja2: trim_blocks: False {{ wazuh_agent_config.rootcheck.frequency }} + {% if ansible_os_family == "Windows" %} + ./shared/win_audit_rcl.txt + ./shared/win_applications_rcl.txt + ./shared/win_malware_rcl.txt + {% endif %} + + {% if ansible_system == "Linux" %} /var/ossec/etc/shared/rootkit_files.txt /var/ossec/etc/shared/rootkit_trojans.txt /var/ossec/etc/shared/system_audit_rcl.txt @@ -50,11 +61,21 @@ {% if cis_distribution_filename is defined %} /var/ossec/etc/shared/{{ cis_distribution_filename }} {% endif %} + {% endif %} yes + no + {% if ansible_os_family == "Windows" %} + C:\wazuh-agent + {% endif %} + + {% if ansible_system == "Linux" %} + /var/ossec/etc/shared + {% endif %} + {{ wazuh_agent_config.syscheck.auto_ignore }} {{ wazuh_agent_config.syscheck.alert_new_files }} @@ -79,9 +100,19 @@ {% for no_diff in wazuh_agent_config.syscheck.no_diff %} {{ no_diff }} {% endfor %} + + {% if ansible_os_family == "Windows" %} + {% for registry_key in wazuh_agent_config.syscheck.windows_registry %} + {% if registry_key.arch is defined %} + {{ registry_key.key }} + {% else %} + {{ registry_key.key }} + {% endif %} + {% endfor %} + {% endif %} - {% if wazuh_agent_config.openscap.disable == 'no' %} + {% if wazuh_agent_config.openscap.disable == 'no' and ansible_system == "Linux"%} no {{ wazuh_agent_config.openscap.timeout }} diff --git a/ansible-wazuh-manager/defaults/main.yml b/ansible-wazuh-manager/defaults/main.yml index 37eb0e04..28fbee8c 100644 --- a/ansible-wazuh-manager/defaults/main.yml +++ b/ansible-wazuh-manager/defaults/main.yml @@ -110,6 +110,10 @@ wazuh_manager_config: executable: 'restart-ossec.sh' expect: '' timeout_allowed: 'no' + - name: 'win_restart-ossec' + executable: 'restart-ossec.cmd' + expect: '' + timeout_allowed: 'no' - name: 'firewall-drop' executable: 'firewall-drop.sh' expect: 'srcip' @@ -129,7 +133,10 @@ wazuh_manager_config: active_responses: - command: 'restart-ossec' location: 'local' - rules_id: 710001 + rules_id: '100002' + - command: 'win_restart-ossec' + location: 'local' + rules_id: '100003' - command: 'host-deny' location: 'local' level: 6 @@ -176,3 +183,19 @@ wazuh_agent_configs: location: '/var/log/httpd/access_log' - format: 'apache' location: '/var/ossec/logs/active-responses.log' + - type: os + type_value: Windows + syscheck: + frequency: 43200 + scan_on_start: 'yes' + auto_ignore: 'no' + alert_new_files: 'yes' + windows_registry: + - key: 'HKEY_LOCAL_MACHINE\Software\Classes\batfile' + arch: 'both' + - key: 'HKEY_LOCAL_MACHINE\Software\Classes\Folder' + localfiles: + - format: 'Security' + location: 'eventchannel' + - format: 'System' + location: 'eventlog' diff --git a/ansible-wazuh-manager/templates/var-ossec-etc-shared-agent.conf.j2 b/ansible-wazuh-manager/templates/var-ossec-etc-shared-agent.conf.j2 index a45a95d8..9d52c8e2 100644 --- a/ansible-wazuh-manager/templates/var-ossec-etc-shared-agent.conf.j2 +++ b/ansible-wazuh-manager/templates/var-ossec-etc-shared-agent.conf.j2 @@ -29,6 +29,16 @@ {{ no_diff }} {% endfor %} {% endif %} + + {% if agent_config.syscheck.windows_registry is defined %} + {% for registry_key in agent_config.syscheck.windows_registry %} + {% if registry_key.arch is defined %} + {{ registry_key.key }} + {% else %} + {{ registry_key.key }} + {% endif %} + {% endfor %} + {% endif %} {% for localfile in agent_config.localfiles %} @@ -43,6 +53,7 @@ {% endfor %} + {% if agent_config.rootcheck is defined %} no yes @@ -57,15 +68,12 @@ {{ agent_config.rootcheck.frequency }} - /var/ossec/etc/shared/rootkit_files.txt - /var/ossec/etc/shared/rootkit_trojans.txt - /var/ossec/etc/shared/system_audit_rcl.txt - /var/ossec/etc/shared/system_audit_ssh.txt {% if agent_config.rootcheck.cis_distribution_filename is not none %} /var/ossec/etc/shared/{{ agent_config.rootcheck.cis_distribution_filename }} {% endif %} yes + {% endif %} {% endfor %} {% endif %} diff --git a/ansible-wazuh-manager/templates/var-ossec-rules-local_rules.xml.j2 b/ansible-wazuh-manager/templates/var-ossec-rules-local_rules.xml.j2 index db0b000a..5cbe7670 100644 --- a/ansible-wazuh-manager/templates/var-ossec-rules-local_rules.xml.j2 +++ b/ansible-wazuh-manager/templates/var-ossec-rules-local_rules.xml.j2 @@ -1,17 +1,5 @@ - - - - syscheck - /var/ossec/etc/shared/agent.conf - agent.conf was modified - - - @@ -28,3 +16,20 @@ is successfully retrieved. + + + + + syscheck + /var/ossec/etc/shared/agent.conf + Linux | agent.conf was modified + + + syscheck + C:\wazuh-agent/shared/agent.conf + Windows | agent.conf was modified + +