Skip to content

Commit

Permalink
feat(Scan): Password-protected files (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
joseotoro authored Jul 20, 2023
1 parent 9f09802 commit bfea504
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
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

This comment has been minimized.

Copy link
@Kyawgyi388013

This comment has been minimized.

Copy link
@Kyawgyi388013

Kyawgyi388013 Oct 25, 2023

password

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

0 comments on commit bfea504

Please sign in to comment.