forked from GhostTroops/scan4all
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (75 loc) · 2.17 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
package main
import (
"embed"
"fmt"
myConst "github.com/hktalent/scan4all/lib"
"github.com/hktalent/scan4all/pkg"
naaburunner "github.com/hktalent/scan4all/pkg/naabu/v2/pkg/runner"
"github.com/projectdiscovery/gologger"
"io"
"log"
"math/rand"
"net/http"
_ "net/http/pprof"
"runtime"
"sync"
"time"
)
//go:embed config/*
var config embed.FS
func init() {
pkg.Init2(&config)
rand.Seed(time.Now().UnixNano())
}
var Wg sync.WaitGroup
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
myConst.Wg = &Wg
defer func() {
log.Println("start close cache, StopCPUProfile... ")
pkg.Cache1.Close()
//if "true" == pkg.GetVal("autoRmCache") {
// os.RemoveAll(pkg.GetVal(pkg.CacheName))
//}
// clear
// 程序都结束了,没有必要清理内存了
// fingerprint.ClearData()
}()
options := naaburunner.ParseOptions()
szTip := ""
if options.Debug && pkg.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)
}
pkg.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)
}
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)
myConst.Wg.Wait()
myConst.StopAll()
}