Advertisement
Guest User

Untitled

a guest
Jul 4th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' cscript service-list.vbs
  2.  
  3. option explicit
  4.  
  5. Dim InterfaceArray
  6. Dim LowerBound
  7. Dim UpperBound
  8. Dim iterate
  9. Dim rule
  10.  
  11. 'Protocol
  12. Const NET_FW_IP_PROTOCOL_TCP = 6
  13. Const NET_FW_IP_PROTOCOL_UDP = 17
  14. Const NET_FW_IP_PROTOCOL_ICMPv4 = 1
  15. Const NET_FW_IP_PROTOCOL_ICMPv6 = 58
  16.  
  17. 'Action
  18. const NET_FW_ACTION_BLOCK = 0
  19. const NET_FW_ACTION_ALLOW = 1
  20.  
  21. 'Direction
  22. const NET_FW_RULE_DIR_IN = 1
  23. const NET_FW_RULE_DIR_OUT = 2
  24.  
  25. ' Profile Type
  26. Const NET_FW_PROFILE2_DOMAIN = 1
  27. Const NET_FW_PROFILE2_PRIVATE = 2
  28. Const NET_FW_PROFILE2_PUBLIC = 4
  29.  
  30. 'Create the FwPolicy2 object.
  31. Dim fwPolicy2
  32. Set fwPolicy2 = CreateObject("HNetCfg.FwPolicy2")
  33.  
  34. 'Get the Service Restriction object for the local firewall policy.
  35. Dim ServiceRestriction
  36. Set ServiceRestriction = fwPolicy2.ServiceRestriction
  37.  
  38. WScript.Echo( "HNetCfg.fwPolicy2.ServiceRestriction" )
  39.  
  40. 'If the service requires sending/receiving certain type of traffic, then add "allow" WSH rules as follows
  41. 'Get the collection of Windows Service Hardening networking rules
  42.  
  43. Dim Rulesobject
  44. Set Rulesobject = ServiceRestriction.Rules
  45.  
  46. WScript.Echo( " Service Rules Count : " & Rulesobject.count )
  47.  
  48. For Each rule In Rulesobject
  49.        
  50.         WScript.Echo("  Profile:          " & rule.Profiles)
  51.  
  52.  
  53.  
  54.         WScript.Echo("  Rule Name:          " & rule.Name)
  55.         WScript.Echo("   ----------------------------------------------")
  56.         WScript.Echo("  Description:        " & rule.Description)
  57.         WScript.Echo("  Application Name:   " & rule.ApplicationName)
  58.         WScript.Echo("  Service Name:       " & rule.ServiceName)
  59.         Select Case rule.Protocol
  60.             Case NET_FW_IP_PROTOCOL_TCP    WScript.Echo("  IP Protocol:        TCP.")
  61.             Case NET_FW_IP_PROTOCOL_UDP    WScript.Echo("  IP Protocol:        UDP.")
  62.             Case NET_FW_IP_PROTOCOL_ICMPv4 WScript.Echo("  IP Protocol:        UDP.")
  63.             Case NET_FW_IP_PROTOCOL_ICMPv6 WScript.Echo("  IP Protocol:        UDP.")
  64.             Case Else                      WScript.Echo("  IP Protocol:        " & rule.Protocol)
  65.         End Select
  66.         if rule.Protocol = NET_FW_IP_PROTOCOL_TCP or rule.Protocol = NET_FW_IP_PROTOCOL_UDP then
  67.             WScript.Echo("  Local Ports:        " & rule.LocalPorts)
  68.             WScript.Echo("  Remote Ports:       " & rule.RemotePorts)
  69.             WScript.Echo("  LocalAddresses:     " & rule.LocalAddresses)
  70.             WScript.Echo("  RemoteAddresses:    " & rule.RemoteAddresses)
  71.         end if
  72.         if rule.Protocol = NET_FW_IP_PROTOCOL_ICMPv4 or rule.Protocol = NET_FW_IP_PROTOCOL_ICMPv6 then
  73.             WScript.Echo("  ICMP Type and Code:    " & rule.IcmpTypesAndCodes)
  74.         end if
  75.         Select Case rule.Direction
  76.             Case NET_FW_RULE_DIR_IN  WScript.Echo("  Direction:          In")
  77.             Case NET_FW_RULE_DIR_OUT WScript.Echo("  Direction:          Out")
  78.         End Select
  79.         WScript.Echo("  Enabled:            " & rule.Enabled)
  80.         WScript.Echo("  Edge:               " & rule.EdgeTraversal)
  81.         Select Case rule.Action
  82.             Case NET_FW_ACTION_ALLOW  WScript.Echo("  Action:             Allow")
  83.             Case NET_FW_ACTION_BLOCk  WScript.Echo("  Action:             Block")
  84.         End Select
  85.         WScript.Echo("  Grouping:           " & rule.Grouping)
  86.         WScript.Echo("  Edge:               " & rule.EdgeTraversal)
  87.         WScript.Echo("  Interface Types:    " & rule.InterfaceTypes)
  88.         InterfaceArray = rule.Interfaces
  89.         if IsEmpty(InterfaceArray) then
  90.             WScript.Echo("  Interfaces:         All")
  91.         else
  92.             LowerBound = LBound(InterfaceArray)
  93.             UpperBound = UBound(InterfaceArray)
  94.             WScript.Echo("  Interfaces:     ")
  95.             for iterate = LowerBound To UpperBound
  96.                 WScript.Echo("       " & InterfaceArray(iterate))
  97.             Next
  98.         end if
  99.  
  100.         WScript.Echo("")
  101. Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement