Recently, thereās been a surge in the popularity of trojan clipboard attacks whereby the attacker convinces the user to carry their attack payload across a security boundary and compromise the device.
Meanwhile, AI hype is all the rage. I recent had a bad experience in what I thought was a simple AI task (draw a map with pushpins in certain cities):
⦠but I was curious to see what AI would say if I pretended to be the target of a trojan clipboard attack. I was pleased to discover that the two AIs I tried both gave solid security advice for situation:

A few days later, the term āvibe-codingā crossed my feed and I groaned a bit when I learned what it means⦠Just describe what you want to the AI and itāll build your app for you. And yet. Thatās kinda exactly how I make a living as a PM: I describe what I want an app to do, and wait for someone else (ideally, our dev team) to build it. I skimmed a few articles about vibe coding and then moved on with my day. I donāt have a lot of time to set up new workflows, install new devtools, subscribe to code-specific AI models, and so forth.
Back to the day job.
Talking to some security researchers looking into the current wave of trojan clipboard attacks, I brainstormed some possible mitigations. We could try to make input surfaces more clear about risk:
⦠but as I noted in my old blog post, we could be even smarter, detecting when the content of a paste came from a browser (akin to the āMark of the Webā on downloads) and provide the user with a context specific warning.
In fact, I realized, we donāt even need to change any of the apps. Years ago, I updated SlickRun to flash anytime the system clipboardās content changes as a simple user-experience improvement. A simple security tool could do the same thingā watch for clipboard changes, see if the content came from the browser, and then warn the user if it was dangerous.
In the old days, Iādāve probably spent an evening or two building such an app, but life is busier now, and my C++ skills are super rusty.
But⦠what if I vibe-coded it? Hmm. Would it work, or would it fail as spectacularly as it did on my map task?
Vibe-coding ClipShield
I popped open Google Gemini (Flash 2.0) and told directed it:
> Write me a trivial C++ app that calls AddClipboardFormatListener and on each WMClipboardUpdate call it scans the text on the clipboard for a string of my choice. If it's found, a MessageBox is shown and the clipboard text is cleared.
In about 15 seconds, it had emitted an entire C++ source file. I pasted it into Visual Studio and tried to compile it, expecting a huge pile of mistakes.
Sure enough, VS complained that there was no WinMain
function. Gemini had named its function main()
. I wonder if it could fix it itself?
> Please change the entry point from main to WinMain
The new code compiled and worked perfectly. Neat! I wonder how well it would do with making bigger changes to the code? Improvements occurred to me in rapid succession:
> To the WM_CLIPBOARDUPDATE code, please also check if the clipboard contains a format named "Chromium internal source URL".
> Update the code so instead of a single searchString we search for any of a set of strings.
> please make the string search case-insensitive
> When blocking, please also emit the clipboard string in the alert, and send it to the debug console via OutputDebugString
In each case, the resulting code was pretty much spot on, although I took the opportunity to tweak some blocks manually for improved performance. Importantly, however, I wasnāt wasting any time on the usual C++ annoyances, string manipulations and conversions, argument passing conventions, et cetera. I was just⦠vibing.
There was a compiler warning from Visual Studio in the log. I wonder if it could fix that? I just pasted the error in with no further instruction:
> Inconsistent annotation for 'WinMain': this instance has no annotations. See c:\program files (x86)\windows kits\10\include\10.0.26100.0\um\winbase.h(1060).
Gemini explained what the warning meant and exactly how to fix it. Hmm⦠What else?
> Is there a way to show the message box on a different thread so it does not block further progress?
Gemini refactored the code to show the alert in a different thread. Wait, is that even legal?
> In Windows API, is it legal to call MessageBox on another thread?
Gemini explained the principles around the UI thread and why showing a simple MessageBox was okay.
> Can you use a mutex to ensure single-instance behavior?
Done. I had to shift the code around a bit (I didnāt want errors to be fatal), but it was trivial.
Hmmā¦. What else. Ooh⦠What if I actually got real antivirus into the mix? I could call AMSI with the contents of the clipboard to let Defender or the system antivirus scan the content and give a verdict on whether itās dangerous.
> Can you add code to call AMSI with the text from the clipboard?
It generated the code instantly. Amazing. Oops, itās not quite right.
> clipboardText.c_str() is a char* but the AmsiScanString function needs an LPCWSTR
Gemini apologized for the error and fixed it. Hmm. Linking failed. This has always been a hassle. I wonder how Gemini will do?
> How do I fix the problem that the link step says "unresolved external symbol AmsiOpenSession"?
Gemini explained the cause of the problem and exactly how to fix it, including every click I needed to perform in Visual Studio. Awesome!
By now, I was just having tons of fun, pair programming a combination of my knowledge with Geminiās strengths.
> Please hoist a time_point named lastClipboardUpdate to a global variable and update it each time the clipboard contents change.
> Please rewrite GetTimestamp not to use auto
I like to know what my types actually are.
> Please monitor keystrokes for the Win+R hotkey and if pressed and it's within 30 seconds of the clipboard copy, show a warning.
I see that it's using WM_HOTKEY.
> The RegisterHotKey call will not work because Windows uses that hotkey. Instead use a keyboard hook.
Gemini understands and writes the new code. It's a little kludgy, watching for the keydown and up events and setting booleans.
> Rather than watching for the VK_LWIN use GetAsyncKeyState to check if it's down.
Gemini fixes the code.
Iām super-impressed. Would the AI do as good a job for anyone who didnāt already deeply understand the space? Maybe not, and probably not as quickly. But it was nice that I had the chance to feel useful.
Iāve published our code up at https://github.com/ericlaw1979/clipshield. Maybe Iāll sign it and package it up into an installer at some point.
Heck, pretty much all thatās left is a cool icon for the .EXE. Maybe Gemini can help?
Ah well. Iāve gotta add value somewhere.
-Eric