MCPcopy
hub / github.com/shadow1ng/fscan / TestExecCommandPing_Blacklist

Function TestExecCommandPing_Blacklist

core/icmp_test.go:320–345  ·  view source on GitHub ↗

TestExecCommandPing_Blacklist 测试Ping命令注入防护

(t *testing.T)

Source from the content-addressed store, hash-verified

318
319// TestExecCommandPing_Blacklist 测试Ping命令注入防护
320func TestExecCommandPing_Blacklist(t *testing.T) {
321 dangerousInputs := []struct {
322 name string
323 input string
324 }{
325 {"分号注入", "192.168.1.1; rm -rf /"},
326 {"与符号注入", "192.168.1.1 & whoami"},
327 {"管道注入", "192.168.1.1 | cat /etc/passwd"},
328 {"反引号注入", "192.168.1.1`whoami`"},
329 {"美元符号", "192.168.1.1$USER"},
330 {"反斜杠", "192.168.1.1\\nwhoami"},
331 {"单引号", "192.168.1.1'"},
332 {"百分号", "192.168.1.1%"},
333 {"双引号", "192.168.1.1\""},
334 {"换行符", "192.168.1.1\nwhoami"},
335 }
336
337 for _, tt := range dangerousInputs {
338 t.Run(tt.name, func(t *testing.T) {
339 result := ExecCommandPing(tt.input)
340 if result {
341 t.Errorf("ExecCommandPing(%q) = true, 应拒绝危险输入", tt.input)
342 }
343 })
344 }
345}
346
347// TestExecCommandPing_ValidInputs 测试合法IP格式
348func TestExecCommandPing_ValidInputs(t *testing.T) {

Callers

nothing calls this directly

Calls 2

ExecCommandPingFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected