0

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

alessio
  • 31
  • 4
  • 1
    No need for a loop, just pipe to `Set-NetConnectionProfile`. – Abraham Zinala Aug 17 '22 at 21:36
  • 1
    you're right, this is embarrassingly easy. I'm just really new. – alessio Aug 17 '22 at 22:11
  • No worries, it happens. That should do what you need tho – Abraham Zinala Aug 18 '22 at 00:19
  • 1
    Just to play devil's advocate, do you understand the possible ramifications of changing public profiles to private? Private profiles are expected to be more secure and in return are often times less protected by firewall policies. Looping through users' connection profiles and changing their McDonalds and Starbucks profiles to private is generally not recommended. – Daniel Aug 18 '22 at 01:24
  • Yea, as I said, I use this in a script that activates winRM wich requires all active connections to be set to Private – alessio Aug 24 '22 at 07:40

2 Answers2

2

The Question is answered easily with the following:

Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private
alessio
  • 31
  • 4
1

Get-NetConnectionProfile only retrieves active connections. enter image description here

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.

RetiredGeek
  • 2,980
  • 1
  • 7
  • 21
  • Thank you for the code! But this was not in my scope as I only need to change all active connections. – alessio Aug 24 '22 at 07:41