mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00

This is a larger internal change that moves the analyzer infrastructure to a more flexible model where the available analyzers don't need to be hardcoded at compile time anymore. While currently they actually still are, this will in the future enable external analyzer plugins. For now, it does already add the capability to dynamically enable/disable analyzers from script-land, replacing the old Analyzer::Available() methods. There are three major parts going into this: - A new plugin infrastructure in src/plugin. This is independent of analyzers and will eventually support plugins for other parts of Bro as well (think: readers and writers). The goal is that plugins can be alternatively compiled in statically or loadead dynamically at runtime from a shared library. While the latter isn't there yet, there'll be almost no code change for a plugin to make it dynamic later (hopefully :) - New analyzer infrastructure in src/analyzer. I've moved a number of analyzer-related classes here, including Analyzer and DPM; the latter now renamed to Analyzer::Manager. More will move here later. Currently, there's only one plugin here, which provides *all* existing analyzers. We can modularize this further in the future (or not). - A new script interface in base/framework/analyzer. I think that this will eventually replace the dpm framework, but for now that's still there as well, though some parts have moved over. I've also remove the dpd_config table; ports are now configured via the analyzer framework. For exmaple, for SSH: const ports = { 22/tcp } &redef; event bro_init() &priority=5 { ... Analyzer::register_for_ports(Analyzer::ANALYZER_SSH, ports); } As you can see, the old ANALYZER_SSH constants have more into an enum in the Analyzer namespace. This is all hardly tested right now, and not everything works yet. There's also a lot more cleanup to do (moving more classes around; removing no longer used functionality; documenting script and C++ interfaces; regression tests). But it seems to generally work with a small trace at least. The debug stream "dpm" shows more about the loaded/enabled analyzers. A new option -N lists loaded plugins and what they provide (including those compiled in statically; i.e., right now it outputs all the analyzers). This is all not cast-in-stone yet, for some things we need to see if they make sense this way. Feedback welcome.
131 lines
3.2 KiB
Text
131 lines
3.2 KiB
Text
##! Implements the core IRC analysis support. The logging model is to log
|
|
##! IRC commands along with the associated response and some additional
|
|
##! metadata about the connection if it's available.
|
|
|
|
module IRC;
|
|
|
|
export {
|
|
|
|
redef enum Log::ID += { LOG };
|
|
|
|
type Info: record {
|
|
## Timestamp when the command was seen.
|
|
ts: time &log;
|
|
## Unique ID for the connection.
|
|
uid: string &log;
|
|
## The connection's 4-tuple of endpoint addresses/ports.
|
|
id: conn_id &log;
|
|
## Nick name given for the connection.
|
|
nick: string &log &optional;
|
|
## User name given for the connection.
|
|
user: string &log &optional;
|
|
|
|
## Command given by the client.
|
|
command: string &log &optional;
|
|
## Value for the command given by the client.
|
|
value: string &log &optional;
|
|
## Any additional data for the command.
|
|
addl: string &log &optional;
|
|
};
|
|
|
|
## Event that can be handled to access the IRC record as it is sent on
|
|
## to the logging framework.
|
|
global irc_log: event(rec: Info);
|
|
}
|
|
|
|
redef record connection += {
|
|
## IRC session information.
|
|
irc: Info &optional;
|
|
};
|
|
|
|
# Some common IRC ports.
|
|
redef capture_filters += { ["irc-6666"] = "port 6666" };
|
|
redef capture_filters += { ["irc-6667"] = "port 6667" };
|
|
redef capture_filters += { ["irc-6668"] = "port 6668" };
|
|
redef capture_filters += { ["irc-6669"] = "port 6669" };
|
|
|
|
# DPD configuration.
|
|
const ports = { 6666/tcp, 6667/tcp, 6668/tcp, 6669/tcp };
|
|
redef likely_server_ports += { ports };
|
|
|
|
event bro_init() &priority=5
|
|
{
|
|
Log::create_stream(IRC::LOG, [$columns=Info, $ev=irc_log]);
|
|
Analyzer::register_for_ports(Analyzer::ANALYZER_IRC, ports);
|
|
}
|
|
|
|
function new_session(c: connection): Info
|
|
{
|
|
local info: Info;
|
|
info$ts = network_time();
|
|
info$uid = c$uid;
|
|
info$id = c$id;
|
|
return info;
|
|
}
|
|
|
|
function set_session(c: connection)
|
|
{
|
|
if ( ! c?$irc )
|
|
c$irc = new_session(c);
|
|
|
|
c$irc$ts=network_time();
|
|
}
|
|
|
|
event irc_nick_message(c: connection, is_orig: bool, who: string, newnick: string) &priority=5
|
|
{
|
|
set_session(c);
|
|
if ( is_orig )
|
|
{
|
|
c$irc$command = "NICK";
|
|
c$irc$value = newnick;
|
|
}
|
|
}
|
|
|
|
event irc_nick_message(c: connection, is_orig: bool, who: string, newnick: string) &priority=-5
|
|
{
|
|
if ( is_orig )
|
|
{
|
|
Log::write(IRC::LOG, c$irc);
|
|
c$irc$nick = newnick;
|
|
}
|
|
}
|
|
|
|
event irc_user_message(c: connection, is_orig: bool, user: string, host: string, server: string, real_name: string) &priority=5
|
|
{
|
|
set_session(c);
|
|
if ( is_orig )
|
|
{
|
|
c$irc$command = "USER";
|
|
c$irc$value = user;
|
|
c$irc$addl=fmt("%s %s %s", host, server, real_name);
|
|
}
|
|
}
|
|
|
|
event irc_user_message(c: connection, is_orig: bool, user: string, host: string, server: string, real_name: string) &priority=-5
|
|
{
|
|
if ( is_orig )
|
|
{
|
|
Log::write(IRC::LOG, c$irc);
|
|
c$irc$user = user;
|
|
}
|
|
}
|
|
|
|
event irc_join_message(c: connection, is_orig: bool, info_list: irc_join_list) &priority=5
|
|
{
|
|
set_session(c);
|
|
if ( is_orig )
|
|
c$irc$command = "JOIN";
|
|
}
|
|
|
|
event irc_join_message(c: connection, is_orig: bool, info_list: irc_join_list) &priority=-5
|
|
{
|
|
if ( is_orig )
|
|
{
|
|
for ( l in info_list )
|
|
{
|
|
c$irc$value = l$channel;
|
|
c$irc$addl = (l$password != "" ? fmt(" with channel key: '%s'", l$password) : "");
|
|
Log::write(IRC::LOG, c$irc);
|
|
}
|
|
}
|
|
}
|