Commit graph

7932 commits

Author SHA1 Message Date
Valerio G
18499fd7d9 Extend DHCP protocol analyzer with new options.
Add the folowing option types:
- 55 Parameters Request List;
- 58 Renewal time;
- 59 Rebinding time;
- 61 Client Identifier;
- 82 Relay Agent Information.

Extend the following events with new parameters, specifically:
- dhcp_discover exports client identifier and parameters request list;
- dhcp_request exports client_identifier and parameters request list;
- dhcp_ack exports rebinding time, renewal time and list of suboptions value of
  dhcp relay agent information option;
- dhcp_inform exports parameters request list.

Add option type specific variables within the scope of DHCP module
(see src/analyzer/protocol/dhcp/types.bif).

Move protocol specific variables "dhcp_msg" and "dhcp_router_list" from scope Global to DHCP::
and adapt inet_net_var in src/NetVar.cc consequently.

Extend src/analyzer/protocols/dhcp/main.bro to handle the new events and to log
dhcp_ack, dhcp_request and dhcp_discover.

Modify scripts/policy/protocols/dhcp/known-devices-and-hostnames.bro to
include new events' variables.
2018-01-08 21:53:58 +01:00
Johanna Amann
8b28b73124 Add CVE ID for BIT-1856. 2018-01-02 09:12:09 +01:00
Andrew Woodford
f07fdc255f SSH protocol now assesses the packet length at an earlier stage within binpac. Stops SSH analyzer constantly raising binpac exceptions. Seems to be because a packet continues to go through binpac when empty and only calls the next packet when asked for more data and not on operations. 2017-12-21 16:34:26 +00:00
Jon Siwek
1c25df6f26 Merge remote-tracking branch 'origin/topic/seth/remove-dns-weird'
* origin/topic/seth/remove-dns-weird:
  Updated news.
  Remove some DNS weirds that caused volume and didn't help anyone.
2017-12-15 15:11:29 -06:00
Jon Siwek
4965a7e156 Fix typo in analyzer::Manager API docs 2017-12-13 14:24:54 -06:00
Seth Hall
f236dcdaa3 Updated news. 2017-12-13 15:09:52 -05:00
Seth Hall
ac955519b2 Remove some DNS weirds that caused volume and didn't help anyone.
These have been lingering for a while and they generally annoy
everyone because of the sheer volume.  They also don't really add
any useful information for debugging and they were generated differently
than most other weirds anyway (which was a little weird...).
2017-12-13 15:00:15 -05:00
Jon Siwek
d6d7f33f5c Clean up PortManager class, mark PortVal ctors deprecated.
Moved PortVal ctors back to public API, but deprecated, just in
case it helps give any external code a chance to adapt.
2017-12-12 11:35:55 -06:00
Jon Siwek
054c4a67c4 Add BRO_DEPRECATED macro. 2017-12-12 11:34:49 -06:00
Jon Siwek
1e4964de77 Preallocate all possible PortVals.
The performance benefit is small (maybe ~1% at most), however, it's a
trivial change without downsides.
2017-12-11 15:29:28 -06:00
Jon Siwek
895e7b06b1 Merge branch 'topic/jazoff/speedup-for'
* topic/jazoff/speedup-for:
  problem: for loops over empty tables are slow.

BIT-1878 #merged
2017-12-08 13:12:09 -06:00
Johanna Amann
03f98c7022 Fix recently introduced double free in OpenSSL code. 2017-12-07 14:47:56 -08:00
Justin Azoff
b730874ea1 problem: for loops over empty tables are slow.
This change doubles the performance of for loops over empty tables.

A bro binary that prints out this size shows for
testing/external/bro-testing/2009-M57-day11-18.trace, for loops are run
over tables of size:

11477 for size 0
8371 for size 1
1227 for size 3
239 for size 2
141 for size 6
57 for size 5
10 for size 4
5 for size 7
2 for size 13
2 for size 8
2 for size 11
1 for size 9

~53% of the for loops were across an empty table.  These loops come from
things like the for loop in the http script over c$http_state$pending

This change prevents the creation of an iteration cookie entirely if the
table is empty.

Using this test script:

    const scan_ports: table[port] of count = { };

    local x = 0;
    while ( x < 20000000 ) {
        for(p in scan_ports) {
        }
        ++x;
    }

