一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術(shù)及教程分享平臺(tái)!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - Python開發(fā)網(wǎng)站目錄掃描器的實(shí)現(xiàn)

Python開發(fā)網(wǎng)站目錄掃描器的實(shí)現(xiàn)

2021-05-31 00:41一清 Python

這篇文章主要介紹了Python開發(fā)網(wǎng)站目錄掃描器的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

有人問為什么要去掃描網(wǎng)站目錄:懂的人自然懂

這個(gè)python腳本的特點(diǎn):

1.基本完善

2.界面美觀(只是畫了個(gè)圖案)

3.可選參數(shù)增加了線程數(shù)

4.user agent細(xì)節(jié)處理

5.多線程顯示進(jìn)度

掃描目標(biāo):metasploitable linux

代碼:webdirscanner.py:

?
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
# -*- coding:utf-8 -*-
__author__ = "yiqing"
import sys
import threading
import random
from queue import queue
from optparse import optionparser
 
try:
  import requests
except exception:
  print "[!] you need to install requests module!"
  print "[!] usage:pip install requests"
  exit()
 
 
class webdirscan:
  """
  web目錄掃描器
  """
 
  def __init__(self, options):
    self.url = options.url
    self.file_name = options.file_name
    self.count = options.count
 
  class dirscan(threading.thread):
    """
    多線程
    """
 
    def __init__(self, queue, total):
      threading.thread.__init__(self)
      self._queue = queue
      self._total = total
 
    def run(self):
      while not self._queue.empty():
        url = self._queue.get()
        # 多線程顯示進(jìn)度
        threading.thread(target=self.msg).start()
        try:
          r = requests.get(url=url, headers=get_user_agent(), timeout=5)
          if r.status_code == 200:
            sys.stdout.write('\r' + '[+]%s\t\t\n' % url)
            # 保存到本地文件,以html的格式
            result = open('result.html', 'a+')
            result.write('<a href="' + url + '" rel="external nofollow" target="_blank">' + url + '</a>')
            result.write('\r\n</br>')
            result.close()
        except exception:
          pass
 
    def msg(self):
      """
      顯示進(jìn)度
      :return:none
      """
      per = 100 - float(self._queue.qsize()) / float(self._total) * 100
      percent = "%s finished| %s all| scan in %1.f %s" % (
        (self._total - self._queue.qsize()), self._total, per, '%')
      sys.stdout.write('\r' + '[*]' + percent)
 
  def start(self):
    result = open('result.html', 'w')
    result.close()
    queue = queue()
    f = open('dict.txt', 'r')
    for i in f.readlines():
      queue.put(self.url + "/" + i.rstrip('\n'))
    total = queue.qsize()
    threads = []
    thread_count = int(self.count)
    for i in range(thread_count):
      threads.append(self.dirscan(queue, total))
    for thread in threads:
      thread.start()
    for thread in threads:
      thread.join()
 
 
def get_user_agent():
  """
  user agent的細(xì)節(jié)處理
  :return:
  """
  user_agent_list = [
    {'user-agent': 'mozilla/4.0 (mozilla/4.0; msie 7.0; windows nt 5.1; fdm; sv1; .net clr 3.0.04506.30)'},
    {'user-agent': 'mozilla/4.0 (compatible; msie 8.0; windows nt 6.0; en) opera 11.00'},
    {
      'user-agent': 'mozilla/5.0 (x11; u; linux i686; de; rv:1.9.0.2) gecko/2008092313 ubuntu/8.04 (hardy) firefox/3.0.2'},
    {
      'user-agent': 'mozilla/5.0 (x11; u; linux i686; en-gb; rv:1.9.1.15) gecko/20101027 fedora/3.5.15-1.fc12 firefox/3.5.15'},
    {
      'user-agent': 'mozilla/5.0 (x11; u; linux i686; en-us) applewebkit/534.10 (khtml, like gecko) chrome/8.0.551.0 safari/534.10'},
    {'user-agent': 'mozilla/5.0 (x11; u; linux i686; en-us; rv:1.9.0.2) gecko/2008092809 gentoo firefox/3.0.2'},
    {
      'user-agent': 'mozilla/5.0 (x11; u; linux x86_64; en-us) applewebkit/534.10 (khtml, like gecko) chrome/7.0.544.0'},
    {'user-agent': 'opera/9.10 (windows nt 5.2; u; en)'},
    {
      'user-agent': 'mozilla/5.0 (iphone; u; cpu os 3_2 like mac os x; en-us) applewebkit/531.21.10 (khtml, like gecko)'},
    {'user-agent': 'opera/9.80 (x11; u; linux i686; en-us; rv:1.9.2.3) presto/2.2.15 version/10.10'},
    {
      'user-agent': 'mozilla/5.0 (windows; u; windows nt 5.1; ru-ru) applewebkit/533.18.1 (khtml, like gecko) version/5.0.2 safari/533.18.5'},
    {'user-agent': 'mozilla/5.0 (windows; u; windows nt 5.1; ru; rv:1.9b3) gecko/2008020514 firefox/3.0b3'},
    {
      'user-agent': 'mozilla/5.0 (macintosh; u; ppc mac os x 10_4_11; fr) applewebkit/533.16 (khtml, like gecko) version/5.0 safari/533.16'},
    {
      'user-agent': 'mozilla/5.0 (macintosh; u; intel mac os x 10_6_6; en-us) applewebkit/534.20 (khtml, like gecko) chrome/11.0.672.2 safari/534.20'},
    {
      'user-agent': 'mozilla/4.0 (compatible; msie 8.0; windows nt 6.1; wow64; trident/4.0; slcc2; .net clr 2.0.50727; infopath.2)'},
    {'user-agent': 'mozilla/4.0 (compatible; msie 6.0; x11; linux x86_64; en) opera 9.60'},
    {
      'user-agent': 'mozilla/5.0 (macintosh; u; intel mac os x 10_6_2; en-us) applewebkit/533.4 (khtml, like gecko) chrome/5.0.366.0 safari/533.4'},
    {'user-agent': 'mozilla/5.0 (windows nt 6.0; u; en; rv:1.8.1) gecko/20061208 firefox/2.0.0 opera 9.51'}
  ]
 
  return random.choice(user_agent_list)
 
 
