Skip to content

Commit

Permalink
detect: http_client_body for HTTP2
Browse files Browse the repository at this point in the history
By using the file.data logic

Ticket: OISF#4067
  • Loading branch information
catenacyber authored and victorjulien committed May 12, 2023
1 parent 6b32bc4 commit 656cddc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
12 changes: 1 addition & 11 deletions src/detect-file-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ static int PrefilterMpmHTTPFiledataRegister(DetectEngineCtx *de_ctx, SigGroupHea
MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id);

/* file API */
static uint8_t DetectEngineInspectFiledata(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags,
void *alstate, void *txv, uint64_t tx_id);
int PrefilterMpmFiledataRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx,
const DetectBufferMpmRegistry *mpm_reg, int list_id);

Expand Down Expand Up @@ -240,13 +237,6 @@ static void DetectFiledataSetupCallback(const DetectEngineCtx *de_ctx,

/* common */

typedef struct PrefilterMpmFiledata {
int list_id;
int base_list_id;
const MpmCtx *mpm_ctx;
const DetectEngineTransforms *transforms;
} PrefilterMpmFiledata;

static void PrefilterMpmFiledataFree(void *ptr)
{
SCFree(ptr);
Expand Down Expand Up @@ -588,7 +578,7 @@ static InspectionBuffer *FiledataGetDataCallback(DetectEngineThreadCtx *det_ctx,
}
}

static uint8_t DetectEngineInspectFiledata(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
uint8_t DetectEngineInspectFiledata(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags,
void *alstate, void *txv, uint64_t tx_id)
{
Expand Down
13 changes: 13 additions & 0 deletions src/detect-file-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,17 @@
/* prototypes */
void DetectFiledataRegister (void);

typedef struct PrefilterMpmFiledata {
int list_id;
int base_list_id;
const MpmCtx *mpm_ctx;
const DetectEngineTransforms *transforms;
} PrefilterMpmFiledata;

uint8_t DetectEngineInspectFiledata(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags,
void *alstate, void *txv, uint64_t tx_id);
int PrefilterMpmFiledataRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx,
const DetectBufferMpmRegistry *mpm_reg, int list_id);

#endif /* __DETECT_FILEDATA_H__ */
9 changes: 8 additions & 1 deletion src/detect-http-client-body.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include "detect-engine-content-inspection.h"
#include "detect-content.h"
#include "detect-pcre.h"
// PrefilterMpmFiledata
#include "detect-file-data.h"

#include "flow.h"
#include "flow-var.h"
Expand Down Expand Up @@ -107,6 +109,11 @@ void DetectHttpClientBodyRegister(void)
DetectAppLayerMpmRegister2("http_client_body", SIG_FLAG_TOSERVER, 2,
PrefilterMpmHttpRequestBodyRegister, NULL, ALPROTO_HTTP1, HTP_REQUEST_BODY);

DetectAppLayerInspectEngineRegister2("http_client_body", ALPROTO_HTTP2, SIG_FLAG_TOSERVER,
HTTP2StateDataClient, DetectEngineInspectFiledata, NULL);
DetectAppLayerMpmRegister2("http_client_body", SIG_FLAG_TOSERVER, 2,
PrefilterMpmFiledataRegister, NULL, ALPROTO_HTTP2, HTTP2StateDataClient);

DetectBufferTypeSetDescriptionByName("http_client_body",
"http request body");

Expand Down Expand Up @@ -158,7 +165,7 @@ static int DetectHttpClientBodySetupSticky(DetectEngineCtx *de_ctx, Signature *s
{
if (DetectBufferSetActiveList(de_ctx, s, g_http_client_body_buffer_id) < 0)
return -1;
if (DetectSignatureSetAppProto(s, ALPROTO_HTTP1) < 0)
if (DetectSignatureSetAppProto(s, ALPROTO_HTTP) < 0)
return -1;
return 0;
}
Expand Down

0 comments on commit 656cddc

Please sign in to comment.