Skip to content

fix(scanner/windows): support when default shell is powershell #1844

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

Merged
merged 1 commit into from
Feb 2, 2024

Conversation

MaineK00n
Copy link
Collaborator

@MaineK00n MaineK00n commented Feb 2, 2024

What did you implement:

Fixes #1835

The issue of failing to identify the OS when the default shell when connecting via SSH is powershell.exe will be fixed by identifying the shell that executes the command and reviewing the escaping of each command.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

remote (default shell: cmd.exe)

before

$ vuls scan
[Feb  2 12:10:40]  INFO [localhost] vuls-0.24.8-bbf53c7639b266e3a658e8f0a8b2ff7bf17e8e62-2023-12-17T20:41:46Z
[Feb  2 12:10:40]  INFO [localhost] Start scanning
[Feb  2 12:10:40]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Feb  2 12:10:40]  INFO [localhost] Validating config...
[Feb  2 12:10:40]  INFO [localhost] Detecting Server/Container OS... 
[Feb  2 12:10:40]  INFO [localhost] Detecting OS of servers... 
[Feb  2 12:10:44]  INFO [localhost] (1/1) Detected: vagrant: windows Windows Server 2022
[Feb  2 12:10:44]  INFO [localhost] Detecting OS of containers... 
[Feb  2 12:10:44]  INFO [localhost] Checking Scan Modes... 
[Feb  2 12:10:44]  INFO [localhost] Detecting Platforms... 
[Feb  2 12:10:55]  INFO [localhost] (1/1) vagrant is running on other


Scan Summary
================
vagrant	windowsWindows Server 2022	5 installed, 0 updatable





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

after

$ vuls scan
[Feb  2 12:08:19]  INFO [localhost] vuls-v0.24.8-build-20240202_114014_a865324
[Feb  2 12:08:19]  INFO [localhost] Start scanning
[Feb  2 12:08:19]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Feb  2 12:08:19]  INFO [localhost] Validating config...
[Feb  2 12:08:19]  INFO [localhost] Detecting Server/Container OS... 
[Feb  2 12:08:19]  INFO [localhost] Detecting OS of servers... 
[Feb  2 12:08:22]  INFO [localhost] (1/1) Detected: vagrant: windows Windows Server 2022
[Feb  2 12:08:22]  INFO [localhost] Detecting OS of containers... 
[Feb  2 12:08:22]  INFO [localhost] Checking Scan Modes... 
[Feb  2 12:08:22]  INFO [localhost] Detecting Platforms... 
[Feb  2 12:08:24]  INFO [localhost] (1/1) vagrant is running on other


Scan Summary
================
vagrant	windowsWindows Server 2022	5 installed, 0 updatable





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

remote (default shell: powershell)

before

$ vuls scan
[Feb  2 12:11:41]  INFO [localhost] vuls-0.24.8-bbf53c7639b266e3a658e8f0a8b2ff7bf17e8e62-2023-12-17T20:41:46Z
[Feb  2 12:11:41]  INFO [localhost] Start scanning
[Feb  2 12:11:41]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Feb  2 12:11:41]  INFO [localhost] Validating config...
[Feb  2 12:11:41]  INFO [localhost] Detecting Server/Container OS... 
[Feb  2 12:11:41]  INFO [localhost] Detecting OS of servers... 
[Feb  2 12:12:32] ERROR [localhost] (1/1) Failed: vagrant, err: [Unknown OS Type:
    github.com/future-architect/vuls/scanner.Scanner.detectOS
        /home/runner/work/vuls/vuls/scanner/scanner.go:800]
[Feb  2 12:12:32] ERROR [localhost] Failed to scan: Failed to init servers. err:
    github.com/future-architect/vuls/scanner.Scanner.Scan
        /home/runner/work/vuls/vuls/scanner/scanner.go:93
  - No scannable host OS:
    github.com/future-architect/vuls/scanner.Scanner.initServers
        /home/runner/work/vuls/vuls/scanner/scanner.go:300

after

$ vuls scan
[Feb  2 12:13:11]  INFO [localhost] vuls-v0.24.8-build-20240202_114014_a865324
[Feb  2 12:13:11]  INFO [localhost] Start scanning
[Feb  2 12:13:11]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Feb  2 12:13:11]  INFO [localhost] Validating config...
[Feb  2 12:13:11]  INFO [localhost] Detecting Server/Container OS... 
[Feb  2 12:13:11]  INFO [localhost] Detecting OS of servers... 
[Feb  2 12:13:17]  INFO [localhost] (1/1) Detected: vagrant: windows Windows Server 2022
[Feb  2 12:13:17]  INFO [localhost] Detecting OS of containers... 
[Feb  2 12:13:17]  INFO [localhost] Checking Scan Modes... 
[Feb  2 12:13:17]  INFO [localhost] Detecting Platforms... 
[Feb  2 12:13:34]  INFO [localhost] (1/1) vagrant is running on other


Scan Summary
================
vagrant	windowsWindows Server 2022	5 installed, 0 updatable





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

local(default shell: cmd.exe)

before

