書籍
書籍検索
新刊 送料無料

エンジニア入門シリーズ

ゼロからマスター!
Colab×Pythonで
バイナリファイル解析実践ガイド

監修: 大塚 玲
著: 大坪 雄平 /萬谷 暢崇 /羽田 大樹 /染谷 実奈美
定価: 4,400円(本体4,000円+税)
判型: B5変型
ページ数: 416 ページ
ISBN: 978-4-910558-35-6
発売日: 2024/10/17
管理No: 133

【目次】

第1章 バイナリ解析に向けた準備運動

  1. 1.1 Pythonである理由
    1. 1.1.1 シンプルで読みやすいコード
    2. 1.1.2 豊富なライブラリ
    3. 1.1.3 オープンソースで活発なコミュニティ
  2. 1.2 プログラミング環境構築
    1. 1.2.1 Colabの特徴
    2. 1.2.2 Googleドライブ上にNotebookを作成する
    3. 1.2.3 プログラミング環境の設定変更と確認
    4. 1.2.4 セルにコードを入力して実行する
    5. 1.2.5 Colab Notebookの機能
  3. 1.3 Pythonの基本
    1. 1.3.1 Pythonの演算処理
    2. 1.3.2 変数と主なデータ型
    3. 1.3.3 コメント
    4. 1.3.4 コレクション
    5. 1.3.5 制御フロー
    6. 1.3.6 関数
  4. 1.4 Pythonでバイナリを扱う準備
    1. 1.4.1 整数の表記法
    2. 1.4.2 整数型から2進数、8進数、16進数表記の文字列型への変換
    3. 1.4.3 2進数、8進数、16進数表記の文字列型から整数型への変換
    4. 1.4.4 Pythonにおける整数型の実装の深堀り
    5. 1.4.5 ビット演算
  5. 1.5 バイナリシーケンス型
    1. 1.5.1 bytesオブジェクト
    2. 1.5.2 bytearrayオブジェクト
    3. 1.5.3 bytesとbytearrayの基本操作
  6. 1.6 各種エンコード
    1. 1.6.1 シーザー暗号
    2. 1.6.2 Base64.
    3. 1.6.3 Deflate.
  7. 1.7 バイナリデータを扱う練習:Base64相互変換関数の自作
  8. コラム:本書からの挑戦状:名刺でCTF

第2章 バイナリファイルの操作

  1. 2.1 バイナリファイルの読み書き
    1. 2.1.1 解析用ファイルの準備
    2. 2.1.2 ファイル操作の基本
    3. 2.1.3 セッションストレージにファイルをアップロード
    4. 2.1.4 Googleドライブ上のファイルの参照
  2. 2.2 ファイル全体の俯瞰
    1. 2.2.1 16進ダンプしてみよう
    2. 2.2.2 練習:stringsを自作してみよう
    3. 2.2.3 ヒストグラムを用いたファイル全体の俯瞰
    4. 2.2.4 情報エントロピーを用いたファイル全体の俯瞰
    5. 2.2.5 画像化によるファイル全体の俯瞰
  3. コラム:バイナリエディタStirlingと目grep

第3章 バイナリファイルの構造解析の練習:画像ファイル

  1. 3.1 バイナリファイルのファイル構造
    1. 3.1.1 ファイル構造の基本要素
  2. 3.2 ファイル形式の判定
    1. 3.2.1 ライブラリを使ったファイル形式の判定
    2. 3.2.2 簡易的なファイル形式判定プログラムの自作
    3. 3.2.3 Magika:AIを使ったファイル形式の判定
  3. 3.3 BMP形式
    1. 3.3.1 解析用BMPファイルの準備
    2. 3.3.2 ライブラリを使った解析
    3. 3.3.3 BMPファイルのフォーマット概要
  4. コラム:コンピューターの性能向上とカラーパレットの衰退
    1. 3.3.4 structモジュールの紹介
  5. コラム:C文字列とPascal文字列:メモリ上の文字列表現
    1. 3.3.5 BMPファイルの情報を表示するプログラムの作成
    2. 3.3.6 応用:BMPファイルを使ったステガノグラフィ
  6. コラム:新技術と研究倫理~ステガノグラフィを例に~
  7. 3.4 PNG形式
    1. 3.4.1 解析用PNGファイルの準備
    2. 3.4.2 ライブラリを使った解析
    3. 3.4.3 PNGファイルの構造
    4. 3.4.4 PNGファイルを分解するプログラムの作成
  8. コラム:GIFの特許問題とPNGの誕生
  9. 3.5 JPEG形式
    1. 3.5.1 解析用JPEGファイルの準備
    2. 3.5.2 ライブラリを使った解析
    3. 3.5.3 JPEGファイルの構造
    4. 3.5.4 JPEGファイルを分解するプログラムの作成
  10. コラム:なぜ便利なライブラリがあるのに自作するのか

