feat(config): Auto-upgrade Windows config.toml from v1 to v2 (#1726)
* add: README.md * add: commands(discover,add-server,add-cpe) * add: implements(discover,add-server,add-cpe) * fix: changed os.Exit(1) in main.go to return an error * fix: lint error * delete: trivy-to-vuls stdIn * fix: Incomprehesible error logs * fix: according to review * add: function converts old config to latest one * delete: add-server * fix: lint error * fix * fix: remote scan error in Windows * fix: lint error * fix * fix: lint error * fix: lint error * add: scanner/scanner.go test normalizeHomeDirForWindows() * fix * fix * fix * fix: remove pointless assignment * fix --------- Co-authored-by: 和田皓翔 <wadahiroka@192.168.0.4> Co-authored-by: 和田皓翔 <wadahiroka@192.168.0.10> Co-authored-by: 和田皓翔 <wadahiroka@192.168.0.6>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
ex "os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -35,6 +36,8 @@ var (
|
||||
|
||||
var servers, errServers []osTypeInterface
|
||||
|
||||
var userDirectoryPath = ""
|
||||
|
||||
// Base Interface
|
||||
type osTypeInterface interface {
|
||||
setServerInfo(config.ServerInfo)
|
||||
@@ -565,6 +568,13 @@ func parseSSHConfiguration(stdout string) sshConfiguration {
|
||||
sshConfig.globalKnownHosts = strings.Split(strings.TrimPrefix(line, "globalknownhostsfile "), " ")
|
||||
case strings.HasPrefix(line, "userknownhostsfile "):
|
||||
sshConfig.userKnownHosts = strings.Split(strings.TrimPrefix(line, "userknownhostsfile "), " ")
|
||||
if runtime.GOOS == constant.Windows {
|
||||
for i, userKnownHost := range sshConfig.userKnownHosts {
|
||||
if strings.HasPrefix(userKnownHost, "~") {
|
||||
sshConfig.userKnownHosts[i] = normalizeHomeDirPathForWindows(userKnownHost)
|
||||
}
|
||||
}
|
||||
}
|
||||
case strings.HasPrefix(line, "proxycommand "):
|
||||
sshConfig.proxyCommand = strings.TrimPrefix(line, "proxycommand ")
|
||||
case strings.HasPrefix(line, "proxyjump "):
|
||||
@@ -574,6 +584,11 @@ func parseSSHConfiguration(stdout string) sshConfiguration {
|
||||
return sshConfig
|
||||
}
|
||||
|
||||
func normalizeHomeDirPathForWindows(userKnownHost string) string {
|
||||
userKnownHostPath := filepath.Join(os.Getenv("userprofile"), strings.TrimPrefix(userKnownHost, "~"))
|
||||
return strings.ReplaceAll(userKnownHostPath, "/", "\\")
|
||||
}
|
||||
|
||||
func parseSSHScan(stdout string) map[string]string {
|
||||
keys := map[string]string{}
|
||||
for _, line := range strings.Split(stdout, "\n") {
|
||||
|
||||
Reference in New Issue
Block a user