mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Spicy: allow providing file id in zeek::file_begin
Address feedback of GH-3470: minor changes of C++ code, unify test cases
This commit is contained in:
parent
ae0b328826
commit
45c558af1e
6 changed files with 29 additions and 70 deletions
|
@ -683,9 +683,10 @@ void rt::protocol_handle_close(const ProtocolHandle& handle) {
|
||||||
|
|
||||||
rt::cookie::FileState* rt::cookie::FileStateStack::push(std::optional<std::string> fid_provided) {
|
rt::cookie::FileState* rt::cookie::FileStateStack::push(std::optional<std::string> fid_provided) {
|
||||||
auto _ = hilti::rt::profiler::start("zeek/rt/file-stack-push");
|
auto _ = hilti::rt::profiler::start("zeek/rt/file-stack-push");
|
||||||
|
if ( fid_provided && find(*fid_provided) )
|
||||||
|
throw InvalidValue(hilti::rt::fmt("Duplicate file id %s provided", *fid_provided));
|
||||||
|
|
||||||
auto fid = fid_provided.value_or(file_mgr->HashHandle(hilti::rt::fmt("%s.%d", _analyzer_id, ++_id_counter)));
|
auto fid = fid_provided.value_or(file_mgr->HashHandle(hilti::rt::fmt("%s.%d", _analyzer_id, ++_id_counter)));
|
||||||
if ( find(fid) )
|
|
||||||
throw InvalidValue(hilti::rt::fmt("Duplicate file id %s provided", fid));
|
|
||||||
_stack.emplace_back(fid);
|
_stack.emplace_back(fid);
|
||||||
return &_stack.back();
|
return &_stack.back();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
|
||||||
FaAaAaAaAaAaAaAaAa
|
|
||||||
FaAaAaAaAaAaAaAaAa
|
|
|
@ -1,3 +1,5 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
FM47gX3vI5ofQPm1li
|
FM47gX3vI5ofQPm1li
|
||||||
FZjUS57tUkGFTibv3
|
FZjUS57tUkGFTibv3
|
||||||
|
FaAaAaAaAaAaAaAaAa
|
||||||
|
FaAaAaAaAaAaAaAaAa
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
# @TEST-REQUIRES: have-spicy
|
|
||||||
#
|
|
||||||
# @TEST-EXEC: spicyz -d -o test.hlto ssh.spicy ./ssh-cond.evt
|
|
||||||
# This is equivalent to file-analysis-data-in, besides the fact that we provide our own file ID.
|
|
||||||
#
|
|
||||||
# @TEST-EXEC: zeek -r ${TRACES}/ssh/single-conn.trace test.hlto %INPUT Spicy::enable_print=T | sort >output
|
|
||||||
#
|
|
||||||
# @TEST-EXEC: cat files.log | zeek-cut fuid filename >files.log.tmp && mv files.log.tmp files.log
|
|
||||||
# @TEST-EXEC: btest-diff files.log
|
|
||||||
#
|
|
||||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=diff-canonifier-spicy btest-diff output
|
|
||||||
|
|
||||||
# @TEST-START-FILE ssh.spicy
|
|
||||||
module SSH;
|
|
||||||
|
|
||||||
import spicy;
|
|
||||||
import zeek;
|
|
||||||
|
|
||||||
global file_counter = 0;
|
|
||||||
|
|
||||||
public type Banner = unit {
|
|
||||||
magic : /SSH-/ {
|
|
||||||
# This is a bit of cheating.
|
|
||||||
local d: spicy::Base64Stream;
|
|
||||||
local dec : bytes = spicy::base64_decode(d, b"MIIESjCCAzKgAwIBAgINAeO0mqGNiqmBJWlQuDANBgkqhkiG9w0BAQsFADBMMSAwHgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMjETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjAeFw0xNzA2MTUwMDAwNDJaFw0yMTEyMTUwMDAwNDJaMEIxCzAJBgNVBAYTAlVTMR4wHAYDVQQKExVHb29nbGUgVHJ1c3QgU2VydmljZXMxEzARBgNVBAMTCkdUUyBDQSAxTzEwggEiMA0GCSqGSIb3DQEBA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IAJbELCQCZwMH56t2Dvqofxs6BBcCFIZUSpxu6x6td0V7SvJCCosirSmIatj/9dSSVDQibet8q/7UK4v4ZUN80atnZz1yg==");
|
|
||||||
dec += spicy::base64_finish(d);
|
|
||||||
|
|
||||||
print self.file_id;
|
|
||||||
zeek::file_data_in(dec);
|
|
||||||
}
|
|
||||||
version : /[^-]*/;
|
|
||||||
dash : /-/;
|
|
||||||
software: /[^\r\n]*/;
|
|
||||||
|
|
||||||
var file_id: string = zeek::file_begin("application/x-x509-ca-cert", "FaAaAaAaAaAaAaAaAa");
|
|
||||||
var file_name: string = "foo-%d.txt" % ++file_counter;
|
|
||||||
};
|
|
||||||
|
|
||||||
on Banner::%done { zeek::file_end(self.file_id); }
|
|
||||||
|
|
||||||
# @TEST-END-FILE
|
|
||||||
|
|
||||||
# @TEST-START-FILE ssh-cond.evt
|
|
||||||
|
|
||||||
import zeek;
|
|
||||||
|
|
||||||
protocol analyzer spicy::SSH over TCP:
|
|
||||||
parse with SSH::Banner,
|
|
||||||
port 22/tcp,
|
|
||||||
replaces SSH;
|
|
||||||
|
|
||||||
on SSH::Banner::software -> event have_filename($file, self.file_name);
|
|
||||||
|
|
||||||
# @TEST-END-FILE
|
|
||||||
|
|
||||||
# Trigger creation of `files.log`.
|
|
||||||
@load base/protocols/ssl
|
|
||||||
redef X509::log_x509_in_files_log = T;
|
|
||||||
|
|
||||||
event have_filename(f: fa_file, filename: string)
|
|
||||||
{
|
|
||||||
f$info$filename = filename;
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
# @TEST-REQUIRES: have-spicy
|
# @TEST-REQUIRES: have-spicy
|
||||||
#
|
#
|
||||||
# @TEST-EXEC: spicyz -d -o test.hlto ssh.spicy ./ssh-cond.evt
|
# @TEST-EXEC: cat ssh.spicy ssh-1.spicy > ssh-test.spicy
|
||||||
|
# @TEST-EXEC: spicyz -d -o test.hlto ssh-test.spicy ./ssh-cond.evt
|
||||||
# @TEST-EXEC: zeek -r ${TRACES}/ssh/single-conn.trace test.hlto %INPUT Spicy::enable_print=T | sort >output
|
# @TEST-EXEC: zeek -r ${TRACES}/ssh/single-conn.trace test.hlto %INPUT Spicy::enable_print=T | sort >output
|
||||||
#
|
#
|
||||||
# @TEST-EXEC: cat x509.log | grep -v ^# | cut -f 4-5 >x509.log.tmp && mv x509.log.tmp x509.log
|
# @TEST-EXEC: cat x509.log | grep -v ^# | cut -f 4-5 >x509.log.tmp && mv x509.log.tmp x509.log
|
||||||
|
@ -9,6 +10,13 @@
|
||||||
# @TEST-EXEC: cat files.log | zeek-cut sha1 filename >files.log.tmp && mv files.log.tmp files.log
|
# @TEST-EXEC: cat files.log | zeek-cut sha1 filename >files.log.tmp && mv files.log.tmp files.log
|
||||||
# @TEST-EXEC: btest-diff files.log
|
# @TEST-EXEC: btest-diff files.log
|
||||||
#
|
#
|
||||||
|
# @TEST-EXEC: cat ssh.spicy ssh-2.spicy > ssh-test.spicy
|
||||||
|
# @TEST-EXEC: spicyz -d -o test.hlto ssh-test.spicy ./ssh-cond.evt
|
||||||
|
# @TEST-EXEC: zeek -r ${TRACES}/ssh/single-conn.trace test.hlto %INPUT Spicy::enable_print=T | sort >>output
|
||||||
|
#
|
||||||
|
# @TEST-EXEC: cat files.log | zeek-cut fuid filename >files.log.tmp && mv files.log.tmp files-2.log
|
||||||
|
# @TEST-EXEC: btest-diff files-2.log
|
||||||
|
#
|
||||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=diff-canonifier-spicy btest-diff output
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER=diff-canonifier-spicy btest-diff output
|
||||||
|
|
||||||
# @TEST-START-FILE ssh.spicy
|
# @TEST-START-FILE ssh.spicy
|
||||||
|
@ -33,7 +41,7 @@ public type Banner = unit {
|
||||||
dash : /-/;
|
dash : /-/;
|
||||||
software: /[^\r\n]*/;
|
software: /[^\r\n]*/;
|
||||||
|
|
||||||
var file_id: string = zeek::file_begin("application/x-x509-ca-cert");
|
var file_id: string;
|
||||||
var file_name: string = "foo-%d.txt" % ++file_counter;
|
var file_name: string = "foo-%d.txt" % ++file_counter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,6 +49,20 @@ on Banner::%done { zeek::file_end(self.file_id); }
|
||||||
|
|
||||||
# @TEST-END-FILE
|
# @TEST-END-FILE
|
||||||
|
|
||||||
|
# First test case - just let Zeek generate the File ID
|
||||||
|
# @TEST-START-FILE ssh-1.spicy
|
||||||
|
|
||||||
|
on Banner::%init { self.file_id = zeek::file_begin("application/x-x509-ca-cert"); }
|
||||||
|
|
||||||
|
# @TEST-END-FILE ssh-1.spicy
|
||||||
|
|
||||||
|
# Second test case - provide a file ID
|
||||||
|
# @TEST-START-FILE ssh-2.spicy
|
||||||
|
|
||||||
|
on Banner::%init { self.file_id = zeek::file_begin("application/x-x509-ca-cert", "FaAaAaAaAaAaAaAaAa"); }
|
||||||
|
|
||||||
|
# @TEST-END-FILE ssh-2.spicy
|
||||||
|
|
||||||
# @TEST-START-FILE ssh-cond.evt
|
# @TEST-START-FILE ssh-cond.evt
|
||||||
|
|
||||||
import zeek;
|
import zeek;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue