Skip to content

Commit

Permalink
successmap
Browse files Browse the repository at this point in the history
  • Loading branch information
zan8in committed Feb 23, 2023
1 parent 14f0740 commit f01a615
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/leo/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func ParseOptions() *Options {

flagSet.CreateGroup("rate-limit", "Rate-Limit",
flagSet.IntVarP(&options.RateLimit, "rate-limit", "rl", 150, "maximum number of requests to send per second"),
flagSet.IntVarP(&options.Concurrency, "concurrency", "c", 25, "maximum number of crack to be executed in parallel"),
flagSet.IntVarP(&options.Concurrency, "concurrency", "c", 100, "maximum number of crack to be executed in parallel"),
)

flagSet.CreateGroup("optimization", "Optimizations",
Expand Down
35 changes: 27 additions & 8 deletions pkg/leo/runner.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package leo

import (
"errors"
"fmt"
"runtime"
"strings"
Expand All @@ -23,6 +24,8 @@ type Runner struct {
callbackchan chan *CallbackInfo

syncfile *fileutil.Syncfile

successmap *sync.Map
}

type HostCredentials struct {
Expand All @@ -48,6 +51,7 @@ func NewRunner(options *Options) (*Runner, error) {
options: options,
callbackchan: make(chan *CallbackInfo),
syncfile: &fileutil.Syncfile{},
successmap: &sync.Map{},
}

defaultPort := DefaultServicePort[options.Service]
Expand Down Expand Up @@ -94,6 +98,8 @@ func NewRunner(options *Options) (*Runner, error) {

func (runner *Runner) Run() {
go func() {
// defer ants.Release()

Ticker = time.NewTicker(time.Second / time.Duration(runner.options.RateLimit))
var wg sync.WaitGroup

Expand All @@ -103,15 +109,27 @@ func (runner *Runner) Run() {

hc := p.(*HostCredentials)

err := runner.execute.start(hc.Host, hc.User, hc.Pass, hc.M)

atomic.AddUint32(&runner.options.CurrentCount, 1)
runner.callbackchan <- &CallbackInfo{
Err: err,
HostInfo: HostInfo{Host: hc.Host, Port: hc.Port},
HostCredentials: *hc,
CurrentCount: runner.options.CurrentCount,

_, ok := runner.successmap.Load(fmt.Sprintf("%s:%s:%s", hc.Host, hc.Port, hc.User))
if !ok {
err := runner.execute.start(hc.Host, hc.User, hc.Pass, hc.M)

runner.callbackchan <- &CallbackInfo{
Err: err,
HostInfo: HostInfo{Host: hc.Host, Port: hc.Port},
HostCredentials: *hc,
CurrentCount: runner.options.CurrentCount,
}
} else {
runner.callbackchan <- &CallbackInfo{
Err: errors.New("successmap, skip crack"),
HostInfo: HostInfo{Host: hc.Host, Port: hc.Port},
HostCredentials: *hc,
CurrentCount: runner.options.CurrentCount,
}
}

})
defer p.Release()

Expand All @@ -121,7 +139,6 @@ func (runner *Runner) Run() {
swg.Add()
go func(host HostInfo) {
defer swg.Done()

m, err := runner.execute.validateService(host.Host, host.Port)
if err != nil {

Expand Down Expand Up @@ -198,6 +215,8 @@ func (runner *Runner) Listener() {
}
runner.options.SuccessList = append(runner.options.SuccessList, strings.TrimSpace(info))
}(info)

runner.successmap.Store(fmt.Sprintf("%s:%s:%s", host, port, user), fmt.Sprintf("%s:%s:%s", host, port, user))
}
if result.Err == nil && result.Status == STATUS_COMPLATE {
time.Sleep(3 * time.Second)
Expand Down

0 comments on commit f01a615

Please sign in to comment.