722 points · by borski · 10y ago · 234 comments
Does it really work? Do sites actually get more traffic by hijacking your keyboard's basic functions to insert advertisements? I guess it probably does. :(
Oh, darn … /s
Then I realized that the reason I was doing that instead of ctrl-c is all the times that web sites break ctrl-c. I literally have gotten used to highlighting, right-clicking, and clicking copy, for a "clean" copy :) I wasn't even aware I was doing this.
Of course, web sites can hook right-clicks. It would be funny if they threw up a fake context menu matching the default context menu of the browser and operating you're using, but with evil versions of commands :)
I don't disable or modify javascript, so with that addition it would have tricked me.
I will say that the people who generate event hooks in browsers need to pull their heads out of their asses before this kind of thing becomes necessary.
But then, I've seen sites that break highlighting. Either intentionally, or accidentally, thinking people will share their every highlight on Twitter (I am looking at you, Medium).
Most people who use terminals know how to protect themselves, and they can recognize questionable content.
This whole problem shouldn't even exist.
https://msdn.microsoft.com/en-us/library/bb250473(v=vs.85).a...
http://i.stack.imgur.com/jvDUh.png
https://developer.mozilla.org/en-US/docs/Mozilla/Preferences...
But the same quick search shows that it does not appear possible to control this in Chrome. If anyone knows how, please correct me.
What browsers really should have are a standard "Ask & Whitelist" dialog for all of these security critical features[1]. It seems Firefox even used to have this feature, but it and the corresponding addon have long since crumbled to dust[2].
Unfortunately browsers are no longer controlled by hackers who think about all the implications of a feature, but by corporations who think about money, and us hackers have to spend inordinate amounts of time trying to play security whack-a-mole, or be forced to give up and use our browsers like sheep, the way the corporations want us to.
[1] There's many more, including utterly ridiculous stuff such as telling websites the battery charge status of your device (and if your charger is plugged in): https://gist.github.com/haasn/69e19fc2fe0e25f3cff5
[2] http://kb.mozillazine.org/Granting_JavaScript_access_to_the_...
How is this method different?
Of course a better solution wouldve been a program which doesnt so easily let you lose data in the first place, but this software was long past that.
All this was introduced to prevent abuse. Apparently it still wasn't enough though...
However, sometimes I want to share a qoute I found online. I don't want a promo for the website inserted into my clipboard. For them, it must be a fine line that realization: user-hostility can be short term profitable but long term fatal.
The problem I see with this scenario is that not everyone is copy-pasting from the browser into a terminal. I for example copy things to my VM's text editor first, then run the command. Other could be copy-pasting to an email for example. In those instances it would be obvious that the site is doing something not so kosher and it would be notices pretty soon I guess, depending on the site's popularit
Try to copy one from this site for example.
http://www.brainyquote.com/quotes/authors/a/albert_einstein....
"Please enable Javascript This site requires Javascript be enabled to provide you the best experience [for us]. Some features [like shoving crap into your clipboard] may not be available with Javascript disabled!"
It's not uncommon to find sites whose definition of "good UX" is exactly the opposite of what I want.
Twitter does this on every single tweeted link. For example copy the link in this tweet: https://twitter.com/twitter/status/727507892283142145
You don't see a https:// on the page, but it gets put on your clipboard because it is actually there with 0 font size. In this case it's actually pointless though because they cut off the end of the url.
It defangs this vulnerability nicely.
echo hacked > hacked.txt; echo -ne '\033[1F\033[2K'
echo innocent --preserve-root
do not remove '/' (default)While we are on the topic of copying and pasting. If the command downloads a script, make sure you download the script out-of-step via curl first, review its contents, and only then execute it. This avoids sites maliciously changing the script based on the User Agent.
To solve this, browsers should probably disallow modifying the clipboard .
curl -sL http://example.com/install.sh | less -eK && \
curl -sL http://example.com/install.sh | bashOn the Mac, applications downloaded from the Internet are quarantined; they stay that way until you accept a warning message displayed at first launch (even if you wait days to launch it for the first time). The OS helpfully remembers where the file came from, e.g. “This was downloaded from www.notmalware.com on July 6, 2000.”.
If a web browser insists on allowing web-controlled Copy behavior, the resulting pasteboard should be given a big, black TAINTED mark that cannot be cleared without a very explicit action. If I go to another application and try to Paste, the other application should not be able to access the data without clearing the quarantine (e.g. OS provides standard dialog that shows the entire text and web site of origin, free of any white text-coloring or Unicode invisibility tricks).
Edit: Sorry, I didn't read close enough.
"not evil"
without a line break as expected. Chrome and Safari.edit: doesn't seem to have unexpected behavior in terminal either. Am I missing something, or does uBlock default deny the scripts that can do this?
edit 2: console log: Copying text command was unsuccessful. uBlock disabled.
This particular attack doesn't work when not using keyboard to copy (think select to copy (traditional X behavior) or using a context menu), it causes text to unselect after busy loop ends, causes fans in my laptop to start working (because of busy new Date loop), causes cursor to cease changing for a certain period of time, requires me to enable JavaScript, requires support for "copy" command (which isn't universal), and requires the user to press CTRL+C either way (otherwise the webpage won't be able to copy into a clipboard).
I guess you could paste an output after a certain time, but because of hijacking on Ctrl key, nothing can be copied before busy loop ends, and as a result, it doesn't prevent "pasting the command into Notepad" just to ensure it's safe - as either what previously was in pastebin or malicious command will be pasted.
https://xfix.github.io/mystery-zone/command.html (disclaimer: I made this page) doesn't have any of those problems (other than requiring the user to copy text in any way (CTRL+C, text selection, context menu, whatever odd interface do you have)), and it still can break vim (and for that matter, bash, zsh (including zsh with paste protection), fish, and emacs).
It is time to rein in all the things that web browsers are complicit in doing at the request of random web sites. There needs to be a lot more thought put into these “APIs” that sites have access to, and a lot more scrutiny of the data.
This clipboard thing remembers me of the webrtc functionality that enable browsers to scan my network without asking me.
At the same time, it's better than those times when you had flash buttons to copy link. So I think it should be allowed to change clipboard on user's action (can it be detected?). But there certainly shouldn't be an event to change clipboard that is fired after the user copies something (selection copy, keyboard shortcut, browser ui, ..).
As others have already pointed out, an API for interacting with the clipboard is a terrible idea that should be removed from the browser.
However, this particular problem of pasting multi-line strings into the terminal is already a solved problem if you use rxvt-unicode. The standard package includes the perl plugin "confirm-paste"[1][2]. Enable it in ~/.Xresources
URxvt.perl-ext-common: default,confirm-paste
confirm-paste passes single line pastes normally, but asks for a y/n confirmation before sending a multi-line paste to the shell.[1] urxvt-confirm-paste(1)
[2] http://cvs.schmorp.de/rxvt-unicode/src/perl/confirm-paste?vi...
in it's feature creep it added clipboard access.
then web site developers thought it's a crucial feature. even github used a flash element to allow easy copy of repo url. as if anyone using git can't copy. then some moron added that to the browser, and every other moron followed.
morons. copying flash...
The solution is definitely to avoid pasting commands with newlines in them into your terminal. With Vim, you can use the + register to paste (e.g. "+p). Using iTerm on OS X, I've added a custom keymap for Cmd+V, bound to Run coprocess:
pbpaste | tr -d "\n"
which filters out the newlines.It isn't perfect because people could try to obscure the command but in general it makes me a lot happier to paste commands into my terminal.
- Paul Vixie, vixie-cron INSTALL file (https://github.com/rhuitl/uClinux/blob/master/user/vixie-cro...)
As it happens, this particular attack doesn't work in gngr [0]. The example uses an absolute positioned div to put extra text out of viewport, which is not picked up by gngr when selecting text.
gngr also doesn't enable Javascript by default, so attacks such as that described in OP are not possible from random site visits. (I recommend uBlock / uMatrix for other browsers).
However, the attack surface is really quite large here. CSS directives such as `opacity: 0.001` could be easily used to mask extra text.
[0]: https://gngr.info/
and https://github.com/UprootLabs/gngr
[1]: https://thejh.net/misc/website-terminal-copy-pasteThen I remembered I had no script enabled, and then I remembered I don't trust JS and browsers by default, they are like OS in my OS that are way complex to be audited and they have access to way too much sensitive things (files, display, keyboard, network).
Weirdly enough, I don't think noScript is the solution (it is heavy, unpractical and I dare not look the code).
I am pretty awry of the evolution of the DOM + JS interaction and the new features brought in browsers that looks like both a cancer and instabilities to come.
So am I immune (Unix style is all I ever use) or is there a way for my browser to mess with that buffer as well?
It is far easier to execute on the desktop (by watching for the control key press, then creating a hidden div that contains the text to be copied + malicious code if necessary).
> document.addEventListener('keydown', function(event) { ... })
Basically, press any key on your keyboard on the website, and it'll work.
It may also be because you have no support for execCommand if it didn't work for CTRL+C.
Just wrote https://github.com/awalGarg/realcopy to "counter" this. Plan to add for FF as well.
The proper way of pasting into vim, which doesn't have this problem, is "+p (as mentioned in the article).
:set pasteThis also includes the awful popular installation commands in the form of "curl -s ... | sh" - which means you are basically giving your computer in the hands of a third party.
As opposed to any other installation method? Do you regularly vet the entire source code of software you install?
Always review the script first.
I am already using a terminal emulator that warns me when I paste multiple lines (ConEmu).
fu9ar@traveler ~ % ^[[200~echo "evil"
It works, but it also doesn't work.Usually I use the middle-click-to-paste feature, which just doesn't work at all.