UJP - 技術情報1

Life is fun and easy!

不正IP報告数

Okan Sensor
 
メイン
ログイン
ブログ カテゴリ一覧

CTF Sandstormというステガノグラフィ問題をmacOS上でやってみた

CTF Sandstormというステガノグラフィ問題をmacOS上でやってみた


概要

更新履歴

  • 2024/02/20 初版

目次

はじめに

 このドキュメントはSECCON 2019で出題されたMiscジャンルのSandstormという問題で,ステガノグラフィに隠された情報を抽出する問題を解く解説を見ながらやってみた手順.
 ツールとしてはexiftool,pnmtopngやzbarimgを使っている.
 なお,環境としてはmacOS上でおこなっている.

問題ファイルを確認

問題ファイルを入手

  • githubに登録されているのでcloneする.

bash-5.2$ git clone https://github.com/SECCON/SECCON2019_online_CTF🆑
Cloning into 'SECCON2019_online_CTF'...
remote: Enumerating objects: 504, done.
remote: Counting objects: 100% (504/504), done.
remote: Compressing objects: 100% (399/399), done.
remote: Total 504 (delta 35), reused 504 (delta 35), pack-reused 0
Receiving objects: 100% (504/504), 15.92 MiB | 2.42 MiB/s, done.
Resolving deltas: 100% (35/35), done.
bash-5.2$

  • 問題ファイルを確認.

bash-5.2$ cd SECCON2019_online_CTF/🆑
bash-5.2$ ls -la🆑
total 4
drwxr-xr-x 10 ujpadmin staff  320  2 19 16:17 .
drwxr-xr-x 50 ujpadmin staff 1600  2 19 16:17 ..
drwxr-xr-x 12 ujpadmin staff  384  2 19 16:17 .git
-rw-r--r--  1 ujpadmin staff  667  2 19 16:17 README.md
drwxr-xr-x  5 ujpadmin staff  160  2 19 16:17 crypto
drwxr-xr-x  3 ujpadmin staff   96  2 19 16:17 fonrensics
drwxr-xr-x  6 ujpadmin staff  192  2 19 16:17 misc🈁
drwxr-xr-x  8 ujpadmin staff  256  2 19 16:17 pwn
drwxr-xr-x  7 ujpadmin staff  224  2 19 16:17 reversing
drwxr-xr-x  8 ujpadmin staff  256  2 19 16:17 web
bash-5.2$ cd misc🆑
bash-5.2$ ls -la🆑
total 0
drwxr-xr-x  6 ujpadmin staff 192  2 19 16:17 .
drwxr-xr-x 10 ujpadmin staff 320  2 19 16:17 ..
drwxr-xr-x  6 ujpadmin staff 192  2 19 16:17 Beeeeeeeeeer
drwxr-xr-x  7 ujpadmin staff 224  2 19 16:17 pngbomb
drwxr-xr-x  7 ujpadmin staff 224  2 19 16:17 sandstorm🈁
drwxr-xr-x  7 ujpadmin staff 224  2 19 16:17 tanuki
bash-5.2$ cd sandstorm/🆑
bash-5.2$ ls -la🆑
total 12
drwxr-xr-x 7 ujpadmin staff 224  2 19 16:17 .
drwxr-xr-x 6 ujpadmin staff 192  2 19 16:17 ..
-rw-r--r-- 1 ujpadmin staff  24  2 19 16:17 FLAG
-rw-r--r-- 1 ujpadmin staff 836  2 19 16:17 README.md
drwxr-xr-x 3 ujpadmin staff  96  2 19 16:17 files🈁
drwxr-xr-x 8 ujpadmin staff 256  2 19 16:17 solver
-rw-r--r-- 1 ujpadmin staff 632  2 19 16:17 writeup.md
bash-5.2$ cd files/🆑
bash-5.2$ ls -la🆑
total 64
drwxr-xr-x 3 ujpadmin staff    96  2 19 16:17 .
drwxr-xr-x 7 ujpadmin staff   224  2 19 16:17 ..
-rw-r--r-- 1 ujpadmin staff 63515  2 19 16:17 sandstorm.png🈁
bash-5.2$

  • ファイルの確認

