Commit graph

394 commits

Author SHA1 Message Date
Jon Siwek
06c6e1188a Merge remote-tracking branch 'origin/topic/vern/set-ops2'
* origin/topic/vern/set-ops2:
  documentation, test suite update
  implemented set relationals
  bug fix for set intersection
  set intersection implemented
  mirroring previous topic/vern/set-ops to get branch up to date, since I'm a n00b

Fixed a couple memory leaks and added a leak test
2018-08-02 10:43:41 -05:00
Damani Wade
3710ff936f Add Cisco FabricPath support 2018-07-27 16:00:54 -05:00
Jon Siwek
35827eeb31 Add rate-limiting sampling mechanism for weird events
The generation of weird events, by default, are now rate-limited
according to these tunable options:

  - Weird::sampling_whitelist
  - Weird::sampling_threshold
  - Weird::sampling_rate
  - Weird::sampling_duration

The new get_reporter_stats() BIF also allows one to query the
total number of weirds generated (pre-sampling) which the new
policy/misc/weird-stats.bro script uses periodically to populate
a weird_stats.log.

There's also new reporter BIFs to allow generating weirds from the
script-layer such that they go through the same, internal
rate-limiting/sampling mechanisms:

  - Reporter::conn_weird
  - Reporter::flow_weird
  - Reporter::net_weird

Some of the code was adapted from previous work by Johanna Amann.
2018-07-26 19:57:36 -05:00
Vern Paxson
88fd7510c6 reap the fruits of v += e 2018-07-26 12:51:36 -07:00
Robin Sommer
8ac17d99a1 Merge remote-tracking branch 'origin/topic/jsiwek/bit-1950'
BIT-1950 #merged

* origin/topic/jsiwek/bit-1950:
  BIT-1950: support PPPoE over QinQ
2018-07-24 15:05:48 +00:00
Johanna Amann
12add53131 Fix special-case-bug for vectors in UnaryExpr.
In some cases one can get the Type() of unaryexpr to be ANY. Vectors so
far did not deal gracefully with this and crashed because trying to
convert any to a vectortype.

This patch fixes this by just using the original vector-type in this
case.
2018-07-20 13:36:38 -07:00
Jon Siwek
463e540c9b Merge remote-tracking branch 'origin/topic/vern/case-insensitive-patterns'
* origin/topic/vern/case-insensitive-patterns:
  use PCRE syntax instead of the beautiful new (?i ...) syntax
  nitlet in NEWS entry
  test suite update for case-insensitive patterns
  document use of double quotes to escape case-insensitivity
  bug fix for recent memory leak patch
  documentation updates for case-insensitive patterns
  d'oh there's isalpha.  I looked earlier for isletter :-P
  fix for handling [:(lower|upper):] in case-insensitive patterns
  implemented /re/i for case-insensitive patterns
2018-07-16 16:04:38 -05:00
Jon Siwek
ad9abd4c9b BIT-1950: support PPPoE over QinQ 2018-07-06 08:04:02 -05:00
Jon Siwek
15d74ac081 BIT-1941: improve unit test stability
Mostly trying to standardize the way tests sleep for arbitrary amounts
of time to make it easier to tell at which particular point the
unit test actually may need the timeout interval increased (or else
debugged further).
2018-07-03 15:00:52 -05:00
Jon Siwek
a97567ef38 Add memory leak unit test for pattern operations 2018-06-26 18:00:51 -05:00
Jon Siwek
c11039cb73 Make old comm. system usages an error unless old_comm_usage_is_ok is set 2018-06-15 17:15:46 -05:00
Robin Sommer
fe7e1ee7f0 Merge topic/actor-system throug a squashed commit. 2018-05-18 22:39:23 +00:00
Pierre LALET
dfa392bd6c Add a test for 802.11 monitor mode 2018-05-15 17:59:26 +02:00
Daniel Thayer
27a7276009 Fix the ip-broken-header.bro test on macOS
There is no xzcat command on macOS by default.
2018-04-23 17:06:01 -05:00
Johanna Amann
0747080e5f Merge branch 'Reporter/MessageFix' of https://github.com/catenacyber/bro
* 'Reporter/MessageFix' of https://github.com/catenacyber/bro:
  Better reporter for Brostring with embedded NUL

