写道
You must be very careful with security when executing JavaScript on the server. If done
incorrectly, server-side JavaScript is susceptible to injection attacks similar to those that
occur in a relational database. However, by following certain rules around accepting
input, you can use JavaScript safely. Alternatively, you can turn off JavaScript execution
altogether by running mongod with the --noscripting option.
The security issues with JavaScript are all related to executing user-provided programs
on the server. You want to avoid doing that, so make sure you aren’t accepting user input
and passing it directly to mongod. For example, suppose you want to print “Hello,
name!”, where name is provided by the user. A naive approach might be to write a Java‐
Script function such as the following:
> func = "function() { print('Hello, "+name+"!'); }"
If name is a user-defined variable, it could be the string "'); db.dropDatabase();
print('", which would turn the code into this:
> func = "function() { print('Hello, '); db.dropDatabase(); print('!'); }"
Now, if you run this code, your entire database will be dropped!
incorrectly, server-side JavaScript is susceptible to injection attacks similar to those that
occur in a relational database. However, by following certain rules around accepting
input, you can use JavaScript safely. Alternatively, you can turn off JavaScript execution
altogether by running mongod with the --noscripting option.
The security issues with JavaScript are all related to executing user-provided programs
on the server. You want to avoid doing that, so make sure you aren’t accepting user input
and passing it directly to mongod. For example, suppose you want to print “Hello,
name!”, where name is provided by the user. A naive approach might be to write a Java‐
Script function such as the following:
> func = "function() { print('Hello, "+name+"!'); }"
If name is a user-defined variable, it could be the string "'); db.dropDatabase();
print('", which would turn the code into this:
> func = "function() { print('Hello, '); db.dropDatabase(); print('!'); }"
Now, if you run this code, your entire database will be dropped!
mongo db 以 javascript 作为脚本语言,
用户可以输入一段恶意的javasript,
比如
前台页面有一个input,让用户输入用户名
但用户输入了类似如下脚本并提交,
'); db.dropDatabase();('
就会删除掉数据库。
解决方法
--noscripting 关闭执行用户输入的javascript,可以避免类似sql注入的攻击。
1. 安装的时候需要加–auth
加了–auth之后MongoDB才需要验证
2. 需要加–nohttpinterface
不加会有一个28017的端口监听,可以通过网页管理mongodb,不需要请去掉
3. 可以加–bind_ip
加之后可以限制访问的ip
4. 可以加–port
加了之后可以重新制定端口,默认为27017
5. 安装完之后需立即在admin数据库中添加一个用户
只有在admin数据库中添加一个用户后才能使认证生效
相关推荐
windows平台上详细介绍MongoDB安全认证的过程,适用于新手
MongoDB安全配置事项 1、开启授权认证 在配置文件mongod.conf 中加入 auth = true 如果你开启了--rest参数,甚至可以直接通过web界面查询数据,执行mongod命令。 2、关闭网页管理 在配置文件mongod.conf 中加入...
MongoDB数据库使用方法及安全配置,有兴趣的可以下载,
MongoDB安全认证.pdf 学习资料 复习资料 教学资源
本文将详细介绍MongoDB安全相关的内容 概述 MongoDB安全主要包括以下4个方面 1、物理隔离 系统不论设计的多么完善,在实施过程中,总会存在一些漏洞。如果能够把不安全的使用方与MongoDB数据库做物理上的隔离,即...
主要介绍了十个提高MongoDB安全性的配置技巧,需要的朋友可以参考下
2.漏洞成因在刚安装完毕的时候MongoDB都默认有一个admin数据库,此时admin数据库是空的,没有记录权限相关的信息 3.漏洞自查如果您是MongoDB
2020年MongoDB数据库最佳安全配置指导文档,通过配置安全选项,实现数据库的存储、传输和使用安全。
1.分篇章进行学习,内容控制30分钟内 2.1个月疗程,不要放弃治疗哦 3.图文并茂,有问题请发到邮箱
主要介绍了MongoDB安全配置详解,本文来自国内安全厂商乌云平台,讲解的还是比较全面的,需要的朋友可以参考下
MongoDB数据库
或者,也可以修改/etc/mongodb.conf,设置auth=true,重启mongod进程。 2.添加用户 代码如下:db.addUser(“admin”, “123456″) 3.安全认证 代码如下:db.auth(“admin”, “123456″) 认证成功的情况下 代码如下:db...
mongodb副本集加分片集群安全认证使用账号密码登录
MongoDB 安全权限控制 各角色及对应授权的详细说明,网上不少文档对dbAdmin这个角色的说明都是错误的,没有介绍清楚,因此自己翻译了MongoDB的官方文档
视频目录: 01-mongodb文档型数据库特点介绍 01-NoSQL简介 02-mongodb安装过程 02-mongodb操作1 ...09-安全和认证 10-replication复制集 10-主从复制 11-shard分片 11-分片 12-使用java操作mongodb
MongoDB的安全认证 4、主讲内容 基础入门部分 章节一:MongoDB相关概念 章节二:单机部署 章节三:基本常用命令 章节四:SpringDataMongoDB操作 高级进阶部分 章节一:索引 章节二:特殊集合 章节三:副本集 章节四...