Commit Graph

594 Commits (c06d8f246303d767d2b5e8c504f58de401e64c0a)

Author SHA1 Message Date
Philippe Antoine c06d8f2463 dcerpc: validate signature with dcerpc keywords
so that they do not use another protocol's keywords
6 years ago
Victor Julien a8e2399ea9 eve/metadata: create preformatted json string at start up
Avoid runtime overhead of assembling metadata json string by
pre-creating it at rule parsing time.
6 years ago
Victor Julien 6ab323d323 detect: hide RegisterTests behind ifdef UNITTESTS
Update all callers to more aggressively use UNITTESTS guards as well.
6 years ago
Jeff Lucovsky fb409664d2 detect: byte_math support 6 years ago
Antti Tönkyrä 57d0f4bb6f detect/flowbits: fix stack overflow in analyzer
Fix stack overflow in DetectFlowbitsAnalyze.

Use dynamically allocated array instead of stack and free
it after it is no longer needed.
6 years ago
Jeff Lucovsky a4132d8e0f detect/transform: Add transform "validate" function
This commit adds an (optional) entry for a validation function. The
validation function, if present, will be used during rule processing.

Its role is to determine if the arguments are compatible with the
transform. E.g., a content string of "this string has whitespace" is not
compatible with the `strip_whitespace` transform.
6 years ago
Philippe Antoine e5d4332ede signature: adds file flag for file_data keyword
So that SigValidate can check if a protocol not supporting
files was set after this keyword
6 years ago
Jeff Lucovsky 5d10db88bc detect/transform: Support transform options
This commit adds support for transform-specific options. During Setup,
transforms have the signature string available for options detection.
When a transform detects an option, it should convert the option into an
internal format and supply a pointer to this format as the last argument
to DetectSignatureAddTransform.

Transforms that support options must provide a function in their
Sigmatch table entry. When the transform is freed, a pointer to the
internal format of the option is passed to this function.
6 years ago
Victor Julien de6c9b9441 detect: clarify and slightly cleanup non-pf logic 6 years ago
Jeff Lucovsky d3a65fe156 detect: Provide `de_ctx` to free functions
This commit makes sure that the `DetectEngineCtx *` is available
to each detector's "free" function.
6 years ago
Jeff Lucovsky d1151f3f8e detect: Provide function to clear per-thread ctx
This commit provides an interface to free previously allocated
per-thread contextual information on the keyword lists.
6 years ago
Jason Ish 8a643c893c detect/parse: allow for OK signature parsing errors
The idea of an OK signature parsing error is an error that is
allowed to occur, but still lets test mode pass, unlike
silent errors which will still fail testing.

This is introduced to allow for app-layer event keywords to be
removed, but not have old rules fail out on this case. For example
the Rust DNS parser removes from DNS app-layer events that are
not used anymore.

To signal that an error is OK, -3 is returned. This also implies
silent.
7 years ago
Jeff Lucovsky be4c6b85de general: Convert _Bool to bool
This commit addresses task 3167 and changes usages of '_Bool` to `bool`.
The latter is included from `suricata-common.h`
7 years ago
Jeff Lucovsky 5e08e6bccf detect: update version comment 7 years ago
Jeff Lucovsky 1cddbc085b detect: Fix typos/spelling errors. 7 years ago
Victor Julien b89059bda7 detect: fix global declaration of sigmatch_table 7 years ago
Victor Julien 44d7f636f2 threading: remove post_pq argument from 'SlotFunc'
This was not in use anywhere.
7 years ago
Victor Julien 4d44ca7739 detect/parse: allow signature parsing to fail silently
A sigmatches 'Setup' function may indicate it intends to fail
silently after the first error. It will return -2 instead of -1
in this case.

This is tracked in the DetectEngineCtx object, so errors will
be shown again at rule reloads.
7 years ago
Victor Julien b5521b58bc detect/parse: add --strict-rule-keywords option
Add --strict-rule-keywords commandline option to enable strict rule
parsing.

It can be used without options or with a comma separated list:
--strict-rule-keywords
--strict-rule-keywords=all
--strict-rule-keywords=classtype,reference

Parsing implementations can use SigMatchStrictEnabled to check
if strict parsing is enabled for them and act accordingly.
7 years ago
Victor Julien 43b5234055 detect/priority: use global define for default prio 7 years ago
Victor Julien 323a747f39 classtype: increase id size
Switch from u8 to u16 to allow for more classtypes.

Rename Signature::class to Signature::class_id to make it clear
it is an id.
7 years ago
Victor Julien c471d81f04 detect/priority: change duplicate priority behavior
Introduce Signature init_flag to indicate priority has been set.
This will be needed in a follow-up classtype update.

Detect duplicate priority instances in a keyword, and use the
highest priority in the rule. Do issue a warning in this case.
7 years ago
Victor Julien 828d2572f8 detect: use BIT_U32 macros for INIT flags 7 years ago
Victor Julien 2a136c917f detect: move includes/declarations closer to use 7 years ago
Victor Julien bc866ff2a0 detect: fix inaccurate comments 7 years ago
Victor Julien 4dff903b35 detect: introduce pkt mpm engines
Instead of the hardcode L4 matching in MPM that was recently introduced,
add an API similar to the AppLayer MPM and inspect engines.

