Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Scan): Password-protected files #80

Merged
merged 2 commits into from
Jul 20, 2023
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
17 changes: 16 additions & 1 deletion cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type fileScanner struct {
printer *utils.Printer
showInVT bool
waitForCompletion bool
password string
}

func (s *fileScanner) Do(path interface{}, ds *utils.DoerState) string {
Expand All @@ -100,7 +101,13 @@ func (s *fileScanner) Do(path interface{}, ds *utils.DoerState) string {
}
defer f.Close()

analysis, err := s.scanner.ScanFile(f, progressCh)
var analysis *vt.Object
if s.password != "" {
analysis, err = s.scanner.ScanFileWithParameters(
f, progressCh, map[string]string{"password": s.password})
} else {
analysis, err = s.scanner.ScanFile(f, progressCh)
}
if err != nil {
return err.Error()
}
Expand Down Expand Up @@ -173,6 +180,7 @@ func NewScanFileCmd() *cobra.Command {
scanner: client.NewFileScanner(),
showInVT: viper.GetBool("open"),
waitForCompletion: viper.GetBool("wait"),
password: viper.GetString("password"),
printer: p,
cli: client}
c.DoWithStringsFromReader(s, argReader)
Expand All @@ -182,6 +190,7 @@ func NewScanFileCmd() *cobra.Command {

addThreadsFlag(cmd.Flags())
addOpenInVTFlag(cmd.Flags())
addPasswordFlag(cmd.Flags())
addWaitForCompletionFlag(cmd.Flags())
addIncludeExcludeFlags(cmd.Flags())
cmd.MarkZshCompPositionalArgumentFile(1)
Expand Down Expand Up @@ -308,3 +317,9 @@ func addWaitForCompletionFlag(flags *pflag.FlagSet) {
"wait", "w", false,
"Wait until the analysis is completed and show the analysis results")
}

func addPasswordFlag(flags *pflag.FlagSet) {
flags.StringP(
"password", "p", "",
"Password of the protected file")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/VirusTotal/vt-cli
go 1.14

require (
github.com/VirusTotal/vt-go v0.0.0-20220413144842-e010bf48aaee
github.com/VirusTotal/vt-go v0.0.0-20230717142150-8431ff2cc00f
github.com/briandowns/spinner v1.7.0
github.com/cavaliercoder/grab v2.0.0+incompatible
github.com/dustin/go-humanize v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/VirusTotal/vt-go v0.0.0-20220413144842-e010bf48aaee h1:JDhi0dS8y9QLMJZA7ezLyXHxYaMlyzX6MDkq0SSc304=
github.com/VirusTotal/vt-go v0.0.0-20220413144842-e010bf48aaee/go.mod h1:u1+HeRyl/gQs67eDgVEWNE7+x+zCyXhdtNVrRJR5YPE=
github.com/VirusTotal/vt-go v0.0.0-20230717142150-8431ff2cc00f h1:49xl3zKS625gxmIRCfmwkXcTzB4cr4FcayRw/RcxhZs=
github.com/VirusTotal/vt-go v0.0.0-20230717142150-8431ff2cc00f/go.mod h1:u1+HeRyl/gQs67eDgVEWNE7+x+zCyXhdtNVrRJR5YPE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
Expand Down