malware classification and traceability

57
Some things about classification and traceability of Malware (關於惡意程式分類與溯源的二三事) Canaan Kao [email protected] [email protected] 2015/08/19 Some things about Malware Classification 1

Upload: canaan-kao

Post on 15-Jan-2017

742 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Malware classification and traceability

Some things about classification and traceability of Malware

(關於惡意程式分類與溯源的二三事)

Canaan Kao

[email protected]

[email protected]

2015/08/19 Some things about Malware Classification 1

Page 2: Malware classification and traceability

Who am I? • 在一家做 IDS/IPS 的公司,寫了十幾年的 code,後來不小心成為 Anti-Virus 廠商的員工。

• 在當學生的時候,執行了教育部的 Anti-botnet 計畫五年,辦了五屆的 Botnet of Taiwan (BoT)研討會。

–不要問我今年有沒有 BoT2015?

• 主要的研究興趣在於 network security, intrusion detection system, reversing engineering, malware detection and embedded system.

2015/08/19 Some things about Malware Classification 2

Page 3: Malware classification and traceability

Agenda

• 關於 Malware/AV 產業 的一些資訊

• 為什麼我們要收集到 Malware 樣本?

• 要怎麼收集 Malware 樣本呢?

• 一些簡單的 Malware 分類法 (素人可用)

• 結論

2015/08/19 Some things about Malware Classification 3

Page 4: Malware classification and traceability

• 關於 Malware/AV 產業 的一些資訊

2015/08/19 Some things about Malware Classification 4

Page 5: Malware classification and traceability

關於 Malware/AV 產業 的一些資訊

• 長久以來,對 Anti-virus (AV)產業來說,偵測已知病毒是比較容易,偵測未知病毒是比較難的。

• 然而十年來,病毒樣本的數量呈指數型成場,對AV產業來說,也不是那麼好處理了。

2015/08/19 Some things about Malware Classification 5

Page 6: Malware classification and traceability

關於 Malware/AV 產業 的一些資訊

2015/08/19 Some things about Malware Classification 6

Page 7: Malware classification and traceability

關於 Malware/AV 產業 的一些資訊

2015/08/19 Some things about Malware Classification 7

Page 8: Malware classification and traceability

關於 Malware/AV 產業 的一些資訊

• The malware samples are increasing exponentially.

–沒錯,這是”失衡的數位軍火發展”.

– Checksum-based rule set is a solution for AV industry to saving manpower.

– A whole/partial file checksum.

– MD5, SHA1 and SHA256 are used by AV industry.

2015/08/19 Some things about Malware Classification 8

Page 9: Malware classification and traceability

關於 Malware/AV 產業 的一些資訊 • 以 ClamAV 為例

– String-based rule 長這樣 • Worm.Bagle.H-zippwd-1

(Clam)=70617373*6170706c69636174696f6e2f6f637465742d73747265616d3b*6e616d653d*2e7a6970*0a5545734442416f414151414141*4141414141

• 需要知道怎麼從病毒樣本裡面選病毒碼,要不然誤判就麻煩了。

– MD5-based rule 長這樣 • a6d8dd5184301ac43290ec2684cfeaa5:79512:Win.Troja

n.Ransom-2205

• 除非 hash collision,要不然不會誤判 適合自動化.

2015/08/19 Some things about Malware Classification 9

Page 10: Malware classification and traceability

關於 Malware/AV 產業 的一些資訊

• 雲端要怎麼用?

–如果 local 無法確定檔案的好壞

–就上雲端查吧

–看是把 file checksum 傳上去查

–或是 把 file 本體 傳上去查

–慢?可能會。

2015/08/19 Some things about Malware Classification 10

Page 11: Malware classification and traceability

關於 Malware/AV 產業 的一些資訊

• The rule distribution of ClamAV in 2010.

2015/08/19 Some things about Malware Classification 11

Page 12: Malware classification and traceability

關於 Malware/AV 產業 的一些資訊

• The rule distribution of ClamAV on 2015/04/14.

2015/08/19 Some things about Malware Classification 12

MD5-based

Others Total

Number 3,686,236

109,962 3,796,198

Percentage 97% 3% 100%

