Skip to content

Commit

Permalink
[+]优化hydra模块检测逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
lcvvvv committed Jan 10, 2022
1 parent 5a49061 commit 7187a18
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/gonmap
35 changes: 17 additions & 18 deletions lib/hydra/hydra.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
)

type Cracker struct {
Pool *pool.Pool
authList *AuthList
authInfo *AuthInfo
Out chan AuthInfo
Pool *pool.Pool
authList *AuthList
authInfo *AuthInfo
Out chan AuthInfo
onlyPassword bool
}

var (
Expand All @@ -33,10 +34,20 @@ var (

func NewCracker(info *AuthInfo, isAuthUpdate bool, threads int) *Cracker {
c := &Cracker{}

if info.Protocol == "redis" {
c.onlyPassword = true
} else {
c.onlyPassword = false
}

c.Pool = pool.NewPool(threads)
c.authInfo = info
c.authList = func() *AuthList {
list := DefaultAuthMap[c.authInfo.Protocol]
if c.onlyPassword {
CustomAuthMap.Username = []string{}
}
if isAuthUpdate {
list.Merge(CustomAuthMap)
return list
Expand All @@ -49,6 +60,7 @@ func NewCracker(info *AuthInfo, isAuthUpdate bool, threads int) *Cracker {
}()
c.Out = make(chan AuthInfo)
c.Pool.Interval = time.Second * 1

return c
}

Expand All @@ -58,20 +70,7 @@ func (c *Cracker) Run() {

//go 任务下发器
go func() {
for _, password := range c.authList.Password {
for _, username := range c.authList.Username {
if c.Pool.Done {
c.Pool.InDone()
return
}
a := NewAuth()
a.Password = password
a.Username = username
c.authInfo.Auth = a
c.Pool.In <- *c.authInfo
}
}
for _, a := range c.authList.Special {
for _, a := range c.authList.Dict(c.onlyPassword) {
if c.Pool.Done {
c.Pool.InDone()
return
Expand Down
24 changes: 24 additions & 0 deletions lib/hydra/type-auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@ func NewAuth() Auth {
return a
}

func NewAuthFromPasswords(passwords []string) []Auth {
var auths []Auth
for _, password := range passwords {
auths = append(auths, Auth{
Username: "",
Password: password,
})
}
return auths
}

func NewAuthFromUsernameAndPassword(usernames, passwords []string) []Auth {
var auths []Auth
for _, password := range passwords {
for _, username := range usernames {
auths = append(auths, Auth{
Username: username,
Password: password,
})
}
}
return auths
}

func NewSpecialAuth(username, password string) Auth {
a := Auth{
Username: username,
Expand Down
11 changes: 11 additions & 0 deletions lib/hydra/type-authlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ func (a *AuthList) Length() int {
}
return (len(a.Password) * len(a.Username)) + len(a.Special)
}

func (a *AuthList) Dict(onlyPassword bool) []Auth {
var dict []Auth
dict = append(dict, a.Special...)
if onlyPassword {
dict = append(dict, NewAuthFromPasswords(a.Password)...)
} else {
dict = append(dict, NewAuthFromUsernameAndPassword(a.Username, a.Password)...)
}
return dict
}

0 comments on commit 7187a18

Please sign in to comment.