Steno BPF tweaks

This commit is contained in:
Josh Brower
2020-01-28 16:53:19 -05:00
parent 3262854f4e
commit ae087c5552
3 changed files with 12 additions and 61 deletions

View File

@@ -1,37 +0,0 @@
#!/bin/bash
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ "$#" -lt 2 ]; then
cat 1>&2 <<EOF
$0 compiles a BPF expression to be passed to stenotype to apply a socket filter.
Its first argument is the interface (link type is required) and all other arguments
are passed to TCPDump.
Examples:
$0 eth0 dst port 80
$0 eth0 udp port 53
EOF
exit 1
fi
interface="$1"
shift
sudo tcpdump -i $interface -ddd $@ | tail -n+2 |
while read line; do
cols=( $line )
printf "%04x%02x%02x%08x" ${cols[0]} ${cols[1]} ${cols[2]} ${cols[3]}
done
echo ""

View File

@@ -11,6 +11,6 @@
, "Interface": "{{ interface }}" , "Interface": "{{ interface }}"
, "Port": 1234 , "Port": 1234
, "Host": "127.0.0.1" , "Host": "127.0.0.1"
, "Flags": ["-v", "--uid=stenographer", "--gid=stenographer"{{ bpf_compiled }}] , "Flags": ["-v", "--uid=stenographer", "--gid=stenographer"{{ BPF_COMPILED }}]
, "CertPath": "/etc/stenographer/certs" , "CertPath": "/etc/stenographer/certs"
} }

View File

@@ -12,8 +12,12 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
{% set VERSION = salt['pillar.get']('static:soversion', '1.1.4') %} {% set VERSION = salt['pillar.get']('static:soversion', 'HH1.1.4') %}
{% set MASTER = salt['grains.get']('master') %} {% set MASTER = salt['grains.get']('master') %}
{% set INTERFACE = salt['pillar.get']('sensor:interface', 'bond0') %}
{% set BPF_STENO = salt['pillar.get']('steno:bpf', None) %}
{% set BPF_COMPILED = "" %}
# PCAP Section # PCAP Section
# Create the logstash group # Create the logstash group
@@ -36,31 +40,19 @@ stenoconfdir:
- group: 939 - group: 939
- makedirs: True - makedirs: True
{% set interface = salt['pillar.get']('sensor:interface', 'bond0') %} {% if BPF_STENO %}
{% set bpf_global = salt['pillar.get']('static:steno:bpf', None) %} {% set BPF_CALC = salt['cmd.script']('/usr/sbin/so-bpf-compile', INTERFACE + ' ' + BPF_STENO|join(" ") ) %}
{% set bpf_steno = salt['pillar.get']('steno:bpf', None) %} {% if BPF_CALC['stderr'] == "" %}
{% set BPF_COMPILED = ",\\\"--filter=" + BPF_CALC['stdout'] + "\\\"" %}
{% if bpf_steno != None or bpf_global != None %}
{% if bpf_steno != None %}
{% set bpf_calc = salt['cmd.script']('salt://pcap/files/compile_bpf.sh', interface + ' ' + bpf_steno) %}
{% else %} {% else %}
{% set bpf_calc = salt['cmd.script']('salt://pcap/files/compile_bpf.sh', interface + ' ' + bpf_global) %}
{% endif %}
{% if bpf_calc['stderr'] == "" %}
{% set bpf_compiled = bpf_calc['stdout'] %}
{% else %}
{% set bpf_compiled = None %}
bpfcompilationfailure: bpfcompilationfailure:
test.configurable_test_state: test.configurable_test_state:
- name: bpfcompfailure
- changes: False - changes: False
- result: False - result: False
- comment: "BPF Compilation Failed - Discarding specified BPF" - comment: "BPF Compilation Failed - Discarding specified BPF"
{% endif %} {% endif %}
{% else %}
{% set bpf_compiled = None %}
{% endif %} {% endif %}
stenoconf: stenoconf:
@@ -72,11 +64,7 @@ stenoconf:
- mode: 644 - mode: 644
- template: jinja - template: jinja
- defaults: - defaults:
bpf_compiled: "" BPF_COMPILED: "{{ BPF_COMPILED }}"
{% if bpf_compiled != None %}
- context:
bpf_compiled: ',"--filter={{ bpf_compiled }}"'
{% endif %}
sensoroniagentconf: sensoroniagentconf:
file.managed: file.managed:
@@ -130,7 +118,7 @@ stenolog:
so-steno: so-steno:
docker_container.running: docker_container.running:
- image: {{ MASTER }}:5000/soshybridhunter/so-steno:HH{{ VERSION }} - image: {{ MASTER }}:5000/soshybridhunter/so-steno:{{ VERSION }}
- network_mode: host - network_mode: host
- privileged: True - privileged: True
- port_bindings: - port_bindings: