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): support CIDR range #1415

Merged
merged 1 commit into from
Jun 10, 2022
Merged

feat(config): support CIDR range #1415

merged 1 commit into from
Jun 10, 2022

Conversation

MaineK00n
Copy link
Collaborator

@MaineK00n MaineK00n commented Mar 11, 2022

What did you implement:

The host section of config.toml can be written in CIDR Range.
This allows a single server section to represent a single network, and when users and keys are common, server sections that were written separately can be combined into one.

Type of change

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

How Has This Been Tested?

Setup

$ vagrant up
$ ssh vagrant@192.168.56.10 -i ../../.ssh/id_rsa
$ ssh vagrant@192.168.56.11 -i ../../.ssh/id_rsa

../../.ssh/id_rsa.pub should be changed according to your environment.

  • Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.define "host1" do |host1|
    host1.vm.box = "ubuntu/focal64"
    host1.vm.network :private_network, ip: "192.168.56.10"
  end

  config.vm.define "host2" do |host2|
    host2.vm.box = "ubuntu/focal64"
    host2.vm.network :private_network, ip: "192.168.56.11"
  end

  if Vagrant.has_plugin?("vagrant-vbguest")
    config.vbguest.auto_update = false  
  end

  config.vm.provision "shell", privileged: false do |s|
    ssh_pub_key = ""
    if File.file?("../../.ssh/id_rsa.pub")
      ssh_pub_key = File.readlines("../../.ssh/id_rsa.pub").first.strip
    else
      puts "No SSH key found. You will need to remedy this before pushing to the repository."
    end
    s.inline = <<-SHELL
      if grep -sq "#{ssh_pub_key}" /home/vagrant/.ssh/authorized_keys; then
        echo "SSH keys already provisioned."
        exit 0;
      fi
      echo "SSH key provisioning."
      mkdir -p /home/vagrant/.ssh/
      touch /home/vagrant/.ssh/authorized_keys
      echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
    SHELL
  end

  config.vm.provision "shell", inline: <<-SHELL
     apt install -y lsof iproute2
     DEBIAN_FRONTEND=noninteractive apt install -y debian-goodies
  SHELL
end

standard

$ go run cmd/vuls/main.go scan -config=./config.toml vuls-target
[Mar 14 15:42:52]  INFO [localhost] vuls-`make build` or `make install` will show the version-
[Mar 14 15:42:52]  INFO [localhost] Start scanning
[Mar 14 15:42:52]  INFO [localhost] config: ./config.toml
[Mar 14 15:42:52]  INFO [localhost] Validating config...
[Mar 14 15:42:52]  INFO [localhost] Detecting Server/Container OS... 
[Mar 14 15:42:52]  INFO [localhost] Detecting OS of servers... 
[Mar 14 15:42:52]  INFO [localhost] (1/2) Detected: vuls-target(192.168.56.10): ubuntu 20.04
[Mar 14 15:42:52]  INFO [localhost] (2/2) Detected: vuls-target(192.168.56.11): ubuntu 20.04
[Mar 14 15:42:52]  INFO [localhost] Detecting OS of containers... 
[Mar 14 15:42:52]  INFO [localhost] Checking Scan Modes... 
[Mar 14 15:42:52]  INFO [localhost] Detecting Platforms... 
[Mar 14 15:42:53]  INFO [localhost] (1/2) vuls-target(192.168.56.11) is running on other
[Mar 14 15:42:53]  INFO [localhost] (2/2) vuls-target(192.168.56.10) is running on other
[Mar 14 15:42:53]  INFO [vuls-target(192.168.56.10)] Scanning OS pkg in fast mode
[Mar 14 15:42:53]  INFO [vuls-target(192.168.56.11)] Scanning OS pkg in fast mode


Scan Summary
================
vuls-target(192.168.56.11)	ubuntu20.04	594 installed
vuls-target(192.168.56.10)	ubuntu20.04	594 installed





To view the detail, vuls tui is useful.
To send a report, run vuls report -h.
  • config.toml
[servers]
[servers.vuls-target]
host                = "192.168.56.10/31"
user               = "vagrant"
keyPath            = "/home/mainek00n/github/github.com/MaineK00n/vuls-targets-docker/.ssh/id_rsa"
scanMode           = ["fast"]
scanModules        = ["ospkg"]

To exclude some IP addresses

Just write ignoreIPAddresses in config.toml. (CIDR notation is also possible.)

  • config.toml
[servers]
[servers.vuls-target]
host                = "192.168.56.10/31"
ignoreIPAddresses = ["192.168.56.11"]
user               = "vagrant"
keyPath            = "/home/mainek00n/github/github.com/MaineK00n/vuls-targets-docker/.ssh/id_rsa"
scanMode           = ["fast"]
scanModules        = ["ospkg"]
$ go run cmd/vuls/main.go scan -config=./config.toml vuls-target
[Mar 14 15:48:59]  INFO [localhost] vuls-`make build` or `make install` will show the version-
[Mar 14 15:48:59]  INFO [localhost] Start scanning
[Mar 14 15:48:59]  INFO [localhost] config: ./config.toml
[Mar 14 15:48:59]  INFO [localhost] Validating config...
[Mar 14 15:48:59]  INFO [localhost] Detecting Server/Container OS... 
[Mar 14 15:48:59]  INFO [localhost] Detecting OS of servers... 
[Mar 14 15:48:59]  INFO [localhost] (1/1) Detected: vuls-target(192.168.56.10): ubuntu 20.04
[Mar 14 15:48:59]  INFO [localhost] Detecting OS of containers... 
[Mar 14 15:48:59]  INFO [localhost] Checking Scan Modes... 
[Mar 14 15:48:59]  INFO [localhost] Detecting Platforms... 
[Mar 14 15:49:00]  INFO [localhost] (1/1) vuls-target(192.168.56.10) is running on other
[Mar 14 15:49:00]  INFO [vuls-target(192.168.56.10)] Scanning OS pkg in fast mode


Scan Summary
================
vuls-target(192.168.56.10)	ubuntu20.04	594 installed





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

vulsdoc/vuls#197

@MaineK00n MaineK00n self-assigned this Mar 11, 2022
@MaineK00n MaineK00n marked this pull request as draft March 11, 2022 11:12
@MaineK00n MaineK00n force-pushed the MaineK00n/support-CIDR branch 3 times, most recently from 4497148 to 04bf883 Compare March 11, 2022 11:29
@MaineK00n MaineK00n force-pushed the MaineK00n/support-CIDR branch from 04bf883 to 465228d Compare March 14, 2022 06:44
@MaineK00n MaineK00n marked this pull request as ready for review March 14, 2022 06:55
@MaineK00n MaineK00n force-pushed the MaineK00n/support-CIDR branch from 465228d to 7f4c8d9 Compare March 14, 2022 07:12
@MaineK00n MaineK00n force-pushed the MaineK00n/support-CIDR branch from 7f4c8d9 to 1d72a19 Compare June 9, 2022 01:55
@kotakanbe kotakanbe merged commit 86b60e1 into master Jun 10, 2022
@kotakanbe kotakanbe deleted the MaineK00n/support-CIDR branch June 10, 2022 09:24
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