Skip to content

Commit a94672c

Browse files
committed
fix 优化,如果检测到系统有nmap,则优先使用nmap,否则继续使用老到流程走naabu流程,性能飞起来
1 parent 57fdabb commit a94672c

File tree

14 files changed

+173
-139
lines changed

14 files changed

+173
-139
lines changed

brute/filefuzz.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func FileFuzz(u string, indexStatusCode int, indexContentLength int, indexbody s
149149
return path, technologies
150150
}
151151
ch <- struct{}{}
152+
//log.Println(u, " ", payload)
152153
go func(payload string) {
153154
if url, req, err := reqPage(u + payload); err == nil {
154155
// 403 by pass

config/doNmapScan.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
XRate=5000
3+
function doMasScan {
4+
if [[ -f $1 ]] ; then
5+
echo $PPSSWWDD|sudo -S nmap -F --top-ports=65535 -n --unique --resolve-all -Pn -sS --min-hostgroup 64 --max-retries 0 --host-timeout 10m --script-timeout 3m --version-intensity 9 --min-rate ${XRate} -T4 -iL $1 -oX $2
6+
else
7+
echo $PPSSWWDD|sudo -S nmap -F --top-ports=65535 -n --unique --resolve-all -Pn -sS --min-hostgroup 64 --max-retries 0 --host-timeout 10m --script-timeout 3m --version-intensity 9 --min-rate ${XRate} -T4 $1 -oX $2
8+
fi
9+
}
10+
doMasScan $1 $2

main.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"embed"
55
"github.com/hktalent/scan4all/pkg"
6-
"github.com/hktalent/scan4all/pkg/hydra"
76
naaburunner "github.com/hktalent/scan4all/pkg/naabu/v2/pkg/runner"
87
"github.com/projectdiscovery/gologger"
98
"io"
@@ -18,8 +17,11 @@ var config embed.FS
1817
func init() {
1918
pkg.Init2(&config)
2019
}
21-
func main() {
2220

21+
var Wg sync.WaitGroup
22+
23+
func main() {
24+
naaburunner.Wg = &Wg
2325
defer func() {
2426
pkg.Cache1.Close()
2527
//if "true" == pkg.GetVal("autoRmCache") {
@@ -46,18 +48,9 @@ func main() {
4648
gologger.Fatal().Msgf("Could not run enumeration: %s\n", err)
4749
}
4850
gologger.Info().Msg("Port scan over,web scan starting")
49-
hvNmap := pkg.CheckHvNmap()
50-
var wg sync.WaitGroup
51-
if hvNmap {
52-
// 弱密码检测
53-
wg.Add(1)
54-
go hydra.DoNmapRst(&wg)
55-
}
5651
err = naabuRunner.Httpxrun()
5752
if err != nil {
5853
gologger.Fatal().Msgf("naabuRunner.Httpxrun Could not run httpRunner: %s\n", err)
5954
}
60-
if hvNmap {
61-
wg.Wait()
62-
}
55+
Wg.Wait()
6356
}

nuclei_Yaml/nuclei_yaml.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func RunNuclei(buf bytes.Buffer, xx chan bool) {
7070
nucleiRunner.Close()
7171
}
7272
func readConfig() {
73+
pwd, _ := os.Getwd()
7374
options.Targets = []string{}
7475
options.TargetsFilePath = ""
7576
options.Resume = ""
@@ -115,7 +116,7 @@ func readConfig() {
115116
options.ReportingConfig = ""
116117
// 启动es记录
117118
if "true" == pkg.GetVal("enableEsSv") {
118-
options.ReportingConfig = "./config/nuclei_esConfig.yaml"
119+
options.ReportingConfig = pwd + "/config/nuclei_esConfig.yaml"
119120
}
120121
options.CustomHeaders = []string{}
121122
options.Vars = goflags.RuntimeMap{}
@@ -235,7 +236,7 @@ func readConfig() {
235236
options.Retries = 1
236237
options.LeaveDefaultPorts = false
237238
options.MaxHostError = 30
238-
options.Project = true // 去重复,导致file missing
239+
options.Project = false // 去重复,导致file missing
239240
options.ProjectPath = os.TempDir()
240241
options.StopAtFirstMatch = false
241242
options.Stream = false
@@ -296,9 +297,8 @@ func readConfig() {
296297
options.TemplatesDirectory = ""
297298
// 嵌入式集成私人版本nuclei-templates 共3744个YAML POC
298299
if "true" == pkg.GetVal("enablEmbedYaml") {
299-
options.Templates = []string{"./config/nuclei-templates"}
300+
options.Templates = []string{pwd + "/config/nuclei-templates"}
300301
options.NoUpdateTemplates = true
301-
302302
} else {
303303

304304
options.NoUpdateTemplates = false

pkg/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,19 @@ func Init2(config *embed.FS) {
235235
Init()
236236
log.Println("init config files is over .")
237237
}
238+
239+
func RemoveDuplication_map(arr []string) []string {
240+
set := make(map[string]struct{}, len(arr))
241+
j := 0
242+
for _, v := range arr {
243+
_, ok := set[v]
244+
if ok {
245+
continue
246+
}
247+
set[v] = struct{}{}
248+
arr[j] = v
249+
j++
250+
}
251+
252+
return arr[:j]
253+
}

pkg/hydra/defuault_mongodb_authlist.go

Lines changed: 0 additions & 88 deletions
This file was deleted.

pkg/hydra/doNmapResult.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package hydra
22

33
import (
4+
"bytes"
5+
"fmt"
46
"github.com/antchfx/xmlquery"
57
"github.com/hktalent/scan4all/pkg"
68
"io/ioutil"
@@ -32,11 +34,11 @@ func GetAttr(att []xmlquery.Attr, name string) string {
3234
return ""
3335
}
3436

35-
func DoParseXml(s string, wg *sync.WaitGroup) {
37+
func DoParseXml(s string, wg *sync.WaitGroup, bf *bytes.Buffer) {
3638
defer wg.Done()
3739
doc, err := xmlquery.Parse(strings.NewReader(s))
3840
if err != nil {
39-
log.Println(err)
41+
log.Println("DoParseXml: ", err)
4042
return
4143
}
4244
var enableEsSv = pkg.GetVal("enableEsSv")
@@ -50,6 +52,7 @@ func DoParseXml(s string, wg *sync.WaitGroup) {
5052
szPort := GetAttr(x.Attr, "portid")
5153
port, _ := strconv.Atoi(szPort)
5254
service := GetAttr(x.SelectElement("service").Attr, "name")
55+
bf.Write([]byte(fmt.Sprintf("%s:%s\n", ip, szPort)))
5356
wg.Add(1)
5457
go CheckWeakPassword(ip, service, port, wg)
5558
// 存储结果到其他地方
@@ -61,7 +64,7 @@ func DoParseXml(s string, wg *sync.WaitGroup) {
6164
}
6265
m1[ip] = append(xx09, []string{szPort, service})
6366
}
64-
//fmt.Printf("%s\t%d\t%s\n", ip, port, service)
67+
fmt.Printf("%s\t%d\t%s\n", ip, port, service)
6568
}
6669
}
6770
}
@@ -74,7 +77,7 @@ func DoParseXml(s string, wg *sync.WaitGroup) {
7477
}
7578
}
7679

77-
func DoNmapRst(wg *sync.WaitGroup) {
80+
func DoNmapRst(wg *sync.WaitGroup, bf *bytes.Buffer) {
7881
defer wg.Done()
7982
if x1, ok := pkg.TmpFile[pkg.Naabu]; ok {
8083
for _, x := range x1 {
@@ -84,9 +87,11 @@ func DoNmapRst(wg *sync.WaitGroup) {
8487
}(x)
8588
b, err := ioutil.ReadFile(x.Name())
8689
if nil == err && 0 < len(b) {
87-
//log.Println("read config file ok: ", s)
90+
//fmt.Println("read nmap xml file ok: ", len(b))
8891
wg.Add(1)
89-
DoParseXml(string(b), wg)
92+
DoParseXml(string(b), wg, bf)
93+
} else {
94+
log.Println("ioutil.ReadFile(x.Name()): ", err)
9095
}
9196
}
9297
} else {

pkg/hydra/hydra.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var (
2222
ProtocolList = []string{
2323
"ssh", "rdp", "ftp", "smb", "telnet",
2424
"mysql", "mssql", "oracle", "postgresql", "mongodb", "redis",
25+
"rsh-spx",
2526
//110: "pop3",
2627
//995: "pop3",
2728
//25: "smtp",
@@ -90,6 +91,7 @@ func (c *Cracker) Run() {
9091
c.Pool.Function = postgresqlCracker
9192
case "ldap":
9293

94+
case "rsh-spx":
9395
case "ssh":
9496
c.Pool.Function = sshCracker
9597
case "telnet":

pkg/hydra/loadDicts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func init() {
124124
Paswd: pkg.GetVal4File("ssh_pswd", ftp_pswd),
125125
DefaultUp: pkg.GetVal4Filedefault("ssh_default", ftp_default),
126126
}
127+
md["rsh-spx"] = md["ssh"]
127128
md["mongodb"] = PPDict{
128129
Username: pkg.GetVal4File("mongodb_username", mongodbusername),
129130
Paswd: pkg.GetVal4File("mongodb_pswd", mongodb_pswd),

pkg/hydra/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func Start(IPAddr string, Port int, Protocol string, wg *sync.WaitGroup) {
4040
if nil != &out && "" != out.Protocol && out.IPAddr != "" && "" != out.Auth.Username {
4141
pkg.SendAData[AuthInfo](fmt.Sprintf("%s:%d", out.IPAddr, out.Port), []AuthInfo{out}, "hydra")
4242
data, _ := json.Marshal(out)
43-
log.Println("成功密码破解:", aurora.BrightRed(string(data)))
43+
fmt.Println("成功密码破解:", aurora.BrightRed(string(data)))
4444
log.Printf("\n[hydra]-> %v:%v[%v]暴力破解 Finish\n", IPAddr, Port, Protocol)
4545
}
4646
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func ParseOptions() *Options {
103103
)
104104

105105
flagSet.CreateGroup("rate-limit", "Rate-limit",
106-
flagSet.IntVar(&options.Threads, "c", 256, "general internal worker threads"),
107-
flagSet.IntVar(&options.Rate, "rate", DefaultRateSynScan, "packets to send per second"),
106+
flagSet.IntVar(&options.Threads, "c", 256*2, "general internal worker threads"),
107+
flagSet.IntVar(&options.Rate, "rate", DefaultRateSynScan*2, "packets to send per second"),
108108
)
109109

110110
flagSet.CreateGroup("output", "Output",
@@ -150,7 +150,7 @@ func ParseOptions() *Options {
150150

151151
flagSet.CreateGroup("optimization", "Optimization",
152152
flagSet.IntVar(&options.Retries, "retries", DefaultRetriesSynScan, "number of retries for the port scan"),
153-
flagSet.IntVar(&options.Timeout, "timeout", DefaultPortTimeoutSynScan, "millisecond to wait before timing out"),
153+
flagSet.IntVar(&options.Timeout, "timeout", DefaultPortTimeoutSynScan/2, "millisecond to wait before timing out"),
154154
flagSet.IntVar(&options.WarmUpTime, "warm-up-time", 2, "time in seconds between scan phases"),
155155
flagSet.BoolVar(&options.Ping, "ping", false, "ping probes for verification of host"),
156156
flagSet.BoolVar(&options.Verify, "verify", false, "validate the ports again with TCP verification"),
@@ -162,7 +162,7 @@ func ParseOptions() *Options {
162162
flagSet.BoolVarP(&options.NoColor, "nc", "no-color", false, "disable colors in CLI output"),
163163
flagSet.BoolVar(&options.Silent, "silent", false, "display only results in output"),
164164
flagSet.BoolVar(&options.Version, "version", false, "display version of naabu"),
165-
flagSet.BoolVar(&options.EnableProgressBar, "stats", false, "display stats of the running scan"),
165+
flagSet.BoolVar(&options.EnableProgressBar, "stats", true, "display stats of the running scan"),
166166
flagSet.IntVarP(&options.StatsInterval, "stats-interval", "si", DefautStatsInterval, "number of seconds to wait between showing a statistics update"),
167167
)
168168

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (r *Runner) Httpxrun() error {
6666
httpxoptions.NoColor = r.options.NoColor
6767
httpxoptions.Silent = r.options.Silent
6868
httpxoptions.Version = r.options.Version
69-
httpxoptions.RateLimit = r.options.Rate / 10
69+
httpxoptions.RateLimit = r.options.Rate
7070

7171
httpxoptions.NoPOC = r.options.NoPOC
7272
httpxoptions.CeyeApi = r.options.CeyeApi
@@ -312,7 +312,7 @@ func (r *Runner) RunEnumeration() error {
312312
r.stats.AddCounter("errors", uint64(0))
313313
r.stats.AddCounter("total", Range*uint64(r.options.Retries))
314314
if err := r.stats.Start(makePrintCallback(), time.Duration(r.options.StatsInterval)*time.Second); err != nil {
315-
gologger.Warning().Msgf("Couldn't start statistics: %s\n", err)
315+
gologger.Warning().Msgf("Couldn't start statistics: %s", err)
316316
}
317317
}
318318

@@ -693,7 +693,7 @@ func makePrintCallback() func(stats clistats.StatisticsClient) {
693693
builder.WriteString(clistats.String(uint64(float64(packets) / float64(total) * 100.0)))
694694
builder.WriteRune('%')
695695
builder.WriteRune(')')
696-
builder.WriteRune('\n')
696+
builder.WriteString(" \r")
697697

698698
fmt.Fprintf(os.Stderr, "%s", builder.String())
699699
builder.Reset()

0 commit comments

Comments
 (0)