$ time bro.orig -b ___bench.bro

real    0m10.732s
user    0m10.415s
sys     0m0.113s

$ time bro.nocookie -b ___bench.bro

real    0m4.694s
user    0m4.464s
sys     0m0.086s
2017-12-07 17:15:14 -05:00
Johanna Amann
6a93abea32 Adjust coding style & fix test failures.
I am still not 100% convinced that there is no memory leak hidden
somwehere...

This also makes everything compile with OpenSSL 1.0.2 for me.
2017-12-07 14:02:27 -08:00
Jeffrey Bencteux
bbe89a79a4 add smb1_transaction2_secondary_request event
parse and expose SMB_COM_TRANSACTION2_SECONDARY (0x33) message to
script level. See MS-CIFS section 2.2.4.47.1.
2017-12-07 10:01:25 +01:00
Jeffrey Bencteux
046c7bc481 add smb1_transaction_secondary_request event
expose SMB_COM_TRANSACTION_SECONDARY (0x26) message to script
language. See MS-CIFS section 2.2.4.34.1.
2017-12-07 10:01:20 +01:00
Jeffrey Bencteux
bd72710e3b add parameters and data to smb1_transaction_request/response messages
expose SMB_Data.Trans_Parameters and SMB_Data.Trans_Data fields of
SMB_COM_TRANSACTION (0x25) message type. See MS-CIFS section
2.2.4.33.1.

These fields are exposed to the script level as Bro strings. Note that
this commit also expose a new event smb1_transaction_response.
2017-12-07 10:01:13 +01:00
Jeffrey Bencteux
f2c3a9495d add SMB_Parameters.Words to smb1_transaction2_request event
expose the fields contained in SMB_Parameters.Words of the
SMB_COM_TRANSACTION2 (0x32) message to the script language. See
MS-CIFS section 2.2.46.1.
2017-12-07 10:00:55 +01:00
Hilko Bengen
ea4cf7dbe9 Adapt most of the X509 support to OpenSSL 1.1 2017-12-06 00:07:49 +01:00
Johanna Amann
bfe94641cf Fix another gcc7 warning.
Warning is:

/home/johanna/bro/master/src/Type.cc: In member function 'virtual bool IndexType::DoUnserialize(UnserialInfo*)':
/home/johanna/bro/master/src/Type.cc:548:60: warning: enum constant in boolean context [-Wint-in-bool-context]
  indices = (TypeList*) BroType::Unserialize(info, TYPE_LIST);
                                                            ^
/home/johanna/bro/master/src/Type.cc: In member function 'virtual bool FuncType::DoUnserialize(UnserialInfo*)':
/home/johanna/bro/master/src/Type.cc:868:61: warning: enum constant in boolean context [-Wint-in-bool-context]
  args = (RecordType*) BroType::Unserialize(info, TYPE_RECORD);
                                                             ^
/home/johanna/bro/master/src/Type.cc:872:62: warning: enum constant in boolean context [-Wint-in-bool-context]
  arg_types = (TypeList*) BroType::Unserialize(info, TYPE_LIST);

This one is a really nice catch in my opinion. GCC is completely correct
- the 2nd argument to Unserialize is a bool. This means that all these
calls always evaluate to Unserialize(info, true). Which is equivalent
with the default, so I just removed the type from the call.

This was probably caused by someone thinking of BroVal::Unserialize,
which needs the type as the 2nd argument.
2017-12-05 11:30:06 -08:00
Johanna Amann
7c03f4dec0 Fix compile warnings raised by gcc7.
/home/johanna/bro/master/src/Sessions.cc: In member function 'void NetSessions::DoNextPacket(double, const Packet*, const IP_Hdr*, const EncapsulationStack*)':
/home/johanna/bro/master/src/Sessions.cc:343:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if ( ip_hdr_len > len )
       ~~~~~~~~~~~^~~~~
/home/johanna/bro/master/src/Sessions.cc:349:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if ( ip_hdr_len > caplen )
       ~~~~~~~~~~~^~~~~~~~
/home/johanna/bro/master/src/Sessions.cc:399:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if ( ip_hdr_len > len )
         ~~~~~~~~~~~^~~~~

