Well, I think you're on the right track. You need to do something like
this line in smb-time.pac:
Val* bro_ts = new Val(secs, TYPE_TIME);
The Val constructor with a type of time takes a double of seconds since
the epoch (UNIX time) and gives you the Bro script timestamp val. How
you actually convert whatever format you're working to UNIX time is up
to you and dependent on the format.
Does that make sense? If you can provide more information on how the
timestamp is actually stored, someone might be able to help figure out
how to convert it.
--Vlad
"Bortoli, Tomas" <tomas.bortoli@sit.fraunhofer.de> writes:
That solution looks good but I am stuck with the encoding of the timestamp.
It's a 64 bit timestamp but I don't know how to interpret it. Picture attaced.
Thanks,
Tomas
That solution looks good but I am stuck with the encoding of the timestamp.
It's a 64 bit timestamp but I don't know how to interpret it. Picture attaced.
Thanks,
Tomas
Well, that's protocol specific, but I did some digging:
>>> TIME_FIXUP_CONSTANT
11644473600
>>> hex(filetime)
'0x01d238cc0f66a007'
>>> filetime/10000000.
13122978809.960194
>>> _-TIME_FIXUP_CONSTANT
1478505209.9601936
>>> datetime.datetime.fromtimestamp(1478505209.9601936).strftime('%Y-%m-%d %H:%M:%S')
'2016-11-07 01:53:29'
This is already implemented in smb-time.pac:
double time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz);
zeek::RecordValPtr SMB_BuildMACTimes(uint64_t modify, uint64_t access,
uint64_t create, uint64_t change);
%}
%code{
double filetime2zeektime(uint64_t ts)
{
// Zeek can't support times back to the 1600's
// so we subtract a lot of seconds.
return (ts / 10000000.0L) - 11644473600.0L;
}
double time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz)
{
tm lTime;
lTime.tm_sec = ${t.two_seconds} * 2;
lTime.tm_min = ${t.minutes};
lTime.tm_hour = ${t.hours};
lTime.tm_mday = ${d.day};
You could try just adding this to your PAC file and then you'll be able
to use that function:
%include ../smb/smb-time.pac
Check out krb-asn1.pac for an example of including another PAC file:
%include ../asn1/asn1.pac
%header{
zeek::ValPtr GetTimeFromAsn1(const KRB_Time* atime, int64 usecs);
zeek::ValPtr GetTimeFromAsn1(zeek::StringVal* atime, int64 usecs);
%}
%code{
zeek::ValPtr GetTimeFromAsn1(const KRB_Time* atime, int64 usecs)
{
auto atime_bytestring = to_stringval(atime->time());
auto result = GetTimeFromAsn1(atime_bytestring.get(), usecs);
return result;
}
zeek::ValPtr GetTimeFromAsn1(zeek::StringVal* atime, int64 usecs)
{
time_t lResult = 0;
This file has been truncated. show original
--Vlad
Thank you very much Vlad!
I finally also solve it in a very similar way in the end (conversion + offset)
Tomas