From 96666ab30712e9c451253f9b689aa6caa1340c26 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 7 Dec 2021 10:19:32 -0500 Subject: [PATCH 01/47] add receiver node --- .../assigned_hostgroups.local.map.yaml | 3 ++- files/firewall/hostgroups.local.yaml | 4 ++++ pillar/logstash/receiver.sls | 10 ++++++++ pillar/top.sls | 8 +++++++ .../config/so/9999_output_redis.conf.jinja | 2 +- salt/top.sls | 24 +++++++++++++++++++ setup/so-functions | 5 +++- setup/so-whiptail | 3 ++- 8 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 pillar/logstash/receiver.sls diff --git a/files/firewall/assigned_hostgroups.local.map.yaml b/files/firewall/assigned_hostgroups.local.map.yaml index 50ef751a4..ee871ad80 100644 --- a/files/firewall/assigned_hostgroups.local.map.yaml +++ b/files/firewall/assigned_hostgroups.local.map.yaml @@ -16,6 +16,7 @@ role: import: manager: managersearch: + receiver: standalone: searchnode: - sensor: \ No newline at end of file + sensor: diff --git a/files/firewall/hostgroups.local.yaml b/files/firewall/hostgroups.local.yaml index d02d7c785..334b090d1 100644 --- a/files/firewall/hostgroups.local.yaml +++ b/files/firewall/hostgroups.local.yaml @@ -44,6 +44,10 @@ firewall: ips: delete: insert: + receiver: + ips: + delete: + insert: search_node: ips: delete: diff --git a/pillar/logstash/receiver.sls b/pillar/logstash/receiver.sls new file mode 100644 index 000000000..fc0788824 --- /dev/null +++ b/pillar/logstash/receiver.sls @@ -0,0 +1,10 @@ +{%- set PIPELINE = salt['pillar.get']('global:pipeline', 'redis') %} +logstash: + pipelines: + manager: + config: + - so/0009_input_beats.conf + - so/0010_input_hhbeats.conf + - so/0011_input_endgame.conf + - so/9999_output_redis.conf.jinja + \ No newline at end of file diff --git a/pillar/top.sls b/pillar/top.sls index 5401b83e3..a81fdc862 100644 --- a/pillar/top.sls +++ b/pillar/top.sls @@ -104,6 +104,14 @@ base: - minions.{{ grains.id }} - data.nodestab + '*_receiver': + - logstash + - logstash.receiver + - elasticsearch.auth + - global + - minions.{{ grains.id }} + - data.receivertab + '*_import': - zeeklogs - secrets diff --git a/salt/logstash/pipelines/config/so/9999_output_redis.conf.jinja b/salt/logstash/pipelines/config/so/9999_output_redis.conf.jinja index 6b9c62e2f..eac5fe304 100644 --- a/salt/logstash/pipelines/config/so/9999_output_redis.conf.jinja +++ b/salt/logstash/pipelines/config/so/9999_output_redis.conf.jinja @@ -1,4 +1,4 @@ -{%- if grains.role in ['so-heavynode'] %} +{%- if grains.role in ['so-heavynode', 'so-receiver'] %} {%- set HOST = salt['grains.get']('host') %} {%- else %} {%- set HOST = salt['grains.get']('master') %} diff --git a/salt/top.sls b/salt/top.sls index a8f2018a6..18f37e713 100644 --- a/salt/top.sls +++ b/salt/top.sls @@ -478,3 +478,27 @@ base: - docker_clean - pipeline.load - learn + + '*_receiver and G@saltversion:{{saltversion}}': + - match: compound + - ca + - ssl + - telegraf + - firewall + {%- if WAZUH != 0 %} + - wazuh + {%- endif %} + {%- if LOGSTASH %} + - logstash + {%- endif %} + {%- if REDIS %} + - redis + {%- endif %} + {%- if FILEBEAT %} + - filebeat + {%- endif %} + {%- if FLEETMANAGER or FLEETNODE %} + - fleet.install_package + {%- endif %} + - schedule + - docker_clean diff --git a/setup/so-functions b/setup/so-functions index daf609f67..20818aa72 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -2665,7 +2665,7 @@ set_initial_firewall_policy() { $default_salt_dir/salt/common/tools/sbin/so-firewall includehost minion "$MAINIP" $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost sensor "$MAINIP" ;; - 'SENSOR' | 'SEARCHNODE' | 'HEAVYNODE' | 'FLEET') + 'SENSOR' | 'SEARCHNODE' | 'HEAVYNODE' | 'FLEET' | 'RECEIVER') $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall includehost minion "$MAINIP" case "$install_type" in 'SENSOR') @@ -2685,6 +2685,9 @@ set_initial_firewall_policy() { 'FLEET') $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost beats_endpoint_ssl "$MAINIP" ;; + 'RECEIVER') + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost receiver "$MAINIP" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/pillar/data/addtotab.sh receivertab "$MINION_ID" "$MAINIP" esac ;; 'PARSINGNODE') diff --git a/setup/so-whiptail b/setup/so-whiptail index c49e7396a..bdaa50849 100755 --- a/setup/so-whiptail +++ b/setup/so-whiptail @@ -796,11 +796,12 @@ whiptail_install_type_dist_existing() { Note: Heavy nodes (HEAVYNODE) are NOT recommended for most users. EOM - install_type=$(whiptail --title "$whiptail_title" --radiolist "$node_msg" 18 58 4 \ + install_type=$(whiptail --title "$whiptail_title" --radiolist "$node_msg" 18 58 5 \ "SENSOR" "Create a forward only sensor " ON \ "SEARCHNODE" "Add a search node with parsing " OFF \ "FLEET" "Dedicated Fleet Osquery Node " OFF \ "HEAVYNODE" "Sensor + Search Node " OFF \ + "RECEIVER" "Receiver Node " OFF \ 3>&1 1>&2 2>&3 # "HOTNODE" "Add Hot Node (Uses Elastic Clustering)" OFF \ # TODO # "WARMNODE" "Add Warm Node to existing Hot or Search node" OFF \ # TODO From ba30c59ec7696eeabb1fbb8a1c16bd864323906c Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 7 Dec 2021 10:56:35 -0500 Subject: [PATCH 02/47] add receiver node --- setup/so-functions | 2 +- setup/so-setup | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/setup/so-functions b/setup/so-functions index 20818aa72..9720cc757 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -1490,7 +1490,7 @@ get_redirect() { get_minion_type() { local minion_type case "$install_type" in - 'EVAL' | 'MANAGERSEARCH' | 'MANAGER' | 'SENSOR' | 'HEAVYNODE' | 'FLEET' | 'STANDALONE' | 'IMPORT') + 'EVAL' | 'MANAGERSEARCH' | 'MANAGER' | 'SENSOR' | 'HEAVYNODE' | 'FLEET' | 'STANDALONE' | 'IMPORT' | 'RECEIVER') minion_type=$(echo "$install_type" | tr '[:upper:]' '[:lower:]') ;; 'HELIXSENSOR') diff --git a/setup/so-setup b/setup/so-setup index 159367793..9d3701fce 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -255,6 +255,8 @@ elif [ "$install_type" = 'HELIXSENSOR' ]; then is_helix=true elif [ "$install_type" = 'IMPORT' ]; then is_import=true +elif [ "$install_type" = 'RECEIVER' ]; then + is_minion=true elif [ "$install_type" = 'ANALYST' ]; then cd .. || exit 255 exec bash so-analyst-install From f3ec5df4479c3b14cf24c6d10a4361497f1404ee Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 7 Dec 2021 11:13:51 -0500 Subject: [PATCH 03/47] add receiver node --- pillar/top.sls | 2 +- setup/so-functions | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pillar/top.sls b/pillar/top.sls index a81fdc862..b3cc8dc8f 100644 --- a/pillar/top.sls +++ b/pillar/top.sls @@ -110,7 +110,7 @@ base: - elasticsearch.auth - global - minions.{{ grains.id }} - - data.receivertab + - data.receiverstab '*_import': - zeeklogs diff --git a/setup/so-functions b/setup/so-functions index 8a0e59842..527d914e5 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -99,7 +99,7 @@ addtotab_generate_templates() { local addtotab_path=$local_salt_dir/pillar/data - for i in evaltab managersearchtab managertab nodestab sensorstab standalonetab; do + for i in evaltab managersearchtab managertab nodestab sensorstab standalonetab receiverstab; do printf '%s\n'\ "$i:"\ "" > "$addtotab_path"/$i.sls @@ -2687,7 +2687,7 @@ set_initial_firewall_policy() { ;; 'RECEIVER') $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost receiver "$MAINIP" - $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/pillar/data/addtotab.sh receivertab "$MINION_ID" "$MAINIP" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/pillar/data/addtotab.sh receiverstab "$MINION_ID" "$MAINIP" esac ;; 'PARSINGNODE') From 06010bd157ce8e465521792e2e2470c38089060e Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 7 Dec 2021 13:34:06 -0500 Subject: [PATCH 04/47] add so-receiver to allowed_states --- salt/allowed_states.map.jinja | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/salt/allowed_states.map.jinja b/salt/allowed_states.map.jinja index 0175953b0..204b0d3b4 100644 --- a/salt/allowed_states.map.jinja +++ b/salt/allowed_states.map.jinja @@ -205,9 +205,17 @@ 'tcpreplay', 'docker_clean' ], + 'so-receiver': [ + 'ca', + 'ssl', + 'telegraf', + 'firewall', + 'schedule', + 'docker_clean' + ], }, grain='role') %} - {% if FILEBEAT and grains.role in ['so-helixsensor', 'so-eval', 'so-manager', 'so-standalone', 'so-node', 'so-managersearch', 'so-heavynode', 'so-import'] %} + {% if FILEBEAT and grains.role in ['so-helixsensor', 'so-eval', 'so-manager', 'so-standalone', 'so-node', 'so-managersearch', 'so-heavynode', 'so-import', 'so-receiver'] %} {% do allowed_states.append('filebeat') %} {% endif %} @@ -215,7 +223,7 @@ {% do allowed_states.append('mysql') %} {% endif %} - {% if (FLEETMANAGER or FLEETNODE) and grains.role in ['so-sensor', 'so-eval', 'so-manager', 'so-standalone', 'so-node', 'so-managersearch', 'so-heavynode'] %} + {% if (FLEETMANAGER or FLEETNODE) and grains.role in ['so-sensor', 'so-eval', 'so-manager', 'so-standalone', 'so-node', 'so-managersearch', 'so-heavynode', 'so-receiver'] %} {% do allowed_states.append('fleet.install_package') %} {% endif %} @@ -235,7 +243,7 @@ {% do allowed_states.append('strelka') %} {% endif %} - {% if WAZUH and grains.role in ['so-eval', 'so-manager', 'so-standalone', 'so-node', 'so-managersearch', 'so-heavynode']%} + {% if WAZUH and grains.role in ['so-eval', 'so-manager', 'so-standalone', 'so-node', 'so-managersearch', 'so-heavynode', 'so-receiver']%} {% do allowed_states.append('wazuh') %} {% endif %} @@ -280,11 +288,11 @@ {% do allowed_states.append('domainstats') %} {% endif %} - {% if LOGSTASH and grains.role in ['so-helixsensor', 'so-manager', 'so-standalone', 'so-node', 'so-managersearch', 'so-heavynode'] %} + {% if LOGSTASH and grains.role in ['so-helixsensor', 'so-manager', 'so-standalone', 'so-node', 'so-managersearch', 'so-heavynode', 'so-receiver'] %} {% do allowed_states.append('logstash') %} {% endif %} - {% if REDIS and grains.role in ['so-manager', 'so-standalone', 'so-managersearch', 'so-heavynode'] %} + {% if REDIS and grains.role in ['so-manager', 'so-standalone', 'so-managersearch', 'so-heavynode', 'so-receiver'] %} {% do allowed_states.append('redis') %} {% endif %} From f8da5c7fe99ff90a0b546aac1b37e146b923c3dd Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 7 Dec 2021 15:59:11 -0500 Subject: [PATCH 05/47] start of fw rules for receiver --- salt/firewall/assigned_hostgroups.map.yaml | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/salt/firewall/assigned_hostgroups.map.yaml b/salt/firewall/assigned_hostgroups.map.yaml index d5fca081f..e56b86277 100644 --- a/salt/firewall/assigned_hostgroups.map.yaml +++ b/salt/firewall/assigned_hostgroups.map.yaml @@ -604,3 +604,69 @@ role: minion: portgroups: - {{ portgroups.salt_manager }} + + receiver: + chain: + DOCKER-USER: + hostgroups: + manager: + portgroups: + - {{ portgroups.elasticsearch_rest }} + - {{ portgroups.elasticsearch_node }} + sensor: + portgroups: + - {{ portgroups.beats_5044 }} + - {{ portgroups.beats_5644 }} + search_node: + portgroups: + - {{ portgroups.redis }} + - {{ portgroups.minio }} + - {{ portgroups.elasticsearch_node }} + - {{ portgroups.beats_5644 }} + heavy_node: + portgroups: + - {{ portgroups.redis }} + - {{ portgroups.minio }} + - {{ portgroups.elasticsearch_node }} + - {{ portgroups.beats_5644 }} + self: + portgroups: + - {{ portgroups.syslog}} + syslog: + portgroups: + - {{ portgroups.syslog }} + beats_endpoint: + portgroups: + - {{ portgroups.beats_5044 }} + beats_endpoint_ssl: + portgroups: + - {{ portgroups.beats_5644 }} + elasticsearch_rest: + portgroups: + - {{ portgroups.elasticsearch_rest }} + endgame: + portgroups: + - {{ portgroups.endgame }} + osquery_endpoint: + portgroups: + - {{ portgroups.fleet_api }} + wazuh_agent: + portgroups: + - {{ portgroups.wazuh_agent }} + wazuh_api: + portgroups: + - {{ portgroups.wazuh_api }} + wazuh_authd: + portgroups: + - {{ portgroups.wazuh_authd }} + INPUT: + hostgroups: + anywhere: + portgroups: + - {{ portgroups.ssh }} + dockernet: + portgroups: + - {{ portgroups.all }} + localhost: + portgroups: + - {{ portgroups.all }} From 429b9cab2f03464755e17925bcbce9eb374eb91c Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 7 Dec 2021 16:22:07 -0500 Subject: [PATCH 06/47] set ip for ossec.conf --- salt/wazuh/files/agent/ossec.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/salt/wazuh/files/agent/ossec.conf b/salt/wazuh/files/agent/ossec.conf index 7e33f5599..6ae873875 100644 --- a/salt/wazuh/files/agent/ossec.conf +++ b/salt/wazuh/files/agent/ossec.conf @@ -4,6 +4,9 @@ {%- set ip = salt['pillar.get']('elasticsearch:mainip', '') %} {%- elif grains['role'] == 'so-sensor' %} {%- set ip = salt['pillar.get']('sensor:mainip', '') %} +{%- else %} + {%- set mainint = salt['pillar.get']('host:mainint') %} + {%- set ip = salt['grains.get']('ip_interfaces:' ~ mainint)[0] %} {%- endif %}