help regarding sending scripts

Hi,

I have a question about sending scripts from one Bro to a second one, and having the second one install the script at run-time, and I was wondering how it would be done. Any help appreciated! Details below.

I am running Bro at the host which needs to receive new policy scripts on the fly from a remote Bro. I was wondering how exactly to use the serialization framework to achieve this. Ideally, I would like to do it at the script-level for simplicity reasons. A script at the host Bro would handle the reception and installation of policy files. It would simply download the file from the remote Bro, and then call a function called “load_policy_file()” to install the script into the running Bro. I could not find any such function to do this in the online documentation. (equivalent of a run-time “@load”). Maybe, I missed something?

If such support is not avail, I was thinking of writing a “load_policy_file” function for Bro that scripts could use. I was also wondering whether I could use the “trigger” mechanism discussed in the "Policy-controlled event management … " paper, but the serialization framework seems heavy-weight for this, since I am only looking to install scripts at run-time, not to make fine-grained changes.

Thanks in advance,
Jayanth

(Late reply, sorry.)

I have a question about sending scripts from one Bro to a second one, and
having the second one install the script at run-time, and I was wondering
how it would be done. Any help appreciated! Details below.

This requires a longer answer ...

We don't have any prepackaged functionality at the moment to simply
do a "send everything and install".

What we have are two things:

(a) a built-in function send_id() which will send a particular
    script-level ID to the remote end, which will install it. That
    includes variables but also event handlers, script functions,
    etc. By sending all global IDs successively, one will eventually
    have sent the whole configuration. (However, that would be best
    done in C++ code by writing a new built-in function).
    
(b) If it doesn't need to be network communication, there's the
    command-line option "--dump-config" that puts the whole
    configuration into a binary file, which can then be picked up by
    another instance dynamically (by copying the file into the
    .state directory of the target Bro). Internally, dump-config
    essentially does just what I sketched above in (a): iterating
    through all IDs and serializing them.

So much for the theory. Now the practical part: I think this whole
set of functionality hasn't been used by anybody in a long time.
Because of Bro's internal structure, replacing policy scripts at
run-time is actually pretty tricky and I wouldn't want to bet much
money that when you try --dump-config, it will "just work". It did
seem to work well with tests done while implementing all this stuff,
yet I think it has never been exercised very much and the problems
are subtle here.

So, depending on what exactly you need, I'd suggest something
different, which is what the Bro cluster is doing:

(1) many policy changes are limited to fine-tuning, e.g., changing
    the value of some configuration paramemter, like extending a
    regexp to match more activity, or changing some detection
    threshold. Sending just values of script variables works
    actually pretty well and the Bro cluster limits online updates
    to such cases: all variables which are declared as &redef can be
    updated dynamically from remote. This is implemented by the
    script aux/cluster/policy/send-config.bro in my branch.

(2) another typical policy change is enabling/disabling a certain
    kind of analysis (such as now loading the HTTP analyzer, or
    disabling scan detection). My branch has some code to enable
    this from remote by grouping related events into "event groups"
    and then allowing to enable/disable event groups remotely. So
    this can also be done during run-time.

(3) finally, for everyting else (like adding new script code, or
    changing an existing handler) Bro needs to be reinstarted. The
    impact of that is mitigated by using persistent state so
    that at least the most important state information is kept
    across restarts.

Any questions? :slight_smile:

Robin

Thanks so much for the long and detailed reply! I am not quite sure which of the many options you suggested I would go for, but I will keep the list posted on what I end up doing. I guess I will play with all your options a little bit, and figure out what works for me.

Thanks,
Jayanth