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

mqtt: add additional tests for reason codes #2102

Closed
wants to merge 3 commits into from
Closed
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
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/mqtt-connect-rules-2/suricata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%YAML 1.1
---

outputs:
- eve-log:
enabled: yes
filetype: regular
filename: eve.json
types:
- mqtt
- alert

app-layer:
protocols:
mqtt:
enabled: yes
4 changes: 4 additions & 0 deletions tests/mqtt-connect-rules-2/test.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alert mqtt any any -> any any (msg:"MQTT CONNACK reason code 134"; mqtt.type:CONNACK; mqtt.reason_code:134; sid:1;)
alert mqtt any any -> any any (msg:"MQTT CONNACK reason code 0"; mqtt.type:CONNACK; mqtt.reason_code:0; sid:2;)


19 changes: 19 additions & 0 deletions tests/mqtt-connect-rules-2/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
requires:
min-version: 8

args:
- -k none

checks:

- filter:
count: 1
match:
event_type: alert
alert.signature: MQTT CONNACK reason code 134

- filter:
count: 0
match:
event_type: alert
alert.signature: MQTT CONNACK reason code 0
2 changes: 2 additions & 0 deletions tests/mqtt-connect-rules/test.rules
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
alert mqtt any any -> any any (msg:"MQTT CONNECT protocol string SUCCESS"; mqtt.connect.protocol_string; content:"MQTT"; sid:1;)
alert mqtt any any -> any any (msg:"MQTT CONNECT protocol string SUCCESS2"; mqtt.connect.protocol_string; content:"M"; sid:2;)
alert mqtt any any -> any any (msg:"MQTT CONNECT protocol string FAIL"; mqtt.connect.protocol_string; content:"Foobar"; sid:3;)
alert mqtt any any -> any any (msg:"MQTT CONNACK reason code 0"; mqtt.type:CONNACK; mqtt.reason_code:0; sid:4;)
alert mqtt any any -> any any (msg:"MQTT DISCONNECT reason code 0"; mqtt.type:DISCONNECT; mqtt.reason_code:0; sid:5;)

12 changes: 12 additions & 0 deletions tests/mqtt-connect-rules/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,15 @@ checks:
match:
event_type: alert
alert.signature: MQTT CONNECT protocol string FAIL

- filter:
count: 1
match:
event_type: alert
alert.signature: MQTT CONNACK reason code 0

- filter:
count: 1
match:
event_type: alert
alert.signature: MQTT DISCONNECT reason code 0
2 changes: 1 addition & 1 deletion tests/mqtt-sub-rules/test.rules
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ alert mqtt any any -> any any (msg:"MQTT CONNECT flags"; mqtt.connect.flags:user
alert mqtt any any -> any any (msg:"MQTT CONNECT username"; mqtt.connect.username; content:"user"; sid:19;)
alert mqtt any any -> any any (msg:"MQTT CONNECT password"; mqtt.connect.password; content:"pass"; sid:20;)
alert mqtt any any -> any any (msg:"MQTT SUBSCRIBE topicY"; mqtt.type:SUBSCRIBE; mqtt.subscribe.topic; content:"topicY"; sid:15;)
alert mqtt any any -> any any (msg:"MQTT SUBSCRIBE topicY"; mqtt.type:SUBACK; mqtt.reason_code:0; sid:16;)
alert mqtt any any -> any any (msg:"MQTT SUBACK topicY reason code 0"; mqtt.type:SUBACK; mqtt.subscribe.topic; content:"topicY"; mqtt.reason_code:0; sid:16;)
16 changes: 16 additions & 0 deletions tests/mqtt-sub-rules/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ checks:
mqtt.subscribe.dup: false
mqtt.subscribe.topics: [{topic: topicX, qos: 0}, {topic: topicY, qos: 0} ]

- filter:
count: 1
match:
event_type: mqtt
mqtt.suback.qos: 0
mqtt.suback.retain: false
mqtt.suback.dup: false
mqtt.suback.message_id: 1
mqtt.suback.qos_granted: [ 0, 0 ]

- filter:
count: 1
match:
Expand Down Expand Up @@ -109,3 +119,9 @@ checks:
match:
event_type: alert
alert.signature: MQTT SUBSCRIBE topicY

- filter:
satta marked this conversation as resolved.
Show resolved Hide resolved
count: 1
match:
event_type: alert
alert.signature: MQTT SUBACK topicY reason code 0
Loading