SkillPilotAI

netsh advfirewall (2/2)

A firewall rule only says allow or block; an IPsec (connection security) rule makes both computers prove their identity first and then encrypts the traffic. Part 2 covers the consec, mainmode and monitor contexts of netsh advfirewall.

114.1 What consec, mainmode and monitor do

ContextHolds
consecConnection security (IPsec) rules: auth + encryption
mainmodeIKE main mode (phase 1) rules: key exchange
monitorLive state and SAs (security associations)
  • Windows only, elevated prompt; on Linux the same job is done by strongSwan and ip xfrm.
  • The video ran only help/show commands on a non-elevated Windows 11 PC, so nothing was changed.

114.2 How IPsec works: main mode then quick mode

IPsec between client PC and file server
  1. 1.Client 192.168.134.10 and file server 192.168.134.20 both have a consec rule

  2. 2.IKE main mode (UDP 500): peers authenticate with Kerberos or a certificate

  3. 3.Main mode SA ready: a secure channel

  4. 4.IKE quick mode: agree ESP aes256 + sha256 keys

  5. 5.Quick mode SA ready

  6. 6.Data travels as ESP (IP proto 50), payload encrypted

Action requireinrequestout in practice
  1. 1.Guest laptop 192.168.134.66 has no domain credential

  2. 2.Sends plain SMB (TCP 445) to the file server

  3. 3.Server requires inbound auth: packet dropped

  4. 4.Server talking out to such a device only requests auth

  5. 5.Auth fails, outbound traffic still goes in clear

114.3 consec add rule: core parameters (20)

Terminal
netsh advfirewall consec add rule ?
Output
Usage: add rule name=<string>  endpoint1=any|localsubnet|dns|dhcp|wins|defaultgateway|  endpoint2=any|localsubnet|dns|dhcp|wins|defaultgateway|  action=requireinrequestout|requestinrequestout|     requireinrequireout|requireinclearout|noauthentication  [mode=transport|tunnel (default=transport)]  [type=dynamic|static (default=static)]  [protocol=0-255|tcp|udp|icmpv4|icmpv6|any (default=any)]Remarks:  - Rule name should be unique and cannot be "all".  - requireinclearout is not valid when mode=Transport.  - At least one authentication must be specified.
actionInboundOutbound
requireinrequestout (default)Auth requiredAuth requested (clear if it fails)
requestinrequestoutRequestedRequested
requireinrequireoutRequiredRequired
requireinclearoutRequiredClear (tunnel mode only)
noauthenticationExempt from IPsecExempt from IPsec
Output
name=IsoRule                unique, not "all"endpoint1/2=any|localsubnet|dns|IP|subnetmode=transport|tunnel       default transportlocaltunnelendpoint=1.1.1.1  remotetunnelendpoint=2.2.2.2   (tunnel mode)enable=yes|no  profile=domain,private  type=static|dynamic  description=textport1=any port2=3389  protocol=tcpinterfacetype=lan|wireless|ras|any

114.4 Authentication: auth1 / auth2 (26)

  • auth1 = first round, verifies the computer (Kerberos, certificate, PSK, NTLM).
  • auth2 = optional second round, verifies the user.
  • A pre-shared key is stored in plain text in the rule: fine only for a lab.
Output
auth1=computerkerb        Kerberos (domain)auth1=computercert        + auth1ca="CN=.."auth1=computercertecdsap256 | computercertecdsap384auth1=computerpsk auth1psk="S3cretKey"   (plain text: lab only)auth1=computerntlm        not with pskauth1=anonymous           no authauth1kerbproxyfqdn=kproxy.example.com   auth1healthcert=yesauth2=userkerb | userntlm | usercert | usercertecdsap256 | usercertecdsap384auth2=computercert        (not with user methods)auth2=anonymous  auth2ca / auth2ecdsap256ca / auth2ecdsap384ca
Output
Add a rule with CA name:netsh advfirewall consec add rule name="cert rule"endpoint1=any endpoint2=any action=requireinrequestoutauth1=computercert auth1ca="C=US, O=MSFT, CN=\'Microsoft North, South, East, and West Root Authority\'"- The " characters within CA name must be replaced with \'- For auth1ca and auth2ca, the CA name must be prefixed by 'CN='.

