]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect-tls-ja3-hash: add setup callback to lowercase content
authorMats Klepsland <mats.klepsland@gmail.com>
Sat, 24 Mar 2018 22:16:40 +0000 (23:16 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 3 May 2018 12:50:47 +0000 (14:50 +0200)
Add setup callback that lowercase the content that follows 'ja3_hash'.

src/detect-tls-ja3-hash.c

index ab9af80fa7b9fe69d66a21b977b2baaa2b2d50be..5f39062f30f24fe9af767884c738ef51a1de7508 100644 (file)
@@ -64,6 +64,8 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
        const DetectEngineTransforms *transforms,
        Flow *_f, const uint8_t _flow_flags,
        void *txv, const int list_id);
+static void DetectTlsJa3HashSetupCallback(const DetectEngineCtx *de_ctx,
+       Signature *s);
 static _Bool DetectTlsJa3HashValidateCallback(const Signature *s,
        const char **sigerror);
 static int g_tls_ja3_hash_buffer_id = 0;
@@ -91,6 +93,9 @@ void DetectTlsJa3HashRegister(void)
 
     DetectBufferTypeSetDescriptionByName("ja3_hash", "TLS JA3 hash");
 
+    DetectBufferTypeRegisterSetupCallback("ja3_hash",
+            DetectTlsJa3HashSetupCallback);
+
     DetectBufferTypeRegisterValidateCallback("ja3_hash",
             DetectTlsJa3HashValidateCallback);
 
@@ -176,6 +181,36 @@ static _Bool DetectTlsJa3HashValidateCallback(const Signature *s,
     return TRUE;
 }
 
+static void DetectTlsJa3HashSetupCallback(const DetectEngineCtx *de_ctx,
+                                          Signature *s)
+{
+    SigMatch *sm = s->init_data->smlists[g_tls_ja3_hash_buffer_id];
+    for ( ; sm != NULL; sm = sm->next)
+    {
+        if (sm->type != DETECT_CONTENT)
+            continue;
+
+        DetectContentData *cd = (DetectContentData *)sm->ctx;
+
+        _Bool changed = FALSE;
+        uint32_t u;
+        for (u = 0; u < cd->content_len; u++)
+        {
+            if (isupper(cd->content[u])) {
+                cd->content[u] = tolower(cd->content[u]);
+                changed = TRUE;
+            }
+        }
+
+        /* recreate the context if changes were made */
+        if (changed) {
+            SpmDestroyCtx(cd->spm_ctx);
+            cd->spm_ctx = SpmInitCtx(cd->content, cd->content_len, 1,
+                                     de_ctx->spm_global_thread_ctx);
+        }
+    }
+}
+
 #ifndef HAVE_NSS
 
 static void DetectTlsJa3HashRegisterTests(void)