TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Don't Copy-Paste from Website to Terminal

689 pointsby dave1010ukabout 12 years ago

40 comments

NelsonMinarabout 12 years ago
Why would I bother copying and pasting the code to my clipboard when common industry practice now is just to invoke the output of curl directly?<p>ruby -e "$(curl -fsSL <a href="https://raw.github.com/mxcl/homebrew/go" rel="nofollow">https://raw.github.com/mxcl/homebrew/go</a>)
评论 #5508528 未加载
评论 #5508862 未加载
评论 #5508702 未加载
评论 #5508728 未加载
评论 #5508661 未加载
评论 #5508655 未加载
评论 #5508665 未加载
评论 #5510312 未加载
评论 #5508607 未加载
moonbootsabout 12 years ago
Bash and Zsh provide shortcuts to open a text editor where commands can be pasted and edited before running (Ctrl-x Ctrl-e in bash, need to enable in zsh [2]). I've been using this on Linux not for security but because I'm still confused by X11's primary and clipboard selections [1]. It seems like every time I try to paste a github repo link, I get the last chunk of code I copied and vice versa.<p>[1] <a href="http://www.nongnu.org/autocutsel/" rel="nofollow">http://www.nongnu.org/autocutsel/</a><p>[2] Sample .zshrc to map edit-command-line to Ctrl-x e:<p><pre><code> autoload edit-command-line zle -N edit-command-line bindkey '^Xe' edit-command-line </code></pre> edit: fixed shortcut for bash<p>edit: forgot about my .zshrc
评论 #5508350 未加载
评论 #5510287 未加载
评论 #5508736 未加载
评论 #5509371 未加载
评论 #5508357 未加载
raymondhabout 12 years ago
Nicely done! Here's the underlying source:<p><pre><code> &#60;p class="codeblock"&#62; &#60;!-- Oh noes, you found it! --&#62; git clone &#60;span style="position: absolute; left: -100px; top: -100px"&#62;/dev/null; clear; echo -n "Hello ";whoami|tr -d '\n';echo -e '!\nThat was a bad idea. Don'"'"'t copy code from websites you don'"'"'t trust!&#60;br&#62;Here'"'"'s the first line of your /etc/passwd: ';head -n1 /etc/passwd&#60;br&#62;git clone &#60;/span&#62; git://git.kernel.org/pub/scm/utils/kup/kup.git &#60;/p&#62;</code></pre>
评论 #5508368 未加载
jolissabout 12 years ago
I suspect that the only way to effectively mitigate this is in the terminal application, by displaying a confirmation <i>with the pasted text</i> before accepting any multi-line[1] paste. For example here: <a href="https://code.google.com/p/iterm2/issues/detail?id=594" rel="nofollow">https://code.google.com/p/iterm2/issues/detail?id=594</a><p>[1] There may be other dangerous characters besides newlines, e.g. escape sequences. I'm not sure if it's possible to make an exhaustive list for something like Bash. Perhaps one has to guard against <i>any</i> paste?
评论 #5508820 未加载
评论 #5508707 未加载
networkedabout 12 years ago
Perhaps the real problem here is that, as noted by Ted Nelson back when the concept started to gain popularity, "[the computer clipboard is] just like a regular clipboard, except (a) you can't see it, (b) it holds only one object, (c) whatever you put there destroys the previous contents." The presented vulnerability hinges on (a), and, Glipper [1] notwithstanding, (a)-(c) is still the default behavior in every GUI I use.<p>[1] <a href="https://launchpad.net/glipper" rel="nofollow">https://launchpad.net/glipper</a>
评论 #5509012 未加载
comexabout 12 years ago
Well... yeah, but even without hidden text, what are you going to do after you clone the repository? Probably `make` or `ruby something.rb` or any number of other commands that can run arbitrary code. If you don't trust someone, you shouldn't be trying to clone their git repo in the first place.
评论 #5508909 未加载
评论 #5508444 未加载
评论 #5508460 未加载
milesabout 12 years ago
Lynx user not affected: <a href="http://tinyapps.org/lynx_not_affected.png" rel="nofollow">http://tinyapps.org/lynx_not_affected.png</a>
评论 #5510939 未加载
hollerithabout 12 years ago
One of many examples by which making the web a better "application-delivery" platform makes it less secure, less reliable, less predictable and more tedious in its original role of sharing text, images and links.
评论 #5508372 未加载
评论 #5508415 未加载
评论 #5508362 未加载
评论 #5508814 未加载
评论 #5508437 未加载
SG-about 12 years ago
I'm confused why this is even allowed by the browsers, you shouldn't be able to send something else to the clipboard. Are there any browser extensions that can 'fix' this issue?
评论 #5508504 未加载
评论 #5508648 未加载
dave1010ukabout 12 years ago
Note: if you don't trust this, paste into a text editor!<p>It works with this CSS:<p><pre><code> position: absolute; left: -100px; top: -100px</code></pre>
评论 #5508339 未加载
评论 #5508274 未加载
LogicXabout 12 years ago
Pasted result is:<p><pre><code> git clone /dev/null; clear; echo -n "Hello ";whoami|tr -d '\n';echo -e '!\nThat was a bad idea. Don'"'"'t copy code from websites you don'"'"'t trust! Here'"'"'s the first line of your /etc/passwd: ';head -n1 /etc/passwd git clone git://git.kernel.org/pub/scm/utils/kup/kup.git</code></pre>
评论 #5508739 未加载
cirwinabout 12 years ago
Good terminal emulators (xterm, urxvt, iTerm2, etc.) have support for "bracketed paste mode" which can be used to fix this problem in zsh: <a href="https://github.com/robbyrussell/oh-my-zsh/pull/1698" rel="nofollow">https://github.com/robbyrussell/oh-my-zsh/pull/1698</a> (original code: <a href="http://www.zsh.org/mla/users/2011/msg00367.html" rel="nofollow">http://www.zsh.org/mla/users/2011/msg00367.html</a>)<p>It's probably easy to write a similar fix for bash.
评论 #5512829 未加载
andrelaszloabout 12 years ago
I usually put a # before anything I paste into a terminal. Mostly because I sometimes get a newline at the end, but it will disarm this behavior too. I'm not sure if it works in all situations though. Edit: Won't work! Use a heredoc (&#60;&#60;paste) or the editor method suggested above instead.
评论 #5508412 未加载
评论 #5508418 未加载
评论 #5508405 未加载
Tyr42about 12 years ago
Actually, since I tried to copy it by triple clicking, which selects one line (at least, I expect it to. It's what sublime text does). That didn't copy any of the malicious text, and it just stopped between the clone and the url.
评论 #5508718 未加载
Qantouriscabout 12 years ago
IMO this is the browsers fault. One expects to copy the selected (visible) text. But kinda hard to fix ...
评论 #5517675 未加载
评论 #5508539 未加载
mobwebabout 12 years ago
Wow, crazy, never really thought about this as an attack vector but it seems pretty obvious. I must confess that as a person who solves many problems by Googling I have directly pasted terminal commands from unknown websites countless times...
decholsabout 12 years ago
So the answer is to paste it into an editor first?
评论 #5508767 未加载
评论 #5508524 未加载
评论 #5510122 未加载
评论 #5509427 未加载
bluetoothabout 12 years ago
This is really just an extension of clickjacking - modifying the UI to trick the user into performing an undesired action. This is a pretty novel idea, and considering how many websites make use of this to slap their permalinks into copied text (albeit with flash, usually), I'm surprised this hasn't been thought of before.<p>It would be an interesting experiment to sneak a harmless command after every snippet on a site like commandlinefu.com.<p>Edit: Also while playing around, I remembered irssi actually has a defense against this. If you try pasting multiple lines, it can detect this. It presents you with a prompt asking if you really intended to paste &#62;5 lines into the text field. I wonder if something like this could be implemented in a shell?
评论 #5510288 未加载
评论 #5508516 未加载
mistofvongolaabout 12 years ago
This is another reason I always type a '#' before copy/pasting any long commands. The main reason is that I sometimes want to edit a long copied command and sometimes a newline get caught in my 'copy'. The '#' prevents it from accidentally executing.
评论 #5508975 未加载
评论 #5508979 未加载
评论 #5509000 未加载
jeromeparadisabout 12 years ago
That's why I always paste to my text editor and copy from there before pasting anything from a Web page.
jayferdabout 12 years ago
I mean, untarring a downloaded tarball from somewhere and running `make` is just as dangerous, right? Only there you can make sure the checksum matches, but people skip that step all the time.
评论 #5508713 未加载
评论 #5508811 未加载
评论 #5508838 未加载
评论 #5509169 未加载
ck2about 12 years ago
Can browsers fix this behavior?<p>It seems like a security hole for many reasons.<p>The default should be to copy plain text as highlighted, and advanced right click for html based copying.
vishnumenonabout 12 years ago
I was just thinking it might be cool to have a service that site owners could include via JS that would ensure that the content in a div is the content seen by the user. It could have a little stamp that says "Verified by SuchAndSuch" in the corner of the div. Should I try to make this? Any obvious issues? Is it worth it?
vxNsrabout 12 years ago
This doesn't seem like such a big deal<p>You have one of two ways to combat this: 1) always copy things to notepad first so whatever it is that you copied you can verify is what you meant to copy<p>2) Use the inspection tool of your browser to copy it from source where things can't really be hidden.<p>I usually do #1 anyway because of weird formatting and characters
munimkaziaabout 12 years ago
Did it stop working for anyone the second time? I tried it once, and it worked (gave me the warning and first line of my /etc/passwd file). I wanted to show it to a coworker but it mysteriously stopped working. It is just copying the displayed text now. Kinda weird..<p>Using Google Chrome 26.0.1410.43 on ubuntu 12.10 64bit.
seldoabout 12 years ago
Or possibly "don't follow instructions from people you don't trust", regardless of what they tell you to do.
cmsjabout 12 years ago
Out of interest, does anyone know of a Mac utility which will intercept the default paste shortcut and pop up a confirmation of what is going to be pasted, with a really quick interface to the previous few items that were copied to the clipboard?
评论 #5508738 未加载
Thrallabout 12 years ago
There is a subtle hint that all is not well if you try to select the code using triple-click: it will only select one half at a time, suggesting it is not the one-liner it appears to be...
评论 #5513075 未加载
kylloabout 12 years ago
Yes, but not just that. It's also important to make an effort to understand what commands you are typing into your shell before typing them (Google them first if you don't know).
fidzabout 12 years ago
In bitbucket, you could simply copy paste <i>clone command in the text field</i>. Isn't text field is far more safe since there should no hidden element?
Achsharabout 12 years ago
Select the text and right click to copy. The trick is over when the "search google for 'malicious text' comes up instead of the command in chrome.
评论 #5509557 未加载
gyepiabout 12 years ago
FWIW, I use shell mode in emacs most of the time and it happily accepts, and buffers, multiline commands until you hit enter, unlike the terminal.
anarchotrollabout 12 years ago
Copying with pentadactyl using Y shows exactly what has been copied on the status line at the bottom of the screen.
melicerteabout 12 years ago
what I usually do before pasting insecure clipboard content to a terminal is that I start with a double quotes character " Once I see the real output, I just have to remove the quotes (&#60;ctrl-a&#62; &#60;del&#62;&#60;return&#62;)
pnathanabout 12 years ago
Well done, sir.<p>Thanks for bringing this up.
Justsignedupabout 12 years ago
ok, honestly, where is the ability to disable clipboard manipulation or similar techniques? Browsers need to do this. I have NEVER seen value if a website's ability to modify my clipboard.
评论 #5511610 未加载
keekdownabout 12 years ago
Hmmm...I just hasn’t been thinking about such things
jpswadeabout 12 years ago
Unless it's from a trusted source...
chickopozoabout 12 years ago
How is this news? Its been done so many times I've lost count.
umarranaabout 12 years ago
shit you almost killed me