Hi Justin,
Do you know that the intel framework supports hashes? If you export a feed of hashes from CIF you can load that into bro and do the alerting on known hashes bad in real time.
Yes. And that was the plan, but unfortunately, I couldn’t get the list of the feeds (hashes) pulled down from REN-ISAC , that’s interesting that they provide other feeds but hashes (will ask in REN-ISAC mailing list to confirm).
But I figured out that you can query their database to get information about a particular hash.
Also, tried looking for a good open source of feeds for hashes, but couldn’t find it hence don’t have any hash feeds currently in intel
Thank you for the code, works perfect!
Made a little tweak, replaced network_time() with current_time() function at both the places.
For some reason I was getting 0.0 as network_time() value when ran the code in try.bro.org with sample http pcap.
Also, added "local mn_EST = mn + 14400.0; " in midnight() function to get local EST in quick and dirty way. (I know the best way to do ii to use Seth’s plugin, will try that next).
Hence, the complete script looks like this now:
module Uniq_hashes;
redef record Files::Info += {
Adding a field column of host and uniq_hash to show from where
the file got downloaded and whether seen first time or duplicate.
host: string &optional &log;
uniq_hash: bool &optional &log ;
};
global SECONDS_IN_DAY = 606024;
global uniq_hashes: set[string] ;
function midnight(): time
{
local now = current_time();
local dt = time_to_double(now);
local mn = double_to_count(dt / SECONDS_IN_DAY) * SECONDS_IN_DAY;
local mn_EST = mn + 14400.0;
return double_to_time(mn_EST);
}
function interval_to_midnight(): interval
{
return midnight() - current_time();
}
event reset_hashes()
{
uniq_hashes = set(); #I think this is the proper way to clear a set?
}
event file_hash(f: fa_file, kind: string, hash: string)
{
#print “file_hash”, f$id, kind, hash;
if(f?$http && f$http?$host)
f$info$host = f$http$host;
if(hash in uniq_hashes)
f$info$uniq_hash = F;
else
{
add uniq_hashes[hash];
f$info$uniq_hash = T;
}
}
event bro_init()
{ #print “current_time”, current_time();
#print “midnight”, midnight();
#print “Time to midnight:”, interval_to_midnight();
schedule interval_to_midnight() { reset_hashes()};
}
Thanks,Fatema.