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

A user reported being confused about the fuid association of subsequent FTP commands when a data transfer has completed. It seems reasonable to unset fuid upon logging a FTP command which had a fuid. The current behavior results in the PORT or PASV commands after a RETR or STOR to have the fuid of the prior file transfer. Similarly, any CWD or DEL commands following a file transfer will unnecessarily be logged with the fuid of the prior file transfer. This tickles the baselines for the private testing PCAP a lot, primarily because there data connections in that pcap are never established properly. E.g, the fuids FzDzid1Dxm9srVKHXf and FEfYX73q5C6GEQZXX9 have been re-used for multiple commands. This may look like we're losing information, but the fuids vanishing in the normal btests belong to a LIST command that isn't logged by default into ftp.log. If it was, the fuid would be attached to it.
70 lines
1.4 KiB
Text
70 lines
1.4 KiB
Text
@load ./info
|
|
@load ./main
|
|
@load ./utils
|
|
@load base/utils/conn-ids
|
|
@load base/frameworks/files
|
|
|
|
module FTP;
|
|
|
|
export {
|
|
## Default file handle provider for FTP.
|
|
global get_file_handle: function(c: connection, is_orig: bool): string;
|
|
|
|
## Describe the file being transferred.
|
|
global describe_file: function(f: fa_file): string;
|
|
|
|
redef record fa_file += {
|
|
ftp: FTP::Info &optional;
|
|
};
|
|
}
|
|
|
|
function get_file_handle(c: connection, is_orig: bool): string
|
|
{
|
|
if ( [c$id$resp_h, c$id$resp_p] !in ftp_data_expected )
|
|
return "";
|
|
|
|
return cat(Analyzer::ANALYZER_FTP_DATA, c$start_time, c$id, is_orig);
|
|
}
|
|
|
|
function describe_file(f: fa_file): string
|
|
{
|
|
# This shouldn't be needed, but just in case...
|
|
if ( f$source != "FTP" )
|
|
return "";
|
|
|
|
for ( _, c in f$conns )
|
|
{
|
|
if ( c?$ftp )
|
|
return FTP::describe(c$ftp);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
event zeek_init() &priority=5
|
|
{
|
|
Files::register_protocol(Analyzer::ANALYZER_FTP_DATA,
|
|
[$get_file_handle = FTP::get_file_handle,
|
|
$describe = FTP::describe_file]);
|
|
}
|
|
|
|
event file_over_new_connection(f: fa_file, c: connection, is_orig: bool) &priority=5
|
|
{
|
|
if ( [c$id$resp_h, c$id$resp_p] !in ftp_data_expected )
|
|
return;
|
|
|
|
local ftp = ftp_data_expected[c$id$resp_h, c$id$resp_p];
|
|
ftp$fuid = f$id;
|
|
|
|
f$ftp = ftp;
|
|
}
|
|
|
|
event file_sniff(f: fa_file, meta: fa_metadata) &priority=5
|
|
{
|
|
if ( ! f?$ftp )
|
|
return;
|
|
|
|
if ( ! meta?$mime_type )
|
|
return;
|
|
|
|
f$ftp$mime_type = meta$mime_type;
|
|
}
|