recog 2.3.5 → 2.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -5
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +7 -4
  6. data/CONTRIBUTING.md +136 -37
  7. data/Gemfile +2 -5
  8. data/README.md +34 -29
  9. data/bin/recog_cleanup +16 -0
  10. data/bin/recog_standardize +142 -0
  11. data/cpe-remap.yaml +21 -0
  12. data/features/data/successful_tests.xml +1 -1
  13. data/features/data/tests_with_warnings.xml +1 -1
  14. data/features/match.feature +4 -0
  15. data/features/support/aruba.rb +3 -0
  16. data/features/verify.feature +8 -4
  17. data/identifiers/README.md +56 -0
  18. data/identifiers/hw_device.txt +77 -0
  19. data/identifiers/hw_family.txt +96 -0
  20. data/identifiers/hw_product.txt +328 -0
  21. data/identifiers/os_architecture.txt +20 -0
  22. data/identifiers/os_device.txt +94 -0
  23. data/identifiers/os_family.txt +325 -0
  24. data/identifiers/os_product.txt +420 -0
  25. data/identifiers/service_family.txt +272 -0
  26. data/identifiers/service_product.txt +556 -0
  27. data/identifiers/software_class.txt +26 -0
  28. data/identifiers/software_family.txt +91 -0
  29. data/identifiers/software_product.txt +333 -0
  30. data/identifiers/vendor.txt +890 -0
  31. data/lib/recog/fingerprint.rb +46 -0
  32. data/lib/recog/version.rb +1 -1
  33. data/requirements.txt +1 -1
  34. data/spec/data/verification_fingerprints.xml +86 -0
  35. data/spec/lib/fingerprint_self_test_spec.rb +1 -1
  36. data/spec/lib/recog/fingerprint/regexp_factory_spec.rb +1 -1
  37. data/spec/lib/recog/fingerprint_spec.rb +89 -0
  38. data/update_cpes.py +1 -1
  39. data/xml/apache_modules.xml +292 -5
  40. data/xml/apache_os.xml +50 -2
  41. data/xml/architecture.xml +19 -7
  42. data/xml/dns_versionbind.xml +113 -11
  43. data/xml/favicons.xml +1700 -0
  44. data/xml/ftp_banners.xml +287 -15
  45. data/xml/h323_callresp.xml +112 -12
  46. data/xml/hp_pjl_id.xml +47 -5
  47. data/xml/html_title.xml +2371 -17
  48. data/xml/http_cookies.xml +82 -7
  49. data/xml/http_servers.xml +839 -41
  50. data/xml/http_wwwauth.xml +154 -27
  51. data/xml/imap_banners.xml +19 -13
  52. data/xml/ldap_searchresult.xml +81 -9
  53. data/xml/mdns_device-info_txt.xml +194 -17
  54. data/xml/mdns_workstation_txt.xml +4 -2
  55. data/xml/mysql_banners.xml +554 -45
  56. data/xml/mysql_error.xml +113 -6
  57. data/xml/nntp_banners.xml +10 -2
  58. data/xml/ntp_banners.xml +95 -11
  59. data/xml/operating_system.xml +90 -3
  60. data/xml/pop_banners.xml +30 -31
  61. data/xml/rsh_resp.xml +11 -2
  62. data/xml/rtsp_servers.xml +96 -0
  63. data/xml/sip_banners.xml +192 -17
  64. data/xml/sip_user_agents.xml +69 -3
  65. data/xml/smb_native_lm.xml +10 -2
  66. data/xml/smb_native_os.xml +80 -2
  67. data/xml/smtp_banners.xml +166 -9
  68. data/xml/smtp_debug.xml +6 -4
  69. data/xml/smtp_ehlo.xml +7 -5
  70. data/xml/smtp_expn.xml +13 -4
  71. data/xml/smtp_help.xml +23 -4
  72. data/xml/smtp_mailfrom.xml +5 -2
  73. data/xml/smtp_noop.xml +6 -5
  74. data/xml/smtp_quit.xml +5 -4
  75. data/xml/smtp_rcptto.xml +5 -2
  76. data/xml/smtp_rset.xml +4 -4
  77. data/xml/smtp_turn.xml +4 -4
  78. data/xml/smtp_vrfy.xml +14 -4
  79. data/xml/snmp_sysdescr.xml +862 -122
  80. data/xml/snmp_sysobjid.xml +47 -2
  81. data/xml/ssh_banners.xml +1153 -192
  82. data/xml/telnet_banners.xml +419 -14
  83. data/xml/x11_banners.xml +27 -4
  84. data/xml/x509_issuers.xml +39 -15
  85. data/xml/x509_subjects.xml +545 -64
  86. metadata +32 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa45c67f4a225e53c7652e9175945a943b73245c9552e50dbe8ba0681ec07722
