2022-01-11 10:25:15 +08:00
|
|
|
package Plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
2024-12-18 22:00:18 +08:00
|
|
|
"github.com/shadow1ng/fscan/Common"
|
2022-01-11 10:25:15 +08:00
|
|
|
_ "github.com/sijms/go-ora/v2"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2024-12-18 23:40:26 +08:00
|
|
|
// OracleScan 执行Oracle服务扫描
|
2024-12-19 16:15:53 +08:00
|
|
|
func OracleScan(info *Common.HostInfo) (tmperr error) {
|
2024-12-20 03:46:09 +08:00
|
|
|
if Common.DisableBrute {
|
2022-01-11 10:25:15 +08:00
|
|
|
return
|
|
|
|
}
|
2024-12-18 23:40:26 +08:00
|
|
|
|
2024-12-31 20:25:54 +08:00
|
|
|
maxRetries := Common.MaxRetries
|
2025-01-01 07:18:36 +08:00
|
|
|
starttime := time.Now().Unix()
|
2024-12-18 23:40:26 +08:00
|
|
|
|
2025-01-01 07:18:36 +08:00
|
|
|
// 遍历所有用户名密码组合
|
2024-12-18 22:00:18 +08:00
|
|
|
for _, user := range Common.Userdict["oracle"] {
|
|
|
|
for _, pass := range Common.Passwords {
|
2022-01-11 10:25:15 +08:00
|
|
|
pass = strings.Replace(pass, "{user}", user, -1)
|
2024-12-18 23:40:26 +08:00
|
|
|
|
2025-01-01 07:18:36 +08:00
|
|
|
// 检查是否超时
|
|
|
|
if time.Now().Unix()-starttime > int64(Common.Timeout) {
|
|
|
|
return fmt.Errorf("扫描超时")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重试循环
|
|
|
|
for retryCount := 0; retryCount < maxRetries; retryCount++ {
|
|
|
|
// 执行Oracle连接
|
|
|
|
done := make(chan struct {
|
|
|
|
success bool
|
|
|
|
err error
|
|
|
|
})
|
|
|
|
|
|
|
|
go func(user, pass string) {
|
|
|
|
success, err := OracleConn(info, user, pass)
|
|
|
|
done <- struct {
|
2024-12-31 20:25:54 +08:00
|
|
|
success bool
|
|
|
|
err error
|
2025-01-01 07:18:36 +08:00
|
|
|
}{success, err}
|
|
|
|
}(user, pass)
|
|
|
|
|
|
|
|
// 等待结果或超时
|
|
|
|
var err error
|
|
|
|
select {
|
|
|
|
case result := <-done:
|
|
|
|
err = result.err
|
|
|
|
if result.success && err == nil {
|
|
|
|
return nil
|
2024-12-31 20:25:54 +08:00
|
|
|
}
|
2025-01-01 07:18:36 +08:00
|
|
|
case <-time.After(time.Duration(Common.Timeout) * time.Second):
|
|
|
|
err = fmt.Errorf("连接超时")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理错误情况
|
|
|
|
if err != nil {
|
|
|
|
errlog := fmt.Sprintf("Oracle %v:%v %v %v %v",
|
|
|
|
info.Host, info.Ports, user, pass, err)
|
|
|
|
Common.LogError(errlog)
|
2024-12-31 20:25:54 +08:00
|
|
|
|
2025-01-01 07:18:36 +08:00
|
|
|
// 检查是否需要重试
|
|
|
|
if retryErr := Common.CheckErrs(err); retryErr != nil {
|
|
|
|
if retryCount == maxRetries-1 {
|
|
|
|
return err
|
2024-12-31 20:25:54 +08:00
|
|
|
}
|
2025-01-01 07:18:36 +08:00
|
|
|
continue // 继续重试
|
2024-12-31 20:25:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-01 07:18:36 +08:00
|
|
|
break // 如果不需要重试,跳出重试循环
|
2022-01-11 10:25:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-12-31 20:25:54 +08:00
|
|
|
|
2022-01-11 10:25:15 +08:00
|
|
|
return tmperr
|
|
|
|
}
|
|
|
|
|
2024-12-18 23:40:26 +08:00
|
|
|
// OracleConn 尝试Oracle连接
|
2024-12-19 16:15:53 +08:00
|
|
|
func OracleConn(info *Common.HostInfo, user string, pass string) (bool, error) {
|
2024-12-18 23:40:26 +08:00
|
|
|
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
|
2022-01-11 10:25:15 +08:00
|
|
|
}
|
2024-12-18 23:40:26 +08:00
|
|
|
defer db.Close()
|
|
|
|
|
|
|
|
// 设置连接参数
|
|
|
|
db.SetConnMaxLifetime(timeout)
|
|
|
|
db.SetConnMaxIdleTime(timeout)
|
|
|
|
db.SetMaxIdleConns(0)
|
|
|
|
|
|
|
|
// 测试连接
|
|
|
|
if err = db.Ping(); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 连接成功
|
2025-01-01 05:24:49 +08:00
|
|
|
result := fmt.Sprintf("Oracle %v:%v:%v %v", host, port, username, password)
|
2024-12-18 23:40:26 +08:00
|
|
|
Common.LogSuccess(result)
|
|
|
|
return true, nil
|
2022-01-11 10:25:15 +08:00
|
|
|
}
|