114.5 Certificate options inside the CA string (17)

Output
auth1ca="CN=\'Contoso Root CA\' <options>"certmapping:yes|no         cert to accountexcludecaname:yes|no       auth1ca onlycatype:root|intermediate   default rootcerthash:<hex>             no 0x, no spacesfollowrenewal:yes          needs certhashcerteku:1.3.6.1.5.5.7.3.1,...   EKU OIDscertname:host1 certnametype:SubjectAltDNS|SubjectAltEmail|SubjectCN|SubjectOU|SubjectO|SubjectDCcertcriteriatype:Selection|Validation|Both   default Bothmultiple certificates: separate with |
  • catype: root or intermediate CA; certhash pins one exact certificate (thumbprint).
  • certeku and certname filter which certificates are accepted; certcriteriatype says selection, validation or both.

114.6 Quick mode crypto and tunnel options (15)

Output
qmpfs=none                 default, no PFSqmpfs=dhgroup1|dhgroup2|dhgroup14|dhgroup24|ecdhp256|ecdhp384qmpfs=mainmode             use MM key exchangeqmsecmethods=esp:sha256-aes256qmsecmethods=ah:sha1+esp:sha1-aes256+60min+20480kb   (with lifetime)qmsecmethods=esp:aesgcm256-aesgcm256qmsecmethods=authnoencap:sha1    no encryptionqmsecmethods=defaultexemptipsecprotectedconnections=yes   (tunnel)applyauthz=yes                         (tunnel authz)
  • qmsecmethods = ESP/AH integrity + encryption with a key lifetime.
  • qmpfs runs a fresh Diffie-Hellman for every new key (perfect forward secrecy).
  • Avoid DES, MD5 and DH group 1.

114.7 consec delete, set and show

