
CVE-2024-23692 | HFS 2.3m/2.4-RC07 RCE脆弱性の修正
You can use HFS (HTTP File Server) to send and receive files. It's different from classic file sharing because it uses web technology. It also differs from classic web servers because it's very easy to use and runs "right out-of-the box".
The virtual file system will allow you to easily share even one single file.
| 項目 | 内容 |
|---|---|
| CVE 番号 | CVE-2024-23692 |
| 影響バージョン | HFS 2.3m、HFS 2.4.0 RC07 以下 |
| 脆弱性タイプ | 未認証のリモートコード実行 (Unauthenticated RCE) |
| CVSS スコア | 9.8 Critical |
| 攻撃ベクトル | ネットワーク経由、認証不要、ユーザー操作不要 |
HFS のテンプレートエンジンは、{.?search.} マクロ(URL クエリパラメータを読み取る)を処理する際に、戻り値に対して再帰的に applyMacrosAndSymbols2() を呼び出すため、ユーザーが制御可能な文字列がテンプレートコードとして実行されます。
攻撃チェーンは 4 つのステップからなります:
1. %url% を含む search パラメータを構築
↓
2. %url% が macroQuote(完全なURL) = {:url_including_payload:} に展開される
↓
3. %password% が空文字列に展開され、{:…:} 参照ブロックが早期に閉じられる
↓
4. 参照ブロック外の {.exec|cmd.} がマクロエンジンによって実行される → RCE
POC 例(セキュリティ研究のみ):
GET /?n=%0A&cmd=whoami&search=%25xxx%25url%25:%password%}{.exec|{.?cmd.}|timeout=15|out=abc.}{.?n.}{.?n.}RESULT:{.?n.}{.^abc.}===={.?n.} HTTP/1.1
修正ファイル: scriptLib.pas
コア関数: noMacrosAllowed() (109–123 行)
function noMacrosAllowed(s:string):string;
// prevent hack attempts
begin
// 手順 1:すべてのマクロマーカーの先頭文字を HTML エンティティに置換
// {. → {. .} → .}
// {: → {: :} → :}
// | → |
repeat
i := findMacroMarker(s, i);
if i = 0 then break;
replace(s, '&#' + intToStr(charToUnicode(s[i])) + ';', i, i);
until false;
// 手順 2:%symbol% 形式のシンボル参照を HTML エンティティに置換
// %url% → %url%
// %password% → %password%
s := reReplace(s, '%([-a-z0-9]+)%', '%$1%', 'mi');
result := s;
end;
呼び出し箇所: すべてのユーザー制御入力がテンプレートエンジンに返される前に、この関数によって処理されます:
修正効果: POC 内の search パラメータは処理後、すべてのマクロマーカーとシンボル参照が HTML エンティティ化され、マクロエンジンの実行を引き起こせなくなります。
Initially developed in 2002 with Delphi 6, now with Delphi 10.3.3 (Community Edition). Icons are generated at http://fontello.com/ . Use fontello.json for further modifications.
For the default template we are targeting compatibility with Chrome 49 as it's the latest version running on Windows XP.
| 呼び出し箇所 | 保護範囲 |
|---|
urlVar() 548 行 | すべての URL クエリパラメータ {.?name.} |
| 698 行 | テンプレート変数の読み取り |
| 1549 行 | Cookie 値 |
| 2089 行 | URL デコード値 |
| 2165 行 | HTTP リクエストヘッダー |
| 2173 行 | POST フォームパラメータ |