Derek,
This is nearly spot on. Here’s what I have in main.bro from the git link you provided that almost works, but is missing some sort of syntax, as it’s giving me errors. If I comment out the If/else statement f$info$filename gives me the content-disposition extracted filename from the protocol. But I need a check placed in line to see if f$info$filename is empty, it’s empty it should go ahead and try to figure out a mime-type extension. Very close, and it’s probably something very obvious I’m looking over.
@load ./file-extensions
module FileExtraction;
export {
Path to store files
const path: string = “” &redef;
Hook to include files in extraction
global extract: hook(f: fa_file, meta: fa_metadata);
Hook to exclude files from extraction
global ignore: hook(f: fa_file, meta: fa_metadata);
}
event file_sniff(f: fa_file, meta: fa_metadata)
{
if ( meta?$mime_type && !hook FileExtraction::extract(f, meta) )
{
if ( !hook FileExtraction::ignore(f, meta) )
return;
if ( meta$mime_type in mime_to_ext )
local fext = mime_to_ext[meta$mime_type];
else
fext = split_string(meta$mime_type, ///)[1];
if ( f$info$filename != “” )
local fname = cat("%s%s-%s", path, f$source, f$info$filename);
else
local fname = cat("%s%s-%s.%s", path, f$source, f$id, fext);
Files::add_analyzer(f, Files::ANALYZER_EXTRACT,
[$extract_filename=fname]);
}
}
error in /opt/bro/share/bro/site/file-extraction/plugins/./…/./main.bro, line 26 and /opt/bro/share/bro/site/file-extraction/plugins/./…/./main.bro, line 28: already defined (FileExtraction::fname)
error in /opt/bro/share/bro/base/frameworks/files/./main.bro, lines 18-28 and /opt/bro/share/bro/site/file-extraction/plugins/./…/./main.bro, line 30: incompatible record types (Files::AnalyzerArgs and [$extract_filename=FileExtraction::fname])
error in /opt/bro/share/bro/site/file-extraction/plugins/./…/./main.bro, line 30 and /opt/bro/share/bro/base/frameworks/files/./main.bro, lines 18-28: type mismatch ([$extract_filename=FileExtraction::fname] and Files::AnalyzerArgs)
error in /opt/bro/share/bro/site/file-extraction/plugins/./…/./main.bro, lines 29-30: argument type mismatch in function call (Files::add_analyzer(FileExtraction::f, Files::ANALYZER_EXTRACT, [$extract_filename=FileExtraction::fname]))
warning in /opt/bro/share/bro/site/file-extraction/plugins/./…/./main.bro, line 30: expression value ignored (Files::add_analyzer(FileExtraction::f, Files::ANALYZER_EXTRACT, [$extract_filename=FileExtraction::fname]))