WebDAV 方法实战检测:OPTIONS/PUT/DELETE 等 8 种方法自动化探测与利用

WebDAV 方法自动化检测与实战利用指南

1. WebDAV 方法安全风险全景分析

WebDAV(Web Distributed Authoring and Versioning)作为HTTP协议的扩展,为远程协作编辑提供了强大支持,但同时也引入了显著的安全隐患。不同于传统HTTP方法,WebDAV特有的PROPFIND、LOCK、MOVE等方法在设计之初就考虑了文件系统级别的操作权限,这使得一旦配置不当,攻击者可能获得对服务器资源的过度控制。

核心风险方法矩阵

方法类型典型风险场景潜在攻击影响
PROPFIND目录遍历攻击敏感文件结构泄露
PUT任意文件上传WebShell植入
DELETE资源删除服务不可用攻击
MOVE/COPY文件重定向权限绕过攻击
LOCK资源锁定拒绝服务攻击

注意:实际测试中需严格遵守授权范围,未经许可的测试可能违反法律法规

现代Web服务器如Apache和Nginx的默认配置通常已禁用这些高风险方法,但以下场景仍可能存在漏洞:

  • 企业协作平台中的WebDAV模块
  • 遗留系统维护界面
  • 错误配置的云存储服务
  • 自定义开发的API端点

2. 自动化检测工具链构建

2.1 基于Python的检测引擎开发

以下代码展示了核心检测逻辑的实现,采用异步IO提升扫描效率:

import aiohttp import asyncio from urllib.parse import urlparse WEBDAV_METHODS = [ 'OPTIONS', 'PUT', 'DELETE', 'PROPFIND', 'MKCOL', 'COPY', 'MOVE', 'LOCK', 'UNLOCK' ] async def check_method(session, url, method): try: async with session.request(method, url, timeout=10) as resp: if resp.status < 400: # 过滤掉明显不支持的状态码 return method, resp.status, await resp.text() except Exception as e: return method, f"Error: {str(e)}" return None async def scan_target(target_url): parsed = urlparse(target_url) base_url = f"{parsed.scheme}://{parsed.netloc}" async with aiohttp.ClientSession() as session: # 首先检测OPTIONS获取支持的方法 options_result = await check_method(session, base_url, 'OPTIONS') supported_methods = WEBDAV_METHODS if options_result and 'Allow' in options_result[2]: # 解析服务器声明支持的方法 allow_header = options_result[2]['Allow'] supported_methods = [m.strip() for m in allow_header.split(',')] # 并发检测所有可能的方法 tasks = [] for method in supported_methods: tasks.append(check_method(session, target_url, method)) results = await asyncio.gather(*tasks) return [r for r in results if r is not None]

2.2 检测报告生成模块

有效的报告应包含以下结构化数据:

漏洞评估维度

  1. 风险等级(基于方法组合评估):

    • 高危:PUT+DELETE组合
    • 中危:PROPFIND+COPY
    • 低危:单独OPTIONS暴露
  2. PoC验证步骤

    # PUT方法验证示例 curl -X PUT http://target/path/test.txt -d "test content" # DELETE方法验证示例 curl -X DELETE http://target/path/test.txt
  3. 修复建议矩阵

服务器类型配置位置推荐设置
Apachehttpd.confLimitExcept GET POST
Nginxserver块`if ($request_method !~ ^(GET
IISWeb.config<verbs allowUnlisted="false">

3. 高级利用技术剖析

3.1 PROPFIND深度利用

PROPFIND方法结合Depth头可实现递归目录遍历:

PROPFIND / HTTP/1.1 Host: vulnerable.com Depth: infinity Content-Type: application/xml Content-Length: 118 <?xml version="1.0"?> <D:propfind xmlns:D="DAV:"> <D:prop><D:displayname/></D:prop> </D:propfind>

响应解析技巧

  • 查找<d:response>标签内的<d:href>节点
  • 注意401 Unauthorized可能表示存在但需要认证的资源
  • 使用XPath提取有效信息://d:response/d:href/text()

3.2 组合攻击模式

场景一:WebShell上传链

  1. 通过PUT上传txt文件:PUT /test.txt
  2. 使用MOVE修改后缀:MOVE /test.txt /shell.jsp
  3. 通过COPY创建备份:COPY /shell.jsp /backups/

场景二:权限绕过攻击

  1. 利用PROPFIND发现备份目录
  2. 通过LOCK锁定配置文件
  3. 使用PUT修改配置实现权限提升

4. 企业级防护方案

4.1 防御层架构设计

纵深防御体系

  1. 边界层

    • WAF规则:阻断非常规HTTP方法
    • 流量清洗:检测异常的PROPFIND请求频率
  2. 应用层

    <!-- Tomcat web.xml示例 --> <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> <http-method>PUT</http-method> <http-method>DELETE</http-method> <!-- 其他需要禁止的方法 --> </web-resource-collection> <auth-constraint/> </security-constraint>
  3. 监控层

    • 实时告警非常规方法请求
    • 基线分析检测异常的WebDAV操作模式

4.2 安全配置检查清单

Apache加固示例

# 禁用WebDAV模块 LoadModule dav_module modules/mod_dav.so → #LoadModule... # 或严格限制方法 <Location "/"> Dav Off <LimitExcept GET POST> Require all denied </LimitExcept> </Location>

Nginx加固示例

location / { if ($request_method ~* "(PUT|DELETE|PROPFIND)") { return 405; } }

在实际企业环境中,建议结合SAST工具定期扫描配置,并通过蓝军演练验证防护效果。对于必须使用WebDAV的场景,应实施证书双向认证和细粒度的ACL控制