【问题标题】:Change Network connection from Public to Private powershell oneliner将网络连接从公共更改为私有 powershell oneliner
【发布时间】:2022-08-24 15:45:43
【问题描述】:

我正在处理 Ducky Script winRM 后门并设置 winRM,用户必须通过专用连接连接到网络。如何使用 powershell 命令自动执行此操作?

Get-NetConnectionProfile 显示所有当前连接的网络。我想创建一个循环来过滤输出并将每个网络名称放入此命令Set-NetConnectionProfile -Name \"NetworkName\" -NetworkCategory Private

  • 不需要循环,只需管道到Set-NetConnectionProfile
  • 你是对的,这很容易令人尴尬。我真的很新。
  • 不用担心,它会发生。那应该做你需要的
  • 只是为了扮演魔鬼的拥护者,您了解将公开资料更改为私人资料的可能后果吗?私有配置文件预计会更安全,而作为回报,防火墙策略的保护通常会少很多倍。通常不建议循环访问用户的连接配置文件并将他们的麦当劳和星巴克配置文件更改为私人。
  • 是的,正如我所说,我在激活 winRM 的脚本中使用它,这需要将所有活动连接设置为 Private

标签: powershell network-programming duckyscript


【解决方案1】:

Get-NetConnectionProfile 仅检索活动连接。

如果您真的想将所有连接配置文件更改为私有,这里是我为完成该任务而编写的一些代码。

<#
.Synopsis
 Change all network profiles to PRIVATE!

.Description
 Change all network profiles to PRIVATE!

.Outputs
 N/A  

.Notes
   Programmer   : RetiredGeek (@askWoody.com) & 
                              (@stackoverflow.com) 
             aka: ComputerMentor
   Created      : 10 Aug 2022
   Last Updated : 10 Aug 2022
   Current Vers : 1.0

.Example
 [d:\path\]Set-AllNetworksPrivate.ps1

 Will set all networks as PRIVATE in the registry.

#>


# Two blank linea above required for Comment-Based Help

#----------------- Main Program ---------------------------

Clear-Host

Add-Type -AssemblyName "System.Windows.Forms"
$StatusMsg = {
  [Windows.Forms.MessageBox]::Show($Message, $Title,
  [Windows.Forms.MessageBoxButtons]::OK ,
  [Windows.Forms.MessageBoxIcon]::$Icon)}

#Setup Variables:

[Int32]$ErrorCnt  = 0  #Note: set to 1 to test error condition!
[Version]$PGMVers = '01.00.00'

$BaseRegPath = "HKLM:\SOFTWARE\Microsoft\"   +
                      "Windows NT\CurrentVersion\" +
                      "NetworkList\Profiles"

$NIPArgs = @{Name         = "Category"
             Value        = 1
             PropertyType = "DWord"
             Force        = $True
             ErrorAction  = "Stop"}

$GCIArgs = @{Path        = "$BaseRegPath"
             ErrorAction = "Stop"}

$Nets = Get-ChildItem @GCIArgs

ForEach ($Net in $Nets) {

  Try   { $Null = $Net | New-ItemProperty @NIPArgs }
  Catch { $ErrorCnt++ }

}

$Title = "Set-AllNetworksPrivate Vers: $PGMVers"
$Message = "Network Status: `n`n"
If ($ErrorCnt -eq 0) {
  $Message += "All profiles set to Private"
  $Icon     = "Information"
}
Else {
  $Message += "$ErrorCnt profile(s) NOT set to Private"
  $Icon     = "Warning"
}
$Null = & $StatusMsg

将文件命名为 Set-AllNetworksPrivate.ps1 以匹配基于注释的帮助。

【讨论】:

  • 谢谢你的代码!但这不在我的范围内,因为我只需要更改所有活动连接。
【解决方案2】:

这个问题很容易回答如下:

Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private

【讨论】:

    猜你喜欢
    • 2014-03-30
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-07
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多