recog 2.3.21 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +42 -16
  4. data/Rakefile +2 -9
  5. data/lib/recog/db.rb +2 -1
  6. data/lib/recog/db_manager.rb +1 -1
  7. data/lib/recog/fingerprint.rb +33 -6
  8. data/lib/recog/fingerprint_parse_error.rb +10 -0
  9. data/lib/recog/verifier.rb +9 -9
  10. data/lib/recog/verify_reporter.rb +17 -6
  11. data/lib/recog/version.rb +1 -1
  12. data/{bin → recog/bin}/recog_match +0 -1
  13. data/{xml → recog/xml}/apache_modules.xml +0 -0
  14. data/{xml → recog/xml}/apache_os.xml +98 -56
  15. data/{xml → recog/xml}/architecture.xml +15 -1
  16. data/recog/xml/dhcp_vendor_class.xml +206 -0
  17. data/{xml → recog/xml}/dns_versionbind.xml +16 -13
  18. data/{xml → recog/xml}/favicons.xml +297 -47
  19. data/{xml → recog/xml}/fingerprints.xsd +9 -1
  20. data/{xml → recog/xml}/ftp_banners.xml +160 -156
  21. data/{xml → recog/xml}/h323_callresp.xml +101 -101
  22. data/{xml → recog/xml}/hp_pjl_id.xml +84 -84
  23. data/{xml → recog/xml}/html_title.xml +727 -34
  24. data/{xml → recog/xml}/http_cookies.xml +160 -77
  25. data/{xml → recog/xml}/http_servers.xml +556 -283
  26. data/{xml → recog/xml}/http_wwwauth.xml +190 -75
  27. data/{xml → recog/xml}/imap_banners.xml +5 -5
  28. data/{xml → recog/xml}/ldap_searchresult.xml +0 -0
  29. data/{xml → recog/xml}/mdns_device-info_txt.xml +389 -26
  30. data/{xml → recog/xml}/mdns_workstation_txt.xml +0 -0
  31. data/{xml → recog/xml}/mysql_banners.xml +1 -1
  32. data/{xml → recog/xml}/mysql_error.xml +0 -0
  33. data/{xml → recog/xml}/nntp_banners.xml +11 -8
  34. data/{xml → recog/xml}/ntp_banners.xml +97 -97
  35. data/{xml → recog/xml}/operating_system.xml +95 -80
  36. data/{xml → recog/xml}/pop_banners.xml +23 -23
  37. data/{xml → recog/xml}/rsh_resp.xml +3 -3
  38. data/{xml → recog/xml}/rtsp_servers.xml +0 -0
  39. data/{xml → recog/xml}/sip_banners.xml +43 -5
  40. data/{xml → recog/xml}/sip_user_agents.xml +175 -27
  41. data/{xml → recog/xml}/smb_native_lm.xml +5 -5
  42. data/{xml → recog/xml}/smb_native_os.xml +25 -25
  43. data/{xml → recog/xml}/smtp_banners.xml +147 -146
  44. data/{xml → recog/xml}/smtp_debug.xml +0 -0
  45. data/{xml → recog/xml}/smtp_ehlo.xml +1 -1
  46. data/{xml → recog/xml}/smtp_expn.xml +0 -0
  47. data/{xml → recog/xml}/smtp_help.xml +11 -11
  48. data/{xml → recog/xml}/smtp_mailfrom.xml +0 -0
  49. data/{xml → recog/xml}/smtp_noop.xml +2 -2
  50. data/{xml → recog/xml}/smtp_quit.xml +0 -0
  51. data/{xml → recog/xml}/smtp_rcptto.xml +0 -0
  52. data/{xml → recog/xml}/smtp_rset.xml +0 -0
  53. data/{xml → recog/xml}/smtp_turn.xml +0 -0
  54. data/{xml → recog/xml}/smtp_vrfy.xml +0 -0
  55. data/{xml → recog/xml}/snmp_sysdescr.xml +1570 -1430
  56. data/{xml → recog/xml}/snmp_sysobjid.xml +38 -27
  57. data/{xml → recog/xml}/ssh_banners.xml +16 -10
  58. data/{xml → recog/xml}/telnet_banners.xml +238 -21
  59. data/{xml → recog/xml}/tls_jarm.xml +56 -6
  60. data/{xml → recog/xml}/x11_banners.xml +3 -3
  61. data/{xml → recog/xml}/x509_issuers.xml +49 -1
  62. data/{xml → recog/xml}/x509_subjects.xml +139 -38
  63. data/recog.gemspec +9 -5
  64. data/spec/data/external_example_fingerprint/hp_printer_ex_01.txt +1 -0
  65. data/spec/data/external_example_fingerprint/hp_printer_ex_02.txt +1 -0
  66. data/spec/data/external_example_fingerprint.xml +8 -0
  67. data/spec/data/external_example_illegal_path_fingerprint.xml +7 -0
  68. data/spec/lib/recog/db_spec.rb +84 -61
  69. data/spec/lib/recog/fingerprint_spec.rb +4 -4
  70. data/spec/lib/recog/verify_reporter_spec.rb +73 -4
  71. data/spec/spec_helper.rb +4 -0
  72. metadata +65 -134
  73. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -37
  74. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
  75. data/.github/ISSUE_TEMPLATE/fingerprint_request.md +0 -27
  76. data/.github/PULL_REQUEST_TEMPLATE +0 -24
  77. data/.github/SECURITY.md +0 -35
  78. data/.github/workflows/ci.yml +0 -26
  79. data/.gitignore +0 -23
  80. data/.rspec +0 -3
  81. data/.ruby-gemset +0 -1
  82. data/.ruby-version +0 -1
  83. data/.snyk +0 -10
  84. data/.travis.yml +0 -25
  85. data/CONTRIBUTING.md +0 -270
  86. data/bin/recog_cleanup +0 -16
  87. data/bin/recog_export +0 -81
  88. data/bin/recog_standardize +0 -148
  89. data/bin/recog_verify +0 -64
  90. data/cpe-remap.yaml +0 -343
  91. data/features/data/failing_banners_fingerprints.xml +0 -20
  92. data/features/data/matching_banners_fingerprints.xml +0 -23
  93. data/features/data/multiple_banners_fingerprints.xml +0 -32
  94. data/features/data/no_tests.xml +0 -3
  95. data/features/data/sample_banner.txt +0 -2
  96. data/features/data/successful_tests.xml +0 -18
  97. data/features/data/tests_with_failures.xml +0 -20
  98. data/features/data/tests_with_warnings.xml +0 -17
  99. data/features/match.feature +0 -36
  100. data/features/support/aruba.rb +0 -3
  101. data/features/support/env.rb +0 -6
  102. data/features/verify.feature +0 -48
  103. data/identifiers/README.md +0 -70
  104. data/identifiers/fields.txt +0 -104
  105. data/identifiers/hw_device.txt +0 -78
  106. data/identifiers/hw_family.txt +0 -113
  107. data/identifiers/hw_product.txt +0 -410
  108. data/identifiers/os_architecture.txt +0 -10
  109. data/identifiers/os_device.txt +0 -75
  110. data/identifiers/os_family.txt +0 -233
  111. data/identifiers/os_product.txt +0 -340
  112. data/identifiers/service_family.txt +0 -249
  113. data/identifiers/service_product.txt +0 -752
  114. data/identifiers/vendor.txt +0 -798
  115. data/lib/recog/verifier_factory.rb +0 -13
  116. data/misc/convert_mysql_err +0 -61
  117. data/misc/order.xsl +0 -17
  118. data/requirements.txt +0 -2
  119. data/spec/lib/fingerprint_self_test_spec.rb +0 -174
  120. data/update_cpes.py +0 -250
