48
Microsoft Malware Classification Challenge 上位手法の紹介 佐野 正太郎

Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

Embed Size (px)

Citation preview

Page 1: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

Microsoft Malware Classification Challenge 上位手法の紹介

佐野 正太郎

Page 2: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

アジェンダ

コンペ概要

ベースラインアプローチ

ワードカウント & ランダムフォレスト

上位手法の紹介

特徴抽出

特徴変換

分類器

優勝チームのモデル

Page 3: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

コンペ概要

Page 4: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

コンペ概要

タスク:マルウェアの分類

入力:ヘキサダンプと逆アセンブリファイル

ヘキサダンプ

(.bytes)

逆アセンブリ

(.asm)

Page 5: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

コンペ概要

.bytes

Your

Model

Malware

Class

Probabilities

.asm

Page 6: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

コンペ概要

.bytes

Your

Model

Malware

Class

Probabilities

.asm

10,868 training samples

1,000 GB in total

9 classes

10,873 test samples

Page 7: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

コンペ概要

クラス毎の確率を各サンプルに対して出力

モデル評価:Log Loss

1

0

1

0

,,log log1 N

i

K

k

kiki pyN

L

Page 8: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

ベースラインアプローチ

Page 9: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

ベースラインアプローチ

Beat the benchmark (~0.182) with RandomForest [4]

ヘキサダンプからワードカウント特徴量抽出

1バイト=1単語

そのままランダムフォレストに投げる

.bytes Random

Forest

Classifier

1-byte

Word

Count

Malware

Classes

Probabilities

Page 10: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

ベースラインアプローチ

コンペ初期からフォーラムに登場

It was a surprise that one can achieve the accuracy of

0.96 just by using counts of ‘00’ and, ‘FF’, and ‘??’. [3]

Page 11: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

特徴抽出

Page 12: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

上位勢の特徴抽出

ヘキサダンプからのワードカウント

逆アセンブリからのワードカウント

ハイブリッドワードカウント

ファイルのメタデータ

テクスチャ画像

Page 13: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

ヘキサダンプからのワードカウント

1バイトを1単語として扱う

Nグラムモデルで性能が向上

優勝チームのモデルでは4グラムまで取得

1ラインを1単語とする方法も [2]

Page 14: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

逆アセンブリからのワードカウント

ヘッダ ヘキサダンプコード アセンブリコード

Page 15: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

逆アセンブリからのワードカウント

ヘッダ ヘキサダンプコード アセンブリコード

インストラクションの カウントをとる

Page 16: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

逆アセンブリからのワードカウント

ヘッダ ヘキサダンプコード アセンブリコード

セグメント名の カウントをとる

Page 17: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

逆アセンブリからのワードカウント

DLL関数のインポート情報を特徴量化

Page 18: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

ハイブリッド特徴量

DAF (Derived Assembly Features) 特徴量 [6]

(1) ヘキサダンプからNグラム特徴量抽出

(2) (1)を情報ゲインで絞り込み

(3) (2)と共起するアセンブリインストラクションを抽出

(4) (3)を情報ゲインで絞り込み

ヘキサダンプ特徴が 重要な場合のみ

インストラクションを 特徴としてカウント

Page 19: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

ファイルのメタデータ

ヘキサダンプファイルのサイズ

逆アセンブリファイルのサイズ

ヘキサンダンプファイルの圧縮レート

逆アセンブリファイルの圧縮レート

etc.

Page 20: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

テクスチャ画像

ヘキサダンプをグレースケール画像に変換

1バイト=1画素値

適当な画像特徴量を抽出

元論文ではGIST特徴量を使用[7]

Page 21: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)
Page 22: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

((((((( ;゚д゚)))))))

Page 23: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

特徴変換

Page 24: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

上位勢の特徴変換

TF-IDF

情報ゲイン

非負値行列因子分解

ランダムフォレスト

Page 25: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

TF-IDF

単語頻度をドキュメント長で正規化

小数のドキュメントにしか出現しない単語を強調

idftftfidf *

docword

worddocdocword

docwordtf

'

