forked from OISF/suricata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
139 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Vlan.id Keyword | ||
============== | ||
|
||
Suricata has a ``vlan.id`` keyword that can be used in signatures to identify | ||
and filter network packets based on Virtual Local Area Network IDs. | ||
|
||
|
||
Signature example:: | ||
|
||
alert ip any any -> any any (msg:"Vlan ID is equal to 300"; vlan.id:300; sid:1;) |
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
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,99 @@ | ||
/* Copyright (C) 2022 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. | ||
*/ | ||
|
||
#include "suricata-common.h" | ||
#include "rust.h" | ||
#include "detect-vlan-id.h" | ||
#include "detect-engine.h" | ||
#include "detect-engine-prefilter.h" | ||
#include "detect-engine-uint.h" | ||
#include "detect-parse.h" | ||
|
||
static int DetectVlanIdMatch( | ||
DetectEngineThreadCtx *det_ctx, Packet *p, const Signature *s, const SigMatchCtx *ctx) | ||
{ | ||
if (p->vlan_idx == 0) { | ||
return 0; | ||
} | ||
|
||
const DetectU16Data *du16 = (const DetectU16Data *)ctx; | ||
for (int i = 0; i < p->vlan_idx; i++) { | ||
if (DetectU16Match(p->vlan_id[i], du16)) | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static void DetectVlanIdFree(DetectEngineCtx *de_ctx, void *ptr) | ||
{ | ||
rs_detect_u16_free(ptr); | ||
} | ||
|
||
static int DetectVlanIdSetup(DetectEngineCtx *de_ctx, Signature *s, const char *rawstr) | ||
{ | ||
DetectU16Data *du16 = DetectU16Parse(rawstr); | ||
if (du16 == NULL) | ||
return -1; | ||
|
||
if (SigMatchAppendSMToList( | ||
de_ctx, s, DETECT_VLAN_ID, (SigMatchCtx *)du16, DETECT_SM_LIST_MATCH) == NULL) { | ||
DetectVlanIdFree(de_ctx, du16); | ||
return -1; | ||
} | ||
s->flags |= SIG_FLAG_REQUIRE_PACKET; | ||
|
||
return 0; | ||
} | ||
|
||
static void PrefilterPacketVlanIdMatch(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx) | ||
{ | ||
const PrefilterPacketHeaderCtx *ctx = pectx; | ||
if (!PrefilterPacketHeaderExtraMatch(ctx, p)) | ||
return; | ||
|
||
DetectU16Data du16; | ||
du16.mode = ctx->v1.u8[0]; | ||
du16.arg1 = ctx->v1.u16[1]; | ||
du16.arg2 = ctx->v1.u16[2]; | ||
if (DetectVlanIdMatch(det_ctx, p, NULL, (const SigMatchCtx *)&du16)) { | ||
PrefilterAddSids(&det_ctx->pmq, ctx->sigs_array, ctx->sigs_cnt); | ||
} | ||
} | ||
|
||
static int PrefilterSetupVlanId(DetectEngineCtx *de_ctx, SigGroupHead *sgh) | ||
{ | ||
return PrefilterSetupPacketHeader(de_ctx, sgh, DETECT_VLAN_ID, SIG_MASK_REQUIRE_FLOW, | ||
PrefilterPacketU16Set, PrefilterPacketU16Compare, PrefilterPacketVlanIdMatch); | ||
} | ||
|
||
static bool PrefilterVlanIdIsPrefilterable(const Signature *s) | ||
{ | ||
return PrefilterIsPrefilterableById(s, DETECT_VLAN_ID); | ||
} | ||
|
||
void DetectVlanIdRegister(void) | ||
{ | ||
sigmatch_table[DETECT_VLAN_ID].name = "vlan.id"; | ||
sigmatch_table[DETECT_VLAN_ID].desc = "match vlan id"; | ||
sigmatch_table[DETECT_VLAN_ID].url = "/rules/vlan-id-keyword.html"; | ||
sigmatch_table[DETECT_VLAN_ID].Match = DetectVlanIdMatch; | ||
sigmatch_table[DETECT_VLAN_ID].Setup = DetectVlanIdSetup; | ||
sigmatch_table[DETECT_VLAN_ID].Free = DetectVlanIdFree; | ||
sigmatch_table[DETECT_VLAN_ID].SupportsPrefilter = PrefilterVlanIdIsPrefilterable; | ||
sigmatch_table[DETECT_VLAN_ID].SetupPrefilter = PrefilterSetupVlanId; | ||
} |
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,23 @@ | ||
/* Copyright (C) 2022 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. | ||
*/ | ||
|
||
#ifndef SURICATA_DETECT_VLAN_ID_H | ||
#define SURICATA_DETECT_VLAN_ID_H | ||
|
||
void DetectVlanIdRegister(void); | ||
|
||
#endif /* SURICATA_DETECT_VLAN_ID_H */ |