windows中的服務隔離 service isolation and service SID(Virtual Account)

來源:互聯網
上載者:User

標籤:network   windows   service   

windows 中的服務隔離在windows vista 以及server 2008之後就有了,可以讓管理員控制本地資源的使用(如檔案、註冊表等等)。之前windows版本中,系統內建了一些高許可權的服務帳號,大家所熟悉的有Local System,Network,LocalService

 

為了最小化許可權使用,通常我們需要建立帳號來賦予最小許可權,然後佈建服務以這個帳號運行,但是如果服務較多,那麼有許許多多的帳號要維護,而且如果你有嚴格的密碼原則的話,比如定期要更改服務帳號的密碼,那真是頭疼。

window 中的Service SID(另外一個稱呼是Virutal Account) 可以針對每個服務啟用,它可以讓管理員針對Service SID來隔離服務使用的資源。同時不必維護服務帳號的密碼。Service SID 帳號訪問網路資源是使用的憑據是電腦帳號,DomainName\ComputerName$.

 

建立Service ID 可以使用

sc sidtype <service_name> unrestricted

sc sidtype <service_name> restricted

 

當然也可以使用sc qsidtype <serviec_name>來查詢Service SID ,我這裡針對微軟的SCOM Agent health service 服務進行查詢。

650) this.width=650;" title="c73fb824-d433-4e5c-9906-abf63bab90a1snip" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px" border="0" alt="c73fb824-d433-4e5c-9906-abf63bab90a1snip" src="http://s3.51cto.com/wyfs02/M02/86/69/wKioL1e-WbyTFOLnAAAOceOZ9yo810.png" "381" height="176" />

 

sidtype 有三種

  • None (0x0) – the service will not have a per-service SID.  服務預設設定為none
  • Unrestricted (0x1) – the service has a per-service SID  服務有一個service SID
  • Restricted (0x3) – the service has a per-service SID and a write-restricted token.服務有一個Service SID,同時加上了防寫保護 標籤。

當服務配置使用Service SID時(無論restricted 或unrestricted) ,Service SID是一串SHA1 Hash.如果想看這個SID的具體值,可以使用

sc showsid <servicename>

650) this.width=650;" title="c140be01-2a35-435b-b609-ef83cdacd1afsnip" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px" border="0" alt="c140be01-2a35-435b-b609-ef83cdacd1afsnip" src="http://s3.51cto.com/wyfs02/M02/86/69/wKiom1e-Wb3BgvDjAAAkvbkU4n4019.png" "630" height="172" />

 

然後我們看看wsearch 的執行帳號配置為本地系統帳號

650) this.width=650;" title="d7699158-e4ed-4a5f-a4c4-790520508de0snip" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px" border="0" alt="d7699158-e4ed-4a5f-a4c4-790520508de0snip" src="http://s3.51cto.com/wyfs02/M02/86/69/wKioL1e-Wb6z-Y_yAAAnFgrt9t8956.png" "472" height="310" />

那這個Service SID起了什麼作用呢,拿SQL Server為例,SQL Server 2008 r2 之前的版本會預設讓local system 帳號放在資料庫sysadmin 中,但是sql server 2012 之後就不放了,那麼之前如果你有個服務運行在local system 帳號,比如我們的SCOM監控服務訪問SQL應該是沒有許可權問題的,但是在sql server 2012 上,你可能需要額外設定,因為這個時候會沒有許可權。這個時候我假設你給SCOM監控用戶端服務啟用了Service SID ,那麼會在healthservice的服務進程上就會增加 nt service\healthservice 的令牌,這個時候如果你單獨在SQL中建立nt service\healthservice 的登入,並賦予相應許可權,那麼這個healthservice 雖然是運行在local system 帳號,但是他卻能訪問sql了。然後你可能還有另外的其他服務B也是以local system 帳號運行,但是這個sql 的許可權卻只給了healthservice 服務,這個服務B卻不能訪問SQL。(之前在沒有Service SID 的時候,你可能一股腦把許可權開給了local system ,然後所有使用local system 登陸的服務都有了訪問SQL 的許可權)。

 

那麼這個Service SID的實戰作用在哪裡呢?這就是這篇文章的終極目的。如果你用SCOM 監控SQL,那麼更高版本的SQL Server的執行帳號管理的問題,你可能已經很頭痛了。使用service SID 可以輕鬆解決這個問題,然後還有個人專門另外建立了管理組件,可以監視有SQL Server的機器上的healthservice 的Service SID有沒有開啟,然後可以用恢複任務來開啟(這個恢複任務預設是禁用的)。然後還可以監控healthservice 的SID帳號有沒有資料庫的許可權。參考這個連結:

https://gallery.technet.microsoft.com/SQL-Server-RunAs-Addendum-0c183c32#content

 

windows內建系統帳號許可權及作用參考:

  • LocalService account (preferred)

    • Name: NT AUTHORITY\LocalService
    • the account has no password (any password information you provide is ignored)
    • HKCU represents the LocalService user account
    • has minimal privileges on the local computer
    • presents anonymous credentials on the network
    • SID: S-1-5-19
    • has its own profile under the HKEY_USERS registry key (HKEY_USERS\S-1-5-19)

    A limited service account that is very similar to Network Service and meant to run standard least-privileged services. However, unlike Network Service it has no ability to access the network as the machine accesses the network as an Anonymous user.

  • NetworkService account

    • NT AUTHORITY\NetworkService
    • the account has no password (any password information you provide is ignored)
    • HKCU represents the NetworkService user account
    • has minimal privileges on the local computer
    • presents the computer‘s credentials (e.g. MANGO$) to remote servers
    • SID: S-1-5-20
    • has its own profile under the HKEY_USERS registry key (HKEY_USERS\S-1-5-20)
    • If trying to schedule a task using it, enter NETWORK SERVICE into the Select User or Groupdialog

    Limited service account that is meant to run standard least-privileged services. This account is far more limited than Local System (or even Administrator) but still has the right to access the network as the machine (see caveat above).

  • LocalSystem account (dangerous, don‘t use!)

    • Name: .\LocalSystem (can also use LocalSystem or ComputerName\LocalSystem)
    • the account has no password (any password information you provide is ignored)
    • SID: S-1-5-18
    • does not have any profile of its own (HKCU represents the default user)
    • has extensive privileges on the local computer
    • presents the computer‘s credentials (e.g. MANGO$) to remote servers

http://windowsitpro.com/security/q-how-can-security-windows-service-benefit-service-isolation-feature-how-can-i-set-service-

https://blogs.technet.microsoft.com/voy/2007/03/22/per-service-sid/

https://support.microsoft.com/en-us/kb/2620201

http://thoughtsonopsmgr.blogspot.com/2014/09/sql-mp-challenge-run-as-accounts.html

windows中的服務隔離 service isolation and service SID(Virtual Account)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.