-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
301 additions
and
413 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"golang.org/x/text/cases" | ||
"golang.org/x/text/language" | ||
"gopkg.in/yaml.v3" | ||
|
||
"github.com/crowdsecurity/crowdsec/pkg/appsec" | ||
"github.com/crowdsecurity/crowdsec/pkg/appsec/appsec_rule" | ||
"github.com/crowdsecurity/crowdsec/pkg/cwhub" | ||
) | ||
|
||
func NewAppsecConfigCLI() *itemCLI { | ||
return &itemCLI{ | ||
name: cwhub.APPSEC_CONFIGS, | ||
singular: "appsec-config", | ||
oneOrMore: "appsec-config(s)", | ||
help: cliHelp{ | ||
example: `cscli appsec-configs list -a | ||
cscli appsec-configs install crowdsecurity/vpatch | ||
cscli appsec-configs inspect crowdsecurity/vpatch | ||
cscli appsec-configs upgrade crowdsecurity/vpatch | ||
cscli appsec-configs remove crowdsecurity/vpatch | ||
`, | ||
}, | ||
installHelp: cliHelp{ | ||
example: `cscli appsec-configs install crowdsecurity/vpatch`, | ||
}, | ||
removeHelp: cliHelp{ | ||
example: `cscli appsec-configs remove crowdsecurity/vpatch`, | ||
}, | ||
upgradeHelp: cliHelp{ | ||
example: `cscli appsec-configs upgrade crowdsecurity/vpatch`, | ||
}, | ||
inspectHelp: cliHelp{ | ||
example: `cscli appsec-configs inspect crowdsecurity/vpatch`, | ||
}, | ||
listHelp: cliHelp{ | ||
example: `cscli appsec-configs list | ||
cscli appsec-configs list -a | ||
cscli appsec-configs list crowdsecurity/vpatch`, | ||
}, | ||
} | ||
} | ||
|
||
func NewAppsecRuleCLI() *itemCLI { | ||
inspectDetail := func(item *cwhub.Item) error { | ||
appsecRule := appsec.AppsecCollectionConfig{} | ||
yamlContent, err := os.ReadFile(item.State.LocalPath) | ||
if err != nil { | ||
return fmt.Errorf("unable to read file %s : %s", item.State.LocalPath, err) | ||
} | ||
if err := yaml.Unmarshal(yamlContent, &appsecRule); err != nil { | ||
return fmt.Errorf("unable to unmarshal yaml file %s : %s", item.State.LocalPath, err) | ||
} | ||
|
||
for _, ruleType := range appsec_rule.SupportedTypes() { | ||
fmt.Printf("\n%s format:\n", cases.Title(language.Und, cases.NoLower).String(ruleType)) | ||
for _, rule := range appsecRule.Rules { | ||
convertedRule, _, err := rule.Convert(ruleType, appsecRule.Name) | ||
if err != nil { | ||
return fmt.Errorf("unable to convert rule %s : %s", rule.Name, err) | ||
} | ||
fmt.Println(convertedRule) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
return &itemCLI{ | ||
name: "appsec-rules", | ||
singular: "appsec-rule", | ||
oneOrMore: "appsec-rule(s)", | ||
help: cliHelp{ | ||
example: `cscli appsec-rules list -a | ||
cscli appsec-rules install crowdsecurity/crs | ||
cscli appsec-rules inspect crowdsecurity/crs | ||
cscli appsec-rules upgrade crowdsecurity/crs | ||
cscli appsec-rules remove crowdsecurity/crs | ||
`, | ||
}, | ||
installHelp: cliHelp{ | ||
example: `cscli appsec-rules install crowdsecurity/crs`, | ||
}, | ||
removeHelp: cliHelp{ | ||
example: `cscli appsec-rules remove crowdsecurity/crs`, | ||
}, | ||
upgradeHelp: cliHelp{ | ||
example: `cscli appsec-rules upgrade crowdsecurity/crs`, | ||
}, | ||
inspectHelp: cliHelp{ | ||
example: `cscli appsec-rules inspect crowdsecurity/crs`, | ||
}, | ||
inspectDetail: inspectDetail, | ||
listHelp: cliHelp{ | ||
example: `cscli appsec-rules list | ||
cscli appsec-rules list -a | ||
cscli appsec-rules list crowdsecurity/crs`, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/crowdsecurity/crowdsec/pkg/cwhub" | ||
) | ||
|
||
func NewCollectionCLI() *itemCLI { | ||
return &itemCLI{ | ||
name: cwhub.COLLECTIONS, | ||
singular: "collection", | ||
oneOrMore: "collection(s)", | ||
help: cliHelp{ | ||
example: `cscli collections list -a | ||
cscli collections install crowdsecurity/http-cve crowdsecurity/iptables | ||
cscli collections inspect crowdsecurity/http-cve crowdsecurity/iptables | ||
cscli collections upgrade crowdsecurity/http-cve crowdsecurity/iptables | ||
cscli collections remove crowdsecurity/http-cve crowdsecurity/iptables | ||
`, | ||
}, | ||
installHelp: cliHelp{ | ||
example: `cscli collections install crowdsecurity/http-cve crowdsecurity/iptables`, | ||
}, | ||
removeHelp: cliHelp{ | ||
example: `cscli collections remove crowdsecurity/http-cve crowdsecurity/iptables`, | ||
}, | ||
upgradeHelp: cliHelp{ | ||
example: `cscli collections upgrade crowdsecurity/http-cve crowdsecurity/iptables`, | ||
}, | ||
inspectHelp: cliHelp{ | ||
example: `cscli collections inspect crowdsecurity/http-cve crowdsecurity/iptables`, | ||
}, | ||
listHelp: cliHelp{ | ||
example: `cscli collections list | ||
cscli collections list -a | ||
cscli collections list crowdsecurity/http-cve crowdsecurity/iptables | ||
List only enabled collections unless "-a" or names are specified.`, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/crowdsecurity/crowdsec/pkg/cwhub" | ||
) | ||
|
||
func NewParserCLI() *itemCLI { | ||
return &itemCLI{ | ||
name: cwhub.PARSERS, | ||
singular: "parser", | ||
oneOrMore: "parser(s)", | ||
help: cliHelp{ | ||
example: `cscli parsers list -a | ||
cscli parsers install crowdsecurity/caddy-logs crowdsecurity/sshd-logs | ||
cscli parsers inspect crowdsecurity/caddy-logs crowdsecurity/sshd-logs | ||
cscli parsers upgrade crowdsecurity/caddy-logs crowdsecurity/sshd-logs | ||
cscli parsers remove crowdsecurity/caddy-logs crowdsecurity/sshd-logs | ||
`, | ||
}, | ||
installHelp: cliHelp{ | ||
example: `cscli parsers install crowdsecurity/caddy-logs crowdsecurity/sshd-logs`, | ||
}, | ||
removeHelp: cliHelp{ | ||
example: `cscli parsers remove crowdsecurity/caddy-logs crowdsecurity/sshd-logs`, | ||
}, | ||
upgradeHelp: cliHelp{ | ||
example: `cscli parsers upgrade crowdsecurity/caddy-logs crowdsecurity/sshd-logs`, | ||
}, | ||
inspectHelp: cliHelp{ | ||
example: `cscli parsers inspect crowdsecurity/httpd-logs crowdsecurity/sshd-logs`, | ||
}, | ||
listHelp: cliHelp{ | ||
example: `cscli parsers list | ||
cscli parsers list -a | ||
cscli parsers list crowdsecurity/caddy-logs crowdsecurity/sshd-logs | ||
List only enabled parsers unless "-a" or names are specified.`, | ||
}, | ||
} | ||
} |
Oops, something went wrong.