2023-05-10 分類: 網(wǎng)站建設
在php中修補xss漏洞,我們可以使用三個php函數(shù)。
這些函數(shù)主要用于清除html標志,這樣就沒辦法注入代碼了。使用更多的函數(shù)是htmlspecialchars() ,它可以將所有的"<"與">"符號轉換成"<" 與">;"。其它可供選擇的函數(shù)還有htmlentities(), 它可以用相應的字符實體(entities)替換掉所有想要替換掉的特征碼(characters)。
php code:
// 這里的代碼主要用于展示這兩個函數(shù)之間輸出的不同
$input = '';
echo htmlspecialchars($input) . '
';
echo htmlentities($input);
?>
htmlentities()的另一個例子
php code:
$str = "a 'quote' is bold";
echo htmlentities($str);
echo htmlentities($str, ent_quotes);
?>
先進個顯示: a 'quote' is bold
第二個顯示:a 'quote' is bold
htmlspecialchars()使用實例
php code:
$new = htmlspecialchars("test", ent_quotes);
echo $new;
?>
顯示: te?st
strip_tags()函數(shù)代替.刪除所有的html元素(elements),除了需要特別允許的元素之外,如:, 或
.
strip_tags()使用實例
php code:
$text = '
test paragraph.
other text';
echo strip_tags($text, '
');
?>
現(xiàn)在我們至少已經(jīng)知道有這些函數(shù)了,當我們發(fā)現(xiàn)我們的站點存在xss漏洞時就可以使用這些代碼了。我近在我的站點上的googlebig(一個mybb論壇的插件)視頻部分發(fā)現(xiàn)了一個xss漏洞,因此我就在想如何使用這些函數(shù)寫段代碼來修補這個搜索漏洞。
www.rwnh.cn
首先我發(fā)現(xiàn)問題出在search.php這一文件上,現(xiàn)在讓我們看看這個查詢及輸出查詢結果中的部分代碼研究一下:
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);
...
在這種情況下,我們通過使用$query這一值作為變量,然后使用htmlentities()這一函數(shù):
php code:
$query = fixquotes(nl2br(filter_text(htmlentities($query))));
新聞標題:可以使用三個php函數(shù)修補xss漏洞
地址分享:http://www.rwnh.cn/news/258840.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、外貿網(wǎng)站建設、ChatGPT、外貿建站、網(wǎng)站建設、品牌網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容