feat: 分离结果输出和日志

This commit is contained in:
ZacharyZcR
2025-01-14 23:38:58 +08:00
parent c6c613a17b
commit 97e9ac7161
38 changed files with 1526 additions and 879 deletions
+25 -15
View File
@@ -16,8 +16,9 @@ func MysqlScan(info *Common.HostInfo) (tmperr error) {
}
maxRetries := Common.MaxRetries
target := fmt.Sprintf("%v:%v", info.Host, info.Ports)
Common.LogDebug(fmt.Sprintf("开始扫描 %v:%v", info.Host, info.Ports))
Common.LogDebug(fmt.Sprintf("开始扫描 %s", target))
totalUsers := len(Common.Userdict["mysql"])
totalPass := len(Common.Passwords)
Common.LogDebug(fmt.Sprintf("开始尝试用户名密码组合 (总用户数: %d, 总密码数: %d)", totalUsers, totalPass))
@@ -38,7 +39,6 @@ func MysqlScan(info *Common.HostInfo) (tmperr error) {
Common.LogDebug(fmt.Sprintf("第%d次重试: %s:%s", retryCount+1, user, pass))
}
// 执行MySQL连接
done := make(chan struct {
success bool
err error
@@ -55,33 +55,43 @@ func MysqlScan(info *Common.HostInfo) (tmperr error) {
}
}(user, pass)
// 等待结果或超时
var err error
select {
case result := <-done:
err = result.err
if result.success && err == nil {
successLog := fmt.Sprintf("MySQL %v:%v %v %v",
info.Host, info.Ports, user, pass)
Common.LogSuccess(successLog)
successMsg := fmt.Sprintf("MySQL %s %v %v", target, user, pass)
Common.LogSuccess(successMsg)
// 保存结果
vulnResult := &Common.ScanResult{
Time: time.Now(),
Type: Common.VULN,
Target: info.Host,
Status: "vulnerable",
Details: map[string]interface{}{
"port": info.Ports,
"service": "mysql",
"username": user,
"password": pass,
"type": "weak-password",
},
}
Common.SaveResult(vulnResult)
return nil
}
case <-time.After(time.Duration(Common.Timeout) * time.Second):
err = fmt.Errorf("连接超时")
}
// 处理错误情况
if err != nil {
errlog := fmt.Sprintf("MySQL %v:%v %v %v %v",
info.Host, info.Ports, user, pass, err)
Common.LogError(errlog)
errMsg := fmt.Sprintf("MySQL %s %v %v %v", target, user, pass, err)
Common.LogError(errMsg)
// 特殊处理认证失败的情况
if strings.Contains(err.Error(), "Access denied") {
break // 跳出重试循环,继续下一个密码
break // 认证失败,尝试下一个密码
}
// 检查是否需要重试
if retryErr := Common.CheckErrs(err); retryErr != nil {
if retryCount == maxRetries-1 {
tmperr = err
@@ -89,9 +99,9 @@ func MysqlScan(info *Common.HostInfo) (tmperr error) {
continue
}
}
continue // 继续重试
continue
}
break // 如果不需要重试,跳出重试循环
break
}
}
}