]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: add http.stat_code sticky buffer keyword
authorVictor Julien <victor@inliniac.net>
Mon, 26 Nov 2018 12:34:16 +0000 (13:34 +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-stat-code.c

index dfe964b476e7781e9a963b5e9c5da5a1ca05bd71..e0a5d9d394467dd808bb42b107ab0a152a4c0a25 100644 (file)
@@ -136,6 +136,7 @@ enum {
     DETECT_AL_HTTP_STAT_MSG,
     DETECT_HTTP_STAT_MSG,
     DETECT_AL_HTTP_STAT_CODE,
+    DETECT_HTTP_STAT_CODE,
     DETECT_AL_HTTP_USER_AGENT,
     DETECT_HTTP_UA,
     DETECT_AL_HTTP_HOST,
index 02ad637b4cf8a3792bed0d7089a2373d76b98284..bf2cd16087e707d50560aa3906d78a4d7e73fb8e 100644 (file)
@@ -64,6 +64,7 @@
 #include "stream-tcp.h"
 
 static int DetectHttpStatCodeSetup(DetectEngineCtx *, Signature *, const char *);
+static int DetectHttpStatCodeSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str);
 #ifdef UNITTESTS
 static void DetectHttpStatCodeRegisterTests(void);
 #endif
@@ -77,6 +78,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
  */
 void DetectHttpStatCodeRegister (void)
 {
+    /* http_stat_code content modifier */
     sigmatch_table[DETECT_AL_HTTP_STAT_CODE].name = "http_stat_code";
     sigmatch_table[DETECT_AL_HTTP_STAT_CODE].desc = "content modifier to match only on HTTP stat-code-buffer";
     sigmatch_table[DETECT_AL_HTTP_STAT_CODE].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-stat-code";
@@ -86,6 +88,13 @@ void DetectHttpStatCodeRegister (void)
 #endif
     sigmatch_table[DETECT_AL_HTTP_STAT_CODE].flags |= SIGMATCH_NOOPT;
 
+    /* http.stat_code content modifier */
+    sigmatch_table[DETECT_HTTP_STAT_CODE].name = "http.stat_code";
+    sigmatch_table[DETECT_HTTP_STAT_CODE].desc = "sticky buffer to match only on HTTP stat-code-buffer";
+    sigmatch_table[DETECT_HTTP_STAT_CODE].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http_stat-code";
+    sigmatch_table[DETECT_HTTP_STAT_CODE].Setup = DetectHttpStatCodeSetupSticky;
+    sigmatch_table[DETECT_HTTP_STAT_CODE].flags |= SIGMATCH_NOOPT;
+
     DetectAppLayerInspectEngineRegister2("http_stat_code", ALPROTO_HTTP,
             SIG_FLAG_TOCLIENT, HTP_RESPONSE_LINE,
             DetectEngineInspectBufferGeneric, GetData);
@@ -119,6 +128,22 @@ static int DetectHttpStatCodeSetup(DetectEngineCtx *de_ctx, Signature *s, const
                                                   ALPROTO_HTTP);
 }
 
+/**
+ * \brief this function setup the http.stat_code 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 DetectHttpStatCodeSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str)
+{
+    DetectBufferSetActiveList(s, g_http_stat_code_buffer_id);
+    s->alproto = ALPROTO_HTTP;
+    return 0;
+}
+
 static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
         const DetectEngineTransforms *transforms, Flow *_f,
         const uint8_t _flow_flags, void *txv, const int list_id)