In file included from /usr/include/machine/endian.h:6:0,
                 from /usr/include/sys/types.h:44,
                 from /usr/include/unistd.h:37,
                 from /home/johanna/bro/master/src/Anon.cc:2:
/home/johanna/bro/master/src/Anon.cc: In member function 'virtual ipaddr32_t AnonymizeIPAddr_Seq::anonymize(ipaddr32_t)':
/home/johanna/bro/master/src/Anon.cc:85:18: warning: operation on '((AnonymizeIPAddr_Seq*)this)->AnonymizeIPAddr_Seq::seq' may be undefined [-Wsequence-point]
  return htonl(seq++);
                  ^
2017-12-05 10:27:23 -08:00
Jon Siwek
8827ece34a Updating submodule(s).
[nomail]
2017-12-05 11:19:57 -06:00
Jon Siwek
ecfacbe96e Fix documentation for ReassemblerStats. 2017-12-05 11:01:09 -06:00
Jon Siwek
9d2c41a4ff Merge remote-tracking branch 'origin/topic/johanna/socks-password'
* origin/topic/johanna/socks-password:
  Do not log SOCKS passwords by default.

BIT-1791 #merged
2017-12-02 09:53:56 -06:00
Johanna Amann
8ba5c03538 Do not log SOCKS passwords by default.
This introduces a new option, SOCKS::default_capture_password which can
be used to specify if Socks passwords are logged by default

Like fot FTP/HTTP, this option is set to false by default.

Addresses BIT-1791
2017-12-01 14:36:57 -08:00
Johanna Amann
94f55532f2 Make parsing of ServerKeyExchange work for D(TLS) < 1.2.
Now we only parse the SignatureAndHashalgorithm field in cases where it
is present. This change also takes care to respect SCTs, which do
include the SignatureAndHashalgorithm in their digitally-signed struct,
even when used in protocol versions that do not have the
SignatureAndHashalgorithm in the protocols digitally-signed struct.

I also added tests to make sure this does indeed work with TLS 1.1 - it
turns out that so far we did not have a single TLS 1.1 pcap.
2017-11-30 12:20:45 -08:00
Johanna Amann
fdf8717588 Merge remote-tracking branch 'origin/master' into topic/johanna/ssl_signature_details 2017-11-30 08:46:54 -08:00
Johanna Amann
1f6954ca3e Add missing ; in SSL binpac parser.
Binpac for some reason also works without it.

Found by Luke Valenta.
2017-11-30 08:42:55 -08: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
f8f343fd3a Add --ccache option to configure script (requires CMake 3.10+).
This just provides a convient way of indicating that ccache should
be used as compiler-wrapper during builds. e.g. when I want dev/debug
builds that (re)compile quickly, I do:

./configure --build-type=debug --generator=Ninja --ccache
2017-11-29 14:11:37 -06:00
Johanna Amann
88f98489a2 Add more details to ssl_server_signature.
This splits out the signature and the hash algorithm from the actual
signature.
2017-11-28 13:45:50 -08:00
Johanna Amann
577357d509 Small fixes and changes for the recent ssl-keyexchange-event merge.
This commit fixes a few small issues.

* server key exchange parameters are only parsed when a named curve is
  given.

* I removed the ssl-verbose.bro and moved the functionality into the
  testcase.

  The information that we get with these events is likely irrelevant to
  the majority of Bro users; I do not think that we have to ship a
  script that uses them by default. A script like this would be
  something to publish via the Bro package manager instead; this is the
  approach that we have taken with a number of the recent SSL addition.

* I marked the ssl_server_curve event as deprecated. More information is
  contained in the new ssl_ecdh_server_params event.

  This is an events that is probably seldomly (or never) directly used
  by anyone; I plan to completely remove it right after the 2.6 release.
2017-11-28 12:33:27 -08:00
Johanna Amann
917d0c881a Merge branch 'topic/lukev/tls-ext' of https://github.com/bro/bro
* 'topic/lukev/tls-ext' of https://github.com/bro/bro:
  add btest w/ baseline for ssl-verbose testing dhe, ecdhe, and rsa key exchange logging
  now passing btest
  update documentation, fix whitespace errors, add certificate extraction to ssl-verbose script
  add verbose SSL logging output that includes cryptographic values
