]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: support file.data for HTTP1 to server
authorPhilippe Antoine <pantoine@oisf.net>
Wed, 24 Aug 2022 20:22:53 +0000 (22:22 +0200)
committerVictor Julien <vjulien@oisf.net>
Fri, 26 Aug 2022 13:50:02 +0000 (15:50 +0200)
That is file sent with POST or PUT

Ticket: #4144

src/detect-file-data.c
src/tests/detect-file-data.c

index 0904b7c527a0e7d648e95801b34f1a8b77cac734..a8096067f99ed088afb4726f1e71e6ba78d63aae 100644 (file)
@@ -97,6 +97,8 @@ void DetectFiledataRegister(void)
             ALPROTO_SMTP, 0);
     DetectAppLayerMpmRegister2("file_data", SIG_FLAG_TOCLIENT, 2, PrefilterMpmHTTPFiledataRegister,
             NULL, ALPROTO_HTTP1, HTP_RESPONSE_BODY);
+    DetectAppLayerMpmRegister2("file_data", SIG_FLAG_TOSERVER, 2, PrefilterMpmFiledataRegister,
+            NULL, ALPROTO_HTTP1, HTP_REQUEST_BODY);
     DetectAppLayerMpmRegister2("file_data", SIG_FLAG_TOSERVER, 2,
             PrefilterMpmFiledataRegister, NULL,
             ALPROTO_SMB, 0);
@@ -124,6 +126,8 @@ void DetectFiledataRegister(void)
 
     DetectAppLayerInspectEngineRegister2("file_data", ALPROTO_HTTP1, SIG_FLAG_TOCLIENT,
             HTP_RESPONSE_BODY, DetectEngineInspectBufferHttpBody, NULL);
+    DetectAppLayerInspectEngineRegister2("file_data", ALPROTO_HTTP1, SIG_FLAG_TOSERVER,
+            HTP_REQUEST_BODY, DetectEngineInspectFiledata, NULL);
     DetectAppLayerInspectEngineRegister2("file_data",
             ALPROTO_SMTP, SIG_FLAG_TOSERVER, 0,
             DetectEngineInspectFiledata, NULL);
@@ -210,14 +214,6 @@ static int DetectFiledataSetup (DetectEngineCtx *de_ctx, Signature *s, const cha
         return -1;
     }
 
-    if ((s->alproto == ALPROTO_HTTP1 || s->alproto == ALPROTO_HTTP) &&
-            (s->init_data->init_flags & SIG_FLAG_INIT_FLOW) && (s->flags & SIG_FLAG_TOSERVER) &&
-            !(s->flags & SIG_FLAG_TOCLIENT)) {
-        SCLogError(SC_ERR_INVALID_SIGNATURE, "Can't use file_data with "
-                "flow:to_server or flow:from_client with http.");
-        return -1;
-    }
-
     if (s->alproto == ALPROTO_SMTP && (s->init_data->init_flags & SIG_FLAG_INIT_FLOW) &&
         !(s->flags & SIG_FLAG_TOSERVER) && (s->flags & SIG_FLAG_TOCLIENT)) {
         SCLogError(SC_ERR_INVALID_SIGNATURE, "Can't use file_data with "
index 444a1f026de90e219d78d50ed30fcc9a357b6deb..e96b3418a3b2cc5a70203343a9da7038d907329a 100644 (file)
@@ -106,22 +106,6 @@ static int DetectFiledataParseTest04(void)
     PASS;
 }
 
-/**
- * \test Test the file_data fails with flow:to_server.
- */
-static int DetectFiledataParseTest05(void)
-{
-    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
-    FAIL_IF_NULL(de_ctx);
-    de_ctx->flags |= DE_QUIET;
-    Signature *s = DetectEngineAppendSig(de_ctx,
-            "alert http any any -> any any "
-            "(msg:\"test\"; flow:to_server,established; file_data; content:\"abc\"; sid:1;)");
-    FAIL_IF_NOT_NULL(s);
-    DetectEngineCtxFree(de_ctx);
-    PASS;
-}
-
 static int DetectFiledataIsdataatParseTest1(void)
 {
     DetectEngineCtx *de_ctx = DetectEngineCtxInit();
@@ -184,7 +168,6 @@ void DetectFiledataRegisterTests(void)
     UtRegisterTest("DetectFiledataParseTest02", DetectFiledataParseTest02);
     UtRegisterTest("DetectFiledataParseTest03", DetectFiledataParseTest03);
     UtRegisterTest("DetectFiledataParseTest04", DetectFiledataParseTest04);
-    UtRegisterTest("DetectFiledataParseTest05", DetectFiledataParseTest05);
 
     UtRegisterTest("DetectFiledataIsdataatParseTest1",
             DetectFiledataIsdataatParseTest1);