mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +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.
116 lines
3.5 KiB
Text
116 lines
3.5 KiB
Text
##! File extraction and introspection for DCC transfers over IRC.
|
|
##!
|
|
##! There is a major problem with this script in the cluster context because
|
|
##! we might see A send B a message that a DCC connection is to be expected,
|
|
##! but that connection will actually be between B and C which could be
|
|
##! analyzed on a different worker.
|
|
##!
|
|
|
|
# Example line from IRC server indicating that the DCC SEND is about to start:
|
|
# PRIVMSG my_nick :^ADCC SEND whateverfile.zip 3640061780 1026 41709^A
|
|
|
|
@load ./main
|
|
@load base/utils/files
|
|
|
|
module IRC;
|
|
|
|
export {
|
|
## Pattern of file mime types to extract from IRC DCC file transfers.
|
|
const extract_file_types = /NO_DEFAULT/ &redef;
|
|
|
|
## On-disk prefix for files to be extracted from IRC DCC file transfers.
|
|
const extraction_prefix = "irc-dcc-item" &redef;
|
|
|
|
redef record Info += {
|
|
## DCC filename requested.
|
|
dcc_file_name: string &log &optional;
|
|
## Size of the DCC transfer as indicated by the sender.
|
|
dcc_file_size: count &log &optional;
|
|
## Sniffed mime type of the file.
|
|
dcc_mime_type: string &log &optional;
|
|
|
|
## The file handle for the file to be extracted
|
|
extraction_file: file &log &optional;
|
|
|
|
## A boolean to indicate if the current file transfer should be extracted.
|
|
extract_file: bool &default=F;
|
|
|
|
## The count of the number of file that have been extracted during the session.
|
|
num_extracted_files: count &default=0;
|
|
};
|
|
}
|
|
|
|
global dcc_expected_transfers: table[addr, port] of Info = table();
|
|
|
|
event file_transferred(c: connection, prefix: string, descr: string,
|
|
mime_type: string) &priority=3
|
|
{
|
|
local id = c$id;
|
|
if ( [id$resp_h, id$resp_p] !in dcc_expected_transfers )
|
|
return;
|
|
|
|
local irc = dcc_expected_transfers[id$resp_h, id$resp_p];
|
|
|
|
irc$dcc_mime_type = split1(mime_type, /;/)[1];
|
|
|
|
if ( extract_file_types == irc$dcc_mime_type )
|
|
{
|
|
irc$extract_file = T;
|
|
}
|
|
|
|
if ( irc$extract_file )
|
|
{
|
|
local suffix = fmt("%d.dat", ++irc$num_extracted_files);
|
|
local fname = generate_extraction_filename(extraction_prefix, c, suffix);
|
|
irc$extraction_file = open(fname);
|
|
}
|
|
}
|
|
|
|
event file_transferred(c: connection, prefix: string, descr: string,
|
|
mime_type: string) &priority=-4
|
|
{
|
|
local id = c$id;
|
|
if ( [id$resp_h, id$resp_p] !in dcc_expected_transfers )
|
|
return;
|
|
|
|
local irc = dcc_expected_transfers[id$resp_h, id$resp_p];
|
|
|
|
local tmp = irc$command;
|
|
irc$command = "DCC";
|
|
Log::write(IRC::LOG, irc);
|
|
irc$command = tmp;
|
|
|
|
if ( irc?$extraction_file )
|
|
set_contents_file(id, CONTENTS_RESP, irc$extraction_file);
|
|
|
|
# Delete these values in case another DCC transfer
|
|
# happens during the IRC session.
|
|
delete irc$extract_file;
|
|
delete irc$extraction_file;
|
|
delete irc$dcc_file_name;
|
|
delete irc$dcc_file_size;
|
|
delete irc$dcc_mime_type;
|
|
delete dcc_expected_transfers[id$resp_h, id$resp_p];
|
|
}
|
|
|
|
event irc_dcc_message(c: connection, is_orig: bool,
|
|
prefix: string, target: string,
|
|
dcc_type: string, argument: string,
|
|
address: addr, dest_port: count, size: count) &priority=5
|
|
{
|
|
set_session(c);
|
|
if ( dcc_type != "SEND" )
|
|
return;
|
|
c$irc$dcc_file_name = argument;
|
|
c$irc$dcc_file_size = size;
|
|
local p = count_to_port(dest_port, tcp);
|
|
Analyzer::expect_connection(to_addr("0.0.0.0"), address, p, Analyzer::ANALYZER_FILE, 5 min);
|
|
dcc_expected_transfers[address, p] = c$irc;
|
|
}
|
|
|
|
event expected_connection_seen(c: connection, a: count) &priority=10
|
|
{
|
|
local id = c$id;
|
|
if ( [id$resp_h, id$resp_p] in dcc_expected_transfers )
|
|
add c$service["irc-dcc-data"];
|
|
}
|