mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-07-14 05:12:36 +08:00
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package Plugins
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
_ "github.com/go-sql-driver/mysql"
|
|
"github.com/shadow1ng/fscan/common"
|
|
"time"
|
|
)
|
|
|
|
type MysqlConn struct{}
|
|
|
|
func MysqlScan(info *common.HostInfo) (tmperr error) {
|
|
if common.IsBrute {
|
|
return
|
|
}
|
|
mysqlConn := &MysqlConn{}
|
|
bt := common.InitBruteThread("mysql", info, common.Timeout, mysqlConn)
|
|
return bt.Run()
|
|
}
|
|
|
|
func (m *MysqlConn) Attack(info *common.HostInfo, user string, pass string, timeout int64) (flag bool, err error) {
|
|
flag = false
|
|
Host, Port, Username, Password := info.Host, info.Ports, user, pass
|
|
dataSourceName := fmt.Sprintf("%v:%v@tcp(%v:%v)/mysql?charset=utf8&timeout=%v", Username, Password, Host, Port, time.Duration(common.Timeout)*time.Second)
|
|
db, err := sql.Open("mysql", dataSourceName)
|
|
if err == nil {
|
|
db.SetConnMaxLifetime(time.Duration(timeout) * time.Second)
|
|
db.SetConnMaxIdleTime(time.Duration(timeout) * time.Second)
|
|
db.SetMaxIdleConns(0)
|
|
defer db.Close()
|
|
err = db.Ping()
|
|
if err == nil {
|
|
result := fmt.Sprintf("[+] mysql:%v:%v:%v %v", Host, Port, Username, Password)
|
|
common.LogSuccess(result)
|
|
flag = true
|
|
}
|
|
}
|
|
return flag, err
|
|
}
|