Skip to content

Commit 8ec2d27

Browse files
committed
add: scanner configs
1 parent 54e8ff0 commit 8ec2d27

5 files changed

Lines changed: 31 additions & 7 deletions

File tree

internal/config/default.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ func Default() Config {
1818
},
1919
Scanner: scanner.Config{
2020
Command: "python scanner.py --host %s",
21+
Enable: false,
22+
Defaults: []string{
23+
"2fa",
24+
"authentication",
25+
"injection",
26+
},
2127
},
2228
MySQL: sql.Config{
2329
Host: "127.0.0.1",

internal/config/scanner/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package scanner
22

33
type Config struct {
4-
Command string `koanf:"command"`
4+
Command string `koanf:"command"`
5+
Enable bool `koanf:"enable"`
6+
Defaults []string `koanf:"defaults"`
57
}

internal/core/scanner/scanner.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ package scanner
33
import "os/exec"
44

55
// Scan a host by using apt-scanner
6-
func Scan(command string) ([]string, error) {
6+
func Scan(command string, enable bool, defaults ...string) ([]string, error) {
77
r := new(report)
88

9+
// load default vulnerabilities
10+
for _, tmp := range defaults {
11+
r.vulnerabilities = append(r.vulnerabilities, tmp)
12+
}
13+
14+
// check scanner enable
15+
if !enable {
16+
return r.vulnerabilities, nil
17+
}
18+
919
// execute command
1020
cmd := exec.Command(command)
1121
if err := cmd.Start(); err != nil {

internal/core/worker/pool.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package worker
22

33
import (
44
"github.com/ptaas-tool/base-api/internal/config"
5+
"github.com/ptaas-tool/base-api/internal/config/scanner"
56
"log"
67

78
"github.com/ptaas-tool/base-api/internal/config/ftp"
@@ -11,10 +12,11 @@ import (
1112
)
1213

1314
type Pool struct {
14-
cfg ftp.Config
15-
ai ai.Config
16-
client client.HTTPClient
17-
models *models.Interface
15+
cfg ftp.Config
16+
ai ai.Config
17+
scanner scanner.Config
18+
client client.HTTPClient
19+
models *models.Interface
1820

1921
template string
2022
capacity int
@@ -29,6 +31,7 @@ func New(cfg config.Config, client client.HTTPClient, models *models.Interface,
2931
ai: cfg.AI,
3032
cfg: cfg.FTP,
3133
client: client,
34+
scanner: cfg.Scanner,
3235
models: models,
3336
capacity: capacity,
3437
template: template,
@@ -60,6 +63,7 @@ func (p *Pool) Register() {
6063
ai: &aiInstance,
6164
cfg: p.cfg,
6265
client: p.client,
66+
scanner: p.scanner,
6367
models: p.models,
6468
channel: p.channel,
6569
reruns: p.reruns,

internal/core/worker/worker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/ptaas-tool/base-api/internal/config/ftp"
12+
scannerCfg "github.com/ptaas-tool/base-api/internal/config/scanner"
1213
"github.com/ptaas-tool/base-api/internal/core/ai"
1314
"github.com/ptaas-tool/base-api/internal/core/scanner"
1415
"github.com/ptaas-tool/base-api/internal/utils/crypto"
@@ -27,6 +28,7 @@ type worker struct {
2728
done chan int
2829
template string
2930
cfg ftp.Config
31+
scanner scannerCfg.Config
3032
client client.HTTPClient
3133
models *models.Interface
3234
ai *ai.AI
@@ -190,7 +192,7 @@ func (w worker) execute(id int) {
190192
})
191193

192194
// start scanner
193-
vulnerabilities, err := scanner.Scan(command)
195+
vulnerabilities, err := scanner.Scan(command, w.scanner.Enable, w.scanner.Defaults...)
194196
if err != nil {
195197
log.Println(fmt.Errorf("[worker.execute] failed to scan host error=%w", err))
196198
}

0 commit comments

Comments
 (0)