38static void DetectAppLayerProtocolRegisterTests(
void);
56static int DetectAppLayerProtocolPacketMatch(
153#define MAX_ALPROTO_NAME 50
160 char *sep = strchr(arg,
',');
163 strlcpy(alproto_copy, arg, sep - arg + 1);
164 alproto_name = alproto_copy;
166 alproto_name = (
char *)arg;
168 if (strcmp(alproto_name,
"failed") == 0) {
170 }
else if (strcmp(alproto_name,
"unknown") == 0) {
173 "keyword can't use negation with protocol 'unknown'");
181 "keyword supplied with unknown protocol \"%s\"",
188 if (strcmp(sep + 1,
"final") == 0) {
190 }
else if (strcmp(sep + 1,
"original") == 0) {
192 }
else if (strcmp(sep + 1,
"either") == 0) {
194 }
else if (strcmp(sep + 1,
"to_server") == 0) {
196 }
else if (strcmp(sep + 1,
"to_client") == 0) {
198 }
else if (strcmp(sep + 1,
"direction") == 0) {
202 "keyword supplied with unknown mode \"%s\"",
242 "have the rule match on an app layer protocol set through "
243 "other keywords that match on this protocol, or have "
244 "already seen a non-negated app-layer-protocol.");
253 for ( ; tsm != NULL; tsm = tsm->
next) {
257 if (HasConflicts(data, them)) {
259 "positive app-layer-protocol match with negated "
260 "match or match for 'failed'.");
291 if (!PrefilterPacketHeaderExtraMatch(
ctx, p)) {
296 if (p->
flow == NULL) {
308 bool negated = (bool)
ctx->v1.u8[2];
309 switch (
ctx->v1.u8[3]) {
335 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
338 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
343 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
352 if (!AppProtoEquals(
ctx->v1.u16[0], alproto)) {
353 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
357 if (AppProtoEquals(
ctx->v1.u16[0], alproto)) {
358 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
384 PrefilterPacketAppProtoSet, PrefilterPacketAppProtoCompare,
385 PrefilterPacketAppProtoMatch);
388static bool PrefilterAppProtoIsPrefilterable(
const Signature *s)
419static int DetectAppLayerProtocolTest01(
void)
425 DetectAppLayerProtocolFree(NULL, data);
429static int DetectAppLayerProtocolTest02(
void)
435 DetectAppLayerProtocolFree(NULL, data);
439static int DetectAppLayerProtocolTest03(
void)
448 "(app-layer-protocol:http; sid:1;)");
463static int DetectAppLayerProtocolTest04(
void)
472 "(app-layer-protocol:!http; sid:1;)");
489static int DetectAppLayerProtocolTest05(
void)
498 "(app-layer-protocol:!http; app-layer-protocol:!smtp; sid:1;)");
520static int DetectAppLayerProtocolTest06(
void)
528 "(app-layer-protocol:smtp; sid:1;)");
534static int DetectAppLayerProtocolTest07(
void)
542 "(app-layer-protocol:!smtp; sid:1;)");
548static int DetectAppLayerProtocolTest08(
void)
556 "(app-layer-protocol:!smtp; app-layer-protocol:http; sid:1;)");
562static int DetectAppLayerProtocolTest09(
void)
570 "(app-layer-protocol:http; app-layer-protocol:!smtp; sid:1;)");
576static int DetectAppLayerProtocolTest10(
void)
584 "(app-layer-protocol:smtp; app-layer-protocol:!http; sid:1;)");
590static int DetectAppLayerProtocolTest11(
void)
596 DetectAppLayerProtocolFree(NULL, data);
600static int DetectAppLayerProtocolTest12(
void)
606 DetectAppLayerProtocolFree(NULL, data);
610static int DetectAppLayerProtocolTest13(
void)
619 "(app-layer-protocol:failed; sid:1;)");
634static int DetectAppLayerProtocolTest14(
void)
642 "(app-layer-protocol:http; flowbits:set,blah; sid:1;)");
652 "(app-layer-protocol:http; flow:to_client; sid:2;)");
663 "(app-layer-protocol:http; flow:to_client,established; sid:3;)");
682static void DetectAppLayerProtocolRegisterTests(
void)
685 DetectAppLayerProtocolTest01);
687 DetectAppLayerProtocolTest02);
689 DetectAppLayerProtocolTest03);
691 DetectAppLayerProtocolTest04);
693 DetectAppLayerProtocolTest05);
695 DetectAppLayerProtocolTest06);
697 DetectAppLayerProtocolTest07);
699 DetectAppLayerProtocolTest08);
701 DetectAppLayerProtocolTest09);
703 DetectAppLayerProtocolTest10);
705 DetectAppLayerProtocolTest11);
707 DetectAppLayerProtocolTest12);
709 DetectAppLayerProtocolTest13);
711 DetectAppLayerProtocolTest14);
AppProto AppLayerGetProtoByName(const char *alproto_name)
Given a protocol string, returns the corresponding internal protocol id.
#define PKT_PROTO_DETECT_TS_DONE
#define PKT_PROTO_DETECT_TC_DONE
struct DetectAppLayerProtocolData_ DetectAppLayerProtocolData
void DetectAppLayerProtocolRegister(void)
@ DETECT_ALPROTO_TOCLIENT
@ DETECT_ALPROTO_TOSERVER
@ DETECT_ALPROTO_DIRECTION
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
int PrefilterSetupPacketHeader(DetectEngineCtx *de_ctx, SigGroupHead *sgh, int sm_type, SignatureMask mask, void(*Set)(PrefilterPacketHeaderValue *v, void *), bool(*Compare)(PrefilterPacketHeaderValue v, void *), void(*Match)(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx))
@ DETECT_APP_LAYER_PROTOCOL
DetectEngineCtx * DetectEngineCtxInit(void)
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
SigTableElmt * sigmatch_table
#define SIG_MASK_REQUIRE_FLOW
#define SIGMATCH_SUPPORT_FIREWALL
#define SIGMATCH_QUOTES_OPTIONAL
#define SIG_FLAG_APPLAYER
#define SIGMATCH_HANDLE_NEGATION
#define FLOW_PKT_TOSERVER
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define PASS
Pass the test.
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
main detection engine ctx
AppProto alproto
application level protocol
Container for matching data for a signature group.
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
a single match condition for a signature
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
int(* SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh)
void(* Free)(DetectEngineCtx *, void *)
void(* RegisterTests)(void)
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
bool(* SupportsPrefilter)(const Signature *s)
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
SignatureInitData * init_data
size_t strlcpy(char *dst, const char *src, size_t siz)
#define SCLogError(...)
Macro used to log ERROR messages.