2

据我了解,Chrome 浏览器使用 WebKit 时间格式作为浏览器历史数据库中的时间戳。WebKit 时间表示为自 1601 年 1 月以来的毫秒数。

我发现许多文章似乎可以回答我的问题,但到目前为止都没有。常见的答案是使用下面的公式将 WebKit 转换为人类可读的本地时间:

SELECT datetime((time/1000000)-11644473600, 'unixepoch', 'localtime') AS time FROM table;

来源: https ://linuxsleuthing.blogspot.com/2011/06/decoding-google-chrome-timestamps-in.html Chrome 的时间戳格式是什么?

我正在尝试使用以下配置在通过 Osquery 收集数据时转换时间戳。

"chrome_browser_history" : {
        "query" : "SELECT urls.id id, urls.url url, urls.title title, urls.visit_count visit_count, urls.typed_count typed_count, urls.last_visit_time last_visit_time, urls.hidden hidden, visits.visit_time visit_time, visits.from_visit from_visit, visits.visit_duration visit_duration, visits.transition transition, visit_source.source source FROM urls JOIN visits ON urls.id = visits.url LEFT JOIN visit_source ON visits.id = visit_source.id",
        "path" : "/Users/%/Library/Application Support/Google/Chrome/%/History",
        "columns" : ["path", "id", "url", "title", "visit_count", "typed_count", "last_visit_time", "hidden", "visit_time", "visit_duration", "source"],
        "platform" : "darwin"
    }

"schedule": {
    "chrome_history": {
    "query": "select distinct url,datetime((last_visit_time/1000000)-11644473600, 'unixepoch', 'localtime') AS time from chrome_browser_history where url like '%nhl.com%';",
    "interval": 10
    }
}

结果事件的时间戳记为 1600 年:

"time":"1600-12-31 18:46:16"

如果我更改配置以提取原始时间戳而不进行转换,我会得到如下标记:

"last_visit_time":"1793021894"

根据我所读到的有关 WebKit 时间的内容,它以 17 位数字表示,这显然不是我所看到的。所以我现在不确定这是否是 Osquery、Chrome 或查询问题。感谢所有帮助和见解!

4

3 回答 3

4

解决了。日期时间转换需要在表定义查询中进行。即在“chrome_browser_history”下定义的查询。

"chrome_browser_history" : {
        "query" : "SELECT urls.id id, urls.url url, urls.title title, urls.visit_count visit_count, urls.typed_count typed_count, datetime(urls.last_visit_time/1000000-11644473600, 'unixepoch') last_visit_time, urls.hidden hidden, visits.visit_time visit_time, visits.from_visit from_visit, visits.visit_duration visit_duration, visits.transition transition, visit_source.source source FROM urls JOIN visits ON urls.id = visits.url LEFT JOIN visit_source ON visits.id = visit_source.id",
        "path" : "/Users/%/Library/Application Support/Google/Chrome/%/History",
        "columns" : ["path", "id", "url", "title", "visit_count", "typed_count", "last_visit_time", "hidden", "visit_time", "visit_duration", "source"],
        "platform" : "darwin"
    }

"schedule": {
    "chrome_history": {
    "query": "select distinct url,last_visit_time from chrome_browser_history where url like '%nhl.com%';",
    "interval": 10
    }
}

尝试在 osquery 预定查询中进行转换(正如我之前尝试的那样)将不起作用。IE:

"schedule": {
"chrome_history": {
"query": "select distinct url,datetime((last_visit_time/1000000)-11644473600, 'unixepoch', 'localtime') AS time from chrome_browser_history where url like '%nhl.com%';",
"interval": 10
}

}

于 2020-04-14T19:34:39.800 回答
1

尝试:

SELECT datetime(last_visit_time/1000000-11644473600, \"unixepoch\") as last_visited, url, title, visit_count FROM urls;

这是我前段时间写的 - 使用 ATC 配置运行 osqueryi 以读取 chrome 历史文件、导出为 json 并将 json 卷曲到 API 端点的单线

https://gist.github.com/defensivedepth/6b79581a9739fa316b6f6d9f97baab1f

于 2020-04-14T11:02:24.510 回答
0

您正在使用的东西是非常直接的sqlite。因此,我将从在 sqlit 中进行调试开始。

首先,您应该验证数据是否符合您的预期。在我的机器上,我看到:

$ cp   Library/Application\ Support/Google/Chrome/Profile\ 1/History /tmp/
$ sqlite3 /tmp/History "select last_visit_time from urls limit 2"
13231352154237916
13231352154237916

其次,我将验证基础数学:

sqlite> select datetime(last_visit_time/1000000-11644473600, "unixepoch") from urls limit 2;
2020-04-14 15:35:54
2020-04-14 15:35:54

如果您将其包含为我们可以复制/粘贴的文本,则测试您的配置片段会更容易。

于 2020-04-14T16:07:35.817 回答