Page 13: Malware classification and traceability

關於 Malware/AV 產業 的一些資訊

• 依照上面那個表所透露的訊息,在目前這個年代,只要你會算 file checksum (md5, sha1, sha256),知道怎麼怎麼查找 file checksum database,你就可以寫掃毒軟體

2015/08/19 Some things about Malware Classification 13

Page 14: Malware classification and traceability

• 為什麼我們要收集 Malware 樣本?

2015/08/19 Some things about Malware Classification 14

Page 15: Malware classification and traceability

為什麼我們要收集 Malware 樣本?

• 1. 對於偵測病毒檔案本身,有病毒樣本,才有偵測率。

• 2. 記錄它在 OS 裡面 I/O 與 網路上的 I/O 用來當作日後偵測或鑑識其行為的依據。

• 3. 當作日後交換與分享的籌碼。

• 4. 研究這 “失衡的數位軍火發展” 到底有多失衡

–為什麼壞人會的,我們都不會?

2015/08/19 Some things about Malware Classification 15

Page 16: Malware classification and traceability

為什麼我們要收集 Malware 樣本?

2015/08/19 Some things about Malware Classification 16

Page 17: Malware classification and traceability

•要怎麼收集 Malware 樣本?

2015/08/19 Some things about Malware Classification 17

Page 18: Malware classification and traceability

要怎麼收集 Malware 樣本?

• 1. 跟同好交換

• 2. 抓好心人打包好的

• 3. 自己裝 Honeypots 慢慢等 – 若需技術支援,請恰大會主辦單位

• 4. 用MD5去可下載的網站查詢 – 新手:就不知道我要的那種毒是什麼 MD5, 怎麼查?

– 有誠意的話,怎麼不整包給我?

• 5. 去買…. – 這年頭,Malware Sample 是可以買的。

2015/08/19 Some things about Malware Classification 18

Page 19: Malware classification and traceability

要怎麼收集 Malware 樣本?

• Malware 樣本怎麼買?

–這邊舉一個光明正大的例子

–傳說中 (VirusTotal) VT 有 private API

–透過這些 API,用戶可以分享其他人上傳的 files.

–諸位上傳的檔案就是這樣被分享給

•各防毒大廠 以及 買得起 VT private API 的單位

2015/08/19 Some things about Malware Classification 19

Page 20: Malware classification and traceability

要怎麼收集 Malware 樣本?

2015/08/19 Some things about Malware Classification 20

Page 21: Malware classification and traceability

要怎麼收集 Malware 樣本? 盡信 VT, 不如無 VT?

2015/08/19 Some things about Malware Classification 21

Page 22: Malware classification and traceability

要怎麼收集 Malware 樣本? 為什麼 AV 廠會讓人有誤導的機會?

• 這張VT的統計圖,或許可以給個交代 – 假設你是AV廠,你每天處理Sample的能力有限,你發現有些 Sample 已經被同業判定為 Malware了,你會再確認嗎?還是直接相信,把處理能力省下來做別的?

2015/08/19 Some things about Malware Classification 22

Page 23: Malware classification and traceability

• 一些簡單的 Malware 分類法 (素人可用)

2015/08/19 Some things about Malware Classification 23

Page 24: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用)

• 1. File checksums (MD5, SHA1, SHA256)

• 2. Using the names given by AVs

• 3. YARA

• 4. Finding malicious behaviors in Sandbox log

• 5. Finding malicious network behaviors in traffic

• 6. Using memory forensic

• 7. 用自己做的病毒碼來分類

2015/08/19 Some things about Malware Classification 24

Page 25: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 1. File checksums (MD5, SHA1, SHA256)

• 嚴格來說,File Checksum 不太能算是一種 Malware 的分類,因為它一個 checksum 通常只能對應到一個 Malware Sample。 – 不方便人類查詢

• 不過,因為這些 checksums – 在 Malware Samples 進行交換與資料處理的時候可以當成 keys 來使用。

– 以及可用來查詢是否在已知的 black/white list 裡面

• 因此,File checksums 算是進行 Malware 分類的必須的基本資料。

2015/08/19 Some things about Malware Classification 25

