Skip to content

Commit

Permalink
detect: allow rule which need both directions to match
Browse files Browse the repository at this point in the history
Ticket: 5665

This is done with `alert ip any any -- any any`
The -- operator means that we will need both directions
  • Loading branch information
catenacyber committed Jan 18, 2024
1 parent 6896a93 commit 33b0fc1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/detect-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,8 @@ static int SigParseBasics(DetectEngineCtx *de_ctx, Signature *s, const char *sig

if (strcmp(parser->direction, "<>") == 0) {
s->init_data->init_flags |= SIG_FLAG_INIT_BIDIREC;
} else if (strcmp(parser->direction, "--") == 0) {
s->init_data->init_flags |= SIG_FLAG_INIT_BOTHDIR;
} else if (strcmp(parser->direction, "->") != 0) {
SCLogError("\"%s\" is not a valid direction modifier, "
"\"->\" and \"<>\" are supported.",
Expand Down Expand Up @@ -2012,7 +2014,7 @@ static int SigValidate(DetectEngineCtx *de_ctx, Signature *s)
SCLogDebug("%s/%d: %d/%d", DetectEngineBufferTypeGetNameById(de_ctx, x), x, bufdir[x].ts,
bufdir[x].tc);
}
if (ts_excl && tc_excl) {
if (ts_excl && tc_excl && (s->init_data->init_flags & SIG_FLAG_INIT_BOTHDIR) == 0) {
SCLogError("rule %u mixes keywords with conflicting directions", s->id);
SCReturnInt(0);
} else if (ts_excl) {
Expand Down
1 change: 1 addition & 0 deletions src/detect.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ typedef struct DetectPort_ {
#define SIG_FLAG_INIT_BIDIREC BIT_U32(3) /**< signature has bidirectional operator */
#define SIG_FLAG_INIT_FIRST_IPPROTO_SEEN \
BIT_U32(4) /** < signature has seen the first ip_proto keyword */
#define SIG_FLAG_INIT_BOTHDIR BIT_U32(5) /**< signature needs both directions to match */
#define SIG_FLAG_INIT_STATE_MATCH BIT_U32(6) /**< signature has matches that require stateful inspection */
#define SIG_FLAG_INIT_NEED_FLUSH BIT_U32(7)
#define SIG_FLAG_INIT_PRIO_EXPLICIT \
Expand Down

0 comments on commit 33b0fc1

Please sign in to comment.