4
- data.tar.gz: 80c8391cdb963c981cd3ebd170f2899a756811dbe1f92e4ac9542e2ed941e9c1
3
+ metadata.gz: 882d241ba5d8115e818c1f3a9373171d502cc4cd1b0d9069a41bd9383aabf90a
4
+ data.tar.gz: d90114dc975f4ae473af3958ba30cfe1d14953299a9585726a6b1d834e6c2091
5
5
  SHA512:
6
- metadata.gz: cb5fbebf168eb99e8d83ceb5e3793e9a708f44a452478b23016aaeaed6da7b30e696a508f87052654a4dea7a90549e6b23c6b3b73343d3a98f7025cdc3b28c24
7
- data.tar.gz: a794f4f31c037afdbacf9bbbf0c137cc89e3ffa4a451d8ca75005b5f907d0ad282a98a8af0a73403be8ac574c1fd3054edf6f6a819655aac0b6728d7adb84a53
6
+ metadata.gz: c98f1e8fc087478c4ac5cc2a6512059976ff8bb99bd83c5f7098856888e31af4f9e8a3643a18a091fa4676df9da83314aee24ef01b0367a381ebee7077aa2fdd
7
+ data.tar.gz: 01034d8c3ca39855af88582e1027ce6f2bd2f60b312d06e9a11f81b8e3ed896801d0e40e09a18a37e57df1adb58dfb0125bcca74bea26443e9b068fd6b60f7d7
data/.gitignore CHANGED
@@ -1,11 +1,23 @@
1
+ # Ruby and tooling specific
1
2
  .yardoc
2
3
  coverage/
3
4
  doc/
4
5
  pkg/
5
- .idea/
6
- .vscode/
6
+
7
7
  /Gemfile.lock
8
8
 
9
- # ignore rvm files
10
- .ruby-version
11
- .ruby-gemset
9
+ #Python specific
10
+ venv
11
+
12
+ # IDE specific
13
+ .vscode/
14
+ .idea
15
+
16
+ # Misc
17
+ **/.DS_Store
18
+
19
+ # CPE XML
20
+ official-cpe-dictionary*.xml
21
+
22
+ # CPE Remap Errors
23
+ errors.txt
@@ -0,0 +1 @@
1
+ recog
@@ -0,0 +1 @@
1
+ 2.6.6
@@ -2,11 +2,14 @@ language: ruby
2
2
  sudo: false
3
3
  cache: bundler
4
4
  rvm:
5
- - '2.3.8'
6
- - '2.4.5'
7
- - '2.5.3'
8
- - '2.6.1'
5
+ - '2.5.8'
6
+ - '2.6.6'
9
7
  - 'jruby-9.1.9.0'
8
+ jdk:
9
+ - openjdk8
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: 'jruby-9.1.9.0'
10
13
  before_install:
11
14
  - "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
12
15
  - rake --version
@@ -3,9 +3,24 @@
3
3
  The users and maintainers of Recog would greatly appreciate any contributions
4
4
  you can make to the project. These contributions typically come in the form of