def main():
  """
  主函數(shù)
  :return: none
  """
  print '''
   ____ _   ____        
  | _ \(_)_ __/ ___| ___ __ _ _ __
  | | | | | '__\___ \ / __/ _` | '_ \
  | |_| | | |  ___) | (_| (_| | | | |
  |____/|_|_| |____/ \___\__,_|_| |_|
 
  welcome to webdirscan
  version:1.0 author: %s
  ''' % __author__
  parser = optionparser('python webdirscanner.py -u <target url> -f <dictionary file name> [-t <thread_count>]')
  parser.add_option('-u', '--url', dest='url', type='string', help='target url for scan')
  parser.add_option('-f', '--file', dest='file_name', type='string', help='dictionary filename')
  parser.add_option('-t', '--thread', dest='count', type='int', default=10, help='scan thread count')
  (options, args) = parser.parse_args()
  if options.url and options.file_name:
    dirscan = webdirscan(options)
    dirscan.start()
    sys.exit(1)
  else:
    parser.print_help()
    sys.exit(1)
 
 
if __name__ == '__main__':
  main()

需要一個(gè)字典文件:

我存進(jìn)去了一些,一部分是確定存在的目錄

dict.txt

?
1
2
3
4
5
6
7
index.php
login
dvwa
phpmyadmin
dav
twiki
login.php

結(jié)果:得到一個(gè)html文件:

?
1
2
3
4
5
6
7
<a href="http://192.168.232.129/twiki" rel="external nofollow" target="_blank">http://192.168.232.129/twiki</a>
 
</br><a href="http://192.168.232.129/index.php" rel="external nofollow" target="_blank">http://192.168.232.129/index.php</a>
 
</br><a href="http://192.168.232.129/phpmyadmin" rel="external nofollow" target="_blank">http://192.168.232.129/phpmyadmin</a>
 
</br>

腳本的使用:

Python開發(fā)網(wǎng)站目錄掃描器的實(shí)現(xiàn)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://www.cnblogs.com/xuyiqing/p/10313775.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本欧美不卡一区二区三区在线 | 国产午夜精品理论片 | 禁止的爱善良的未删减版hd | 高清不卡一区 | 特级夫妻大片免费在线播放 | 精品国产一区二区三区久久久蜜臀 | 九九大香尹人视频免费 | 男男视频18免费网站 | 五月天网站 | 精品国产免费久久久久久 | 精品视频一区在线观看 | 性欧美xxxxxxx另类 | 5g影院天天影院天天爽影院网站 | 精品久久成人 | 短篇同学新婚h系列小说 | 亚洲福利视频在线观看 | 成人福利网| 花蝴蝶www| 免费一区| 久久精品国产清白在天天线 | 香蕉91| 亚洲大尺码 | 2021国产麻豆剧传媒剧情 | 星星动漫在线观看无删减 | 久久视频这有精品63在线国产 | 国产va免费精品高清在线 | 高清毛片aaaaaaaaa片 | 国产欧美日韩精品一区二区三区 | 国产一区二区免费不卡在线播放 | 精品视频久久久久 | 久久视频在线视频观看天天看视频 | 色老板视频在线 | 日韩美女强理论片 | 国产精品亚洲片夜色在线 | 亚洲第五色综合网啪啪 | 男人亚洲天堂 | 色综合视频在线观看 | 成人福利网站含羞草 | 精品一卡2卡3卡4卡5卡亚洲 | jizz女16处| 网址在线观看你懂我意思吧免费的 |