vagrant@WIN-HL763J091HK C:\Users\vagrant>vuls.exe scan
time="Feb  2 03:03:13" level=info msg="vuls-0.24.8-bbf53c7639b266e3a658e8f0a8b2ff7bf17e8e62-2023-12-17T20:41:46Z" 
time="Feb  2 03:03:13" level=info msg="Start scanning" 
time="Feb  2 03:03:13" level=info msg="config: C:\\Users\\vagrant\\config.toml" 
time="Feb  2 03:03:13" level=info msg="Validating config..." 
time="Feb  2 03:03:13" level=info msg="Detecting Server/Container OS... " 
time="Feb  2 03:03:13" level=info msg="Detecting OS of servers... " 
time="Feb  2 03:03:17" level=info msg="(1/1) Detected: localhost: windows Windows Server 2022" 
time="Feb  2 03:03:17" level=info msg="Detecting OS of containers... " 
time="Feb  2 03:03:17" level=info msg="Checking Scan Modes... " 
time="Feb  2 03:03:17" level=info msg="Detecting Platforms... " 
time="Feb  2 03:03:27" level=info msg="(1/1) localhost is running on other" 


Scan Summary
================
localhost       windowsWindows Server 2022      5 installed, 0 updatable





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

after

vagrant@WIN-HL763J091HK C:\Users\vagrant>vuls.exe scan
time="Feb  2 02:59:33" level=info msg="vuls-v0.24.8-build-20240202_114712_a865324" 
time="Feb  2 02:59:33" level=info msg="Start scanning" 
time="Feb  2 02:59:33" level=info msg="config: C:\\Users\\vagrant\\config.toml" 
time="Feb  2 02:59:33" level=info msg="Validating config..." 
time="Feb  2 02:59:33" level=info msg="Detecting Server/Container OS... " 
time="Feb  2 02:59:33" level=info msg="Detecting OS of servers... " 
time="Feb  2 02:59:42" level=info msg="(1/1) Detected: localhost: windows Windows Server 2022" 
time="Feb  2 02:59:42" level=info msg="Detecting OS of containers... " 
time="Feb  2 02:59:42" level=info msg="Checking Scan Modes... " 
time="Feb  2 02:59:42" level=info msg="Detecting Platforms... " 
time="Feb  2 02:59:59" level=info msg="(1/1) localhost is running on other" 


Scan Summary
================
localhost       windowsWindows Server 2022      5 installed, 0 updatable





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

local (default shell: powershell)

before

PS C:\Users\vagrant> .\vuls.exe scan
time="Feb  2 03:06:34" level=info msg="vuls-0.24.8-bbf53c7639b266e3a658e8f0a8b2ff7bf17e8e62-2023-12-17T20:41:46Z" 
time="Feb  2 03:06:34" level=info msg="Start scanning" 
time="Feb  2 03:06:34" level=info msg="config: C:\\Users\\vagrant\\config.toml"
time="Feb  2 03:06:34" level=info msg="Validating config..."
time="Feb  2 03:06:34" level=info msg="Detecting Server/Container OS... "
time="Feb  2 03:06:34" level=info msg="Detecting OS of servers... "
time="Feb  2 03:06:38" level=info msg="(1/1) Detected: localhost: windows Windows Server 2022" 
time="Feb  2 03:06:38" level=info msg="Detecting OS of containers... " 
time="Feb  2 03:06:38" level=info msg="Checking Scan Modes... "
time="Feb  2 03:06:38" level=info msg="Detecting Platforms... "
time="Feb  2 03:06:50" level=info msg="(1/1) localhost is running on other" 


Scan Summary
================
localhost       windowsWindows Server 2022      5 installed, 0 updatable





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

after

PS C:\Users\vagrant> .\vuls.exe scan
time="Feb  2 03:04:54" level=info msg="vuls-v0.24.8-build-20240202_114712_a865324" 
time="Feb  2 03:04:54" level=info msg="Start scanning" 
time="Feb  2 03:04:54" level=info msg="config: C:\\Users\\vagrant\\config.toml"
time="Feb  2 03:04:54" level=info msg="Validating config..."
time="Feb  2 03:04:54" level=info msg="Detecting Server/Container OS... "
time="Feb  2 03:04:54" level=info msg="Detecting OS of servers... "
time="Feb  2 03:04:58" level=info msg="(1/1) Detected: localhost: windows Windows Server 2022" 
time="Feb  2 03:04:58" level=info msg="Detecting OS of containers... " 
time="Feb  2 03:04:58" level=info msg="Checking Scan Modes... "
time="Feb  2 03:04:58" level=info msg="Detecting Platforms... "
time="Feb  2 03:05:11" level=info msg="(1/1) localhost is running on other" 


Scan Summary
================
localhost       windowsWindows Server 2022      5 installed, 0 updatable





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

@MaineK00n MaineK00n self-assigned this Feb 2, 2024
@MaineK00n MaineK00n force-pushed the MaineK00n/fix-remote-windows branch 3 times, most recently from d7b094c to b55786f Compare February 2, 2024 03:59
@MaineK00n MaineK00n marked this pull request as ready for review February 2, 2024 04:00
@MaineK00n MaineK00n force-pushed the MaineK00n/fix-remote-windows branch 2 times, most recently from 6893560 to 9a68d29 Compare February 2, 2024 06:03
@MaineK00n MaineK00n force-pushed the MaineK00n/fix-remote-windows branch from 9a68d29 to b08223c Compare February 2, 2024 06:31
@MaineK00n MaineK00n requested a review from shino February 2, 2024 06:42
Copy link
Collaborator

@shino shino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎊

@MaineK00n MaineK00n merged commit b9ebcf3 into master Feb 2, 2024
@MaineK00n MaineK00n deleted the MaineK00n/fix-remote-windows branch February 2, 2024 06:42
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.

Remote scan from Linux to Windows fails
2 participants