Skip to content

Commit ba8ab58

Browse files
committed
embed poc
1 parent 35d3ddc commit ba8ab58

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

internal/runner/runner.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,25 @@ func New(options *config.Options, htemplate *html.HtmlTemplate, acb config.ApiCa
6161
}
6262

6363
// init pocs
64-
allPocsYamlSlice := []string{}
64+
allPocsEmbedYamlSlice := []string{}
6565
if len(options.PocsFilePath) > 0 {
6666
options.PocsDirectory.Set(options.PocsFilePath)
6767
// console print
6868
fmt.Println(" " + options.PocsFilePath)
6969
} else {
7070
// init default afrog-pocs
7171
if allDefaultPocsYamlSlice, err := pocs.GetPocs(); err == nil {
72-
allPocsYamlSlice = append(allPocsYamlSlice, allDefaultPocsYamlSlice...)
72+
allPocsEmbedYamlSlice = append(allPocsEmbedYamlSlice, allDefaultPocsYamlSlice...)
7373
}
7474
// init ~/afrog-pocs
7575
pocsDir, _ := poc.InitPocHomeDirectory()
7676
if len(pocsDir) > 0 {
7777
options.PocsDirectory.Set(pocsDir)
7878
}
7979
}
80-
allPocsYamlSlice = append(allPocsYamlSlice, runner.catalog.GetPocsPath(options.PocsDirectory)...)
80+
allPocsYamlSlice := runner.catalog.GetPocsPath(options.PocsDirectory)
8181

82-
if len(allPocsYamlSlice) == 0 {
82+
if len(allPocsYamlSlice) == 0 && len(allPocsEmbedYamlSlice) == 0 {
8383
return errors.New("未找到可执行脚本(POC),请检查`默认脚本`或指定新の脚本(POC)")
8484
}
8585

@@ -89,7 +89,7 @@ func New(options *config.Options, htemplate *html.HtmlTemplate, acb config.ApiCa
8989
}
9090

9191
// init scan sum
92-
options.Count = len(options.Targets) * len(allPocsYamlSlice)
92+
options.Count = len(options.Targets) * (len(allPocsYamlSlice) + len(allPocsEmbedYamlSlice))
9393

9494
// fmt.Println(ShowUsage())
9595

@@ -109,7 +109,7 @@ func New(options *config.Options, htemplate *html.HtmlTemplate, acb config.ApiCa
109109

110110
//
111111
e := core.New(options)
112-
e.Execute(allPocsYamlSlice)
112+
e.Execute(allPocsYamlSlice, allPocsEmbedYamlSlice)
113113

114114
return nil
115115
}

pkg/core/excute.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ import (
44
"github.com/zan8in/afrog/pkg/log"
55
"github.com/zan8in/afrog/pkg/poc"
66
"github.com/zan8in/afrog/pkg/utils"
7+
"github.com/zan8in/afrog/pocs"
78
)
89

910
var (
1011
ReverseCeyeApiKey string
1112
ReverseCeyeDomain string
1213
)
1314

14-
func (e *Engine) Execute(allPocsYamlSlice utils.StringSlice) {
15+
func (e *Engine) Execute(allPocsYamlSlice, allPocsEmbedYamlSlice utils.StringSlice) {
1516
ReverseCeyeApiKey = e.options.Config.Reverse.Ceye.ApiKey
1617
ReverseCeyeDomain = e.options.Config.Reverse.Ceye.Domain
1718

18-
//http2.Init(e.options)
19-
2019
var pocSlice []poc.Poc
2120

2221
for _, pocYaml := range allPocsYamlSlice {
@@ -28,6 +27,15 @@ func (e *Engine) Execute(allPocsYamlSlice utils.StringSlice) {
2827
pocSlice = append(pocSlice, p)
2928
}
3029

30+
for _, pocEmbedYaml := range allPocsEmbedYamlSlice {
31+
p, err := pocs.ReadPocs(pocEmbedYaml)
32+
if err != nil {
33+
log.Log().Error(err.Error())
34+
continue
35+
}
36+
pocSlice = append(pocSlice, p)
37+
}
38+
3139
swg := e.workPool.PocSwg
3240
for _, p := range pocSlice {
3341
swg.Add()

pocs/poc.go

+14-20
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,44 @@ package pocs
22

33
import (
44
"embed"
5-
"fmt"
65
"io/fs"
7-
"os"
8-
"path/filepath"
96
"strings"
7+
8+
"github.com/zan8in/afrog/pkg/poc"
9+
"gopkg.in/yaml.v2"
1010
)
1111

1212
//go:embed afrog-pocs/*
1313
var f embed.FS
1414

1515
func GetPocs() ([]string, error) {
1616
allPocs := []string{}
17+
1718
err := fs.WalkDir(f, ".", func(path string, d fs.DirEntry, err error) error {
1819
if err != nil {
1920
return err
2021
}
2122
// fmt.Printf("path=%q, isDir=%v\n", path, d.IsDir())
2223
if !d.IsDir() && strings.HasSuffix(path, ".yaml") || strings.HasSuffix(path, ".yml") {
23-
file := filepath.Base(path)
24-
absPath, err := resolvePath(filepath.Dir(path))
25-
if err != nil {
26-
return err
27-
}
28-
allPocs = append(allPocs, filepath.Join(absPath, file))
24+
allPocs = append(allPocs, path)
2925
}
3026
return nil
3127
})
28+
3229
return allPocs, err
3330
}
3431

35-
func resolvePath(pocName string) (string, error) {
36-
if filepath.IsAbs(pocName) {
37-
return pocName, nil
38-
}
32+
func ReadPocs(path string) (poc.Poc, error) {
33+
var poc = poc.Poc{}
3934

40-
curDirectory, err := os.Getwd()
35+
file, err := f.Open(path)
4136
if err != nil {
42-
return "", err
37+
return poc, err
4338
}
39+
defer file.Close()
4440

45-
pocPath := filepath.Join(curDirectory, "pocs", pocName)
46-
if len(pocPath) > 0 {
47-
return pocPath, nil
41+
if err := yaml.NewDecoder(file).Decode(&poc); err != nil {
42+
return poc, err
4843
}
49-
50-
return "", fmt.Errorf("no such path found: %s", pocName)
44+
return poc, nil
5145
}

0 commit comments

Comments
 (0)