Skip to content

Commit 6d18552

Browse files
committed
fix main.go:49:21: call of hydra.DoNmapRst copies lock value: sync.WaitGroup contains sync.noCopy
1 parent 22c48a5 commit 6d18552

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

config/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"naabu_dns": {},
5757
"naabu": {"TopPorts": "http","ScanAllIPS": true},
5858
"nuclei": {},
59-
"enablEmbedYaml": false,
59+
"enablEmbedYaml": true,
6060
"httpx": {},
6161
"enableEsSv": false,
6262
"esthread": 8,

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func main() {
4646
// 弱密码检测
4747
var wg sync.WaitGroup
4848
wg.Add(1)
49-
go hydra.DoNmapRst(wg)
49+
go hydra.DoNmapRst(&wg)
5050
err = naabuRunner.Httpxrun()
5151
if err != nil {
5252
gologger.Fatal().Msgf("naabuRunner.Httpxrun Could not run httpRunner: %s\n", err)

pkg/config.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package pkg
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67
"github.com/spf13/viper"
78
"io/ioutil"
89
"log"
910
"os"
11+
"os/exec"
12+
"regexp"
13+
"runtime"
1014
"strings"
1115
)
1216

@@ -147,3 +151,35 @@ func init() {
147151
}
148152

149153
var G_Options interface{}
154+
155+
func GetNmap() string {
156+
nmap := "nmap"
157+
if runtime.GOOS == "windows" {
158+
nmap = "nmap.exe"
159+
}
160+
return nmap
161+
}
162+
163+
func CheckHvNmap() bool {
164+
r, _ := regexp.Compile(`.*Starting Nmap \d\.\d+.*`)
165+
s, err := DoCmd(GetNmap(), "-v")
166+
if nil == err && r.Match([]byte(s)) {
167+
return true
168+
}
169+
return false
170+
}
171+
172+
// 最佳的方法是将命令写到临时文件,并通过bash进行执行
173+
func DoCmd(args ...string) (string, error) {
174+
cmd := exec.Command(args[0], args[1:]...)
175+
var stdout, stderr bytes.Buffer
176+
cmd.Stdout = &stdout // 标准输出
177+
cmd.Stderr = &stderr // 标准错误
178+
err := cmd.Run()
179+
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
180+
// out, err := cmd.CombinedOutput()
181+
if nil != err {
182+
return "", err
183+
}
184+
return string(outStr + "\n" + errStr), err
185+
}

pkg/hydra/doNmapResult.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func DoParseXml(s string) {
7070
}
7171
}
7272

73-
func DoNmapRst(wg sync.WaitGroup) {
73+
func DoNmapRst(wg *sync.WaitGroup) {
7474
defer wg.Done()
7575
if x1, ok := pkg.TmpFile[pkg.Naabu]; ok {
7676
for _, x := range x1 {

pkg/naabu/v2/pkg/runner/runner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func (r *Runner) RunEnumeration() error {
213213
if err := r.scanner.IPRanger.Add(cidr.String()); err != nil {
214214
gologger.Warning().Msgf("Couldn't track %s in scan results: %s\n", cidr, err)
215215
}
216+
// 可以优化基于nmap
216217
ipStream, _ := mapcidr.IPAddressesAsStream(cidr.String())
217218
for ip := range ipStream {
218219
for _, port := range r.scanner.Ports {
@@ -335,7 +336,7 @@ func (r *Runner) RunEnumeration() error {
335336
r.options.ResumeCfg.Retry = currentRetry
336337
r.options.ResumeCfg.Seed = currentSeed
337338
r.options.ResumeCfg.Unlock()
338-
339+
// 可以优化基于nmap
339340
b := blackrock.New(int64(Range), currentSeed)
340341
for index := int64(0); index < int64(Range); index++ {
341342
xxx := b.Shuffle(index)

0 commit comments

Comments
 (0)