add scannedVia field to know the way of access such as SSH, local or pseudo (#811)
* add sacnned via * change scannedVia type to const
This commit is contained in:
committed by
Kota Kanbe
parent
824fbb6368
commit
53aaea9fe2
@@ -390,6 +390,13 @@ func (l *base) convertToModel() models.ScanResult {
|
||||
errs = append(errs, fmt.Sprintf("%s", e))
|
||||
}
|
||||
|
||||
scannedVia := scannedViaRemote
|
||||
if isLocalExec(l.ServerInfo.Port, l.ServerInfo.Host) {
|
||||
scannedVia = scannedViaLocal
|
||||
} else if l.ServerInfo.Type == config.ServerTypePseudo {
|
||||
scannedVia = scannedViaPseudo
|
||||
}
|
||||
|
||||
return models.ScanResult{
|
||||
JSONVersion: models.JSONVersion,
|
||||
ServerName: l.ServerInfo.ServerName,
|
||||
@@ -402,6 +409,7 @@ func (l *base) convertToModel() models.ScanResult {
|
||||
IPv4Addrs: l.ServerInfo.IPv4Addrs,
|
||||
IPv6Addrs: l.ServerInfo.IPv6Addrs,
|
||||
ScannedCves: l.VulnInfos,
|
||||
ScannedVia: scannedVia,
|
||||
RunningKernel: l.Kernel,
|
||||
Packages: l.Packages,
|
||||
SrcPackages: l.SrcPackages,
|
||||
|
||||
@@ -162,8 +162,7 @@ func exec(c conf.ServerInfo, cmd string, sudo bool, log ...*logrus.Entry) (resul
|
||||
logger := getSSHLogger(log...)
|
||||
logger.Debugf("Executing... %s", strings.Replace(cmd, "\n", "", -1))
|
||||
|
||||
if c.Port == "local" &&
|
||||
(c.Host == "127.0.0.1" || c.Host == "localhost") {
|
||||
if isLocalExec(c.Port, c.Host) {
|
||||
result = localExec(c, cmd, sudo)
|
||||
} else if conf.Conf.SSHNative {
|
||||
result = sshExecNative(c, cmd, sudo)
|
||||
@@ -175,6 +174,10 @@ func exec(c conf.ServerInfo, cmd string, sudo bool, log ...*logrus.Entry) (resul
|
||||
return
|
||||
}
|
||||
|
||||
func isLocalExec(port, host string) bool {
|
||||
return port == "local" && (host == "127.0.0.1" || host == "localhost")
|
||||
}
|
||||
|
||||
func localExec(c conf.ServerInfo, cmdstr string, sudo bool) (result execResult) {
|
||||
cmdstr = decorateCmd(c, cmdstr, sudo)
|
||||
var cmd *ex.Cmd
|
||||
|
||||
@@ -32,6 +32,12 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
const (
|
||||
scannedViaRemote = "remote"
|
||||
scannedViaLocal = "local"
|
||||
scannedViaPseudo = "pseudo"
|
||||
)
|
||||
|
||||
var (
|
||||
errOSFamilyHeader = xerrors.New("X-Vuls-OS-Family header is required")
|
||||
errOSReleaseHeader = xerrors.New("X-Vuls-OS-Release header is required")
|
||||
|
||||
Reference in New Issue
Block a user