Microsoft MVP성태의 닷넷 이야기
.NET Framework: 477. SeCreateGlobalPrivilege 특권과 WCF NamedPipe [링크 복사], [링크+제목 복사],
조회: 18112
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




... 16  17  18  19  20  21  22  23  24  [25]  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13011정성태3/21/20226913오류 유형: 802. 윈도우 운영체제에서 웹캠 카메라 인식이 안 되는 경우
13010정성태3/21/20225831오류 유형: 801. Oracle.ManagedDataAccess.Core - GetTypes 호출 시 "Could not load file or assembly 'System.DirectoryServices.Protocols...'" 오류
13009정성태3/20/20227478개발 환경 구성: 640. docker - ibmcom/db2 컨테이너 실행
13008정성태3/19/20226763VS.NET IDE: 176. 비주얼 스튜디오 - 솔루션 탐색기에서 프로젝트를 선택할 때 csproj 파일이 열리지 않도록 만드는 방법
13007정성태3/18/20226332.NET Framework: 1181. C# - Oracle.ManagedDataAccess의 Pool 및 그것의 연결 개체 수를 알아내는 방법파일 다운로드1
13006정성태3/17/20227441.NET Framework: 1180. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 remuxing.c 예제 포팅
13005정성태3/17/20226248오류 유형: 800. C# - System.InvalidOperationException: Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true.
13004정성태3/16/20226228디버깅 기술: 182. windbg - 닷넷 메모리 덤프에서 AppDomain에 걸친 정적(static) 필드 값을 조사하는 방법
13003정성태3/15/20226392.NET Framework: 1179. C# - (.NET Framework를 위한) Oracle.ManagedDataAccess 패키지의 성능 카운터 설정 방법
13002정성태3/14/20227184.NET Framework: 1178. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 http_multiclient.c 예제 포팅
13001정성태3/13/20227540.NET Framework: 1177. C# - 닷넷에서 허용하는 메서드의 매개변수와 호출 인자의 최대 수
13000정성태3/12/20227141.NET Framework: 1176. C# - Oracle.ManagedDataAccess.Core의 성능 카운터 설정 방법
12999정성태3/10/20226645.NET Framework: 1175. Visual Studio - 프로젝트 또는 솔루션의 Clean 작업 시 응용 프로그램에서 생성한 파일을 함께 삭제파일 다운로드1
12998정성태3/10/20226206.NET Framework: 1174. C# - ELEMENT_TYPE_FNPTR 유형의 사용 예
12997정성태3/10/202210659오류 유형: 799. Oracle.ManagedDataAccess - "ORA-01882: timezone region not found" 오류가 발생하는 이유
12996정성태3/9/202215732VS.NET IDE: 175. Visual Studio - 인텔리센스에서 오버로드 메서드를 키보드로 선택하는 방법
12995정성태3/8/20228105.NET Framework: 1173. .NET에서 Producer/Consumer를 구현한 BlockingCollection<T>
12994정성태3/8/20227354오류 유형: 798. WinDbg - Failed to load data access module, 0x80004002
12993정성태3/4/20227168.NET Framework: 1172. .NET에서 Producer/Consumer를 구현하는 기초 인터페이스 - IProducerConsumerCollection<T>
12992정성태3/3/20228637.NET Framework: 1171. C# - BouncyCastle을 사용한 암호화/복호화 예제파일 다운로드1
12991정성태3/2/20227784.NET Framework: 1170. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 transcode_aac.c 예제 포팅
12990정성태3/2/20227472오류 유형: 797. msbuild - The BaseOutputPath/OutputPath property is not set for project '[...].vcxproj'
12989정성태3/2/20226961오류 유형: 796. mstest.exe - System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.Tips.WebLoadTest.Tip
12988정성태3/2/20225934오류 유형: 795. CI 환경에서 Docker build 시 csproj의 Link 파일에 대한 빌드 오류
12987정성태3/1/20227440.NET Framework: 1169. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 demuxing_decoding.c 예제 포팅
12986정성태2/28/20228254.NET Framework: 1168. C# -IIncrementalGenerator를 적용한 Version 2 Source Generator 실습 [1]
... 16  17  18  19  20  21  22  23  24  [25]  26  27  28  29  30  ...