可以使用三個(gè)php函數(shù)修補(bǔ)xss漏洞

2023-05-10    分類(lèi): 網(wǎng)站建設(shè)

在php中修補(bǔ)xss漏洞,我們可以使用三個(gè)php函數(shù)。
這些函數(shù)主要用于清除html標(biāo)志,這樣就沒(méi)辦法注入代碼了。使用更多的函數(shù)是htmlspecialchars() ,它可以將所有的"<"與">"符號(hào)轉(zhuǎn)換成"<" 與">;"。其它可供選擇的函數(shù)還有htmlentities(), 它可以用相應(yīng)的字符實(shí)體(entities)替換掉所有想要替換掉的特征碼(characters)。
php code:
// 這里的代碼主要用于展示這兩個(gè)函數(shù)之間輸出的不同
$input = '';
echo htmlspecialchars($input) . '
';
echo htmlentities($input);
?>
htmlentities()的另一個(gè)例子
php code:
$str = "a 'quote' is bold";
echo htmlentities($str);
echo htmlentities($str, ent_quotes);
?>
先進(jìn)個(gè)顯示: a 'quote' is bold
第二個(gè)顯示:a 'quote' is bold
htmlspecialchars()使用實(shí)例
php code:
$new = htmlspecialchars("test", ent_quotes);
echo $new;
?>
顯示: te?st
strip_tags()函數(shù)代替.刪除所有的html元素(elements),除了需要特別允許的元素之外,如:,

.
strip_tags()使用實(shí)例
php code:
$text = '

test paragraph.

other text';
echo strip_tags($text);
echo "n";
// allow


echo strip_tags($text, '

');
?>
現(xiàn)在我們至少已經(jīng)知道有這些函數(shù)了,當(dāng)我們發(fā)現(xiàn)我們的站點(diǎn)存在xss漏洞時(shí)就可以使用這些代碼了。我近在我的站點(diǎn)上的googlebig(一個(gè)mybb論壇的插件)視頻部分發(fā)現(xiàn)了一個(gè)xss漏洞,因此我就在想如何使用這些函數(shù)寫(xiě)段代碼來(lái)修補(bǔ)這個(gè)搜索漏洞。
muchs.cn
首先我發(fā)現(xiàn)問(wèn)題出在search.php這一文件上,現(xiàn)在讓我們看看這個(gè)查詢(xún)及輸出查詢(xún)結(jié)果中的部分代碼研究一下:
php code:
function search($query, $page)
{
global $db, $bgcolor2, $bgcolor4, $sitename, $io_db, $module_url, $list_page_items, $hm_index;
$option = trim($option);
$query = trim($query); $query = fixquotes(nl2br(filter_text($query)));
$db->escape_string($query);
$db->escape_string($option);
alpha_search($query);
...
在這種情況下,我們通過(guò)使用$query這一值作為變量,然后使用htmlentities()這一函數(shù):
php code:
$query = fixquotes(nl2br(filter_text(htmlentities($query))));

新聞標(biāo)題:可以使用三個(gè)php函數(shù)修補(bǔ)xss漏洞
地址分享:http://muchs.cn/news/258840.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、ChatGPT、外貿(mào)建站網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司