I slightly changed the code for beautification purposes and added a
testcase. No functional changes.
2018-04-16 10:58:45 -07:00
Johanna Amann
db6f028003 Add config framework.
The configuration framework consists of three mostly distinct parts:

* option variables
* the config reader
* the script level framework

I will describe the three elements in the following.

Internally, this commit also performs a range of changes to the Input
manager; it marks a lot of functions as const and introduces a new
ValueToVal method (which could in theory replace the already existing
one - it is a bit more powerful).

This also changes SerialTypes to have a subtype for Values, just as
Fields already have it; I think it was mostly an oversight that this was
not introduced from the beginning. This should not necessitate any code
changes for people already using SerialTypes.

option variable
===============

The option keyword allows variables to be specified as run-tine options.
Such variables cannot be changed using normal assignments. Instead, they
can be changed using Option::set. It is possible to "subscribe" to
options and be notified when an option value changes.

Change handlers can also change values before they are applied; this
gives them the opportunity to reject changes. Priorities can be
specified if there are several handlers for one option.

Example script:

option testbool: bool = T;

function option_changed(ID: string, new_value: bool): bool
  {
  print fmt("Value of %s changed from %s to %s", ID, testbool, new_value);
  return new_value;
  }

event bro_init()
  {
  print "Old value", testbool;
  Option::set_change_handler("testbool", option_changed);
  Option::set("testbool", F);
  print "New value", testbool;
  }

config reader
=============

The config reader provides a way to read configuration files back into
Bro. Most importantly it automatically converts values to the correct
types. This is important because it is at least inconvenient (and
sometimes near impossible) to perform the necessary type conversions in
Bro scripts themselves. This is especially true for sets/vectors.

Configuration generally look like this:

[option name][tab/spaces][new variable value]

so, for example:

testaddr 2607:f8b0:4005:801::200e
testinterval 60
testtime 1507321987
test_set a	b	c	d	erdbeerschnitzel

The reader uses the option name to look up the type that variable has in
the Bro core and automatically converts the value to the correct type.

Example script use:

type Idx: record {
  option_name: string;
};

type Val: record {
  option_val: string;
};

global currconfig: table[string] of string = table();

event InputConfig::new_value(name: string, source: string, id: string, value: any)
  {
  print id, value;
  }

event bro_init()
  {
  Input::add_table([$reader=Input::READER_CONFIG, $source="../configfile", $name="configuration", $idx=Idx, $val=Val, $destination=currconfig, $want_record=F]);
  }

Script-level config framework
=============================

The script-level framework ties these two features together and makes
them a bit more convenient to use. Configuration files can simply be
specified by placing them into Config::config_files. The framework also
creates a config.log that shows all value changes that took place.

Usage example:

redef Config::config_files += {configfile};

export {
  option testbool : bool = F;
}

The file is now monitored for changes; when a change occurs the
respective option values are automatically updated and the value change
is written to config.log.
2017-11-29 13:46:59 -08:00
Jon Siwek
57b3e21de7 Merge remote-tracking branch 'origin/topic/robin/event-args'
* origin/topic/robin/event-args:
  Fix assignments to event arguments becoming visible to subsequent handlers.
2017-11-21 13:24:07 -06:00
Robin Sommer
5b88936070 Fix assignments to event arguments becoming visible to subsequent
handlers.

It's well known that changes to mutable event arguments, like tables,
become visible to all places where those values are used, including
subsequent handlers of the same event. However, there's a related case
that's more suprising: simply assigning *a new value* to an event
argument passes through, too. This commit fixes that behaviour. (We
even had a btest with a baseline reflecting the problen).
2017-10-27 13:28:48 -07:00
Johanna Amann
924ed053c7 Fix OOB read in Sessions.cc
IP packets that have a header length that is greater than the total
length of the packet cause a integer overflow, which cause range-checks
to fail, which causes OOB reads.

Furthermore Bro does not currently check the version field of IP packets
that are read from tunnels. I added this check - otherwhise Bro reports
bogus IP information in its error messages, just converting the data
from the place where the IP information is supposed to be to IPs.

