AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1757109
Accepted
brandeded
brandeded
Asked: 2022-12-10 19:29:22 +0800 CST2022-12-10 19:29:22 +0800 CST 2022-12-10 19:29:22 +0800 CST

如何在没有交互的情况下在 powershell.exe 中设置变量?

  • 772

我的 Windows 机器上发生了一件非常奇怪的事情。

不管我是否加载我的,启动时都会立即设置$profile一个名为的变量。$itempowershell.exe

我执行了以下操作:

  • 在调用-noprofile期间使用了开关。powershell.exe
  • 审查了由 加载的所有 DLL powershell.exe,并验证没有 DLL 是通过AppInit_DLLs键加载的。
  • 我powershell.exe从另一台没有出现问题的机器上复制了一个版本。
  • 我已经尝试作为另一个用户,并且该值仍然存在于该用户拥有的进程中。
  • 我列举了functions:PSdrive
  • 我在流程资源管理器中查看了环境变量。
  • 我已经查看了所有配置文件(在 中列出$profile | select *)

怎么可能$item一开机就设置powershell.exe?

windows
  • 1 1 个回答
  • 29 Views

1 个回答

  • Voted
  1. Best Answer
    Matt Cargile
    2022-12-10T20:33:26+08:002022-12-10T20:33:26+08:00

    我在使用版本22.1.2.217的Sentinel One XDR(例如 S1)时遇到了这个问题。它们将代码加载到会话中并污染全局变量命名空间。您可以在 Windows 中打开Powershell 日志记录以查看所有代码。我认为该功能称为agent.deepVisibility.scripts.powershell可以找到以Administrator身份运行命令行应用程序。以下是启用日志记录的摘录。SentinelCtl configure

    要启用自动转录,请通过管理模板 -> Windows 组件 -> Windows PowerShell 在组策略中启用打开 PowerShell 脚本块日志记录功能。

    Github上的这个问题详细介绍了代码。此外,有关 S1 脚本的一般信息也在此存储库中。第三,可以在链接到Twitter线程的 Github评论中找到少量信息。以下是玷污用户变量命名空间的适用代码。

    $local:Po_wer_Spl_oit_Indicators = (
        ("{0}{5}{4}{2}{3}{1}" -f 'Inv','ion','nje','ct','I','oke-Dll'),
        ("{6}{2}{3}{8}{1}{7}{5}{0}{4}" -f 'o','eP','nvoke-','Reflect','n','ecti','I','EInj','iv'),
        ("{1}{0}{3}{2}"-f'v','In','lcode','oke-Shel'),
        ("{0}{2}{3}{1}" -f'Invoke-','ommand','W','miC'),
        ("{5}{1}{3}{2}{4}{0}" -f 'd','t-E','a','ncodedComm','n','Ou'),
        ("{4}{0}{2}{3}{1}" -f 'ut-C','l','ompre','ssedDl','O'),
        ("{2}{3}{4}{1}{0}" -f't','p','Out-Encrypted','Sc','ri'),
        ("{0}{2}{3}{1}"-f 'Rem','t','ove-Comm','en'),
        ("{0}{3}{7}{6}{2}{4}{5}{1}"-f'New','ion','te','-User','n','ceOpt','is','Pers'),
        ("{3}{2}{5}{1}{0}{4}" -f'eOpt','istenc','w-Elevated','Ne','ion','Pers'),
        ("{2}{3}{0}{1}{4}"-f 'is','te','Ad','d-Pers','nce'),
        ("{0}{3}{2}{1}" -f'Install-','P','S','S'),
        ("{4}{0}{3}{2}{5}{1}" -f 't-S','s','ka','ecurityPac','Ge','ge'),
        ("{3}{2}{1}{0}"-f 'gnature','-AVSi','ind','F'),
        ("{6}{2}{3}{1}{0}{5}{4}"-f 'u','ip','voke-T','okenMan','ion','lat','In'),
        ("{0}{3}{2}{4}{5}{1}" -f'In','n','oke-C','v','re','dentialInjectio'),
        ("{1}{2}{0}{3}{4}" -f'Nin','I','nvoke-','jaCop','y'),
        ("{2}{0}{1}" -f'Mimika','tz','Invoke-'),
        ("{1}{2}{3}{0}" -f'rokes','Get','-Ke','yst'),
        ("{2}{4}{1}{3}{0}"-f'ord','PPP','Get','assw','-G'),
        ("{3}{2}{1}{0}" -f'on','log','GPPAuto','Get-'),
        ("{3}{1}{5}{0}{2}{4}"-f 'cr','d','e','Get-Time','enshot','S'),
        ("{2}{4}{0}{1}{5}{3}"-f'lumeS','had','N','y','ew-Vo','owCop'),
        ("{1}{0}{3}{2}"-f '-VolumeShad','Get','py','owCo'),
        ("{1}{2}{3}{5}{4}{0}"-f 'y','Mount-Vol','umeShad','o','op','wC'),
        ("{2}{3}{4}{1}{0}{5}"-f 'wCop','eShado','Remo','ve-','Volum','y'),
        ("{2}{3}{4}{0}{1}{5}"-f'i','a','Get-VaultC','red','ent','l'),
        ("{1}{3}{2}{0}"-f'p','Out-M','um','inid'),
        ("{4}{1}{2}{0}{3}" -f 'neAudi','et-Mi','cropho','o','G'),
        ("{3}{5}{2}{6}{0}{1}{4}"-f'oot','Rec','te','S','ord','et-Mas','rB'),
        ("{0}{2}{1}{3}"-f 'Set-Crit','calP','i','rocess'),
        ("{2}{0}{1}{3}"-f 'oke','-Po','Inv','rtscan'),
        ("{1}{3}{2}{0}"-f 'ttpStatus','G','H','et-'),
        ("{2}{3}{1}{0}"-f'DnsLookup','-Reverse','Invo','ke'),
        ("{1}{3}{2}{0}" -f'oup','Get-Pro','r','cessTokenG'),
        ("{2}{0}{1}"-f 'et-Syst','em','G'),
        ("{0}{4}{3}{2}{1}" -f'Invok','oast','er','b','e-Ker')
    )
    foreach ($item in $local:Po_wer_Spl_oit_Indicators) {
            Set-PSBreakpoint -Command $item -Action { <#sentinelbreakpoints#> . {
        $local:PreviousErrCount = $error.count
        try { '' | out-file ':::::\windows\sentinel\8' } catch {}
        while ($PreviousErrCount -ne $error.count) {
            $error.remove($error[0])
        }
        Remove-Variable PreviousErrCount -Scope local -Confirm:$false -WhatIf:$false} } | Out-Null
    };
    

    如果您想完全清除会话中的干扰,下面是一些代码。他们挂钩$PSDefaultParameterValues并减慢会话速度。此外,S1 中断了管道的使用Get-PSBreakpoint | Remove-PSBreakpoint。

    # VS Code doesn't have the same issue for some reason.
    if ($PSVersionTable.PSEdition -eq 'Desktop' -and $env:TERM_PROGRAM -ne 'vscode') {
        # Addition of breakpoints slow down the session. Calling fully qualified function to avoid using function override.
        Microsoft.PowerShell.Utility\Get-PSBreakpoint | Microsoft.PowerShell.Utility\Remove-PSBreakpoint
        # Software doesn't clean up these variables
        Remove-Variable -Name 'item', 'Po_wer_Spl_oit_Indicators' -ErrorAction 'Ignore'
        # Software overrides and hooks into these functions and breaks things. For instance, `gbp | rbp` doesn't work
        Remove-Item -Path 'Function:\Get-PSBreakpoint' -ErrorAction 'Ignore'
        Remove-Item -Path 'Function:\New-Object' -ErrorAction 'Ignore'
        Remove-Item -Path 'Function:\Set-ExecutionPolicy' -ErrorAction 'Ignore'
        Remove-Item -Path 'Function:\Remove-PSBreakpoint' -ErrorAction 'Ignore'
        Remove-Item -Path 'Function:\Disable-PSBreakpoint' -ErrorAction 'Ignore'
        Remove-Item -Path 'Function:\Enable-PSBreakpoint' -ErrorAction 'Ignore'
        # Other functions added that aren't needed
        Remove-Item -Path 'Function:\Disable-PSBreakpoint_Hook' -ErrorAction 'Ignore'
        Remove-Item -Path 'Function:\Enable-PSBreakpoint_Hook' -ErrorAction 'Ignore'
        Remove-Item -Path 'Function:\Get-PSBreakpoint_Hook' -ErrorAction 'Ignore'
        Remove-Item -Path 'Function:\New-Object_Hook' -ErrorAction 'Ignore'
        Remove-Item -Path 'Function:\Remove-PSBreakpoint_Hook' -ErrorAction 'Ignore'
        Remove-Item -Path 'Function:\Set-ExecutionPolicy_Hook' -ErrorAction 'Ignore'
    }
    
    • 2

相关问题

  • 如何在 Windows Precision 触摸板上禁用鼠标加速?

  • 批量重命名图像文件集

  • Python 的“pass”参数的批处理等价物是什么?

  • 在 Windows 上与 Docker 守护进程通信

  • 资源管理器侧面板中的桌面外壳快捷方式

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve