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

비밀번호

댓글 작성자
 




... 31  32  33  [34]  35  36  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
12779정성태8/13/20218970개발 환경 구성: 596. 공공 데이터 포털에서 버스 노선 및 위치 정보 조회 API 사용법
12778정성태8/12/20216237오류 유형: 755. PyCharm - "Manage Repositories"의 목록이 나오지 않는 문제
12777정성태8/12/20217872오류 유형: 754. Visual Studio - Input or output cannot be redirected because the specified file is invalid.
12776정성태8/12/20217201오류 유형: 753. gunicorn과 uwsgi 함께 사용 시 ERR_CONNECTION_REFUSED
12775정성태8/12/202117644스크립트: 22. 파이썬 - 윈도우 환경에서 개발한 Django 앱을 WSL 환경의 gunicorn을 이용해 실행
12774정성태8/11/20218798.NET Framework: 1087. C# - Collection 개체의 다중 스레드 접근 시 "Operations that change non-concurrent collections must have exclusive access" 예외 발생
12773정성태8/11/20217969개발 환경 구성: 595. PyCharm - WSL과 연동해 Django App을 윈도우에서 리눅스 대상으로 개발
12772정성태8/11/20219480스크립트: 21. 파이썬 - 윈도우 환경에서 개발한 Django 앱을 WSL 환경의 uwsgi를 이용해 실행 [1]
12771정성태8/11/20217887Windows: 196. "Microsoft Windows Subsystem for Linux Background Host" / "Vmmem"을 종료하는 방법
12770정성태8/11/20218569.NET Framework: 1086. C# - Windows Forms 응용 프로그램의 자식 컨트롤 부하파일 다운로드1
12769정성태8/11/20216520오류 유형: 752. Python - ImportError: No module named pip._internal.cli.main 두 번째 이야기
12768정성태8/10/20217554.NET Framework: 1085. .NET 6에 포함된 신규 BCL API [1]파일 다운로드1
12767정성태8/10/20218651오류 유형: 752. Python - ImportError: No module named pip._internal.cli.main
12766정성태8/9/20217170Java: 32. closing inbound before receiving peer's close_notify
12765정성태8/9/20216493Java: 31. Cannot load JDBC driver class 'org.mysql.jdbc.Driver'
12764정성태8/9/202144932Java: 30. XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid
12763정성태8/9/20217949Java: 29. java.lang.NullPointerException - com.mysql.jdbc.ConnectionImpl.getServerCharset
12762정성태8/8/202111505Java: 28. IntelliJ - Unable to open debugger port 오류
12761정성태8/8/20218689Java: 27. IntelliJ - java: package javax.inject does not exist [2]
12760정성태8/8/20216089개발 환경 구성: 594. 전용 "Command Prompt for ..." 단축 아이콘 만들기
12759정성태8/8/20219218Java: 26. IntelliJ + Spring Framework + 새로운 Controller 추가 [2]파일 다운로드1
12758정성태8/7/20218578오류 유형: 751. Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
12757정성태8/7/20219255Java: 25. IntelliJ + Spring Framework 프로젝트 생성
12756정성태8/6/20218065.NET Framework: 1084. C# - .NET Core Web API 단위 테스트 방법 [1]파일 다운로드1
12755정성태8/5/20217172개발 환경 구성: 593. MSTest - 단위 테스트에 static/instance 유형의 private 멤버 접근 방법파일 다운로드1
12754정성태8/5/20218092오류 유형: 750. manage.py - Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
... 31  32  33  [34]  35  36  37  38  39  40  41  42  43  44  45  ...