Skip to content

Commit 03ba8a7

Browse files
catenacybervictorjulien
authored andcommitted
mqtt: bounds number of messages per tx
Ticket: 8525
1 parent 4985eb9 commit 03ba8a7

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

rules/mqtt-events.rules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ alert mqtt any any -> any any (msg:"SURICATA MQTT missing message ID"; app-layer
1313
alert mqtt any any -> any any (msg:"SURICATA MQTT unassigned message type (0 or >15)"; app-layer-event:mqtt.unassigned_msg_type; classtype:protocol-command-decode; sid:2229008; rev:1;)
1414
alert mqtt any any -> any any (msg:"SURICATA MQTT too many transactions"; app-layer-event:mqtt.too_many_transactions; classtype:protocol-command-decode; sid:2229009; rev:1;)
1515
alert mqtt any any -> any any (msg:"SURICATA MQTT malformed traffic"; app-layer-event:mqtt.malformed_traffic; classtype:protocol-command-decode; sid:2229010; rev:1;)
16+
alert mqtt any any -> any any (msg:"SURICATA MQTT too many messages"; app-layer-event:mqtt.too_many_messages; classtype:protocol-command-decode; sid:2229011; rev:1;)

rust/src/mqtt/mqtt.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ static mut MAX_MSG_LEN: u32 = 1048576;
4646

4747
static mut MQTT_MAX_TX: usize = 1024;
4848

49+
static mut MQTT_MAX_MSGS: usize = 1024;
50+
4951
pub(super) static mut ALPROTO_MQTT: AppProto = ALPROTO_UNKNOWN;
5052

5153
#[derive(AppLayerFrameType)]
@@ -68,6 +70,7 @@ pub enum MQTTEvent {
6870
UnassignedMsgType,
6971
TooManyTransactions,
7072
MalformedTraffic,
73+
TooManyMessages,
7174
}
7275

7376
#[derive(Debug)]
@@ -318,7 +321,11 @@ impl MQTTState {
318321
}
319322
MQTTOperation::PUBREC(ref v) | MQTTOperation::PUBREL(ref v) => {
320323
if let Some(tx) = self.get_tx_by_pkt_id(v.message_id as u32) {
321-
tx.msg.push(msg);
324+
if tx.msg.len() >= unsafe { MQTT_MAX_MSGS } {
325+
tx.tx_data.set_event(MQTTEvent::TooManyMessages as u8);
326+
} else {
327+
tx.msg.push(msg);
328+
}
322329
} else {
323330
let mut tx = self.new_tx(msg, toclient);
324331
MQTTState::set_event(&mut tx, MQTTEvent::MissingPublish);
@@ -801,6 +808,13 @@ pub unsafe extern "C" fn SCMqttRegisterParser() {
801808
SCLogError!("Invalid value for mqtt.max-tx");
802809
}
803810
}
811+
if let Some(val) = conf_get("app-layer.protocols.mqtt.max-messages") {
812+
if let Ok(v) = val.parse::<usize>() {
813+
MQTT_MAX_MSGS = v;
814+
} else {
815+
SCLogWarning!("Invalid value for mqtt.max-messages");
816+
}
817+
}
804818
if let Some(val) = conf_get("app-layer.protocols.mqtt.max-msg-length") {
805819
if let Ok(v) = get_memval(val) {
806820
MAX_MSG_LEN = v as u32;

suricata.yaml.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,8 @@ app-layer:
954954
# unsubscribe-topic-match-limit: 100
955955
# Maximum number of live MQTT transactions per flow
956956
# max-tx: 4096
957+
# Maximum number of messages per transaction
958+
# max-messages: 1024
957959
krb5:
958960
enabled: yes
959961
bittorrent-dht:

0 commit comments

Comments
 (0)