Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Milliseconds and microseconds are set to zero when uploading a CSV using the CLI client or importer client - Web UI unaffected #3173

Open
J-A-Sec opened this issue Sep 3, 2024 · 9 comments
Assignees
Labels
Bug Data import All things that are with importing data

Comments

@J-A-Sec
Copy link

J-A-Sec commented Sep 3, 2024

Describe the bug
When uploading a Hayabusa-generated CSV timeline via the CLI client or importer client, milliseconds and microseconds are set to zero in the datetime and timestamp fields. Timestamps tested have been in RFC-3339 and ISO-8601 format.

When uploading the same CSV using the web UI, the timestamps retain their microsecond precision.

To Reproduce
Steps to reproduce the behaviour:

  1. Generate a Hayabusa CSV timeline using the Timesketch-verbose profile and with the flag --ISO8601
  2. Import the CSV into Timesketch using the web UI and note the datetime & timestamp of the first entry
  3. Import the same CSV into Timesketch using the CLI client or importer script, and note the datetime & timestamp of the first entry on each timeline.
  4. Compare the datetime and timestamps of the timelines. Microsecond precision is replaced with zeros on the timelines not uploaded via the web UI.

Expected behaviour
Microsecond precision in timestamps are preserved when uploading CSV timelines using the CLI client or importer script.

Screenshots
Snippet of timestamp in Hayabusa CSV timeline:
image

Timesketch fields of CSV timeline uploaded using the web UI:
image

Timesketch fields of CSV timeline uploaded using the CLI client:
image

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Edge
  • Version 120.0.2210.144
@J-A-Sec J-A-Sec added the Bug label Sep 3, 2024
@jaegeral
Copy link
Collaborator

jaegeral commented Sep 3, 2024

can you provide a csv sample with all values including the headers?

@J-A-Sec
Copy link
Author

J-A-Sec commented Sep 3, 2024

Sure, I've attached a small sample. I can confirm that the same behaviour is observed with this file.

Versions:
Timesketch release: 20240717
API Client Version: 20240215
Importer Client Version: 20230721

Sample.csv

@jaegeral
Copy link
Collaborator

jaegeral commented Sep 3, 2024

Thx.

There was some previous art: 30da8aa

and https://github.com/google/timesketch/blob/master/test_tools/test_events/validate_timestamp_conversion.csv might be the right place to add more variation to it.

@jaegeral jaegeral self-assigned this Sep 3, 2024
@jaegeral jaegeral added the Data import All things that are with importing data label Sep 3, 2024
@jaegeral
Copy link
Collaborator

jaegeral commented Sep 3, 2024

So can confirm, the following:

string = (
                '"total precision","123456789",'
                '"2024-07-24T10:57:02.877297Z","Write time","timestamptest"\n'
            )
            file_object.write(string)

results in:

+-----------+---------------------------+-----------------+------------------+------------------+
| comment   | datetime                  | message         |        timestamp | timestamp_desc   |
|-----------+---------------------------+-----------------+------------------+------------------|
| []        | 2015-07-24 19:01:01+00:00 | ISO8601         |      1.3317e+15  | Write time       |
| []        | 2015-07-24 19:01:01+00:00 | Wrong epoch     | 123456           | Write time       |
| []        | 2015-07-24 19:01:01+00:00 | Notimestamp     |    nan           | Write time       |
| []        | 2024-07-24 10:57:02+00:00 | total precision |      1.23457e+08 | Write time       |
| []        | NaT                       | no_datetime     | 123456           | Write time       |
+-----------+---------------------------+-----------------+------------------+------------------+

@jaegeral
Copy link
Collaborator

jaegeral commented Sep 4, 2024

Based on:

TIMESKETCH_FIELDS = frozenset({"message", "datetime", "timestamp_desc"})

datetime is the leading field, and timestamp is not mandatory.

@jaegeral
Copy link
Collaborator

assuming it is here:

data_frame["datetime"] = date.dt.strftime("%Y-%m-%dT%H:%M:%S%z")

@jaegeral
Copy link
Collaborator

So we now have unittests to reproduce the problem, stay tuned for hopefully fixing it, but we need to discuss what our expectation here is.

@J-A-Sec
Copy link
Author

J-A-Sec commented Sep 24, 2024

Thanks @jaegeral.

I have another timestamp issue which may be related - if not I can raise this separately.

Importing a CSV using timesketch_importer from a different data set to the original issue results in a malformed datetime, but only with how it's displayed.

Snippet of the CSV (headers/columns truncated):

RecordNumber,EventRecordId,TimeCreated,EventId
33,33,2023-05-03T07:36:43.9116468+00:00,21
40,40,2023-05-03T07:54:40.1398633+00:00,21
47,47,2023-05-03T08:22:34.8842158+00:00,21

The timestamp format makes no difference to the result; I've tried cutting off the offset, precision below 1 second, removing the "T".

Once imported to the timeline, it appears in the correct place chronologically. The image below shows the same events, the top 3 of each section are from CLI import, the bottom 3 are from web upload.
image

Strangely, the UNIX timestamp is correct for the CLI upload and incorrect for the web upload:
CLI upload: 1683099403.9116466
Web upload: 1683099403911646

Note: These were uploaded using a formatter.yaml file to define message, datetime, timestamp_desc etc., but the importer fairs no better when excluding a formatter file.

@J-A-Sec
Copy link
Author

J-A-Sec commented Sep 24, 2024

This latest issue has been referenced here: #3084 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Data import All things that are with importing data
Projects
None yet
Development

No branches or pull requests

2 participants