Skip to content

Commit

Permalink
fix(contrib/fvuls): Add flag to specify snmp community for future-vul…
Browse files Browse the repository at this point in the history
…s discover (#1762)

* add: community option for discover command

* fix: README

---------

Co-authored-by: 和田皓翔 <[email protected]>
  • Loading branch information
wadda0714 and 和田皓翔 authored Oct 12, 2023
1 parent 1c79cc5 commit 738f275
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions contrib/future-vuls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ future-vuls discover --cidr 192.168.0.0/24 --output discover_list.toml
Flags:
--cidr string cidr range
--community string snmp community name. default: public
-h, --help help for discover
--output string output file
--snmp-version string snmp version v1,v2c and v3. default: v2c
Expand Down
9 changes: 7 additions & 2 deletions contrib/future-vuls/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
cidr string
snmpVersion string
proxy string
community string
)

func main() {
Expand Down Expand Up @@ -105,7 +106,10 @@ func main() {
if snmpVersion != "v1" && snmpVersion != "v2c" && snmpVersion != "v3" {
return fmt.Errorf("Invalid snmpVersion")
}
if err := discover.ActiveHosts(cidr, outputFile, snmpVersion); err != nil {
if community == "" {
community = config.Community
}
if err := discover.ActiveHosts(cidr, outputFile, snmpVersion, community); err != nil {
fmt.Printf("%v", err)
// avoid to display help message
os.Exit(1)
Expand Down Expand Up @@ -145,7 +149,8 @@ func main() {

cmdDiscover.PersistentFlags().StringVar(&cidr, "cidr", "", "cidr range")
cmdDiscover.PersistentFlags().StringVar(&outputFile, "output", "", "output file")
cmdDiscover.PersistentFlags().StringVar(&snmpVersion, "snmp-version", "", "snmp version v1,v2c and v3. default: v2c ")
cmdDiscover.PersistentFlags().StringVar(&snmpVersion, "snmp-version", "", "snmp version v1,v2c and v3. default: v2c")
cmdDiscover.PersistentFlags().StringVar(&community, "community", "", "snmp community name. default: public")

cmdAddCpe.PersistentFlags().StringVarP(&token, "token", "t", "", "future vuls token ENV: VULS_TOKEN")
cmdAddCpe.PersistentFlags().StringVar(&outputFile, "output", "", "output file")
Expand Down
1 change: 1 addition & 0 deletions contrib/future-vuls/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
DiscoverTomlFileName = "discover_list.toml"
SnmpVersion = "v2c"
FvulsDomain = "vuls.biz"
Community = "public"
DiscoverTomlTimeStampFormat = "20060102150405"
)

Expand Down
8 changes: 4 additions & 4 deletions contrib/future-vuls/pkg/discover/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// ActiveHosts ...
func ActiveHosts(cidr string, outputFile string, snmpVersion string) error {
func ActiveHosts(cidr string, outputFile string, snmpVersion string, community string) error {
scanner := pingscanner.PingScanner{
CIDR: cidr,
PingOptions: []string{
Expand All @@ -42,7 +42,7 @@ func ActiveHosts(cidr string, outputFile string, snmpVersion string) error {

servers := make(config.DiscoverToml)
for _, activeHost := range activeHosts {
cpes, err := executeSnmp2cpe(activeHost, snmpVersion)
cpes, err := executeSnmp2cpe(activeHost, snmpVersion, community)
if err != nil {
fmt.Printf("failed to execute snmp2cpe. err: %v\n", err)
continue
Expand Down Expand Up @@ -100,9 +100,9 @@ func ActiveHosts(cidr string, outputFile string, snmpVersion string) error {
return nil
}

func executeSnmp2cpe(addr string, snmpVersion string) (cpes map[string][]string, err error) {
func executeSnmp2cpe(addr string, snmpVersion string, community string) (cpes map[string][]string, err error) {
fmt.Printf("%s: Execute snmp2cpe...\n", addr)
result, err := exec.Command("./snmp2cpe", snmpVersion, addr, "public").CombinedOutput()
result, err := exec.Command("./snmp2cpe", snmpVersion, addr, community).CombinedOutput()
if err != nil {
return nil, fmt.Errorf("failed to execute snmp2cpe. err: %v", err)
}
Expand Down

0 comments on commit 738f275

Please sign in to comment.