C.P.Sub 開源留言板系統存在多個漏洞

Broken Access Control

在檢查登入狀態時, Auth.php 會先檢查路徑是否包含 login ,否則直接檢查 cookie 中是否有 cpsub_usernamecpsub_password ,因此可以直接在 cookie 中新增這兩個欄位並存取 manage.php 便可直接繞過登入機制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if(!preg_match("/login/", $page)){
if($this->getLib->checkVal($cookie)){
if(isset($cookie['cpsub_username']) && isset($cookie['cpsub_password'])){
$username = $this->getLib->setFilter($cookie['cpsub_username']);
$password = $this->getLib->setFilter($cookie['cpsub_password']);
}
else{
$username = "";
$password = "";
}
if($this->getLib->checkVal($username)){
$login = "1";
$session['login'] = $login;
$session['cpsub_username'] = $username;
}
}
}

Refleced XSS

在未登入的情況下, manage.php 中的 p 參數會導致 XSS Injection 主要是因為 checkAuth() 在驗證失敗後會將使用者倒回 login.php?re={$p} ,但在 getRedirect() 時直接使用 Javascript 拼接字串設定 location.href ,因此,攻擊者可以透過 ; 插入惡意 javascript 達到 XSS

1
2
3
4
5
6
7
8
function getRedirect($get_string){
$returnVal = $get_string;
if($this->checkVal($returnVal)){
//$get_string = foo';alert();'
$returnVal = "<script>window.location.href='{$get_string}'</script>";
}
return $returnVal;
}

LFI

同一個 p 參數在使用者有登入的情況下,會被拼接成 ./admin/{$p}.php ,檢查檔案是否存在後被塞進 include() ,我們可以透過 ../ path traversal 並 include() 系統上的任意 php 檔。

1
2
3
4
$include_path = $getLib->checkAdminPath($p);
if($getLib->checkVal($include_path)){
include($include_path) ;
}

上傳漏洞

上傳功能只黑名單 .php.asp,如果用 php8 / php5 / phtml 等同樣會被解析成 php 的檔案同樣能輕鬆上傳後門到系統上。