]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect-tls-version: add support for 'raw' matching
authorMats Klepsland <mats.klepsland@gmail.com>
Mon, 27 Aug 2018 08:13:00 +0000 (10:13 +0200)
committerMats Klepsland <mats.klepsland@gmail.com>
Sun, 16 Sep 2018 19:13:10 +0000 (21:13 +0200)
Add support for matching a 'raw' TLS version using a hex string, e.g:

  tls.version:0x7f12;

The above example matches TLSv1.3 draft 16.

src/detect-tls-version.c
src/detect-tls-version.h

index 4b994422a0af50c34c9ede06a9eb3b69e60c85d5..cc513e4b8903a09fb57b83f799b29567c8a6e3ea 100644 (file)
@@ -121,9 +121,11 @@ static int DetectTlsVersionMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx,
         SCLogDebug("client (toserver) version is 0x%02X", version);
     }
 
-    /* Match all TLSv1.3 drafts as TLSv1.3 */
-    if (((version >> 8) & 0xff) == 0x7f) {
-        version = TLS_VERSION_13;
+    if ((tls_data->flags & DETECT_TLS_VERSION_FLAG_RAW) == 0) {
+        /* Match all TLSv1.3 drafts as TLSv1.3 */
+        if (((version >> 8) & 0xff) == 0x7f) {
+            version = TLS_VERSION_13;
+        }
     }
 
     if (tls_data->ver == version) {
@@ -168,7 +170,7 @@ static DetectTlsVersionData *DetectTlsVersionParse (const char *str)
         }
 
         /* We have a correct id option */
-        tls = SCMalloc(sizeof(DetectTlsVersionData));
+        tls = SCCalloc(1, sizeof(DetectTlsVersionData));
         if (unlikely(tls == NULL))
             goto error;
 
@@ -185,14 +187,17 @@ static DetectTlsVersionData *DetectTlsVersionParse (const char *str)
             tmp_str += 1;
         }
 
-        if (strcmp("1.0", tmp_str) == 0) {
+        if (strncmp("1.0", tmp_str, 3) == 0) {
             temp = TLS_VERSION_10;
-        } else if (strcmp("1.1", tmp_str) == 0) {
+        } else if (strncmp("1.1", tmp_str, 3) == 0) {
             temp = TLS_VERSION_11;
-        } else if (strcmp("1.2", tmp_str) == 0) {
+        } else if (strncmp("1.2", tmp_str, 3) == 0) {
             temp = TLS_VERSION_12;
-        } else if (strcmp("1.3", tmp_str) == 0) {
+        } else if (strncmp("1.3", tmp_str, 3) == 0) {
             temp = TLS_VERSION_13;
+        } else if ((strncmp("0x", tmp_str, 2) == 0) && (strlen(str) == 6)) {
+            temp = (uint16_t)strtol(tmp_str, NULL, 0);
+            tls->flags |= DETECT_TLS_VERSION_FLAG_RAW;
         } else {
             SCLogError(SC_ERR_INVALID_VALUE, "Invalid value");
             SCFree(orig);
index c4dd16925e1ad9b0fbb5a83a2008aae794d2a869..fa808f39409d807a67914f09c67c741b9ce8d8ae 100644 (file)
 #ifndef __DETECT_TLS_VERSION_H__
 #define __DETECT_TLS_VERSION_H__
 
+#define DETECT_TLS_VERSION_FLAG_RAW  BIT_U8(0)
+
 typedef struct DetectTlsVersionData_ {
     uint16_t ver; /** tls version to match */
+    uint8_t flags;
 } DetectTlsVersionData;
 
 /* prototypes */