Reputation: 91
Im working on a Ducky Script winRM backdoor and to set winRM up, the User must be connected to a network on a Private connection. How can I automate this with powershell commands?
Get-NetConnectionProfile
shows all the currently connected network. I would like to make a loop that filters that output and puts every network name in this command Set-NetConnectionProfile -Name "NetworkName" -NetworkCategory Private
Upvotes: 2
Views: 16244
Reputation: 91
The Question is answered easily with the following:
Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private
Upvotes: 6
Reputation: 3168
Get-NetConnectionProfile only retrieves active connections.
If you truly want to change all connection profiles to Private here's some code I wrote to accomplish that task.
<#
.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
Name the file Set-AllNetworksPrivate.ps1 to match the comment based help.
Upvotes: 1