Windows/Kernel

kernel 모드에서 PE 파일의 코드사인 여부 확인

구조개발자 2020. 7. 28. 17:56

드라이버에서 프로세스 생성, 모듈 로드 통지를 받은 후 이걸 앱으로 올려 앱에서 해당 파일의 코드사인 여부를 판단하면 되는데, 전 이 모든 것을 커널 드라이버로 끝내고 싶단 말이에요.

 

그래서 방법이 없나??? 라고 고민 하던 중 재미있는 글을 읽었습니다. 

 

MSDN ZwQueryInformationProcess 에서 PS_PROTECTION 항목입니다. 

 

ProcessProtectionInformation 을 주고 콜 하면 PS_PROTECTION 구조체를 얻을 수 있는데 이 구조체 안에 흥미진진한 데이터가 있습니다. 

 

typedef struct _PS_PROTECTION {
    union {
        UCHAR Level;
        struct {
            UCHAR Type   : 3;
            UCHAR Audit  : 1;                  // Reserved
            UCHAR Signer : 4;
        };
    };
} PS_PROTECTION, *PPS_PROTECTION;

Type 3비트에 담긴 내용

typedef enum _PS_PROTECTED_TYPE {
    PsProtectedTypeNone = 0,
    PsProtectedTypeProtectedLight = 1,
    PsProtectedTypeProtected = 2
} PS_PROTECTED_TYPE, *PPS_PROTECTED_TYPE;

Signer 4비트에 담긴 내용

typedef enum _PS_PROTECTED_SIGNER {
    PsProtectedSignerNone = 0,
    PsProtectedSignerAuthenticode,
    PsProtectedSignerCodeGen,
    PsProtectedSignerAntimalware,
    PsProtectedSignerLsa,
    PsProtectedSignerWindows,
    PsProtectedSignerWinTcb,
    PsProtectedSignerWinSystem,
    PsProtectedSignerApp,
    PsProtectedSignerMax
} PS_PROTECTED_SIGNER, *PPS_PROTECTED_SIGNER;

Signer 안에 담긴 내용이 마구 마구 와닿습니다. 

우선 코드로 만들어 테스트를 해보고요.

 

 

원문:

 

PS_PROTECTION

When the ProcessInformationClass parameter is ProcessProtectionInformation, the buffer pointed to by the ProcessInformation parameter should be large enough to hold a single PS_PROTECTION structure having the following layout:

 

...

 

 

ZwQueryInformationProcess function - Win32 apps

ZwQueryInformationProcess function In this article --> [ZwQueryInformationProcess may be altered or unavailable in future versions of Windows. Applications should use the alternate functions listed in this topic.] Retrieves information about the specified

docs.microsoft.com