fix: Telnet 弱口令误报,Cisco MOTD 横幅触发 shell prompt 误判 (Closes #590)

isShellPrompt 使用 Contains 匹配 # $ > 单字符,Cisco IOS MOTD 横幅中
的装饰线(###)和文本内容会误触发,导致未发送凭据就判定认证成功。

重写 isShellPrompt 改为行尾匹配,排除全同字符装饰线;
performTelnetAuth 等待 login prompt 阶段移除 isShellPrompt 检查,
未授权检测由 testUnauthAccess 专门负责。
This commit is contained in:
ZacharyZcR
2026-06-27 16:35:18 +08:00
parent ed45d0ead5
commit a3ccc2827b
2 changed files with 84 additions and 10 deletions
+45
View File
@@ -37,3 +37,48 @@ func TestClassifyTelnetErrorType(t *testing.T) {
})
}
}
func TestIsShellPrompt(t *testing.T) {
p := NewTelnetPlugin()
positive := []struct {
name, data string
}{
{"linux root", "root@host:~#"},
{"linux user", "user@host:~$"},
{"cisco", "Router>"},
{"cisco enable", "Router#"},
{"bracket prompt", "[admin@host ~]$"},
{"paren prompt", "host(config)#"},
{"bash keyword", "bash-4.2$"},
{"trailing space", "root@host:~# "},
{"multiline last", "Welcome\nroot@host:~#"},
}
negative := []struct {
name, data string
}{
{"empty", ""},
{"decoration hashes", "################"},
{"decoration arrows", ">>>>>>>>"},
{"decoration dollars", "$$$$$$$$"},
{"cisco motd border", "###################################################"},
{"motd with hash mid", "# Welcome to Cisco IOS"},
{"plain text", "Cisco IOS Software, Version 12.2"},
{"login prompt", "Login:"},
{"password prompt", "Password:"},
{"motd multiline", "##########\nWelcome to Router\n##########"},
}
for _, tt := range positive {
if !p.isShellPrompt(tt.data) {
t.Errorf("isShellPrompt(%q) = false, want true [%s]", tt.data, tt.name)
}
}
for _, tt := range negative {
if p.isShellPrompt(tt.data) {
t.Errorf("isShellPrompt(%q) = true, want false [%s]", tt.data, tt.name)
}
}
}