Page 26: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 1. File checksums (MD5, SHA1, SHA256)

2015/08/19 Some things about Malware Classification 26

Page 27: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 2. Using the names given by AVs

• 選一個 AV 依照它對這些 sample 的命名來分類。 – 因為我們有時候 Honeypot 收到的,AV 不一定來得及認識,所以在那個當下會有無名可用的問題。

• 選多個 AVs 理論上總會有人認得新的 Malware Samples 吧? – 但是會衍生出命名混亂的狀況。

– 例如:Taidoor 有人叫 simbot @_@

• (使用者真的在乎他們中什麼毒嗎? – 反正最後都是無差別重灌?

– 假設不在乎,AV 廠有沒有可能隨便弄個名字?)

2015/08/19 Some things about Malware Classification 27

Page 28: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 2. Using the names given by AVs

• 當年(2011)我用程式自動生成了一條 snort rule:

– Alert TCP any any -> any 80 (

• msg:"Malware Name Unknown-1";

• uricontent:"/up.php?id=20111012183696";nocase;

• content:"Host: stat.downvision.com";nocase;

• reference:email,[email protected];

• reference:md5,3f9cf028a39c32c81d44379bb701383d;

• sid:20005459;)

2015/08/19 Some things about Malware Classification 28

Page 29: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 2. Using the names given by AVs

• 當年的判定是這樣:

2015/08/19 Some things about Malware Classification 29

Page 30: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 2. Using the names given by AVs

• 現在的判定是這樣:

2015/08/19 Some things about Malware Classification 30

Page 31: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 2. Using the names given by AVs

• 為什麼當年敢 release 那條 snort rule?

–有點忘了,可能當時還年輕

2015/08/19 Some things about Malware Classification 31

Page 32: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) YARA

• YARA

–是個好用的 tool

–用來偵測 packers 與 exe 的原生 compilers 有幫助。

• 搞不懂為什麼一堆 Malware 要用 Delphi 寫 @_@

–不過 Yara 的 rule 似乎不好寫,尤其是在 PE entry pointer 的比對上

2015/08/19 Some things about Malware Classification 32

Page 33: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) YARA

• 不過 Yara 的 rule 似乎需要些經驗才好寫,尤其是在 PE entry pointer 的比對上。

2015/08/19 Some things about Malware Classification 33

Page 34: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) Finding malicious behaviors in Sandbox log

• 如果我們有時間,我們可以把一些 samples 用 Sandbox 執行起來,記錄它們的

– File I/O: 對象, 次數, 順序, 內容 等等

– WIN API usage: 對象, 次數, 順序, 內容 等等

–綜合上述我們可以歸納出一個惡意行為模式。

–理論上,同種的Malware應該會有類似的行為。

–所以,下次如果有 Sample 跑出類似的行為,我們就可以判它是 Malware !!

• 原則是這樣,但是我們在實務上需要很小心

2015/08/19 Some things about Malware Classification 34

Page 35: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) Finding malicious network behaviors in traffic

2015/08/19 Some things about Malware Classification 35

Page 36: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) Finding malicious network behaviors in traffic

2015/08/19 Some things about Malware Classification 36

Page 37: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) Finding malicious network behaviors in traffic

2015/08/19 Some things about Malware Classification 37

Page 38: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) Finding malicious network behaviors in traffic

• 那個 unknown 的C3e7d7960590baaefbc72d601e0b6d73 最後

2015/08/19 Some things about Malware Classification 38

Page 39: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) Using memory forensic

• 這個基本上需要藉助 VM/Sandbox/實機

–先把 Sample 執行起來

–進行 memory dump

–理論上,有加殼 (packing) 的 Malware 在這個時候應該是脫光了,方便研究人員進行分類與比對。

–不過,這招有點花時間,考驗研究員對於OS記憶體的資料結構的熟悉度

2015/08/19 Some things about Malware Classification 39

Page 40: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類

• 對於素人來說,要做病毒碼,最麻煩的應該就是病毒的殼了….

–如果脫不了殼,就只能做最外面那層的 file checksum.

2015/08/19 Some things about Malware Classification 40

Page 41: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類

