mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-05-05 18:32:54 +00:00
137 lines
3.3 KiB
Go
137 lines
3.3 KiB
Go
package Plugins
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"github.com/shadow1ng/fscan/Common"
|
|
_ "github.com/sijms/go-ora/v2"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func OracleScan(info *Common.HostInfo) (tmperr error) {
|
|
if Common.DisableBrute {
|
|
return
|
|
}
|
|
|
|
maxRetries := Common.MaxRetries
|
|
target := fmt.Sprintf("%v:%v", info.Host, info.Ports)
|
|
|
|
Common.LogDebug(fmt.Sprintf("开始扫描 %s", target))
|
|
totalUsers := len(Common.Userdict["oracle"])
|
|
totalPass := len(Common.Passwords)
|
|
Common.LogDebug(fmt.Sprintf("开始尝试用户名密码组合 (总用户数: %d, 总密码数: %d)", totalUsers, totalPass))
|
|
|
|
tried := 0
|
|
total := totalUsers * totalPass
|
|
|
|
// 遍历所有用户名密码组合
|
|
for _, user := range Common.Userdict["oracle"] {
|
|
for _, pass := range Common.Passwords {
|
|
tried++
|
|
pass = strings.Replace(pass, "{user}", user, -1)
|
|
Common.LogDebug(fmt.Sprintf("[%d/%d] 尝试: %s:%s", tried, total, user, pass))
|
|
|
|
// 重试循环
|
|
for retryCount := 0; retryCount < maxRetries; retryCount++ {
|
|
if retryCount > 0 {
|
|
Common.LogDebug(fmt.Sprintf("第%d次重试: %s:%s", retryCount+1, user, pass))
|
|
}
|
|
|
|
// 执行Oracle连接
|
|
done := make(chan struct {
|
|
success bool
|
|
err error
|
|
}, 1)
|
|
|
|
go func(user, pass string) {
|
|
success, err := OracleConn(info, user, pass)
|
|
select {
|
|
case done <- struct {
|
|
success bool
|
|
err error
|
|
}{success, err}:
|
|
default:
|
|
}
|
|
}(user, pass)
|
|
|
|
// 等待结果或超时
|
|
var err error
|
|
select {
|
|
case result := <-done:
|
|
err = result.err
|
|
if result.success && err == nil {
|
|
successMsg := fmt.Sprintf("Oracle %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": "oracle",
|
|
"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 {
|
|
errMsg := fmt.Sprintf("Oracle %s 尝试失败 用户名: %v 密码: %v 错误: %v", target, user, pass, err)
|
|
Common.LogError(errMsg)
|
|
|
|
if retryErr := Common.CheckErrs(err); retryErr != nil {
|
|
if retryCount == maxRetries-1 {
|
|
continue
|
|
}
|
|
continue
|
|
}
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
Common.LogDebug(fmt.Sprintf("扫描完成,共尝试 %d 个组合", tried))
|
|
return tmperr
|
|
}
|
|
|
|
// OracleConn 尝试Oracle连接
|
|
func OracleConn(info *Common.HostInfo, user string, pass string) (bool, error) {
|
|
host, port, username, password := info.Host, info.Ports, user, pass
|
|
timeout := time.Duration(Common.Timeout) * time.Second
|
|
|
|
// 构造连接字符串
|
|
connStr := fmt.Sprintf("oracle://%s:%s@%s:%s/orcl",
|
|
username, password, host, port)
|
|
|
|
// 建立数据库连接
|
|
db, err := sql.Open("oracle", connStr)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
defer db.Close()
|
|
|
|
// 设置连接参数
|
|
db.SetConnMaxLifetime(timeout)
|
|
db.SetConnMaxIdleTime(timeout)
|
|
db.SetMaxIdleConns(0)
|
|
|
|
// 测试连接
|
|
if err = db.Ping(); err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return true, nil
|
|
}
|