Skip to content

Commit

Permalink
detect: explicitly forbid impossible cases fot bidir rules
Browse files Browse the repository at this point in the history
Only allows bidir rules when needed.
When there is only one direction, just write a single dir rule.

Do not allow flow keyword to set a direction.

Do not allow keywords ambiguous about direction.
  • Loading branch information
catenacyber committed Jan 18, 2024
1 parent 33b0fc1 commit e83e49b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/detect-flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,16 @@ int DetectFlowSetup (DetectEngineCtx *de_ctx, Signature *s, const char *flowstr)
bool appendsm = true;
/* set the signature direction flags */
if (fd->flags & DETECT_FLOW_FLAG_TOSERVER) {
if (s->init_data->init_flags & SIG_FLAG_INIT_BOTHDIR) {
SCLogError("rule %u means to use both directions, cannot specify a flow direction", s->id);
return -1;
}
s->flags |= SIG_FLAG_TOSERVER;
} else if (fd->flags & DETECT_FLOW_FLAG_TOCLIENT) {
if (s->init_data->init_flags & SIG_FLAG_INIT_BOTHDIR) {
SCLogError("rule %u means to use both directions, cannot specify a flow direction", s->id);
return -1;
}
s->flags |= SIG_FLAG_TOCLIENT;
} else {
s->flags |= SIG_FLAG_TOSERVER;
Expand Down
10 changes: 10 additions & 0 deletions src/detect-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,16 @@ static int SigValidate(DetectEngineCtx *de_ctx, Signature *s)
} else if (dir_amb) {
SCLogDebug("%u: rule direction cannot be deduced from keywords", s->id);
}
if (s->init_data->init_flags & SIG_FLAG_INIT_BOTHDIR) {
if (!ts_excl || !tc_excl) {
SCLogError("rule %u should use both directions, but does not", s->id);
SCReturnInt(0);
}
if (dir_amb) {
SCLogError("rule %u means to use both directions, cannot have keywords ambiguous about directions", s->id);
SCReturnInt(0);
}
}

if ((s->flags & SIG_FLAG_REQUIRE_PACKET) &&
(s->flags & SIG_FLAG_REQUIRE_STREAM)) {
Expand Down

0 comments on commit e83e49b

Please sign in to comment.