首页 > 其他分享 >学习笔记-.net安全之ueditor远程下载分析

学习笔记-.net安全之ueditor远程下载分析

时间:2022-11-07 11:02:18浏览次数:78  
标签:ueditor pathFormat -. Replace ToString var new net

0x00 简介

UEditor 的.NET版本N年前爆出一个远程下载漏洞。

0x01 漏洞成因

URL:

http://192.168.110.129:520/gbk-net/net/controller.ashx?action=catchimage

在POC中请求的URL如上,直接定位到文件controller.ashx

utf8-net\net\controller.ashx


case "listfile":
    action = new ListFileManager(context, Config.GetString("fileManagerListPath"), Config.GetStringList("fileManagerAllowFiles"));
    break;
case "catchimage":
    action = new CrawlerHandler(context);
    break;

catchimage 调用CrawlerHandler 进而跟进CrawlerHandler

utf8-net\net\App_Code\CrawlerHandler.cs


public class CrawlerHandler : Handler
{
    private string[] Sources;
    private Crawler[] Crawlers;
    public CrawlerHandler(HttpContext context) : base(context) { }

    public override void Process()
    {
        Sources = Request.Form.GetValues("source[]");
        if (Sources == null || Sources.Length == 0)
        {
            WriteJson(new
            {
                state = "参数错误:没有指定抓取源"
            });
            return;
        }
        Crawlers = Sources.Select(x => new Crawler(x, Server).Fetch()).ToArray();
        WriteJson(new
        {
            state = "SUCCESS",
            list = Crawlers.Select(x => new
            {
                state = x.State,
                source = x.SourceUrl,
                url = x.ServerUrl
            })
        });
    }
}

CrawlerHandler获取Sources判断是否为空,这里只需要构造Sources[]=url即可,然后后调用Crawler Fetch

Crawler Fetch()


public Crawler Fetch()
{
    if (!IsExternalIPAddress(this.SourceUrl))
    {
        State = "INVALID_URL";
        return this;
    }
    var request = HttpWebRequest.Create(this.SourceUrl) as HttpWebRequest;
    using (var response = request.GetResponse() as HttpWebResponse)
    {
        if (response.StatusCode != HttpStatusCode.OK)
        {
            State = "Url returns " + response.StatusCode + ", " + response.StatusDescription;
            return this;
        }
        if (response.ContentType.IndexOf("image") == -1)
        {
            State = "Url is not an image";
            return this;
        }
        ServerUrl = PathFormatter.Format(Path.GetFileName(this.SourceUrl), Config.GetString("catcherPathFormat"));
        var savePath = Server.MapPath(ServerUrl);
        if (!Directory.Exists(Path.GetDirectoryName(savePath)))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(savePath));
        }
        try
        {
            var stream = response.GetResponseStream();
            var reader = new BinaryReader(stream);
            byte[] bytes;
            using (var ms = new MemoryStream())
            {
                byte[] buffer = new byte[4096];
                int count;
                while ((count = reader.Read(buffer, 0, buffer.Length)) != 0)
                {
                    ms.Write(buffer, 0, count);
                }
                bytes = ms.ToArray();
            }
            File.WriteAllBytes(savePath, bytes);
            State = "SUCCESS";
        }
        catch (Exception e)
        {
            State = "抓取错误:" + e.Message;
        }
        return this;
    }
}

这里首先调用函数IsExternalIPAddress 判断你是不是一个正常的域名,不是则return
然后请求传入的URL查看是否响应200,再判断ContentType是否为image,在这里其实只要构建服务器返回的Content-Typeimage/xxxx即可,重点在PathFormatter我们跟进。

utf8-net\net\App_Code\PathFormater.cs