bash-5.2$ file sandstorm.png🆑
sandstorm.png: PNG image data, 584 x 328, 8-bit/color RGBA, interlaced
bash-5.2$

  • PNGファイルだと確認できた.
  • ファイルを開いてみたらこんな感じ.


画像の情報を調べる

exiftoolを使って画像ファイルの詳細を確認

  • スマホなどのデジカメで写真を撮ると画像に撮影カメラや画像圧縮方法などのテキスト情報がEXIF情報として記録される.
  • exiftoolはその情報を表示するコマンドラインツール.
  • 多分,以前インストールしたので今回は入っている前提.

bash-5.2$ exiftool sandstorm.png🆑
ExifTool Version Number         : 12.76
File Name                       : sandstorm.png
Directory                       : .
File Size                       : 64 kB
File Modification Date/Time     : 2024:02:19 16:17:21+09:00
File Access Date/Time           : 2024:02:19 16:20:13+09:00
File Inode Change Date/Time     : 2024:02:19 16:20:11+09:00
File Permissions                : -rw-r--r--
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 584
Image Height                    : 328
Bit Depth                       : 8
Color Type                      : RGB with Alpha
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Adam7 Interlace🈁
Background Color                : 255 255 255
Image Size                      : 584x328
Megapixels                      : 0.192
bash-5.2$

  • この情報でわかるのはPNG形式ファイルで,インターレース.
  • インターレース方式がAdam7がヒントだとのこと.

正解を導き出すsolverコマンドをビルド

  • ダウンロードした問題の中には回答を導き出すツールが入っている.
  • ソースコードなのでビルドする.

bash-5.2$ cd ../🆑
bash-5.2$ cd solver🆑
bash-5.2$ ls -la🆑
total 272
drwxr-xr-x 8 ujpadmin staff    256  2 19 17:42 .
drwxr-xr-x 8 ujpadmin staff    256  2 19 16:25 ..
-rw-r--r-- 1 ujpadmin staff    278  2 19 16:17 Makefile🈁
-rw-r--r-- 1 ujpadmin staff 231033  2 19 16:17 miniz.c
-rw-r--r-- 1 ujpadmin staff     50  2 19 16:17 miniz.h
-rw-r--r-- 1 ujpadmin staff  27002  2 19 16:17 pngle.c
-rw-r--r-- 1 ujpadmin staff   2914  2 19 16:17 pngle.h
-rw-r--r-- 1 ujpadmin staff   2061  2 19 16:17 solver.c
bash-5.2$

  • Makefileを確認.

bash-5.2$ cat Makefile🆑
CFLAGS+=-Os -Wall

all: solve

solver: solver.c pngle.c miniz.c miniz.h Makefile
    $(CC) $(CFLAGS) -o solver solver.c pngle.c miniz.c -lm

solve: flag.png
    zbarimg flag.png

flag.png: solver
    ./solver < ../files/sandstorm.png | pnmtopng > flag.png🈁

clean:
    rm -f solver flag.png
bash-5.2$

  • ここでは,次にような記載がある.
  • make solverとするとC言語プログラムをコンパイルする.
  • make solveとすると,zbarmingコマンドでバーコード画像を認識させている
  • make flag.pngとすると,問題ファイルをsolverコマンドに読み込ませ,その出力結果をptmtopngコマンドで受け取り,flag.pngファイルを作る方法の記載
  • まずはコンパイルだけするのでmake solverを実行する.

