Skip to content

Commit 0f0d72b

Browse files
author
SqlRush
committed
Classify PowerShell netstat protocol queries
1 parent 12f235d commit 0f0d72b

4 files changed

Lines changed: 8 additions & 0 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ M5 补充:PowerShell read-only classifier 收紧 `Get-WinEvent`,普通查询
267267

268268
M5 补充:PowerShell native read-only classifier 收紧 `ver`,裸命令仍按只读处理,但不再接受任意 flag 或位置参数。
269269

270+
M5 补充:PowerShell native read-only classifier 补齐 `netstat -p <protocol>` 只读协议查询形态,协议值走 literal guard,缺值和动态表达式值仍拒绝。
271+
270272
M5 补充:Bash 前台输出和 `BashOutput` 现在都走统一 tool-result budget 截断/落盘路径;`BashOutput` 增加 100k 最大结果限制,大后台输出会保存完整内容并返回 `full_output_path` 元数据。
271273

272274
M5 补充:Bash/PowerShell 后台任务现在会发 `*_background_started``*_background_finished` tool progress 事件,包含后台 ID、shell/status、exit/timed_out/cancelled、duration、时间戳和输出字节数,不携带 command 文本;completed、timed_out、cancelled 终态均已覆盖测试。

docs/claude-code-go-rewrite-plan.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ test/parity/ # golden tests against TS/official behavior
244244
- 本轮补充:PowerShell read-only classifier 收紧系统信息类 cmdlet,`Get-ComputerInfo` 从 allow-all 改为 literal `-Property` 白名单,`Get-Host`/`Get-Culture`/`Get-UICulture`/`Get-Uptime` 不再接受未知 flag 或位置参数。
245245
- 本轮补充:PowerShell read-only classifier 收紧 `Get-WinEvent`,普通查询参数拒绝 `$env:`/hashtable 等动态表达式,`-FilterXPath` 走单独 XPath literal guard,允许 `[]`/`@Name` 语法但拒绝 PowerShell 动态表达式形态。
246246
- 本轮补充:PowerShell native read-only classifier 收紧 `ver`,裸命令仍按只读处理,但不再接受任意 flag 或位置参数。
247+
- 本轮补充:PowerShell native read-only classifier 补齐 `netstat -p <protocol>` 只读协议查询形态,协议值走 literal guard,缺值和动态表达式值仍拒绝。
247248
- 本轮补充:`BashOutput` 现在设置 100k 最大结果大小,和前台 `Bash` 一起覆盖大输出 tool-result preview 截断、完整输出落盘及 `full_output_path` 元数据。
248249
- 本轮补充:Bash/PowerShell 后台命令现在会通过 tool progress 通道发 started/finished 事件,记录后台 ID、shell/status、exit/timed_out/cancelled、duration、时间戳和 stdout/stderr byte count,且 completed、timed_out、cancelled 终态测试确保 progress 不携带 command 文本。
249250
- 本轮补充:WebSearch domain filters 现在在 schema 层声明 array `items:string`,通用 tool schema validator 同步支持 `items` 校验;`allowed_domains`/`blocked_domains` 会拒绝空字符串、URL/port、非法 wildcard 和非域名 label。

internal/tools/powershell/tools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,7 @@ var powerShellNativeReadOnlyCommands = map[string]powerShellNativeReadOnlyConfig
15501550
},
15511551
"netstat": {
15521552
allowedFlags: stringSet("-a", "-b", "-e", "-f", "-n", "-o", "-p", "-q", "-r", "-s", "-t", "-x", "-y"),
1553+
valueFlags: stringSet("-p"),
15531554
},
15541555
"systeminfo": {
15551556
allowedFlags: stringSet("/fo", "/nh"),

internal/tools/powershell/tools_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ func TestPowerShellCommandClassification(t *testing.T) {
231231
"Get-CimClass -ClassName Win32_Process",
232232
"ipconfig /all",
233233
"netstat -ano",
234+
"netstat -p tcp -ano",
234235
"systeminfo /FO CSV /NH",
235236
"tasklist /V /FO CSV",
236237
"where.exe git",
@@ -441,6 +442,9 @@ func TestPowerShellCommandClassification(t *testing.T) {
441442
"ver anything",
442443
"route add 10.0.0.0 mask 255.0.0.0 192.168.1.1 print",
443444
"netsh interface ipv4 show addresses",
445+
"netstat -p $env:PROTO",
446+
"netstat -p @{N='tcp'}",
447+
"netstat -p",
444448
"arp -d 127.0.0.1",
445449
`where.exe /R C:\Users git`,
446450
`where.exe /R \\server\share git`,

0 commit comments

Comments
 (0)