ruby-nmap 0.9.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +5 -5
  2. data/.document +1 -0
  3. data/.editorconfig +11 -0
  4. data/.github/workflows/ruby.yml +31 -0
  5. data/ChangeLog.md +122 -67
  6. data/Gemfile +11 -5
  7. data/LICENSE.txt +1 -1
  8. data/README.md +88 -50
  9. data/Rakefile +8 -3
  10. data/UPGRADING.md +47 -0
  11. data/gemspec.yml +6 -6
  12. data/lib/nmap/command.rb +765 -0
  13. data/lib/nmap/version.rb +1 -1
  14. data/lib/nmap/xml/address.rb +38 -0
  15. data/lib/nmap/xml/cpe/url.rb +80 -0
  16. data/lib/nmap/xml/cpe.rb +47 -0
  17. data/lib/nmap/xml/hop.rb +22 -0
  18. data/lib/nmap/xml/host.rb +546 -0
  19. data/lib/nmap/xml/host_script.rb +26 -0
  20. data/lib/nmap/xml/hostname.rb +44 -0
  21. data/lib/nmap/xml/ip_id_sequence.rb +26 -0
  22. data/lib/nmap/xml/os.rb +131 -0
  23. data/lib/nmap/xml/os_class.rb +86 -0
  24. data/lib/nmap/xml/os_match.rb +22 -0
  25. data/lib/nmap/xml/port.rb +114 -0
  26. data/lib/nmap/xml/postscript.rb +26 -0
  27. data/lib/nmap/xml/prescript.rb +26 -0
  28. data/lib/nmap/xml/run_stat.rb +22 -0
  29. data/lib/nmap/xml/scan.rb +38 -0
  30. data/lib/nmap/xml/scan_task.rb +55 -0
  31. data/lib/nmap/xml/scanner.rb +22 -0
  32. data/lib/nmap/xml/script.rb +110 -0
  33. data/lib/nmap/xml/scripts.rb +33 -0
  34. data/lib/nmap/xml/sequence.rb +52 -0
  35. data/lib/nmap/xml/service.rb +172 -0
  36. data/lib/nmap/xml/status.rb +22 -0
  37. data/lib/nmap/xml/tcp_sequence.rb +48 -0
  38. data/lib/nmap/xml/tcp_ts_sequence.rb +26 -0
  39. data/lib/nmap/xml/traceroute.rb +73 -0
  40. data/lib/nmap/xml/uptime.rb +22 -0
  41. data/lib/nmap/xml.rb +46 -44
  42. data/ruby-nmap.gemspec +38 -83
  43. data/spec/command_spec.rb +726 -0
  44. data/spec/fixtures/down_host_scan.xml +16 -0
  45. data/spec/{local_scan.xml → fixtures/local_scan.xml} +1 -1
  46. data/spec/{scan.xml → fixtures/scan.xml} +1 -1
  47. data/spec/spec_helper.rb +2 -2
  48. data/spec/{address_spec.rb → xml/address_spec.rb} +2 -2
  49. data/spec/{cpe → xml/cpe}/url_spec.rb +1 -1
  50. data/spec/{cpe_examples.rb → xml/cpe_examples.rb} +1 -1
  51. data/spec/{hop_spec.rb → xml/hop_spec.rb} +2 -2
  52. data/spec/{host_script_spec.rb → xml/host_script_spec.rb} +2 -2
  53. data/spec/{host_spec.rb → xml/host_spec.rb} +12 -8
  54. data/spec/{hostname_spec.rb → xml/hostname_spec.rb} +2 -2
  55. data/spec/{ip_id_sequence_spec.rb → xml/ip_id_sequence_spec.rb} +3 -3
  56. data/spec/{os_class_spec.rb → xml/os_class_spec.rb} +3 -3
  57. data/spec/{os_match_spec.rb → xml/os_match_spec.rb} +2 -2
  58. data/spec/{os_spec.rb → xml/os_spec.rb} +3 -3
  59. data/spec/{port_spec.rb → xml/port_spec.rb} +10 -5
  60. data/spec/{postscript_spec.rb → xml/postscript_spec.rb} +2 -2
  61. data/spec/{prescript_spec.rb → xml/prescript_spec.rb} +2 -2
  62. data/spec/{run_stat_spec.rb → xml/run_stat_spec.rb} +2 -2
  63. data/spec/{scan_spec.rb → xml/scan_spec.rb} +2 -2
  64. data/spec/{scan_task_spec.rb → xml/scan_task_spec.rb} +6 -6
  65. data/spec/{scanner_spec.rb → xml/scanner_spec.rb} +3 -3
  66. data/spec/xml/script_spec.rb +137 -0
  67. data/spec/xml/scripts_examples.rb +19 -0
  68. data/spec/{sequence_examples.rb → xml/sequence_examples.rb} +1 -0
  69. data/spec/{service_spec.rb → xml/service_spec.rb} +31 -5
  70. data/spec/{status_spec.rb → xml/status_spec.rb} +4 -3
  71. data/spec/{tcp_sequence_spec.rb → xml/tcp_sequence_spec.rb} +3 -3
  72. data/spec/{tcp_ts_sequence_spec.rb → xml/tcp_ts_sequence_spec.rb} +3 -3
  73. data/spec/{traceroute_spec.rb → xml/traceroute_spec.rb} +3 -3
  74. data/spec/{uptime_spec.rb → xml/uptime_spec.rb} +2 -2
  75. data/spec/xml_spec.rb +93 -45
  76. metadata +78 -99
  77. data/.travis.yml +0 -14
  78. data/lib/nmap/address.rb +0 -34
  79. data/lib/nmap/cpe/url.rb +0 -78
  80. data/lib/nmap/cpe.rb +0 -45
  81. data/lib/nmap/hop.rb +0 -20
  82. data/lib/nmap/host.rb +0 -586
  83. data/lib/nmap/host_script.rb +0 -18
  84. data/lib/nmap/hostname.rb +0 -42
  85. data/lib/nmap/ip_id_sequence.rb +0 -24
  86. data/lib/nmap/os.rb +0 -127
  87. data/lib/nmap/os_class.rb +0 -82
  88. data/lib/nmap/os_match.rb +0 -18
  89. data/lib/nmap/port.rb +0 -99
  90. data/lib/nmap/postscript.rb +0 -16
  91. data/lib/nmap/prescript.rb +0 -16
  92. data/lib/nmap/program.rb +0 -102
  93. data/lib/nmap/run_stat.rb +0 -20
  94. data/lib/nmap/scan.rb +0 -34
  95. data/lib/nmap/scan_task.rb +0 -50
  96. data/lib/nmap/scanner.rb +0 -18
  97. data/lib/nmap/scripts.rb +0 -71
  98. data/lib/nmap/sequence.rb +0 -50
  99. data/lib/nmap/service.rb +0 -170
  100. data/lib/nmap/status.rb +0 -18
  101. data/lib/nmap/task.rb +0 -381
  102. data/lib/nmap/tcp_sequence.rb +0 -46
  103. data/lib/nmap/tcp_ts_sequence.rb +0 -22
  104. data/lib/nmap/traceroute.rb +0 -71
  105. data/lib/nmap/uptime.rb +0 -20
  106. data/spec/scripts_examples.rb +0 -35
  107. data/spec/task_spec.rb +0 -150
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: '07049218e947bfd368b40b59010f838c9e298f25'
4
- data.tar.gz: 94176a6041fc4da9a2adcd7ebf4ea9714ff6b6e2
2
+ SHA256:
3
+ metadata.gz: c140058ce1941bb9671a06f6c35b32c702479601d00a9c21906fae39eb18cbf3
4
+ data.tar.gz: d94fbbffd46099d543aa8f27c0577fa8c387ff45d267911d8b47e5b5348f8500
5
5
  SHA512:
