add scanner info in -to-saas (#783)
This commit is contained in:
committed by
Kota Kanbe
parent
53f4a29fb1
commit
e0e71b2eae
@@ -24,7 +24,9 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
@@ -48,8 +50,11 @@ type TempCredential struct {
|
||||
}
|
||||
|
||||
type payload struct {
|
||||
GroupID int `json:"GroupID"`
|
||||
Token string `json:"Token"`
|
||||
GroupID int `json:"GroupID"`
|
||||
Token string `json:"Token"`
|
||||
ScannedBy string `json:"ScannedBy"`
|
||||
ScannedIPv4s string `json:"ScannedIPv4s"`
|
||||
ScannedIPv6s string `json:"ScannedIPv6s"`
|
||||
}
|
||||
|
||||
// UploadSaas : UploadSaas
|
||||
@@ -59,9 +64,18 @@ func (w SaasWriter) Write(rs ...models.ScanResult) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
ipv4s, ipv6s, err := util.IP()
|
||||
if err != nil {
|
||||
util.Log.Errorf("Failed to fetch scannedIPs: %s", err)
|
||||
}
|
||||
hostname, _ := os.Hostname()
|
||||
|
||||
payload := payload{
|
||||
GroupID: c.Conf.Saas.GroupID,
|
||||
Token: c.Conf.Saas.Token,
|
||||
GroupID: c.Conf.Saas.GroupID,
|
||||
Token: c.Conf.Saas.Token,
|
||||
ScannedBy: hostname,
|
||||
ScannedIPv4s: strings.Join(ipv4s, ", "),
|
||||
ScannedIPv6s: strings.Join(ipv6s, ", "),
|
||||
}
|
||||
|
||||
var body []byte
|
||||
|
||||
@@ -20,7 +20,6 @@ package scan
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -596,7 +595,7 @@ func scanVulns(jsonDir string, scannedAt time.Time, timeoutSec int) error {
|
||||
}, timeoutSec)
|
||||
|
||||
hostname, _ := os.Hostname()
|
||||
ipv4s, ipv6s, err := ip()
|
||||
ipv4s, ipv6s, err := util.IP()
|
||||
if err != nil {
|
||||
util.Log.Errorf("Failed to fetch scannedIPs: %s", err)
|
||||
}
|
||||
@@ -627,38 +626,6 @@ func scanVulns(jsonDir string, scannedAt time.Time, timeoutSec int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ip returns scanner network ip addresses
|
||||
func ip() (ipv4Addrs []string, ipv6Addrs []string, err error) {
|
||||
ifaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
for _, i := range ifaces {
|
||||
addrs, _ := i.Addrs()
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
ip = v.IP
|
||||
case *net.IPAddr:
|
||||
ip = v.IP
|
||||
}
|
||||
|
||||
// only global unicast address
|
||||
if !ip.IsGlobalUnicast() {
|
||||
continue
|
||||
}
|
||||
|
||||
if ok := ip.To4(); ok != nil {
|
||||
ipv4Addrs = append(ipv4Addrs, ip.String())
|
||||
} else {
|
||||
ipv6Addrs = append(ipv6Addrs, ip.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
return ipv4Addrs, ipv6Addrs, nil
|
||||
}
|
||||
|
||||
// EnsureResultDir ensures the directory for scan results
|
||||
func EnsureResultDir(scannedAt time.Time) (currentDir string, err error) {
|
||||
jsonDirName := scannedAt.Format(time.RFC3339)
|
||||
|
||||
33
util/util.go
33
util/util.go
@@ -19,6 +19,7 @@ package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
@@ -93,6 +94,38 @@ func URLPathParamJoin(baseURL string, paths []string, params map[string]string)
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
// IP returns scanner network ip addresses
|
||||
func IP() (ipv4Addrs []string, ipv6Addrs []string, err error) {
|
||||
ifaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
for _, i := range ifaces {
|
||||
addrs, _ := i.Addrs()
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
ip = v.IP
|
||||
case *net.IPAddr:
|
||||
ip = v.IP
|
||||
}
|
||||
|
||||
// only global unicast address
|
||||
if !ip.IsGlobalUnicast() {
|
||||
continue
|
||||
}
|
||||
|
||||
if ok := ip.To4(); ok != nil {
|
||||
ipv4Addrs = append(ipv4Addrs, ip.String())
|
||||
} else {
|
||||
ipv6Addrs = append(ipv6Addrs, ip.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
return ipv4Addrs, ipv6Addrs, nil
|
||||
}
|
||||
|
||||
// ProxyEnv returns shell environment variables to set proxy
|
||||
func ProxyEnv() string {
|
||||
httpProxyEnv := ""
|
||||
|
||||
Reference in New Issue
Block a user