程序员都应该了解哪些安全知识

fmms 12年前
     <p>        导读:本文来自 StackOverflow 上的一个问答贴。网友 M.H 提问: 我是一名 IT 专业学生,现在是大三,直到现在我们才开始学习很多计算机相关的课程(编程、算法、计算机体系结构、数学等……)。</p>    <p>        但是还有一个叫“安全”的世界离我们很远,我是指:计算机安全、互联网安全、网络安全、Hacking、破解等。 </p>    <p>        我很确信没有人可以知晓所有安全知识,但我确信,肯定有一定的“最低限度”知识,是每个程序员或 IT 学生应当了解的。我的问题是,那些“最低限度”知识包括了哪些?希望您能给我建议一些电子书,或课程,或任何有助于我探索这条路的东西。</p>    <p>        目前这个问题得分最高的回复是由 <a href="/misc/goto?guid=4958334670340671615" rel="nofollow" target="_blank">bignum</a> 提供的,如下:</p>    <p>        如果想要你的程序是安全的,请记住如下原则:</p>    <p>        <strong>● 不要信任用户的输入信息!</strong></p>    <p>        ● 验证所有来自非信任源的输入信息,是使用白名单,不是黑名单。</p>    <p>        ● 从一开始就要策划安全。安全并不是可以在最后来做的。</p>    <p>        ● 保持简单。复杂性会增加安全漏洞的可能性。</p>    <p>        ● 最低限度保持你程序的攻击面(<a href="/misc/goto?guid=4958334671148635018" rel="nofollow" target="_blank">attack surface</a>)。</p>    <p>        ● 确保程序有“自动防故障装置”(<a href="/misc/goto?guid=4958334671944274473" rel="nofollow" target="_blank">Fail-safe</a>)</p>    <p>        ● 采用深度防御(<a href="/misc/goto?guid=4958334672736784830" rel="nofollow" target="_blank">defence in depth</a>)</p>    <p>        ● 坚持最小特权原则(<a href="/misc/goto?guid=4958334673531526358" rel="nofollow" target="_blank">least privilege</a>)</p>    <p>        ● 采用威胁建模(<a href="/misc/goto?guid=4958334674326084770" rel="nofollow" target="_blank">threat modelling</a>)(Web 程序更应如此)</p>    <p>        ● 权限分离(<a href="/misc/goto?guid=4958334675125617264" rel="nofollow" target="_blank">Compartmentalize</a>)</p>    <p>        ● 没有不透风的墙,在代码中隐藏秘密都无法长久。</p>    <p>        ● Don’t write your own crypto / 不要自己编写一种加密方法 (译注:见下文另外一位网友的回复)</p>    <p>        ● 采用加密(crypto),并不意味着你就安全了(攻击者会寻找弱点)</p>    <p>        ● 注意缓冲区溢出,并了解如何防范</p>    <p>        下面是一些优秀书籍和在线文章:</p>    <p>        ●《<a href="/misc/goto?guid=4958334675920090895" rel="nofollow" target="_blank"> Writng Secure Code   编写安全的代码 (第二版)</a>》- 我认为每个程序员都该读读这本书 (译注:第二版还没有中文,据说在翻译中……)</p>    <p style="text-align:center;"><a title="Writing Secure Code, Second Edition" rel="lightbox[16240]"><img title="Writing Secure Code, Second Edition" alt="程序员都应该了解哪些安全知识" src="https://simg.open-open.com/show/19bd4206ff84f626b6f5074db1a082f8.jpg" width="300" height="300" /></a></p>    <p>        ● <a href="/misc/goto?guid=4958334676722760221" rel="nofollow" target="_blank">Building Secure Software: How to Avoid Security Problems the Right Way 构建安全的软件:避免产生软件安全问题的正确方法</a></p>    <p style="text-align:center;"><a title="Building Secure Software - How to Avoid Security Problems the Right Way" rel="lightbox[16240]"><img title="Building Secure Software - How to Avoid Security Problems the Right Way" alt="程序员都应该了解哪些安全知识" src="https://simg.open-open.com/show/a06d2519f74cb81ce8db7a05dd12ebb7.jpg" width="300" height="300" /></a></p>    <p>        ● <a href="/misc/goto?guid=4958334677532424511" rel="nofollow" target="_blank">Secure Programming Cookbook for C and C++: Recipes for Cryptography, Authentication, Input Validation & More</a></p>    <p style="text-align:center;"><a title="Secure Programming Cookbook" rel="lightbox[16240]"><img title="Secure Programming Cookbook" alt="程序员都应该了解哪些安全知识" src="https://simg.open-open.com/show/1e75a6b9ab06be37586af8c303a09b51.jpg" width="300" height="300" /></a></p>    <p>        ● <a href="/misc/goto?guid=4958334678333662237" rel="nofollow" target="_blank">Exploiting Software</a> (译注:在线电子书)</p>    <p>        ● <a href="/misc/goto?guid=4958334679137598490" rel="nofollow" target="_blank">Security Engineering</a> (an excellent read,在线电子书)</p>    <p>        ●<a href="/misc/goto?guid=4958334679928962920" rel="nofollow" target="_blank"> Secure Programming for Linux and Unix HOWTO</a> (译注:在线电子书)</p>    <p>        <a href="/misc/goto?guid=4958334680723977166" rel="nofollow" target="_blank">Tyler McHenry</a> 也给出了他认为程序员做安全的第一原则:<strong>Don’t roll your own</strong>。除非你是安全专家或密码破译专家,否则就采用现有的成熟安全平台、框架、或库。这些东西都经过了专家和黑客们深思熟虑、修补、更新和检测。你得利用这些优势,而不是忽视,试图推到<a title="重来" href="http://www.amazon.cn/gp/product/B0048EKQS0/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&tag=vastwork-23&linkCode=as2&camp=536&creative=3200&creativeASIN=B0048EKQS0" rel="nofollow" target="_blank">重来</a>。</p>    <p>        英文原文:<a href="/misc/goto?guid=4958334682254586014" rel="nofollow" target="_blank">StackOverflow</a>    编译:<a href="/misc/goto?guid=4958185140659301754" target="_blank">伯乐</a>在线 – <a href="/misc/goto?guid=4958334683776671019" target="_blank">黄利民</a></p>