• 這時候就要靠 ClamAV 來幫忙脫殼 – clamscan -v --stdout --tempdir=./vir.tmp --leave-

temps=yes UnknownFile

– 進到 vir.tmp 尋找脫殼後的病毒本體或是具有代表性的檔

– 找到代表性的檔案後,用 • sigtool --md5 剛選的代表性的檔案

• 會得到新的病毒碼 把它加到 – /var/lib/clamav/test.hdb

– 再用 clamscan 掃剛剛那個 UnknownFile 以及其他的 files (why?).

2015/08/19 Some things about Malware Classification 41

Page 42: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類 (Demo)

• 我準備了 30 個 以 Sha256 為名的 Malware Sample:

• 0004d90568e5d1d456c2bfc2011685b45d6dbb64f0a1f7ab30a639ac3711b023 • 0004de274e7827cc41753ec5654323e820622f9536861c147f54d4f1876858d5 • 00051e60e804a45e6841bc7a6424f1561aca968eadd344349435e73ee0017478 • 00061b86f1a4681f0cbb06f5855a1ca9989515fea76addf99e0f66775e093dd2 • 00074a52208e5dde0bab55ed316c6e668a005a02f140654f2f7a94ae8df5d47c • 000769117fc00c0be0979b05ec927ba4afbfc3756e63f9985d628803811b7cc3 • 0007a77752f16949ee78897e4b5b0306298528123e0b588dfba8f1417a59e87f • 000c5dd2ab658fd7d0fb46383d8ab82d85a8115266b2acc2d49dd7bf75f70ff5 • 00111adf4b439e401359d271a68ffbca0b89fec637bbaa630636478e98d96c9e • 001653e0bc89d19cedf3601f75bea6e2fade53ee1104216207fa2caa606d2a2a • 0018678059ea8b3ed410dc0f8de60f01411a801abcae1cf8f210ab41bc3931a5 • 001a873ebb978450dfeccc684e9839087e5d586e7c74da9d5330cc1abcfe369a • 001bc132c4bc0715bd451333cc49d08af0f8d66faeff9db0b36781c217456611 • 001cd2ce309fbee802b772f7d718bd9b61a0be1689f2d0e7c3a39671d0cde937 • 001d431b78a49f954c6243715f3804ff60fdf0059e076331cd8b54002aeab9bd • 0020d96dd3cae9a877aa116a0b6aa30f4ed1791bd89db4c15aba24515398ca2d

2015/08/19 Some things about Malware Classification 42

Page 43: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類 (Demo)

• 002274d653577a473d0c88390b861b7b70613e818a59e14e862e577e13227770 • 00240adc2f41e6f1a860b3ee9befa3b7c80b6f4b9dbfbd9e4911996a33ccc6ca • 0024d09ca47d63cdae67e7f648984904bdbd59eb112654bc607b683d64c50482 • 0025cefd83126af6164c97653cf53f28f29f151b9eb8f291ac5ccb1dcc3b3a98 • 002626066e66c3e093cbc1a57518ce3a170b88cf6d6946f60d0316f6987bd4c5 • 0028058a6e593e6dc0399310940bb40aa45a4b86b3d45b643383c3c5f4ad0ff8 • 00290135454717428c70eb081a40a5dc1d6ff84a9c50ec0e868c7f92e90d6635 • 002929712f3589f58d9ab09cf12667b07f2f5e9c31d96afcb815d58a18e8403b • 002a8aac7b16f6485d0a0f8540d5d2d70df1beaa0f26449229694508c3d38a05 • 002afb8af0efb4819eed4cacb98780a2bebd05141f0d34b12a6eaa3d4c8911b2 • 002f162a94109db95848f48e029f792323f460c5807632f77f77a6aa571e5253 • 00378150c97f62579eb4fcf5781402bf9691f1f1ac9a415e7394cd0683cdd1eb • 0037921ac81b136e33036cdb34157551b0dd41576f32c50393c689bdfaa513cd • 0038c136407412a22806103e99b40d9010f885b7964b9d6a620e11f90f7a607a

2015/08/19 Some things about Malware Classification 43

Page 44: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類 (Demo)

• ClamAV 的 scan results:

2015/08/19 Some things about Malware Classification 44

