Skip to content

Commit 8884ea2

Browse files
committed
snort3_demo: build so_rule 3_13 using cmake. The result is more portable
1 parent 5c84405 commit 8884ea2

File tree

6 files changed

+89
-17
lines changed

6 files changed

+89
-17
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
install/
3+
sid_3_13.h
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
cmake_minimum_required ( VERSION 3.4.3 )
2+
project (sorule_id_3_13 C CXX)
3+
4+
set (CMAKE_CXX_STANDARD 14)
5+
set (CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set (CMAKE_CXX_EXTENSIONS OFF)
7+
8+
include ( FindPkgConfig )
9+
pkg_search_module ( SNORT3 REQUIRED snort>=3 )
10+
11+
add_library (
12+
so_rule
13+
MODULE
14+
sid_3_13.cc
15+
sid_3_13.h
16+
)
17+
18+
target_compile_options (
19+
so_rule
20+
PRIVATE
21+
-fno-rtti
22+
)
23+
24+
set_target_properties (
25+
so_rule
26+
PROPERTIES
27+
PREFIX ""
28+
)
29+
30+
target_include_directories (
31+
so_rule PUBLIC
32+
${SNORT3_INCLUDE_DIRS}
33+
)
34+
35+
install (
36+
TARGETS so_rule
37+
LIBRARY
38+
DESTINATION "${CMAKE_SOURCE_DIR}/install"
39+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.PHONY: build sid_3-13.h install clean
2+
3+
build: sid_3_13.h
4+
cmake -B build/ -G Ninja .
5+
cmake --build build/
6+
7+
sid_3_13.h: sid_3_13.txt
8+
snort --rule-to-text < sid_3_13.txt > sid_3_13.h
9+
10+
install:
11+
cmake --install build/
12+
13+
clean:
14+
rm sid_3_13.h
15+
rm -rf build/
16+
rm -rf install/
File renamed without changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
alert http
2+
(
3+
msg:"Too much Cheez Whiz is bad mkay.";
4+
flow:to_server,established;
5+
http_uri; content:"crazy";
6+
http_uri:query; content:"withThe=CheezWhiz";
7+
http_uri:query; content:"cans=";
8+
service:http;
9+
reference:url,http://www.kraftbrands.com/cheezwhiz/;
10+
classtype:misc-activity;
11+
gid:3;
12+
sid:13;
13+
rev:1;
14+
soid:3_13_1;
15+
so:cans 7;
16+
)
17+

tests/ips_options/so_and_soid/test.bats

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,32 @@ base=sid_3_13
55
pcap="cheez.pcap"
66
cfg="snort.lua"
77

8-
gcc_opts="-std=c++14 -Wall -g -ggdb -O0"
9-
stub_opts="--warn-all --plugin-path ."
8+
stub_opts="--warn-all --plugin-path so_rule/install"
109
run_opts="-q -A csv"
1110

1211
setup()
1312
{
14-
CXX=g++
15-
16-
if [[ "$OSTYPE" == "freebsd"* ]]; then
17-
CXX='clang++'
18-
elif [[ "$OSTYPE" == "linux-musl"* ]]; then
19-
gcc_opts="-std=c++14 -Wall -g -ggdb -O0"
20-
fi
21-
22-
local cppflags="$(pkg-config --cflags snort) $(pkg-config --variable=DAQ_CPPFLAGS snort)"
23-
24-
$snort --rule-to-text < $base.txt > $base.h
25-
${CXX} -c $gcc_opts $cppflags -fPIC -o $base.o $base.cc
26-
${CXX} -shared -o $base.so $base.o
13+
pushd so_rule/
14+
make sid_3_13.h build install
15+
popd
16+
ls -alh so_rule/install
2717
}
2818

2919
@test "SO and SOID - 3:13" {
20+
echo $snort $stub_opts --dump-dynamic-rules > stub.rule
3021
$snort $stub_opts --dump-dynamic-rules > stub.rule
22+
23+
echo $snort $stub_opts -c $cfg -R stub.rule -r $pcap $run_opts &> snort.out
3124
$snort $stub_opts -c $cfg -R stub.rule -r $pcap $run_opts &> snort.out
25+
26+
cat snort.out
3227
cat stub.rule snort.out | diff expected -
3328
}
3429

3530
teardown()
3631
{
37-
rm -f snort.out *.z *.o *.so stub.rule *.h
32+
pushd so_rule/
33+
make clean
34+
popd
35+
rm -f snort.out stub.rule
3836
}
39-

0 commit comments

Comments
 (0)