Skip to content

Commit 059d7e7

Browse files
authored
Malicious code scanner (#614)
1 parent 6976bb9 commit 059d7e7

File tree

27 files changed

+1187
-15
lines changed

27 files changed

+1187
-15
lines changed

cli/docs/flags.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
GitCountContributors = "count-contributors"
2626
Enrich = "sbom-enrich"
2727
UploadCdx = "upload-cdx"
28+
MaliciousScan = "malicious-scan"
2829

2930
// TODO: Deprecated commands (remove at next CLI major version)
3031
AuditMvn = "audit-maven"
@@ -129,6 +130,7 @@ const (
129130
ScanVuln = scanPrefix + Vuln
130131
SecretValidation = "validate-secrets"
131132
StaticSca = "static-sca"
133+
malProjectKey = Project
132134
scanProjectKey = scanPrefix + Project
133135
uploadProjectKey = UploadCdx + "-" + Project
134136

@@ -175,6 +177,9 @@ var commandFlags = map[string][]string{
175177
Enrich: {
176178
Url, XrayUrl, user, password, accessToken, ServerId, Threads, InsecureTls,
177179
},
180+
MaliciousScan: {
181+
Url, XrayUrl, user, password, accessToken, ServerId, Threads, InsecureTls, OutputFormat, MinSeverity, AnalyzerManagerCustomPath, WorkingDirs, malProjectKey,
182+
},
178183
BuildScan: {
179184
Url, XrayUrl, user, password, accessToken, ServerId, scanProjectKey, BuildVuln, OutputFormat, Fail, ExtendedTable, Rescan, InsecureTls, TriggerScanRetries,
180185
},
@@ -256,6 +261,7 @@ var flagsMap = map[string]components.Flag{
256261
scanRegexp: components.NewBoolFlag(RegexpFlag, "Set to true to use a regular expression instead of wildcards expression to collect files to scan."),
257262
scanAnt: components.NewBoolFlag(AntFlag, "Set to true to use an ant pattern instead of wildcards expression to collect files to scan."),
258263
scanProjectKey: components.NewStringFlag(Project, "JFrog project key, to enable Xray to determine security violations accordingly. The command accepts this option only if the --repo-path and --watches options are not provided. If none of the three options are provided, the command will show all known vulnerabilities."),
264+
malProjectKey: components.NewStringFlag(Project, "JFrog project key"),
259265
uploadProjectKey: components.NewStringFlag(Project, "JFrog project key to upload the file to."),
260266
Watches: components.NewStringFlag(Watches, "Comma-separated list of Xray watches to determine violations. Supported violations are CVEs, operational risk, and Licenses. Incompatible with --project and --repo-path."),
261267
RepoPath: components.NewStringFlag(RepoPath, "Artifactory repository path, to enable Xray to determine violations accordingly. The command accepts this option only if the --project and --watches options are not provided. If none of the three options are provided, the command will show all known vulnerabilities."),

cli/docs/maliciousscan/help.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package maliciousscan
2+
3+
import (
4+
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
5+
)
6+
7+
func GetDescription() string {
8+
return "[Beta] Scan malicious models (pickle files, etc.) located in the working directory."
9+
}
10+
11+
func GetArguments() []components.Argument {
12+
return []components.Argument{}
13+
}

cli/scancommands.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
flags "github.com/jfrog/jfrog-cli-security/cli/docs"
2222
auditSpecificDocs "github.com/jfrog/jfrog-cli-security/cli/docs/auditspecific"
2323
enrichDocs "github.com/jfrog/jfrog-cli-security/cli/docs/enrich"
24+
maliciousScanDocs "github.com/jfrog/jfrog-cli-security/cli/docs/maliciousscan"
2425
mcpDocs "github.com/jfrog/jfrog-cli-security/cli/docs/mcp"
2526
auditDocs "github.com/jfrog/jfrog-cli-security/cli/docs/scan/audit"
2627
buildScanDocs "github.com/jfrog/jfrog-cli-security/cli/docs/scan/buildscan"
@@ -40,6 +41,7 @@ import (
4041

4142
"github.com/jfrog/jfrog-cli-security/commands/audit"
4243
"github.com/jfrog/jfrog-cli-security/commands/curation"
44+
"github.com/jfrog/jfrog-cli-security/commands/maliciousscan"
4345
"github.com/jfrog/jfrog-cli-security/commands/scan"
4446
"github.com/jfrog/jfrog-cli-security/commands/upload"
4547

@@ -72,6 +74,15 @@ func getAuditAndScansCommands() []components.Command {
7274
Category: securityCategory,
7375
Action: EnrichCmd,
7476
},
77+
{
78+
Name: "malicious-scan",
79+
Aliases: []string{"ms"},
80+
Flags: flags.GetCommandFlags(flags.MaliciousScan),
81+
Description: maliciousScanDocs.GetDescription(),
82+
Arguments: maliciousScanDocs.GetArguments(),
83+
Category: securityCategory,
84+
Action: MaliciousScanCmd,
85+
},
7586
{
7687
Name: "build-scan",
7788
Aliases: []string{"bs"},
@@ -230,6 +241,43 @@ func EnrichCmd(c *components.Context) error {
230241
return commandsCommon.Exec(EnrichCmd)
231242
}
232243

244+
func MaliciousScanCmd(c *components.Context) error {
245+
serverDetails, err := CreateServerDetailsFromFlags(c)
246+
if err != nil {
247+
return err
248+
}
249+
if err = validateConnectionInputs(serverDetails); err != nil {
250+
return err
251+
}
252+
format, err := outputFormat.GetOutputFormat(c.GetStringFlagValue(flags.OutputFormat))
253+
if err != nil {
254+
return err
255+
}
256+
threads, err := pluginsCommon.GetThreadsCount(c)
257+
if err != nil {
258+
return err
259+
}
260+
minSeverity, err := getMinimumSeverity(c)
261+
if err != nil {
262+
return err
263+
}
264+
workingDirs := []string{}
265+
if c.GetStringFlagValue(flags.WorkingDirs) != "" {
266+
workingDirs = splitByCommaAndTrim(c.GetStringFlagValue(flags.WorkingDirs))
267+
}
268+
maliciousScanCmd := maliciousscan.NewMaliciousScanCommand().
269+
SetServerDetails(serverDetails).
270+
SetWorkingDirs(workingDirs).
271+
SetThreads(threads).
272+
SetOutputFormat(format).
273+
SetMinSeverityFilter(minSeverity).
274+
SetProject(getProject(c))
275+
if c.IsFlagSet(flags.AnalyzerManagerCustomPath) {
276+
maliciousScanCmd.SetCustomAnalyzerManagerPath(c.GetStringFlagValue(flags.AnalyzerManagerCustomPath))
277+
}
278+
return commandsCommon.Exec(maliciousScanCmd)
279+
}
280+
233281
func ScanCmd(c *components.Context) error {
234282
if len(c.Arguments) == 0 && !c.IsFlagSet(flags.SpecFlag) {
235283
return pluginsCommon.PrintHelpAndReturnError("providing either a <source pattern> argument or the 'spec' option is mandatory", c)

0 commit comments

Comments
 (0)