
このリポジトリには、よく知られたJavaデシリアライゼーション悪用ツールysoserialへの私の更新が含まれています。
これは、https://github.com/frohoff/ysoserial で入手できるオリジナルの ysoserial アプリケーションのフォークです。
Java における Runtime.getRuntime().exec(String.class) の動作上、パイプを制御したり出力をファイルに送ったりする必要があるネストされた複雑なコマンド(例: cat /etc/passwd > /tmp/passwd_copy)は、Runtime クラスの exec() メソッドによって実行されるコマンドがターミナル環境内で実行されないため、機能しません。1つの回避策として "/bin/sh -c 'command'" を実行する方法がありますが、'command' 内のスペース文字を ${IFS} を使ってエスケープしないと、期待どおりには動作しません。この問題と可能な回避策の詳細については、詳細を深く解説している こちらのブログ記事 をお読みください。
この問題を解決する良い方法は、文字列の配列を期待する Runtime.getRuntime().exec(String[].class) メソッドに引数を渡すことです。最適な方法は、Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", "command"}) を実行することです。この方法で引数を渡すと、java は /bin/bash を実行し、-c と 'command' という引数を正しい方法で渡していることを理解し、ターミナル環境内でコマンドを実行します。これにより、ネストされた複雑なコマンド(| や ; を使用)や、入力と出力の制御(< と > を使用)が可能になります。
これを踏まえて、コマンドを実行するために使用したいターミナルの種類(cmd / bash / powershell または none)を ysoserial に指定できる機能を追加しました。この変更により、そのターミナルコンテキスト内でコマンドが実行されるため、複雑なコマンドでも本来どおりに実行できます。
pimps@Scorpion:~/git/ysoserial-modified/target$ java -jar ysoserial-modified.jar
Y SO SERIAL?
Usage: java -jar ysoserial-[version]-all.jar [payload type] [terminal type: cmd / bash / powershell / none] '[command to execute]'
ex: java -jar ysoserial-[version]-all.jar CommonsCollections5 bash 'touch /tmp/ysoserial'
Available payload types:
BeanShell1 [org.beanshell:bsh:2.0b5]
C3P0 [com.mchange:c3p0:0.9.5.2, com.mchange:mchange-commons-java:0.2.11]
CommonsBeanutils1 [commons-beanutils:commons-beanutils:1.9.2, commons-collections:commons-collections:3.1, commons-logging:commons-logging:1.2]
CommonsCollections1 [commons-collections:commons-collections:3.1]
CommonsCollections2 [org.apache.commons:commons-collections4:4.0]
CommonsCollections3 [commons-collections:commons-collections:3.1]
CommonsCollections4 [org.apache.commons:commons-collections4:4.0]
CommonsCollections5 [commons-collections:commons-collections:3.1]
CommonsCollections6 [commons-collections:commons-collections:3.1]
FileUpload1 [commons-fileupload:commons-fileupload:1.3.1, commons-io:commons-io:2.4]
Groovy1 [org.codehaus.groovy:groovy:2.3.9]
Hibernate1 []
...
このリポジトリの /target ディレクトリからコンパイル済みの jar をダウンロードするか、ここをクリック してください。
自分でコンパイルする場合:
Java 1.7+ と Maven 3.x+ が必要です。
$ git clone https://github.com/pimps/ysoserial-modified.git
$ cd ysoserial-modified
$ mvn clean package -DskipTests
jar ファイルは target ディレクトリに配置されます。