Skip to content

Commit

Permalink
增加API功能,适合工具联动使用
Browse files Browse the repository at this point in the history
  • Loading branch information
keac committed May 21, 2024
1 parent ca2965c commit 27c795d
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 56 deletions.
1 change: 1 addition & 0 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type ENOptions struct {
IsMergeOut bool //聚合
IsNoMerge bool //聚合
OutPutType string // 导出文件类型
IsApiMode bool
ENConfig *ENConfig
}

Expand Down
1 change: 1 addition & 0 deletions common/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func Flag(Info *ENOptions) {
flag.BoolVar(&Info.IsShow, "is-show", true, "是否展示信息输出")
//其他设定
flag.BoolVar(&Info.IsGroup, "is-group", false, "查询关键词为集团")
flag.BoolVar(&Info.IsApiMode, "api", false, "API模式运行")
flag.BoolVar(&Info.ISKeyPid, "is-pid", false, "批量查询文件是否为公司PID")
flag.IntVar(&Info.DelayTime, "delay", 0, "每个请求延迟(S)-1为随机延迟1-5S")
flag.StringVar(&Info.Proxy, "proxy", "", "设置代理")
Expand Down
4 changes: 3 additions & 1 deletion common/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"flag"
"github.com/gin-gonic/gin"
"github.com/projectdiscovery/gologger/levels"
"github.com/wgpsec/ENScan/common/gologger"
"github.com/wgpsec/ENScan/common/utils"
Expand All @@ -16,6 +17,7 @@ func Parse(options *ENOptions) {
//DEBUG模式设定
if options.IsDebug {
gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)
gin.SetMode(gin.DebugMode)
gologger.Debug().Msgf("DEBUG 模式已开启\n")
}

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

if options.KeyWord == "" && options.CompanyID == "" && options.InputFile == "" {
if options.KeyWord == "" && options.CompanyID == "" && options.InputFile == "" && !options.IsApiMode {
flag.PrintDefaults()
os.Exit(0)
}
Expand Down
29 changes: 15 additions & 14 deletions enscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,33 @@ import (
)

func main() {
var enOptions common.ENOptions
common.Flag(&enOptions)
common.Parse(&enOptions)
var quitSig = make(chan os.Signal, 1)
signal.Notify(quitSig, os.Interrupt, os.Kill)
go func() {
for {
select {
case <-quitSig:
gologger.Error().Msgf("任务未完成退出,自动保存过程文件!")
enDataList := make(map[string][]map[string]string)
close(runner.EnCh)
if len(runner.EnCh) > 0 {
for ch := range runner.EnCh {
utils.MergeMap(ch, enDataList)
}
err := common.OutFileByEnInfo(enDataList, "意外退出保存文件", "xlsx", "outs")
if err != nil {
gologger.Error().Msgf(err.Error())
if !enOptions.IsApiMode {
gologger.Error().Msgf("任务未完成退出,自动保存过程文件!")
enDataList := make(map[string][]map[string]string)
close(runner.EnCh)
if len(runner.EnCh) > 0 {
for ch := range runner.EnCh {
utils.MergeMap(ch, enDataList)
}
err := common.OutFileByEnInfo(enDataList, "意外退出保存文件", "xlsx", "outs")
if err != nil {
gologger.Error().Msgf(err.Error())
}
}
}
log.Fatal("exit.by.signal")
}
}
}()

var enOptions common.ENOptions
common.Flag(&enOptions)
common.Parse(&enOptions)
runner.RunEnumeration(&enOptions)

}
29 changes: 25 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
github.com/antchfx/htmlquery v1.3.1
github.com/gin-gonic/gin v1.10.0
github.com/go-resty/resty/v2 v2.7.0
github.com/olekukonko/tablewriter v0.0.5
github.com/projectdiscovery/gologger v1.1.12
Expand All @@ -12,37 +13,57 @@ require (
github.com/tidwall/sjson v1.2.3
github.com/xuri/excelize/v2 v2.8.1
go.mongodb.org/mongo-driver v1.9.0
golang.org/x/net v0.21.0
golang.org/x/net v0.25.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/antchfx/xpath v1.3.0 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mholt/archiver/v3 v3.5.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pierrec/lz4/v4 v4.1.2 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 27c795d

Please sign in to comment.