From bdedf0fd3061e17cd2d9a5e991eb410930372b27 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Fri, 14 Jun 2024 01:11:25 -0700 Subject: [PATCH] Added the missing `--syn-scan` option. --- data/templates/script.rb.erb | 26 +++++---- lib/ronin/nmap/cli/commands/new.rb | 9 +++ man/ronin-nmap-new.1.md | 3 + spec/cli/commands/new_spec.rb | 92 +++++++++++++++++++++--------- 4 files changed, 91 insertions(+), 39 deletions(-) diff --git a/data/templates/script.rb.erb b/data/templates/script.rb.erb index 613d524..23a8deb 100644 --- a/data/templates/script.rb.erb +++ b/data/templates/script.rb.erb @@ -10,28 +10,30 @@ xml = Ronin::Nmap.parse(ARGV[0]) <%- end -%> <%- else -%> xml = Ronin::Nmap.scan do |nmap| -<%- case @targets.length -%> -<%- when 0 -%> - nmap.targets = ARGV[0] -<%- when 1 -%> - nmap.targets = <%= @targets[0].inspect %> +<%- if @xml_file -%> + nmap.xml_file = <%= @xml_file.inspect %> <%- else -%> - nmap.targets = <%= @targets.inspect %> + # nmap.xml_file = "path/to/nmap.xml" <%- end -%> <%- if @syn_scan -%> nmap.syn_scan = true +<%- else -%> + # nmap.syn_scan = true <%- end -%> <%- if @ports -%> - nmap.ports = <%= @ports.inspect %> + nmap.ports = <%= @ports.inspect %> <%- else -%> - # nmap.ports = [22, 80, 443, 8000..9000] + # nmap.ports = [22, 80, 443, 8000..9000] <%- end -%> -<%- if @xml_file -%> - nmap.xml_file = <%= @xml_file.inspect %> +<%- case @targets.length -%> +<%- when 0 -%> + nmap.targets = ARGV[0] +<%- when 1 -%> + nmap.targets = <%= @targets[0].inspect %> <%- else -%> - # nmap.xml_file = "path/to/nmap.xml" + nmap.targets = <%= @targets.inspect %> <%- end -%> -) +end <%- end -%> <% if @features[:printing] -%> diff --git a/lib/ronin/nmap/cli/commands/new.rb b/lib/ronin/nmap/cli/commands/new.rb index 4874f1e..9e5af82 100644 --- a/lib/ronin/nmap/cli/commands/new.rb +++ b/lib/ronin/nmap/cli/commands/new.rb @@ -87,6 +87,10 @@ class New < Command @xml_file = file end + option :syn_scan, desc: 'Enables SYN scanning' do + @syn_scan = true + end + option :ports, short: '-p', value: { type: String, @@ -127,6 +131,11 @@ class New < Command # @return [String, nil] attr_reader :xml_file + # Specifies whether to enable SYN scanning. + # + # @return [Boolean] + attr_reader :syn_scan + # The optional ports to scan. # # @return [Array, "-", nil] diff --git a/man/ronin-nmap-new.1.md b/man/ronin-nmap-new.1.md index 424a352..25785d5 100644 --- a/man/ronin-nmap-new.1.md +++ b/man/ronin-nmap-new.1.md @@ -38,6 +38,9 @@ library. : Parses or writes the scan results to the given XML File. Is compatible with both `--parser` and `--scanner`. +`--syn-scan` +: Enables SYN scanning. Only compatible with the `--scanner` option. + `-p`, `--port` {*PORT* \| \[*PORT1*\]-\[*PORT2*\]}[,...] : Specifies the ports to scan. Not compatible with the `--parser` option. diff --git a/spec/cli/commands/new_spec.rb b/spec/cli/commands/new_spec.rb index b6d653f..11a4ca6 100644 --- a/spec/cli/commands/new_spec.rb +++ b/spec/cli/commands/new_spec.rb @@ -48,6 +48,14 @@ end end + context "when given the '--syn-scan' option" do + let(:argv) { %w[--syn-scan] } + + it "must set #syn_scan to true" do + expect(subject.syn_scan).to be(true) + end + end + context "when given the '--ports PORT,...' option" do let(:ports) { [22, 80, 443] } let(:argv) { ['--ports', "#{ports.join(',')}"] } @@ -153,10 +161,11 @@ require 'ronin/nmap' xml = Ronin::Nmap.scan do |nmap| - nmap.targets = ARGV[0] - # nmap.ports = [22, 80, 443, 8000..9000] # nmap.xml_file = "path/to/nmap.xml" - ) + # nmap.syn_scan = true + # nmap.ports = [22, 80, 443, 8000..9000] + nmap.targets = ARGV[0] + end RUBY ) end @@ -246,10 +255,11 @@ require 'ronin/nmap' xml = Ronin::Nmap.scan do |nmap| - nmap.targets = ARGV[0] - # nmap.ports = [22, 80, 443, 8000..9000] # nmap.xml_file = "path/to/nmap.xml" - ) + # nmap.syn_scan = true + # nmap.ports = [22, 80, 443, 8000..9000] + nmap.targets = ARGV[0] + end RUBY ) end @@ -267,10 +277,11 @@ require 'ronin/nmap' xml = Ronin::Nmap.scan do |nmap| - nmap.targets = ARGV[0] - # nmap.ports = [22, 80, 443, 8000..9000] # nmap.xml_file = "path/to/nmap.xml" - ) + # nmap.syn_scan = true + # nmap.ports = [22, 80, 443, 8000..9000] + nmap.targets = ARGV[0] + end xml.each_host do |host| puts "[ \#{host.ip} ]" @@ -301,10 +312,11 @@ require 'ronin/nmap' xml = Ronin::Nmap.scan do |nmap| - nmap.targets = ARGV[0] - # nmap.ports = [22, 80, 443, 8000..9000] # nmap.xml_file = "path/to/nmap.xml" - ) + # nmap.syn_scan = true + # nmap.ports = [22, 80, 443, 8000..9000] + nmap.targets = ARGV[0] + end Ronin::DB.connect Ronin::Nmap::Importer.import(xml) @@ -325,10 +337,32 @@ require 'ronin/nmap' xml = Ronin::Nmap.scan do |nmap| - nmap.targets = ARGV[0] - # nmap.ports = [22, 80, 443, 8000..9000] nmap.xml_file = #{file.inspect} - ) + # nmap.syn_scan = true + # nmap.ports = [22, 80, 443, 8000..9000] + nmap.targets = ARGV[0] + end + RUBY + ) + end + end + + context "when given the '--syn-scan' option" do + let(:argv) { %w[--syn-scan] } + + it "must add `nmap.syn_scan = true` line to the `Ronin::Nmap.scan` block" do + expect(File.read(path)).to eq( + <<~RUBY + #!/usr/bin/env ruby + + require 'ronin/nmap' + + xml = Ronin::Nmap.scan do |nmap| + # nmap.xml_file = "path/to/nmap.xml" + nmap.syn_scan = true + # nmap.ports = [22, 80, 443, 8000..9000] + nmap.targets = ARGV[0] + end RUBY ) end @@ -346,10 +380,11 @@ require 'ronin/nmap' xml = Ronin::Nmap.scan do |nmap| - nmap.targets = ARGV[0] - nmap.ports = #{ports.inspect} # nmap.xml_file = "path/to/nmap.xml" - ) + # nmap.syn_scan = true + nmap.ports = #{ports.inspect} + nmap.targets = ARGV[0] + end RUBY ) end @@ -379,10 +414,11 @@ require 'ronin/nmap' xml = Ronin::Nmap.scan do |nmap| - nmap.targets = ARGV[0] - nmap.ports = #{ports.inspect} # nmap.xml_file = "path/to/nmap.xml" - ) + # nmap.syn_scan = true + nmap.ports = #{ports.inspect} + nmap.targets = ARGV[0] + end RUBY ) end @@ -416,10 +452,11 @@ require 'ronin/nmap' xml = Ronin::Nmap.scan do |nmap| - nmap.targets = ARGV[0] - nmap.ports = #{ports.inspect} # nmap.xml_file = "path/to/nmap.xml" - ) + # nmap.syn_scan = true + nmap.ports = #{ports.inspect} + nmap.targets = ARGV[0] + end RUBY ) end @@ -436,10 +473,11 @@ require 'ronin/nmap' xml = Ronin::Nmap.scan do |nmap| - nmap.targets = ARGV[0] - nmap.ports = "-" # nmap.xml_file = "path/to/nmap.xml" - ) + # nmap.syn_scan = true + nmap.ports = "-" + nmap.targets = ARGV[0] + end RUBY ) end