Sunday, July 8, 2018

Activer/Désactiver le pare-feu (firewall) Windows

Il suffit d'adapter ce code pour le lancer avec psexec. 2 solutions :
- copier un fichier *.bat sur la machine et l'exécuter
- lancer le code en ligne

Code pour activer ou désactiver le firewall (fonctionne sur Windows Vista et supérieur)

Commande Netsh :
:: Source : SANS.ORG - SEC05 - Securing Windows and PowerShell Automation course - scripts@ECHO OFF
:: Securing Windows Track :: SANS Institute :: Jason Fossen
:: This is for the firewall in Windows Vista, Server 2008 and later only (not XP).
:: Disables the firewall for all profiles.
netsh.exe advfirewall set allprofiles state off
:: Enables the firewall for all profiles.
netsh.exe advfirewall set allprofiles state on

Powershell :
Run as Administrator > cmd.exe 
# Pour désactiver
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -Command "& {Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False}"
# Pour Activer 
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -Command "& {Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False}"