5
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) to be
6
+ in new versions of the [recog gem](https://rubygems.org/gems/recog) being
7
7
  released. The process for everything is described below.
8
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
+
9
24
  ## Contributing Issues / Bug Reports
10
25
 
11
26
  If you encounter any bugs or problems with Recog, please file them
@@ -14,6 +29,8 @@ possible. If the bug is straight-forward enough and you understand the fix for
14
29
  the bug well enough, you may take the simpler, less-paperwork route and simply
15
30
  fill a PR with the fix and the necessary details.
16
31
 
32
+ [^back to top](#contributing-to-recog)
33
+
17
34
  ## Contributing Code
18
35
 
19
36
  Recog uses a model nearly identical to that of
@@ -26,33 +43,39 @@ this document.
26
43
 
27
44
  On the other hand, if you haven't, read on!
28
45
 
46
+ [^back to top](#contributing-to-recog)
47
+
29
48
  ### Fork and Clone
30
49
 
31
50
  Generally, this should only need to be done once, or if you need to start over.
32
51
 
33
52
  1. Fork Recog: Visit https://github.com/rapid7/recog and click Fork,
34
53
  selecting your github account if prompted
35
- 2. Clone ```git@github.com:<your-github-username>/recog.git```, replacing
36
- ```<your-github-username>``` with, you guessed it, your Github username.
37
- 3. Add the master Recog repository as your upstream:
38
-
39
- ```
40
- git remote add upstream git://github.com/rapid7/recog.git
41
- ```
42
- 4. 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:
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:
43
57
 
58
+ ```bash
59
+ git remote add upstream git://github.com/rapid7/recog.git
44
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
45
65
  [remote "upstream"]
46
66
  url = git@github.com:rapid7/recog.git
47
67
  fetch = +refs/heads/*:refs/remotes/upstream/*
48
68
  fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*
49
69
  ```
50
- 5. Fetch the latest revisions, including PRs:
51
70
 
52
- ```
71
+ 1. Fetch the latest revisions, including PRs:
72
+
73
+ ```bash
53
74
  git fetch --all
54
75
  ```
55
76
 
77
+ [^back to top](#contributing-to-recog)
78
+
56
79
  ### Branch and Improve
57
80
 
58
81
  If you have a contribution to make, first create a branch to contain your
@@ -60,7 +83,7 @@ work. The name is yours to choose, however generally it should roughly
60
83
  describe what you are doing. In this example, and from here on out, the
61
84
  branch will be FOO, but you should obviously change this:
62
85
 
63
- ```
86
+ ```bash
64
87
  git fetch --all
65
88
  git checkout master
66
89
  git rebase upstream/master
@@ -73,17 +96,66 @@ Please note that changes to [lib/recog/version.rb](https://github.com/rapid7/rec
73
96
 
74
97
  Now push your changes to your fork:
75
98
 
76
- ```
99
+ ```bash
77
100
  git push origin FOO
78
101
  ```
79
102
 
80
103
  Finally, submit the PR. Navigate to ```https://github.com/<your-github-username>/recog/compare/FOO```, fill in the details and submit.
81
104
 
105
+ [^back to top](#contributing-to-recog)
106
+
82
107
  ### Testing
83
108
 
84
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`.
85
110
 
86
- ## Updating CPEs
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
87
159
 
88
160
  There exists some automation to update the CPEs that might be asserted with
89
161
  some recog fingerprints. This should be run periodically to ensure that all
@@ -91,30 +163,47 @@ fingerprints that could have CPEs do, etc.
91
163
 
92
164
  First, setup a python3 venv:
93
165
 
94
- ```
166
+ ```bash
95
167
  python3 -m venv venv
96
- source venv/bin/activate
168
+ source venv/{bin,Scripts}/activate
97
169
  pip install -r requirements.txt
98
170
  ```
99
171
 
100
172
  Download the latest CPE 2.3 dictionary:
101
173
 
102
- ```
103
- wget https://nvd.nist.gov/feeds/xml/cpe/dictionary/official-cpe-dictionary_v2.3.xml.gz
104
- ````
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
+ ```
105
178
 
106
- Run the CPE automation against every XML file, using GNU `parallel` to speed things up:
179
+ Run the CPE automation against every XML file:
107
180
 
108
- ```
109
- ls xml/*.xml | parallel --gnu "./update_cpes.py {} official-cpe-dictionary_v2.3.xml cpe-remap.yaml && xmllint --format --noblanks {} > {}.bak && mv {}.bak {} || echo {}" 2> errors.txt
110
- ```
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
+ ```
111
196
 
112
197
  Any mismatched fingerprints will be listed in `errors.txt` for eventual
113
198
  maintenance. The `cpe-remap.yaml` file can be used to map between
114
199
  vendor/product/etc differences between Recog and CPE, or to work around bugs in
115
200
  either.
116
201
 
117
- ## Landing PRs
202
+ [^back to top](#contributing-to-recog)
203
+
204
+ ## Project Operations
205
+
206
+ ### Landing PRs
118
207
 
119
208
  (Note: this portion is a work-in-progress. Please update it as things change)
120
209
 
@@ -126,46 +215,56 @@ In short:
126
215
  1. Follow the "Fork and Clone" steps from above
127
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:
128
217
 
129
- ```
218
+ ```bash
130
219
  [remote "upstream"]
131
220
  url = git@github.com:rapid7/recog.git
132
221
  fetch = +refs/heads/*:refs/remotes/upstream/*
133
222
  fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*
134
223
  ```
224
+
135
225
  3. Fetch the latest revisions, including PRs:
136
226
 
137
- ```
227
+ ```bash
138
228
  git fetch --all
139
229
  ```
230
+
140
231
  4. Checkout and branch the PR for testing. Replace ```PR``` below with the actual PR # in question:
141
232
 
142
- ```
233
+ ```bash
143
234
  git checkout -b landing-PR upstream/pr/PR
144
235
  ```
236
+
145
237
  5. Test the PR (see the Testing section above)
146
238
  6. Merge with master, re-test, validate and push:
147
239
 
148
- ```
240
+ ```bash
149
241
  git checkout -b upstream-master --track upstream/master
150
242
  git merge -S --no-ff --edit landing-PR # merge the PR into upstream-master
243
+
151
244
  # re-test if/as necessary
152
245
  git push upstream upstream-master:master --dry-run # confirm you are pushing what you expect
246
+
153
247
  git push upstream upstream-master:master # push upstream-master to upstream:master
154
248
  ```
249
+
155
250
  7. If applicable, release a new version (see next section)
156
251
 
157
- ## Releasing New Versions
252
+ [^back to top](#contributing-to-recog)
253
+
254
+ ### Releasing New Versions
158
255
 
159
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.
160
257
 
161
258
  When a new version of Recog is to be released, you _must_ follow the instructions below.
162
259
 
163
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:
164
- 1. Get an account on [Rubygems](https://rubygems.org)
165
- 2. 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:
166
- ```
167
- gem owner recog -a EMAIL
168
- ```
169
- 2. 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.
170
- 3. 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`.
171
- 4. 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.
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/Gemfile CHANGED
@@ -1,13 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec name: 'recog'
4
4
 
5
5
  gem 'nokogiri'
6
6
 
7
7
  group :test do
8
8
  gem 'rake'
9
- gem 'rspec', '>= 2.99'
10
- gem 'cucumber', '~> 1.3.8'
11
- gem 'aruba', '~> 0.5.3'
12
- gem 'regexp_parser', '~> 0.2.0'
9
+ gem 'regexp_parser'
13
10
  end
data/README.md CHANGED
@@ -1,30 +1,45 @@
1
- Recog: A Recognition Framework
2
- =====
3
-
4
- Recog is a framework for identifying products, services, operating systems, and hardware by matching fingerprints against data returned from various network probes. Recog makes it simple to extract useful information from web server banners, snmp system description fields, and a whole lot more. Recog is open source, please see the [LICENSE](https://raw.githubusercontent.com/rapid7/recog/master/LICENSE) file for more information.
1
+ # Recog: A Recognition Framework
5
2
 
6
3
  [![Gem Version](https://badge.fury.io/rb/recog.svg)](http://badge.fury.io/rb/recog)
7
4
  [![Build Status](https://travis-ci.org/rapid7/recog.svg?branch=master)](https://travis-ci.org/rapid7/recog)
8
5
 
6
+
7
+ Recog is a framework for identifying products, services, operating systems, and hardware by matching fingerprints against data returned from various network probes. Recog makes it simple to extract useful information from web server banners, snmp system description fields, and a whole lot more.
8
+
9
+ Recog is open source, please see the [LICENSE](https://raw.githubusercontent.com/rapid7/recog/master/LICENSE) file for more information.
10
+
11
+ ## Table of Contents
12
+
13
+ 1. [Installation](#installation)
14
+ 1. [Maturity](#maturity)
15
+ 1. [Fingerprints](#fingerprints)
16
+ 1. [Contributing](#contributing)
17
+
9
18
  ## Installation
10
19
 
11
- Recog consists of both XML fingerprint files and an assortment of code, mostly in Ruby, that makes it easy to develop, test, and use the contained fingerprints. In order to use the included ruby code, a recent version of Ruby (2.1+) is required, along with Rubygems and the `bundler` gem. Once these dependencies are in place, use the following commands to grab the latest source code and install any additional dependencies.
20
+ Recog consists of both XML fingerprint files and an assortment of code, mostly in Ruby, that makes it easy to develop, test, and use the contained fingerprints. In order to use the included ruby code, a recent version of Ruby (2.31+) is required, along with Rubygems and the `bundler` gem. Once these dependencies are in place, use the following commands to grab the latest source code and install any additional dependencies.
21
+
22
+ ```shell
23
+ $ git clone git@github.com:rapid7/recog.git
24
+ $ cd recog
25
+ $ bundle install
26
+ ```
12
27
 
13
- $ git clone git@github.com:rapid7/recog.git
14
- $ cd recog
15
- $ bundle install
28
+ [^back to top](#recog-a-recognition-framework)
16
29
 
17
30
  ## Maturity
18
31
 
19
32
  Please note that while the XML fingerprints themselves are quite stable and well-tested, the Ruby codebase in Recog is still fairly new and subject to change quickly. Please contact us (research[at]rapid7.com) before leveraging the Recog code within any production projects.
20
33
 
34
+ [^back to top](#recog-a-recognition-framework)
35
+
21
36
  ## Fingerprints
22
37
 
23
38
  The fingerprints within Recog are stored in XML files, each of which is designed to match a specific protocol response string or field. For example, the file [ssh_banners.xml](https://github.com/rapid7/recog/blob/master/xml/ssh_banners.xml) can determine the os, vendor, and sometimes hardware product by matching the initial SSH daemon banner string.
24
39
 
25
40
  A fingerprint file consists of an XML document like the following:
26
41
 
27
- ```
42
+ ```xml
28
43
  <fingerprints matches="ssh.banner">
29
44
  <fingerprint pattern="^RomSShell_([\d\.]+)$">
30
45
  <description>Allegro RomSShell SSH</description>
@@ -36,15 +51,15 @@ A fingerprint file consists of an XML document like the following:
36
51
  </fingerprints>
37
52
  ```
38
53
 
39
- The first line should always consist of the XML version declaration. The first element should always be a `fingerpints` block with a `matches` attribute indicating what data this fingerprint file is supposed to match. The `matches` attribute is normally in the form of `protocol.field`.
54
+ The first line should always consist of the XML version declaration. The first element should always be a `fingerprints` block with a `matches` attribute indicating what data this fingerprint file is supposed to match. The `matches` attribute is normally in the form of `protocol.field`.
40
55
 
41
56
  Inside of the `fingerprints` element there should be one or more `fingerprint` elements. Every `fingerprint` must contain a `pattern` attribute, which contains the regular expression to be used to match against the data. An optional `flags` attribute can be specified to control how the regular expression is to be interpreted. See [the Recog documentation for `FLAG_MAP`](http://www.rubydoc.info/gems/recog/Recog/Fingerprint/RegexpFactory#FLAG_MAP-constant) for more information.
42
57
 
43
58
  Inside of the fingerprint, a `description` element should contain a human-readable string describing this fingerprint.
44
59
 
45
- At least one `example` element should be present, however multiple `example` elements are preferred. These elements are used as part of the test coverage present in rspec which validates that the provided data matches the specified regular expression. Additionally, if the fingerprint is using the `param` elements to extract field values from the data (described next), you can add these expected extractions as attributes for the `example` elements. In the example above, this:
60
+ At least one `example` element should be present, however multiple `example` elements are preferred. These elements are used as part of the test coverage present in `rspec` which validates that the provided data matches the specified regular expression. Additionally, if the fingerprint is using the `param` elements to extract field values from the data (described next), you can add these expected extractions as attributes for the `example` elements. In the example above, this:
46
61
 
47
- ```
62
+ ```xml
48
63
  <example service.version="4.62">RomSShell_4.62</example>
49
64
  ```
50
65
 
@@ -54,29 +69,19 @@ The `param` elements contain a `pos` attribute, which indicates what capture fie
54
69
 
55
70
  The `example` string can be base64 encoded to permit the use of unprintable characters. To signal this to Recog an `_encoding` attribute with the value of `base64` is added to the `example` element. Based64 encoded text that is longer than 80 characters may be wrapped with newlines as shown below to aid in readability.
56
71
 
57
- ````
72
+ ````xml
58
73
  <example _encoding="base64">
59
74
  dGllczGEAAAAlQQWMS4yLjg0MC4xMTM1NTYuMS40LjgwMAQuZGF0YS5yZW1vdmVkLjCEAAAAK
60
75
  AQdZG9tYWluQ29udHJvbGxlckZ1bmN0aW9uYWxpdHkxhAAAAAMEATc=
61
76
  </example>
62
77
  ````
63
78
 
64
- ### Testing
65
-
66
- Once a fingerprint has been added, the `example` entries can be tested by executing `bin/recog_verify` against the fingerprint file:
79
+ [^back to top](#recog-a-recognition-framework)
67
80
 
68
- ```
69
- $ bin/recog_verify xml/ssh_banners.xml
70
- ```
71
-
72
- Matches can be tested on the command-line in a similar fashion:
73
-
74
- ```
75
- $ echo 'OpenSSH_6.6p1 Ubuntu-2ubuntu1' | bin/recog_match xml/ssh_banners.xml -
76
- 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"}
77
- ```
81
+ ## Contributing
78
82
 
79
- ### Best Practices
83
+ The users and maintainers of Recog would greatly appreciate any contributions
84
+ you can make to the project. For guidelines and instructions please see
85
+ [CONTRIBUTING.MD](CONTRIBUTING.md)
80
86
 
81
- * 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.
82
- * 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.
87
+ [^back to top](#recog-a-recognition-framework)