Share part of the registration code with the AppLayer.

Implement for the tcp.hdr and udp.hdr keywords.
7 years ago
Victor Julien 14896365ef detect: remove Threadvars argument from API calls
Remove it as it's (almost) never used. If it is really needed it can
be accessed through DetectEngineThreadCtx::tv as well.
7 years ago
Victor Julien 47ef8f5822 detect/mpm: add l4-header support
Prepare MPM part of the detection engine for a new type of per
packet matching, where the L4 header will be inspected.

Preparation for TCP header inspection keyword.
7 years ago
Victor Julien 0965afd661 detect: pkt inspect engines
Instead of hard coded calls to the inspection logic for
payload inspection and 'MATCH'-list inspection use a callback
approach. This will register a callback per 'sm_list' much like
how app-layer inspect engines are registered.

This will allow for adding more types later without adding
runtime overhead.

Implement the callback for the PMATCH and MATCH logic.
7 years ago
Victor Julien d623dc4ac0 detect/parse: add flag to indicate keyword is deprecated
Issue warning when it is still used.
7 years ago
Victor Julien d270a7603a detect/inspect: add flags to inspect buffer 7 years ago
Victor Julien 92f08d85aa detect/iponly: improve negation handling in parsing 7 years ago
Victor Julien ba1de99f10 detect/address: clean up 'any' logic 7 years ago
Victor Julien 477e46da78 detect/http-client-body: convert to inspect api v2 8 years ago
Victor Julien 33b81f7439 detect: add verbosity of --list-keywords
Add indicators of content modifier or sticky buffer, and also
allow registering an alternative to a keyword.
8 years ago
Victor Julien d3e953e5f2 detect: switch keyword flags u16 8 years ago
Victor Julien 0b3220a0df detect: improve inspect buffer handling
Fix and Optimize cleanup. For the simple single inspect buffer optimize
the cleanup by keeping track of the actually used buffers. This avoid
looping over unused buffers.

Fix the case of cleaning not being done after a tx if the next tx is
also inspected in the context of the same packet.

Fix cleanup of the multi-inspect buffers. Optimize in 2 ways. First
like with single keep track of which multi-inspect buffers have been
used. Second, keep a max of the buffers within a multi-inspect buffer.
Use this max to limit (nested) looping.
8 years ago
Victor Julien 16100e592d file: use u32 file id everywhere 8 years ago
Victor Julien 2ae8d1a208 cocci/detect: add flags check to SigTableElmt 8 years ago
Victor Julien 1f4cd75f05 detect: clean up sgh flags and add cocci check 8 years ago
Victor Julien 1df38c3b97 cocci: add more flag checks 8 years ago
Victor Julien 67c90954c0 detect: use BIT_* macros
Also add notes that when adding flags they should be added to the
analyzer as well.
8 years ago
Victor Julien 7fca17639d detect/prefilter: speed up setup
If the global detect.prefilter.default setting is not "auto", it is
wasteful to run each prefilter setup routine. This patch tracks which
of the engines have been explicitly enabled in the rules and only
runs those.
8 years ago
Victor Julien 085521b218 detect: include keyword types in detect.h 8 years ago
Victor Julien 35c5ae3458 detect: limit flush logic to sigs that need it
Limit the early 'flush' logic to sigs that actually need to match
on both stream and http bodies.
8 years ago
Victor Julien c0adff3770 detect: remove STATE_MATCH flag use at runtime
Instead, use it only at init time and use Signature::app_inspect
directly at runtime.
8 years ago
Victor Julien 83d2d7bb4b detect: minor formatting fixups 8 years ago
Victor Julien 12fec46d13 multi-tenant: introduce device selector
Add device to tenant mapping support:

  mappings:
  - device: ens5f0
    tenant-id: 1
  - device: ens5f1
    tenant-id: 23

Implemented by assigning the tenant id to the 'livedev', which means
it's only supported for capture methods that use the livedev API.

It's also currently not supported for IPS. In a case like 'eth0 -> eth1'
it's unclear which tenant should be used for the return traffic in a
flow, where the incoming device is 'eth1'.
8 years ago
Victor Julien a2b8ea57fc detect/dce: fix false positives in detection
If a signature didn't explicitly specified 'dcerpc' or 'smb' as the
app proto, false positives on other traffic could happen. This was
caused by the sig not having a app_proto set. This isn't set as the
rule is supposed to match against either ALPROTO_DCERPC or ALPROTO_SMB.

To avoid adding runtime costs for checking for both protocols, this
patch adds a new flag for DCERPC in the 'mask' logic. The flag is set
on the sig if dce_* keywords are present and set on the packet if the
flow's app proto is either ALPROTO_DCERPC or ALPROTO_SMB.

Bug #2559

Reported-by: Jason Taylor
8 years ago
Victor Julien df88c048ba detect: fix delayed detect
Last multi-detect changes broken delayed-detect by refusing to reload
a 'stub' detect engine. This patch distinguishes between a stub for
multi-tenancy and for delayed detect.
8 years ago