我是靠谱客的博主 踏实钢笔,这篇文章主要介绍Python打造漏洞扫描器 7 扫描器之敏感目录爆破,现在分享给大家,希望可以做个参考。

扫描器之敏感目录爆破

一、实验介绍

1.1 实验内容

通过调用字典访问url通过网页返回的状态来判断是否存在此目录。

1.2 实验知识点

  • requests
  • threading

1.3 实验环境

  • python2.7
  • Xfce终端

1.4 适合人群

本课程难度为一般,属于初级级别课程,适合具有Python基础的用户,熟悉python基础知识加深巩固。

1.5 代码获取

你可以通过下面命令将代码下载到实验楼环境中,作为参照对比进行学习。

复制代码
1
2
$ wget http://labfile.oss.aliyuncs.com/courses/761/shiyanlouscan7.zip

二、开发准备

在项目目录data新建一个dir.txt,里面的内容为url目录字典。可以自己创建也可以从 shiyanlouscan7.zip中获取。

三、实验步骤

3.1 简述

敏感目录爆破,通过字典爆破网站目录结构,可能会得到敏感的目录结构

如果学习过之前的几章,这节课是非常的轻车熟路了。主要就是两个python库threading requests的使用。

3.2 装载字典文件

在 lib/core 中创建 webdir.py 文件。

首先将字典文件加入到队列中,设置一些需要初始化的值。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
def __init__(self,root,threadNum): self.root = root self.threadNum = threadNum self.headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20', 'Referer': 'http://www.shiyanlou.com', 'Cookie': 'whoami=w8ay', } self.task = Queue.Queue() self.s_list = [] filename = os.path.join(sys.path[0], "data", "dir.txt") for line in open(filename): self.task.put(root + line.strip())

3.3 检测网页状态

为了提升检测网站的速度,我们只需要用head访问网页头来判断返回的状态码即可:

复制代码
1
2
3
4
5
6
7
8
9
def checkdir(self,url): status_code = 0 try: r = requests.head(url,headers=self.headers) status_code = r.status_code except: status_code = 0 return status_code

3.4 线程函数

线程函数主要是从队列中取出数据,然后循环访问。

复制代码
1
2
3
4
5
6
7
8
def test_url(self): while not self.task.empty(): url = self.task.get() s_code = self.checkdir(url) if s_code==200: self.s_list.append(url) print "Testing: %s status:%s"%(url,s_code)

3.5 工作线程

work函数是调用的主函数,通过work函数来启动线程,开始任务。

复制代码
1
2
3
4
5
6
7
8
9
10
def work(self): threads = [] for i in range(self.threadNum): t = threading.Thread(target=self.test_url()) threads.append(t) t.start() for t in threads: t.join() print('[*] The DirScan is complete!')

3.6 输出函数

在工作线程test_url中我们有

复制代码
1
2
3
if s_code==200: self.s_list.append(url)

这样一段代码,s_list是访问成功得到的列表,输出函数我们输出列表s_list即可:

复制代码
1
2
3
4
5
6
def output(): if len(self.s_list): print "[*] status = 200 dir:" for url in s_list: print url

我设定的是状态码为200的时候才会加入,当然大家也可以在工作线程test_url设置状态码不等于404的时候加入。

3.7 代码整理

总代码如下:

复制代码
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
#!/usr/bin/env python # __author__= 'w8ay' import os import sys import Queue import requests import threading class webdir: def __init__(self,root,threadNum): self.root = root self.threadNum = threadNum self.headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20', 'Referer': 'http://www.shiyanlou.com', 'Cookie': 'whoami=w8ay', } self.task = Queue.Queue() self.s_list = [] filename = os.path.join(sys.path[0], "data", "dir.txt") for line in open(filename): self.task.put(root + line.strip()) def checkdir(self,url): status_code = 0 try: r = requests.head(url,headers=self.headers) status_code = r.status_code except: status_code = 0 return status_code def test_url(self): while not self.task.empty(): url = self.task.get() s_code = self.checkdir(url) if s_code==200: self.s_list.append(url) print "Testing: %s status:%s"%(url,s_code) def work(self): threads = [] for i in range(self.threadNum): t = threading.Thread(target=self.test_url()) threads.append(t) t.start() for t in threads: t.join() print('[*] The DirScan is complete!') def output(): if len(self.s_list): print "[*] status = 200 dir:" for url in s_list: print url

3.8 集成到扫描器

单个模块我们当然可以单独使用了,不过我们可以通过调用扫描器来使用。
将模块加入扫描程序主文件 w8ay.py中。

此处输入图片的描述

不要忘了 import 我们的 webdir 模块

现在。我们的扫描器运行流程是:

  1. 域名->转换ip->端口扫描
  2. 敏感目录扫描
  3. CMS识别
  4. 爬虫信息收集 ->基于爬虫的各类模块

四、实验总结

这个版本的敏感目录扫描时最为初级的扫描工具,在实际当中,如果网站有防火墙,waf之类的东西都可以轻易的防住这些扫描,该如何突破呢?方法很多,有兴趣可以自行查询资料。

最后

以上就是踏实钢笔最近收集整理的关于Python打造漏洞扫描器 7 扫描器之敏感目录爆破的全部内容,更多相关Python打造漏洞扫描器内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部