2017-11-28 12:11:38 -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
Jon Siwek
787b1e6bf2 Merge branch 'topic/corelight/reporter-hook' of https://github.com/corelight/bro
* 'topic/corelight/reporter-hook' of https://github.com/corelight/bro:
  Add reporter hook.
2017-11-21 12:28:52 -06:00
Jon Siwek
deced3795c Fix a nb_dns.c compile error (older OSs) due to C90 vs C99. 2017-11-21 11:35:33 -06:00
Jon Siwek
82a51e0731 Merge branch 'topic/corelight/load-hook' of https://github.com/corelight/bro
* 'topic/corelight/load-hook' of https://github.com/corelight/bro:
  Fix and extend behavior of HookLoadFile

I refactored some parts of scan.l to avoid the ambiguity of some
branches returning 0 and some branches not returning anything.
2017-11-20 14:06:45 -06:00
Jon Siwek
26dc94c31d BIT-1827: fix error on initializing DNS w/ IPv6 nameserver.
This just skips over IPv6 nameserver addresses for now and uses the
first IPv4 one in the resolver config.  Should be possible to support
IPv6, but that may need more testing (e.g. need to make sure the code
will be portable to various platforms).
2017-11-20 11:36:04 -06:00
Jon Siwek
105cdb5aaf Add --build-type flag to configure wrapper. 2017-11-20 08:39:11 -06:00
Robin Sommer
7139e30bed Updating submodule(s).
[nomail]
2017-11-17 15:27:26 -08:00
Robin Sommer
b99f4d1331 Merge branch 'master' of git.bro.org:bro 2017-11-17 15:16:26 -08:00
Robin Sommer
395c26b8be Updating submodule(s).
[nomail]
2017-11-17 15:13:01 -08:00
Robin Sommer
44baf1b355 Merge remote-tracking branch 'origin/topic/dnthayer/ticket1863'
* origin/topic/dnthayer/ticket1863:
  Fix ASCII logging of very large values of type "double"
  Add more test cases to ascii-double.bro
2017-11-17 15:11:22 -08:00
Robin Sommer
25c6a777a1 Merge remote-tracking branch 'origin/topic/jazoff/contentline-limit'
Changed '>' to '>=' in new length check.

* origin/topic/jazoff/contentline-limit:
  add a max_line_length flag to ContentLine_Analyzer
2017-11-17 14:56:50 -08:00
Robin Sommer
c74dbbfe59 Merge remote-tracking branch 'origin/topic/johanna/header-fix'
* origin/topic/johanna/header-fix:
  Fix OOB read in Sessions.cc
2017-11-17 14:51:21 -08:00
Johanna Amann
b852437126 Add reporter hook.
The hook being added is:

bool HookReporter(const std::string& prefix, const EventHandlerPtr event,
                  const Connection* conn, const val_list* addl, bool location,
                  const Location* location1, const Location* location2,
                  bool time, const std::string& buffer) override;

This hook gives access to basically all information that is available in
the function in Reporter.cc that performs the logging. The hook is
called each time when anything passes through the reporter in the cases
in which an event usually would be called. This includes weirds. The
hook can return false to prevent the normal reporter events from being
raised.
2017-11-16 13:02:12 -08:00
Johanna Amann
91dcefe104 Fix and extend behavior of HookLoadFile
This commit fixes and extends the behavior of HookLoadFile. Before this
change, HookLoadFile appended ".bro" to each path that was @loaded, even
if the path specified directory names. Furthermore it only gave the path
of the file as it was specified in the Bro script without revealing the
final path of the file that it was going to load.

This patch changes this behavior - in addition to giving the unmodified
path given in the @load command, the hook now returns the resolved path
of the file or directory it is going to load (if found). The hook is
furthermore raises for @load-sigs and @load-plugin; a enum specifies the
kind of load that is happening.
2017-11-16 12:31:27 -08:00
Johanna Amann
bde4404b5e Update submodules
[nomail]
2017-11-10 21:33:17 +01:00
Luke Valenta
3af440ffcf add btest w/ baseline for ssl-verbose testing dhe, ecdhe, and rsa key exchange logging 2017-11-09 11:48:24 -05:00
Luke Valenta
65e65080a0 now passing btest 2017-11-08 11:33:39 -05:00