-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
detect: helper to have pure rust keywords
Only implemented for snmp.version and mqtt.password But should be implemented for more
- Loading branch information
1 parent
9942cc0
commit 580bb9c
Showing
6 changed files
with
186 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* Copyright (C) 2023 Open Information Security Foundation | ||
* | ||
* You can copy, redistribute or modify this Program under the terms of | ||
* the GNU General Public License version 2 as published by the Free | ||
* Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
/** | ||
* \file | ||
* | ||
* \author Philippe Antoine <[email protected]> | ||
* | ||
*/ | ||
|
||
#include "suricata-common.h" | ||
#include "detect-engine.h" | ||
#include "detect-engine-helper.h" | ||
#include "detect-engine-mpm.h" | ||
#include "detect-engine-prefilter.h" | ||
#include "detect-parse.h" | ||
|
||
int DetectHelperBufferRegister(const char *name, AppProto alproto, bool toclient, bool toserver) | ||
{ | ||
if (toserver) { | ||
DetectAppLayerInspectEngineRegister2( | ||
name, alproto, SIG_FLAG_TOSERVER, 0, DetectEngineInspectGenericList, NULL); | ||
} | ||
if (toclient) { | ||
DetectAppLayerInspectEngineRegister2( | ||
name, alproto, SIG_FLAG_TOCLIENT, 0, DetectEngineInspectGenericList, NULL); | ||
} | ||
return DetectBufferTypeRegister(name); | ||
} | ||
|
||
InspectionBuffer *DetectHelperGetData(struct DetectEngineThreadCtx_ *det_ctx, | ||
const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, | ||
const int list_id, | ||
bool (*GetBuf)(void *txv, const uint8_t flow_flags, const uint8_t **buf, uint32_t *buf_len)) | ||
{ | ||
InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id); | ||
if (buffer->inspect == NULL) { | ||
const uint8_t *b = NULL; | ||
uint32_t b_len = 0; | ||
|
||
if (!GetBuf(txv, flow_flags, &b, &b_len)) | ||
return NULL; | ||
|
||
InspectionBufferSetup(det_ctx, list_id, buffer, b, b_len); | ||
InspectionBufferApplyTransforms(buffer, transforms); | ||
} | ||
return buffer; | ||
} | ||
|
||
int DetectHelperBufferMpmRegister(const char *name, const char *desc, AppProto alproto, | ||
bool toclient, bool toserver, InspectionBufferGetDataPtr GetData) | ||
{ | ||
if (toserver) { | ||
DetectAppLayerInspectEngineRegister2( | ||
name, alproto, SIG_FLAG_TOSERVER, 0, DetectEngineInspectBufferGeneric, GetData); | ||
DetectAppLayerMpmRegister2( | ||
name, SIG_FLAG_TOSERVER, 2, PrefilterGenericMpmRegister, GetData, alproto, 0); | ||
} | ||
if (toclient) { | ||
DetectAppLayerInspectEngineRegister2( | ||
name, alproto, SIG_FLAG_TOCLIENT, 0, DetectEngineInspectBufferGeneric, GetData); | ||
DetectAppLayerMpmRegister2( | ||
name, SIG_FLAG_TOCLIENT, 2, PrefilterGenericMpmRegister, GetData, alproto, 0); | ||
} | ||
DetectBufferTypeSetDescriptionByName(name, desc); | ||
return DetectBufferTypeGetByName(name); | ||
} | ||
|
||
int DetectHelperKeywordRegister(const SCPluginSigTableElmt *kw) | ||
{ | ||
if (DETECT_TBLSIZE_IDX < DETECT_TBLSIZE) { | ||
sigmatch_table[DETECT_TBLSIZE_IDX].name = kw->name; | ||
sigmatch_table[DETECT_TBLSIZE_IDX].desc = kw->desc; | ||
sigmatch_table[DETECT_TBLSIZE_IDX].flags = kw->flags; | ||
sigmatch_table[DETECT_TBLSIZE_IDX].AppLayerTxMatch = kw->AppLayerTxMatch; | ||
sigmatch_table[DETECT_TBLSIZE_IDX].Setup = kw->Setup; | ||
sigmatch_table[DETECT_TBLSIZE_IDX].Free = kw->Free; | ||
DETECT_TBLSIZE_IDX++; | ||
return DETECT_TBLSIZE_IDX - 1; | ||
} | ||
return -1; | ||
} | ||
|
||
int DetectHelperKeywordSetup(DetectEngineCtx *de_ctx, AppProto alproto, uint16_t kw_id, int buf_id, | ||
Signature *s, void *ctx) | ||
{ | ||
if (DetectSignatureSetAppProto(s, alproto) != 0) | ||
return -1; | ||
|
||
/* okay so far so good, lets get this into a SigMatch | ||
* and put it in the Signature. */ | ||
if (SigMatchAppendSMToList(de_ctx, s, kw_id, (SigMatchCtx *)ctx, buf_id) == NULL) { | ||
return -1; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* Copyright (C) 2023 Open Information Security Foundation | ||
* | ||
* You can copy, redistribute or modify this Program under the terms of | ||
* the GNU General Public License version 2 as published by the Free | ||
* Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
/** | ||
* \file | ||
* | ||
* \author Philippe Antoine <[email protected]> | ||
*/ | ||
|
||
#ifndef __DETECT_ENGINE_HELPER_H | ||
#define __DETECT_ENGINE_HELPER_H | ||
|
||
#include "app-layer-protos.h" | ||
#include "detect.h" | ||
|
||
// Structure for keyword dynamic registration by plugin | ||
typedef struct SCPluginSigTableElmt { | ||
const char *name; | ||
const char *desc; | ||
uint16_t flags; | ||
int (*Setup)(DetectEngineCtx *, Signature *, const char *); | ||
void (*Free)(DetectEngineCtx *, void *); | ||
int (*AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, | ||
const Signature *, const SigMatchCtx *); | ||
} SCPluginSigTableElmt; | ||
|
||
int DetectHelperKeywordRegister(const SCPluginSigTableElmt *kw); | ||
int DetectHelperBufferRegister(const char *name, AppProto alproto, bool toclient, bool toserver); | ||
|
||
typedef bool (*SimpleGetTxBuffer)(void *, uint8_t, const uint8_t **, uint32_t *); | ||
|
||
int DetectHelperKeywordSetup(DetectEngineCtx *de_ctx, AppProto alproto, uint16_t kw_id, int buf_id, | ||
Signature *s, void *ctx); | ||
InspectionBuffer *DetectHelperGetData(struct DetectEngineThreadCtx_ *det_ctx, | ||
const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, | ||
const int list_id, SimpleGetTxBuffer GetBuf); | ||
int DetectHelperBufferMpmRegister(const char *name, const char *desc, AppProto alproto, | ||
bool toclient, bool toserver, InspectionBufferGetDataPtr GetData); | ||
|
||
#endif /* __DETECT_ENGINE_HELPER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters