見習いフォレンジッカーのメモ

デジタルフォレンジックに関することを書いていこうと思います。誤りを含む可能性も高いので、信じるか信じないかはあなた次第です。。

Catalina上で保全してきたUnifiedLogを解析する -Analyze the acquired UnifiedLog on Catalina-

ご存知の方もいらっしゃるかもしれませんが、今回も調査に役立つかもしれない調査方法を見つけたので、今わかっていること(こうだと思っていること)やちょっとした検証や考察などについて書きます。

Some of you may know, I found a way of invistigation that might be useful.
So I wrote about what I know now (what I am thinking), how I found this, some verifications, and considerations.

【概要(前置き)】[Introduction]
現在のmacOSの主要ログであるUnifiedLogですが、mojaveではこちらの記事(https://support.blackbagtech.com/hc/en-us/articles/360024686592-Examining-USB-Device-Connections-from-macOS-Sierra-High-Sierra-and-Mojave)のように/private/var/db/diagnostics/と/private/var/db/uuidtext/の中身を1つのディレクトリに格納し、そのディレクトリ名を~.logarchiveとすることでmacOS標準のlogコマンドやコンソール.appを使って解析することができました。
しかし、Catalinaになると、同じことをしても下記のようにエラーになり解析することができませんでした。

When analyzing UnifiedLog in mojave, [merge the contents of "/private/var/db/diagnostics/" and "/private/var/db/uuidtext/" into one directory, and then change the directory name to "~.logarchive"] can possible to analyze using the  "log" command and "Console.app"(as in this article. https://support.blackbagtech.com/hc/en-us/articles/360024686592-Examining-USB-Device-Connections-from-macOS-Sierra-High-Sierra-and-Mojave).
However, in Catalina, even if I did the same thing, the following error occurred and I could not analyze it.

f:id:kasasagi_f:20200311024433p:plain

live環境であれば、調査対象Mac上のターミナルからlogコマンドでunifiedログを調査可能(もしくはsudo log collectでCatalina上でもlogコマンドで解析可能な.logarchiveを作成可能)ですが、実際の調査時は証拠保全やTriageしてきたファイルから調査することも多いと思いますので、この方法ができないとUnifiedLogの解析がし難いという問題があります(商用ツールなどがあれば別ですが)。そこで今回は、この対処法について考えてみました。

In a live environment, the unified log can be investigated using the log command from the terminal on the target mac(or you can create a .logarchive that can be analyzed with the log command on Catalina with sudo log collect). However, at the time of actual investigation, I think that it is often the case to investigate from the files that have undergone evidence preservation and Triage, so there is a problem that it is difficult to analyze UnifiedLog because this(.logarchive) method is not possible (except for commercial tools etc. ). So this time, I thought about this solution.

  

【意義】[How it can be useful for investigation]
Catalina上でも、証拠保全やTriageしてきたファイルからlogコマンドやコンソール.appで解析可能なlogarchiveを生成することができます。

Even on Catalina, logarchive that can be analyzed with "log" command or "Console.app" can be generated from files that have undergone evidence preservation and triage.

 

【解析対象ファイルの場所】[Location of files to be analyzed]
/private/var/db/diagnostics/
/private/var/db/uuidtext/

 

【検証】[verification]
まず始めに、今回の事象が、OSのVer.によって引き起こされる問題なのか(あるいはlogコマンドの仕様が変更されたのか)、それとも、Logファイルの中身の問題なのか切り分ける為、Catalinaで作成したエラーが出てlogコマンドを受け付けない.logarchiveファイルを、mojaveに持っていきlogコマンドがきくか確かめました。
すると、mojave上でものままではlog showコマンドで解析できませんが、ガイダンスの通りlog show --forceのオプションを用いればCatalinaから持ってきた.logarchiveが、使用可能な状態にupdateされることがわかりました。(一方でCatalinaでは--forceコマンドを使用してもlog showコマンドをupdateしたり閲覧することはできません)

First of all, I decided to determine whether this is a problem caused by the OS Ver.(or whether the specification of the log command has been changed) or a problem in the contents of the Log file.
Therefore, I moved the .logarchive file created by Catalina, which had an error and did not accept the log command, to mojave and checked whether it could be processed by the log command.
Then, it is not possible to analyze with the log show command as it is on mojave, but if you use the option of log show --force as guidance, the .logarchive brought from Catalina was updated to a usable state. (On the other hand, in Catalina, it is not possible to update or view the log show command even if you use the --force command)

f:id:kasasagi_f:20200311025749p:plain

f:id:kasasagi_f:20200311030832p:plain

f:id:kasasagi_f:20200311030106p:plain
このことから、logの中身そのものではなく、OSやlogコマンドの仕様変更が原因だと仮説を立てました。また、log show初回実行時の警告文から、Catalinaで処理できないlogarchiveは古い形式(Ver.4以前 3?)であるのではないかと考えました。

Based on this, we hypothesized that the cause was not the .logarchive itself, but a change in the specifications of the OS and the log command. Also, from the warning message at the time of the first execution of log show, I thought that logarchive that can not be processed by Catalina may be in old format (Ver.3 ?).

次に、もう一度同じ検証を繰り返し、このlog showコマンドがきくアップデート後のlogarchive(--force後)と、うまくいかないアップデート前のlogarchive(--force前)の内容物を比較すると、うまくいくケースのlogarchiveにはinfo.plistと言うファイルがあることに気づきました。(また、log collectというコマンドを使用するとCatalina上でも解析可能な.logarchiveが作成されるので、これと、log showコマンドが効かない.logarchiveも比較してみましたが、同じくlog show可能な方にはinfo.plistが存在することを確認しました)

Next, we repeated the same verification again, and compared the contents of logarchive (before --force) where the log show command works, and logarchive (before --force) before the update that did not work. Then I noticed that a successful logarchive had a file called info.plist. (In addition, I know that using the command "log collect" creates a .logarchive that can be analyzed on Catalina. And, I also confirmed that info.plist exists in it.)

f:id:kasasagi_f:20200311032038p:plain

--force前

f:id:kasasagi_f:20200311032115p:plain

--force後

このファイルはxml形式のplistで、中には下記のようなキーや値が格納されていました。

This file was an xml format plist, which contained the following keys and values.

f:id:kasasagi_f:20200311032429p:plain

--force後に作成されたinfo.plist

f:id:kasasagi_f:20200311033301p:plain

log collectコマンドで作成した.logarchiveの中のinfo.plist(抜粋)

今回の検証の目的は、証拠保全やTriageしてきたファイルからもlogコマンドで解析する方法を探すことなので、このinfo.plistを人工的に作り出せば解析可能なlogarchiveになるのではないかと考え、このinfo.plistに必須と思われる要素を探しました。
1つ1つkeyや値を削除して、logコマンドで解析可能か確認し、なくてはならない要素を絞り込みました。その結果、--force後のinfo.plistの内容を追加することでCatalinaのlogコマンドでも解析可能な.logarchiveファイルになることがわかりました。(実際は、--force後のplistの中身がミニマムであろうという見立てを立て、その後そうじゃない可能性を検証しました)

The purpose of this verification is to find a way to analyze the log command from the files that have undergone evidence preservation and triage, so we thought that if this info.plist was created artificially, it would be a logarchive that could be analyzed. I looked for elements that seemed to be required in info.plist.
Each key and value were deleted in order, and the log command was used to check whether it could be analyzed, and the essential elements were narrowed down. As a result, it was found that by adding "contents of info.plist after --force", it becomes .logarchive file that can be analyzed even by Catalina's log command.

【追記】[add]:2021/01/18
こちらのリンクにある様に、info.plistの中身のOSArchiveVersionは4にすると時間がずれる為、2が良いとの事でした。我ながらこのブログの間違え率高いですね。そして、去年はinputもoutputもかなり怠っていたのでそれも悔やまれます。申し訳ございません。
As you can see in this link, the OSArchiveVersion in the info.plist should be 2, because the time is shifted if it is 4. I have a high rate of mistakes in this blog. I also regret that I neglected to do input last year. I also apologize for that.
【要確認のより詳細な検証結果】[confirmation required]
https://www.mac4n6.com/blog/2020/4/20/analysis-of-apple-unified-log-quarantine-edition-entry-1-converting-log-archive-files-on-1015-catalina

 

あらゆるCatalinaで試したわけではないですが、いくつかの環境では同様のinfo.plistをlogarchiveの中に追加する方法で、logコマンドで解析不能なlogarchiveを解析可能な状態にすることができました。
log showの結果に、"log: warning: The log archive contains partial or missing metadata"というメッセージが出ていたり、log collectの中には他にも沢山のデータがあるので欠損などが生じないか注意は必要ですが、この方法を用いれば全く調査できないという事態は回避できそうに見えます。

Although I did not try with a lot of Catalina, in some environments it was possible to make a logarchive that could not be parsed with the log command parseable by adding a same info.plist to the logarchive .
In the result of log show, the message "log: warning: The log archive contains partial or missing metadata" appears, and there is a lot of other data in log collect, so be careful if there is any loss etc. It is necessary, but it seems that using this method can avoid a situation where no investigation is possible.

【追記】[add]:2021/01/18
前述の様にOSArchiveVersionは2の方が良さそうです。
The OSArchiveVersion should be set to 2.


【考察】[Consideration]
これは、恐らくlogコマンドが対応しているlogarchiveのフォーマットに起因すると思われます。
先述の通り、mojaveにおいて、info.plistがない.logarchiveを使用する場合は、「Version4にアップデートする必要があります」と言ったエラーが出てくる為、info.plistがないものはVer.3かそれ以前のものであったようです。
しかし、CatalinaからはVer.4しか受け付けてくれず、かつVer.4へのアップデート機能もなくなったので、log showで内容の閲覧ができなくなったのではないかと思われます。
その為、info.plistに「OSArchiveVersion」が「4」という設定を入れて、logarchiveに混ぜ込めばVer.4と認識され、処理可能になったのではないでしょうか。

This is probably due to the format of the logarchive supported by the log command.As mentioned above, when using logarchive without info.plist in mojave, an error stating "It is necessary to update to Version 4" appears. It seems to have been the previous one.
However, since Catalina only accepted Ver.4 and the update function to Ver.4 was also lost, it seems that the contents could not be viewed with log show.
Therefore, if you set "OSArchiveVersion" to "4" in info.plist and merge it with logarchive, it will be recognized as Ver.4 and it will be possible to process it.

From next time, I would like to introduce my recently announced self-made tools for mac4n6.

【追記】[add]:2021/01/18
OSArchiveVersionは2でも良さそうなので、この仮説は間違っている様です。
This hypothesis seems to be wrong, since OSArchiveVersion can be 2.