Skip to content

Instantly share code, notes, and snippets.

@Flashwalker
Created September 9, 2021 15:23
Show Gist options
  • Save Flashwalker/18a43a68bc3a4451d004cd1f241014f1 to your computer and use it in GitHub Desktop.
Save Flashwalker/18a43a68bc3a4451d004cd1f241014f1 to your computer and use it in GitHub Desktop.
Block remote smb network in connections on Windows
::Set firewall on
netsh advfirewall set currentprofile state on
::Block in connections from all
netsh advfirewall firewall add rule name="blockSMBforeign_TCP-139" action=block protocol=TCP dir=in localport=139 remoteip=any
netsh advfirewall firewall add rule name="blockSMBforeign_TCP-445" action=block protocol=TCP dir=in localport=445 remoteip=any
::Allow only local connections from 192.16.0.0/16 subnet
netsh advfirewall firewall add rule name="allowSMB_0_0_16_TCP-139" action=allow protocol=TCP dir=in localport=139 remoteip=192.168.0.0/16
netsh advfirewall firewall add rule name="allowSMB_0_0_16_TCP-445" action=allow protocol=TCP dir=in localport=445 remoteip=192.168.0.0/16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment