]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/http_method: add http.method sticky buffer
authorVictor Julien <victor@inliniac.net>
Sun, 25 Nov 2018 15:44:54 +0000 (16:44 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 29 Jan 2019 12:27:57 +0000 (13:27 +0100)
src/detect-engine-register.h
src/detect-http-method.c

index b3787a2b69c6bf9b49909a2b8df10f0f3c738398..00364844c8721a6890b2ff3ee06d320f22eb9985 100644 (file)
@@ -113,6 +113,7 @@ enum {
 
     DETECT_AL_HTTP_COOKIE,
     DETECT_AL_HTTP_METHOD,
+    DETECT_HTTP_METHOD,
     DETECT_AL_HTTP_PROTOCOL,
     DETECT_AL_HTTP_START,
     DETECT_AL_URILEN,
index 48a96aac018e5ca09ace46eaa5a43e6e3eb43954..42b2247b8ab05ffcc7369121fb63dc81c1566fc1 100644 (file)
@@ -61,6 +61,7 @@
 
 static int g_http_method_buffer_id = 0;
 static int DetectHttpMethodSetup(DetectEngineCtx *, Signature *, const char *);
+static int DetectHttpMethodSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str);
 #ifdef UNITTESTS
 void DetectHttpMethodRegisterTests(void);
 #endif
@@ -75,6 +76,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
  */
 void DetectHttpMethodRegister(void)
 {
+    /* http_method content modifier */
     sigmatch_table[DETECT_AL_HTTP_METHOD].name = "http_method";
     sigmatch_table[DETECT_AL_HTTP_METHOD].desc = "content modifier to match only on the HTTP method-buffer";
     sigmatch_table[DETECT_AL_HTTP_METHOD].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-method";
@@ -85,6 +87,13 @@ void DetectHttpMethodRegister(void)
 #endif
     sigmatch_table[DETECT_AL_HTTP_METHOD].flags |= SIGMATCH_NOOPT;
 
+    /* http.method sticky buffer */
+    sigmatch_table[DETECT_HTTP_METHOD].name = "http.method";
+    sigmatch_table[DETECT_HTTP_METHOD].desc = "sticky buffer to match specifically and only on the HTTP method buffer";
+    sigmatch_table[DETECT_HTTP_METHOD].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-method";
+    sigmatch_table[DETECT_HTTP_METHOD].Setup = DetectHttpMethodSetupSticky;
+    sigmatch_table[DETECT_HTTP_METHOD].flags |= SIGMATCH_NOOPT;
+
     DetectAppLayerInspectEngineRegister2("http_method", ALPROTO_HTTP,
             SIG_FLAG_TOSERVER, HTP_REQUEST_LINE,
             DetectEngineInspectBufferGeneric, GetData);
@@ -123,6 +132,22 @@ static int DetectHttpMethodSetup(DetectEngineCtx *de_ctx, Signature *s, const ch
                                                   ALPROTO_HTTP);
 }
 
+/**
+ * \brief this function setup the http.method keyword used in the rule
+ *
+ * \param de_ctx   Pointer to the Detection Engine Context
+ * \param s        Pointer to the Signature to which the current keyword belongs
+ * \param str      Should hold an empty string always
+ *
+ * \retval 0       On success
+ */
+static int DetectHttpMethodSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str)
+{
+    DetectBufferSetActiveList(s, g_http_method_buffer_id);
+    s->alproto = ALPROTO_HTTP;
+    return 0;
+}
+
 /**
  *  \retval 1 valid
  *  \retval 0 invalid