
ホスト、サービス、およびコンテンツのパターン認識
Recogは、さまざまなネットワークプローブから返されるデータに対してフィンガープリントをマッチングすることで、製品、サービス、オペレーティングシステム、ハードウェアを識別するためのフレームワークです。Recogを使用すると、Webサーバーのバナー、SNMPシステム記述フィールド、その他多数から有用な情報を簡単に抽出できます。
Recogはオープンソースです。詳細については、LICENSEファイルを参照してください。
2022年3月31日、Recogのコンテンツ(XMLフィンガープリントファイルとユーティリティ)は、Recogフレームワークライブラリの実装から分割されました。元のRecogリポジトリにはRecogのコンテンツが含まれ、Recog-RubyリポジトリにはRuby言語実装が含まれています。Recogのコンテンツは、gitサブモジュールとしてRecog-Rubyに含まれ、recogディレクトリの下に配置されています。分割後のRecog gemバージョン3.0.0以上では、1. recogディレクトリの下にXMLフィンガープリントディレクトリが含まれ、2. 他のツールはフィンガープリント管理に焦点を当てているため、recog_matchツールのみが含まれます。
リポジトリの分割に伴い、デフォルトブランチはmasterからmainに名称変更されました。これらの変更より前に作成されたクローンは、ローカル環境で手動で更新する必要があります。フォークを使用している場合は、フォークの設定に移動し、ブランチの名称変更の手順に従って、デフォルトブランチを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デーモンの初期バナー文字列をマッチングすることで、OS、ベンダー、場合によってはハードウェア製品を特定できます。
フィンガープリントファイルは、次のような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要素の中には、1つ以上のfingerprint要素が必要です。各fingerprintには、データのマッチングに使用する正規表現を含むpattern属性が必須です。正規表現の解釈方法を制御するために、オプションのflags属性を指定できます。詳細については、FLAG_MAPに関するRecogのドキュメントを参照してください。
フィンガープリント内のdescription要素には、このフィンガープリントを説明する人間が読める文字列を含める必要があります。
少なくとも1つのexample要素が存在する必要がありますが、複数のexample要素が推奨されます。これらの要素は、提供されたデータが指定された正規表現にマッチすることを検証するrspecのテストカバレッジの一部として使用されます。さらに、フィンガープリントがparam要素を使用してデータからフィールド値を抽出する場合(次で説明)、これらの期待される抽出値をexample要素の属性として追加できます。上記の例では、これ:
<example service.version="4.62">RomSShell_4.62</example>
は、RomSShell_4.62が提供された正規表現にマッチし、service.versionの値が4.62であることをテストします。
example文字列は、印刷できない文字を使用できるようにbase64エンコードできます。これをRecogに通知するには、値がbase64の_encoding属性をexample要素に追加します。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では追跡されません。
次の例では、Recogのフィンガープリントデータを使用するシンプルなRubyコマンドラインツールであるbin/recog_matchを使用します。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)"}
ファビコンの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パラメータ補間 | ✅ | ✅ | ✅ |