성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Roll A Lisp In C - Reading ; https...
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>윈도우의 Protected Process (Light) 보안</h1> <p> 10년도 넘은 시간이 흘러, 그 당시에는 다음의 코드가 service.exe에 대해 잘 실행됐는데,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 다른 프로세스에 환경 변수 설정하는 방법 - 두 번째 이야기 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/1438'>https://www.sysnet.pe.kr/2/0/1438</a> Reading the environment variables of another process ; <a target='tab' href='https://stackoverflow.com/questions/37906715/reading-the-environment-variables-of-another-process'>https://stackoverflow.com/questions/37906715/reading-the-environment-variables-of-another-process</a> </pre> <br /> 지금은 OpenProcess 호출에서 에러 코드 5, 즉 "Access is denied"를 반환합니다. 어떤 게 문제일까 싶어서 Process Explorer를 통해 확인했더니,<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='open_process_failed_1.png' src='/SysWebRes/bbs/open_process_failed_1.png' /><br /> <br /> "PsProtectedSignerWinTcb-Light"라는 문자열이 눈에 띄는군요. ^^ 다행히 검색해 보면 이에 대해 자세한 분석 글이 나옵니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Do You Really Know About LSA Protection (RunAsPPL)? ; <a target='tab' href='https://itm4n.github.io/lsass-runasppl/'>https://itm4n.github.io/lsass-runasppl/</a> </pre> <br /> 그러니까, EXE 파일을 마이크로소프트 측의 특별한 (Enhanced Key Usage에 추가 보안 목록이 있는) 인증서로 서명한 유형에 따라 PP(Protected Process)/PPL(Protected Process Light) 프로세스 취급을 받는데요, 이런 프로세스들은 일반 프로세스 권한으로는 설령 SE_DEBUG_NAME이 있다 해도 접근할 수 없습니다. (<a href='https://www.sysnet.pe.kr/2/0/12677#lxss_svc'>lsxxmanager.dll을 호스팅하는 svchost.exe도 그런 사례</a>입니다.)<br /> <br /> 글쓴이는 이것을 우회하기 위해 "Known DLL" 등의 트릭도 써봤으나,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Bypassing LSA Protection in Userland ; <a target='tab' href='https://blog.scrt.ch/2021/04/22/bypassing-lsa-protection-in-userland/'>https://blog.scrt.ch/2021/04/22/bypassing-lsa-protection-in-userland/</a> itm4n/PPLdump ; <a target='tab' href='https://github.com/itm4n/PPLdump'>https://github.com/itm4n/PPLdump</a> </pre> <br /> Windows 10 21H2 버전부터는 저것도 막혔다고 합니다. 따라서 남은 방법은, 1) 보안을 우회할 커널 드라이버를 만들거나, 2) 간혹 Anti-Virus 프로그램 등에서 만든 커널 드라이버 중 PPL 프로세스의 핸들을 열고 있는 것을 찾아내 재사용하는 정도가 있습니다.<br /> <br /> 2가지 모두 공식적으로 쓸 만한 방법은 아닙니다.<br /> <br /> 그래도 위의 방법 중 1번에 대한 테스트를 해볼까요? 이를 위해 <a target='tab' href='https://www.sysnet.pe.kr/2/0/1666'>Mimikatz</a>를 다운로드하는데, 유의할 점은 Windows 11에서는 이것을 바이러스로 인식하기 때문에 Windows Defender에 의해 실행 자체가 되지 않습니다.<br /> <br /> 따라서 실습하려면 Windows Server 2022 등의 다른 운영체제가 있어야 합니다. (혹은 Windows 11의 Defender 기능을 끕니다.) 그에 더해 다음과 같이 간단하게 OpenProcess API를 호출하는 프로그램을 작성하고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > #include <iostream> #include <windows.h> #include <tchar.h> BOOL sm_EnableTokenPrivilege(LPCTSTR pszPrivilege) { // ...[생략: <a target='tab' href='https://github.com/hostilefork/titlewait/blob/master/src/NTProcessInfo.cpp#L34'>https://github.com/hostilefork/titlewait/blob/master/src/NTProcessInfo.cpp#L34</a>]... } int _tmain(int argc, TCHAR* argv[]) { TCHAR* app; DWORD pid; HANDLE proc; if (argc != 2) { app = _tcsrchr(argv[0], '\\'); _tprintf(TEXT("Usage: %s [PID]\n"), app ? ++app : argv[0]); return -1; } _stscanf_s(argv[1], TEXT("%lu"), &pid); sm_EnableTokenPrivilege(SE_DEBUG_NAME); <span style='color: blue; font-weight: bold'>if (!(proc = OpenProcess(PROCESS_QUERY_INFORMATION /* | PROCESS_VM_READ | PROCESS_VM_WRITE */, FALSE, pid))) { DWORD dwError = ::GetLastError(); printf("OpenProcess: not worked!, %d", dwError); return dwError; }</span> printf("OpenProcess: worked!\n"); CloseHandle(proc); } </pre> <br /> services.exe PID에 대해 관리자 권한으로 다음과 같이 실행해 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // services.exe의 PID == 652인 경우, c:\temp> <span style='color: blue; font-weight: bold'>ConsoleApplication1.exe 652</span> OpenProcess: not worked!, 5 </pre> <br /> 이렇게 동작하지 않습니다. 반면, Mimikatz는 mimidrv.sys 커널 드라이버를 제공하고 있는데요, 그 모듈에 PP/PPL 보안을 무력화하는 코드가 들어 있습니다. 실제로 다음과 같이 명령을 내리면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\temp> <span style='color: blue; font-weight: bold'>mimikatz.exe</span> .#####. mimikatz 2.2.0 (x64) #19041 Sep 19 2022 17:44:08 .## ^ ##. "A La Vie, A L'Amour" - (oe.eo) ## / \ ## /*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com ) ## \ / ## > https://blog.gentilkiwi.com/mimikatz '## v ##' Vincent LE TOUX ( vincent.letoux@gmail.com ) '#####' > https://pingcastle.com / https://mysmartlogon.com ***/ mimikatz # <span style='color: blue; font-weight: bold'>!+</span> [*] 'mimidrv' service not present [+] 'mimidrv' service successfully registered [+] 'mimidrv' service ACL to everyone [+] 'mimidrv' service started mimikatz # <span style='color: blue; font-weight: bold'>!processprotect /process:services.exe /remove</span> Process : services.exe PID 652 -> 00/00 [0-0-0] </pre> <br /> 아래와 같이 OpenProcess가 잘 동작합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // services.exe의 PID == 652인 경우, c:\temp> <span style='color: blue; font-weight: bold'>ConsoleApplication1.exe 652</span> OpenProcess: worked! </pre> <br /> 이후, 다시 보호를 하면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > mimikatz # <span style='color: blue; font-weight: bold'>!processprotect /process:services.exe</span> </pre> <br /> OpenProcess는 더 이상 동작하지 않습니다. OpenProcess가 안 되니, 이후의 DLL Injection 등은 시도조차 할 수 없게 되었습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 참고로, OpenProcess의 모든 호출이 실패하는 것은 아닙니다. PROCESS_QUERY_LIMITED_INFORMATION, PROCESS_SET_LIMITED_INFORMATION, PROCESS_TERMINATE, PROCESS_SUSPEND_RESUME에 대해서는 가능합니다.<br /> <br /> 또한, Windows 11과 Server Server 2022의 보안 정책이 다소 다른 듯합니다. 일례로 Process Explorer의 경우 Windows 11 환경에서는 PP/PPL 보안이 적용된 프로세스에 대해서는 환경 변수 목록을 가져오지 못합니다. 반면 Windows Server 2022의 경우에는 해당 정보를 가져오는 데에는 문제가 없습니다.<br /> <br /> 현재 마이크로소프트는 Windows 11의 경우 wininit.exe, csrss.exe, smss.exe 및 Windows Defender 같은 프로세스(msmpeng.exe) 등의 극히 제한적인 범위로 PP/PPL 보안을 적용하고 있습니다. 그런데 <a target='tab' href='https://itm4n.github.io/lsass-runasppl/'>본문의 경우</a>, RunAsPPL 레지스트리 설정을 추가한 상황으로 설명하고 있습니다. 그래서 원래 lsass.exe는 PPL 프로세스가 아니지만 RunAsPPL 설정을 하면 PPL로 뜨는 것 같습니다. 그런 탓에 mimikatz가 Windows 11에서도 여전히 기본 명령어로도 잘 동작하지만 RunAsPPL로 lsass.exe가 보호받는 경우에는 (mimidrv.sys에서 제공하는) processprotect 명령어를 이용해 PPL 플래그를 제거하는 단계를 거쳐야 합니다.<br /> <br /> 이걸 테스트하려면 RunAsPPL 설정과 함께 재부팅도 해야 하고, mimikatz 바이러스 인식을 막기 위해 Windows Defender Credential Guard를 꺼야 하는데, <br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Disable Windows Defender Credential Guard ; <a target='tab' href='https://learn.microsoft.com/en-us/windows/security/identity-protection/credential-guard/credential-guard-manage#disable-windows-defender-credential-guard'>https://learn.microsoft.com/en-us/windows/security/identity-protection/credential-guard/credential-guard-manage#disable-windows-defender-credential-guard</a> </pre> <br /> 굳이 해볼 가치는 없어 보여 생략합니다. ^^<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1774
(왼쪽의 숫자를 입력해야 합니다.)