Skip to content

Commit

Permalink
fixed #44 优化init执行顺序 2022-07-30
Browse files Browse the repository at this point in the history
  • Loading branch information
x51pwn committed Jul 30, 2022
1 parent f5115e6 commit bd58177
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 148 deletions.
16 changes: 9 additions & 7 deletions brute/dicts.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ func CvtLines(s string) []string {
var basicusers []string

func init() {
tomcatuserpass = CvtUps(util.GetVal4File("tomcatuserpass", szTomcatuserpass))
jbossuserpass = CvtUps(util.GetVal4File("jbossuserpass", szJbossuserpass))
weblogicuserpass = CvtUps(util.GetVal4File("weblogicuserpass", szWeblogicuserpass))
filedic = append(filedic, CvtLines(util.GetVal4File("filedic", szFiledic))...)
top100pass = append(top100pass, CvtLines(util.GetVal4File("top100pass", szTop100pass))...)
basicusers = strings.Split(strings.TrimSpace(util.GetVal4File("httpuser", httpass)), "\n")
top100pass = append(top100pass, strings.Split(strings.TrimSpace(util.GetVal4File("httpass", httpass)), "\n")...)
util.RegInitFunc(func() {
tomcatuserpass = CvtUps(util.GetVal4File("tomcatuserpass", szTomcatuserpass))
jbossuserpass = CvtUps(util.GetVal4File("jbossuserpass", szJbossuserpass))
weblogicuserpass = CvtUps(util.GetVal4File("weblogicuserpass", szWeblogicuserpass))
filedic = append(filedic, CvtLines(util.GetVal4File("filedic", szFiledic))...)
top100pass = append(top100pass, CvtLines(util.GetVal4File("top100pass", szTop100pass))...)
basicusers = strings.Split(strings.TrimSpace(util.GetVal4File("httpuser", httpass)), "\n")
top100pass = append(top100pass, strings.Split(strings.TrimSpace(util.GetVal4File("httpass", httpass)), "\n")...)
})
}
26 changes: 14 additions & 12 deletions brute/filefuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,22 @@ var (

// 初始化字典、数组等
func init() {
bakSuffix = util.GetVal4File("bakSuffix", bakSuffix)
fuzzct = util.GetVal4File("fuzzct", fuzzct)
util.RegInitFunc(func() {
bakSuffix = util.GetVal4File("bakSuffix", bakSuffix)
fuzzct = util.GetVal4File("fuzzct", fuzzct)

InitGeneral()
regs = strings.Split(strings.TrimSpace(fuzzct), "\n")
var err error
// 初始化多时候一次性编译,否则会影响效率
for _, reg := range regs {
regsMap[reg], err = regexp.Compile(reg)
if nil != err {
log.Println(reg, " regexp.Compile error: ", err)
InitGeneral()
regs = strings.Split(strings.TrimSpace(fuzzct), "\n")
var err error
// 初始化多时候一次性编译,否则会影响效率
for _, reg := range regs {
regsMap[reg], err = regexp.Compile(reg)
if nil != err {
log.Println(reg, " regexp.Compile error: ", err)
}
}
}
//regs = append(regs, ret...)
//regs = append(regs, ret...)
})
}

// 绝对404请求文件前缀
Expand Down
2 changes: 1 addition & 1 deletion brute/fuzzAI.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func init() {
sz404Url = util.GetVal4File("404url", sz404Url)
page404Title = strings.Split(strings.TrimSpace(fuzz404), "\n")
asz404Url = strings.Split(strings.TrimSpace(sz404Url), "\n")
data, err := util.Cache1.Get(asz404UrlKey)
data, err := util.NewKvDbOp().Get(asz404UrlKey)
if nil == err && 0 < len(data) {
aT1 := asz404Url
if nil != json.Unmarshal(data, &asz404Url) {
Expand Down
25 changes: 20 additions & 5 deletions lib/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"runtime"
"strconv"
"strings"
"time"
)

// 字符串包含关系,且大小写不敏感
Expand Down Expand Up @@ -160,7 +161,8 @@ func RandStringRunes(n int) string {
return string(b)
}

func Init() {
// 初始化配置文件信息,这个必须先执行
func Init2() {
pwd, _ := os.Getwd()
SzPwd = pwd
var ConfigName = "config/config.json"
Expand Down Expand Up @@ -281,7 +283,7 @@ func doDir(config *embed.FS, s fs.DirEntry, szPath string) {
var UserHomeDir string = "./"

// 初始化到开头
func Init2(config *embed.FS) {
func Init1(config *embed.FS) {
dirname, err := os.UserHomeDir()
if nil == err {
UserHomeDir = dirname
Expand All @@ -305,14 +307,27 @@ func Init2(config *embed.FS) {
}
}
} else {
log.Println("Init:", err)
log.Println("Init2:", err)
}
}
Init()
init5()
Init2()
init3()
log.Println("init config files is over .")
}

var fnInit []func()

func RegInitFunc(cbk func()) {
fnInit = append(fnInit, cbk)
}
func DoInit(config *embed.FS) {
Init1(config)
rand.Seed(time.Now().UnixNano())
for _, x := range fnInit {
x()
}
}

func RemoveDuplication_map(arr []string) []string {
set := make(map[string]struct{}, len(arr))
j := 0
Expand Down
5 changes: 3 additions & 2 deletions lib/util/kvDb.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (r *KvDbOp) Init(szDb string) error {
opts.LevelSizeMultiplier = 20
db, err := badger.Open(opts)
if nil != err {
log.Println("Init k-v db 不能多个进程同时开启", err)
log.Println("Init2 k-v db 不能多个进程同时开启", err)
return err
}
r.DbConn = db
Expand Down Expand Up @@ -115,6 +115,7 @@ func (r *KvDbOp) Put(key string, data []byte) {
}

// 调整初始化顺序
func init5() {
// 初始化 kvDb
func init3() {
NewKvDbOp()
}
8 changes: 1 addition & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,20 @@ import (
"github.com/hktalent/scan4all/lib/api"
"github.com/hktalent/scan4all/lib/util"
"log"
"math/rand"
"net/http"
_ "net/http/pprof"
"runtime"
"sync"
"time"
)

//go:embed config/*
var config embed.FS

func init() {
util.Init2(&config)
rand.Seed(time.Now().UnixNano())
}

var Wg sync.WaitGroup

func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
util.DoInit(&config)
util.Wg = &Wg
defer util.CloseAll()
szTip := ""
Expand Down
4 changes: 3 additions & 1 deletion pkg/fingerprint/eHoleFingerData.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ import (
var eHoleFinger string

func init() {
eHoleFinger = util.GetVal4File("eHoleFinger", eHoleFinger)
util.RegInitFunc(func() {
eHoleFinger = util.GetVal4File("eHoleFinger", eHoleFinger)
})
}
4 changes: 3 additions & 1 deletion pkg/fingerprint/localFingerData.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ import (
var localFinger string

func init() {
localFinger = util.GetVal4File("localFinger", localFinger)
util.RegInitFunc(func() {
localFinger = util.GetVal4File("localFinger", localFinger)
})
}
142 changes: 72 additions & 70 deletions pkg/hydra/loadDicts.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,76 +132,78 @@ type PPDict struct {
var md = map[string]*PPDict{}

func init() {
md["ftp"] = &PPDict{
Username: util.GetVal4File("ftp_user", ftpusername),
Paswd: util.GetVal4File("ftp_pswd", ftp_pswd),
DefaultUp: util.GetVal4Filedefault("ftp_default", ftp_default),
}
md["ssh"] = &PPDict{
Username: util.GetVal4File("ssh_username", username),
Paswd: util.GetVal4File("ssh_pswd", pswd),
DefaultUp: util.GetVal4Filedefault("ssh_default", ssh_default),
}
md["rsh-spx"] = md["ssh"]
md["snmp"] = &PPDict{
Username: util.GetVal4File("snmp_user", snmp_user),
Paswd: util.GetVal4File("snmp_pswd", snmp_pswd),
DefaultUp: util.GetVal4Filedefault("snmp_default", snmp_default),
}
// 再增加字典
md["wap-wsp"] = &PPDict{
Username: util.GetVal4File("es_user", es_user),
Paswd: util.GetVal4File("es_pswd", es_pswd),
DefaultUp: util.GetVal4Filedefault("es_default", es_default),
}
md["router"] = md["wap-wsp"]
md["mongodb"] = &PPDict{
Username: util.GetVal4File("mongodb_username", mongodbusername),
Paswd: util.GetVal4File("mongodb_pswd", mongodb_pswd),
DefaultUp: util.GetVal4Filedefault("mongodb_default", mongodb_default),
}
md["mongod"] = md["mongodb"]
md["mssql"] = &PPDict{
Username: util.GetVal4File("mssql_username", mssqlusername),
Paswd: util.GetVal4File("mssql_pswd", mssql_pswd),
DefaultUp: util.GetVal4Filedefault("mssql_default", mssql_default),
}
md["mysql"] = &PPDict{
Username: util.GetVal4File("mysql_username", mysqlusername),
Paswd: util.GetVal4File("mysql_pswd", mysql_pswd),
DefaultUp: util.GetVal4File("mysql_default", mysql_default),
}
md["oracle"] = &PPDict{
Username: util.GetVal4File("oracle_username", oracleusername),
Paswd: util.GetVal4File("oracle_pswd", oracle_pswd),
DefaultUp: util.GetVal4Filedefault("oracleh_default", oracle_default),
}
md["postgresql"] = &PPDict{
Username: util.GetVal4File("postgresql_username", postgresqlusername),
Paswd: util.GetVal4File("postgresql_pswd", postgresql_pswd),
DefaultUp: util.GetVal4Filedefault("postgresql_default", postgresql_default),
}
md["rdp"] = &PPDict{
Username: util.GetVal4File("rdp_username", rdpusername),
Paswd: util.GetVal4File("rdp_pswd", rdp_pswd),
DefaultUp: util.GetVal4Filedefault("rdp_default", rdp_default),
}
md["redis"] = &PPDict{
Username: util.GetVal4File("redis_username", redisusername),
Paswd: util.GetVal4File("redis_pswd", redis_pswd),
DefaultUp: util.GetVal4Filedefault("redis_default", redis_default),
}
md["smb"] = &PPDict{
Username: util.GetVal4File("smb_username", smbusername),
Paswd: util.GetVal4File("smb_pswd", smb_pswd),
DefaultUp: util.GetVal4Filedefault("smb_default", smb_default),
}
md["winrm"] = md["smb"]
md["telnet"] = &PPDict{
Username: util.GetVal4File("telnet_username", telnetusername),
Paswd: util.GetVal4File("telnet_pswd", telnet_pswd),
DefaultUp: util.GetVal4Filedefault("telnet_default", telnet_default),
}
util.RegInitFunc(func() {
md["ftp"] = &PPDict{
Username: util.GetVal4File("ftp_user", ftpusername),
Paswd: util.GetVal4File("ftp_pswd", ftp_pswd),
DefaultUp: util.GetVal4Filedefault("ftp_default", ftp_default),
}
md["ssh"] = &PPDict{
Username: util.GetVal4File("ssh_username", username),
Paswd: util.GetVal4File("ssh_pswd", pswd),
DefaultUp: util.GetVal4Filedefault("ssh_default", ssh_default),
}
md["rsh-spx"] = md["ssh"]
md["snmp"] = &PPDict{
Username: util.GetVal4File("snmp_user", snmp_user),
Paswd: util.GetVal4File("snmp_pswd", snmp_pswd),
DefaultUp: util.GetVal4Filedefault("snmp_default", snmp_default),
}
// 再增加字典
md["wap-wsp"] = &PPDict{
Username: util.GetVal4File("es_user", es_user),
Paswd: util.GetVal4File("es_pswd", es_pswd),
DefaultUp: util.GetVal4Filedefault("es_default", es_default),
}
md["router"] = md["wap-wsp"]
md["mongodb"] = &PPDict{
Username: util.GetVal4File("mongodb_username", mongodbusername),
Paswd: util.GetVal4File("mongodb_pswd", mongodb_pswd),
DefaultUp: util.GetVal4Filedefault("mongodb_default", mongodb_default),
}
md["mongod"] = md["mongodb"]
md["mssql"] = &PPDict{
Username: util.GetVal4File("mssql_username", mssqlusername),
Paswd: util.GetVal4File("mssql_pswd", mssql_pswd),
DefaultUp: util.GetVal4Filedefault("mssql_default", mssql_default),
}
md["mysql"] = &PPDict{
Username: util.GetVal4File("mysql_username", mysqlusername),
Paswd: util.GetVal4File("mysql_pswd", mysql_pswd),
DefaultUp: util.GetVal4File("mysql_default", mysql_default),
}
md["oracle"] = &PPDict{
Username: util.GetVal4File("oracle_username", oracleusername),
Paswd: util.GetVal4File("oracle_pswd", oracle_pswd),
DefaultUp: util.GetVal4Filedefault("oracleh_default", oracle_default),
}
md["postgresql"] = &PPDict{
Username: util.GetVal4File("postgresql_username", postgresqlusername),
Paswd: util.GetVal4File("postgresql_pswd", postgresql_pswd),
DefaultUp: util.GetVal4Filedefault("postgresql_default", postgresql_default),
}
md["rdp"] = &PPDict{
Username: util.GetVal4File("rdp_username", rdpusername),
Paswd: util.GetVal4File("rdp_pswd", rdp_pswd),
DefaultUp: util.GetVal4Filedefault("rdp_default", rdp_default),
}
md["redis"] = &PPDict{
Username: util.GetVal4File("redis_username", redisusername),
Paswd: util.GetVal4File("redis_pswd", redis_pswd),
DefaultUp: util.GetVal4Filedefault("redis_default", redis_default),
}
md["smb"] = &PPDict{
Username: util.GetVal4File("smb_username", smbusername),
Paswd: util.GetVal4File("smb_pswd", smb_pswd),
DefaultUp: util.GetVal4Filedefault("smb_default", smb_default),
}
md["winrm"] = md["smb"]
md["telnet"] = &PPDict{
Username: util.GetVal4File("telnet_username", telnetusername),
Paswd: util.GetVal4File("telnet_pswd", telnet_pswd),
DefaultUp: util.GetVal4Filedefault("telnet_default", telnet_default),
}
})
}

func GetDefaultFtpList(t string) *AuthList {
Expand Down
26 changes: 14 additions & 12 deletions pkg/hydra/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ import (
)

func init() {
InitDefaultAuthMap()
var a1, a2 []string
HydraUser := util.GetVal4File("HydraUser", "")
if "" != HydraUser {
a1 = strings.Split(HydraUser, "\n")
}
util.RegInitFunc(func() {
InitDefaultAuthMap()
var a1, a2 []string
HydraUser := util.GetVal4File("HydraUser", "")
if "" != HydraUser {
a1 = strings.Split(HydraUser, "\n")
}

HydraPass := util.GetVal4File("HydraPass", "")
if "" != HydraPass {
a2 = strings.Split(HydraPass, "\n")
}
//加载自定义字典
InitCustomAuthMap(a1, a2)
HydraPass := util.GetVal4File("HydraPass", "")
if "" != HydraPass {
a2 = strings.Split(HydraPass, "\n")
}
//加载自定义字典
InitCustomAuthMap(a1, a2)
})
}

// 密码破解
Expand Down
4 changes: 0 additions & 4 deletions pkg/kscan/lib/grdp/glog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import (
"sync"
)

func init() {

}

var (
logger *log.Logger
level LEVEL
Expand Down
Loading

0 comments on commit bd58177

Please sign in to comment.