,}in ' {#

}in {#

} including docs {#

docs} all {#log

wordidfword

Page 26: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

情報ゲイン

ある特徴を既知とした場合のエントロピーの差分

計算の簡単化

単語の頻度 => 出現したかどうかの二項値

クラス毎に独立して特徴を選択

)|()()( xYHYHxGain

))(log)(log(

)log()(log)(

22

}1,0{

2

v

v

v

v

v

v

v

v

v

v

t

n

t

n

t

p

t

p

t

t

t

n

t

n

t

p

t

pxGain

ポジティブサンプル数 ネガティブサンプル数

トータルサンプル数

対象特徴を固定した場合のサンプル数

Page 27: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

非負値行列因子分解

Nグラムワードカウントは多次元な非負値行列

非負値の特性を保ったまま次元圧縮

非負値行列を非負値行列の積に分解

下の例では5次元から2次元に圧縮

20011

01210

13

00

21

01

23641

00000

41232

01210

Page 28: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

ランダムフォレスト

分類器ではなく特徴選択手法として利用

学習後にFeature Importanceの低い特徴を捨てる

Page 29: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

分類器

Page 30: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

XGBoost

高速・多機能な勾配ブースティングの実装

アンサンブル木学習 + 勾配法

勾配法の要領で逐次的に弱い木を学習

))(,()()( 1

1

1 xFyLxFxF ti

n

i

Fttt

前ステップまでに 学習したフォレスト

次ステップの木は 前ステップの負勾配にフィット

Page 31: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

Averaging

複数モデル出力の単純平均をサブミットする 幾何平均で性能が向上することも

Averaging multiple different green lines should bring us closer to the black line. [5]

Page 32: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

Stacking

複数モデルの出力を統合するモデルを学習

XGBoost Neural

Network XGBoost

Nearest

Neighbors

XGBoost Random

Forest

Extra

Tree

Averaging

Page 33: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

まとめ

ワードカウントベースの 特徴抽出

情報量ゲインや行列分解による特徴数のバランシング

ファイルの メタ情報

テクスチャ 画像

XGBoost

Averaging or Stacking

Page 34: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

優勝チームのモデル

Page 35: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

Opcode

2-gram

Opcode

3-gram

Opcode

4-gram

Header

1-gram

Hexdump

4-gram

&

Info Grain

DAF

1-gram

DLL

1-gram

Random

Forest

XGBoost

Assembly

Texture

Image

Instruction

1-gram

Hexdump

1-gram

Random

Forest

Semi-supervised Learning with Test Dataset

Averaging

Page 36: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

Opcode

2-gram

Opcode

3-gram

Opcode

4-gram

Header

1-gram

Hexdump

4-gram

&

Info Grain

DAF

1-gram

DLL

1-gram

Random

Forest

XGBoost

Assembly

Texture

Image

Instruction

1-gram

Hexdump

1-gram

Random

Forest

Semi-supervised Learning with Test Dataset

Averaging

Page 37: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

逆アセンブリによるテクスチャ画像

逆アセンブリファイルのバイト列をテクスチャ化

先頭1000ピクセルの画素値を特徴量とする

ヘキサダンプ テクスチャ

逆アセンブリ テクスチャ

Page 38: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

テストデータを含めた半教師あり学習

トレーニングデータでモデル学習(中間モデル)

中間モデルで全テストデータをラベル付け

ラベル付きテストデータを複数のチャンクに分割

各チャンクに対し:

対象チャンク以外のトレーニングデータとラベル付き テストデータで最終モデルを学習

最終モデルで対象チャンクのクラス確率を予測

各チャンクの結果を統合

Page 39: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

Opcode

2-gram

Opcode

3-gram

Opcode

4-gram

Header

1-gram

Hexdump

4-gram

&

Info Grain

DAF

1-gram

DLL

1-gram

Random

Forest

XGBoost

Assembly

Texture

Image

Instruction

1-gram

Hexdump

1-gram

Random

Forest

Semi-supervised Learning with Test Dataset

Averaging

Page 40: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

Opcode

2-gram

Opcode

3-gram

Opcode

4-gram

Segment

1-gram

Hexdump

4-gram

&

Info Grain

DAF

1-gram

DLL

1-gram

Random

Forest

XGBoost

Assembly

Texture

Image

Instruction

1-gram

Hexdump

1-gram

Random

Forest

Semi-supervised Learning with Test Dataset

Averaging

Golden Features

Page 41: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

どの特徴が効いていたか?

0

0.002

0.004

0.006

0.008

0.01

0.012

0.014

0.016

Opcode-count Opcode Count Segment Count

Opcode Count Segment Count ASM Texture

All Features

Cross Validation

Public Leaderboard

Private Leaderboard

Lo

g-l

oss

Page 42: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

Private Leaderboard

Page 43: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

Private Leaderboard

Public Leaderboard

Page 44: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)
Page 45: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

Thank you!

Page 46: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

リファレンス

1. First place code and documents

https://www.kaggle.com/c/malware-

classification/forums/t/13897/first-place-code-and-documents

2. 2nd place code and documentation

https://www.kaggle.com/c/malware-

classification/forums/t/13863/2nd-place-code-and-documentation

3. 3rd place code and documentation

https://www.kaggle.com/c/malware-

classification/forums/t/14065/3rd-place-code-and-documentation

Page 47: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

リファレンス

4. Beat the benchmark (~0.182) with RandomForest

https://www.kaggle.com/c/malware-classification/forums/t/12490/beat-

the-benchmark-0-182-with-randomforest

5. Kaggle Ensembling Guide

http://mlwave.com/kaggle-ensembling-guide

Page 48: Microsoft Malware Classification Challenge 上位手法の紹介 (in Kaggle Study Meetup)

リファレンス

6. Masud, M. M., Khan, L., and Thuraisingham, B., “A

Scalable Multi-level Feature Extraction Technique to

Detect Malicious Executables,” Information Systems

Frontiers, Vol. 10, No. 1, pp. 33-45, (2008).

7. Nataraj, L., Yegneswaran, V., Porras, P. and Zhang, J. “A

Comparative Assessment of Malware Classification Using

Binary Texture Analysis and Dynamic Analysis,”

Proceedings of the 4th ACM Workshop on Security and

Artificial Intelligence, 21-30 (2011).