-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
110 lines (94 loc) · 2.6 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"strings"
"time"
"gopkg.in/yaml.v2"
)
type ScanConfig struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata struct {
Name string `yaml:"name"`
} `yaml:"metadata"`
Spec struct {
ScanType string `yaml:"scanType"`
Parameters []string `yaml:"parameters"`
} `yaml:"spec"`
}
func main() {
// WELCOME Banner
fmt.Println(".............. WELCOME TO secureCodeBox CLI ..............")
// Print Scan Options
fmt.Println("Select Scan Type:")
fmt.Println("1- Scanning network")
fmt.Println("2- Repeat Scans on a Schedule")
fmt.Println("3- Scanning Web Application")
fmt.Println("4- Post-processing with Hooks")
fmt.Println("5- Storing Findings with Persistence Hooks")
fmt.Println("6- Automatically Scan your Cluster with Autodiscovery")
fmt.Println("7- Enforce Engagement")
reader := bufio.NewReader(os.Stdin)
//Get Scan Option input from User
fmt.Print("Enter your choice: ")
input, err := reader.ReadString('\n')
if err != nil {
fmt.Println("Error reading input:", err)
os.Exit(1)
}
//Choose Input Type
scanType := strings.TrimSpace(input)
//nmap Scanning and yaml file creation
if scanType == "1" || scanType == "Scanning network" {
var targetURL string
fmt.Print("Enter target URL: ")
targetURL, err = reader.ReadString('\n')
if err != nil {
fmt.Println("Error reading target URL:", err)
os.Exit(1)
}
targetURL = strings.TrimSpace(targetURL)
config := ScanConfig{
APIVersion: "execution.securecodebox.io/v1",
Kind: "Scan",
Metadata: struct {
Name string `yaml:"name"`
}{Name: fmt.Sprintf("nmap-%s", targetURL)},
Spec: struct {
ScanType string `yaml:"scanType"`
Parameters []string `yaml:"parameters"`
}{
ScanType: scanType,
Parameters: []string{
targetURL,
},
},
}
output, err := yaml.Marshal(&config)
if err != nil {
fmt.Println("Error marshalling YAML:", err)
os.Exit(1)
}
// Create the output_yaml directory if it doesnot already exist
if _, err := os.Stat("output_yaml"); os.IsNotExist(err) {
err := os.Mkdir("output_yaml", 0755)
if err != nil {
fmt.Println("Error creating output directory:", err)
os.Exit(1)
}
}
fileName := fmt.Sprintf("output_yaml/output_%s.yaml", time.Now().Format("2024-03-31-01-01-05"))
err = ioutil.WriteFile(fileName, output, 0644)
if err != nil {
fmt.Println("Error writing YAML file:", err)
os.Exit(1)
}
fmt.Println("YAML file generated successfully.")
} else {
//Other Scan options not created yet
fmt.Println("THIS PART IS NOT CREATED YET!")
}
}