没有合适的资源?快使用搜索试试~ 我知道了~
高版本AES-GCM模式加密的Shiro漏洞利用1
需积分: 0 2 下载量 144 浏览量
2022-08-03
12:29:20
上传
评论
收藏 1.64MB PDF 举报
温馨提示
试读
11页
高版本AES-GCM模式加密的Shiro漏洞利用1
资源详情
资源评论
资源推荐
⾼
版
本
AES-GCM
模
式
加
密
的
Shiro
漏
洞
利
⽤
Shiro
⾼
版
本
加
密
⽅
式
从
AES-CBC
换
成
了
AES-GCM
,
由
于
加
密
算
法
的
变
化
导
致
⽤
于
攻
击
shiro-550
的
exp
⽆
法
试
⽤
于
新
版
Shiro
⾼
版
本
的
加
密
解
密
调
⽤
了
AesCipherService
AesCipherService
中
设
定
的
加
密
⽅
式
为
AES-GCM
,
Padding
为
None
public class AesCipherService extends DefaultBlockCipherService {
private static final String ALGORITHM_NAME = "AES";
public AesCipherService() {
super("AES");
this.setMode(OperationMode.GCM);
this.setStreamingMode(OperationMode.GCM);
Shiro
⾼
版
本
加
密
⽅
式
下
的
漏
洞
利
⽤
加
密
⽅
式
的
变
化
加
密
模
式
的
变
化
发
⽣
在
针
对
Oracle Padding Attack
的
修
复
,
1.4.2
版
本更
换
为了
AES-
GCM
加
密
⽅
式
GCM
模
式
下,
补
位信
息
是
完
全
不
需
要
考
虑
的
,
明
⽂
与
密
⽂
有
着相
同
的
⻓
度
this.setPaddingScheme(PaddingScheme.NONE);
}
protected AlgorithmParameterSpec createParameterSpec(byte[] iv, boolean streaming) {
return (AlgorithmParameterSpec)((!streaming || !OperationMode.GCM.name().equals(thi
s.getStreamingModeName())) && (streaming || !OperationMode.GCM.name().equals(this.getModeNa
me())) ? super.createParameterSpec(iv, streaming) : new GCMParameterSpec(this.getKeySize(),
iv));
}
}
加
密
解
密
⽅
法
的
实
现
在
JcaCipherService
public ByteSource encrypt(byte[] plaintext, byte[] key) {
byte[] ivBytes = null;
boolean generate = this.isGenerateInitializationVectors(false);
if (generate) {
ivBytes = this.generateInitializationVector(false);
if (ivBytes == null || ivBytes.length == 0) {
throw new IllegalStateException("Initialization vector generation is enable
d - generated vector cannot be null or empty.");
}
}
return this.encrypt(plaintext, key, ivBytes, generate);
}
然
后
⽣
成
ivBytes
initializationVectorSize
为
128
会
随
机
⽣
成
16
位
的
ivBytes
加
密
解
密实
现
Encrypt
protected byte[] generateInitializationVector(boolean streaming) {
int size = this.getInitializationVectorSize();
String msg;
if (size <= 0) {
msg = "initializationVectorSize property must be greater than zero. This numbe
r is typically set in the " + CipherService.class.getSimpleName() + " subclass constructor.
Also check your configuration to ensure that if you are setting a value, it is positive.";
throw new IllegalStateException(msg);
} else if (size % 8 != 0) {
msg = "initializationVectorSize property must be a multiple of 8 to represent a
s a byte array.";
throw new IllegalStateException(msg);
} else {
int sizeInBytes = size / 8;
byte[] ivBytes = new byte[sizeInBytes];
SecureRandom random = this.ensureSecureRandom();
random.nextBytes(ivBytes);
return ivBytes;
}
}
之
后
传
⼊
重
载
的
同名
⽅
法
进
⾏
加
密
private ByteSource encrypt(byte[] plaintext, byte[] key, byte[] iv, boolean prependIv) thro
ws CryptoException {
int MODE = true;
byte[] output;
if (prependIv && iv != null && iv.length > 0) {
byte[] encrypted = this.crypt(plaintext, key, iv, 1);
output = new byte[iv.length + encrypted.length];
System.arraycopy(iv, 0, output, 0, iv.length);
System.arraycopy(encrypted, 0, output, iv.length, encrypted.length);
} else {
output = this.crypt(plaintext, key, iv, 1);
}
if (log.isTraceEnabled()) {
log trace("Incoming plaintext of size " + (plaintext != null ? plaintext length
剩余10页未读,继续阅读
KerstinTongxi
- 粉丝: 21
- 资源: 277
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0