Microsoft MVP성태의 닷넷 이야기
.NET Framework: 477. SeCreateGlobalPrivilege 특권과 WCF NamedPipe [링크 복사], [링크+제목 복사],
조회: 25082
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 4개 있습니다.)
(시리즈 글이 4개 있습니다.)
.NET Framework: 199. .NET 코드 - Named Pipe 닷넷 서버와 VC++ 클라이언트 제작
; https://www.sysnet.pe.kr/2/0/971

.NET Framework: 464. 프로세스 간 통신 시 소켓 필요 없이 간단하게 Pipe를 열어 통신하는 방법
; https://www.sysnet.pe.kr/2/0/1751

.NET Framework: 477. SeCreateGlobalPrivilege 특권과 WCF NamedPipe
; https://www.sysnet.pe.kr/2/0/1806

Linux: 20. C# - Linux에서의 Named Pipe를 이용한 통신
; https://www.sysnet.pe.kr/2/0/11964




SeCreateGlobalPrivilege 특권과 WCF NamedPipe

아래와 같은 질문이 있습니다.

WCF namedpipe 퍼블리싱 충돌 문제
; https://www.sysnet.pe.kr/3/0/1350

문제를 정리해 보면 대충 이렇습니다.

"A 프로그램"이 "net.pipe://localhost/servicename/{47280BB5-44EE-49F0-B440-F83878349985}\0" 주소로 WCF NamedPipe를 열었고 "B 프로그램"에서 해당 주소로 WCF NamedPipe 연결을 할 수 있습니다.

하지만, "(NT 서비스로 등록된) C 프로그램"이 "net.pipe://localhost/0" 주소로 WCF NamedPipe를 열었는데, 이후로 "B 프로그램"에서 "A 프로그램"으로의 NamedPipe 접속이 안됨.


그러면서, 재현할 수 있는 최소한의 예제 코드를 올려주었기 때문에 금방 문제를 확인할 수 있었습니다. 실제로 "C 프로그램"이 뜬 상태에서 "B 프로그램"의 접속 시도 시 발생하는 예외는 다음과 같습니다.

C:\temp\wcf test client\bin\Debug>"wcf test client.exe"

Unhandled Exception: System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at net.pipe://localhost/anothersevice/{47280BB5-44EE-49F0-B440-F83878349985}/identifier that could accept the message. This is often causedby an incorrect address or SOAP action. See InnerException, if present, for more details.

Server stack trace:
   at System.ServiceModel.Channels.ConnectionUpgradeHelper.DecodeFramingFault(ClientFramingDecoder decoder, IConnection connection, Uri via, String contentType, TimeoutHelper& timeoutHelper)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)
   at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
   at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at AnotherService.IAnotherService.Hello()
   at wcf_test_client.Program.Main(String[] args) in e:\...\wcf test client\Program.cs:line 25

게다가... 질문하신 분이 stackoverflow.com의 Q&A 하나를 소개까지 했는데요. ^^

3rd party app breaks our WCF application
; http://stackoverflow.com/questions/15981392/3rd-party-app-breaks-our-wcf-application/15987095#15987095

그렇습니다. 질문은 이렇게 해주셔야 ^^ 저도 답변하는 데 흥이 납니다.




일단, 현상을 보니까 "A 프로그램"을 "관리자 권한"으로 실행하면 "C 프로그램"과 상관없이 "B 프로그램"에서 연결이 잘 됩니다. 결국 해답은 "3rd party app breaks our WCF application" 글에 포함되어 있습니다.

Administrators 그룹의 계정과 서비스 계정은 기본적으로 "SeCreateGlobalPrivilege" 특권이 허용되어 있기 때문에, 관리자 권한으로 승격한 경우와 NT 서비스들의 경우에는 해당 EXE 프로세스에 다음과 같이 "SeCreateGlobalPrivilege" 특권이 추가되어 있습니다.

wcf_namedpipe_namespace_0.png

이 특권이 있는 상태에서 NamedPipe를 만들면 "전역 네임스페이스"에 커널 객체의 이름이 등록됩니다.

그래서, 다시 문제를 정리해 보면,

"A 프로그램"은 "Local 네임스페이스"에 WCF NmaedPipe 주소를 등록하고 서비스 시작
"B 프로그램"은 "전역 네임스페이스"에 등록된 WCF NamedPipe 주소를 먼저 검색하고,
               없으면, "Local 네임스페이스"에 등록된 WCF NamedPipe 주소를 검색하고, 있으면 연결.