第4章 バイナリファイルの構造解析実践編:コンテナファイル(アーカイブ、文書ファイル)

  1. 4.1 zip形式
    1. 4.1.1 解析用zipファイルの準備
    2. 4.1.2 ライブラリを使った解析
    3. 4.1.3 zipファイルフォーマットの構造
    4. 4.1.4 zip展開プログラムの自作
    5. 4.1.5 応用:破損したzipファイルの復元
  2. コラム:解析業務とアジャイル開発
  3. 4.2 PDF形式
    1. 4.2.1 解析用PDFファイルの準備
    2. 4.2.2 ライブラリを使った解析
    3. 4.2.3 PDFの仕様概要
    4. 4.2.4 PDFを解析しながら仕様を学ぶ
  4. コラム:o-checker:ファイルフォーマットに着目したマルウェア検知ツール

第5章 応用編1 バイナリファイル解析の道具箱Binary Refinery

  1. 5.1 Binary Refineryとは
    1. 5.1.1 実行環境のセットアップ
  2. 5.2 Binary Refineryのドキュメントとヘルプ
  3. 5.3 入出力に使う機能
    1. 5.3.1 ファイルの内容の出力
    2. 5.3.2 データに関する情報の出力
    3. 5.3.3 efコマンドの機能を使ったPythonスクリプト
    4. 5.3.4 手入力によるバイナリデータの出力
    5. 5.3.5 emitコマンドの機能を使ったPythonスクリプト
    6. 5.3.6 ファイルへの出力
    7. 5.3.7 dumpコマンドの機能を使ったPythonスクリプト
  4. 5.4 データの表示に使う機能
    1. 5.4.1 ファイルの内容の16進ダンプ表示
    2. 5.4.2 peekコマンドの機能を使ったPythonスクリプト
  5. 5.5 データの切り出しに使う機能
    1. 5.5.1 範囲指定によるデータの切り出し
    2. 5.5.2 データの分割
    3. 5.5.3 snipコマンドとchopコマンドの機能を使ったPythonスクリプト
  6. 5.6 バイナリと数値の変換に使う機能
    1. 5.6.1 16進数からのデコード
    2. 5.6.2 2進数、8進数等のデコード
    3. 5.6.3 packコマンドの機能を使ったPythonスクリプト
  7. 5.7 ビット演算に使う機能
    1. 5.7.1 加算と減算
    2. 5.7.2 addコマンドとsubコマンドの機能を使ったPythonスクリプト
    3. 5.7.3 ビットの反転、ローテート、シフト
    4. 5.7.4 negコマンド等の機能を使ったPythonスクリプト
  8. 5.8 XOR演算関係の機能
    1. 5.8.1 XOR演算
    2. 5.8.2 xorコマンドとrotlコマンドの機能を組み合わせたPythonスクリプト
    3. 5.8.3 XORキーの推定
    4. 5.8.4 xkeyコマンドがXORキーを推定する方法
    5. 5.8.5 XORキー推定による自動デコード
    6. 5.8.6 xkeyコマンドの機能を使ったPythonスクリプト
  9. コラム:xkeyコマンドとautoxorコマンドが役立つ場面
  10. 5.9 デコードとエンコードに使う機能
    1. 5.9.1 Base64デコード
    2. 5.9.2 カスタム文字セットを使ったBase64エンコードとデコード
    3. 5.9.3 バイト列の逆順への並べ替え
    4. 5.9.4 各ブロック内のバイト列の逆順への並べ替え
    5. 5.9.5 シーザー暗号
    6. 5.9.6 URLデコード
    7. 5.9.7 revコマンド等の機能を組み合わせたPythonスクリプト
  11. 5.10 圧縮関係の機能
    1. 5.10.1 zlibで圧縮されたデータの展開
    2. 5.10.2 LZMAで圧縮されたデータの展開
    3. 5.10.3 様々な圧縮アルゴリズムによる圧縮データの自動展開
    4. 5.10.4 decompressコマンドの機能を使ったPythonスクリプト
  12. 5.11 その他の機能
    1. 5.11.1 暗号関係の機能
    2. 5.11.2 ファイルの構造をパースする機能
    3. 5.11.3 ファイルカービングの機能
  13. 5.12 演習:難読化されたPHPスクリプトの解析
    1. 5.12.1 解析対象のPHPスクリプト
    2. 5.12.2 可読化方法の解明
    3. 5.12.3 難読化された部分を可読化するPythonスクリプト
    4. 5.12.4 別解:コマンド実行による可読化
    5. 5.12.5 難読化を行うPHPスクリプト
  14. コラム:Binary Refineryを活用して開発しているバイナリファイル解析ツール

