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

비밀번호

댓글 작성자
 




... 46  47  48  49  50  51  52  53  54  55  56  [57]  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12209정성태4/13/202010509오류 유형: 614. 리눅스 환경에서 C/C++ 프로그램이 Segmentation fault 에러가 발생한 경우 (2)
12208정성태4/12/20209982Linux: 29. 리눅스 환경에서 C/C++ 프로그램이 Segmentation fault 에러가 발생한 경우
12207정성태4/2/20208958스크립트: 19. Windows PowerShell의 NonInteractive 모드
12206정성태4/2/202011262오류 유형: 613. 파일 잠금이 바로 안 풀린다면? - The process cannot access the file '...' because it is being used by another process.
12205정성태4/2/20208647스크립트: 18. Powershell에서는 cmd.exe의 명령어를 지원하진 않습니다.
12204정성태4/1/20208462스크립트: 17. Powershell 명령어에 ';' (semi-colon) 문자가 포함된 경우
12203정성태3/18/202010507오류 유형: 612. warning: 'C:\ProgramData/Git/config' has a dubious owner: '...'.
12202정성태3/18/202013117개발 환경 구성: 486. .NET Framework 프로젝트를 위한 GitLab CI/CD Runner 구성
12201정성태3/18/202010916오류 유형: 611. git-credential-manager.exe: Using credentials for username "Personal Access Token". [1]
12200정성태3/18/202011334VS.NET IDE: 145. NuGet + Github 라이브러리 디버깅 관련 옵션 3가지 - "Enable Just My Code" / "Enable Source Link support" / "Suppress JIT optimization on module load (Managed only)"
12199정성태3/17/20209182오류 유형: 610. C# - CodeDomProvider 사용 시 Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '...\f2_6uod0.tmp'.
12198정성태3/17/202011933오류 유형: 609. SQL 서버 접속 시 "Cannot open user default database. Login failed."
12197정성태3/17/202011080VS.NET IDE: 144. .NET Core 콘솔 응용 프로그램을 배포(publish) 시 docker image 자동 생성 - 두 번째 이야기 [1]
12196정성태3/17/20209013오류 유형: 608. The ServicedComponent being invoked is not correctly configured (Use regsvcs to re-register).
12195정성태3/16/202010720.NET Framework: 902. C# - 프로세스의 모든 핸들을 열람 - 세 번째 이야기
12194정성태3/16/202013037오류 유형: 607. PostgreSQL - Npgsql.NpgsqlException: sorry, too many clients already
12193정성태3/16/20209725개발 환경 구성: 485. docker - SAP Adaptive Server Enterprise 컨테이너 실행 [1]
12192정성태3/14/202012175개발 환경 구성: 484. docker - Sybase Anywhere 16 컨테이너 실행
12191정성태3/14/202012539개발 환경 구성: 483. docker - OracleXE 컨테이너 실행 [1]
12190정성태3/14/20208649오류 유형: 606. Docker Desktop 업그레이드 시 "The process cannot access the file 'C:\Program Files\Docker\Docker\resources\dockerd.exe' because it is being used by another process."
12189정성태3/13/202013496개발 환경 구성: 482. Facebook OAuth 처리 시 상태 정보 전달 방법과 "유효한 OAuth 리디렉션 URI" 설정 규칙
12188정성태3/13/202015809Windows: 169. 부팅 시점에 실행되는 chkdsk 결과를 확인하는 방법
12187정성태3/12/20208471오류 유형: 605. NtpClient was unable to set a manual peer to use as a time source because of duplicate error on '...'.
12186정성태3/12/20209565오류 유형: 604. The SysVol Permissions for one or more GPOs on this domain controller and not in sync with the permissions for the GPOs on the Baseline domain controller.
12185정성태3/11/202010259오류 유형: 603. The browser service was unable to retrieve a list of servers from the browser master...
12184정성태3/11/202011663오류 유형: 602. Automatic certificate enrollment for local system failed (0x800706ba) The RPC server is unavailable. [3]
... 46  47  48  49  50  51  52  53  54  55  56  [57]  58  59  60  ...