이렇게 동작하고 있는데, "C 프로그램"에서 "전역 네임스페이스"로 "A 프로그램"이 열었던 pipe 주소를 포함하는 형식의 주소가 사용되면, 이제 "B 프로그램"의 서비스 검색이 "전역 네임스페이스" 단계에서 조건을 만족하는 이름 규칙이 있으므로 거기로 연결을 시도한 것입니다. 하지만, "A 프로그램"을 "관리자 권한"으로 실행하면 "A 프로그램"의 NamedPipe 이름이 "전역 네임스페이스"에 등록되므로 정상적으로 "B 프로그램"이 서비스로 연결을 합니다.

(일단, 위의 동작은 마이크로소프트 문서에서 찾은 것은 아니고... 그냥 실행을 통해 찾아낸 현상이 그런 것입니다.)




그렇다면, 의문이 하나 있습니다. 현재 로그인 계정이 "Administrators"에 속해 있는데, 왜? '관리자 권한'으로 승격시켜야만 하느냐입니다. 이에 대해서는 아래의 글에서 예전에 설명한 것이 도움이 되는데요.

UAC 이모저모
; https://www.sysnet.pe.kr/2/0/449

"
UAC는 "filtered standard user access token", "full access token"의 2가지 access token을 관리.

윈도우즈 특권의 경우, 제한 목록에 있는 RID 값을 소유한 계정이 로그인한 경우 생성되는 "filtered standard user access token" 은 다음의 특권을 제외한 모든 특권들이 제거된다.

  • SeChangeNotifyPrivilege
  • SeShutdownPrivilege
  • SeUndockPrivilege
  • SeReserveProcessorPrivilege
  • SeTimeZonePrivilege
"


따라서, 로그인한 계정은 "Administrators"에 속해있어도 UAC 환경에서는 '관리자 권한'으로 승격되지 않은 상태에서는 "filtered standard user access token"을 가지고 있으므로 이 중에는 "SeCreateGlobalPrivilege" 권한을 소유할 수 없기 때문에 그런 현상이 발생하는 것입니다.




이쯤에서, 문제에 대한 해결책은 이렇게 정리됩니다.

  • WCF NamedPipe 사용 코드는, "관리자 그룹"에 속한 사용자를 관리자 권한으로 실행시키거나,
  • 또는, "NT 서비스"에서 NamedPipe를 열어서 사용

위의 2가지 방법 이외에는, 네임스페이스 검색 우선 순위에 따라 WCF의 연결 문제를 해결할 수 없습니다.




참고로, 경우에 따라 "Administrators"에 속하지 않은 사용자가 로그인할 수도 있는데요. 이런 경우에는 해당 사용자 계정 내에서는 아무리 용을 써도 "SeCreateGlobalPrivilege" 특권을 가질 수 없습니다. 이 특권을 가지려면, 사용자가 분명하게 허용해야 합니다. 이를 위해 "gpedit.msc"에서 "Computer Configuration(컴퓨터 구성)" / "Windows Settings(설정)" / "Security Settings(보안 설정)" / "Local Policies(로컬 정책)" / "User Rights Assignment(사용자 권한 할당)"에서 "Create global objects(전역 개체 만들기)" 정책에 다음과 같이 사용자 계정을 포함시킵니다.

wcf_namedpipe_namespace_1.png

이렇게 해줘야만, "Administrators" 그룹에 속하지 않은 사용자 계정에서 WCF NamedPipe 등록을 전역 개체로 할 수 있습니다.




혹시나 싶어서,

Process Privileges
; http://processprivileges.codeplex.com/

위의 코드를 사용해서 "filtered standard user access token" 상태의 EXE 프로세스에서 SeCreateGlobalPrivilege 특권을 활성화하려고 했지만,

Process process = Process.GetCurrentProcess();

using (ProcessPrivileges.PrivilegeEnabler enabler = new ProcessPrivileges.PrivilegeEnabler(
                Process.GetCurrentProcess(), ProcessPrivileges.Privilege.CreateGlobal))
{
    Console.WriteLine("{0} => {1}",
    ProcessPrivileges.Privilege.CreateGlobal,
    process.GetPrivilegeState(ProcessPrivileges.Privilege.CreateGlobal)); // 출력 결과: CreateGlobal => Removed
}

아쉽게도 "filtered standard user access token" 상태에서는 SeCreateGlobalPrivilege 특권이 절대 포함되지 않았습니다.

또 다른 테스트로, 이번엔 "administrators" 그룹 계정의 '관리자 권한' 승격 상태에서 정상적으로 실행하는 "A 프로그램"을, 다음과 같이 명시적으로 특권을 제거하고 WCF NamedPipe를 사용해 봤는데...

Process process = Process.GetCurrentProcess();
process.DisablePrivilege(Privilege.CreateGlobal);

Console.WriteLine("{0} => {1}",
    ProcessPrivileges.Privilege.CreateGlobal,
    process.GetPrivilegeState(ProcessPrivileges.Privilege.CreateGlobal)); // 출력 결과: CreateGlobal => Disabled

