]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
bittorrent-dht: only attempt to parse dht messages
authorJason Ish <jason.ish@oisf.net>
Wed, 7 Sep 2022 22:46:20 +0000 (16:46 -0600)
committerVictor Julien <vjulien@oisf.net>
Fri, 28 Oct 2022 09:48:13 +0000 (11:48 +0200)
The bittorrent flow is shared with transport messages as well as dht
messages. Only attempt to parse dht message as dht, ignore the rest.

rust/src/bittorrent_dht/bittorrent_dht.rs

index 346635714f535ddd2b2ed17f20c1d8b97d9ee309..0e0d77fd87a6525bbcccb5d34db202d0adca938a 100644 (file)
@@ -92,7 +92,21 @@ impl BitTorrentDHTState {
         return tx;
     }
 
+    fn is_dht(input: &[u8]) -> bool {
+        if input.len() > 5 {
+            match &input[0..5] {
+                b"d1:ad" | b"d1:rd" | b"d2:ip" | b"d1:el" => true,
+                _ => false,
+            }
+        } else {
+            false
+        }
+    }
+
     pub fn parse(&mut self, input: &[u8]) -> bool {
+        if !Self::is_dht(input) {
+            return true;
+        }
         let mut tx = self.new_tx();
         let mut status = true;