Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): Auto-upgrade Windows config.toml from v1 to v2 #1726

Merged
merged 24 commits into from
Sep 21, 2023
Merged

feat(config): Auto-upgrade Windows config.toml from v1 to v2 #1726

merged 24 commits into from
Sep 21, 2023

Conversation

wadda0714
Copy link
Contributor

@wadda0714 wadda0714 commented Aug 30, 2023

What did you implement:

  • If an older version of config.toml is detected when scanning with the Windows version of the scanner, The config.toml will automatically be upgraded to the latest version. The old config.toml is version 1 (v1), while the latest one is version 2 (v2).

  • Fixed a bug that caused an error when performing a remote scan from Windows.

$ vuls.exe scan
time="Sep 11 10:30:48" level=info msg="vuls--build-20230907_155834_49d8b95"
time="Sep 11 10:30:48" level=info msg="Start scanning"
time="Sep 11 10:30:48" level=info msg="config: C:\\Program Files\\vuls-saas\\config.toml"
time="Sep 11 10:30:48" level=info msg="Validating config..."
time="Sep 11 10:30:48" level=info msg="Detecting Server/Container OS... "
time="Sep 11 10:30:48" level=info msg="Detecting OS of servers... "
time="Sep 11 10:30:48" level=info msg="(1/2) Detected: localhost: windows Windows 10 Version 22H2 for x64-based Systems"
time="Sep 11 10:30:54" level=error msg="(2/2) Failed: ec2, err: [Failed to find the host in known_hosts. Please exec `$ ssh.exe -i C:\\\\Users\\ome-202304wada\\.ssh\\vuls-stg.pem -p 22 -l ec2-user x.x.x.x` or `$ ssh-keyscan.exe -p 22 x.x.x.x >> %userprofile%/.ssh/known_hosts`:\n    github.com/future-architect/vuls/scanner.validateSSHConfig\n        /Users/xxxxxx/go/vuls/scanner/scanner.go:477]"

The error points out that the known_host file is missing the host information to connect to.
Looking at the code,there was a section that executed such a command.

ssh.exe -G -i {authorized_key} -p 22 -l {username} {ipaddr}"

This command outputs the configuration information of the specified SSH connection destination to stdout, including information on the path of the known_host file.

userknownhostsfile ~/.ssh/known_hosts ~/.ssh/known_hosts2

When parsing this output, the current version did not remove the~ in the path.
~ refers to the user's home directory on Unix-like systems.
Since ~ is not available on Windows, this may be the cause of the missing known_hosts file.
So, I changed the scanner to remove the ~ from the known_host file path only when it is run on Windows, and instead use the environment variable userprofile, which points to the user's home directory in Windows.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

config.toml(old version)

[Servers]

  [Servers.localhost]
    Host = "localhost"
    UUID = "c08438be-cd4e-f1b3-471a-1444c3a11574"
    WinUpdateSrc = "2"
    CabPath = ""

[Proxy]
  ProxyURL = ""
  BypassList = ""**

saas-credential.json(old version)

{
 "GroupID": 2603,
 "Token": "",
}
$ vuls.exe configtest
time="Aug 25 17:36:26" level=info msg="vuls-`make build` or `make install` will show the version-"
time="Aug 25 17:36:26" level=info msg="An outdated version of config.toml was detected. Converting to newer version..."
time="Aug 25 17:36:26" level=info msg="Validating config..."
time="Aug 25 17:36:26" level=info msg="Detecting Server/Container OS... "
time="Aug 25 17:36:26" level=info msg="Detecting OS of servers... "
time="Aug 25 17:36:26" level=info msg="(1/1) Detected: localhost: windows Windows 10 Version 22H2 for x64-based Systems"
time="Aug 25 17:36:26" level=info msg="Detecting OS of containers... "
time="Aug 25 17:36:26" level=info msg="Checking Scan Modes..."
time="Aug 25 17:36:26" level=info msg="Checking dependencies..."
time="Aug 25 17:36:26" level=info msg="Checking sudo settings..."
time="Aug 25 17:36:26" level=info msg="It can be scanned with fast scan mode even if warn or err messages are displayed due to lack of dependent packages or sudo settings in fast-root or deep scan mode"
time="Aug 25 17:36:26" level=info msg="Scannable servers are below..."
localhost

config.toml(converted)

version = "v2"

[saas]
  GroupID = 2603
  Token = ""
  URL = "https://auth.2119e7c929.vuls.biz/one-time-auth"

[default]