第6章 バイナリファイルの構造解析 実践編:実行ファイル

  1. 6.1 解析用ファイルの準備
  2. 6.2 ELF解析ライブラリ:elftoolsの準備
  3. 6.3 ELFファイルの構造
    1. 6.3.1 ELFヘッダーの構造
    2. 6.3.2 セクションヘッダーの構造
  4. 6.4 最初に実行されるプログラムコードの取得
  5. 6.5 Pythonで逆アセンブル
  6. コラム:パッカーとエントリーポイント
  7. 6.6 アセンブリコードの読み方入門
    1. 6.6.1 (逆)コンパイルと(逆)アセンブル
    2. 6.6.2 アセンブリコードを読む自習の準備
    3. 6.6.3 アセンブリの文法
    4. 6.6.4 スタック
    5. 6.6.5 条件分岐:フラグレジスタとジャンプ命令
    6. 6.6.6 関数
    7. 6.6.7 命令セット

第7章 応用編2 バイナリ解析実践CTF

  1. 7.1 CTFとバイナリ解析
  2. 7.2 x86-64プログラムの解析
    1. 7.2.1 例題1:メモリに展開されたパスワード
    2. 7.2.2 例題2:ソルバーを作成してパスワードを推測
    3. 7.2.3 例題3:ビット演算の難読化
  3. 7.3 Pythonバイトコードの解析
    1. 7.3.1 Pythonバイトコードを解析する方法
    2. 7.3.2 例題4:pycを解析する問題
  4. 7.4 本章のまとめ
  5. コラム:CTF(Capture The Flag)のススメ

第8章 応用編3 機械学習を用いたバイナリ解析~マルウェアの種類推定を例に~

  1. 8.1 マルウェアとは
  2. 8.2 機械学習とは
  3. 8.3 マルウェア解析と機械学習
    1. 8.3.1 マルウェア解析
    2. 8.3.2 機械学習によるマルウェア解析
  4. 8.4 特徴量の作成
  5. 8.5 グラフニューラルネットワークを使用したマルウェア分類
    1. 8.5.1 グラフニューラルネットワーク
    2. 8.5.2 データセットの確認
    3. 8.5.3 学習と評価
  6. 8.6 独自のデータセットを作成する方法
    1. 8.6.1 仮想環境とは
    2. 8.6.2 マルウェアを扱う際の注意点
    3. 8.6.3 VirtualBoxのインストール
    4. 8.6.4 仮想マシンの準備
    5. 8.6.5 データセットの作成
    6. 8.6.6 データセットの取り出し
    7. 8.6.7 仮想マシンをクリーンな環境に戻す
  7. 8.7 機械学習を用いたマルウェア分類における課題と展望
  8. 8.8 まとめ
  9. コラム:様々なサイバーセキュリティ分野の学術会議
  10. おわりに

付録

  1. 付録A Pythonのバイナリデータ操作のチートシート
  2. 付録B 各数値表記とASCIIの対応表
  3. 付録C Colab以外の環境で使用できる便利なバイナリファイル解析ツール達