bash-5.2$ make solver🆑
cc -Os -Wall -o solver solver.c pngle.c miniz.c -lm
bash-5.2$ ls -la🆑
total 340
drwxr-xr-x 9 ujpadmin staff    288  2 19 17:52 .
drwxr-xr-x 8 ujpadmin staff    256  2 19 16:25 ..
-rw-r--r-- 1 ujpadmin staff    278  2 19 16:17 Makefile
-rw-r--r-- 1 ujpadmin staff 231033  2 19 16:17 miniz.c
-rw-r--r-- 1 ujpadmin staff     50  2 19 16:17 miniz.h
-rw-r--r-- 1 ujpadmin staff  27002  2 19 16:17 pngle.c
-rw-r--r-- 1 ujpadmin staff   2914  2 19 16:17 pngle.h
-rwxr-xr-x 1 ujpadmin staff  68856  2 19 17:52 solver🈁
-rw-r--r-- 1 ujpadmin staff   2061  2 19 16:17 solver.c
bash-5.2$

  • コマンドが作成できたのでMakefileに書いてある方法で分析を実行.

bash-5.2$ ./solver < ../files/sandstorm.png | pnmtopng > flag.png🆑
bash: pnmtopng: コマンドが見つかりません
bash-5.2$

  • pnmtopngコマンドが無い.

pnmtopngをインストール

  • pnmtopngはNetpbmという画像を扱うプログラムとライブラリのパッケージに含まれている.
  • 今回はHomeBrewを使ってインストールする.
  • まずはパッケージの調査.
$ brew info netpbm🆑
==> netpbm: stable 11.02.07 (bottled), HEAD
Image manipulation
https://netpbm.sourceforge.net/
Conflicts with:
  jbigkit (because both install `pbm.5` and `pgm.5` files)
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/n/netpbm.rb
License: GPL-3.0-or-later
==> Dependencies
Build: subversion ✘
Required: jasper ✔, jpeg-turbo ✔, libpng ✘, libtiff ✔
==> Options
--HEAD
    Install HEAD version
==> Analytics
install: 26,532 (30 days), 113,247 (90 days), 412,620 (365 days)
install-on-request: 12,762 (30 days), 51,303 (90 days), 183,562 (365 days)
build-error: 1 (30 days)
$

  • インストールの実行.
$ brew install netpbm🆑
==> Downloading https://ghcr.io/v2/homebrew/core/netpbm/manifests/11.02.07
############################################################################## 100.0%
==> Fetching netpbm
==> Downloading https://ghcr.io/v2/homebrew/core/netpbm/blobs/sha256:2e09b7a6e6918d9996116da7208c96c1f0cfffa9ddc13af9b5666ca4a80ae7a9
############################################################################## 100.0%
==> Pouring netpbm--11.02.07.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/netpbm/11.02.07: 416 files, 17.7MB
==> Running `brew cleanup netpbm`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
$

  • インストールされた中から,今回利用するpnmtopngコマンドを確認.
$ which pnmtopng🆑
/usr/local/bin/pnmtopng
$ pnmtopng --version🆑
pnmtopng: Using libnetpbm from Netpbm Version: Netpbm 11.2.7
pnmtopng: Built from source dated 2023-12-27 04:11:15
pnmtopng: Built by brew
pnmtopng: BSD defined
pnmtopng: RGB_ENV='RGBDEF'
pnmtopng: RGBENV= 'RGBDEF' (env vbl is unset)
$

  • pnmtopngがインストールできた.

solverコマンドで再度回答になるファイルを作成

  • solverコマンドを再度を実行
bash-5.2$ ./solver < ../files/sandstorm.png | pnmtopng > flag.png 🆑
bash-5.2$ ls -la flag.png🆑
-rw-r--r-- 1 ujpadmin staff 1620  2 19 18:04 flag.png
bash-5.2$ open flag.png🆑
bash-5.2$

  • ファイルが作成されたので,openコマンドでファイルを開いてみる.
  • 次のような画像が表示された.



zbarimgをインストールしてコマンドラインでQRコードを読みとる

  • Makefileにはzbarmingコマンドを使えとあったので,macOSで確認.

bash-5.2$ zbarimg🆑
bash: zbarimg: コマンドが見つかりません
bash-5.2$

  • そんなコマンドはない.
  • HomeBrewでパッケージを検索.

