Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next/sv/125/20230904/v1 #1372

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
2 changes: 2 additions & 0 deletions tests/reputation-config/iprep-categories.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1,BadHosts,Known bad hosts
2,Google,Known google host
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1.2.3.4,1,101
1.2.3.5,1,101
1.1.1.0/24,6,88
24 changes: 24 additions & 0 deletions tests/reputation-config/reputation-config-cr-lf/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
command: |
${SRCDIR}/src/suricata -c "${SRCDIR}/suricata.yaml" -l "${OUTPUT_DIR}" \
--set "threshold-file=${TEST_DIR}/../threshold.config" \
--set "classification-file="${SRCDIR}`[ -f ${SRCDIR}/etc/classification.config ] && printf '/etc'`/classification.config \
--set "reference-config-file="${SRCDIR}`[ -f ${SRCDIR}/etc/reference.config ] && printf '/etc'`/reference.config \
-S "${TEST_DIR}/../test.rules" \
--set "reputation-categories-file=${TEST_DIR}/../iprep-categories.txt" \
--set "default-reputation-path=$TEST_DIR" \
--set "reputation-files.0=${TEST_DIR}/iprep-data.txt" \
--engine-analysis

checks:
- shell:
args: grep 'Loading reputation file' suricata.log | wc -l | xargs
expect: 1
- shell:
args: grep '1 rule files processed. 2 rules successfully loaded, 0 rules failed' suricata.log | wc -l | xargs
expect: 1
- shell:
args: grep '2 signatures processed' suricata.log | wc -l | xargs
expect: 1
- shell:
args: grep 'Error[:]' suricata.log | wc -l | xargs
expect: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.2.3.4,1,1011.2.3.5,1,1011.1.1.0/24,6,88
Expand Down
24 changes: 24 additions & 0 deletions tests/reputation-config/reputation-config-cr/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
command: |
${SRCDIR}/src/suricata -c "${SRCDIR}/suricata.yaml" -l "${OUTPUT_DIR}" \
--set "threshold-file=${TEST_DIR}/../threshold.config" \
--set "classification-file="${SRCDIR}`[ -f ${SRCDIR}/etc/classification.config ] && printf '/etc'`/classification.config \
--set "reference-config-file="${SRCDIR}`[ -f ${SRCDIR}/etc/reference.config ] && printf '/etc'`/reference.config \
-S "${TEST_DIR}/../test.rules" \
--set "reputation-categories-file=${TEST_DIR}/../iprep-categories.txt" \
--set "default-reputation-path=$TEST_DIR" \
--set "reputation-files.0=${TEST_DIR}/iprep-data.txt" \
--engine-analysis

checks:
- shell:
args: grep 'Loading reputation file' suricata.log | wc -l | xargs
expect: 1
- shell:
args: grep '1 rule files processed. 2 rules successfully loaded, 0 rules failed' suricata.log | wc -l | xargs
expect: 1
- shell:
args: grep '2 signatures processed' suricata.log | wc -l | xargs
expect: 1
- shell:
args: grep 'Error[:]' suricata.log | wc -l | xargs
expect: 0
3 changes: 3 additions & 0 deletions tests/reputation-config/reputation-config-lf/iprep-data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1.2.3.4,1,101
1.2.3.5,1,101
1.1.1.0/24,6,88
24 changes: 24 additions & 0 deletions tests/reputation-config/reputation-config-lf/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
command: |
${SRCDIR}/src/suricata -c "${SRCDIR}/suricata.yaml" -l "${OUTPUT_DIR}" \
--set "threshold-file=${TEST_DIR}/../threshold.config" \
--set "classification-file="${SRCDIR}`[ -f ${SRCDIR}/etc/classification.config ] && printf '/etc'`/classification.config \
--set "reference-config-file="${SRCDIR}`[ -f ${SRCDIR}/etc/reference.config ] && printf '/etc'`/reference.config \
-S "${TEST_DIR}/../test.rules" \
--set "reputation-categories-file=${TEST_DIR}/../iprep-categories.txt" \
--set "default-reputation-path=$TEST_DIR" \
--set "reputation-files.0=${TEST_DIR}/iprep-data.txt" \
--engine-analysis

checks:
- shell:
args: grep 'Loading reputation file' suricata.log | wc -l | xargs
expect: 1
- shell:
args: grep '1 rule files processed. 2 rules successfully loaded, 0 rules failed' suricata.log | wc -l | xargs
expect: 1
- shell:
args: grep '2 signatures processed' suricata.log | wc -l | xargs
expect: 1
- shell:
args: grep 'Error[:]' suricata.log | wc -l | xargs
expect: 0
20 changes: 20 additions & 0 deletions tests/reputation-config/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pathlib import Path

# Create config files with a mix syntax
test = 'reputation-config'
test_options = [
{ 'path': f'{test}-lf', 'eol': '\n' },
{ 'path': f'{test}-cr', 'eol': '\r' },
{ 'path': f'{test}-cr-lf', 'eol': '\r\n' },
]

# Categories and IPs from
# https://docs.suricata.io/en/suricata-6.0.0/reputation/ipreputation/ip-reputation-format.html

for test in test_options:
path, eol = Path(test['path']), test['eol']

with open(path / 'iprep-data.txt', 'w') as rep_cfg:
rep_cfg.write(f'1.2.3.4,1,101{eol}')
rep_cfg.write(f'1.2.3.5,1,101{eol}')
rep_cfg.write(f'1.1.1.0/24,6,88{eol}')
2 changes: 2 additions & 0 deletions tests/reputation-config/test.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alert ip any any -> any any (msg:"BadHosts: Some bad hosts have been detected"; iprep:any,BadHosts,>,30; sid:1; rev:1;)
alert ip any any -> any any (msg:"Google: Some google host has been detected"; iprep:any,Google,>,30; sid:2; rev:1;)
Empty file.