data/CONTRIBUTING.md DELETED
@@ -1,270 +0,0 @@
1
- # Contributing to Recog
2
-
3
- The users and maintainers of Recog would greatly appreciate any contributions
4
- you can make to the project. These contributions typically come in the form of
5
- filed bugs/issues or pull requests (PRs). These contributions routinely result
6
- in new versions of the [recog gem](https://rubygems.org/gems/recog) being
7
- released. The process for everything is described below.
8
-
9
- ## Table of Contents
10
-
11
- 1. [Contributing Issues / Bug Reports](#contributing-issues-/-bug-reports)
12
- 1. [Contributing Code](#contributing-code)
13
- 1. [Fork and Clone](#fork-and-clone)
14
- 1. [Branch and Improve](#branch-and-improve)
15
- 1. [Testing](#testing)
16
- 1. [Fingerprints](#fingerprints)
17
- 1. [Best Practices](#best-practices)
18
- 1. [Fingerprint Testing](#fingerprint-testing)
19
- 1. [Updating CPEs](#updating-cpes)
20
- 1. [Project Operations](#project-operations)
21
- 1. [Landing PRs](#landing-prs)
22
- 1. [Releasing New Versions](#releasing-new-versions)
23
-
24
- ## Contributing Issues / Bug Reports
25
-
26
- If you encounter any bugs or problems with Recog, please file them
27
- [here](https://github.com/rapid7/recog/issues/new), providing as much detail as
28
- possible. If the bug is straight-forward enough and you understand the fix for
29
- the bug well enough, you may take the simpler, less-paperwork route and simply
30
- fill a PR with the fix and the necessary details.
31
-
32
- [^back to top](#contributing-to-recog)
33
-
34
- ## Contributing Code
35
-
36
- Recog uses a model nearly identical to that of
37
- [Metasploit](https://github.com/rapid7/metasploit-framework) as outlined
38
- [here](https://github.com/rapid7/metasploit-framework/wiki/Setting-Up-a-Metasploit-Development-Environment),
39
- at least from a ```git``` perspective. If you've been through that process
40
- (or, even better, you've been through it many times with many people), you can
41
- do exactly what you did for Metasploit but with Recog and ignore the rest of
42
- this document.
43
-
44
- On the other hand, if you haven't, read on!
45
-
46
- [^back to top](#contributing-to-recog)
47
-
48
- ### Fork and Clone
49
-
50
- Generally, this should only need to be done once, or if you need to start over.
51
-
52
- 1. Fork Recog: Visit https://github.com/rapid7/recog and click Fork,
53
- selecting your github account if prompted
54
- 1. Clone `git@github.com:<your-github-username>/recog.git`, replacing
55
- `<your-github-username>` with, you guessed it, your Github username.
56
- 1. Add the master Recog repository as your upstream:
57
-
58
- ```bash
59
- git remote add upstream git://github.com/rapid7/recog.git
60
- ```
61
-
62
- 1. Update your `.git/config` to ensure that the `remote ["upstream"]` section is configured to pull both branches and PRs from upstream. It should look something like the following, in particular the second `fetch` option:
63
-
64
- ```bash
65
- [remote "upstream"]
66
- url = git@github.com:rapid7/recog.git
67
- fetch = +refs/heads/*:refs/remotes/upstream/*
68
- fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*
69
- ```
70
-
71
- 1. Fetch the latest revisions, including PRs:
72
-
73
- ```bash
74
- git fetch --all
75
- ```
76
-
77
- [^back to top](#contributing-to-recog)
78
-
79
- ### Branch and Improve
80
-
81
- If you have a contribution to make, first create a branch to contain your
82
- work. The name is yours to choose, however generally it should roughly
83
- describe what you are doing. In this example, and from here on out, the
84
- branch will be FOO, but you should obviously change this:
85
-
86
- ```bash
87
- git fetch --all
88
- git checkout master
89
- git rebase upstream/master
90
- git checkout -b FOO
91
- ```
92
-
93
- Now, make your changes, commit as necessary with useful commit messages.
94
-
95
- Please note that changes to [lib/recog/version.rb](https://github.com/rapid7/recog/blob/master/lib/recog/version.rb) in PRs are almost never necessary.
96
-
97
- Now push your changes to your fork:
98
-
99
- ```bash
100
- git push origin FOO
101
- ```
102
-
103
- Finally, submit the PR. Navigate to ```https://github.com/<your-github-username>/recog/compare/FOO```, fill in the details and submit.
104
-
105
- [^back to top](#contributing-to-recog)
106
-
107
- ### Testing
108
-
109
- When your PR is submitted, it will be automatically subjected to the full run of tests in [Travis](https://travis-ci.org/rapid7/recog/), however you are encourage to perform testing _before_ submitting the PR. To do this, simply run `rake tests`.
110
-
111
- [^back to top](#contributing-to-recog)
112
-
113
- ## Fingerprints
114
-
115
- ### Best Practices
116
-
117
- * Create a single fingerprint for each product as long as the pattern remains clear and readable. If that is not possible, the pattern should be logically decomposed into additional fingerprints.
118
-
119
- * Create regular expressions that allow for flexible version number matching. This ensures greater probability of matching a product. For example, all known public releases of a product report either `major.minor` or `major.minor.build` format version numbers. If the fingerprint strictly matches this version number format, it would fail to match a modified build of the product that reports only a `major` version number format.
120
-
121
- [^back to top](#contributing-to-recog)
122
-
123
- ### Fingerprint Testing
124
-
125
- Once a fingerprint has been added, the `example` entries can be tested by executing `bin/recog_verify` against the fingerprint file:
126
-
127
- ```shell
128
- bin/recog_verify xml/ssh_banners.xml
129
- ```
130
-
131
- Matches can be tested on the command-line in a similar fashion:
132
-
133
- ```shell
134
- $ echo 'OpenSSH_6.6p1 Ubuntu-2ubuntu1' | bin/recog_match xml/ssh_banners.xml -
135
- MATCH: {"matched"=>"OpenSSH running on Ubuntu 14.04", "service.version"=>"6.6p1", "openssh.comment"=>"Ubuntu-2ubuntu1", "service.vendor"=>"OpenBSD", "service.family"=>"OpenSSH", "service.product"=>"OpenSSH", "os.vendor"=>"Ubuntu", "os.device"=>"General", "os.family"=>"Linux", "os.product"=>"Linux", "os.version"=>"14.04", "service.protocol"=>"ssh", "fingerprint_db"=>"ssh.banner", "data"=>"OpenSSH_6.6p1 Ubuntu-2ubuntu1"}
136
- ```
137
-
138
- [^back to top](#contributing-to-recog)
139
-
140
-
141
- ### Standardizing Vendors, Products, and Services
142
-
143
- Given the number of fingerprints in Recog, it can be common for specific products, vendors, or services to be identified with different spellings and casing.
144
- To limit the creep of slightly-different-names, the `bin/recog_standardize` script can be used to extract all identifiers and merge them into the known lists.
145
-
146
- To get started, run the `recog_standardize` tool:
147
- ```shell
148
- ruby bin/recog_standardize
149
- ```
150
-
151
- Review any new additions to the text files under `identifiers/`. If any of these names are close to an existing name, update the offending fingerprint to use
152
- the existing name instead. Once the fingerprints are fixed, removed the "extra" names from the identifiers files, and run the tool again.
153
-
154
-
155
- [^back to top](#contributing-to-recog)
156
-
157
-
158
- ### Updating CPEs
159
-
160
- There exists some automation to update the CPEs that might be asserted with
161
- some recog fingerprints. This should be run periodically to ensure that all
162
- fingerprints that could have CPEs do, etc.
163
-
164
- First, setup a python3 venv:
165
-
166
- ```bash
167
- python3 -m venv venv
168
- source venv/{bin,Scripts}/activate
169
- pip install -r requirements.txt
170
- ```
171
-
172
- Download the latest CPE 2.3 dictionary:
173
-
174
- ```bash
175
- curl -o official-cpe-dictionary_v2.3.xml.gz https://nvd.nist.gov/feeds/xml/cpe/dictionary/official-cpe-dictionary_v2.3.xml.gz && \
176
- gunzip official-cpe-dictionary_v2.3.xml.gz
177
- ```
178
-
179
- Run the CPE automation against every XML file:
180
-
181
- ```bash
182
- # Update the CPEs (sequentially)
183
- ls xml/*.xml | xargs -i python update_cpes.py {} official-cpe-dictionary_v2.3.xml cpe-remap.yaml 2>>errors.txt
184
- ```
185
-
186
- You may want to use GNU `parallel` to speed things up:
187
- ```bash
188
- # Update the CPEs (with GNU Parallel)
189
- ls xml/*.xml | parallel --gnu "python update_cpes.py {} official-cpe-dictionary_v2.3.xml cpe-remap.yaml" 2>>errors.txt
190
- ```
191
-
192
- Clean up the whitespace across all fingerprints:
193
- ```bash
194
- ruby bin/recog_cleanup
195
- ```
196
-
197
- Any mismatched fingerprints will be listed in `errors.txt` for eventual
198
- maintenance. The `cpe-remap.yaml` file can be used to map between
199
- vendor/product/etc differences between Recog and CPE, or to work around bugs in
200
- either.
201
-
202
- [^back to top](#contributing-to-recog)
203
-
204
- ## Project Operations
205
-
206
- ### Landing PRs
207
-
208
- (Note: this portion is a work-in-progress. Please update it as things change)
209
-
210
- Much like with the process of submitting PRs, Recog's process for landing PRs
211
- is very similar to [Metasploit's process for landing
212
- PRs](https://github.com/rapid7/metasploit-framework/wiki/Landing-Pull-Requests).
213
- In short:
214
-
215
- 1. Follow the "Fork and Clone" steps from above
216
- 2. Update your `.git/config` to ensure that the `remote ["upstream"]` section is configured to pull both branches and PRs from upstream. It should look something like the following, in particular the second `fetch` option:
217
-
218
- ```bash
219
- [remote "upstream"]
220
- url = git@github.com:rapid7/recog.git
221
- fetch = +refs/heads/*:refs/remotes/upstream/*
222
- fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*
223
- ```
224
-
225
- 3. Fetch the latest revisions, including PRs:
226
-
227
- ```bash
228
- git fetch --all
229
- ```
230
-
231
- 4. Checkout and branch the PR for testing. Replace ```PR``` below with the actual PR # in question:
232
-
233
- ```bash
234
- git checkout -b landing-PR upstream/pr/PR
235
- ```
236
-
237
- 5. Test the PR (see the Testing section above)
238
- 6. Merge with master, re-test, validate and push:
239
-
240
- ```bash
241
- git checkout -b upstream-master --track upstream/master
242
- git merge -S --no-ff --edit landing-PR # merge the PR into upstream-master
243
-
244
- # re-test if/as necessary
245
- git push upstream upstream-master:master --dry-run # confirm you are pushing what you expect
246
-
247
- git push upstream upstream-master:master # push upstream-master to upstream:master
248
- ```
249
-
250
- 7. If applicable, release a new version (see next section)
251
-
252
- [^back to top](#contributing-to-recog)
253
-
254
- ### Releasing New Versions
255
-
256
- When Recog's critical parts are modified, for example its fingerprints or underlying supporting code, a new version _must_ eventually be released. These new releases can then be optionally included in projects such as Metasploit or products such as Rapid7's Nexpose in a controlled manner. Releases for non-functional updates such as updates to documentation are not necessary.
257
-
258
- When a new version of Recog is to be released, you _must_ follow the instructions below.
259
-
260
- 1. If are not already a Recog project contributor for the Recog gem (you'd be listed [here under OWNERS](https://rubygems.org/gems/recog)), become one:
261
- 1. Get an account on [Rubygems](https://rubygems.org)
262
- 1. Contact one of the Recog project contributors (listed [here under OWNERS](https://rubygems.org/gems/recog) and have them add you to the Recog gem. They'll need to run: `gem owner recog -a EMAIL`
263
-
264
- 1. Edit [lib/recog/version.rb](https://github.com/rapid7/recog/blob/master/lib/recog/version.rb) and increment `VERSION`. Commit and push to rapid7/recog master.
265
-
266
- 1. Run `rake release`. Among other things, this creates the new gem, uploads it to Rubygems and tags the release with a tag like `v<VERSION>`, where `<VERSION>` is replaced with the version from `version.rb`. For example, if you release version 1.2.3 of the gem, the tag will be `v1.2.3`.
267
-
268
- 1. If your default remote repository is not `rapid7/recog`, you must ensure that the tags created in the previous step are also pushed to the right location(s). For example, if `origin` is your fork of recog and `upstream` is `rapid7/master`, you should run `git push --tags --dry-run upstream` to confirm what tags will be pushed and then `git push --tags upstream` to push the tags.
269
-
270
- [^back to top](#contributing-to-recog)
data/bin/recog_cleanup DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
4
- require 'optparse'
5
- require 'ostruct'
6
- require 'recog'
7
-
8
- # Cleanup trailing whitespace around fingerprints
9
- Dir[ File.expand_path(File.join(File.dirname(__FILE__), "..", "xml")) + "/*.xml" ].each do |f|
10
- data = File.read(f).
11
- gsub(/\s+$/, ''). # Trailing whitespace and empty lines
12
- gsub("</fingerprint>", "</fingerprint>\n"). # Every fingerprint should have an empty line after it
13
- gsub("-->", "-->\n") # Every comment should have an empty line after it
14
-
15
- File.write(f, data)
16
- end
data/bin/recog_export DELETED
@@ -1,81 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
4
- require 'optparse'
5
- require 'ostruct'
6
- require 'recog'
7
-
8
- def squash_lines(str)
9
- str.split(/\n/).join(' ').gsub(/\s+/, ' ')
10
- end
11
-
12
- def export_text(options)
13
- end
14
-
15
- def export_ruby(options)
16
- $stdout.puts "# Recog fingerprint database export [ #{File.basename(options.xml_file)} ] on #{Time.now.to_s}"
17
- $stdout.puts "fp_str = '' # Set this value to the match string"
18
- $stdout.puts "fp_match = {} # Match results are stored here"
19
- $stdout.puts ""
20
- $stdout.puts "case fp_str"
21
- options.db.fingerprints.each do |fp|
22
- puts " # #{squash_lines fp.name}"
23
- puts " when /#{fp.regex.to_s}/"
24
- fp.tests.each do |test|
25
- puts " # Example: #{squash_lines test}"
26
- end
27
- fp.params.each_pair do |k,v|
28
- if v[0] == 0
29
- puts " fp_match[#{k.inspect}] = #{v[1].inspect}"
30
- else
31
- puts " fp_match[#{k.inspect}] = $#{v[0].to_s}"
32
- end
33
- end
34
- puts ""
35
- end
36
- $stdout.puts "end"
37
- end
38
-
39
-
40
- options = OpenStruct.new(etype: :ruby)
41
-
42
- option_parser = OptionParser.new do |opts|
43
- opts.banner = "Usage: #{$0} [options] XML_FINGERPRINTS_FILE"
44
- opts.separator "Exports an XML fingerprint database to another format."
45
- opts.separator ""
46
- opts.separator "Options"
47
-
48
- opts.on("-t", "--type type",
49
- "Choose a type of export.",
50
- " [r]uby (default - export a ruby case statement with regular expressions)",
51
- " [t]ext (export a text description of the fingerprints)") do |etype|
52
- case etype.downcase
53
- when /^r/
54
- options.etype = :ruby
55
- when /^t/
56
- options.etype = :text
57
- end
58
- end
59
-
60
- opts.on("-h", "--help", "Show this message.") do
61
- puts opts
62
- exit
63
- end
64
- end
65
- option_parser.parse!(ARGV)
66
-
67
- if ARGV.count != 1
68
- puts option_parser
69
- exit
70
- end
71
-
72
- options.xml_file = ARGV.shift
73
- options.db = Recog::DB.new(options.xml_file)
74
-
75
- case options.etype
76
- when :ruby
77
- export_ruby(options)
78
- when :text
79
- export_text(options)
80
- end
81
-
@@ -1,148 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
4
- require 'optparse'
5
- require 'ostruct'
6
- require 'recog'
7
-
8
- def load_identifiers(path)
9
- res = {}
10
- File.readlines(path).map{|line| line.strip}.each do |ident|
11
- res[ident] = true
12
- end
13
- return res
14
- end
15
-
16
- def write_identifiers(vals, path)
17
- res = []
18
- vals.each_pair do |k,v|
19
- res = res.push(k)
20
- end
21
- res = res.map{|x| x.strip}.select{|x| x.length > 0}.sort.uniq
22
- File.write(path, res.join("\n") + "\n")
23
- end
24
-
25
- bdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "identifiers"))
26
-
27
- options = OpenStruct.new(write: false)
28
- option_parser = OptionParser.new do |opts|
29
- opts.banner = "Usage: #{$0} [options] XML_FINGERPRINT_FILE1 ..."
30
- opts.separator "Verifies that each fingerprint asserts known identifiers."
31
- opts.separator ""
32
- opts.separator "Options"
33
-
34
- opts.on("-w", "--write") do
35
- options.write = true
36
- end
37
-
38
- opts.on("-h", "--help", "Show this message.") do
39
- puts opts
40
- exit
41
- end
42
- end
43
- option_parser.parse!(ARGV)
44
-
45
- if ARGV.empty?
46
- $stderr.puts 'Missing XML fingerprint files'
47
- puts option_parser
48
- exit(1)
49
- end
50
-
51
- # Load the unique identifiers
52
- vendors = load_identifiers(File.join(bdir, "vendor.txt"))
53
- fields = load_identifiers(File.join(bdir, "fields.txt"))
54
- os_arch = load_identifiers(File.join(bdir, "os_architecture.txt"))
55
- os_prod = load_identifiers(File.join(bdir, "os_product.txt"))
56
- os_family = load_identifiers(File.join(bdir, "os_family.txt"))
57
- os_device = load_identifiers(File.join(bdir, "os_device.txt"))
58
- hw_prod = load_identifiers(File.join(bdir, "hw_product.txt"))
59
- hw_family = load_identifiers(File.join(bdir, "hw_family.txt"))
60
- hw_device = load_identifiers(File.join(bdir, "hw_device.txt"))
61
- svc_prod = load_identifiers(File.join(bdir, "service_product.txt"))
62
- svc_family = load_identifiers(File.join(bdir, "service_family.txt"))
63
-
64
-
65
- ARGV.each do |arg|
66
- Dir.glob(arg).each do |file|
67
- ndb = Recog::DB.new(file)
68
- ndb.fingerprints.each do |f|
69
- f.params.each do |k,v|
70
- paramIndex, val = v
71
- if ! fields[k]
72
- puts "FIELD MISSING: #{k}"
73
- fields[k] = true
74
- end
75
- next if paramIndex != 0
76
- next if val.index("{") != nil
77
- next if val.strip == ""
78
- case k
79
- when "os.vendor", "service.vendor", "service.component.vendor", "hw.vendor"
80
- if ! vendors[val]
81
- puts "VENDOR MISSING: #{val}"
82
- vendors[val] = true
83
- end
84
- when "os.arch"
85
- if ! os_arch[val]
86
- puts "OS ARCH MISSING: #{val}"
87
- os_arch[val] = true
88
- end
89
- when "os.product"
90
- if ! os_prod[val]
91
- puts "OS PRODUCT MISSING: #{val}"
92
- os_prod[val] = true
93
- end
94
- when "os.family"
95
- if ! os_family[val]
96
- puts "OS FAMILY MISSING: #{val}"
97
- os_family[val] = true
98
- end
99
- when "os.device"
100
- if ! os_device[val]
101
- puts "OS DEVICE MISSING: #{val}"
102
- os_device[val] = true
103
- end
104
- when "hw.product"
105
- if ! hw_prod[val]
106
- puts "HW PRODUCT MISSING: #{val}"
107
- hw_prod[val] = true
108
- end
109
- when "hw.family"
110
- if ! hw_family[val]
111
- puts "HW FAMILY MISSING: #{val}"
112
- hw_family[val] = true
113
- end
114
- when "hw.device"
115
- if ! hw_device[val]
116
- puts "HW DEVICE MISSING: #{val}"
117
- hw_device[val] = true
118
- end
119
- when "service.product", "service.component.product"
120
- if ! svc_prod[val]
121
- puts "SERVICE PRODUCT MISSING: #{val}"
122
- svc_prod[val] = true
123
- end
124
- when "service.family"
125
- if ! svc_family[val]
126
- puts "SERVICE FAMILY MISSING: #{val}"
127
- svc_family[val] = true
128
- end
129
- end
130
- end
131
- end
132
- end
133
- end
134
-
135
- exit if ! options.write
136
-
137
- # Write back the unique identifiers
138
- write_identifiers(vendors, File.join(bdir, "vendor.txt"))
139
- write_identifiers(fields, File.join(bdir, "fields.txt"))
140
- write_identifiers(os_arch, File.join(bdir, "os_architecture.txt"))
141
- write_identifiers(os_prod, File.join(bdir, "os_product.txt"))
142
- write_identifiers(os_family, File.join(bdir, "os_family.txt"))
143
- write_identifiers(os_device, File.join(bdir, "os_device.txt"))
144
- write_identifiers(hw_prod, File.join(bdir, "hw_product.txt"))
145
- write_identifiers(hw_family, File.join(bdir, "hw_family.txt"))
146
- write_identifiers(hw_device, File.join(bdir, "hw_device.txt"))
147
- write_identifiers(svc_prod, File.join(bdir, "service_product.txt"))
148
- write_identifiers(svc_family, File.join(bdir, "service_family.txt"))
data/bin/recog_verify DELETED
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
4
- require 'optparse'
5
- require 'ostruct'
6
- require 'recog'
7
- require 'recog/verifier_factory'
8
-
9
- options = OpenStruct.new(color: false, detail: false, quiet: false, warnings: true)
10
-
11
- option_parser = OptionParser.new do |opts|
12
- opts.banner = "Usage: #{$0} [options] XML_FINGERPRINT_FILE1 ..."
13
- opts.separator "Verifies that each fingerprint passes its internal tests."
14
- opts.separator ""
15
- opts.separator "Options"
16
-
17
- opts.on("-f", "--format FORMATTER",
18
- "Choose a formatter.",
19
- " [s]ummary (default - failure/warning msgs and summary)",
20
- " [q]uiet (configured failure/warning msgs only)",
21
- " [d]etail (fingerprint name with tests and expanded summary)") do |format|
22
- if format.start_with? 'd'
23
- options.detail = true
24
- end
25
- if format.start_with? 'q'
26
- options.quiet = true
27
- end
28
- end
29
-
30
- opts.on("-c", "--color", "Enable color in the output.") do
31
- options.color = true
32
- end
33
-
34
- opts.on("--[no-]warnings", "Track warnings") do |o|
35
- options.warnings = o
36
- end
37
-
38
- opts.on("-h", "--help", "Show this message.") do
39
- puts opts
40
- exit
41
- end
42
- end
43
- option_parser.parse!(ARGV)
44
-
45
- if ARGV.empty?
46
- $stderr.puts 'Missing XML fingerprint files'
47
- puts option_parser
48
- exit(1)
49
- end
50
-
51
- warnings = 0
52
- failures = 0
53
- ARGV.each do |arg|
54
- Dir.glob(arg).each do |file|
55
- ndb = Recog::DB.new(file)
56
- options.fingerprints = ndb.fingerprints
57
- verifier = Recog::VerifierFactory.build(options)
58
- verified = verifier.verify
59
- failures += verifier.reporter.failure_count
60
- warnings += verifier.reporter.warning_count
61
- end
62
- end
63
-
64
- exit failures + warnings