역시나 "B 프로그램"에서 접속 문제가 발생했습니다. 관리자 권한 승격 상태에서도 "SeCreateGlobalPrivilege" 특권이 없으면 전역 네임스페이스에 등록하지 못하므로 마찬가지의 문제가 발생하는 것입니다.

결론적으로, SeCreateGlobalPrivilege 특권의 유무에 따라 문제가 발생하는 것이 맞겠습니다.






[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 9/12/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 136  137  138  139  140  141  142  143  144  145  146  147  148  149  [150]  ...
NoWriterDateCnt.TitleFile(s)
1302정성태6/25/201229303개발 환경 구성: 151. Azure 웹 사이트에 사용자 도메인 네임 연결하는 방법
1301정성태6/20/201225647오류 유형: 156. KB2667402 윈도우 업데이트 실패 및 마이크로소프트 Answers 웹 사이트 대응
1300정성태6/20/201231679.NET Framework: 329. C# - Rabin-Miller 소수 생성방법을 이용하여 RSACryptoServiceProvider의 개인키를 직접 채워보자 [1]파일 다운로드2
1299정성태6/18/201232771제니퍼 .NET: 21. 제니퍼 닷넷 - Ninject DI 프레임워크의 성능 분석 [2]파일 다운로드2
1298정성태6/14/201234286VS.NET IDE: 72. Visual Studio에서 pfx 파일로 서명한 경우, 암호는 어디에 저장될까? [2]
1297정성태6/12/201230932VC++: 63. 다른 프로세스에 환경 변수 설정하는 방법파일 다운로드1
1296정성태6/5/201227584.NET Framework: 328. 해당 DLL이 Managed인지 / Unmanaged인지 확인하는 방법 - 두 번째 이야기 [4]파일 다운로드1
1295정성태6/5/201224997.NET Framework: 327. RSAParameters와 System.Numerics.BigInteger 이야기파일 다운로드1
1294정성태5/27/201248469.NET Framework: 326. 유니코드와 한글 - 유니코드와 닷넷을 이용한 한글 처리 [7]파일 다운로드2
1293정성태5/24/201229697.NET Framework: 325. System.Drawing.Bitmap 데이터를 Parallel.For로 처리하는 방법 [2]파일 다운로드1
1292정성태5/24/201223706.NET Framework: 324. First-chance exception에 대해 조건에 따라 디버거가 멈추게 할 수는 없을까? [1]파일 다운로드1
1291정성태5/23/201230180VC++: 62. 배열 초기화를 위한 기계어 코드 확인 [2]
1290정성태5/18/201235003.NET Framework: 323. 관리자 권한이 필요한 작업을 COM+에 대행 [7]파일 다운로드1
1289정성태5/17/201239178.NET Framework: 322. regsvcs.exe로 어셈블리 등록 시 시스템 변경 사항 [5]파일 다운로드2
1288정성태5/17/201226343.NET Framework: 321. regasm.exe로 어셈블리 등록 시 시스템 변경 사항 (3) - Type Library파일 다운로드1
1287정성태5/17/201229192.NET Framework: 320. regasm.exe로 어셈블리 등록 시 시스템 변경 사항 (2) - .NET 4.0 + .NET 2.0 [2]
1286정성태5/17/201238112.NET Framework: 319. regasm.exe로 어셈블리 등록 시 시스템 변경 사항 (1) - .NET 2.0 + x86/x64/AnyCPU [5]
1285정성태5/16/201233178.NET Framework: 318. gacutil.exe로 어셈블리 등록 시 시스템 변경 사항파일 다운로드1
1284정성태5/15/201225604오류 유형: 155. Windows Phone 연결 상태에서 DRIVER POWER STATE FAILURE 블루 스크린 뜨는 현상
1283정성태5/12/201233201.NET Framework: 317. C# 관점에서의 Observer 패턴 구현 [1]파일 다운로드1
1282정성태5/12/201226009Phone: 6. Windows Phone 7 Silverlight에서 Google Map 사용하는 방법 [3]파일 다운로드1
1281정성태5/9/201233104.NET Framework: 316. WPF/Silverlight의 그래픽 단위와 Anti-aliasing 처리를 이해하자 [1]파일 다운로드1
1280정성태5/9/201226067오류 유형: 154. Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, ...'.
1279정성태5/9/201224831.NET Framework: 315. 해당 DLL이 Managed인지 / Unmanaged인지 확인하는 방법 [1]파일 다운로드1
1278정성태5/8/201226054오류 유형: 153. Visual Studio 디버깅 - Unable to break execution. This process is not currently executing the type of code that you selected to debug.
1277정성태5/8/201231229오류 유형: 152. cmd.exe - The system cannot write to the specified device. [2]
... 136  137  138  139  140  141  142  143  144  145  146  147  148  149  [150]  ...