Page 45: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類 (Demo)

• 其中,ClamAV 說下面三個是好的 • 0020d96dd3cae9a877aa116a0b6aa30f4ed1791bd89db4c15aba24515398ca2d

• 002929712f3589f58d9ab09cf12667b07f2f5e9c31d96afcb815d58a18e8403b

• 0038c136407412a22806103e99b40d9010f885b7964b9d6a620e11f90f7a607a

• 但是我們懷疑它們應該還是有問題,於是 clamscan -v --stdout --tempdir=./vir.tmp

--leave-temps=yes

./unknown/./0038c1407412a22806103e99b40d9010f885b7964b9d6a620e11f90f7a607a

> debug.txt

2015/08/19 Some things about Malware Classification 45

Page 46: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類 (Demo)

• 發現 vir.tmp 裡面有一些被解出來的檔案

2015/08/19 Some things about Malware Classification 46

Page 47: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類 (Demo)

• 發現某個 folder 應該有嫌疑,先算它們的 file type,裡面的 content.001 居然是個自解安裝程式…

2015/08/19 Some things about Malware Classification 47

Page 48: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類 (Demo)

• 再算它們的 MD5

2015/08/19 Some things about Malware Classification 48

Page 49: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類 (Demo)

• 拿 content.001 的 MD5 (c7f6ed56312c8fbb58ae6ed445c38df4) 去問 VT

2015/08/19 Some things about Malware Classification 49

Page 50: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類 (Demo)

• 用

– sigtool --md5 content.001

–產生最簡單的 md5 rule

– c7f6ed56312c8fbb58ae6ed445c38df4:59640:Group1

– 加回 /var/lib/clamav/test.hdb

2015/08/19 Some things about Malware Classification 50

Page 51: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類 (Demo)

• 再用一次 clamscan -v ./unknown/. > result.txt

• 發現我們很幸運地找到這些 Malware 的共用元件。

2015/08/19 Some things about Malware Classification 51

Page 52: Malware classification and traceability

一些簡單的 Malware 分類法 (素人可用) 用自己做的病毒碼來分類 (Demo)

• 一些問題: – 1. ClamAV 不能脫殼 (unpack) 的怎麼辦?

• 自己脫脫看,不然就先放著,或是直接送VT.

• 如果 Sandbox 發現它做壞事,那就先做最外面那層的 MD5 來治標。

– 2. ClamAV 解開的檔案,VT 都說沒問題? • 放個幾天再問VT

• 看White List 怎麼說?

• 如果 Sandbox 發現它做壞事,那就先做最外面那層的 MD5 治標。

• 0day? APT? 當我們能力所不及的時候,送 VT 也是選項。

2015/08/19 Some things about Malware Classification 52

Page 53: Malware classification and traceability

•結論

2015/08/19 Some things about Malware Classification 53

Page 54: Malware classification and traceability

結論

• 如果可以,少傳東西上 VT,但用 file checksum/url 查詢應該無妨,但也不可盡信 VT。

• Malware 的 name 有時候不是那麼重要,重要的是該擋下的是否有即時被擋下

• 對於 Malware 的研究人員,ClamAV 無論是它的 src 或是 bin,在Malware的分類上都比想像中有用

• 由於時代的演進,病毒碼的製作與病毒的分群,已經不像過去需要超高的技術門檻,只要有心,人人都可以做AV。

2015/08/19 Some things about Malware Classification 54

Page 55: Malware classification and traceability

Q&A

• Thank you

• E-mail:

[email protected]

• Facebook for BoT conference:

– https://www.facebook.com/BotnetCon

2015/08/19 Some things about Malware Classification 55

Page 56: Malware classification and traceability

參考資料

• (講員太忙,有機會再補)

2015/08/19 Some things about Malware Classification 56

Page 57: Malware classification and traceability

One more thing

• 對了,如果有人想學習 Malware/Virus 偵測,卻沒有樣本,可以

– Google viruses-20070914

–印象中這包有六萬多隻2007年左右的樣本

–不用拿 MD5 去查

– (是有點舊,不過學習用,就不要太計較了 )

2015/08/19 Some things about Malware Classification 57