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(configtest,scan): detect known_hosts error #1386

Merged
merged 1 commit into from
Feb 11, 2022

Conversation

MaineK00n
Copy link
Collaborator

What did you implement:

vuls uses SSH connection when scanning.
The SSH connection of vuls scan is basically set to StrictHostKeyChecking=yes, so the host's public key must be registered in known_hosts.
However, the error message does not classify whether the error is caused by the host's public key not being registered in known_hosts or not.
This PR classifies the errors that occur when the host's public key is not registered in known_hosts for the user.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

master

$ vuls scan
[Feb 10 23:13:10]  INFO [localhost] vuls-v0.19.2-build-20220128_200342_b4c23c1
[Feb 10 23:13:10]  INFO [localhost] Start scanning
[Feb 10 23:13:10]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Feb 10 23:13:10]  INFO [localhost] Validating config...
[Feb 10 23:13:10]  INFO [localhost] Detecting Server/Container OS... 
[Feb 10 23:13:10]  INFO [localhost] Detecting OS of servers... 
[Feb 10 23:13:11] ERROR [localhost] (1/1) Failed: vuls-target, err: [Failed to detect OS:
    github.com/future-architect/vuls/scanner.Scanner.detectOS
        /home/mainek00n/go/src/github.com/future-architect/vuls/scanner/serverapi.go:452
  - Unable to connect via SSH. Scan with -vvv option to print SSH debugging messages and check SSH settings. If you have never SSH to the host to be scanned, SSH to the host before scanning in order to add the HostKey. root@127.0.0.1 port: 2222
    execResult: servername: vuls-target
      cmd: /usr/bin/ssh -tt -o StrictHostKeyChecking=yes -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=auto -o ControlPath=/home/mainek00n/.vuls/controlmaster-%r-vuls-target.%p -o Controlpersist=10m root@127.0.0.1 -p 2222 -i /home/mainek00n/github/github.com/MaineK00n/vuls-targets-docker/.ssh/id_rsa -o PasswordAuthentication=no stty cols 1000; ls /etc/debian_version
      exitstatus: 255
      stdout: 
      stderr: 
      err: %!s(<nil>):
    github.com/future-architect/vuls/scanner.detectDebian
        /home/mainek00n/go/src/github.com/future-architect/vuls/scanner/debian.go:52]
[Feb 10 23:13:11] ERROR [localhost] Failed to scan: Failed to init servers. err:
    github.com/future-architect/vuls/scanner.Scanner.Scan
        /home/mainek00n/go/src/github.com/future-architect/vuls/scanner/serverapi.go:86
  - No scannable host OS:
    github.com/future-architect/vuls/scanner.Scanner.initServers
        /home/mainek00n/go/src/github.com/future-architect/vuls/scanner/serverapi.go:239

MaineK00n/detect-known_hosts-err

$ vuls scan
[Feb 10 23:15:10]  INFO [localhost] vuls-v0.19.3-build-20220210_231344_fef4291
[Feb 10 23:15:10]  INFO [localhost] Start scanning
[Feb 10 23:15:10]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Feb 10 23:15:10]  INFO [localhost] Validating config...
[Feb 10 23:15:10]  INFO [localhost] Detecting Server/Container OS... 
[Feb 10 23:15:10]  INFO [localhost] Detecting OS of servers... 
[Feb 10 23:15:10] ERROR [localhost] (1/1) Failed: vuls-target, err: [Failed to find the host in known_hosts. Plaese exec `$ ssh -i /home/mainek00n/github/github.com/MaineK00n/vuls-targets-docker/.ssh/id_rsa -p 2222 root@127.0.0.1` or `$ ssh-keyscan -H -p 2222 127.0.0.1 >> ~/.ssh/known_hosts`:
    github.com/future-architect/vuls/scanner.checkHostinKnownHosts
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/serverapi.go:381]
[Feb 10 23:15:10] ERROR [localhost] Failed to scan: Failed to init servers. err:
    github.com/future-architect/vuls/scanner.Scanner.Scan
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/serverapi.go:87
  - No scannable host OS:
    github.com/future-architect/vuls/scanner.Scanner.initServers
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/serverapi.go:242

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 10, 2022
@MaineK00n MaineK00n force-pushed the MaineK00n/detect-known_hosts-err branch from fef4291 to 3d808b0 Compare February 10, 2022 14:27
@MaineK00n MaineK00n force-pushed the MaineK00n/detect-known_hosts-err branch from 3d808b0 to bcd9986 Compare February 10, 2022 14:32
@kotakanbe kotakanbe self-requested a review February 11, 2022 03:54
Copy link
Member

@kotakanbe kotakanbe left a comment

Choose a reason for hiding this comment

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

Cool!!!

@kotakanbe kotakanbe merged commit 671be3f into master Feb 11, 2022
@kotakanbe kotakanbe deleted the MaineK00n/detect-known_hosts-err branch February 11, 2022 03:54
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.

2 participants