Skip to content

Commit 27c795d

Browse files
committed
增加API功能,适合工具联动使用
1 parent ca2965c commit 27c795d

File tree

9 files changed

+196
-56
lines changed

9 files changed

+196
-56
lines changed

common/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type ENOptions struct {
4747
IsMergeOut bool //聚合
4848
IsNoMerge bool //聚合
4949
OutPutType string // 导出文件类型
50+
IsApiMode bool
5051
ENConfig *ENConfig
5152
}
5253

common/flag.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func Flag(Info *ENOptions) {
4747
flag.BoolVar(&Info.IsShow, "is-show", true, "是否展示信息输出")
4848
//其他设定
4949
flag.BoolVar(&Info.IsGroup, "is-group", false, "查询关键词为集团")
50+
flag.BoolVar(&Info.IsApiMode, "api", false, "API模式运行")
5051
flag.BoolVar(&Info.ISKeyPid, "is-pid", false, "批量查询文件是否为公司PID")
5152
flag.IntVar(&Info.DelayTime, "delay", 0, "每个请求延迟(S)-1为随机延迟1-5S")
5253
flag.StringVar(&Info.Proxy, "proxy", "", "设置代理")

common/parse.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package common
22

33
import (
44
"flag"
5+
"github.com/gin-gonic/gin"
56
"github.com/projectdiscovery/gologger/levels"
67
"github.com/wgpsec/ENScan/common/gologger"
78
"github.com/wgpsec/ENScan/common/utils"
@@ -16,6 +17,7 @@ func Parse(options *ENOptions) {
1617
//DEBUG模式设定
1718
if options.IsDebug {
1819
gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)
20+
gin.SetMode(gin.DebugMode)
1921
gologger.Debug().Msgf("DEBUG 模式已开启\n")
2022
}
2123

@@ -52,7 +54,7 @@ func Parse(options *ENOptions) {
5254
gologger.Fatal().Msgf("配置文件当前[V%.1f] 程序需要[V%.1f] 不匹配,请备份配置文件重新运行-v\n", conf.Version, cfgYV)
5355
}
5456

55-
if options.KeyWord == "" && options.CompanyID == "" && options.InputFile == "" {
57+
if options.KeyWord == "" && options.CompanyID == "" && options.InputFile == "" && !options.IsApiMode {
5658
flag.PrintDefaults()
5759
os.Exit(0)
5860
}

enscan.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,33 @@ import (
1111
)
1212

1313
func main() {
14+
var enOptions common.ENOptions
15+
common.Flag(&enOptions)
16+
common.Parse(&enOptions)
1417
var quitSig = make(chan os.Signal, 1)
1518
signal.Notify(quitSig, os.Interrupt, os.Kill)
1619
go func() {
1720
for {
1821
select {
1922
case <-quitSig:
20-
gologger.Error().Msgf("任务未完成退出,自动保存过程文件!")
21-
enDataList := make(map[string][]map[string]string)
22-
close(runner.EnCh)
23-
if len(runner.EnCh) > 0 {
24-
for ch := range runner.EnCh {
25-
utils.MergeMap(ch, enDataList)
26-
}
27-
err := common.OutFileByEnInfo(enDataList, "意外退出保存文件", "xlsx", "outs")
28-
if err != nil {
29-
gologger.Error().Msgf(err.Error())
23+
if !enOptions.IsApiMode {
24+
gologger.Error().Msgf("任务未完成退出,自动保存过程文件!")
25+
enDataList := make(map[string][]map[string]string)
26+
close(runner.EnCh)
27+
if len(runner.EnCh) > 0 {
28+
for ch := range runner.EnCh {
29+
utils.MergeMap(ch, enDataList)
30+
}
31+
err := common.OutFileByEnInfo(enDataList, "意外退出保存文件", "xlsx", "outs")
32+
if err != nil {
33+
gologger.Error().Msgf(err.Error())
34+
}
3035
}
3136
}
3237
log.Fatal("exit.by.signal")
3338
}
3439
}
3540
}()
36-
37-
var enOptions common.ENOptions
38-
common.Flag(&enOptions)
39-
common.Parse(&enOptions)
4041
runner.RunEnumeration(&enOptions)
4142

4243
}

go.mod

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.21
44

55
require (
66
github.com/antchfx/htmlquery v1.3.1
7+
github.com/gin-gonic/gin v1.10.0
78
github.com/go-resty/resty/v2 v2.7.0
89
github.com/olekukonko/tablewriter v0.0.5
910
github.com/projectdiscovery/gologger v1.1.12
@@ -12,37 +13,57 @@ require (
1213
github.com/tidwall/sjson v1.2.3
1314
github.com/xuri/excelize/v2 v2.8.1
1415
go.mongodb.org/mongo-driver v1.9.0
15-
golang.org/x/net v0.21.0
16+
golang.org/x/net v0.25.0
1617
gopkg.in/yaml.v2 v2.4.0
1718
)
1819

1920
require (
2021
github.com/andybalholm/brotli v1.0.6 // indirect
2122
github.com/antchfx/xpath v1.3.0 // indirect
23+
github.com/bytedance/sonic v1.11.6 // indirect
24+
github.com/bytedance/sonic/loader v0.1.1 // indirect
25+
github.com/cloudwego/base64x v0.1.4 // indirect
26+
github.com/cloudwego/iasm v0.2.0 // indirect
2227
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
28+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
29+
github.com/gin-contrib/sse v0.1.0 // indirect
30+
github.com/go-playground/locales v0.14.1 // indirect
31+
github.com/go-playground/universal-translator v0.18.1 // indirect
32+
github.com/go-playground/validator/v10 v10.20.0 // indirect
33+
github.com/goccy/go-json v0.10.2 // indirect
2334
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
2435
github.com/golang/snappy v0.0.4 // indirect
2536
github.com/json-iterator/go v1.1.12 // indirect
2637
github.com/klauspost/compress v1.13.6 // indirect
38+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
2739
github.com/klauspost/pgzip v1.2.5 // indirect
40+
github.com/leodido/go-urn v1.4.0 // indirect
2841
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
42+
github.com/mattn/go-isatty v0.0.20 // indirect
2943
github.com/mattn/go-runewidth v0.0.9 // indirect
3044
github.com/mholt/archiver/v3 v3.5.1 // indirect
31-
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
45+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3246
github.com/modern-go/reflect2 v1.0.2 // indirect
3347
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
3448
github.com/nwaples/rardecode v1.1.3 // indirect
49+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
3550
github.com/pierrec/lz4/v4 v4.1.2 // indirect
3651
github.com/richardlehane/mscfb v1.0.4 // indirect
3752
github.com/richardlehane/msoleps v1.0.3 // indirect
3853
github.com/tidwall/match v1.1.1 // indirect
3954
github.com/tidwall/pretty v1.2.0 // indirect
55+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
56+
github.com/ugorji/go/codec v1.2.12 // indirect
4057
github.com/ulikunitz/xz v0.5.11 // indirect
4158
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
4259
github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect
4360
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
44-
golang.org/x/crypto v0.19.0 // indirect
45-
golang.org/x/text v0.14.0 // indirect
61+
golang.org/x/arch v0.8.0 // indirect
62+
golang.org/x/crypto v0.23.0 // indirect
63+
golang.org/x/sys v0.20.0 // indirect
64+
golang.org/x/text v0.15.0 // indirect
65+
google.golang.org/protobuf v1.34.1 // indirect
4666
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
4767
gopkg.in/sourcemap.v1 v1.0.5 // indirect
68+
gopkg.in/yaml.v3 v3.0.1 // indirect
4869
)

0 commit comments

Comments
 (0)