├── .gitignore ├── LICENSE ├── README.md ├── SUMMARY.md ├── ch1.md ├── ch10.md ├── ch2.md ├── ch3.md ├── ch4.md ├── ch5.md ├── ch6.md ├── ch7.md ├── ch8.md ├── ch9.md ├── cover.jpg ├── img ├── .gitignore ├── 1-1-1.jpg ├── 1-1-2.jpg ├── 1-1-3.jpg ├── 1-2-1.jpg ├── 1-2-2.jpg ├── 1-2-3.jpg ├── 1-3-1.jpg ├── 1-3-2.jpg ├── 1-4-1.jpg ├── 1-4-2.jpg ├── 1-5-1.jpg ├── 1-5-2.jpg ├── 1-5-3.jpg ├── 1-6-1.jpg ├── 1-6-2.jpg ├── 1-6-3.jpg ├── 1-7-1.jpg ├── 1-7-2.jpg ├── 1-7-3.jpg ├── 1-7-4.jpg ├── 1-8-1.jpg ├── 1-8-2.jpg ├── 1-8-3.jpg ├── 1-8-4.jpg ├── 2-1-1.jpg ├── 2-1-2.jpg ├── 2-1-3.jpg ├── 2-10-1.jpg ├── 2-10-2.jpg ├── 2-10-3.jpg ├── 2-10-4.jpg ├── 2-10-5.jpg ├── 2-2-1.jpg ├── 2-2-2.jpg ├── 2-2-3.jpg ├── 2-2-4.jpg ├── 2-3-1.jpg ├── 2-4-1.jpg ├── 2-4-2.jpg ├── 2-4-3.jpg ├── 2-4-4.jpg ├── 2-5-1.jpg ├── 2-5-2.jpg ├── 2-6-1.jpg ├── 2-6-2.jpg ├── 2-6-3.jpg ├── 2-6-4.jpg ├── 2-7-1.jpg ├── 2-7-2.jpg ├── 2-7-3.jpg ├── 2-8-1.jpg ├── 2-9-1.jpg ├── 2-9-2.jpg ├── 3-1-1.jpg ├── 3-1-2.jpg ├── 3-2-1.jpg ├── 3-2-2.jpg ├── 3-3-1.jpg ├── 3-3-2.jpg ├── 3-3-3.jpg ├── 3-3-4.jpg ├── 3-4-1.jpg ├── 3-4-2.jpg ├── 3-4-3.jpg ├── 3-4-4.jpg ├── 3-4-5.jpg ├── 3-4-6.jpg ├── 3-4-7.jpg ├── 3-5-1.jpg ├── 3-5-2.jpg ├── 3-5-3.jpg ├── 3-5-4.jpg ├── 3-6-1.jpg ├── 3-6-2.jpg ├── 3-6-3.jpg ├── 3-6-4.jpg ├── 4-1-1.jpg ├── 4-1-2.jpg ├── 4-1-3.jpg ├── 4-1-4.jpg ├── 4-10-1.jpg ├── 4-10-2.jpg ├── 4-10-3.jpg ├── 4-11-1.jpg ├── 4-2-1.jpg ├── 4-2-2.jpg ├── 4-2-3.jpg ├── 4-3-1.jpg ├── 4-3-2.jpg ├── 4-3-3.jpg ├── 4-3-4.jpg ├── 4-3-5.jpg ├── 4-4-1.jpg ├── 4-4-2.jpg ├── 4-4-3.jpg ├── 4-4-4.jpg ├── 4-5-1.jpg ├── 4-5-2.jpg ├── 4-5-3.jpg ├── 4-5-4.jpg ├── 4-5-5.jpg ├── 4-6-1.jpg ├── 4-6-2.jpg ├── 4-6-3.jpg ├── 4-7-1.jpg ├── 4-7-2.jpg ├── 4-7-3.jpg ├── 4-8-1.jpg ├── 4-9-1.jpg ├── 4-9-2.jpg ├── 4-9-3.jpg ├── 5-1-1.jpg ├── 5-1-2.jpg ├── 5-2-1.jpg ├── 5-2-2.jpg ├── 5-2-3.jpg ├── 5-3-1.jpg ├── 5-3-2.jpg ├── 5-3-3.jpg ├── 5-3-4.jpg ├── 5-3-5.jpg ├── 5-4-1.jpg ├── 5-4-2.jpg ├── 5-4-3.jpg ├── 5-4-4.jpg ├── 5-4-5.jpg ├── 5-5-1.jpg ├── 5-5-2.jpg ├── 5-5-3.jpg ├── 5-5-4.jpg ├── 5-6-1.jpg ├── 5-6-2.jpg ├── 5-6-3.jpg ├── 6-1-1.jpg ├── 6-1-2.jpg ├── 6-1-3.jpg ├── 6-1-4.jpg ├── 6-1-5.jpg ├── 6-10-1.jpg ├── 6-10-2.jpg ├── 6-10-3.jpg ├── 6-10-4.jpg ├── 6-10-5.jpg ├── 6-10-6.jpg ├── 6-2-1.jpg ├── 6-2-2.jpg ├── 6-2-3.jpg ├── 6-2-4.jpg ├── 6-2-5.jpg ├── 6-3-1.jpg ├── 6-3-2.jpg ├── 6-3-3.jpg ├── 6-3-4.jpg ├── 6-4-1.jpg ├── 6-4-2.jpg ├── 6-4-3.jpg ├── 6-5-1.jpg ├── 6-5-2.jpg ├── 6-5-3.jpg ├── 6-5-4.jpg ├── 6-5-5.jpg ├── 6-5-6.jpg ├── 6-6-1.jpg ├── 6-6-2.jpg ├── 6-6-3.jpg ├── 6-6-4.jpg ├── 6-6-5.jpg ├── 6-7-1.jpg ├── 6-7-2.jpg ├── 6-7-3.jpg ├── 6-7-4.jpg ├── 6-7-5.jpg ├── 6-7-6.jpg ├── 6-8-1.jpg ├── 6-8-2.jpg ├── 6-8-3.jpg ├── 6-8-4.jpg ├── 6-9-1.jpg ├── 6-9-2.jpg ├── 6-9-3.jpg ├── 7-1-1.jpg ├── 7-1-2.jpg ├── 7-1-3.jpg ├── 7-2-1.jpg ├── 7-2-2.jpg ├── 7-2-3.jpg ├── 7-2-4.jpg ├── 7-2-5.jpg ├── 7-3-1.jpg ├── 7-3-2.jpg ├── 7-3-3.jpg ├── 7-3-4.jpg ├── 7-3-5.jpg ├── 7-3-6.jpg ├── 7-4-1.jpg ├── 7-4-10.jpg ├── 7-4-11.jpg ├── 7-4-12.jpg ├── 7-4-13.jpg ├── 7-4-14.jpg ├── 7-4-15.jpg ├── 7-4-2.jpg ├── 7-4-3.jpg ├── 7-4-4.jpg ├── 7-4-5.jpg ├── 7-4-6.jpg ├── 7-4-7.jpg ├── 7-4-8.jpg ├── 7-4-9.jpg ├── 7-5-1.jpg ├── 7-5-2.jpg ├── 7-5-3.jpg ├── 7-5-4.jpg ├── 7-6-1.jpg ├── 7-6-2.jpg ├── 7-6-3.jpg ├── 7-6-4.jpg ├── 7-6-5.jpg ├── 7-6-6.jpg ├── 7-6-7.jpg ├── 7-7-1.jpg ├── 7-7-2.jpg ├── 7-7-3.jpg ├── 7-7-4.jpg ├── 7-7-5.jpg ├── 7-7-6.jpg ├── 7-7-7.jpg ├── 7-7-8.jpg ├── 7-8-1.jpg ├── 7-8-2.jpg ├── 7-8-3.jpg ├── 7-9-1.jpg ├── 7-9-2.jpg ├── 7-9-3.jpg ├── 8-0-1.jpg ├── 8-1-1.jpg ├── 8-1-2.jpg ├── 8-1-3.jpg ├── 8-1-4.jpg ├── 8-2-1.jpg ├── 8-2-2.jpg ├── 8-2-3.jpg ├── 8-2-4.jpg ├── 8-3-1.jpg ├── 8-3-2.jpg ├── 8-3-3.jpg ├── 8-3-4.jpg ├── 8-4-1.jpg ├── 8-5-1.jpg ├── 8-5-2.jpg ├── 8-5-3.jpg ├── 8-6-1.jpg ├── 8-6-2.jpg ├── 8-6-3.jpg ├── 9-1-1.jpg ├── 9-1-2.jpg ├── 9-1-3.jpg ├── 9-1-4.jpg ├── 9-2-1.jpg ├── 9-2-2.jpg ├── 9-3-1.jpg ├── 9-3-2.jpg ├── 9-3-3.jpg ├── 9-3-4.jpg ├── 9-4-1.jpg ├── 9-4-2.jpg ├── 9-4-3.jpg ├── 9-5-1.jpg ├── 9-5-2.jpg ├── 9-5-3.jpg ├── 9-5-4.jpg └── qr_alipay.png └── styles └── ebook.css /.gitignore: -------------------------------------------------------------------------------- 1 | _book 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License (CC BY-NC-SA 4.0) 2 | 3 | Copyright © 2020 ApacheCN(apachecn@163.com) 4 | 5 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 6 | 7 | Section 1 – Definitions. 8 | 9 | a. Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 10 | b. Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 11 | c. BY-NC-SA Compatible License means a license listed at creativecommons.org/compatiblelicenses, approved by Creative Commons as essentially the equivalent of this Public License. 12 | d. Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 13 | e. Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 14 | f. Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 15 | g. License Elements means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution, NonCommercial, and ShareAlike. 16 | h. Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 17 | i. Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 18 | j. Licensor means the individual(s) or entity(ies) granting rights under this Public License. 19 | k. NonCommercial means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange. 20 | l. Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 21 | m. Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 22 | n. You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 23 | 24 | Section 2 – Scope. 25 | 26 | a. License grant. 27 | 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 28 | A. reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and 29 | B. produce, reproduce, and Share Adapted Material for NonCommercial purposes only. 30 | 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 31 | 3. Term. The term of this Public License is specified in Section 6(a). 32 | 4. Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 33 | 5. Downstream recipients. 34 | A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 35 | B. Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply. 36 | C. No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 37 | 6. No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 38 | b. Other rights. 39 | 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 40 | 2. Patent and trademark rights are not licensed under this Public License. 41 | 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes. 42 | 43 | Section 3 – License Conditions. 44 | 45 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 46 | 47 | a. Attribution. 48 | 1. If You Share the Licensed Material (including in modified form), You must: 49 | A. retain the following if it is supplied by the Licensor with the Licensed Material: 50 | i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 51 | ii. a copyright notice; 52 | iii. a notice that refers to this Public License; 53 | iv. a notice that refers to the disclaimer of warranties; 54 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 55 | B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 56 | C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 57 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 58 | 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 59 | b. ShareAlike. 60 | In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. 61 | 1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-NC-SA Compatible License. 62 | 2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. 63 | 3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. 64 | 65 | Section 4 – Sui Generis Database Rights. 66 | 67 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 68 | 69 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only; 70 | b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and 71 | c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 72 | 73 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 74 | 75 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 76 | 77 | a. Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You. 78 | b. To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You. 79 | c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 80 | 81 | Section 6 – Term and Termination. 82 | 83 | a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 84 | b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 85 | 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 86 | 2. upon express reinstatement by the Licensor. 87 | For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 88 | c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 89 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 90 | 91 | Section 7 – Other Terms and Conditions. 92 | 93 | a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 94 | b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 95 | 96 | Section 8 – Interpretation. 97 | 98 | a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 99 | b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 100 | c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 101 | d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kali Linux Web 渗透测试秘籍 中文版 2 | 3 | > 原书:[Kali Linux Web Penetration Testing Cookbook](https://www.packtpub.com/networking-and-servers/kali-linux-web-penetration-testing-cookbook) 4 | > 5 | > 译者:[飞龙](https://github.com/wizardforcel) 6 | > 7 | > 第二版请见[ Kali Linux Web 渗透测试手册(第二版)](https://github.com/xuanhun/HackingResource#kali-linux-%E6%B8%97%E9%80%8F%E6%B5%8B%E8%AF%95%E6%89%8B%E5%86%8C%E7%AC%AC2%E7%89%88) 8 | 9 | + [在线阅读](https://www.gitbook.com/book/wizardforcel/kali-linux-web-pentest-cookbook/details) 10 | + [PDF格式](https://www.gitbook.com/download/pdf/book/wizardforcel/kali-linux-web-pentest-cookbook) 11 | + [EPUB格式](https://www.gitbook.com/download/epub/book/wizardforcel/kali-linux-web-pentest-cookbook) 12 | + [MOBI格式](https://www.gitbook.com/download/mobi/book/wizardforcel/kali-linux-web-pentest-cookbook) 13 | + [Github](https://github.com/wizardforcel/kali-linux-web-pentest-cookbook-zh) 14 | + [Git@OSC](http://git.oschina.net/wizardforcel/kali-linux-web-pentest-cookbook-zh) 15 | 16 | ## 赞助我 17 | 18 | ![](img/qr_alipay.png) 19 | 20 | ## 协议 21 | 22 | [CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/) 23 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | + [Kali Linux Web 渗透测试秘籍 中文版](README.md) 2 | + [第一章 配置 Kali Linux](ch1.md) 3 | + [第二章 侦查](ch2.md) 4 | + [第三章 爬虫和蜘蛛](ch3.md) 5 | + [第四章 漏洞发现](ch4.md) 6 | + [第五章 自动化扫描](ch5.md) 7 | + [第六章 利用 -- 低悬的果实](ch6.md) 8 | + [第七章 高级利用](ch7.md) 9 | + [第八章 中间人攻击](ch8.md) 10 | + [第九章 客户端攻击和社会工程](ch9.md) 11 | + [第十章 OWASP Top 10 的预防](ch10.md) -------------------------------------------------------------------------------- /ch1.md: -------------------------------------------------------------------------------- 1 | # 第一章 配置 Kali Linux 2 | 3 | > 作者:Gilberto Najera-Gutierrez 4 | 5 | > 译者:[飞龙](https://github.com/) 6 | 7 | > 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/) 8 | 9 | ## 简介 10 | 11 | 在第一章中,我们会涉及如何准备我们的 Kali 以便能够遵循这本书中的秘籍,并使用虚拟机建立带有存在漏洞的 Web 应用的实验室。 12 | 13 | ## 1.1 升级和更新 Kali 14 | 15 | 在我们开始 Web 应用安全测试之前,我们需要确保我们拥有所有必要的最新工具。这个秘籍涉及到使 Kali 和它的工具保持最新版本的基本步骤。 16 | 17 | ### 准备 18 | 19 | 我们从 Kali 已经作为主操作系统安装到计算机上,并带有网络连接来开始。这本书中所使用的版本为 2.0。你可以从 下载 live CD 和安装工具。 20 | 21 | ### 操作步骤 22 | 23 | 一旦你的 Kali 实例能够启动和运行,执行下列步骤: 24 | 25 | 1. 以 root 登录 Kali。默认密码是 toor,不带双引号。你也可以使用`su`来切换到该用户,或者如果喜欢使用普通用户而不是 root 的话,用`sudo`来执行单条命令。 26 | 27 | 2. 打开终端。 28 | 29 | 3. 运行`apt-get update`命令。这会下载可用于安装的包(应用和工具)的更新列表。 30 | 31 | ``` 32 | apt-get update 33 | ``` 34 | 35 | ![](img/1-1-1.jpg) 36 | 37 | 4. 一旦安装完成,执行下列命令来将非系统的包更新到最新的稳定版。 38 | 39 | ``` 40 | apt-get upgrade 41 | ``` 42 | 43 | ![](img/1-1-2.jpg) 44 | 45 | 5. 当被询问是否继续时,按下`Y`并按下回车。 46 | 47 | 6. 下面,让我们升级我们的系统。键入下列命令并按下回车: 48 | 49 | ``` 50 | apt-get dist-upgrade 51 | ``` 52 | 53 | ![](img/1-1-3.jpg) 54 | 55 | 7. 现在,我们更新了 Kali 并准备好了继续。 56 | 57 | ### 工作原理 58 | 59 | 这个秘籍中,我们涉及到了更新基于 Debian 的系统(比如 Kali)的基本步骤。首先以`update`参数调用`apt-get`来下载在所配置的仓库中,用于我们的特定系统的包的最新列表。下载和安装仓库中最新版本的所有包之后,`dist-update`参数下载和安装`upgrade`没有安装的系统包(例如内核和内核模块)。 60 | 61 | > 这本书中,我们假设 Kali 已经作为主操作系统在电脑上安装。也可以将它安装在虚拟机中。这种情况下,要跳过秘籍“安装 VirtualBox”,并按照“为正常通信配置虚拟机”配置 Kali VM 的网络选项。 62 | 63 | ### 更多 64 | 65 | 有一些工具,例如 Metasploit 框架,拥有自己的更新命令。可以在这个秘籍之后执行它们。命令在下面: 66 | 67 | ``` 68 | msfupdate 69 | ``` 70 | 71 | ## 1.2 安装和运行 OWASP Mantra 72 | 73 | OWASP(开放 Web 应用安全项目,)中的研究员已经将 Mozilla FIrefox 与 大量的插件集成,这些插件用于帮助渗透测试者和开发者测试 Web 应用的 bug 或安全缺陷。这个秘籍中,我们会在 Kali 上安装 OWASP Mantra(),首次运行它,并查看一些特性。 74 | 75 | 大多数 Web 应用渗透测试都通过浏览器来完成。这就是我们为什么需要一个带有一组工具的浏览器来执行这样一个任务。OWASP Mantra 包含一系列插件来执行任务,例如: 76 | 77 | + 嗅探和拦截 HTTP 请求 78 | 79 | + 调试客户端代码 80 | 81 | + 查看和修改 Cookie 82 | 83 | + 收集关于站点和应用的信息 84 | 85 | ### 准备 86 | 87 | 幸运的是, OWASP Mantra 默认包含于 Kali 的仓库中。所以,要确保我们获得了浏览器的最新版本,我们需要更新包列表: 88 | 89 | ``` 90 | apt-get update 91 | ``` 92 | 93 | ### 操作步骤 94 | 95 | 1. 打开终端并执行: 96 | 97 | ``` 98 | apt-get install owasp-mantra-ff 99 | ``` 100 | 101 | ![](img/1-2-1.jpg) 102 | 103 | 2. 在安装完成之后,访问菜单:` Applications | 03 - Web Application Analysis | Web Vulnerability Scanners | owasp-mantra-ff`来首次启动 Mantra。或者在终端中输入下列命令: 104 | 105 | ``` 106 | owasp-mantra-ff 107 | ``` 108 | 109 | ![](img/1-2-2.jpg) 110 | 111 | 3. 在新打开的浏览器中,点击 OWASP 图标之后点击`Tools`。这里我们可以访问到所有 OWASP Mantra 包含的工具。 112 | 113 | ![](img/1-2-3.jpg) 114 | 115 | 4. 我们会在之后的章节中使用这些工具。 116 | 117 | ### 另见 118 | 119 | 你可能也对 Mantra on Chromium (MOC)感兴趣,这是 Mantra 的一个替代版本,基于 Chromium 浏览器。当前,它只对 Windows 可用:。 120 | 121 | ## 1.3 配置 Iceweasel 浏览器 122 | 123 | 如果我们不喜欢 OWASP Mantra,我们可以使用 Firefox 的最新版本,并安装我们自己的测试相关插件。Kali Linux 包含了 Iceweasel,另一个 Firefox 的变体。我们这里会使用它来看看如何在它上面安装我们的测试工具。 124 | 125 | ### 操作步骤 126 | 127 | 1. 打开 Iceweasel 并访问`Tools | Add-ons`。就像下面的截图这样: 128 | 129 | ![](img/1-3-1.jpg) 130 | 131 | 2. 在搜素框中,输入`tamper data `并按下回车。 132 | 133 | ![](img/1-3-2.jpg) 134 | 135 | 3. 在`Tamper Data `插件中点击`Install`。 136 | 137 | 4. 对话框会弹出,询问我们接受 EULA,点击`Accept and Install...`。 138 | 139 | > 你可能需要重启你的浏览器来完成特定插件的安装。 140 | 141 | 5. 下面,我们在搜索框中搜索`cookies manager+ `。 142 | 143 | 6. 在`cookies manager+ `插件中点击`Install`。 144 | 145 | 7. 现在,搜索`Firebug`。 146 | 147 | 8. 搜索和安装`Hackbar`。 148 | 149 | 9. 搜索和安装` HTTP Requester`。 150 | 151 | 0. 搜索和安装`Passive Recon`。 152 | 153 | ### 工作原理 154 | 155 | 目前为止,我们在 Web 浏览器中安装了一些工具,但是对 Web 应用渗透测试者来说,这些工具好在哪里呢? 156 | 157 | + `Cookies Manager+`:这个插件允许我们查看,并有时候修改浏览器从应用受到的 Cookie 的值。 158 | 159 | + `Firebug`:这是任何 Web 开发者的必需品。它的主要功能是网页的内嵌调试器。它也在你对页面执行一些客户端修改时非常有用。 160 | 161 | + `Hackbar`:这是一个非常简单的插件,帮助我们尝试不同的输入值,而不需要修改或重写完整的 URL。在手动检查跨站脚本工具和执行注入的时候,我们会很频繁地使用它。 162 | 163 | + `Http Requester`:使用这个工具,我们就能构造 HTTP 链接,包括 GET、POST 和 PUT 方法,并观察来自服务器的原始响应。 164 | 165 | + `Passive Recon`:它允许我们获得关于网站被访问的公共信息,通过查询 DNS 记录、WHOIS、以及搜索信息,例如邮件地址、链接和 Google 中的合作者。 166 | 167 | + `Tamper Data`:这个插件能够在请求由浏览器发送之后,捕获任何到达服务器的请求。这提供给我们了在将数据引入应用表单之后,在它到达服务器之前修改它的机会。 168 | 169 | ### 更多 170 | 171 | 有一些插件同样对 Web 应用渗透测试者有用,它们是: 172 | 173 | + XSS Me 174 | + SQL Inject Me 175 | + FoxyProxy 176 | + iMacros 177 | + FirePHP 178 | + RESTClient 179 | + Wappalyzer 180 | 181 | ## 1.4 安装 VirtualBox 182 | 183 | 这是我们的第四篇秘籍,会帮助我们建立虚拟机环境,并运行它来实施我们的渗透测试。我们会使用 VirtualBox 在这样的环境中运行主机。这个秘籍中,我们会了解如何安装 VirtualBox 以及使它正常工作。 184 | 185 | ### 准备 186 | 187 | 在我们在 Kali 中安装任何东西之前,我们都必须确保我们拥有最新版本的包列表: 188 | 189 | ``` 190 | apt-get update 191 | ``` 192 | 193 | ### 操作步骤 194 | 195 | 1. 我们首先实际安装 VirtualBox: 196 | 197 | ``` 198 | apt-get install virtualbox 199 | ``` 200 | 201 | ![](img/1-4-1.jpg) 202 | 203 | 2. 安装完成之后,我们要在菜单中寻找 VirtualBox,通过访问`Applications | Usual applications | Accessories | VirtualBox`。作为替代,我们也可以从终端调用它: 204 | 205 | ``` 206 | virtualbox 207 | ``` 208 | 209 | ![](img/1-4-2.jpg) 210 | 211 | 现在,我们运行了 VirtualBox 并且已经准备好配置虚拟机来构建我们自己的测试环境。 212 | 213 | ### 工作原理 214 | 215 | VirtualBox 允许我们在我们的 Kali 主机上通过虚拟化运行多个主机。通过它,我们可以使用不同的计算机和操作系统来挂载完整的环境。并同时运行它们,只要 Kali 主机的内存资源和处理能力允许。 216 | 217 | ### 更多 218 | 219 | 虚拟机扩展包,提供了 VirtualBox 的虚拟机附加特性,例如 USB 2.0/3.0 支持和远程桌面功能。它可以从 下载。在下载完成后双击它,VirtualBox 会做剩余的事情。 220 | 221 | ### 另见 222 | 223 | 除此之外有一些可视化选项。如果你使用过程中感到不方便,你可以尝试: 224 | 225 | + VMware Player/Workstation 226 | + Qemu 227 | + Xen 228 | + KVM 229 | 230 | ## 1.5 创建漏洞虚拟机 231 | 232 | 现在我们准备好创建我们的第一个虚拟机,它是托管 Web 应用的服务器,我们使用应用来实践和提升我们的渗透测试技巧。 233 | 234 | 我们会使用叫做 OWASP BWA( Broken Web Apps)的虚拟机,它是存在漏洞的 Web 应用的集合,特别为执行安全测试而建立。 235 | 236 | ### 操作步骤 237 | 238 | 1. 访问 ,并下载最新版本的`.ova`文件。在本书写作过程中,它是`OWASP_Broken_Web_Apps_ VM_1.1.1.ova`。 239 | 240 | ![](img/1-5-1.jpg) 241 | 242 | 2. 等待下载完成,之后打开文件: 243 | 244 | 3. VirtualBox 的导入对话框会显示。如果你打算修改机器名称或描述,你可以通过双击值来完成。我们会命名为`vulnerable_vm`,并且使剩余选项保持默认。点击`Import`。 245 | 246 | ![](img/1-5-2.jpg) 247 | 248 | 4. 导入需要花费一分钟,之后我们会看到我们的虚拟机显示在 VirtualBox 的列表中。让我们选中它并点击`Start`。 249 | 250 | 5. 在机器启动之后,我们会被询问登录名和密码,输入`root`作为登录名,`owaspbwa`作为密码,这样设置。 251 | 252 | ![](img/1-5-3.jpg) 253 | 254 | ### 工作原理 255 | 256 | OWASP BWA 是一个项目,致力于向安全从业者和爱好者提供安全环境,用于提升攻击技巧,并识别和利用 Web 应用中的漏洞,以便帮助开发者和管理员修复和防止漏洞。 257 | 258 | 这个虚拟机包含不同类型的 Web 应用,一些基于 PHP,一些基于 Java,甚至还有一些基于 .NET 的漏洞应用。也有一些已知应用的漏洞版本,例如 WordPress 或 Joomla。 259 | 260 | ### 另见 261 | 262 | 当我们谈论漏洞应用和虚拟机的时候,有很多选择。有一个著名网站含有大量的此类应用,它是 VulnHub(`https:// www.vulnhub.com/`)。它也有一些思路,帮助你解决一些挑战并提升你的技能。 263 | 264 | 这本书中,我们会为一些秘籍使用另一个虚拟机: bWapp Bee-box。它也可以从 VulnHub 下载:。 265 | 266 | ## 1.6 获取客户端虚拟机 267 | 268 | 当我们执行中间人攻击(MITM)和客户端攻击时,我们需要另一台虚拟机来向已经建立的服务器发送请求。这个秘籍中,我们会下载 Microsoft Windows 虚拟机并导入到 VirtualBox 中。 269 | 270 | ### 操作步骤 271 | 272 | 1. 首先我们需要访问下载站点 。 273 | 274 | 2. 这本书中,我们会在 Win7 虚拟机中使用 IE8。 275 | 276 | ![](img/1-6-1.jpg) 277 | 278 | 3. 文件下载之后,我们需要解压它。访问它下载的位置。 279 | 280 | 4. 右击它并点击`Extract Here`(解压到此处)。 281 | 282 | 5. 解压完成后,打开`.ova`文件并导入到 VirtualBox 中。 283 | 284 | ![](img/1-6-2.jpg) 285 | 286 | 6. 现在启动新的虚拟机(名为`IE8 - Win7`),我们就准备好客户端了。 287 | 288 | ![](img/1-6-3.jpg) 289 | 290 | ### 工作原理 291 | 292 | Microsoft 向开发者提供了这些虚拟机来在不同的 Windows 和 IE 版本上测试它们的应用,带有 30 天的免费许可,这足以用于实验了。 293 | 294 | 作为渗透测试者,意识到真实世界的应用可能位于多个平台,这些应用的用户可能使用大量的不同系统和 Web 浏览器来和互相通信非常重要。知道了这个之后,我们应该使用任何客户端/服务器的设施组合,为成功的渗透测试做准备。 295 | 296 | ### 另见 297 | 298 | 对于服务端和客户端的虚拟机,如果你在使用已经构建好的配置时感到不便,你总是可以构建和配置你自己的虚拟机。这里是一些关于如何实现的信息:。 299 | 300 | ## 1.7 为正常通信配置虚拟机 301 | 302 | 为了能够和我们的虚拟服务器和客户端通信,我们需要位于相同网段内。但是将带有漏洞的虚拟机放到局域网中可能存在安全风险。为了避免它,我们会在 VirtualBox 中做一个特殊的配置,允许我们在 Kali 中和服务器及客户端虚拟机通信,而不将它们暴露给网络。 303 | 304 | ### 准备 305 | 306 | 在我们开始之前,打开 VirtualBox 并且宝漏洞服务器和客户端虚拟机都关闭了。 307 | 308 | ### 操作步骤 309 | 310 | 1. 在 VirtualBox 中访问`File | Preferences… | Network`。 311 | 312 | 2. 选择`Host-only Networks`标签页。 313 | 314 | 3. 点击`+`按钮来添加新网络。 315 | 316 | 4. 新的网络(`vboxnet0`)会创建,它的详细窗口会弹出。如果没有,选项网络并点击编辑按钮来编辑它的属性。 317 | 318 | ![](img/1-7-1.jpg) 319 | 320 | 5. 在对话框中,你可以指定网络配置。如果它不影响你的本地网络配置,将其保留默认。你也可以修改它并使用其它为局域网保留的网段中的地址,例如 10.0.0.0/8、172.16.0.0/12、192.168.0.0/16。 321 | 322 | 6. 合理配置之后,点击`OK`。 323 | 324 | 7. 下一步是配置漏洞虚拟机(vulnerable_vm)。选择它并访问它的设置。 325 | 326 | 8. 点击`Network `并且在`Attached to:`下拉菜单中,选择` Host-only Adapter`。 327 | 328 | 9. 在`Name`中,选择`vboxnet0`。 329 | 330 | 0. 点击`OK`。 331 | 332 | ![](img/1-7-2.jpg) 333 | 334 | 1. 在客户端虚拟机(`IE8 - Win7`)中执行第七步到第十步。 335 | 336 | 2. 在配置完两个虚拟机之后,让我们测试它们是否能真正通信。启动两个虚拟机。 337 | 338 | 3. 让我们看看宿主系统的网络通信:打开终端并输入: 339 | 340 | ``` 341 | ifconfig 342 | ``` 343 | 344 | ![](img/1-7-3.jpg) 345 | 346 | 4. 我们可以看到我们拥有叫做`vboxnet0 `的网络适配器,并且它的 IP 地址为 192.168.56.1。取决于你所使用的配置,这可能有所不同。 347 | 348 | 5. 登录 vulnerable_vm 并检查适配器`eth0`的 IP 地址。 349 | 350 | ``` 351 | ifconfig 352 | ``` 353 | 354 | 6. 现在,让我们访问我们的客户端主机`IE8 - Win7`。打开命令行提示符并输入: 355 | 356 | ``` 357 | ipconfig 358 | ``` 359 | 360 | 7. 现在,我们拥有了三台机器上的 IP 地址。 361 | 362 | + 192.168.56.1 :宿主机 363 | + 192.168.56.102 :vulnerable_vm 364 | + 192.168.56.103 :IE8 - Win7 365 | 366 | 8. 为了测试通信,我们打算从宿主机中 ping 两个虚拟机。 367 | 368 | ``` 369 | ping -c 4 192.168.56.102 370 | ping -c 4 192.168.56.103 371 | ``` 372 | 373 | ![](img/1-7-4.jpg) 374 | 375 | ping 会发送 ICMP 请求给目标,并等待回复。这在测试网络上两个节点之间是否可以通信的时候非常有用。 376 | 377 | 9. 我们对两个虚拟机做相同操作,来检车到服务器和到另一台虚拟机的通信是否正常。 378 | 379 | 0. IE8 - Win7 虚拟机可能不响应 ping,这是正常的,因为 Win7 的配置默认不响应 ping。为了检查连接性,我们可以从 Kali 主机使用`arping`。 380 | 381 | ``` 382 | arping –c 4 192.168.56.103 383 | ``` 384 | 385 | ### 工作原理 386 | 387 | 仅有主机的网络是虚拟网络,它的行为像 LAN,但是它仅仅能够访问宿主机,所运行的虚拟机不会暴露给外部系统。这种网络也为宿主机提供了虚拟适配器来和虚拟机通信,就像它们在相同网段那样。 388 | 389 | 使用我们刚刚完成的配置,我们就能够在客户端和服务器之间通信,二者都可以跟 Kali 主机通信,Kali 会作为攻击主机。 390 | 391 | ## 1.8 了解漏洞 VM 上的 Web 应用 392 | 393 | OWASP BWA 包含许多 Web 应用,其内部含有常见攻击的漏洞。它们中的一些专注于一些特定技巧的实验,而其它尝试复制碰巧含有漏洞的,真实世界的应用。 394 | 395 | 这个秘籍中,我们会探索 vulnerable_vm,并了解一些其中包含的应用。 396 | 397 | ### 准备 398 | 399 | 我们需要启动我们的 vulnerable_vm,并正确配置它的网络。这本书中,我们会使用 192.168.56.102 作为它的 IP 地址。 400 | 401 | ### 操作步骤 402 | 403 | 1. vulnerable_vm 启动后,打开 Kali 主机的 Web 浏览器并访问`http://192.168.56.102`。你会看到服务器所包含的所有应用列表。 404 | 405 | ![](img/1-8-1.jpg) 406 | 407 | 2. 让我们访问`Damn Vulnerable Web Application`。 408 | 409 | 3. 使用`admin`作为用户名,`admin`作为密码。我们可以看到左边的菜单:菜单包含我们可以实验的所有漏洞的链接:爆破、命令执行、SQL 注入,以及其它。同样,DVWA 安全这部分是我们用于配置漏洞输入的安全(或复杂性)等级的地方。 410 | 411 | ![](img/1-8-2.jpg) 412 | 413 | 4. 登出并返回服务器的主页。 414 | 415 | 5. 现在我们点击`OWASP WebGoat.NET`。这是个 .NET 应用,其中我们可以实验文件和代码注入攻击,跨站脚本,和加密漏洞。它也含有 WebGoat Coins Customer Portal,它模拟了商店应用,并可以用于实验漏洞利用和漏洞识别。 416 | 417 | ![](img/1-8-3.jpg) 418 | 419 | 6. 现在返回服务器的主页。 420 | 421 | 7. 另一个包含在虚拟机中的有趣应用是 BodgeIt。它是基于 JSP 的在线商店的最小化版本。它拥有我们可以加入购物车的商品列表,带有高级选项的搜索页面,为新用户准备的注册表单,以及登录表单。这里没有到漏洞的直接引用,反之,我们需要自己找它们。 422 | 423 | ![](img/1-8-4.jpg) 424 | 425 | 8. 我们在一个秘籍中不能浏览所有应用,但是我们会在这本书中使用它们。 426 | 427 | ### 工作原理 428 | 429 | 主页上的应用组织为六组: 430 | 431 | + 训练应用:这些应用分为几部分,专注于实验特定的漏洞或攻击技巧。他它们中的一些包含教程、解释或其他形式的指导。 432 | 433 | + 真实的,内部含有漏洞的应用:这些应用的行为就像真实世界的应用(商店】博客或社交网络)一样,但是开发者出于训练目的在内部设置了漏洞。 434 | 435 | + 真实应用的旧(漏洞)版本:真是应用的旧版本,例如 WordPress 和 Joomla 含有已知的可利用的漏洞。这对于测试我们的漏洞识别技巧非常实用。 436 | 437 | + 用于测试工具的应用:这个组中的应用可以用做自动化漏洞扫描器的基准线测试。 438 | 439 | + 演示页面/小应用:这些小应用拥有一个或一些漏洞,仅仅出于演示目的。 440 | 441 | + OWASP 演示应用:OWASP AppSensor 是个有趣的应用,它模拟了社交网络并含有一些漏洞。但是他会记录任何攻击的意图,这在尝试学习的时候很有帮助。例如,如何绕过一些安全设备,例如网络应用防火墙。 442 | -------------------------------------------------------------------------------- /ch10.md: -------------------------------------------------------------------------------- 1 | # 第十章 OWASP Top 10 的预防 2 | 3 | > 作者:Gilberto Najera-Gutierrez 4 | 5 | > 译者:[飞龙](https://github.com/) 6 | 7 | > 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/) 8 | 9 | ## 简介 10 | 11 | 每个渗透测试的目标都是识别应用、服务器或网络中的可能缺陷,它们能够让攻击者有机会获得敏感系统的信息或访问权限。检测这类漏洞的原因不仅仅是了解它们的存在以及推断出其中的漏洞,也是为了努力预防它们或者将它们降至最小。 12 | 13 | 这一章中,我们会观察一些如何预防多数 Web 应用漏洞的例子和推荐,根据 OWASP: 14 | 15 | https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project 16 | 17 | ## A1 预防注入攻击 18 | 19 | 根据 OWASP,Web 应用中发现的最关键的漏洞类型就是一些代码的注入攻击,例如 SQL 注入、OS 命令注入、HTML 注入(XSS)。 20 | 21 | 这些漏洞通常由应用的弱输入校验导致。这个秘籍中,我们会设计一些处理用户输入和构造所使用的请求的最佳实践。 22 | 23 | ### 操作步骤 24 | 25 | 1. 为了防止注入攻击,首先需要合理校验输入。在服务端,这可以由编写我们自己的校验流程来实现,但是最佳选择是使用语言自己的校验流程,因为它们更加广泛使用并测试过。一个极好的激励就是 PHP 中的` filter_var `,或者 ASP.NET 中的 校验助手。例如,PHP 中的邮箱校验类似于: 26 | 27 | ```php 28 | function isValidEmail($email){ 29 | return filter_var($email, FILTER_VALIDATE_EMAIL); 30 | } 31 | ``` 32 | 33 | 2. 在客户端,检验可以由创建 JavaScript 校验函数来完成,使用正则表达式。例如,邮箱检验流程是: 34 | 35 | ```js 36 | function isValidEmail (input) { 37 | var result=false; 38 | var email_regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[azA-Z0-9.-]{2,4}$/; 39 | if ( email_regex.test(input) ) { 40 | result = true; 41 | } 42 | return result; 43 | } 44 | ``` 45 | 46 | 3. 对于 SQL 注入,避免拼接输入值为查询十分关键。反之,使用参数化查询。每个编程语言都有其自己的版本: 47 | 48 | PHP MySQLLi: 49 | 50 | ```php 51 | $query = $dbConnection->prepare('SELECT * FROM table WHERE name = ?'); 52 | $query->bind_param('s', $name); 53 | $query->execute(); 54 | ``` 55 | 56 | C#: 57 | 58 | ```csharp 59 | string sql = "SELECT * FROM Customers WHERE CustomerId = @ CustomerId"; 60 | SqlCommand command = new SqlCommand(sql); command.Parameters.Add(new SqlParameter("@CustomerId", System. Data.SqlDbType.Int)); 61 | command.Parameters["@CustomerId"].Value = 1; 62 | ``` 63 | 64 | Java: 65 | 66 | ```java 67 | String custname = request.getParameter("customerName"); 68 | String query = "SELECT account_balance FROM user_data WHERE user_ name =? "; 69 | PreparedStatement pstmt = connection.prepareStatement( query ); 70 | pstmt.setString( 1, custname); 71 | ResultSet results = pstmt.executeQuery( ); 72 | ``` 73 | 74 | 4. 考虑注入出现的时机,对减少可能的损失总量也有帮助。所以,使用低权限的系统用户来运行数据库和 Web 服务器。 75 | 76 | 5. 确保输入用于连接数据库服务器的用户不是数据库管理员。 77 | 78 | 6. 禁用甚至删除允许攻击者执行系统命令或提权的储存过程,例如 MSSQL 服务器中的`xp_cmdshell `。 79 | 80 | ### 工作原理 81 | 82 | 预防任何类型代码注入攻击的主要部分永远是合理的输入校验,位于服务端也位于客户端。 83 | 84 | 对于 SQL 注入,始终使用参数化或者预编译查询。而不是拼接 SQL 语句和输入。参数化查询将函数参数插入到 SQL 语句特定的位置,消除了程序员通过拼接构造查询的需求。 85 | 86 | 这个秘籍中,我们使用了语言内建的校验函数,但是如果你需要校验一些特殊类型的参数,你可以通过使用正则表达式创建自己的版本。 87 | 88 | 除了执行正确校验,我们也需要在一些人蓄意注入一些代码的情况下,降低沦陷的影响。这可以通过在操作系统的上下文中为 Web 服务器合理配置用户权限,以及在数据库服务器上下文中配置数据库和 OS 来实现。 89 | 90 | ### 另见 91 | 92 | 对于数据校验来讲,最有用的工具就是正则表达式。在处理和过滤大量信息的时候,它们也能够让渗透测试变得更容易。所以好好了解它们很有必要。我推荐你查看一些站点: 93 | 94 | + http://www.regexr.com/ 一个很好的站点,其中我们可以获得示例和参数并测试我们自己的表达式来查看是否有字符串匹配。 95 | 96 | + http://www.regular-expressions.info 它包含教程和实例来了解如何使用正则表达式。它也有一份实用的参考,关于主流语言和工具的特定实现。 97 | 98 | + http://www.princeton.edu/~mlovett/reference/Regular-Expressions.pdf (Jan Goyvaerts 编写的《Regular Expressions, The Complete Tutorial》)就像它的标题所说,它是个正则表达式的非常完备的脚本,包含许多语言的示例。 99 | 100 | ## A2 构建合理的身份验证和会话管理 101 | 102 | 带有缺陷的身份验证和会话管理是当今 Web 应用中的第二大关键的漏洞。 103 | 104 | 身份验证是用户证明它们是它们所说的人的过程。这通常通过用户名和密码来完成。一些该领域的常见缺陷是宽松的密码策略,以及隐藏式的安全(隐藏资源缺乏身份验证)。 105 | 106 | 会话管理是登录用户的会话标识符的处理。在 Web 服务器中,这可以通过实现会话 Cookie 和标识来完成。这些标识符可以植入、盗取,或者由攻击者使用社会工程、XSS 或 CSRF 来“劫持”。所以,开发者必须特别注意如何管理这些信息。 107 | 108 | 这个秘籍中,我们会设计到一些实现用户名/密码身份验证,以及管理登录用户的会话标识符的最佳实践。 109 | 110 | ### 操作步骤 111 | 112 | 1. 如果应用中存在只能由授权用户查看的页面、表单或者任何信息片段,确保在展示它们之前存在合理的身份验证。 113 | 114 | 2. 确保用户名、ID、密码和所有其它身份验证数据是大小写敏感的,并且对每个用户唯一。 115 | 116 | 3. 建立强密码策略,强迫用户创建至少满足下列条件的密码: 117 | 118 | + 对于 8 个字符,推荐 10 个。 119 | + 使用大写和小写字母。 120 | + 至少使用一个数字。 121 | + 至少使用一个特殊字符(空格、` !`、`&`、`#`、`%`,以及其它)。 122 | + 禁止用户名、站点名称、公司名称或者它们的变体(大小写转换、l33t、它们的片段)用于密码。 123 | + 禁止使用“常见密码”列表中的密码:https://www.teamsid.com/worst-passwords-2015/ 。 124 | + 永远不要显示用户是否存在或者信息格式是否正确的错误信息。对不正确的登录请求、不存在的用户、名称或密码不匹配模式、以及所有可能的登录错误使用相同的泛化信息。这种信息类似于: 125 | 126 | 登录数据不正确。 127 | 128 | 用户名或密码无效。 129 | 130 | 访问禁止。 131 | 132 | 4. 密码不能以纯文本格式储存在数据库中。使用强哈希算法,例如 SHA-2、scrypt、或者 bcrypt,它们特别为难以使用 GPU 破解而设计。 133 | 134 | 5. 在对比用户输入和密码时,计算输入的哈希之后比较哈希之后的字符串。永远不要解密密码来使用纯文本用户输入来比较。 135 | 136 | 6. 避免基本的 HTML 身份验证。 137 | 138 | 7. 可能的话,使用多因素验证(MFA),这意味着使用不止一个身份验证因素来登录: 139 | 140 | + 一些你知道的(账户信息或密码) 141 | 142 | + 一些你拥有的(标识或手机号) 143 | 144 | + 一些你的特征(生物计量) 145 | 146 | 8. 如果可能的话,实现证书、预共享密钥、或其它无需密码的身份校验协议(OAuth2、OpenID、SAML、或者 FIDO)。 147 | 148 | 9. 对于会话管理,推荐使用语言内建的会话管理系统,Java、ASP.NET和 PHP。它们并不完美,但是能够确保提供设计良好和广泛测试的机制,而且比起开发团队在时间紧迫情况下的自制版本,它们更易于实现。 149 | 150 | 0. 始终为登录和登录后的页面使用 HTTPS -- 显然,要防止只接受 SSL 和 TLS v1.1 连接。 151 | 152 | 1. 为了确保 HTTPS 能够生效,可以使用 HSTS。它是由 Web 应用指定的双向选择的特性。通过 Strict-Transport-Security 协议头,它在 `http://`存在于 URL 的情况下会重定向到安全的选项,并防止“无效证书”信息的覆写。例如使用 Burp Suite 的时候会出现的情况。更多信息请见: https://www.owasp.org/index.php/HTTP_Strict_Transport_Security 。 153 | 154 | 2. 始终设置 HTTPOnly 和安全的 Cookie 属性。 155 | 156 | 3. 设置最少但实际的会话过期时间。确保正常用户离开之后,攻击者不能复用会话,并且用户能够执行应用打算执行的操作。 157 | 158 | ### 工作原理 159 | 160 | 身份校验机制通常在 Web 应用中简化为用户名/密码登录页面。虽然并不是最安全的选择,但它对于用户和开发者最简单,以及当密码被盗取时,最重要的层面就是它们的强度。 161 | 162 | 我们可以从这本书看到,密码强度由破解难度决定,通过爆破、字典或猜测。这个秘籍的第一个提示是为了使密码更难以通过建立最小长度的混合字符集来破解,难以通过排除更直觉的方案(用户名、常见密码、公司名称)来猜测,并且通过使用强哈希或加密储存,难以在泄露之后破解。 163 | 164 | 对于会话管理来说,过期时间、唯一性和会话 ID 的强度(已经在语言内建机制中实现),以及 Cookie 设置中的安全都是关键的考虑因素。 165 | 166 | 谈论身份校验安全的最重要的层面是,如果消息可以通过中间人攻击拦截或者服务,没有任何安全配置、控制或强密码是足够安全的。所以,合理配置的加密通信频道的使用,例如 TLS,对保护我们的用户身份数据来说极其重要。 167 | 168 | ### 另见 169 | 170 | OWASP 拥有一些非常好的页面,关于身份校验和会话管理。我们推荐你在构建和配置 Web 应用时阅读并仔细考虑它们。 171 | 172 | + https://www.owasp.org/index.php/Authentication_Cheat_Sheet 173 | + https://www.owasp.org/index.php/Session_Management_Cheat_Sheet 174 | 175 | ## A3 预防跨站脚本 176 | 177 | 我们之前看到,跨站脚本,在展示给用户的数据没有正确编码,并且浏览器将其解释并执行为脚本代码时发生。这也存在输入校验因素,因为恶意代码通常由输入变量插入。 178 | 179 | 这个秘籍中,我们会涉及开发者所需的输入校验和输出编码,来防止应用中的 XSS 漏洞。 180 | 181 | ### 工作原理 182 | 183 | 1. 应用存在 XSS 漏洞的第一个标志是,页面准确反映了用户提供的输入。所以,尝试不要使用用户提供的信息来构建输出文本。 184 | 185 | 2. 当你需要将用户提供的信息放在输出页面上时,校验这些数据来防止任何类型代码的插入。我们已经在 A1 中看到如何实现它。 186 | 187 | 3. 出于一些原因,如果用户被允许输入特殊字符或者代码段,在它插入到输出之前,过滤或合理编码文本。 188 | 189 | 4. 对于过滤,在 PHP 中,可以使用`filter_var `。例如,如果你想让字符串为邮件地址: 190 | 191 | ```php 192 | $email = "john(.doe)@exa//mple.com"; 193 | $email = filter_var($email, FILTER_SANITIZE_EMAIL); 194 | echo $email; 195 | ``` 196 | 197 | 对于编码,你可以在 PHP 中使用`htmlspecialchars `: 198 | 199 | ```php 200 | $str = "The JavaScript HTML tags are 228 | ``` 229 | 230 | ![](img/4-5-4.jpg) 231 | 232 | 页面会执行脚本,并弹出提示框,表明这个页面上存在跨站脚本漏洞。 233 | 234 | 6. 现在检查源码来观察输入中发生了什么。 235 | 236 | ![](img/4-5-5.jpg) 237 | 238 | 我们的输入看起来作为 HTML 的一部分来处理。浏览器解释了`