fscan/plugins/test_mysql.go
ZacharyZcR 678d750c8a refactor: 重构插件架构,实现单文件插件系统
将复杂的三文件插件架构(connector/exploiter/plugin)重构为简化的单文件插件架构,
大幅减少代码重复和维护成本,提升插件开发效率。

主要改进:
• 将每个服务插件从3个文件简化为1个文件
• 删除过度设计的工厂模式、适配器模式等抽象层
• 消除plugins/services/、plugins/adapters/、plugins/base/复杂目录结构
• 实现直接的插件注册机制,提升系统简洁性
• 保持完全向后兼容,所有扫描功能和输出格式不变

重构统计:
• 删除文件:100+个复杂架构文件
• 新增文件:20个简化的单文件插件
• 代码减少:每个插件减少60-80%代码量
• 功能增强:所有插件包含完整扫描和利用功能

已重构插件: MySQL, SSH, Redis, MongoDB, PostgreSQL, MSSQL, Oracle,
Neo4j, Memcached, RabbitMQ, ActiveMQ, Cassandra, FTP, Kafka, LDAP,
Rsync, SMTP, SNMP, Telnet, VNC

验证通过: 新系统编译运行正常,所有插件功能验证通过
2025-08-25 23:57:00 +08:00

68 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package plugins
import (
"context"
"fmt"
"time"
"github.com/shadow1ng/fscan/common"
)
// TestMySQLPlugin 测试新的MySQL插件实现
func TestMySQLPlugin() {
fmt.Println("=== 测试简化的MySQL插件 ===")
// 初始化必要的全局变量
common.Timeout = 5
common.DisableBrute = false
common.Passwords = []string{"", "root", "123456", "admin", "password"}
common.Userdict = map[string][]string{
"mysql": {"root", "mysql", "admin"},
}
// 创建插件实例
plugin := NewMySQLPlugin()
fmt.Printf("插件名称: %s\n", plugin.GetName())
fmt.Printf("支持端口: %v\n", plugin.GetPorts())
// 测试用例1本地不存在的MySQL服务应该失败
fmt.Println("\n--- 测试1: 连接不存在的MySQL服务 ---")
testHost := &common.HostInfo{
Host: "127.0.0.1",
Ports: "3306",
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
result := plugin.Scan(ctx, testHost)
fmt.Printf("扫描结果: Success=%v, Service=%s\n", result.Success, result.Service)
if result.Error != nil {
fmt.Printf("错误信息: %v\n", result.Error)
}
if result.Success {
fmt.Printf("发现弱密码: %s/%s\n", result.Username, result.Password)
}
// 测试用例2禁用暴力破解模式
fmt.Println("\n--- 测试2: 禁用暴力破解模式 ---")
common.DisableBrute = true
result2 := plugin.Scan(ctx, testHost)
fmt.Printf("服务识别结果: Success=%v, Service=%s\n", result2.Success, result2.Service)
if result2.Banner != "" {
fmt.Printf("服务Banner: %s\n", result2.Banner)
}
if result2.Error != nil {
fmt.Printf("错误信息: %v\n", result2.Error)
}
fmt.Println("\n=== MySQL插件测试完成 ===")
}
// 如果直接运行这个文件,执行测试
func init() {
// 注释掉自动测试,避免在导入时执行
// TestMySQLPlugin()
}