0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Blast from the past picoCTF (Writeup)

0
Posted at

【picoCTF】[Blast from the past] Writeup

問題概要

  • Category: Forensics

Description:

The judge for these pictures is a real fan of antiques. Can you age this photo to the specifications?
Set the timestamps on this picture to 1970:01:01 00:00:00.001+00:00 with as much precision as possible for each timestamp. In this example, +00:00 is a timezone adjustment. Any timezone is acceptable as long as the time is equivalent. As an example, this timestamp is acceptable as well: 1969:12:31 19:00:00.001-05:00. For timestamps without a timezone adjustment, put them in GMT time (+00:00). The checker program provides the timestamp needed for each.
Use this picture.
Submit your modified picture here:
nc -w 2 mimas.picoctf.net 61553 < original_modified.jpg
Check your modified picture here:
nc mimas.picoctf.net 60053

日本語訳:

これらの写真の審査員は本物のアンティークファンです。この写真を仕様に合わせて古くすることができますか?
この写真のすべてのタイムスタンプを、可能な限り正確に 1970:01:01 00:00:00.001+00:00 に設定してください。この例の +00:00 はタイムゾーン調整です。時間が同等である限り、どのタイムゾーンでも許容されます(例:1969:12:31 19:00:00.001-05:00 も可)。タイムゾーン調整がないタイムスタンプはGMT時間(+00:00)にしてください。チェッカープログラムが、必要な各タイムスタンプを教えてくれます。
与えられた画像を使用し、指定のサーバーへ修正した画像を送信して確認してください。


解法のプロセス(アプローチ)

1. 画像の確認と初期調査

まずはダウンロードした画像ファイル(original.jpg)に、どのようなタイムスタンプ(Exif情報)が含まれているのかを確認します。解析には exiftool が便利です。

exiftool -time:all original.jpg

実行結果:

Modify Date                     : 2023:11:20 15:46:23
Date/Time Original              : 2023:11:20 15:46:23
Create Date                     : 2023:11:20 15:46:23
Sub Sec Time                    : 703
Sub Sec Time Original           : 703
Sub Sec Time Digitized          : 703
Time Stamp                      : 2023:11:21 05:46:21.420+09:00
Create Date                     : 2023:11:20 15:46:23.703
Date/Time Original              : 2023:11:20 15:46:23.703
Modify Date                     : 2023:11:20 15:46:23.703

基本の日時タグに加え、ミリ秒(Sub Sec Time)や、Samsung独自のタイムスタンプタグ(Time Stamp)が存在することが分かります。これら全てを 1970:01:01 00:00:00.001 に書き換えるのが今回の目標です。

2. ExifToolによる標準タグの書き換えと復旧

まずは、ExifToolを使って一般的なタグを書き換えます。元のファイルを残すためコピーしてから作業します。

cp original.jpg original_modified.jpg
exiftool -AllDates="1970:01:01 00:00:00.001" original_modified.jpg
exiftool -SubSecCreateDate="1970:01:01 00:00:00.001" original_modified.jpg
exiftool -SubSecDateTimeOriginal="1970:01:01 00:00:00.001" original_modified.jpg
exiftool -SubSecModifyDate="1970:01:01 00:00:00.001" original_modified.jpg

💡 コラム:ExifToolによる「オフセット破壊」の罠
ExifToolは非常に優秀ですが、タグを編集した際にファイルの内部構造を自動で再構築します。この時、メーカー独自のメタデータ(MakerNotes)のオフセットが破損し、チェッカープログラムに弾かれてしまうことがあります。

壊れてしまった Samsung の Time Stamp などを正常な状態に戻すため、元の画像から MakerNotes だけを抽出して上書き復旧させます。

exiftool -TagsFromFile original.jpg -MakerNotes original_modified.jpg

3. 「隠れたミリ秒タグ」の特定

標準タグの修正はできましたが、Samsung独自の Time Stamp タグがまだ古い日付のまま残っています。
実は、このタグはExifToolでは**書き換え不可(Read-Only)になっており、さらに実際のバイナリ内部では「日付の文字列」ではなく「13桁のUnixエポックタイム(ミリ秒)」**として保存されています。

-v3 オプションを使って生のデータ構造を覗き見ます。

exiftool -v3 original_modified.jpg | grep -i "Time"

実行結果抜粋:

  | | 0)  ExposureTime = 0.041662 (41662000/1000000000)
  | | 7)  DateTimeOriginal = 2023:11:20 15:46:23
  | | 19) SubSecTime = 703
  | | 20) SubSecTimeOriginal = 703
  | | 21) SubSecTimeDigitized = 703
  TimeStamp = 1700513181420

Samsungのタイムスタンプの正体は 1700513181420(2023年11月20日 20:46:21 UTC)であることが分かりました。私たちが目指すのは「1970年1月1日 00:00:00.001」つまりエポックタイム開始から1ミリ秒後なので、この数字を 0000000000001 に書き換える必要があります。

4. バイナリエディタを使った直接書き換え

Read-Onlyのタグを書き換えるため、そしてファイル構造をこれ以上破壊しないために、VS Codeの拡張機能「Hex Editor」などのバイナリエディタを使って直接上書き(パッチ当て)を行います。

【書き換えターゲット】
文字数(バイト数)が絶対に増減しないよう、以下の箇所を検索して慎重に上書きします。

  • 検索: 1700513181420
  • 置換: 0000000000001

image.png

このように13桁の数字をピッタリ上書きし、保存(Ctrl + S)すればバイナリ改ざんは完了です。

5. 提出とフラグ獲得

文字数とオフセットを完全に維持した完璧な偽装画像(original_modified.jpg)が出来上がりました。
これを問題文で指定された netcat (nc) コマンドで提出用サーバーに送信します。

nc -w 2 mimas.picoctf.net 61553 < original_modified.jpg

続いて、確認用のサーバーに接続して結果を見ます。

nc mimas.picoctf.net 60053

実行結果:

Checking tag 1/7
Great job, you got that one!
... (省略) ...
Checking tag 7/7
Great job, you got that one!

picoCTF{71m3_7r4v311ng_p1c7ur3_83ecb41c}

すべてのチェッカーを通過し、見事にフラグをゲットできました!

Flag:
picoCTF{71m3_7r4v311ng_p1c7ur3_83ecb41c}


お疲れさまでした!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?