mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00

- policy/ renamed to scripts/ - By default BROPATH now contains: - scripts/ - scripts/policy - scripts/site - *Nearly* all tests pass. - All of scripts/base/ is loaded by main.cc - Can be disabled by setting $BRO_NO_BASE_SCRIPTS - Scripts in scripts/base/ don't use relative path loading to ease use of BRO_NO_BASE_SCRIPTS (to copy and paste that script). - The scripts in scripts/base/protocols/ only (or soon will only) do logging and state building. - The scripts in scripts/base/frameworks/ add functionality without causing any additional overhead. - All "detection" activity happens through scripts in scripts/policy/. - Communications framework modified temporarily to need an environment variable to actually enable (ENABLE_COMMUNICATION=1) - This is so the communications framework can be loaded as part of the base without causing trouble when it's not needed. - This will be removed once a resolution to ticket #540 is reached.
124 lines
2.8 KiB
Text
124 lines
2.8 KiB
Text
##! This is the script that implements the core IRC analysis support. It only
|
|
##! logs a very limited subset of the IRC protocol by default. The points
|
|
##! that it logs at are NICK commands, USER commands, and JOIN commands. It
|
|
##! log various bits of meta data as indicated in the :bro:type:`Info` record
|
|
##! along with the command at the command arguments.
|
|
|
|
module IRC;
|
|
|
|
export {
|
|
redef enum Log::ID += { IRC };
|
|
|
|
type Tag: enum {
|
|
EMPTY
|
|
};
|
|
|
|
type Info: record {
|
|
ts: time &log;
|
|
uid: string &log;
|
|
id: conn_id &log;
|
|
nick: string &log &optional;
|
|
user: string &log &optional;
|
|
channels: set[string] &log &optional;
|
|
|
|
command: string &log &optional;
|
|
value: string &log &optional;
|
|
addl: string &log &optional;
|
|
tags: set[Tag] &log;
|
|
};
|
|
|
|
global irc_log: event(rec: Info);
|
|
}
|
|
|
|
redef record connection += {
|
|
irc: Info &optional;
|
|
};
|
|
|
|
# Some common IRC ports.
|
|
redef capture_filters += { ["irc-6666"] = "port 6666" };
|
|
redef capture_filters += { ["irc-6667"] = "port 6667" };
|
|
|
|
# DPD configuration.
|
|
global irc_ports = { 6666/tcp, 6667/tcp } &redef;
|
|
redef dpd_config += { [ANALYZER_IRC] = [$ports = irc_ports] };
|
|
|
|
event bro_init() &priority=5
|
|
{
|
|
Log::create_stream(IRC, [$columns=Info, $ev=irc_log]);
|
|
}
|
|
|
|
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, 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, 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, c$irc);
|
|
}
|
|
}
|
|
}
|