Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[preview] detect grouping v174 #1811

Closed
wants to merge 89 commits into from
Closed

Conversation

inliniac
Copy link
Contributor

Introduce 'ac-ks' or the Kenneth Steele AC implementation. It's
actually 'ac-tile' written by Ken for the Tilera platform. This
patch adds support for it on other architectures as well.

Enable ac-tile for other archs as 'ac-ks'.

Fix a bunch of OOB reads in the loops that triggered ASAN.
Use sgh-mpm-context single is it is set to 'auto' when ac-ks is used.
Remove: ac-gfbs, wumanber, b2g, b3g.
Add funcs to see if a rule needs a SYN flag in the packet.
Each SGH has a unique ipproto and direction.
Replace tree based approach for rule grouping with a per port (tcp/udp)
and per protocol approach.

Grouping now looks like:

               +----+
               |icmp+--->
               +----+
               |gre +--->
               +----+
               |esp +--->
               +----+
          other|... |
        +----->-----+
        |      |N   +--->
        |      +----+
        |
        | tcp  +----+   +----+
        +----->+ 80 +-->+ 139+-->
        |      +----+   +----+
        |
        | udp  +----+   +----+
    +---+----->+ 53 +-->+ 135+-->
    |          +----+   +----+
    |toserver
+--->
    |toclient
    |
    +--->

So the first 'split' in the rules is the direction: toserver or toclient.
Rules that don't have a direction, are in both branches.

Then the split is between tcp/udp and the other protocols. For tcp and
udp port lists are used. For the other protocols, grouping is simply per
protocol.

The ports used are the destination ports for toserver sigs and source
ports for toclient sigs.
Allow multi-proto, multi-direction sgh's.
Update port grouping logic. Previously it would create one consistent
list w/o overlap. It largely still does this, except for the 'catch
all' port group at the end of the list. This port group contains all
the sigs that didn't fit into the other groups.
Per rule group tracking of checks, use of lists, mpm matches,
post filter counts.

Logs SGH id so it can be compared with the rule_group.json output.

TODO json output
Dump a json record containing all sigs that need to be inspected after
prefilter. Part of profiling. Only dump if threshold is met, which is
currently set by:

 --set detect.profile-match-logging-threshold=200

TODO: threshold setting, yaml
TODO: log also IP tuple, to make it more useful in case of online mode
For all mpm wrapper functions, check minlen vs the input buffer to see
if we can bypass the mpm search.

Next to this, make all the function inline. Also constify the input and
do other minor cleanups.
SGH's for tcp and udp are now always only per proto and per direction.
This means we can simply reuse the packet and stream mpm pointers.

The SGH's for the other protocols already used a directionless catch
all mpm pointer.
Create a hash table of unique DetectPort objects before trying to
create a unique list of these objects. This safes a lot of cycles
in the creation of the list.
Allow setting of shared or unique setting per app buffer type:
e.g. detect.mpm.http_uri.shared=true
Instead of detect-engine which used a list for no good reason, use a
simple map now.

detect:
  profile: medium
  custom-values:
    toclient-groups: 3
    toserver-groups: 25
  sgh-mpm-context: auto
  inspection-recursion-limit: 3000
  # If set to yes, the loading of signatures will be made after the capture
  # is started. This will limit the downtime in IPS mode.
  #delayed-detect: yes
@pevma
Copy link
Member

pevma commented Jan 29, 2016

I have the following set up -


 detect-engine:
   - profile: custom
   - custom-values:
     toclient-groups: 1000
     toserver-groups: 1000


but in suricata.log I have those:

> [26082] 29/1/2016 -- 03:12:47 - (detect.c:3801) <Info> (SigAddressPrepareStage1) -- building signature grouping structure, stage 1: preprocessing rules... complete
> [26082] 29/1/2016 -- 03:12:47 - (detect.c:3673) <Info> (RulesGroupByPorts) -- TCP toserver: 41 port groups, 41 unique SGH's, 0 copies
> [26082] 29/1/2016 -- 03:12:47 - (detect.c:3673) <Info> (RulesGroupByPorts) -- TCP toclient: 21 port groups, 16 unique SGH's, 5 copies
> [26082] 29/1/2016 -- 03:12:47 - (detect.c:3673) <Info> (RulesGroupByPorts) -- UDP toserver: 41 port groups, 26 unique SGH's, 15 copies
> [26082] 29/1/2016 -- 03:12:47 - (detect.c:3673) <Info> (RulesGroupByPorts) -- UDP toclient: 21 port groups, 16 unique SGH's, 5 copies
> [26082] 29/1/2016 -- 03:12:47 - (detect.c:3421) <Info> (RulesGroupByProto) -- OTHER toserver: 254 proto groups, 3 unique SGH's, 251 copies
> [26082] 29/1/2016 -- 03:12:47 - (detect.c:3457) <Info> (RulesGroupByProto) -- OTHER toclient: 254 proto groups, 0 unique SGH's, 254 copies
> [26082] 29/1/2016 -- 03:12:47 - (detect.c:4188) <Info> (SigAddressPrepareStage4) -- Unique rule groups: 102
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:822) <Info> (MpmStoreReportStats) -- Builtin MPM "toserver TCP packet": 32
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:822) <Info> (MpmStoreReportStats) -- Builtin MPM "toclient TCP packet": 14
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:822) <Info> (MpmStoreReportStats) -- Builtin MPM "toserver TCP stream": 33
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:822) <Info> (MpmStoreReportStats) -- Builtin MPM "toclient TCP stream": 15
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:822) <Info> (MpmStoreReportStats) -- Builtin MPM "toserver UDP packet": 25
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:822) <Info> (MpmStoreReportStats) -- Builtin MPM "toclient UDP packet": 16
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:822) <Info> (MpmStoreReportStats) -- Builtin MPM "other IP packet": 3
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:829) <Info> (MpmStoreReportStats) -- AppLayer MPM "toserver http_uri": 14
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:829) <Info> (MpmStoreReportStats) -- AppLayer MPM "toserver http_raw_uri": 1
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:829) <Info> (MpmStoreReportStats) -- AppLayer MPM "toserver http_header": 11
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:829) <Info> (MpmStoreReportStats) -- AppLayer MPM "toclient http_header": 3
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:829) <Info> (MpmStoreReportStats) -- AppLayer MPM "toserver http_raw_header": 1
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:829) <Info> (MpmStoreReportStats) -- AppLayer MPM "toserver http_method": 2
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:829) <Info> (MpmStoreReportStats) -- AppLayer MPM "toclient file_data": 2
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:829) <Info> (MpmStoreReportStats) -- AppLayer MPM "toserver http_client_body": 4
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:829) <Info> (MpmStoreReportStats) -- AppLayer MPM "toserver http_cookie": 2
> [26082] 29/1/2016 -- 03:12:47 - (detect-engine-mpm.c:829) <Info> (MpmStoreReportStats) -- AppLayer MPM "toclient http_cookie": 3


