0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Integrity Level 全部言えるかな?

Posted at

Integrity Levelとは

Integrity Level(長いので以下IL)は、Windowsにおいてセキュリティのために設けられている1つの仕組みです。
レベルということで、高低があります。
プロセス(より正確にはトークン)に設定され、ILが低いプロセスはレジストリ、ファイル、他プロセスへのアクセスなどの様々な面において制約を受けます。

必要性

冒頭にも書きましたが、セキュリティのために必要です。
これがないとマルウェアが、簡単にやりたい放題できてしまいます。
また、マルウェアに限らずユーザー自身がシステムのレジストリやファイルを誤って消してしまう、という事故も防ぐ事ができます

早見表

こちらから引っ張って来ました。初めて見るレベルもあったのは内緒です。

Untrusted < Low < Medium < Medium Plus < High < System < Protected Process

Well-Known Sidにはありませんが、AppContainerもよく使用されます。
また、Installerというものも存在します。

ピックアップ

  • Medium
    一般ユーザーおよび、昇格可能ユーザーが普通にプロセスを起動した場合のレベルです。これが基準になります。
  • Untrusted
  • AppContainer
    ブラウザや、ストアアプリ、Steamなどがサンドボックス環境を用意するためにあえて使用しています。

確認の仕方

手っ取り早く、Process Explorerを使用してみてください。
image.png

上げ下げ

普通にやる

管理者ユーザーの場合、立ち上げたプロセスはそもそもHighになっています。
一般ユーザーや昇格可能ユーザーの場合はプロセスを「管理者として実行」を行う事で昇格が可能です。
また、exeファイルに管理者権限が必要なマニュフェストが設定されている場合は、自動的に昇格確認画面が表示されます。
image.png

コーディング

SetTokenInformationというAPIでトークンにILのSIDを指定してセットしてください。
そのトークンを使用してCreateProcessAsUserWを行えば、設定したILのプロセスが立ち上がります。

title
#include <stdio.h>
#include <windows.h>
#include <sddl.h>

int main()
{
	HANDLE hToken = NULL;
	HANDLE hNewToken = NULL;

	if (!::OpenProcessToken(GetCurrentProcess(), MAXIMUM_ALLOWED, &hToken))
		return 0;

	if (DuplicateTokenEx(hToken, MAXIMUM_ALLOWED, NULL, SecurityImpersonation, TokenPrimary, &hNewToken))
	{
		WCHAR wszIntegritySid[20] = L"S-1-16-4096";//Low
		PSID pIntegritySid = NULL;
		TOKEN_MANDATORY_LABEL TIL = { 0 };
		PROCESS_INFORMATION ProcInfo = { 0 };
		STARTUPINFO StartupInfo = { 0 };
		if (::ConvertStringSidToSidW(wszIntegritySid, &pIntegritySid))
		{
			TIL.Label.Attributes = SE_GROUP_INTEGRITY;
			TIL.Label.Sid = pIntegritySid;
			if (::SetTokenInformation(hNewToken, TokenIntegrityLevel, &TIL, sizeof(TOKEN_MANDATORY_LABEL) + GetLengthSid(pIntegritySid)))
			{
				if (::CreateProcessAsUserW(hNewToken, L"C:\\Windows\\system32\\notepad.exe",
					NULL, NULL, NULL, FALSE, 0, NULL, NULL, &StartupInfo, &ProcInfo))
				{
					::CloseHandle(ProcInfo.hThread);
					::CloseHandle(ProcInfo.hProcess);
				}
			}
			::LocalFree(pIntegritySid);
		}
		::CloseHandle(hNewToken);
	}
	::CloseHandle(hToken);
	return 0;
}

最後に

Medium PlusとProtectedはこの記事を書くに当たって、初めて知りました。
InstallerのILが載っていないことも考えると、まだ見ぬILがあるかも知れない。
他のILを知っている方がいたら教えてください。

関連記事
Hack Tricks Integrity Levels

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?