8cca4346a5
Add a new datasource that: - Receives HTTP requests from remediation components - Apply rules on them to determine whether they are malicious or not - Rules can be evaluated in-band (the remediation component will block the request directly) or out-band (the RC will let the request through, but crowdsec can still process the rule matches with scenarios) The PR also adds support for 2 new hub items: - appsec-configs: Configure the Application Security Engine (which rules to load, in which phase) - appsec-rules: a rule that is added in the Application Security Engine (can use either our own format, or seclang) --------- Co-authored-by: alteredCoder <kevin@crowdsec.net> Co-authored-by: Sebastien Blot <sebastien@crowdsec.net> Co-authored-by: mmetc <92726601+mmetc@users.noreply.github.com> Co-authored-by: Marco Mariani <marco@crowdsec.net>
102 lines
2.6 KiB
Go
102 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/aquasecurity/table"
|
|
"github.com/enescakir/emoji"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/hubtest"
|
|
)
|
|
|
|
func hubTestResultTable(out io.Writer, testResult map[string]bool) {
|
|
t := newLightTable(out)
|
|
t.SetHeaders("Test", "Result")
|
|
t.SetHeaderAlignment(table.AlignLeft)
|
|
t.SetAlignment(table.AlignLeft)
|
|
|
|
for testName, success := range testResult {
|
|
status := emoji.CheckMarkButton.String()
|
|
if !success {
|
|
status = emoji.CrossMark.String()
|
|
}
|
|
|
|
t.AddRow(testName, status)
|
|
}
|
|
|
|
t.Render()
|
|
}
|
|
|
|
func hubTestListTable(out io.Writer, tests []*hubtest.HubTestItem) {
|
|
t := newLightTable(out)
|
|
t.SetHeaders("Name", "Path")
|
|
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft)
|
|
t.SetAlignment(table.AlignLeft, table.AlignLeft)
|
|
|
|
for _, test := range tests {
|
|
t.AddRow(test.Name, test.Path)
|
|
}
|
|
|
|
t.Render()
|
|
}
|
|
|
|
func hubTestParserCoverageTable(out io.Writer, coverage []hubtest.Coverage) {
|
|
t := newLightTable(out)
|
|
t.SetHeaders("Parser", "Status", "Number of tests")
|
|
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
|
|
parserTested := 0
|
|
|
|
for _, test := range coverage {
|
|
status := emoji.RedCircle.String()
|
|
if test.TestsCount > 0 {
|
|
status = emoji.GreenCircle.String()
|
|
parserTested++
|
|
}
|
|
t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
|
|
}
|
|
|
|
t.Render()
|
|
}
|
|
|
|
func hubTestAppsecRuleCoverageTable(out io.Writer, coverage []hubtest.Coverage) {
|
|
t := newLightTable(out)
|
|
t.SetHeaders("Appsec Rule", "Status", "Number of tests")
|
|
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
|
|
parserTested := 0
|
|
|
|
for _, test := range coverage {
|
|
status := emoji.RedCircle.String()
|
|
if test.TestsCount > 0 {
|
|
status = emoji.GreenCircle.String()
|
|
parserTested++
|
|
}
|
|
t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
|
|
}
|
|
|
|
t.Render()
|
|
}
|
|
|
|
func hubTestScenarioCoverageTable(out io.Writer, coverage []hubtest.Coverage) {
|
|
t := newLightTable(out)
|
|
t.SetHeaders("Scenario", "Status", "Number of tests")
|
|
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
|
|
parserTested := 0
|
|
|
|
for _, test := range coverage {
|
|
status := emoji.RedCircle.String()
|
|
if test.TestsCount > 0 {
|
|
status = emoji.GreenCircle.String()
|
|
parserTested++
|
|
}
|
|
t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
|
|
}
|
|
|
|
t.Render()
|
|
}
|