$ brew search zbarimg🆑
==> Formulae
zbar
$

  • 似たような名前のものが見つかったので調べる.

$ brew info zbar🆑
==> zbar: stable 0.23.93 (bottled), HEAD
Suite of barcodes-reading tools
https://github.com/mchehab/zbar
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/z/zbar.rb
License: LGPL-2.1-only
==> Dependencies
Build: pkg-config ✔, xmlto ✔
Required: imagemagick ✘, jpeg-turbo ✔
==> Options
--HEAD
    Install HEAD version
==> Analytics
install: 2,399 (30 days), 6,095 (90 days), 16,926 (365 days)
install-on-request: 2,148 (30 days), 5,244 (90 days), 14,150 (365 days)
build-error: 1 (30 days)
$

  • 機能がバーコードリーダーとあるので,これを使うこととする.

$ brew install zbar
==> Downloading https://formulae.brew.sh/api/formula.jws.json
############################################################ 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
############################################################ 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/zbar/manifests/0.23.93
############################################################ 100.0%
==> Fetching zbar
==> Downloading https://ghcr.io/v2/homebrew/core/zbar/blobs/sha256:b262f392f862ff8f4
ba5808c70f77f2b857a95f392e8d2bad9e0c670b329e519
############################################################ 100.0%
==> Pouring zbar--0.23.93.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/zbar/0.23.93: 33 files, 832.8KB
==> Running `brew cleanup zbar`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
$

  • コマンドを確認.
$ which zbar🆑
$

  • 無かった.
  • インストールディレクトリを確認

$ ls -la /usr/local/Cellar/zbar/0.23.93/bin🆑
total 72
drwxr-xr-x  3 ujpadmin admin    96  1  9 18:15 .
drwxr-xr-x 14 ujpadmin admin   448  2 20 01:34 ..
-r-xr-xr-x  1 ujpadmin admin 70448  2 20 01:34 zbarimg🈁
$

  • コマンドを確認.
bash-5.2$ zbarimg --version🆑
0.23.93
bash-5.2$ zbarimg -h🆑
usage: zbarimg [options] <image>...

scan and decode bar codes from one or more image files

options:
    -h, --help      display this help text
    --version       display version information and exit
    --polygon       output points delimiting code zone with decoded symbol data
    -q, --quiet     minimal output, only print decoded symbol data
    -v, --verbose   increase debug output level
    --verbose=N     set specific debug output level
    -d, --display   enable display of following images to the screen
    -D, --nodisplay disable display of following images (default)
    --xml, --noxml  enable/disable XML output format
    --raw           output decoded symbol data without converting charsets
    -1, --oneshot   exit after scanning one bar code
    -S<CONFIG>[=<VALUE>], --set <CONFIG>[=<VALUE>]
                    set decoder/scanner <CONFIG> to <VALUE> (or 1)

bash-5.2$

  • zbarimgコマンドでQRコード画像のファイルを読み出してみる.
bash-5.2$ zbarimg flag.png
QR-Code:SECCON{p0nlMpzlCQ5AHol6}

scanned 1 barcode symbols from 1 images in 0.02 seconds

bash-5.2$

  • FLAGが取り出せた.

振り返りと解説writeup?

  • 問題として渡されたPNGファイルは,Adam7という方式を使ったインターレス形式で作成されている.
  • インターレス形式は,昔インターネット回線が遅い時代,待ち時間も楽しめるように画像が徐々に表示されるように作られた形式.
  • ブロックを飛ばしながらデータが格納されていて,Adam7は7枚の画像を組み合わせて最終的に読み出した時の1つの画像になるように定義されたファイル.
  • 今回の問題では,その7枚の画像の1枚目にQRコードが入った画像があったので,solverコマンドでそれを抽出して保存.
  • 今回はほぼ解答を抽出するsolverコマンドが用意されていたから解答を導き出すための手順を確認しただけで,実際には画像の形式から推測し,画像ファイルを分解するプログラムを作成する能力が必要になるので,難易度は高い.

広告スペース
Google