修复凭证测试器计数器、消除panic、补齐i18n

- credential_tester: testCredentialWithRetry返回ErrorType,修复网络错误计数器永久不递增的bug
- scanner: os.Exit(1)改为return,defer Cleanup可正常执行
- probe_parser: 5处panic改为error返回,调用链透传到init()
- common库: parsers/initialize/network/session共17处硬编码中文改用i18n
- services插件: 18个文件115处硬编码中文改用i18n
- locale: 补齐service/parser/network相关~25个中英文键
This commit is contained in:
ZacharyZcR
2026-05-18 04:55:20 +08:00
parent c266912dcb
commit 77827bef66
33 changed files with 221 additions and 100 deletions
+12 -11
View File
@@ -10,6 +10,7 @@ import (
"time"
"github.com/shadow1ng/fscan/common"
"github.com/shadow1ng/fscan/common/i18n"
"github.com/shadow1ng/fscan/plugins"
)
@@ -147,7 +148,7 @@ func TestCredentialsConcurrently(
return &ScanResult{
Success: false,
Service: serviceName,
Error: fmt.Errorf("无凭据可测试"),
Error: fmt.Errorf(i18n.GetText("service_no_test_creds")),
}
}
@@ -159,7 +160,7 @@ func TestCredentialsConcurrently(
return &ScanResult{
Success: false,
Service: serviceName,
Error: fmt.Errorf("目标不可达: %w", err),
Error: fmt.Errorf(i18n.Tr("service_target_unreachable", "%w"), err),
}
}
_ = preConn.Close()
@@ -222,7 +223,7 @@ func TestCredentialsConcurrently(
Type: plugins.ResultTypeCredential, // 标记这是凭据测试结果
Success: false,
Service: serviceName,
Error: fmt.Errorf("未发现弱密码"),
Error: fmt.Errorf(i18n.GetText("service_no_weak_pass")),
}
}
@@ -255,14 +256,14 @@ func workerTestCredentials(
}
// 带重试的凭据测试
result := testCredentialWithRetry(ctx, cred, authFn, serviceName, testConfig)
result, errType := testCredentialWithRetry(ctx, cred, authFn, serviceName, testConfig)
if result != nil && result.Success {
resultChan <- result
return
}
// 跟踪连续网络错误
if result != nil && result.Error != nil {
if errType == ErrorTypeNetwork {
consecutiveNetErrors++
} else {
consecutiveNetErrors = 0
@@ -277,12 +278,12 @@ func testCredentialWithRetry(
authFn AuthFunc,
serviceName string,
testConfig ConcurrentTestConfig,
) *ScanResult {
) (*ScanResult, ErrorType) {
for attempt := 0; attempt < testConfig.MaxRetries; attempt++ {
// 检查是否应该停止
select {
case <-ctx.Done():
return nil
return nil, ErrorTypeUnknown
default:
}
@@ -298,14 +299,14 @@ func testCredentialWithRetry(
Service: serviceName,
Username: cred.Username,
Password: cred.Password,
}
}, ErrorTypeUnknown
}
// 根据错误类型决定是否重试
switch result.ErrorType {
case ErrorTypeAuth:
// 认证错误(密码错误),不重试
return nil
return nil, result.ErrorType
case ErrorTypeNetwork, ErrorTypeUnknown:
// 网络错误或未知错误,可以重试(可能是服务端限流等临时问题)
if attempt < testConfig.MaxRetries-1 {
@@ -313,13 +314,13 @@ func testCredentialWithRetry(
select {
case <-ctx.Done():
timer.Stop()
return nil
return nil, result.ErrorType
case <-timer.C:
}
}
}
}
return nil
return nil, ErrorTypeNetwork
}
// =============================================================================