Protect / Defend – Windows – Firewall

 

List and toggle profile state

 

1.     List all firewall rules

netsh advfirewall firewall show rule name=all > firewall_rules.txt





2.     View current profile state

netsh advfirewall show currentprofile

A screenshot of a computer

Description automatically generated

3.     Change inbound policy

netsh advfirewall set currentprofile firewallpolicy blockinboundalways,allowoutbound

netsh advfirewall show currentprofile



4.     Toggle profiles off/on

netsh advfirewall set allprofile state off


A black screen with white text

Description automatically generated

A screenshot of a computer error

Description automatically generated
netsh advfirewall set allprofile state on

A black screen with white text

Description automatically generated
A screenshot of a computer

Description automatically generated
NOTE: You can toggle individual profiles as well:

netsh advfirewall set publicprofile state off/on
netsh advfirewall set privateprofile state off/on
netsh advfirewall set domainprofile state off/on

Creating Rules

1.     Allow OpenSSH in for SFTP from anywhere.

netsh advfirewall firewall add rule name="OpenSSH SSH Server (sshd)" dir=in action=allow protocol=tcp localport=22

A black screen with white text

Description automatically generated

2.     Allow OpenSSH in for SFTP from specific IP

netsh advfirewall firewall add rule name="OpenSSH SSH Server (sshd)" dir=in action=allow protocol=tcp localport=22 remoteip=172.16.99.19

A black screen with white text

Description automatically generated

Note: You can also specify an entire subnet in the “remoteip=” parameter ex: 172.16.99.0/24

Deleting Rules

1.     Remove OpenSSH in for SFTP from specific IP

netsh advfirewall firewall delete rule name="OpenSSH SSH Server (sshd)"

A black screen with white text

Description automatically generated

Logging

1.     Enable logging dropped connections

netsh advfirewall set currentprofile logging droppedconnections enable
A screen shot of a computer

Description automatically generated

2.     Enable logging allowed connections

netsh advfirewall set currentprofile logging allowedconnections enable

A screen shot of a computer

Description automatically generated

3.     Check the logs

Navigate: “%systemroot%system32\logfiles\firewall\pfirewall.log”

A screenshot of a computer error

Description automatically generated

A screenshot of a computer

Description automatically generated