Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 1.1.1 - 2024-04-04

* Fix bug in SPN smart feedback
* Add tag flag to example tools

## 1.1.0 - 2024-04-03

* Update protos
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ You can enable PML detection by calling the `SetPMLEnable` function:
client.SetPMLEnable()
```

### Enable SPN feedback

You can enable SPN feedback by calling the `SetFeedbackEnable` function:

```go
client.SetFeedbackEnable()
```

## Usage Examples
As examples, you can find two important files in the `tools/` directory of the SDK package:

Expand Down Expand Up @@ -182,6 +190,12 @@ API key for service authentication if authentication is enabled
`-pml`
Specify to enable PML (Predictive Machine Learning) detection

`-feedback`
Specify to enable SPN feedback

`-tag <string>`
Specify the tags to be used for scanning, separated by commas

### scanfiles

This is another program that uses the gRPC client library to communicate with our server. Depending on whether or not the `-good` flag is specified, and the scan result returned from the scan, the program will output result that shows the testing was successful or not.
Expand Down Expand Up @@ -214,6 +228,13 @@ API key for service authentication if authentication is enabled
`-pml`
Specify to enable PML (Predictive Machine Learning) detection

`-feedback`
Specify to enable SPN feedback

`-tag <string>`
Specify the tags to be used for scanning, separated by commas


## Proxy Configuration

The cli tool loads the proxy configuration from the following set of optional environment variables
Expand Down
17 changes: 11 additions & 6 deletions grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ type AmaasClient struct {
appName string
archHandler AmaasClientArchiveHandler
pml bool
feedback bool
}

func scanRun(ctx context.Context, cancel context.CancelFunc, c pb.ScanClient, dataReader AmaasClientReader, disableCache bool, tags []string, pml bool, bulk bool) (string, error) {
func scanRun(ctx context.Context, cancel context.CancelFunc, c pb.ScanClient, dataReader AmaasClientReader, disableCache bool, tags []string, pml bool, bulk bool, feedback bool) (string, error) {

defer cancel()

Expand Down Expand Up @@ -274,7 +275,7 @@ func scanRun(ctx context.Context, cancel context.CancelFunc, c pb.ScanClient, da

hashSha1, _ := dataReader.Hash("sha1")

if err = runInitRequest(stream, dataReader.Identifier(), uint64(size), hashSha256, hashSha1, tags, pml, bulk); err != nil {
if err = runInitRequest(stream, dataReader.Identifier(), uint64(size), hashSha256, hashSha1, tags, pml, bulk, feedback); err != nil {
return makeFailedScanJSONResp(), err
}

Expand All @@ -290,9 +291,9 @@ func scanRun(ctx context.Context, cancel context.CancelFunc, c pb.ScanClient, da
return result, nil
}

func runInitRequest(stream pb.Scan_RunClient, identifier string, dataSize uint64, hashSha256 string, hashSha1 string, tags []string, pml bool, bulk bool) error {
func runInitRequest(stream pb.Scan_RunClient, identifier string, dataSize uint64, hashSha256 string, hashSha1 string, tags []string, pml bool, bulk bool, feedback bool) error {
if err := stream.Send(&pb.C2S{Stage: pb.Stage_STAGE_INIT,
FileName: identifier, RsSize: dataSize, FileSha256: hashSha256, FileSha1: hashSha1, Tags: tags, Trendx: pml, Bulk: bulk}); err != nil {
FileName: identifier, RsSize: dataSize, FileSha256: hashSha256, FileSha1: hashSha1, Tags: tags, Trendx: pml, Bulk: bulk, SpnFeedback: feedback}); err != nil {
err = sanitizeGRPCError(err)
logMsg(LogLevelError, MSG("MSG_ID_ERR_INIT"), err)
return err
Expand Down Expand Up @@ -409,7 +410,7 @@ func (ac *AmaasClient) bufferScanRun(buffer []byte, identifier string, tags []st

ctx = ac.buildAppNameContext(ctx)

return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), bufferReader, ac.disableCache, tags, ac.pml, true)
return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), bufferReader, ac.disableCache, tags, ac.pml, true, ac.feedback)
}

func (ac *AmaasClient) fileScanRun(fileName string, tags []string) (string, error) {
Expand Down Expand Up @@ -439,7 +440,7 @@ func (ac *AmaasClient) fileScanRunNormalFile(fileName string, tags []string) (st

ctx = ac.buildAppNameContext(ctx)

return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), fileReader, ac.disableCache, tags, ac.pml, true)
return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), fileReader, ac.disableCache, tags, ac.pml, true, ac.feedback)
}

func (ac *AmaasClient) setupComm() error {
Expand Down Expand Up @@ -1001,6 +1002,10 @@ func (ac *AmaasClient) SetPMLEnable() {
ac.pml = true
}

func (ac *AmaasClient) SetFeedbackEnable() {
ac.feedback = true
}

func validateTags(tags []string) error {
if len(tags) == 0 {
return errors.New("tags cannot be empty")
Expand Down
2 changes: 1 addition & 1 deletion grpc_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func TestScanRunWithInvalidTags(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(180))

// act
_, err := scanRun(ctx, cancel, nil, nil, false, tt.tags, false, true)
_, err := scanRun(ctx, cancel, nil, nil, false, tt.tags, false, true, false)

// assert
assert.Equal(t, tt.expectedErr, err.Error())
Expand Down
14 changes: 13 additions & 1 deletion tools/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"log"
"os"
"strings"

amaasclient "github.com/trendmicro/tm-v1-fs-golang-sdk"
)
Expand All @@ -15,6 +16,8 @@ var (
enableTLS = flag.Bool("tls", false, "enable TLS")
region = flag.String("region", "", "the region to connect to")
pml = flag.Bool("pml", false, "enable predictive machine learning detection")
feedback = flag.Bool("feedback", false, "enable SPN feedback")
tag = flag.String("tag", "", "tags to be used for scanning")
)

func main() {
Expand Down Expand Up @@ -43,7 +46,16 @@ func main() {
client.SetPMLEnable()
}

result, err := client.ScanFile(*fileName, nil)
if *feedback {
client.SetFeedbackEnable()
}

var tagsArray []string
if *tag != "" {
tagsArray = strings.Split(*tag, ",")
}

result, err := client.ScanFile(*fileName, tagsArray)
if err != nil {
log.Fatalf(err.Error())
}
Expand Down
25 changes: 19 additions & 6 deletions tools/scanfiles/scanfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func main() {
var fileList []string
var region string
var pml bool
var feedback bool
var tag string

flag.StringVar(&path, "path", "", "Path of file or directory to scan.")
flag.BoolVar(&scanGoodFiles, "good", false, "Specify if scanning good/non-malicious files.")
Expand All @@ -63,6 +65,8 @@ func main() {
flag.BoolVar(&enableTLS, "tls", false, "Specify to enable server authentication by client for GRPC")
flag.StringVar(&region, "region", "", "the region to connect to")
flag.BoolVar(&pml, "pml", false, "enable predictive machine learning detection")
flag.BoolVar(&feedback, "feedback", false, "enable SPN feedback")
flag.StringVar(&tag, "tag", "", "tags to be used for scanning")

flag.Parse()

Expand Down Expand Up @@ -98,6 +102,15 @@ func main() {
ac.SetPMLEnable()
}

if feedback {
ac.SetFeedbackEnable()
}

var tagsArray []string
if tag != "" {
tagsArray = strings.Split(tag, ",")
}

if fileInfo.IsDir() {

files, err := ioutil.ReadDir(path)
Expand Down Expand Up @@ -125,9 +138,9 @@ func main() {

var tr OverallTestResult
if scanInParallel {
tr = scanFileListInParallel(fileList, scanGoodFiles, ac)
tr = scanFileListInParallel(fileList, scanGoodFiles, ac, tagsArray)
} else {
tr = scanFileListInSequence(fileList, scanGoodFiles, ac)
tr = scanFileListInSequence(fileList, scanGoodFiles, ac, tagsArray)
}

jsonData, _ := json.Marshal(tr)
Expand All @@ -138,7 +151,7 @@ func main() {
os.Exit(0)
}

func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient) OverallTestResult {
func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient, tags []string) OverallTestResult {

var tr OverallTestResult
tr.Passed = true
Expand All @@ -153,7 +166,7 @@ func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaa

sr.StartTime = time.Now()

jsonResult, err := scanner.ScanFile(fileList[i], nil)
jsonResult, err := scanner.ScanFile(fileList[i], tags)
if err != nil {
log.Print(err.Error())
}
Expand All @@ -173,7 +186,7 @@ func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaa
return tr
}

func scanFileListInParallel(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient) OverallTestResult {
func scanFileListInParallel(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient, tags []string) OverallTestResult {

var tr OverallTestResult
tr.Passed = true
Expand All @@ -192,7 +205,7 @@ func scanFileListInParallel(fileList []string, scanGoodFiles bool, scanner *amaa

sr.StartTime = time.Now()

jsonResult, err := scanner.ScanFile(f, nil)
jsonResult, err := scanner.ScanFile(f, tags)
if err != nil {
log.Print(err.Error())
}
Expand Down