[servers]
  [servers.localhost]
    host = "localhost"
    port = "local"
    [servers.localhost.uuids]
      localhost = "c08438be-cd4e-f1b3-471a-1444c3a11574"
    [servers.localhost.windows]
      serverSelection = 2

Remote Scan

# See README for details: https://vuls.io/docs/en/usage-settings.html

version = "v2"

[saas]
  GroupID = xxx
  Token = "xxxx"
  URL = "https://auth.vuls.biz/one-time-auth"

[default]

[servers]
  [servers.localhost]
    host = "localhost"
    port = "local"
    [servers.localhost.uuids]
      localhost = "xxxx"
    [servers.localhost.windows]
      serverSelection = 2

  [servers.ec2]
    user = "ec2-user"
    host = "x.x.x.x"
    port = "22"
    keyPath = "xxxx"
    [servers.ec2.uuids]
      ec2 = "xxxx"
    [servers.ec2.windows]
      serverSelection = 0
$ vuls.exe scan 
time="Sep 11 10:33:19" level=info msg="vuls--build-20230908_140759_247ace3" 
time="Sep 11 10:33:19" level=info msg="Start scanning" 
time="Sep 11 10:33:19" level=info msg="config: C:\\Program Files\\vuls-saas\\config.toml" 
time="Sep 11 10:33:19" level=info msg="Validating config..." 
time="Sep 11 10:33:19" level=info msg="Detecting Server/Container OS... " 
time="Sep 11 10:33:19" level=info msg="Detecting OS of servers... " 
time="Sep 11 10:33:19" level=info msg="(1/2) Detected: localhost: windows Windows 10 Version 22H2 for x64-based Systems" 
time="Sep 11 10:33:34" level=warning msg="First SSH Connection to Host: x.x.x.x:22 timeout" 
time="Sep 11 10:35:49" level=info msg="(2/2) Detected: ec2: amazon 1" 
time="Sep 11 10:35:49" level=info msg="Detecting OS of containers... " 
time="Sep 11 10:35:49" level=info msg="Checking Scan Modes... " 
time="Sep 11 10:35:49" level=info msg="Detecting Platforms... " 
time="Sep 11 10:36:10" level=info msg="(1/2) localhost is running on other" 
time="Sep 11 10:36:10" level=info msg="(2/2) ec2 is running on aws" 
time="Sep 11 10:36:14" level=info msg="Scanning listen port..." 
time="Sep 11 10:36:14" level=info msg="Using Port Scanner: Vuls built-in Scanner" 
time="Sep 11 10:36:21" level=info msg="Scanning OS pkg in fast mode" 
time="Sep 11 10:37:25" level=info msg="Scanning listen port..." 
time="Sep 11 10:37:25" level=info msg="Using Port Scanner: Vuls built-in Scanner" 
time="Sep 11 10:37:25" level=warning msg="Some warnings occurred during scanning on ec2. Please fix the warnings to get a useful information. Execute configtest subcommand before scanning to know the cause of the warnings. warnings: [Standard OS support is EOL(End-of-Life). Purchase extended support if available or Upgrading your OS is strongly recommended.]" 


Scan Summary
================
localhost	windowsWindows 10 Version 22H2 for x64-based Systems	42 installed, 0 updatable   
ec2      	amazon1                                             	447 installed, 141 updatable

Warning: [Standard OS support is EOL(End-of-Life). Purchase extended support if available or Upgrading your OS is strongly recommended.]



To view the detail, vuls tui is useful.
To send a report, run vuls report -h.

Checklist:

You don't have to satisfy all of the following.

  • Write tests
  • Write documentation
  • Check that there aren't other open pull requests for the same issue/feature
  • Format your source code by make fmt
  • Pass the test by make test
  • Provide verification config / commands
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES

Reference

@wadda0714 wadda0714 changed the title [WIP] feat(config): Added the function to convert old configurations to new configurations in Windows [WIP] feat(config): Add the function to convert old configurations to new configurations in Windows Aug 30, 2023
@wadda0714 wadda0714 changed the title [WIP] feat(config): Add the function to convert old configurations to new configurations in Windows feat(config): Add the function to convert old configurations to new configurations in Windows Sep 13, 2023
@kotakanbe kotakanbe changed the title feat(config): Add the function to convert old configurations to new configurations in Windows feat(config): Auto-upgrade Windows config.toml from v1 to v2 Sep 13, 2023
@kotakanbe kotakanbe self-requested a review September 21, 2023 07:40
@kotakanbe kotakanbe merged commit f6509a5 into future-architect:master Sep 21, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants