Recog 是一个通过将指纹与各种网络探测返回的数据进行匹配来识别产品、服务、操作系统和硬件的框架。Recog 让从 Web 服务器横幅、snmp 系统描述字段以及更多数据中提取有用信息变得简单。
Recog 是开源的,更多信息请参阅 LICENSE 文件。
2022 年 3 月 31 日,Recog 内容——XML 指纹文件和实用工具——已从 Recog 框架库实现中拆分出来。原 Recog 仓库现在包含 Recog 内容,Recog-Ruby 仓库包含 Ruby 语言实现。Recog 内容作为 git 子模块包含在 Recog-Ruby 中,并嵌套在 recog 目录下。拆分后的所有版本号大于或等于 3.0.0 的 Recog gem 将:1. 在 recog 目录下包含 XML 指纹目录,并且 2. 只包含 recog_match 工具,因为其他工具专注于指纹管理。
与仓库拆分同步,默认分支已从 master 重命名为 main。在这些更改之前创建的任何克隆都必须在你的本地环境中手动更新。如果你有 fork,请导航到你的 fork 的设置,并按照重命名分支中的说明将默认分支更改为 main。
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
(可选)运行以下命令以删除对旧分支名的跟踪引用。
# dry-run to confirm stale references that will be deleted before proceeding
git remote prune origin --dry-run
git remote prune origin
如果你之前使用的是上游跟踪分支 upstream-master,请运行以下命令以删除旧分支并创建新的上游跟踪分支。
git branch -d upstream-master
git checkout -b upstream-main --track upstream/main
(可选)运行以下命令以删除对旧上游分支名的跟踪引用。
# dry-run to confirm stale references that will be deleted before proceeding
git remote prune upstream --dry-run
git remote prune upstream
Recog 由 XML 指纹文件和一组代码(主要使用 Ruby 编写)组成,这些代码使开发、测试和使用所包含的指纹变得容易。为了使用附带的 Ruby 代码,需要较新版本的 Ruby(2.31+),以及 Rubygems 和 bundler gem。一旦这些依赖就绪,请使用以下命令获取最新源代码并安装任何其他依赖。
$ git clone [email protected]:rapid7/recog.git
$ cd recog
$ bundle install
请注意,虽然 XML 指纹本身相当稳定且经过充分测试,但 Ruby 代码库仍然比较新,并且可能快速变化。在任何生产项目中使用 Recog 代码之前,请先联系我们(research[at]rapid7.com)。
Recog 中的指纹存储在 XML 文件中,每个文件都旨在匹配特定的协议响应字符串或字段。例如,文件 ssh_banners.xml 可以通过匹配初始 SSH 守护进程横幅字符串来确定操作系统、供应商,有时还有硬件产品。
一个指纹文件由如下所示的 XML 文档组成:
<fingerprints matches="ssh.banner">
<fingerprint pattern="^RomSShell_([\d\.]+)$">
<description>Allegro RomSShell SSH</description>
<example service.version="4.62">RomSShell_4.62</example>
<param pos="0" name="service.vendor" value="Allegro"/>
<param pos="0" name="service.product" value="RomSShell"/>
<param pos="1" name="service.version"/>
</fingerprint>
</fingerprints>
第一行应始终是 XML 版本声明。第一个元素应始终是一个 fingerprints 块,并带有 matches 属性,指示此指纹文件应该匹配的数据。matches 属性通常采用 protocol.field 的形式。
在 fingerprints 元素内部,应有一个或多个 fingerprint 元素。每个 fingerprint 都必须包含一个 pattern 属性,该属性包含用于匹配数据的正则表达式。可以指定可选的 flags 属性,以控制正则表达式的解释方式。更多信息请参阅 Recog 的 FLAG_MAP 文档。
在指纹内部,description 元素应包含一个人类可读的字符串,用于描述该指纹。
至少应存在一个 example 元素,但最好使用多个 example 元素。这些元素用作 rspec 中测试覆盖的一部分,用于验证提供的数据与指定的正则表达式匹配。此外,如果指纹使用 param 元素从数据中提取字段值(将在下面描述),则可以将这些预期提取结果添加为 example 元素的属性。在上面的示例中,这个:
<example service.version="4.62">RomSShell_4.62</example>
用于测试 RomSShell_4.62 是否与提供的正则表达式匹配,以及 service.version 的值是否为 4.62。
example 字符串可以进行 base64 编码,以允许使用不可打印字符。为了向 Recog 发出此信号,需要向 example 元素添加一个值为 base64 的 _encoding 属性。超过 80 个字符的 Base64 编码文本可以像下面这样用换行符换行,以提高可读性。
<example _encoding="base64">
dGllczGEAAAAlQQWMS4yLjg0MC4xMTM1NTYuMS40LjgwMAQuZGF0YS5yZW1vdmVkLjCEAAAAK
AQdZG9tYWluQ29udHJvbGxlckZ1bmN0aW9uYWxpdHkxhAAAAAMEATc=
</example>
此外,示例可以放置在与 XML 文件位于同一目录下的、与 XML 文件同名的目录中:
xml/services.xml
xml/services/file1
xml/services/file2
...
然后可以使用 _filename 属性加载它们:
<example _filename="file1"/>
这对于长示例很有用。
param 元素包含一个 pos 属性,该属性指示应从 pattern 中提取哪个捕获字段;对于静态字符串,则为 0。name 属性是成功匹配时报告的键;value 在 pos 值为 0 时是静态字符串,否则被省略并从捕获的字段中获取。
value 属性支持来自其他字段的数据插值。这在通过正则表达式捕获 hw.product 的值并在 os.product 中重用它时通常很有用。
以下是来自 http_servers.xml 的示例,其中 hw.product 被捕获并重用。
<fingerprint pattern="^Eltex (TAU-\d+[A-Z]*(?:\.IP)?)$">
<description>Eltex TAU model VoIP gateway</description>
<example hw.product="TAU-72">Eltex TAU-72</example>
<example hw.product="TAU-1.IP">Eltex TAU-1.IP</example>
<param pos="0" name="os.vendor" value="Eltex"/>
<param pos="0" name="os.product" value="{hw.product} Firmware"/>
<param pos="0" name="os.device" value="VoIP Gateway"/>
<param pos="0" name="hw.vendor" value="Eltex"/>
<param pos="1" name="hw.product"/>
<param pos="0" name="hw.device" value="VoIP Gateway"/>
</fingerprint>
对于名称以 _tmp. 开头的临时属性,有特殊的处理。这些属性可用于插值,但不会在输出中发出。当某个产品名称在各种横幅、供应商营销中不一致,或者在尝试生成 CPE 时与 NIST 值不一致,此功能很有用。在这些情况下,可以提取横幅中有用的部分,并构造一个新值,而不会使匹配所发出的数据变得混乱。
<fingerprint pattern="^foo baz switchThing-(\d{4})$">
<description>NetCorp NX series switches</description>
<example hw.product="NX8200">foo baz switchThing-8200</example>
<param pos="0" name="hw.vendor" value="NetCorp"/>
<param pos="0" name="hw.product" value="NX{_tmp.001}"/>
<param pos="2" name="_tmp.001"/>
</fingerprint>
这些临时属性不会在 identifiers/fields.txt 中被跟踪。
以下示例使用 bin/recog_match,这是一个简单的 Ruby 命令行工具,使用 Recog 的指纹数据。在运行 Recog 之前通常需要进行预处理,例如提取 HTTP 标头值等。所有指纹数据都可以在 xml/*.xml 中找到。
根据连接后服务器的横幅响应来对 FTP 服务器进行指纹识别:
# Example plaintext input
echo -n '220 Microsoft FTP Service' | bin/recog_match xml/ftp_banners.xml -
# Example command using nmap
nmap -sV -script=banner -p 21 192.168.123.13 | grep --color=never '_banner' | cut -d: -f2- | bin/recog_match xml/ftp_banners.xml -
# Example output
MATCH: {"matched"=>"Microsoft FTP Server on Windows XP, 2003 or later without version", "service.vendor"=>"Microsoft", "service.product"=>"IIS", "service.family"=>"IIS", "service.cpe23"=>"cpe:/a:microsoft:iis:-", "os.vendor"=>"Microsoft", "os.family"=>"Windows", "os.product"=>"Windows", "os.cpe23"=>"cpe:/o:microsoft:windows:-", "host.name"=>"220", "service.protocol"=>"ftp", "fingerprint_db"=>"ftp.banner", "data"=>"220 Microsoft FTP Service"}
使用 HTTP Set-Cookie 标头值对 HTTP 服务器进行指纹识别:
# Example plaintext input
echo 'laravel_session=eyJ...etc..etc...%3D; expires=Mon, 13-Mar-2023 16:48:58 GMT; Max-Age=7200; path=/; httponly; samesite=lax' | bin/recog_match xml/http_cookies.xml -
# Example cURL command
curl --silent -I http://localhost:9001 | grep --color=never -i '^Set-Cookie:' | cut -d: -f2- | bin/recog_match xml/http_cookies.xml -
# Example output
MATCH: {"matched"=>"Laravel PHP web application framework", "service.vendor"=>"Laravel", "service.product"=>"Laravel", "service.cpe23"=>"cpe:/a:laravel:laravel:-", "service.protocol"=>"http", "fingerprint_db"=>"http_header.cookie", "data"=>"laravel_session=eyJ...etc..etc...%3D; expires=Mon, 13-Mar-2023 16:48:58 GMT; Max-Age=7200; path=/; httponly; samesite=lax"}
使用 HTTP Server 标头值对 HTTP 服务器进行指纹识别:
# Example plaintext input
echo -n 'Apache/2.4.38 (Debian)' | bin/recog_match xml/http_servers.xml -
# Example cURL command
curl --silent -I http://localhost:9001 | grep --color=never -i '^Server:' | cut -d: -f2- | bin/recog_match xml/http_servers.xml -
# Example output
MATCH: {"matched"=>"Apache", "service.vendor"=>"Apache", "service.product"=>"HTTPD", "service.family"=>"Apache", "service.version"=>"2.4.38", "service.cpe23"=>"cpe:/a:apache:http_server:2.4.38", "apache.info"=>"(Debian)", "service.protocol"=>"http", "fingerprint_db"=>"http_header.server", "data"=>"Apache/2.4.38 (Debian)"}
使用 favicon 的 md5sum 来识别正在运行的服务:
# Example plaintext input
echo -n fe22dd2bb09daccf58256611ac491469 | bin/recog_match xml/favicons.xml -
# Example cURL command
curl --silent http://localhost:8000/favicon.ico | md5sum | awk '{ print $1 }' | bin/recog_match xml/favicons.xml -
# Example output
MATCH: {"matched"=>"Drupal CMS", "service.vendor"=>"Drupal", "service.product"=>"CMS", "service.certainty"=>"0.5", "service.cpe23"=>"cpe:/a:drupal:drupal:-", "service.protocol"=>"", "fingerprint_db"=>"favicon.md5", "data"=>"fe22dd2bb09daccf58256611ac491469"}
使用 HTTP WWW-Authenticate 标头值对 HTTP 服务器进行指纹识别:
# Example plaintext input
echo -n 'Basic realm="monit"' | bin/recog_match xml/http_wwwauth.xml -
# Example cURL command
curl --silent -I http://localhost:9001 | grep --color=never -i '^WWW-Authenticate:' | cut -d: -f2- | bin/recog_match xml/http_wwwauth.xml -
# Example output
MATCH: {"matched"=>"Minot", "service.vendor"=>"Tildeslash", "service.product"=>"Monit", "service.cpe23"=>"cpe:/a:tildeslash:monit:-", "service.protocol"=>"http", "fingerprint_db"=>"http_header.wwwauth", "data"=>"Basic realm=\"monit\""}
根据服务器对 10 个 TLS Client Hello 数据包的响应来对 TLS 服务器进行指纹识别。指纹识别基于 https://github.com/salesforce/jarm
# Example plaintext input
echo -n 07d14d16d21d21d07c42d43d000000f50d155305214cf247147c43c0f1a823 | bin/recog_match xml/jarm.xml -
# Example command using Salesforce's JARM against a running Metasploit listener
python3 $code/jarm/jarm.py -p 8443 192.168.123.1 | grep --color=never 'JARM: ' | awk -F: '{ print $2 }' | bin/recog_match xml/tls_jarm.xml -
# Example output
MATCH: {"matched"=>"Metasploit listener", "service.vendor"=>"Rapid7", "service.product"=>"Metasploit", "service.cpe23"=>"cpe:/a:rapid7:metasploit:-", "service.protocol"=>"tls", "fingerprint_db"=>"tls.jarm", "data"=>"07d14d16d21d21d07c42d43d000000f50d155305214cf247147c43c0f1a823"}
Recog 的用户和维护者非常感谢您能对项目做出的任何贡献。有关指南和说明,请参阅 CONTRIBUTING.MD
| 功能 ✨ | rapid7/recog-ruby | rapid7/recog-java | runZeroInc/recog-go |
|---|
| 指纹验证 CLI 工具 | ✅ | ✅ | ✅ |
| 指纹匹配 CLI 工具 | ✅ | ✅ | |
| 支持 base64 编码的示例 | ✅ | ✅ | ✅ |
| 支持基于文件系统的外部示例 | ✅ | ✅ | ✅ |
| 指纹匹配 CPE 参数插值 | ✅ | ✅ | ✅ |