【参考文献】

  • 高田寛、“プログラムのリバースエンジニアリングの法的課題” 企業法学研究2020 第9 巻2 号(2020)(https://www.jabl.org/kigyouhougakukenkyuu2020Vo.9No.2_Takada.pdf)
  • https://jupyter.org/
  • https://colab.research.google.com/
  • https://drive.google.com/
  • https://docs.python.org/ja/3/library/stdtypes.html#common-sequence-operations
  • https://docs.python.org/ja/3/reference/lexical_analysis.html#f-strings
  • https://docs.python.org/ja/3/library/functions.html#int
  • https://docs.python.org/ja/3/library/stdtypes.html#bytes
  • https://docs.python.org/ja/3/library/stdtypes.html#bytearray
  • https://docs.python.org/ja/3/library/stdtypes.html#bytes-methods
  • https://docs.python.org/ja/3/library/codecs.html#standard-encodings
  • https://docs.python.org/ja/3/library/codecs.html
  • https://datatracker.ietf.org/doc/html/rfc1421
  • https://datatracker.ietf.org/doc/html/rfc1950
  • https://datatracker.ietf.org/doc/html/rfc1952
  • https://datatracker.ietf.org/doc/html/rfc1951
  • MIL-STD-188-100, Military Standard: Common Long Haul Tactical Communication System Technical Standards, 1972
  • Shannon, Claude Elwood. "A mathematical theory of communication." The Bell system technical journal 27.3 (1948): 379-423.
  • https://numpy.org/doc/stable/user/basics.types.html
  • https://numpy.org/doc/stable/user/basics.creation.html
  • https://www.vector.co.jp/soft/win95/util/se079072.html
  • https://github.com/yotsubo/o-glasses
  • https://github.com/yotsubo/o-glassesX
  • https://github.com/yotsubo/o-glasses2023
  • https://github.com/ahupp/python-magic
  • https://www.darwinsys.com/file/
  • https://en.m.wikipedia.org/wiki/List_of_file_signatures
  • https://opensource.googleblog.com/2024/02/magika-ai-powered-fast-and-efficient-file-typeidentification.html
  • https://github.com/google/magika
  • https://google.github.io/magika/
  • https://docs.python.org/ja/3/library/pathlib.html
  • https://python-pillow.org/
  • https://www.colordic.org/s
  • https://docs.python.org/ja/3/library/struct.html
  • https://opencv.org/
  • https://scikit-image.org/
  • https://pypi.org/project/pypng/
  • http://www.libpng.org/pub/png/spec/1.2/png-1.2.pdf
  • PNG Signature: http://www.libpng.org/pub/png/book/chapter08.html
  • https://docs.python.org/ja/3/library/zlib.html
  • https://pillow.readthedocs.io/en/stable/_modules/PIL/PngImagePlugin.html
  • (再掲)http://www.libpng.org/pub/png/spec/1.2/png-1.2.pdf
  • https://ftp-osl.osuosl.org/pub/libpng/documents/pngext-1.5.0.html
  • http://www.libpng.org/pub/png/#history
  • https://developers.google.com/speed/webp?hl=ja
  • https://aomediacodec.github.io/av1-avif/
  • https://docs.python.org/3/library/zipfile.html
  • https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT など
  • https://pypi.org/project/pypdf/
  • https://pypdf.readthedocs.io/en/stable/index.html
  • https://pypi.org/project/pdfminer.six/
  • https://pypi.org/project/pdfminer/
  • https://pdfminersix.readthedocs.io/en/latest/faq.html#why-are-there-cid-x-values-in-the-textual-output
  • https://pdfminersix.readthedocs.io/en/latest/index.html
  • https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf
  • https://github.com/binref/refinery
  • https://github.com/binref/refinery/tree/master/tutorials
  • https://gchq.github.io/CyberChef/
  • https://git-scm.com/
  • https://binref.github.io/
  • https://datatracker.ietf.org/doc/html/rfc1321
  • https://datatracker.ietf.org/doc/html/rfc3174
  • https://datatracker.ietf.org/doc/html/rfc6234
  • https://docs.python.org/ja/3/library/argparse.html
  • https://docs.python.org/ja/3/howto/functional.html#generators
  • https://docs.python.org/ja/3/tutorial/controlflow.html#pass-statements
  • https://docs.python.org/ja/3/tutorial/errors.html
  • https://docs.python.org/ja/3/library/argparse.html#mutual-exclusion
  • 三村守, 大坪雄平, 田中英彦. "悪性文書ファイルに埋め込まれたRAT の検知手法." 情報処理学会論文誌55.2(2014): 1089-1099. https://lab.iisec.ac.jp/~tanaka_lab/images/pdf/journal/journal-2014-01.pdf
  • https://datatracker.ietf.org/doc/html/rfc4648
  • https://datatracker.ietf.org/doc/html/rfc4648#section-6
  • https://www.dcode.fr/base92-encoding#q1
  • https://datatracker.ietf.org/doc/html/rfc4648#section-5
  • https://docs.python.org/ja/3/library/urllib.parse.html#url-quoting
  • https://datatracker.ietf.org/doc/html/rfc1950
  • https://datatracker.ietf.org/doc/html/rfc1952
  • https://tukaani.org/xz/xz-file-format.txt
  • https://www.7-zip.org/sdk.html
  • https://www.sourceware.org/bzip2/
  • https://www.php.net/manual/ja/function.str-rot13
  • https://www.php.net/manual/ja/function.strrev
  • https://www.php.net/manual/ja/function.base64-decode
  • https://www.php.net/manual/ja/function.gzinflate
  • https://www.php.net/manual/ja/function.eval
  • https://www.php.net/manual/ja/function.strcmp
  • https://www.php.net/manual/ja/language.types.string.php#language.types.string.syntax.heredoc
  • https://downloadcenter.trellix.com/products/mcafee-avert/fileinsight.msi
  • https://github.com/nmantani/FileInsight-plugins/blob/master/README.ja.md
  • https://codeblue.jp/2019/bluebox/FileInsight-plugins/
  • https://www.blackhat.com/us-21/arsenal/schedule/
  • https://github.com/binref/refinery/issues/24
  • https://github.com/binref/refinery/pull/25
  • https://github.com/binref/refinery/issues/46
  • https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
  • https://www.capstone-engine.org/lang_python.html
  • https://github.com/lattera/glibc/blob/master/sysdeps/x86_64/start.S
  • Isawa, Ryoichi, et al. "An accurate packer identification method using support vector machine." IEICE Transactions on Fundamentals of Electronics, Communications and Computer Sciences 97.1 (2014): 253-263.
  • 大坪雄平, 大塚玲, 岩田吉弘, 三村守, 榊剛史. "転移学習による機械語命令列分類における学習の効率化." 人工知能学会全国大会論文集第33 回(2019). 一般社団法人人工知能学会, 2019.
  • https://en.wikipedia.org/wiki/X86_calling_conventions
  • https://gitlab.com/x86-psABIs/x86-64-ABI/-/jobs/artifacts/master/raw/x86-64-ABI/abi.pdf?job=build
  • https://rada.re/
  • https://docs.python.org/ja/3/library/dis.html
  • https://docs.python.org/ja/3/library/marshal.html
  • https://ctftime.org/
  • https://github.com/sajjadium/ctf-archives
  • https://policies.google.com/terms
  • https://github.com/elastic/ember
  • https://lief.re
  • Nataraj, Lakshmanan, et al. "Malware images: visualization and automatic classification." Proceedings of the 8th international symposium on visualization for cyber security. 2011.
  • Raff, Edward, et al. "Malware detection by eating a whole exe." Workshops at the thirty-second AAAI conference on artificial intelligence. 2018.
  • Minami Someya, Yuhei Otsubo, and Akira Otsuka. "FCGAT: Interpretable malware classification method using function call graph and attention mechanism." Proc. Netw. Distrib. Syst. Secur.(NDSS) Symp.2023.
  • CBOW: Mikolov, Tomas et al. “Efficient Estimation of Word Representations in Vector Space.” International Conference on Learning Representations (2013).
  • skip-gram: Mikolov, Tomas et al. “Distributed Representations of Words and Phrases and their Compositionality.” Neural Information Processing Systems (2013).
  • https://rada.re/
  • https://radimrehurek.com/gensim
  • https://scikit-learn.org/stable/
  • Scarselli, F, et al. (2008). The graph neural network model. IEEE transactions on neural networks, 20(1), 61-80.
  • 35 P. Veličković, et al."Graph Attention Networks"6th International Conference on Learning Representations.2017.
  • https://pytorch.org
  • https://yutaroogawa.github.io/pytorch_tutorials_jp
  • https://github.com/pyg-team/pytorch_geometric
  • https://whyisyoung.github.io/BODMAS
  • https://docs.python.org/ja/3/library/pickle.html
  • https://seaborn.pydata.org/
  • https://www.virtualbox.org/
  • https://www.vmware.com/products/workstation-pro/html.html
  • https://learn.microsoft.com/ja-jp/virtualization/hyper-v-on-windows/about/
  • https://www.oracle.com/jp/virtualization/technologies/vm/downloads/virtualbox-downloads.html
  • https://releases.ubuntu.com/jammy/
  • https://docs.python.org/ja/3/library/functions.html#repr
  • https://docs.python.org/ja/3/library/functions.html#eval

【口コミ】

  • ※口コミはありません。
ページトップへ戻る