/
generate.go
44 lines (34 loc) · 992 Bytes
/
generate.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
package cmd
import (
"errors"
"github.com/4armed/cve-2023-5044/pkg/poc"
"github.com/spf13/cobra"
)
func GenerateCmd(o *Options) *cobra.Command {
cmd := &cobra.Command{
Use: "generate",
Short: "Generate an ingress object to exploit CVE-2023-5044",
Long: "Generate an ingress object to exploit CVE-2023-5044",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return o.Generate()
},
}
o.PrintFlags.AddFlags(cmd)
return cmd
}
func (o *Options) Generate() error {
if o.ConfigFlags.Namespace == nil || *o.ConfigFlags.Namespace == "" {
ns := "default"
o.ConfigFlags.Namespace = &ns
}
i := poc.Generate(*o.ConfigFlags.Namespace, o.IngressObjectNamePrefix, o.RedirectPath, o.CloseItOffPath, o.ExploitCommand)
if o.PrintFlags.OutputFormat == nil {
return errors.New("no output format specified")
}
printer, err := o.PrintFlags.ToPrinter()
if err != nil {
return err
}
return printer.PrintObj(i, o.Out)
}