Filtering by service name RRS feed

  • Question

  • I would like to make WFP filter with Win32 Service name as condition. This seems to work fine for some services e.g. Windows Update. However, if I create filter that sould block 'Print Spooler' service traffic, printing to network printer still succeeds. Results are same for the filter created programmatically or through Windows Firewall UI. For the printing case, using application path (%SystemRoot%\system32\spoolsv.exe) as filter condition works. But in same use cases using service name would be more convenient.

    Below is my filter. Any idea what I am doing wrong?

    C:\Windows\System32>sc showsid Spooler

    NAME: Spooler
    SERVICE SID: S-1-5-80-3951239711-1671533544-1416304335-3763227691-3930497994

    							<name>block spooler</name>
    						<filterCondition numItems="1">

    -- Antti

    Tuesday, April 3, 2012 7:43 AM

All replies

  • You need to use sc.exe qsidtype <serviceName>.  If the SERVICE_SID_TYPE is NONE, then the sid will not be present in the service's process token.

    This is from Win8:

       C:\>sc qsidtype spooler
       [SC] QueryServiceConfig2 SUCCESS

       SERVICE_NAME: spooler

    This is from Win7:

       [SC] QueryServiceConfig2 SUCCESS

       SERVICE_NAME: spooler

    Which OS are you using?

    Dusty Harper [MSFT]
    Microsoft Corporation
    This posting is provided "AS IS", with NO warranties and confers NO rights

    Thursday, April 5, 2012 5:13 PM
  • I have tried this mainly on Windows 7. I tested this on Windows 8 too, with a quick test works same way as in Windows 7.

    I doubt that SERVICE_SID_TYPE is the root cause in this case. SERVICE_SID_TYPE is UNRESTRICTED for both spooler and Windows Update (wuauserv) services. wuauserv can be blocked, spooler can't.

    C:\>sc qsidtype spooler
    [SC] QueryServiceConfig2 SUCCESS

    SERVICE_NAME: spooler

    C:\>sc qsidtype wuauserv
    [SC] QueryServiceConfig2 SUCCESS

    SERVICE_NAME: wuauserv

    -- Antti

    Tuesday, April 10, 2012 12:04 PM
  • Block by service name uses Service SID as filtering condition. There are cases when a service impersonates when it binds to the socket. In such cases, traffic is sent in context of user and SID that is being examined by WFP is the user's SID and not the service SID. Hence block by service name doesnt work. May be this happens in case of spooler svc. For wuauserv, it doesnot impersonate so the rule by service name seems to work.
    Friday, April 13, 2012 11:33 AM
  • I tried with simple Win32 service, running under Local System account, no impersonations, just opening a normal sokcet. WFP didn't block the connection. Process Explorer's TCP/IP tab also shows my service name with the socket.

    Could it be that filtering only works for services running as Network Service account?

    -- Antti

    Wednesday, April 18, 2012 3:08 PM