0x00 CSV Formula Injection
这个之前在玩其它的靶场的时候就已经接触过了,上次的时候由于代码问题,没有办法复现成功,这次又碰到了。其实就是利用excel
来执行系统命令,越来越感觉hacker
的无所不能,牛逼。
先看home.php
if($conn){
$stmt = $conn1->prepare("SELECT itemcode,itemname,categ,price from caffaine");
$stmt->execute();
echo "<table class='table table-striped'>";
echo "<tr><th>Item Code</th><th>Item Name</th><th>Category</th><th>Price</th></tr>";
while($rows=$stmt->fetch(PDO::FETCH_NUM)){
echo "<tr>";
echo "<td>".htmlspecialchars($rows[0])."</td>";
echo "<td>".htmlspecialchars($rows[1])."</td>";
echo "<td>".htmlspecialchars($rows[2])."</td>";
echo "<td>$".htmlspecialchars($rows[3])."</td>";
echo "</tr>";
}
}
echo "</table>";
用的预处理PDO
不存在注入点,再看导出文件export.php
<?php
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=xvwa-export.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('itemcode', 'itemname', 'categ','price'));
include('../../config.php');
$sql='SELECT itemcode,itemname,categ,price from caffaine';
$result = $conn->query($sql);
while ($row = mysqli_fetch_assoc($result)) fputcsv($output, $row);
?>
一样的,只是一个输出csv
格式的php
文件,也没看到有效输入信息。
也就是说,参数没有办法从这里添加,于是找找找找找,发现了这个。
这四个参数和上面的基本是一样的阿,于是上传了一波。
这里payload
写在name
和category
应该都可以的,此时观察表单信息。
下载CSV
文件,并打开。
有安全提示,点启用
,不然无法触发。
继续点是
(感觉真的只能去欺骗大爷大妈了。。。)
成功执行。。。
0x02 webug4.0 csv
回头再来看看webug4.0
中的csv
。。。
我去,把上传点给干掉了,难怪当时不知道在哪上传数据。。。
<table id="table">
<tr>
<th>Name</th>
<th>Age</th>
<th>Email</th>
</tr>
<?php
if ($res) {
while (list($id, $name, $age, $email, $deflag) = mysqli_fetch_row($res)){
echo '<tr>';
echo '<input type="text" hidden="hidden" name="id[]" value="'.$id.'">';
echo '<td><div contenteditable="true">'.$name.'</div></td>';
echo '<td><div contenteditable="true">'.$age.'</div></td>';
echo '<td><div contenteditable="true">'.$email.'</div></td>';
echo '</tr>';
}
}
?>
</table>
<div>
<button type="button" id="button">导出</button>
</div>
</body>
<script src="../../../aa/html/table-to-excel.js"></script>
<script>
var tableToExcel = new TableToExcel();
document.getElementById('button').onclick = function () {
tableToExcel.render("table");
};
</script>
导出是通过javascript
来完成的,由于点击没反应,所以我去查了下这个JS
原来这个功能是需要外部引入的,接着审查元素。。。
还真有一个,访问着看一下。
太惨了,没这个JS
,难怪下载不下来。。。
找了下也没看到对应的名字,算了,不修复了,就这样吧,过去的就让他过去,感觉这几个月的代码水平比年前强多了啊,年前不知道怎么动手,现在感觉完全不是问题,还不错还不错,继续学习,继续加油。