Skip to content

Commit

Permalink
Added the missing --syn-scan option.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jun 14, 2024
1 parent a3592da commit bdedf0f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 39 deletions.
26 changes: 14 additions & 12 deletions data/templates/script.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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] -%>

Expand Down
9 changes: 9 additions & 0 deletions lib/ronin/nmap/cli/commands/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Integer, Range(Integer,Integer)>, "-", nil]
Expand Down
3 changes: 3 additions & 0 deletions man/ronin-nmap-new.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
92 changes: 65 additions & 27 deletions spec/cli/commands/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')}"] }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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} ]"
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit bdedf0f

Please sign in to comment.