This behavior brings us closer to what other software (e.g. Wireshark)
displays in these cases.
2017-10-19 10:29:29 -07:00
Daniel Thayer
fcbf54f697 Fix the test group name in some broker test files
Some broker leak tests were being ignored because the test group
name was incorrect.
2017-04-07 12:24:29 -05:00
Johanna Amann
7c7e12ab94 Merge remote-tracking branch 'origin/topic/seth/BIT-1480'
* origin/topic/seth/BIT-1480:
  Small change to avoid potentially over reading memory.
  Implement ERSPAN support.

BIT-1480 #merged
2017-02-15 15:32:47 -08:00
Seth Hall
59f0477d29 Implement ERSPAN support.
This is a small caveat to this implementation.  The ethernet
header that is carried over the tunnel is ignored.  If a user
tries to do MAC address logging, it will only show the MAC
addresses for the outer tunnel and the inner MAC addresses
will be stripped and not available anywhere.
2017-02-03 12:29:22 -08:00
Johanna Amann
7feaf4499f Fix layer 2 connection flipping.
If connection flipping occured in Sessions.cc code (invoked e.g. when
the original SYN is missing), layer 2 flipping was not performed. This
change switches to always use the connection flipping code in Conn.cc
which performs the switch correctly.
2017-01-30 15:13:56 -08:00
Daniel Thayer
de1c13e3a3 Fix test core.pcap.dumper to work on OpenBSD
The sdiff command on OpenBSD truncates the output at a different
position than sdiff on other platforms.  Simple fix is to use diff
instead of sdiff.
2016-12-01 16:35:54 -06:00
Johanna Amann
544317fc1e Test output change on FreeBSD 11.0 (changed one tab to space).
Let's just always filter the tab and make it a space on all systems -
with that the comparison should hopefully work everywhere.
2016-10-06 12:37:50 -07:00
Johanna Amann
5d8da0b182 Address coverity errors. 2016-08-16 11:16:50 -07:00
Robin Sommer
39734255be Change TCP analysis to process connections without the initial SYN as
non-partial connections.

Before, if we saw a responder-side SYN/ACK, but had not seen the
initial orginator-side SYN, Bro would treat the connection as partial,
meaning that most application-layer analyzers would refuse to inspect
the payload. That was unfortunate because all payload data was
actually there (and even passed to the analyzers). This change make
Bro consider these connections as complete, so that analyzers will
just normally process them.

The leads to couple more connections in the test-suite to now being
analyzed.

Addresses #1492. (I used an HTTP trace for debugging instead of the
HTTPS trace from the ticket, as the clear-text makes it easier to
track the data flow).
2016-07-11 17:18:32 -07:00
Johanna Amann
74e98565f4 Merge remote-tracking branch 'origin/topic/robin/history-rxmit'
* origin/topic/robin/history-rxmit:
  Flagging retransmissions in connection history.
  Removing ack_above_hole event.

BIT-977 #merged
2016-07-08 19:30:10 -07:00
Robin Sommer
0c080bca7a Extendign connection history field to flag when Bro flips a
connection's endpoints.

The character is '^'.

Addresses BIT-1629.
2016-07-08 14:56:52 -07:00
Robin Sommer
394b16e1f2 Flagging retransmissions in connection history.
This adds a t/T letter for the first TCP payload retransmission from
originator or responder, respectively.

Addresses BIT-977.
2016-07-06 15:01:16 -07:00
Robin Sommer
ca3f7eadbe Fix segfault when an existing enum identifier is added again with a
different value.

Addresses BIT-931.

Also switching the internal enum ID map to storing std::string for
easier memory management.
2016-07-05 17:54:10 -07:00
Robin Sommer
4035af4b12 Fixing test portability. 2016-06-15 09:05:36 -07:00
Robin Sommer
2335a62a07 Preventing the event processing from looping endlessly when an event
reraised itself during execution of its handlers.
2016-06-14 18:11:32 -07:00
Jan Grashoefer
50cf694aae Moved link-layer addresses into endpoints.
The link-layer addresses are now part of the connection endpoints
following the originator-responder-pattern. The addresses are printed
with leading zeros. Additionally link-layer addresses are also extracted
for 802.11 plus RadioTap.
2016-06-02 01:46:26 +02:00
Robin Sommer
57aef6d49f Add MAC addresses to connection record.
c$eth_src and c$eth_dst now contain the Ethernet address if available.
A new script protocols/conn/mac-logging.bro adds these to conn.log
when loaded.
2016-05-29 17:18:47 -07:00
Robin Sommer
3581ead0d9 Ignoring packets with negative timestamps.
These used to stall Bro. Addresses BIT-1562 and BIT-1443.
2016-05-23 13:22:22 -07:00
Daniel Thayer
d91dd8d9a8 Fix Bro and unit tests when broker is not enabled
When Bro was compiled with broker disabled, then some Bro scripts
were referencing functions and types that were not defined.  Fixed
by adding @ifdefs to several scripts.  Removed one @ifdef because
it was causing several unit tests to fail.