6
- metadata.gz: 6b753b489e1f5f8ee6e03ea9162e7a120d3fdfcb97d138f3cd0d6b02f521b0630240322e8ebb76b88a54437095b1ac40e2f2271e1692b0665df8f7203ee8bd7f
7
- data.tar.gz: f00bec7139dcd52ef9f4d351da5c3821fa0a2f20cb3570927b11b80f0c90f74cdf32876a252f1ad9b4a1b8051921c493af848991896d857b657381431438285f
6
+ metadata.gz: 98bcdb056f50dc8640ef5b4c3e3eaf1daacc2055328f0fd1c995faec543abf81d2fac5da1290e91ec88a91ea8f9bdbbc9fa03b16c9f02709ed65078c9ceeea82
7
+ data.tar.gz: 444e4918a0debc3686c346456b38e7e9a2a12573144a83c01519c28253ecdee8ab331c9e5cc7d74dee61a224eb59aea0729140d42ae1c59f8a391449ed395ae3
data/.document CHANGED
@@ -1,3 +1,4 @@
1
1
  -
2
2
  ChangeLog.md
3
3
  LICENSE.txt
4
+ UPGRADING.md
data/.editorconfig ADDED
@@ -0,0 +1,11 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ insert_final_newline = true
6
+ tab_width = 8
7
+ trim_trailing_whitespace = true
8
+
9
+ [{Gemfile,Rakefile,*.rb,*.gemspec,*.yml}]
10
+ indent_style = space
11
+ indent_size = 2
@@ -0,0 +1,31 @@
1
+ name: CI
2
+
3
+ on: [ push, pull_request ]
4
+
5
+ jobs:
6
+ tests:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby:
12
+ - '2.7'
13
+ - '3.0'
14
+ - '3.1'
15
+ - jruby
16
+ - truffleruby
17
+ name: Ruby ${{ matrix.ruby }}
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ - name: Install libxml2-dev and libxslt1-dev
25
+ run: |
26
+ sudo apt update -y && \
27
+ sudo apt install -y --no-install-recommends --no-install-suggests libxml2-dev libxslt1-dev
28
+ - name: Install dependencies
29
+ run: bundle install --jobs 4 --retry 3
30
+ - name: Run tests
31
+ run: bundle exec rake test
data/ChangeLog.md CHANGED
@@ -1,10 +1,61 @@
1
+ ### 1.0.0 / 2022-11-11
2
+
3
+ * Switched from [rprogram] to [command_mapper].
4
+ * Replaced `Nmap::Program` and `Nmap::Task` with {Nmap::Command}.
5
+ * Moved all XML classes under {Nmap::XML}.
6
+ * See [UPGRADING] for more details on how to upgrade from 0.10.0 to 1.0.0.
7
+
8
+ #### Nmap::Command
9
+
10
+ * Added support for the `--unique` option as `nmap.unique`.
11
+ * Added support for the `--resolve-all` option as `nmap.resolve_all`.
12
+ * Added support for the `--noninteractive` option as `nmap.non_interactive`.
13
+ * Added support for the `--proxies` option as `nmap.proxies`.
14
+ * Added support for the `--data` option as `nmap.data`.
15
+ * Added support for the `--data-string` option as `nmap.data_string`.
16
+ * Added support for the `--script-help` option as `nmap.script_help`.
17
+ * Added support for the `--script-args-file` option as `nmap.script_args_file`.
18
+ * Added support for the `--script-timeout` option as `nmap.script_timeout`.
19
+ * Added support for the `--initial-rtt-timeout` option as
20
+ `nmap.initial_rtt_timeout`.
21
+ * Added support for the `-vv` option as `nmap.extra_verbose`.
22
+ * Allow passing Integer values to `verbose:` or `nmap.verbose=` for
23
+ `-v`**level**.
24
+ * Greatly improved the validation of input values.
25
+ * Removed `#script_params` and `#script_params=` aliases for `#script_args` and
26
+ `#script_args=`.
27
+
28
+ #### Nmap::XML
29
+
30
+ * Removed the deprecated `Nmap::XML.load` method in favor of {Nmap::XML.parse}.
31
+ * Removed the `Nmap::XML#prescripts` alias to `Nmap::XML#prescript`.
32
+ * Removed the `Nmap::XML#postscripts` alias to `Nmap::XML#postscript`.
33
+ * Removed `Nmap::XML::Host#tcpsequence` in favor of
34
+ {Nmap::XML::Host#tcp_sequence}.
35
+ * Removed `Nmap::XML::Host#ipidsequence` in favor of
36
+ {Nmap::XML::Host#ip_id_sequence}.
37
+ * Removed `Nmap::XML::Host#tcptssequence` in favor of
38
+ {Nmap::XML::Host#tcp_ts_sequence}.
39
+ * Removed `Nmap::XML#inspect` method.
40
+ * Added {Nmap::XML::Script}.
41
+ * Removed `Nmap::XML::Scripts#script_data`.
42
+ * Changed {Nmap::XML::Scripts#scripts} to return {Nmap::XML::Script} objects.
43
+
44
+ ### 0.10.0 / 2020-03-17
45
+
46
+ * Added `Nmap::Task#exclude_ports` for the `--exclude-ports` option.
47
+ * Added `Nmap::Status#reason_ttl`.
48
+ * Added `Nmap::Port#reason_ttl`.
49
+ * Added `Nmap::XML#task`.
50
+ * Alias `Nmap::ScanTask#extra_info` to `Nmap::ScanTask#extrainfo`.
51
+
1
52
  ### 0.9.3 / 2018-05-01
2
53
 
3
54
  * Added missing `Nmap::Task#defeat_icmp_ratelimit` for the
4
55
  `--defeat-icmp-ratelimit` option.
5
56
  * Added missing `Nmap::Task#nsock_engine` for the `--nsock-engine` option.
6
- * Added the {Nmap::XML#prescripts} alias.
7
- * Added the {Nmap::XML#postscripts} alias.
57
+ * Added the `Nmap::XML#prescripts` alias.
58
+ * Added the `Nmap::XML#postscripts` alias.
8
59
  * Allow `Task#sctp_init_ping` to accept a port Range object.
9
60
  * Fixed a typo in the `Task#defeat_rst_ratelimit` name.
10
61
  * Fixed the option formatting of `Nmap::Task#syn_discovery`.
@@ -15,81 +66,81 @@
15
66
 
16
67
  ### 0.9.2 / 2017-01-13
17
68
 
18
- * Fix file descriptor leak in {Nmap::XML#initialize} by using
69
+ * Fix file descriptor leak in `Nmap::XML#initialize` by using
19
70
  `File.open(path) { |file| ... }` instead of `File.new(path)`, which keeps the
20
71
  file descriptor open until GC collects the `File` instance.
21
72
 
22
73
  ### 0.9.1 / 2016-07-18
23
74
 
24
- * Fixed {Nmap::Host#ipv6} when there are no `ipv6` type addresses.
25
- * Fixed {Nmap::OS#fingerprint} when there is no `osfingerprint` element.
75
+ * Fixed `Nmap::Host#ipv6` when there are no `ipv6` type addresses.
76
+ * Fixed `Nmap::OS#fingerprint` when there is no `osfingerprint` element.
26
77
 
27
78
  ### 0.9.0 / 2016-07-14
28
79
 
29
- * Added {Nmap::Address#vendor}.
30
- * Added {Nmap::Service#to_s}.
31
- * Added {Nmap::HostScript}.
32
- * Added {Nmap::Prescript}.
33
- * Added {Nmap::Postscript}.
34
- * Added {Nmap::XML#prescript}.
35
- * Added {Nmap::XML#postscript}.
80
+ * Added `Nmap::Address#vendor`.
81
+ * Added `Nmap::Service#to_s`.
82
+ * Added `Nmap::HostScript`.
83
+ * Added `Nmap::Prescript`.
84
+ * Added `Nmap::Postscript`.
85
+ * Added `Nmap::XML#prescript`.
86
+ * Added `Nmap::XML#postscript`.
36
87
  * Added `Nmap::Task#quiet` (aka `-v0`).
37
88
  * `#script_data` methods can now parse arbitrarily nested Arrays/Hashes.
38
- * Fixed {Nmap::CPE#each_cpe} to only match child `cpe` elements, not all
89
+ * Fixed `Nmap::CPE#each_cpe` to only match child `cpe` elements, not all
39
90
  `cpe` elements within the document.
40
- * Changed {Nmap::Service#to_s} to output product/version only if both are
91
+ * Changed `Nmap::Service#to_s` to output product/version only if both are
41
92
  present.
42
93
  * Changed `Nmap::Task#skip_discovery` to use `-Pn` instead of `-PN`, which was
43
94
  deprecated in nmap >= 7.00.
44
95
 
45
96
  ### 0.8.0 / 2014-04-16
46
97
 
47
- * Added {Nmap::XML#each_down_host}.
48
- * Added {Nmap::XML#down_hosts}.
49
- * Added {Nmap::XML#host}.
50
- * Added {Nmap::XML#up_host}.
51
- * Added {Nmap::XML#down_host}.
52
- * Added {Nmap::Host#hostname}.
53
- * Added {Nmap::Hostname#user?}.
54
- * Added {Nmap::Hostname#ptr?}.
55
- * Added {Nmap::Program.sudo_scan}.
56
- * Added {Nmap::Program#sudo_scan}.
57
- * Renamed {Nmap::XML.load} to {Nmap::XML.parse}.
98
+ * Added `Nmap::XML#each_down_host`.
99
+ * Added `Nmap::XML#down_hosts`.
100
+ * Added `Nmap::XML#host`.
101
+ * Added `Nmap::XML#up_host`.
102
+ * Added `Nmap::XML#down_host`.
103
+ * Added `Nmap::Host#hostname`.
104
+ * Added `Nmap::Hostname#user?`.
105
+ * Added `Nmap::Hostname#ptr?`.
106
+ * Added `Nmap::Program.sudo_scan`.
107
+ * Added `Nmap::Program#sudo_scan`.
108
+ * Renamed `Nmap::XML.load` to `Nmap::XML.parse`.
58
109
  * Fixed a typo in the `--privileged` flag (@BrentonEarl)
59
110
  * Allow multiple values in the `--script` flag.
60
- * Alias {Nmap::Task#script_params} to `script_args`.
111
+ * Alias `Nmap::Task#script_params` to `script_args`.
61
112
 
62
113
  ### 0.7.0 / 2014-05-09
63
114
 
64
- * Added {Nmap::CPE}.
65
- * Added {Nmap::CPE::URL}.
66
- * Added {Nmap::Hop}.
67
- * Added {Nmap::Hostname}.
68
- * Added {Nmap::Traceroute}.
69
- * Added {Nmap::Host#traceroute}.
70
- * Added {Nmap::Host#uptime}. (@roodee)
71
- * Added {Nmap::Service#ssl?}.
72
- * Added {Nmap::Service#protocol}.
73
- * Added {Nmap::Service#extra_info}.
74
- * Added {Nmap::Service#os_type}.
75
- * Added {Nmap::Service#device_type}.
76
- * Added {Nmap::Service#fingerprint}. (@roodee)
77
- * Added {Nmap::Uptime}. (@roodee)
78
- * Added {Nmap::RunStat}. (@roodee)
79
- * Added {Nmap::XML.load}. (@vzctl)
80
- * Added {Nmap::XML.open}.
81
- * Added {Nmap::XML#each_run_stat}.
82
- * Added {Nmap::XML#run_stats}.
83
- * Added {Nmap::XML#each_task}.
84
- * Fixed xpath bug in {Nmap::OS#each_class} (@roodee).
115
+ * Added `Nmap::CPE`.
116
+ * Added `Nmap::CPE::URL`.
117
+ * Added `Nmap::Hop`.
118
+ * Added `Nmap::Hostname`.
119
+ * Added `Nmap::Traceroute`.
120
+ * Added `Nmap::Host#traceroute`.
121
+ * Added `Nmap::Host#uptime`. (@roodee)
122
+ * Added `Nmap::Service#ssl?`.
123
+ * Added `Nmap::Service#protocol`.
124
+ * Added `Nmap::Service#extra_info`.
125
+ * Added `Nmap::Service#os_type`.
126
+ * Added `Nmap::Service#device_type`.
127
+ * Added `Nmap::Service#fingerprint`. (@roodee)
128
+ * Added `Nmap::Uptime`. (@roodee)
129
+ * Added `Nmap::RunStat`. (@roodee)
130
+ * Added `Nmap::XML.load`. (@vzctl)
131
+ * Added `Nmap::XML.open`.
132
+ * Added `Nmap::XML#each_run_stat`.
133
+ * Added `Nmap::XML#run_stats`.
134
+ * Added `Nmap::XML#each_task`.
135
+ * Fixed xpath bug in `Nmap::OS#each_class` (@roodee).
85
136
 
86
137
  ### 0.6.0 / 2012-11-07
87
138
 
88
- * Added {Nmap::Service}.
89
- * Renamed `Nmap::IpidSequence` to {Nmap::IpIdSequence}.
90
- * Renamed {Nmap::Host#ipidsequence} to {Nmap::Host#ip_id_sequence}.
91
- * Renamed {Nmap::Host#tcpsequence} to {Nmap::Host#tcp_sequence}.
92
- * Renamed {Nmap::Host#tcptssequence} to {Nmap::Host#tcp_ts_sequence}.
139
+ * Added `Nmap::Service`.
140
+ * Renamed `Nmap::IpidSequence` to `Nmap::IpIdSequence`.
141
+ * Renamed `Nmap::Host#ipidsequence` to `Nmap::Host#ip_id_sequence`.
142
+ * Renamed `Nmap::Host#tcpsequence` to `Nmap::Host#tcp_sequence`.
143
+ * Renamed `Nmap::Host#tcptssequence` to `Nmap::Host#tcp_ts_sequence`.
93
144
 
94
145
  ### 0.5.1 / 2012-05-27
95
146
 
@@ -100,20 +151,20 @@
100
151
 
101
152
  * Require nokogiri ~> 1.3.
102
153
  * Require rprogram ~> 0.3.
103
- * `ip_scan` in {Nmap::Task} should map to `-sO` (thanks corvus).
154
+ * `ip_scan` in `Nmap::Task` should map to `-sO` (thanks corvus).
104
155
 
105
156
  ### 0.4.1 / 2010-11-23
106
157
 
107
- * Fixed a bug in {Nmap::XML#each} where it was calling `each_up_hosts`,
108
- and not {Nmap::XML#each_up_host}.
109
- * {Nmap::OS#each_class}, {Nmap::OS#each_match}, {Nmap::XML#each_host} and
110
- {Nmap::XML#each_up_host} now return an Enumerator object if no block
158
+ * Fixed a bug in `Nmap::XML#each` where it was calling `each_up_hosts`,
159
+ and not `Nmap::XML#each_up_host`.
160
+ * `Nmap::OS#each_class`, `Nmap::OS#each_match`, `Nmap::XML#each_host` and
161
+ `Nmap::XML#each_up_host` now return an Enumerator object if no block
111
162
  is given.
112
163
  * Use `yield` instead of `block.call` for a slight performance improvement.
113
164
 
114
165
  ### 0.4.0 / 2010-11-17
115
166
 
116
- * Added new options to {Nmap::Task} based on nmap 5.21:
167
+ * Added new options to `Nmap::Task` based on nmap 5.21:
117
168
  * `-PY` - `nmap.sctp_init_ping`
118
169
  * `-PR` - `nmap.arp_ping`
119
170
  * `-sY` - `nmap.sctp_init_scan`
@@ -137,27 +188,27 @@
137
188
 
138
189
  ### 0.3.0 / 2010-11-08
139
190
 
140
- * Added {Nmap::Host#scripts}.
141
- * Added {Nmap::Scripts#scripts Nmap::Port#scripts}.
191
+ * Added `Nmap::Host#scripts`.
192
+ * Added `Nmap::Port#scripts`.
142
193
 
143
194
  ### 0.2.0 / 2010-10-29
144
195
 
145
196
  * Require nokogiri >= 1.3.0.
146
197
  * Require rprogram ~> 0.2.0.
147
- * Added {Nmap::XML#tasks}.
148
- * Added {Nmap::Scanner#start_time}.
149
- * Added {Nmap::ScanTask#duration}.
150
- * Added {Nmap::Host#start_time}.
151
- * Added {Nmap::Host#end_time}.
198
+ * Added `Nmap::XML#tasks`.
199
+ * Added `Nmap::Scanner#start_time`.
200
+ * Added `Nmap::ScanTask#duration`.
201
+ * Added `Nmap::Host#start_time`.
202
+ * Added `Nmap::Host#end_time`.
152
203
  * Allow `Nmap::Tasks#ports=` to accept port ranges.
153
- * Omit the `-p` option if no ports are given to {Nmap::Task}.
204
+ * Omit the `-p` option if no ports are given to `Nmap::Task`.
154
205
  * Have the `Nmap::Host#each_*` methods return an `Enumerator` object if no
155
206
  block is given.
156
207
 
157
208
  ### 0.1.1 / 2010-01-02
158
209
 
159
210
  * Require RProgram >= 0.1.8.
160
- * Adds `sudo` and `sudo=` instance methods to {Nmap::Task}.
211
+ * Adds `sudo` and `sudo=` instance methods to `Nmap::Task`.
161
212
 
162
213
  ### 0.1.0 / 2009-11-13
163
214
 
@@ -165,3 +216,7 @@
165
216
  * Provides a Ruby interface for running Nmap.
166
217
  * Provides a Parser for enumerating Nmap XML scan files.
167
218
 
219
+ [rprogram]: https://github.com/postmodern/rprogram#readme
220
+ [command_mapper]: https://github.com/postmodern/command_mapper.rb#readme
221
+
222
+ [UPGRADING]: https://github.com/postmodern/ruby-nmap/blob/main/UPGRADING.md
data/Gemfile CHANGED
@@ -2,13 +2,19 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ # gem 'command_mapper', '~> 0.3', github: 'postmodern/command_mapper.rb',
6
+ # branch: '0.3.0'
7
+
5
8
  group :development do
6
9
  gem 'rake'
7
- gem 'rubygems-tasks', '~> 0.2'
8
- gem 'rspec', '~> 3.0'
10
+ gem 'rubygems-tasks', '~> 0.2'
11
+ gem 'rspec', '~> 3.0'
12
+ gem 'simplecov', '~> 0.20'
9
13
 
10
- gem 'json'
11
- gem 'simplecov', '~> 0.7'
12
14
  gem 'kramdown'
13
- gem 'yard', '~> 0.9'
15
+ gem 'redcarpet', platform: :mri
16
+ gem 'yard', '~> 0.9'
17
+ gem 'yard-spellcheck', require: false
18
+
19
+ gem 'dead_end', require: false
14
20
  end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2018 Postmodern
1
+ Copyright (c) 2009-2022 Postmodern
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,102 +1,140 @@
1
1
  # ruby-nmap
2
2
 
3
- * [Source](https://github.com/sophsec/ruby-nmap/)
4
- * [Issues](https://github.com/sophsec/ruby-nmap/issues)
3
+ [![CI](https://github.com/postmodern/ruby-nmap/actions/workflows/ruby.yml/badge.svg)](https://github.com/postmodern/ruby-nmap/actions/workflows/ruby.yml)
4
+ [![Code Climate](https://codeclimate.com/github/postmodern/ruby-nmap.svg)](https://codeclimate.com/github/postmodern/ruby-nmap)
5
+ [![Gem Version](https://badge.fury.io/rb/ruby-nmap.svg)](https://badge.fury.io/rb/ruby-nmap)
6
+
7
+ * [Source](https://github.com/postmodern/ruby-nmap/)
8
+ * [Issues](https://github.com/postmodern/ruby-nmap/issues)
5
9
  * [Documentation](http://rubydoc.info/gems/ruby-nmap/frames)
6
- * [Email](mailto:postmodern.mod3 at gmail.com)
7
- * [![Build Status](https://travis-ci.org/sophsec/ruby-nmap.svg)](https://travis-ci.org/sophsec/ruby-nmap)
8
10
 
9
11
  ## Description
10
12
 
11
- A Ruby interface to [nmap], the exploration tool and security / port scanner.
13
+ A Ruby API to [nmap], the exploration tool and security / port scanner.
14
+ Allows automating nmap and parsing nmap XML files.
12
15
 
13
16
  ## Features
14
17
 
15
- * Provides a Ruby interface for running nmap.
18
+ * Provides a Ruby API for automating nmap.
16
19
  * Provides a Parser for enumerating nmap XML scan files.
20
+ * Supports the full [Nmap XML DTD][nmap-dtd].
17
21
 
18
22
  ## Examples
19
23
 
20
24
  Run Nmap from Ruby:
21
25
 
22
- require 'nmap/program'
23
-
24
- Nmap::Program.scan do |nmap|
25
- nmap.syn_scan = true
26
- nmap.service_scan = true
27
- nmap.os_fingerprint = true
28
- nmap.xml = 'scan.xml'
29
- nmap.verbose = true
30
-
31
- nmap.ports = [20,21,22,23,25,80,110,443,512,522,8080,1080]
32
- nmap.targets = '192.168.1.*'
33
- end
26
+ ```ruby
27
+ require 'nmap/command'
28
+
29
+ Nmap::Command.run do |nmap|
30
+ nmap.connect_scan = true
31
+ nmap.service_scan = true
32
+ nmap.output_xml = 'scan.xml'
33
+ nmap.verbose = true
34
+
35
+ nmap.ports = [20, 21, 22, 23, 25, 80, 110, 443, 512, 522, 8080, 1080]
36
+ nmap.targets = '192.168.1.*'
37
+ end
38
+ ```
34
39
 
35
40
  Run `sudo nmap` from Ruby:
36
41
 
37
- require 'nmap/program'
42
+ ```ruby
43
+ require 'nmap/command'
38
44
 
39
- Nmap::Program.sudo_scan do |nmap|
40
- nmap.syn_scan = true
41
- # ...
42
- end
45
+ Nmap::Command.sudo do |nmap|
46
+ nmap.syn_scan = true
47
+ nmap.os_fingerprint = true
48
+ nmap.service_scan = true
49
+ nmap.output_xml = 'scan.xml'
50
+ nmap.verbose = true
51
+
52
+ nmap.ports = [20, 21, 22, 23, 25, 80, 110, 443, 512, 522, 8080, 1080]
53
+ nmap.targets = '192.168.1.*'
54
+ end
55
+ ```
43
56
 
44
57
  Parse Nmap XML scan files:
45
58
 
46
- require 'nmap/xml'
59
+ ```ruby
60
+ require 'nmap/xml'
47
61
 
48
- Nmap::XML.new('scan.xml') do |xml|
49
- xml.each_host do |host|
50
- puts "[#{host.ip}]"
51
-
52
- host.each_port do |port|
53
- puts " #{port.number}/#{port.protocol}\t#{port.state}\t#{port.service}"
54
- end
55
- end
62
+ Nmap::XML.open('scan.xml') do |xml|
63
+ xml.each_host do |host|
64
+ puts "[#{host.ip}]"
65
+
66
+ host.each_port do |port|
67
+ puts " #{port.number}/#{port.protocol}\t#{port.state}\t#{port.service}"
56
68
  end
69
+ end
70
+ end
71
+ ```
57
72
 
58
73
  Print NSE script output from an XML scan file:
59
74
 
60
- require 'nmap/xml'
75
+ ```ruby
76
+ require 'nmap/xml'
61
77
 
62
- Nmap::XML.new('nse.xml') do |xml|
63
- xml.each_host do |host|
64
- puts "[#{host.ip}]"
78
+ Nmap::XML.open('nse.xml') do |xml|
79
+ xml.each_host do |host|
80
+ puts "[#{host.ip}]"
65
81
 
66
- host.scripts.each do |name,output|
67
- output.each_line { |line| puts " #{line}" }
68
- end
82
+ host.scripts.each do |name,output|
83
+ output.each_line { |line| puts " #{line}" }
84
+ end
69
85
 
70
- host.each_port do |port|
71
- puts " [#{port.number}/#{port.protocol}]"
86
+ host.each_port do |port|
87
+ puts " [#{port.number}/#{port.protocol}]"
72
88
 
73
- port.scripts.each do |name,output|
74
- puts " [#{name}]"
89
+ port.scripts.each do |id,script|
90
+ puts " [#{id}]"
75
91
 
76
- output.each_line { |line| puts " #{line}" }
77
- end
78
- end
92
+ script.output.each_line { |line| puts " #{line}" }
79
93
  end
80
94
  end
95
+ end
96
+ end
97
+ ```
81
98
 
82
99
  ## Requirements
83
100
 
84
101
  * [ruby] >= 2.0.0
85
102
  * [nmap] >= 5.00
86
103
  * [nokogiri] ~> 1.3
87
- * [rprogram] ~> 0.3
104
+ * [command_mapper] ~> 0.3
88
105
 
89
106
  ## Install
90
107
 
91
- $ gem install ruby-nmap
108
+ * Debian / Ubuntu:
109
+
110
+ ```shell
111
+ $ sudo apt install nmap
112
+ ```
113
+
114
+ * Fedora / RedHat:
115
+
116
+ ```shell
117
+ $ sudo dnf install nmap
118
+ ```
119
+
120
+ * Homebrew:
121
+
122
+ ```shell
123
+ $ brew install nmap
124
+ ```
125
+
126
+ ```shell
127
+ $ gem install ruby-nmap
128
+ ```
92
129
 
93
130
  ## License
94
131
 
95
- Copyright (c) 2009-2018 Postmodern
132
+ Copyright (c) 2009-2022 Postmodern
96
133
 
97
134
  See {file:LICENSE.txt} for license information.
98
135
 
99
136
  [nmap]: http://www.insecure.org/
100
137
  [ruby]: https://www.ruby-lang.org/
101
138
  [nokogiri]: http://nokogiri.rubyforge.org/
102
- [rprogram]: https://github.com/postmodern/rprogram#readme
139
+ [command_mapper]: https://github.com/postmodern/command_mapper.rb#readme
140
+ [nmap-dtd]: https://nmap.org/book/nmap-dtd.html
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Gem::Tasks.new
20
20
  require 'rspec/core/rake_task'
21
21
  RSpec::Core::RakeTask.new
22
22
 
23
- task :spec => 'spec/scan.xml'
23
+ task :spec => 'spec/fixtures/scan.xml'
24
24
  task :test => :spec
25
25
  task :default => :spec
26
26
 
@@ -28,7 +28,12 @@ require 'yard'
28
28
  YARD::Rake::YardocTask.new
29
29
  task :doc => :yard
30
30
 
31
- file 'spec/scan.xml' do
31
+ file 'spec/fixtures/scan.xml' do |t|
32
32
  puts ">>> Scanning scanme.nmap.org ..."
33
- sh 'sudo nmap -v -sS -sU -A -O --script ssh2-enum-algos,ssh-hostkey -oX spec/scan.xml scanme.nmap.org'
33
+ sh "sudo nmap -v -sS -sU -A -O --script ssh2-enum-algos,ssh-hostkey -oX #{t.name} scanme.nmap.org"
34
+ end
35
+
36
+ file 'spec/fixtures/down_host_scan.xml' do |t|
37
+ puts ">>> Scanning 225.0.0.1 ..."
38
+ sh "sudo nmap -v -sS -oX #{t.name} 225.0.0.1"
34
39
  end
data/UPGRADING.md ADDED
@@ -0,0 +1,47 @@
1
+ # Migration Guide
2
+
3
+ ## 0.10.0 -> 1.0.0
4
+
5
+ ### `Nmap::Program`/`Namp::Task` -> `Nmap::Command`
6
+
7
+ * Replace all method calls to `Nmap::Program.scan` with `Nmap::Command.run`.
8
+ * Replace all method calls to `Nmap::Program.sudo_scan` with `Nmap::Command.sudo`.
9
+ * Rename all instances of `raw_ip` with `send_ip`.
10
+ * Rename all instances of `raw_ethernet` to `send_eth`.
11
+ * Rename all instances of `disable_stylesheet` to `no_stylesheet`.
12
+ * Rename all instances of `nmap_stylesheet` to `webxml`.
13
+ * Rename all instances of `append` to `append_output`.
14
+ * Rename all instances of `save` to `output_normal`.
15
+ * Rename all instances of `grepable` to `output_grepable`.
16
+ * Rename all instances of `skiddie` to `output_skiddie`.
17
+ * Rename all instances of `xml` to `output_xml`.
18
+ * Rename all instances of `script_params` to `script_args`.
19
+ * Remove any instances of the `:interactive` option or `nmap.interactive`, as
20
+ the `--interactive` option is no longer supported by nmap.
21
+
22
+ ### `Nmap::XML`
23
+
24
+ * `Nmap::XML.new` now only accepts a parsed `Nokogiri::XML::Document` object.
25
+ Use `Nmap::XML.open` or `Nmap::XML.parse` if you wish to parse XML files or
26
+ strings.
27
+ * Replace any method calls to `Nmap::XML.load` with {Nmap::XML.parse}.
28
+ * Rename any method calls to `` to `tcp_sequence`.
29
+ * Rename any method calls to `tcpsequence` to `tcp_sequence`.
30
+ * Rename any method calls to `ipidsequence` to `ip_id_sequence`.
31
+ * Rename any method calls to `tcptssequence` to `tcp_ts_sequence`.
32
+ * Rename any method calls to `prescripts` to `prescript`.
33
+ * Rename any method calls to `postscripts` to `postscript`.
34
+ * The [scripts][Nmap::XML::Scripts#scripts] method now returns an Array of
35
+ [Nmap::XML::Script] objects, instead of raw script output Strings.
36
+ In order to access the raw script output Strings, call the
37
+ [output][Nmap::XML::Script#output] method on each returned [Nmap::XML::Script]
38
+ objects instead.
39
+ * The `script_data` method has been removed.
40
+ In order to get the script's structured data, call
41
+ the [data][Nmap::XML::Script#data] method on each returned [Nmap::XML::Script]
42
+ objects instead.
43
+ * Rename any method calls to `extrainfo` to `extra_info`.
44
+
45
+ [Nmap::XML::Scripts#scripts]: https://rubydoc.info/gems/ruby-nmap/Nmap/XML/Scripts.html#scripts-instance_method
46
+ [Nmap::XML::Script]: https://rubydoc.info/gems/ruby-nmap/Nmap/XML/Script.html
47
+ [Nmap::XML::Script#output]: https://rubydoc.info/gems/ruby-nmap/Nmap/XML/Script.html#output-instance_method
data/gemspec.yml CHANGED
@@ -1,13 +1,13 @@
1
1
  name: ruby-nmap
2
- summary: A Ruby interface to Nmap.
2
+ summary: A Ruby API to nmap.
3
3
  description:
4
- A Ruby interface to Nmap, the exploration tool and security / port
5
- scanner.
4
+ A Ruby API to nmap, the exploration tool and security / port
5
+ scanner. Allows automating nmap and parsing nmap XML files.
6
6
 
7
7
  license: MIT
8
8
  authors: Postmodern
9
9
  email: postmodern.mod3@gmail.com
10
- homepage: https://github.com/sophsec/ruby-nmap#readme
10
+ homepage: https://github.com/postmodern/ruby-nmap#readme
11
11
  has_yard: true
12
12
 
13
13
  required_ruby_version: ">= 2.0.0"
@@ -16,7 +16,7 @@ requirements: nmap >= 5.00
16
16
 
17
17
  dependencies:
18
18
  nokogiri: ~> 1.3
19
- rprogram: ~> 0.3
19
+ command_mapper: ~> 0.3
20
20
 
21
21
  development_dependencies:
22
- bundler: ~> 1.0
22
+ bundler: ~> 2.0