Custom mode seems is not taking effect

@pevma
Copy link
Member

pevma commented Feb 10, 2016

This works as expected.
I have readjusted the config - as per the commit message here -
51bbde3

to

 detect:
   profile: custom
   custom-values:
     toclient-groups: 1000
     toserver-groups: 1000

resulting in:

[25314] 10/2/2016 -- 02:09:33 - (detect.c:3801) (SigAddressPrepareStage1) -- building signature grouping structure, stage 1: preprocessing rules... complete
[25314] 10/2/2016 -- 02:09:33 - (detect.c:3673) (RulesGroupByPorts) -- TCP toserver: 529 port groups, 303 unique SGH's, 226 copies
[25314] 10/2/2016 -- 02:09:33 - (detect.c:3673) (RulesGroupByPorts) -- TCP toclient: 112 port groups, 57 unique SGH's, 55 copies
[25314] 10/2/2016 -- 02:09:33 - (detect.c:3673) (RulesGroupByPorts) -- UDP toserver: 106 port groups, 58 unique SGH's, 48 copies
[25314] 10/2/2016 -- 02:09:33 - (detect.c:3673) (RulesGroupByPorts) -- UDP toclient: 33 port groups, 19 unique SGH's, 14 copies
[25314] 10/2/2016 -- 02:09:33 - (detect.c:3421) (RulesGroupByProto) -- OTHER toserver: 254 proto groups, 3 unique SGH's, 251 copies
[25314] 10/2/2016 -- 02:09:33 - (detect.c:3457) (RulesGroupByProto) -- OTHER toclient: 254 proto groups, 0 unique SGH's, 254 copies
[25314] 10/2/2016 -- 02:10:04 - (detect.c:4188) (SigAddressPrepareStage4) -- Unique rule groups: 440
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:822) (MpmStoreReportStats) -- Builtin MPM "toserver TCP packet": 204
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:822) (MpmStoreReportStats) -- Builtin MPM "toclient TCP packet": 38
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:822) (MpmStoreReportStats) -- Builtin MPM "toserver TCP stream": 200
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:822) (MpmStoreReportStats) -- Builtin MPM "toclient TCP stream": 45
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:822) (MpmStoreReportStats) -- Builtin MPM "toserver UDP packet": 57
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:822) (MpmStoreReportStats) -- Builtin MPM "toclient UDP packet": 19
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:822) (MpmStoreReportStats) -- Builtin MPM "other IP packet": 3
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:829) (MpmStoreReportStats) -- AppLayer MPM "toserver http_uri": 38
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:829) (MpmStoreReportStats) -- AppLayer MPM "toserver http_raw_uri": 1
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:829) (MpmStoreReportStats) -- AppLayer MPM "toserver http_header": 15
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:829) (MpmStoreReportStats) -- AppLayer MPM "toclient http_header": 3
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:829) (MpmStoreReportStats) -- AppLayer MPM "toserver http_raw_header": 1
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:829) (MpmStoreReportStats) -- AppLayer MPM "toserver http_method": 2
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:829) (MpmStoreReportStats) -- AppLayer MPM "toclient file_data": 2
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:829) (MpmStoreReportStats) -- AppLayer MPM "toserver http_client_body": 8
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:829) (MpmStoreReportStats) -- AppLayer MPM "toserver http_cookie": 2
[25314] 10/2/2016 -- 02:10:04 - (detect-engine-mpm.c:829) (MpmStoreReportStats) -- AppLayer MPM "toclient http_cookie": 3

Sorry for the confusion.

@inliniac
Copy link
Contributor Author

Replaced by #1852

@inliniac inliniac closed this Feb 15, 2016
@inliniac inliniac deleted the dev-detect-grouping-v174 branch March 25, 2016 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants