forked from GhostTroops/scan4all
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
91 lines (86 loc) · 2.34 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"embed"
"fmt"
"github.com/hktalent/scan4all/lib/util"
naaburunner "github.com/hktalent/scan4all/pkg/naabu/v2/pkg/runner"
"github.com/projectdiscovery/gologger"
"io"
"io/ioutil"
"log"
"math/rand"
"net/http"
_ "net/http/pprof"
"os"
"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.Wg = &Wg
defer func() {
util.Cache1.Close()
if runtime.GOOS == "windows" || util.GetValAsBool("autoRmCache") {
os.RemoveAll(util.GetVal(util.CacheName))
}
// clear
// 程序都结束了,没有必要清理内存了
// fingerprint.ClearData()
}()
options := naaburunner.ParseOptions()
szTip := ""
if options.Debug && util.GetValAsBool("enablDevDebug") {
// debug 优化时启用///////////////////////
go func() {
szTip = "Since you started http://127.0.0.1:6060/debug/pprof/ with -debug, close the program with: control + C"
fmt.Println("debug info: \nopen http://127.0.0.1:6060/debug/pprof/\n\ngo tool pprof -seconds=10 -http=:9999 http://localhost:6060/debug/pprof/heap")
http.ListenAndServe(":6060", nil)
}()
//////////////////////////////////////////*/
}
if false == options.Debug && false == options.Verbose {
// disable standard logger (ref: https://github.com/golang/go/issues/19895)
log.SetFlags(0)
log.SetOutput(io.Discard)
}
util.G_Options = options
if runtime.GOOS == "windows" {
options.NoColor = true
}
naabuRunner, err := naaburunner.NewRunner(options)
if err != nil {
gologger.Fatal().Msgf("naaburunner.NewRunner Could not create runner: %s\n", err)
}
if util.GetValAsBool("noScan") {
s1, err := naabuRunner.MergeToFile()
if nil == err {
data, err := ioutil.ReadFile(s1)
if nil == err {
naaburunner.Naabubuffer.Write(data)
}
}
} else {
gologger.Info().Msg("Port scan starting....")
err = naabuRunner.RunEnumeration()
if err != nil {
gologger.Fatal().Msgf("Could not run enumeration: %s\n", err)
}
gologger.Info().Msg("Port scan over,web scan starting")
}
err = naabuRunner.Httpxrun()
if err != nil {
gologger.Fatal().Msgf("naabuRunner.Httpxrun Could not run httpRunner: %s\n", err)
}
log.Printf("wait for all threads to end\n%s", szTip)
util.Wg.Wait()
util.StopAll()
naabuRunner.Close()
}