TUTOS.EU

Désactiver toutes les règles entrantes du Firewall

Désactiver toutes les règles entrantes du Firewall de Windows et sauvegarder leur nom dans un fichier

Par défaut le firewall bloque les flux. Par défaut également les règles que vous ajoutez les autorisent.

Pour bien prendre la main sur les règles du firewall, le script ci-dessous désactive toutes les règles entrantes du Firewall excepté celles concernant le "core". Il sauvegarde également le nom de toutes les règles qui ont été désactivés dans un fichier texte.

#powershell -command "C:\NomDuScript.ps1"
#Get-Command *-*firewall*
Clear-host


$MyLine = [string]
$NomFichierACreer = [string]

$EmplacementFichier = "C:\ListeDesPolices.txt"
$MonFichier = New-Item -type file $EmplacementFichier -Force #Création du fichier vierge

Import-Module NetSecurity

#$MesReglesFW = Get-netfirewallrule #| format-table name, displaygroup, action, direction, enabled -autosize
$MesReglesFW = Get-netfirewallrule | where {($_.enabled -EQ "True") -and ($_.direction -EQ "Inbound") -and ($_.DisplayName -like "Core*" -eq $false)}
#$MesReglesFW |gm

foreach ($UneLigne in $MesReglesFW){
	Write-Host "$($UneLigne.DisplayName) : $($UneLigne.Enabled) : $($UneLigne.direction)"
	#$MyLine = "$($UneLigne.DisplayName) : $($UneLigne.Enabled)"
	$MyLine = "$($UneLigne.DisplayName)"
	add-content $MonFichier $MyLine
	Set-NetFirewallRule -DisplayName $UneLigne.DisplayName -Enabled False
}
Lien vers le fichier : cliquez ici Copier le code

Ensuite vous pouvez très bien autoriser tout le traffic sur une plage d'adresse IP donnée, soit la votre :

New-NetFirewallRule -DisplayName "Tout authoriser en local" -Action Allow -Direction Inbound -RemoteAddress 192.168.0.0/16
Lien vers le fichier : cliquez ici Copier le code

Pour activer et configurer le log des firewalls vous pouvez utiliser ces commandes

netsh advfirewall set allprofiles state on
netsh advfirewall set allprofiles logging filename C:\pfirewall.log
netsh advfirewall set allprofiles logging maxfilesize 8192
netsh advfirewall set allprofiles logging droppedconnections enable
netsh advfirewall set allprofiles logging allowedconnections disable
Lien vers le fichier : cliquez ici Copier le code

Sur un serveur fraichement déployé, désactiver toutes les règles entrantes (y compris celle dont le nom commence par "Core") correspond à désactiver ces règles :

Windows Remote Management (HTTP-In)
Windows Remote Management (HTTP-In)
Core Networking - Destination Unreachable (ICMPv6-In)
Core Networking - Packet Too Big (ICMPv6-In)
Core Networking - Time Exceeded (ICMPv6-In)
Core Networking - Parameter Problem (ICMPv6-In)
Core Networking - Neighbor Discovery Solicitation (ICMPv6-In)
Core Networking - Neighbor Discovery Advertisement (ICMPv6-In)
Core Networking - Router Advertisement (ICMPv6-In)
Core Networking - Router Solicitation (ICMPv6-In)
Core Networking - Multicast Listener Query (ICMPv6-In)
Core Networking - Multicast Listener Report (ICMPv6-In)
Core Networking - Multicast Listener Report v2 (ICMPv6-In)
Core Networking - Multicast Listener Done (ICMPv6-In)
Core Networking - Destination Unreachable Fragmentation Needed (ICMPv4-In)
Core Networking - Internet Group Management Protocol (IGMP-In)
Core Networking - Dynamic Host Configuration Protocol (DHCP-In)
Core Networking - Dynamic Host Configuration Protocol for IPv6(DHCPV6-In)
Core Networking - Teredo (UDP-In)
Core Networking - IPHTTPS (TCP-In)
Core Networking - IPv6 (IPv6-In)
Firefox (C:\Program Files (x86)\Mozilla Firefox)
Firefox (C:\Program Files (x86)\Mozilla Firefox)
Remote Desktop - Shadow (TCP-In)
Remote Desktop - User Mode (UDP-In)
Remote Desktop - User Mode (TCP-In)
File and Printer Sharing (LLMNR-UDP-In)
File and Printer Sharing (Echo Request - ICMPv6-In)
File and Printer Sharing (Echo Request - ICMPv4-In)
File and Printer Sharing (Spooler Service - RPC-EPMAP)
File and Printer Sharing (Spooler Service - RPC)
File and Printer Sharing (NB-Datagram-In)
File and Printer Sharing (NB-Name-In)
File and Printer Sharing (SMB-In)
File and Printer Sharing (NB-Session-In)
File Server Remote Management (WMI-In)
File Server Remote Management (DCOM-In)
File Server Remote Management (SMB-In)
Lien vers le fichier : cliquez ici Copier le code

2