【问题标题】:Windows Defender - Add exclusion folder programmaticallyWindows Defender - 以编程方式添加排除文件夹
【发布时间】:2017-03-07 02:22:15
【问题描述】:

我出于研究目的检查了不同的键盘记录器,然后偶然发现了 Refog:

https://www.refog.com/keylogger/

这个程序可以捕捉到很多系统事件,但真正引起我注意的是别的东西。该程序创建了一个名为 Mpk 的隐藏文件夹,路径为 C:\Windows\SysWOW64\Mpk。它被标记为操作系统文件夹,因为在我取消标记Hide protected operating system files (recommended) 之前它是不可见的。我想,这可以通过attrib +s +h "C:\Windows\SysWOW64\Mpk" 这样的 attrib 命令来完成,所以没有什么革命性的。

但是,他们还为此文件夹添加了 Windows Defender 的排除项。他们如何以编程方式做到这一点?我正在运行 Windows 10 Pro x64。

【问题讨论】:

    标签: windows windows-10 windows-defender


    【解决方案1】:

    只是想我会发布这个,因为它确实花了我几秒钟的时间来弄清楚如何在 C# 中执行此操作,但这里是为我工作的代码:

            var elevated = new ProcessStartInfo("powershell")
            {
                UseShellExecute = false,
                CreateNoWindow = true,
                Verb = "runas",
                Arguments = " -Command Add-MpPreference -ExclusionPath '" + directory + "'"
            };
            Process.Start(elevated);
    

    【讨论】:

      【解决方案2】:

      在提升的 shell 中运行(在开始菜单中搜索 cmd 并点击 Ctrl+Shift+Enter)。

      powershell -Command Add-MpPreference -ExclusionPath "C:\tmp"
      powershell -Command Add-MpPreference -ExclusionProcess "java.exe"
      powershell -Command Add-MpPreference -ExclusionExtension ".java"
      
      powershell -Command Remove-MpPreference -ExclusionExtension ".java"
      

      【讨论】:

      • 考虑它可能带来的风险:如果你真的排除了所有Temp文件夹,每个应用程序都可以下载可疑文件,你将不会再收到通知。
      • 你是对的。只要不是系统临时文件夹就可以了。
      • 添加 java.exe 排除是严重的安全威胁!
      • 我喜欢您显示添加删除排除项的方式,并指出正确的文档。我用它来从 Chocolatey 安装 NirLauncher,暂时排除了 Chocolatey 目录(位于当前用户的 %TEMP% 下:不是永久允许的位置。排除:powershell -Command Add-MpPreference -ExclusionPath "%TEMP%\chocolatey\NuGetScratch" 安装:choco update --yes nirlauncher 删除排除:@ 987654329@ "%TEMP%\chocolatey\NuGetScratch"`
      • 对于那些抱怨安全风险的人:这些只是例子!很有用,因为它报告了三个案例和删除案例。
      【解决方案3】:

      转到powershell

      Add-MpPreference -ExclusionPath "C:\Temp"

      参考: https://docs.microsoft.com/en-us/powershell/module/defender/add-mppreference?view=win10-ps

      【讨论】:

      • 考虑它可能带来的风险:如果你真的排除了所有Temp文件夹,每个应用程序都可以下载可疑文件,你将不会再收到通知。
      【解决方案4】:

      最简单的方法是在 CMD 中使用具有提升权限的 PowerShell(如 balrob's answer),但您也可以使用 PowerShell 环境变量让您的生活更轻松;例如:

      powershell -inputformat none -outputformat none -NonInteractive -Command Add-MpPreference -ExclusionPath $ENV:USERPROFILE\Downloads
      

      这将添加当前用户的下载文件夹,例如。 C:\Users\Susana\Downloads.

      要获取 PowerShell 提供的环境变量列表,可以使用以下 PowerShell 命令:

      Get-ChildItem Env: | Sort Name
      

      如您所见,有 windir 变量。除了您提到的子文件夹,他们还可以使用它。

      【讨论】:

        【解决方案5】:

        执行此操作的正确方法是使用 Add-MpPreference PowerShell cmdlet。使用此 cmdlet 可为文件扩展名、路径和进程添加排除项,并为高、中和低威胁添加默认操作。

        您可以使用以下命令行从 Windows 10 中提升的 cmd shell 轻松执行此操作:

        powershell -inputformat none -outputformat none -NonInteractive -Command Add-MpPreference -ExclusionPath "C:\Windows\SysWOW64\Mpk"
        

        【讨论】:

        • 工作得很好,但是如果文件路径中有空格,则需要对命令进行转义,如下所示:powershell -inputformat none -outputformat none -NonInteractive -Command "Add-MpPreference -ExclusionPath 'C:\Program Files (x86)\sysconfig'"
        • 请问我怎样才能用多个路径做到这一点? @balrob
        • 一个逗号分隔的列表(逗号周围没有空格)应该这样做,例如-ExclusionPath 'path1','path2'
        • 使用以下命令确认更改:powershell -inputformat none -outputformat text -NonInteractive -Command Get-MpPreference
        • .. 或检查其中的 Windows Defender 设置配置以查看更改。
        【解决方案6】:

        经过一番挖掘,我找到了以下文件夹:

        HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths
        

        我无法向我的用户添加密钥。我收到以下错误:Cannot create key: You do not have the requisite permissions to create a new key under Paths

        但是 SYSTEM、WinDefend 和 TrustedInstaller 都有完全控制。最好的猜测是他们使用了 DevxExec devxexec.exe /user:TrustedInstaller cmd 之类的东西并将密钥写入注册表。

        【讨论】:

        • 没有。每个用户都有自己的注册表。
        猜你喜欢
        • 2019-03-19
        • 2012-07-13
        • 2021-11-19
        • 2014-06-11
        • 1970-01-01
        • 2022-01-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多