public static string Format(string originFileName, string pathFormat)
{
    if (String.IsNullOrWhiteSpace(pathFormat))
    {
        pathFormat = "{filename}{rand:6}";
    }

    var invalidPattern = new Regex(@"[\\\/\:\*\?\042\<\>\|]");
    originFileName = invalidPattern.Replace(originFileName, "");  //替换正则匹配到的为空1.png.aspx

    string extension = Path.GetExtension(originFileName); //.aspx
    string filename = Path.GetFileNameWithoutExtension(originFileName);

    pathFormat = pathFormat.Replace("{filename}", filename);
    pathFormat = new Regex(@"\{rand(\:?)(\d+)\}", RegexOptions.Compiled).Replace(pathFormat, new MatchEvaluator(delegate(Match match)
    {
        var digit = 6;
        if (match.Groups.Count > 2)
        {
            digit = Convert.ToInt32(match.Groups[2].Value);
        }
        var rand = new Random();
        return rand.Next((int)Math.Pow(10, digit), (int)Math.Pow(10, digit + 1)).ToString();
    }));

    pathFormat = pathFormat.Replace("{time}", DateTime.Now.Ticks.ToString());
    pathFormat = pathFormat.Replace("{yyyy}", DateTime.Now.Year.ToString());
    pathFormat = pathFormat.Replace("{yy}", (DateTime.Now.Year % 100).ToString("D2"));
    pathFormat = pathFormat.Replace("{mm}", DateTime.Now.Month.ToString("D2"));
    pathFormat = pathFormat.Replace("{dd}", DateTime.Now.Day.ToString("D2"));
    pathFormat = pathFormat.Replace("{hh}", DateTime.Now.Hour.ToString("D2"));
    pathFormat = pathFormat.Replace("{ii}", DateTime.Now.Minute.ToString("D2"));
    pathFormat = pathFormat.Replace("{ss}", DateTime.Now.Second.ToString("D2"));

    return pathFormat + extension;
}

整个逻辑流程就是 originFileName: 1.png?.aspx -> 1.png.aspx - > .aspx

pathFormat: 获取config.json的格式 然后拼接返回保存文件的路径,可以把代码单独扣出来运行。

其实我们直接控制Content-Typeimage/xxxx 后缀名为我们想要的即可,比如

http://192.168.110.1:8000/1.ashx

0x02 总结

有的网上的poc只是为了方便大多数环境,当我们细读源码后知道新的方法往往能找到一些WAF绕过的技巧。

点击关注,共同学习!
安全狗的自我修养

github haidragon

https://github.com/haidragon

标签:ueditor,pathFormat,-.,Replace,ToString,var,new,net
From: https://www.cnblogs.com/haidragon/p/16865242.html

相关文章

  • 学习笔记-.net安全
    0x00简介本章内容:1.xss2.csrf3.文件上传0x01XSS在asp.net中我们插入XSS代码经常会遇到一个错误ApotentiallydangerousRequest.Form这是因为在aspx文件头一般......
  • 学习笔记-.net安全越权
    0x00ASP.NET安全认证1.在web.config中有四种验证模式:方式描述windowIIS验证,在内联网环境中非常有用Passport微软集中式身份验证,一次登录便可访问所有成员......
  • networkQuality
    基本使用networkQuality 是一个命令行工具,需要使用「终端」App(或者你首选的其他终端模拟器)运行。方法是:首先,点按「程序坞」(Dock)中的「启动台」(LaunchPad)图标,在搜索栏中......
  • Ubuntu系统中CUDA套件nvvp启动后报错Unable to make protected void java.net.URLClas
    最近在看cuda方面的内容,需要对cuda代码做一些性能分析,于是需要使用nvvp,但是启动nvvp后报错:Causedby:java.lang.reflect.InaccessibleObjectException:Unabletomakepr......
  • ASP.NET Core教程-Configuration(配置)- Cache(缓存)
    更新记录转载请注明出处:2022年11月7日发布。2022年11月5日从笔记迁移到博客。缓存缓存的概念缓存(Caching)是系统优化中简单又有效的工具,投入小收效大。数据库中......
  • 基于 .NET 7 的 QUIC 实现 Echo 服务
    前言随着今年6月份的HTTP/3协议的正式发布,它背后的网络传输协议QUIC,凭借其高效的传输效率和多路并发的能力,也大概率会取代我们熟悉的使用了几十年的TCP,成为互联网的......
  • ASP.NET Core 集成 Elastic APM 实现链路追踪
    ElasticAPM部署访问ElasticAPM由四个基本组件构成:APMAgents:各个语言的客户端程序,一系列开源库,用于连接APMServerAPMServerElasticsearchKibanaAPMServer......
  • .net core在centos上使用libgdiplus库图像处理
    #Seehttps://aka.ms/containerfastmodetounderstandhowVisualStudiousesthisDockerfiletobuildyourimagesforfasterdebugging.FROMmcr.microsoft.com/......
  • Mininet 第一周
    Mininet是一个可以在有限资源的普通电脑上快速建立大规模SDN原型系统的网络仿真工具。该系统由虚拟的终端节点(End-Host)、OpenFlow交换机、控制器(也支持远程控制器)组成,这使......
  • 《ASP.NET Core技术内幕与项目实战》精简集-目录
    本系列是杨中科2022年最新作品《ASP.NETCore技术内幕与项目实战》及B站配套视频(强插点赞)的精简集,是一个读书笔记。总结和提炼了主要知识点,遵守代码优先原则,以利于快速复习......