マルウェア解析に必要な素養~スクリプト編~ ==== :::success 親ページ:[マルウェア解析に必要な素養](https://hackmd.io/s/S1kLEr5x#) ::: マリシャスなスクリプトファイルにまつわるトピックをまとめています。 [TOC] コマンドプロンプト ---- cmd.exe ### 難読化 [DOSfuscation: Exploring the Depths of Cmd.exe Obfuscation and Detection Techniques | FireEye Inc](https://www.fireeye.com/blog/threat-research/2018/03/dosfuscation-exploring-obfuscation-and-detection-techniques.html) (2018/3/22) PowerShell ---- 急増中。特にダウンローダーがよく使っている。 * [PowerShell マルウェアが急増: 解析したスクリプトの 95.4% が悪質 | Symantec Connect](https://www.symantec.com/connect/tr/blogs/powershell-954-0?page=1) * [セキュリティ研究センターブログ: マルウェア解析奮闘記 Powershell多用マルウェアの解析](http://blog.macnica.net/blog/2016/10/powershell-38fc.html) PowerShell は、元は Windowsで動作する、コマンドラインシェルおよびスクリプト言語を指します。システムの管理やプロセスの自動化を実現するもので、非常に「無駄に」多機能です。PowerShell は 2017 年にオープンソース化され、Linux、macOSでも利用可能なプラットフォームとなりました。 攻撃者の気持ちになってコードを書こうとすると情報が少なすぎて結構苦労します(APIリストを片っ端から目grepしたほうが早いくらい)。PowerShellを調べているつもりが \.Net Frameworkの話にすり替わっているのはあるあるです。 [PR]同人誌「TomoriNao Vol. 2」で、筆者はPowerShellでのDLLインジェクションのやり方を解説しました。 ### Powershellの実行方法 * powershell.exe * .NetのPowerShellクラス * AVは純正のpowershell.exeの起動だけを監視すればいいというわけではない(AVベンダーは大変だな) * [Executing PowerShell scripts from C# – Keith Babinec's Development Blog](https://blogs.msdn.microsoft.com/kebab/2014/04/28/executing-powershell-scripts-from-c/) (2014/4/28) TODO:他にある? ### 実行ポリシーの回避 TODO ### 攻撃経路 #### LNKファイル→PowerShell * [LNKファイルを利用してマルウェアをダウンロードする手法が増加中 | トレンドマイクロ セキュリティブログ](http://blog.trendmicro.co.jp/archives/15091) (2017/5/31) #### LNKファイル→HTAファイル→VBScript→PowerShell/RTFファイル→HTAファイル→VBScript→PowerShell * [PowerShell Empireを利用した標的型攻撃 | LAC WATCH | 株式会社ラック](https://www.lac.co.jp/lacwatch/people/20170807_001352.html) (2017/8/7) #### Powerpointファイル→リンクをホバー→Powershell * [PowerPoint File Downloads Malware When You Hover a Link, No Macros Required](https://www.bleepingcomputer.com/news/security/powerpoint-file-downloads-malware-when-you-hover-a-link-no-macros-required/) (2017/6/2) * [マウスオーバとマクロを利用、PowerPoint文書閲覧時に感染させる攻撃手法に注意 | トレンドマイクロ セキュリティブログ](http://blog.trendmicro.co.jp/archives/15257) (2017/6/19) ### 難読化と難読化解除 TODO 例: * `-enc`(頻出) UTF-16をBase64でエンコードしたやつ? #### 難読化参考情報 * [PowerShell難読化の基礎 (1) – Binary Pulsar](http://binary-pulsar.azurewebsites.net/2018/09/01/ps-obfuscate-pt1/) (2018/9/1) * [PowerShell難読化の基礎 (2) – Binary Pulsar](http://binary-pulsar.azurewebsites.net/2018/09/08/ps-obfuscate-pt2/) (2018/9/8) * https://github.com/pan-unit42/public_tools/tree/master/powershellprofiler (2019/10/23) * Powershellスクリプトの難読化を解除するとともに、ふるまいを元にリスクを推定 * [Practical Behavioral Profiling of PowerShell Scripts through Static Analysis (Part 1)](https://unit42.paloaltonetworks.com/practical-behavioral-profiling-of-powershell-scripts-through-static-analysis-part-1/) ### バイパス https://twitter.com/omespino/status/1082361280248336384 (2019/1/8) > **@omespino** > #Protip can you pop a calc with "C:\>powershell C:\*\*2\n??e*d.*?" ? yes. > bypass blacklisted words filter (or firewalls) via wildcards > > C:\>powershell C:\??*?\*3?\c?lc.?x? calc > C:\>powershell C:\*\*2\n??e*d.* notepad > C:\>powershell C:\*\*2\t?s*r.* taskmgr > > #BugBounty #infosec #### Invoke-PSImage https://github.com/peewpw/Invoke-PSImage > Embeds a PowerShell script in the pixels of a PNG file and generates a oneliner to execute 実例: * [McAfee Labs脅威レポート: 2018年3月](https://www.mcafee.com/enterprise/ja-jp/assets/.../rp-quarterly-threats-mar-2018.pdf) * > 2017年12月: 平昌冬季オリンピックを含む組織を標的にした攻撃では、ステガノグラフィーと、攻撃の数日前にリリースされた新しいツールInvoke-PSImageが使用されました。Operation Gold Dragonは被害者のシステムに常駐し、デバイスやクラウドアカウントに保存されたデータを、攻撃者が自由に検索してアクセスできるようにしていました。 ### WMI TODO ### .NET Framework PowerShellはC#が使えるからね。 ### PowerShellに関する情報セキュリティ系論文 [[1709.07508] Hijacking .NET to Defend PowerShell](https://arxiv.org/abs/1709.07508) (2017/9/21) > This paper focuses on repurposing various stealthy runtime .NET hijacking techniques implemented for PowerShell attacks for defensive monitoring of PowerShell. 比較的平易に書かれていてPowerShell入門者には読みやすいかも。Powershellを堅牢化する話。まあまあ面白かったです。 VBScript (VBS) ---- TODO .NET ---- ### 解析例 [The anatomy of a .NET malware dropper](https://www.cybereason.com/blog/.net-malware-dropper) (2018/9/10) ### 解析ツール * [dnSpy](https://github.com/0xd4d/dnSpy) … デコンパイラ+デバッガ JavaScript ---- 標的型メールの添付ファイルとして登場する。 TODO:具体例 ### 難読化と難読化解除 TODO * [JavaScript難読化ツールの紹介と比較 - 備忘録](https://kagasu.hatenablog.com/entry/2017/03/30/194024) (2017/3/30) * よくまとまっている * [JavaScript難読化読経](https://www.slideshare.net/hasegawayosuke/javascript-51570525) (2015/8/13) * 難読化コードを読んでみよう系 * [JavaScriptマルウェアの解析テクニック | IIJ Engineers Blog](https://eng-blog.iij.ad.jp/archives/4427) (2019/12/06) * JSの初級的解析テクニックの解説。js-beautify(難読化解除)やSpider Monkey(JSエンジン)を利用した解析を解説。 #### 実例 [よくわからないJavaScriptが綺麗にされたらCard Stealerだった件 | リクルートテクノロジーズ メンバーズブログ](https://recruit-tech.co.jp/blog/2019/05/10/cardstealer/) (2019/5/10) > 今回観測した攻撃の流れは、以下と推測しており、クレジットカード情報の盗み出しを目的としていると考えられます。 ### 脆弱性検出 [バグハンターのためのクライアントサイドJavaScriptの静的解析 - No1zy Web Security Blog](https://no1zy.hatenablog.com/entry/static-analysis-of-javascript-for-bughunters)(2018/12/2) HTA ---- 本章はmalicous な HTML Applicationsを扱う。 [HTAを利用したワンクリックウエアの新たな手口 | トレンドマイクロ セキュリティブログ](http://blog.trendmicro.co.jp/archives/2729) (2009/4/7) [Smuggling HTA files in Internet Explorer/Edge](https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2017/august/smuggling-hta-files-in-internet-exploreredge/) (2017/8/) > A HTA file is usually made up of HTML and script such as JScript or VBScript, much like a normal web page. TODO:HTAをよく理解してないのでやってみたい [PowerShell Empireを利用した標的型攻撃 | LAC WATCH | 株式会社ラック](https://www.lac.co.jp/lacwatch/people/20170807_001352.html) (2017/8/7) > 中身はリンク先としてHTML Application (HTA)を実行する機能を持つmshta.exeがIPアドレス(80[.]209[.]252[.]70)を引数として指定されています > HTAファイルは、図7に示す通り、VBScriptを利用して、PowerShellスクリプトを実行します。オプション「-enc」以降のPowerShellスクリプトはコードがエンコードされており、図8(筆者注:省略)がデコードしたものです。 [Demiguise](https://github.com/nccgroup/demiguise) by NCC Group (2017/8) 暗号化されたHTAファイルを含むHTMLファイルを生成 悪性文書ファイル ---- マリシャスな文書ファイルは、主に研究方面で「悪性文書ファイル」と呼ばれる。解析者がmaldocと読んでいることもある。 ### VBAマクロ VBAはMicrosoft Officeのマクロ機能。典型的、古典的手口。 [Advanced VBA Macros Attack & Defence - eu-19-Lagadec-Advanced-VBA-Macros-Attack-And-Defence-2.pdf](https://i.blackhat.com/eu-19/Wednesday/eu-19-Lagadec-Advanced-VBA-Macros-Attack-And-Defence-2.pdf) (2019/12) 例: * [Metasploitを使ってconnect-back shellを起動するWord文書を作ってみる - ももいろテクノロジー](http://inaz2.hatenablog.com/entry/2015/11/13/225247) * [電卓を起動するWord文書を作ってみる - ももいろテクノロジー](http://inaz2.hatenablog.com/entry/2015/10/12/155137) * [流行マルウェア「EMOTET」の内部構造を紐解く | MBSD Blog](https://www.mbsd.jp/blog/20181225_2.html)(2018/12/25) * 難読化されたマクロ付きのdocファイルがダウンローダーとして動作。 * > この難読されたマクロが実行されると、複数のコマンドプロンプトやPowerShellが実行され複数の不正サーバへの接続が発生、最終的にEMOTET本体であるEXEファイルがダウンロード・実行されEMOTETに感染します。 [余談]筆者が学生時代でしていた学内バイトでの話。SEの方に某動画データベースの疑似ダンプを渡す必要がありました。Webページをスクレイピングして、メタ情報をデータベース化するためにExcelのVBAマクロを使いました。自動でIEが立ち上がって、ページをなめてくれるので便利でした。うまく使うとポータビリティが高い便利な機能です。 ### PDF TODO:説明。メインターゲットはAdobe Acrobat。フォーム機能もエクスプロイトされているのも抑えたいところ。 解析例: * https://twitter.com/erikpistelli/status/1136178950818926592 > @erikpistelli > Video: PDF/XDP Malware Reversing - https://youtu.be/d7Nno1d9N9Q - Since I don't have time to write many articles, this is my first video tutorial. :) If you like it and want to see more, let me know! 参考: * [Abusing Adobe Reader’s JavaScript APIs by Abdul-Aziz Hariri & Brian G…](http://www.slideshare.net/codeblue_jp/abusing-adobe-readers-javascript-apis-by-abdulaziz-hariri-brian-gorenc-code-blue-2015) ### RTF リッチテキストファイル。 TODO:具体例 気になる子ちゃん: * Webページで利用可能なリッチテキストエディタはExploit可能なのだろうか?
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up