Terminal
netsh advfirewall consec delete rule ?
Output
Usage: delete rule name=<string>  [type=dynamic|static]  [profile=public|private|domain|any[,...] (default=any)]  [endpoint1=any|localsubnet|dns|dhcp|wins|defaultgateway|  [endpoint2=any|localsubnet|dns|dhcp|wins|defaultgateway|  [port1=0-65535|<port range>[,...]|any (default=any)]  [port2=0-65535|<port range>[,...]|any (default=any)]  [protocol=0-255|tcp|udp|icmpv4|icmpv6|any]  - If multiple matches are found, all matching rules are deleted.Examples:  netsh advfirewall consec delete rule name="rule1"  netsh advfirewall consec delete rule name=all type=dynamic
Terminal
netsh advfirewall consec set rule ?
Output
Usage: set rule  group=<string> | name=<string>  [type=dynamic|static]  [profile=public|private|domain|any[,...] (default=any)]  new  [name=<string>]  [action=requireinrequestout|requestinrequestout|  [enable=yes|no]  - Values after the new keyword are updated in the rule.  If there are    no values, or keyword new is missing, no changes are made.  - A group of rules can only be enabled or disabled.  netsh advfirewall consec set rule name="rule1" new  name="rule2"
Terminal
netsh advfirewall consec show rule ?netsh advfirewall consec show rule name=all
Output
Usage: show rule name=<string>  [profile=public|private|domain|any[,...]]  [type=dynamic|static (default=static)]  [verbose]$ netsh advfirewall consec show rule name=allThe requested operation requires elevation (Run as administrator).
  • Even reading IPsec rules needs elevation; dynamic rules need type=dynamic.

114.8 mainmode context (IKE phase 1)

Terminal
netsh advfirewall mainmode ?netsh advfirewall mainmode add rule ?
Output
Commands in this context:add            - Adds a new mainmode rule.delete         - Deletes all matching mainmode rules.dump           - Displays a configuration script.set            - Sets new values for properties of an existing rule.show           - Displays a specified mainmode rule. $ netsh advfirewall mainmode add rule ?Usage: add rule name=<string>  mmsecmethods=dhgroup1|dhgroup2|dhgroup14|dhgroup24|ecdhp256|  ecdhp384:3des|des|aes128|aes192|aes256-md5|sha1|sha256  |sha384[,...]|default  [mmforcedh=yes|no (default=no)]  [mmkeylifetime=<num>min,<num>sess]  - The minimum main mode keylifetime is mmkeylifetime=1min.    The maximum main mode mmkeylifetime= 2880min.  - The mmsecmethods keyword default sets the policy to:    dhgroup2-aes128-sha1,dhgroup2-3des-sha1
  • mmsecmethods is required; default = dhgroup2-aes128-sha1,dhgroup2-3des-sha1, which is weak today.
  • Main mode rules control the key exchange, not the data traffic.
Output
mmsecmethods=<keyexch>:<enc>-<integrity> keyexch: dhgroup1|2|14|24, ecdhp256|384 enc: 3des|des|aes128|aes192|aes256 integrity: md5|sha1|sha256|sha384mmsecmethods=dhgroup14:aes256-sha256mmforcedh=yes   mmkeylifetime=480min,0sessprofile=any|current|domain|private|public  endpoint1=192.168.1.0/24auth1=computerkerb|computercert|computerpsk  (no auth2 in main mode)delete rule name=test | name=all  [profile=domain] [type=dynamic]set rule name=test new name=test2 | new mmkeylifetime=60minshow rule name=all verbose     (real run: requires elevation)

114.9 monitor context: runtime state and SAs (25)

Terminal
netsh advfirewall monitor show ?netsh advfirewall monitor show qmsa
Output
show consec    - Displays current consec state information.show currentprofile - Displays the currently active profiles.show firewall  - Displays current firewall state information.show mainmode  - Displays current mainmode state information.show mmsa      - Displays the main mode SAsshow qmsa      - Displays the quick mode SAs.$ netsh advfirewall monitor show qmsaThe requested operation requires elevation (Run as administrator).
Output
show consec rule name=all profile=public   [verbose]show firewall rule name=all dir=in|out profile=activeshow mainmode rule name=all  [verbose]show mmsa | show mmsa all | show mmsa 192.168.0.3 192.168.0.4show qmsa | show qmsa all | show qmsa <src> <dst>delete mmsa all | delete mmsa <src> <dst>delete qmsa all | delete qmsa <src> <dst>
  • monitor shows live state, not configured rules.
  • delete qmsa all forces a fresh negotiation: the next packet builds a new SA.

114.10 Comparison: main mode vs quick mode

PointMain mode (IKE phase 1)Quick mode (phase 2)
JobAuthenticate peers, build secure channelAgree ESP/AH algorithms and keys for data
ResultMM SAQM SA
netshmainmode rules, mmsecmethodsconsec rule qmsecmethods, qmpfs
RenewalLess often (mmkeylifetime)More often (minutes / KB)
monitorshow mmsashow qmsa

114.11 Common mistakes

  • Thinking a consec rule opens a port: it only does auth + encryption; you still need a firewall add rule.
  • requireinrequestout on servers, then a non-domain Linux machine cannot connect: it cannot do Kerberos, so plain packets are dropped.
  • Using auth1=computerpsk in production (key in plain text).
  • Leaving mmsecmethods=default (DH group 2, 3DES, SHA1).

114.12 Interview tips

  • Main mode = peers authenticate, MM SA; quick mode = ESP/AH keys inside that channel, QM SA renews often.
  • consec = IPsec policy; firewall rule = allow/block. Both are needed.
  • requireinrequestout: inbound must authenticate, outbound only requests.
  • Check live SAs with netsh advfirewall monitor show mmsa / qmsa (elevated).