analyzer/files: handle non-analyzer names in describe_file()

When a fa_file object is created through the use of Input::add_analysis(),
the fa_file's source is likely not valid representation of an analyzer's
tag and a Files::describe() should not error and instead return an empty
description.

Add a new Analyzer::is_tag() helper that can be used to pre-check `f$source`.
This commit is contained in:
Arne Welzel 2022-12-02 15:36:49 +01:00
parent 1e06c8bfda
commit 85ce48eb1e
7 changed files with 97 additions and 8 deletions

View file

@ -0,0 +1,10 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
#separator \x09
#set_separator ,
#empty_field (empty)
#unset_field -
#path files
#open XXXX-XX-XX-XX-XX-XX
#fields ts fuid uid id.orig_h id.orig_p id.resp_h id.resp_p source depth analyzers mime_type filename duration local_orig is_orig seen_bytes total_bytes missing_bytes overflow_bytes timedout parent_fuid
#types time string string addr port addr port string count set[string] string string interval bool bool count count count count bool string
XXXXXXXXXX.XXXXXX F6EpcI3V7f021PQMmh - - - - - ./myfile 0 SHA1 application/pdf - 0.000000 - - 73 - 0 0 F -

View file

@ -0,0 +1,10 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
#separator \x09
#set_separator ,
#empty_field (empty)
#unset_field -
#path notice
#open XXXX-XX-XX-XX-XX-XX
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p fuid file_mime_type file_desc proto note msg sub src dst p n peer_descr actions email_dest suppress_for
#types time string addr port addr port string string string enum enum string string addr addr port count string set[enum] set[string] interval
XXXXXXXXXX.XXXXXX - - - - - F6EpcI3V7f021PQMmh application/pdf (empty) - NoticeTestType test - - - - - - Notice::ACTION_LOG (empty) 3600.000000

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
file_hash, sha1, 0
[fuid=F6EpcI3V7f021PQMmh, desc=, mime=application/pdf, cid=<uninitialized>, cuid=<uninitialized>]

View file

@ -0,0 +1,36 @@
# @TEST-DOC: Call create_file_info() and populate_file_info2() when a file has been added through Input::add_analysis()
# @TEST-EXEC: zeek -b %INPUT > output
# @TEST-EXEC: btest-diff output
# @TEST-EXEC: btest-diff files.log
# @TEST-EXEC: btest-diff notice.log
@load base/protocols/http
@load base/frameworks/files
redef enum Notice::Type += { NoticeTestType };
event file_new(f: fa_file)
{
Files::add_analyzer(f, Files::ANALYZER_SHA1);
}
event file_hash(f: fa_file, kind: string, hash: string)
{
print "file_hash", kind, f?$conns ? |f$conns| : 0;
local fi = Notice::create_file_info(f);
print fi;
local n: Notice::Info = Notice::Info($note=NoticeTestType, $msg="test");
Notice::populate_file_info2(fi, n);
NOTICE(n);
}
event zeek_init()
{
Input::add_analysis([$source="./myfile", $name="./myfile"]);
}
@TEST-START-FILE ./myfile
%PDF-1.5
This isn't an actual pdf, but it shows in files.log as such :-)
@TEST-END-FILE