Also fixed the @TEST-REQUIRES check in tests that rely on broker so
that such tests are skipped when broker is disabled.
2016-05-10 06:24:35 -05:00
Daniel Thayer
f5361fb27c Sync the core/leaks/broker/data.bro test with broker/data.bro 2016-04-26 23:34:39 -05:00
Daniel Thayer
b1876bf744 Code cleanup for some broker tests
Simplified some function names, fixed some names of broker script wrappers,
reorder some broker function calls to avoid potential race conditions, and
don't have bro read a trace file when it will not be used.
2016-04-26 22:30:12 -05:00
Daniel Thayer
f46dfac63a Rename the BrokerStore namespace to Broker 2016-03-30 16:39:19 -05:00
Daniel Thayer
9f5c820c7b Rename the BrokerComm namespace to Broker 2016-03-30 14:31:25 -05:00
Johanna Amann
107737c9a0 Fix memory leaks in stats.cc and smb.cc
No test for smb leak because I don't have anything that triggers this.
2016-02-08 15:38:09 -08:00
Johanna Amann
8913b60fd1 Add IRC leak test. 2016-02-08 14:27:58 -08:00
Seth Hall
88f2a066ce Improved Radiotap support and a test.
Radiotap support should be fully functional now with Radiotap
packets that include IPv4 and IPv6.  Other radiotap packets are
silently ignored.  This includes a test which has 802.11 headers
both with and without QoS data.
2016-01-19 04:10:44 -05:00
Robin Sommer
a83d97937e Extending rexmit_inconsistency() event to receive an additional
parameter with the packet's TCP flags, if available.
2015-10-26 14:16:08 -07:00
Johanna Amann
708ede22c6 Refactor X509 generalizedtime support and test.
The generalizedtime support in for certificates now fits more
seamlessly to how the rest of the code was structured and does the
different processing for UTC and generalized times at the beginning,
when checking for them.

The test does not output the common name anymore, since the output
format might change accross openssl versions (inserted the serial
instead).

I also added a bit more error checking for the UTC time case.
2015-09-18 12:46:49 -07:00
Yun Zheng Hu
2327f5bba5 Fixed parsing of V_ASN1_GENERALIZEDTIME timestamps in x509 certificates 2015-09-10 10:50:35 +02:00
Johanna Amann
fd6f9e470f Add a number of out_of_bound checks to Packet.cc
Mostly this verifies that we actually have the full headers that we are
trying to read in a packet.

Addresses BIT-1463
2015-08-31 13:09:18 -07:00
Robin Sommer
36b5a4db08 Merge branch 'master' of https://github.com/knielander/bro
I reworked this a bit:

    - Moved the globals into a new Pcap::* namespace, and renamed them
      slightly.

    - Moved the definitions of the globals into pcap/const.bif.

    - Also moved the existing 'snaplen' into Pcap::* and removed
      SnapLen() from the PktSrc API (it's really a pcap thing).

    - Likewise moved the existing functions precompile_pcap_filter,
      install_pcap_filter, and pcap_error, into Pcap::*.

    - Did some more refactoring for the pcap code.

* 'master' of https://github.com/knielander/bro:
  Refactored patch (removed options, less ambiguous name)
  Allow Bro to run in fanout mode.
  Allow libpcap buffer size to be set manually.
  Allow Bro to run in fanout mode.
  Allowed libpcap buffer size to be set via configuration.
2015-08-30 22:09:32 -07:00
Robin Sommer
1b9ee38e69 Fix potential crash TCP headers were captured incompletely.
Test case provided by Jonathan Ganz.

BIT-1425 #close
2015-08-30 18:49:05 -07:00