安全与隐私thejh.net编辑精选
不要从网页复制粘贴到终端
Don't Copy-Paste from Website to Terminal
2013 — 2015,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这个页面演示了一个经典的终端安全陷阱:网页上显示的代码可以包含肉眼看不见的隐藏内容(如屏幕外定位的 span),复制粘贴到终端执行时,隐藏的恶意命令会一并运行。作者用一个看似无害的 git clone 命令做演示,粘贴后实际执行了读取 /etc/passwd 的脚本,以此提醒用户不要盲目从网页复制命令到终端。
为什么经久不衰:curl | bash 式安装至今仍是主流做法,这个演示提醒人们粘贴的文本未必是你看到的内容,安全意识历久弥新。
HN 评论精选
讽刺业界流行的 curl 管道执行模式比复制粘贴更危险
既然业界通行做法是直接执行 curl 的输出,比如 ruby -e "$(curl -fsSL ...)",我何必费劲复制粘贴到剪贴板呢?
NelsonMinar查看英文原文
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? ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)
揭示演示的具体实现原理:用 CSS 隐藏恶意命令
干得漂亮!这是底层源码:代码块里藏了一个绝对定位到屏幕外的 span,内容是 /dev/null; clear; echo ... 读取 /etc/passwd 第一行的恶意命令。
raymondh查看英文原文
Nicely done! Here's the underlying source: <p class="codeblock"> <!-- Oh noes, you found it! --> git clone <span style="position: absolute; left: -100px; top: -100px">/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!<br>Here'"'"'s the first line of your /etc/passwd: ';head -n1 /etc/passwd<br>git clone </span> git://git.kernel.org/pub/scm/utils/kup/kup.git </p>
建议从终端应用层面增加粘贴确认来根治问题
我认为唯一有效的缓解方法是在终端应用层面:粘贴多行内容前先显示确认。除了换行符,还可能有其他危险字符如转义序列,也许得防范任何粘贴。
joliss查看英文原文
I suspect that the only way to effectively mitigate this is in the terminal application, by displaying a confirmation with the pasted text before accepting any multi-line[1] paste. For example here: https://code.google.com/p/iterm2/issues/detail?id=594 [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 any paste?
指出浏览器审查无法防范服务器按 UA 返回不同内容
另外,用浏览器查看 curl | bash 的文件内容并不足够。服务器很容易根据 User-Agent 检测出 curl/wget,对不同请求返回不同内容。应该先把内容存成本地文件,读过之后再决定是否运行。
Goopplesoft查看英文原文
Aside: its not sufficient to look at a file you 'curl | bash' into bash via your browser. It is very trivial to detect curl/wget's UA (mine has: "User-Agent": "curl/7.43.0") and dynamically modify files depending on the request's UI. if 'curl' in request.UA: return 'something malicious' else: return 'something nice' Always create a local file with the content, read it, then perhaps run it.
历次讨论
同类还值得读
非法素数
Illegal prime
维基百科条目,介绍“非法素数”:某些素数之所以被称为“非法”,是因为它们经特定编码后,恰好对应一段被法律禁止传播的数据——最著名的是 DVD 解密程序 DeCSS 的代码,有人把…
安全与隐私上首页 5 次 · 2010–2021en.wikipedia.org编辑精选关于 /dev/urandom 的常见误区
Myths about /dev/urandom
(Thomas Hühn 撰写,2014 年首发并持续更新)逐条反驳关于 /dev/urandom 的常见误解:它与 /dev/random 使用的是同一个 CSPRNG,一旦完…
安全与隐私上首页 5 次 · 2014–20202uo.de编辑精选AES 高级加密标准火柴人图解
A Stick Figure Guide to the Advanced Encryption Standard (AES)
一篇用火柴人漫画形式讲解 AES(高级加密标准)算法的经典科普文章。
安全与隐私上首页 5 次 · 2009–2022moserware.com编辑精选指纹是用户名,不是密码
Fingerprints are Usernames, not Passwords
作者(eCryptfs 维护者、Ubuntu 安全工程师)认为指纹等生物特征是公开、不可更改的标识,应视作用户名而非密码,不能当作秘密凭据用于认证。
安全与隐私上首页 4 次 · 2013–2017blog.dustinkirkland.comHTTPS 连接的最初几毫秒(2009)
The First Few Milliseconds of an HTTPS Connection (2009)
逐毫秒拆解一次 HTTPS 连接建立时发生了什么,重点讲 TLS 握手、证书验证、RSA 签名与密钥协商等机制,面向不熟悉该领域的读者。
安全与隐私上首页 4 次 · 2009–2020moserware.com编辑精选