MongoDB数据库安全
本文最后更新于 517 天前,其中的信息可能已经有所发展或是发生改变。

1、前言

前几天,我自己的项目myblog博客后台系统的MongoDB数据库被黑客删除了,新增了一个RREAD_ME_TO_RECOVER_YOUR_DATA的数据库,里面是一个叫做readme的collection。打开后主要内容如下:

All your data is a backed up. You must pay 0.015 BTC to 1TvCTpihDcmEjs9weTeKyruYYEY6n5xCB 48 hours for recover it. After 48 hours expiration we will leaked and exposed all your data. In case of refusal to pay, we will contact the General Data Protection Regulation, GDPR and notify them that you store user data in an open form and is not safe. Under the rules of the law, you face a heavy fine or arrest and your base dump will be dropped from our server! You can buy bitcoin here, does not take much time to buy https://localbitcoins.com with this guide https://localbitcoins.com/guides/how-to-buy-bitcoins After paying write to me in the mail with your DB IP: allmydataback@cock.li and you will receive a link to download your database dump.

大概意思是你的数据库被我们删除了,你需要支付0.015比特币(约等于39262¥)来恢复你的数据,不然48小时后我们你的数据会被暴露,如果拒付你将面临巨额罚款。

当时我的数据库里面只有4张表,数据不太重要,由于需要在本地进行调试,因此没有设置密码。当时是在登录这个后台才发现被删除的,如果这种情况发生在公司,就会变得很可怕。

2、安全设置

2.1 开启authorization验证

2.1.1 第一步,开启权限验证

打开宝塔面板的MongoDB,进入配置文件

security:
    authorization: enabled;

2.1.2 第二步,设置用户名、密码

// 进入控制台,运行mongo
cd /www/server/mongodb/bin/
./mongo

// 使用管理员身份创建用户cds,并指定用户对数据库myblog具有读写权限
use admin;
db.createUser({
    user: "cds",
    pwd:"cds333",
    roles:[{
        role:"readWrite",
        db:"myblog"
    }]
})

2.1.3 第三步,验证并重启MongoDB

db.auth('cds', 'cds333')

2.2 阻止远程访问

设置bindIP:127.0.0.1

2.3 修改端口号

端口号需要在服务器的安全组或防火墙以及宝塔的防火墙里添加。添加后直接修改配置文件将27017改成修改的数值即可。

3、常见问题

  • 如果需要让MongoDB可以远程访问,设置bindIP:0.0.0.0
  • 如果需要实现检索,使用db.essay.ensureIndex({category:"text"}),表示使用category字段对essay表进行检索
本文链接:https://likepoems.com/articles/mongodb-database-security/
转载说明:本站文章若无特别说明,皆为原创,转载请注明来源:likepoems,谢谢!^^
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