EnglishFrenchGermanItalianPortugueseSpanish

Небольшой трюк с WRP под Windows Vista+

Как известно, в операционной системе Windows (2000, XP, 2003) существует механизм защиты системных файлов, также известный как Windows File Protection. Данный механизм не позволяет изменять или удалять критичные объекты операционной системы, в частности системные DLL и различные драйверы. В случае обнаружения изменений ОС восстанавливает такие файлы.

Вкратце суть алгоритма сводилась к следующему: в системном процессе winlogon.exe существовал следящий поток. Если он замечал изменение системной компоненты, то компонента восстанавливалась из запасной копии.

В скором времени данный алгоритм изучили и были придуманы многочисленные способы обхода данной технологи. Использование недокументированных функций системной библиотеки sfc_os.dll или изменение sfc.dll/sfc_os.dll стали широко использоваться в различных вредоносных программах.

Но не это нас интересует, а то, как видоизменился данный механизм в операционных системах Windows Vista и Windows 7.

В данных операционных системах Microsoft полностью отказалась от данной технологии и перешла на технологию Windows Resource Protection. Теперь в системе нет следящего потока, а доступ к файлам ограничивается операционной системой с помощью DACL и ACL, стандартного механизма защиты Windows. Однако даже у администратора нет прав на изменение или удаление системных файлов.

Поэкспериментируем с операционной системой Windows 7 RTM и попробуем удалить какой-либо системный файл.

Так выглядит попытка удаления системного файла, которую я отследил с помощью Process Monitor

Посмотрим свойства файла

Как и было сказано даже у администратора нет прав на изменение файла.

Посмотрим, как с этим обстоят дела у TrustedInstaller

Как мы видим — полный контроль над файлом.

Однако, если вы администратор, то вы можете захватить владение данным файлом и потом уже выставить ему необходимые права.

Все это не очень удобно, если необходимо произвести изменение нескольких файлов. Попробуем найти способ проще. Для этого воспользуемся отладчиком WinDbg и утилитой psgetsid, которая умеет транслировать имя в SID и обратно:

C:\1>psgetsid «NT SERVICE\TrustedInstaller»

PsGetSid v1.43 — Translates SIDs to names and vice versa
Copyright (C) 1999-2006 Mark Russinovich
Sysinternals — www.sysinternals.com

SID for NT SERVICE\TrustedInstaller:
S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464

Теперь перечислим все процессы в системе и попробуем найти хотя бы один имеющий нужные нам права:

kd> !for_each_process «r $t0 = @#Process; r? $t1 = @@c++(((nt!_EPROCESS*)@$t0)->Token.Object); !token -n @$t1 & 0xFFFFFFF8;»

Приведу лишь token первого процесса (системного):

_TOKEN 87a01398
TS Session ID: 0
User: S-1-5-18 (Well Known Group: NT AUTHORITY\SYSTEM)
Groups:
00 S-1-5-32-544 (Alias: BUILTIN\Administrators)
Attributes — Default Enabled Owner
01 S-1-1-0 (Well Known Group: localhost\Everyone)
Attributes — Mandatory Default Enabled
02 S-1-5-11 (Well Known Group: NT AUTHORITY\Authenticated Users)
Attributes — Mandatory Default Enabled
03 S-1-16-16384 Unrecognized SID
Attributes — GroupIntegrity GroupIntegrityEnabled
Primary Group: S-1-5-18 (Well Known Group: NT AUTHORITY\SYSTEM)
Privs:
02 0×000000002 SeCreateTokenPrivilege Attributes -
03 0×000000003 SeAssignPrimaryTokenPrivilege Attributes -
04 0×000000004 SeLockMemoryPrivilege Attributes — Enabled Default
05 0×000000005 SeIncreaseQuotaPrivilege Attributes -
07 0×000000007 SeTcbPrivilege Attributes — Enabled Default
08 0×000000008 SeSecurityPrivilege Attributes -
09 0×000000009 SeTakeOwnershipPrivilege Attributes -
10 0x00000000a SeLoadDriverPrivilege Attributes -
11 0x00000000b SeSystemProfilePrivilege Attributes — Enabled Default
12 0x00000000c SeSystemtimePrivilege Attributes -
13 0x00000000d SeProfileSingleProcessPrivilege Attributes — Enabled Default
14 0x00000000e SeIncreaseBasePriorityPrivilege Attributes — Enabled Default
15 0x00000000f SeCreatePagefilePrivilege Attributes — Enabled Default
16 0×000000010 SeCreatePermanentPrivilege Attributes — Enabled Default
17 0×000000011 SeBackupPrivilege Attributes -
18 0×000000012 SeRestorePrivilege Attributes -
19 0×000000013 SeShutdownPrivilege Attributes -
20 0×000000014 SeDebugPrivilege Attributes — Enabled Default
21 0×000000015 SeAuditPrivilege Attributes — Enabled Default
22 0×000000016 SeSystemEnvironmentPrivilege Attributes -
23 0×000000017 SeChangeNotifyPrivilege Attributes — Enabled Default
25 0×000000019 SeUndockPrivilege Attributes -
28 0x00000001c SeManageVolumePrivilege Attributes -
29 0x00000001d SeImpersonatePrivilege Attributes — Enabled Default
30 0x00000001e SeCreateGlobalPrivilege Attributes — Enabled Default
31 0x00000001f SeTrustedCredManAccessPrivilege Attributes -
32 0×000000020 SeRelabelPrivilege Attributes -
33 0×000000021 SeIncreaseWorkingSetPrivilege Attributes — Enabled Default
34 0×000000022 SeTimeZonePrivilege Attributes — Enabled Default
35 0×000000023 SeCreateSymbolicLinkPrivilege Attributes — Enabled Default
Authentication ID: (0,3e7)
Impersonation Level: Anonymous
TokenType: Primary
Source: *SYSTEM* TokenFlags: 0×2000 ( Token in use )
Token ID: 3ea ParentToken ID: 0
Modified ID: (0, 3eb)
RestrictedSidCount: 0 RestrictedSids: 00000000
OriginatingLogonSession: 0

Попробуем во всем выводе в консоли WinDbg найти SID TrustedInstaller. На моем тестовом стенде ничего найдено не было. Но ведь есть сервис, который может изменять системные компоненты и находится он в \Windows\servicing\TrustedInstaller.exe, а запустить его мы можем вручную из вкладки Services. Называется он Windows Modules Installer и имеет следующее описание: «Enables installation, modification, and removal of Windows updates and optional components. If this service is disabled, install or uninstall of Windows updates might fail for this computer.»

После запуска можно повторить команду вывода Token для каждого процесса или найти Token вручную в процессе TrustedInstaller.exe.

PROCESS 85f79030 SessionId: 0 Cid: 0910 Peb: 7ffd3000 ParentCid: 01e8
DirBase: 3ef59520 ObjectTable: 90e37080 HandleCount: 121.
Image: TrustedInstaller.exe

kd> ? poi( 85f79030 + 0xf8 ) & 0xFFFFFFF8
Evaluate expression: -1730040888 = 98e1abc8

0xf8 – это смещение до Token в структуре nt!_EPROCESS, а Token – это структура nt!_EX_FAST_REF:

kd> dt nt!_EX_FAST_REF
+0×000 Object : Ptr32 Void
+0×000 RefCnt : Pos 0, 3 Bits
+0×000 Value : Uint4B

Поэтому необходимо отбросить младшие 3 бита адреса.

kd> !token -n 98e1abc8
_TOKEN 98e1abc8
TS Session ID: 0
User: S-1-5-18 (Well Known Group: NT AUTHORITY\SYSTEM)
Groups:
00 S-1-16-16384 Unrecognized SID
Attributes — GroupIntegrity GroupIntegrityEnabled
01 S-1-1-0 (Well Known Group: localhost\Everyone)
Attributes — Mandatory Default Enabled
02 S-1-5-32-545 (Alias: BUILTIN\Users)
Attributes — Mandatory Default Enabled
03 S-1-5-6 (Well Known Group: NT AUTHORITY\SERVICE)
Attributes — Mandatory Default Enabled
04 S-1-2-1 (no name mapped)
Attributes — Mandatory Default Enabled
05 S-1-5-11 (Well Known Group: NT AUTHORITY\Authenticated Users)
Attributes — Mandatory Default Enabled
06 S-1-5-15 (Well Known Group: NT AUTHORITY\This Organization)
Attributes — Mandatory Default Enabled
07 S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464 (Well Known Group: NT SERVICE\TrustedInstaller)
Attributes — Default Enabled Owner
08 S-1-5-5-0-1412741 (no name mapped)
Attributes — Mandatory Default Enabled Owner LogonId
09 S-1-2-0 (Well Known Group: localhost\LOCAL)
Attributes — Mandatory Default Enabled
10 S-1-5-32-544 (Alias: BUILTIN\Administrators)
Attributes — Default Enabled Owner
Primary Group: S-1-5-18 (Well Known Group: NT AUTHORITY\SYSTEM)
Privs:
03 0×000000003 SeAssignPrimaryTokenPrivilege Attributes -
04 0×000000004 SeLockMemoryPrivilege Attributes — Enabled Default
05 0×000000005 SeIncreaseQuotaPrivilege Attributes -
07 0×000000007 SeTcbPrivilege Attributes — Enabled Default
08 0×000000008 SeSecurityPrivilege Attributes -
09 0×000000009 SeTakeOwnershipPrivilege Attributes -
10 0x00000000a SeLoadDriverPrivilege Attributes -
11 0x00000000b SeSystemProfilePrivilege Attributes — Enabled Default
12 0x00000000c SeSystemtimePrivilege Attributes -
13 0x00000000d SeProfileSingleProcessPrivilege Attributes — Enabled Default
14 0x00000000e SeIncreaseBasePriorityPrivilege Attributes — Enabled Default
15 0x00000000f SeCreatePagefilePrivilege Attributes — Enabled Default
16 0×000000010 SeCreatePermanentPrivilege Attributes — Enabled Default
17 0×000000011 SeBackupPrivilege Attributes — Enabled
18 0×000000012 SeRestorePrivilege Attributes — Enabled
19 0×000000013 SeShutdownPrivilege Attributes -
20 0×000000014 SeDebugPrivilege Attributes — Enabled Default
21 0×000000015 SeAuditPrivilege Attributes — Enabled Default
22 0×000000016 SeSystemEnvironmentPrivilege Attributes -
23 0×000000017 SeChangeNotifyPrivilege Attributes — Enabled Default
25 0×000000019 SeUndockPrivilege Attributes -
28 0x00000001c SeManageVolumePrivilege Attributes -
29 0x00000001d SeImpersonatePrivilege Attributes — Enabled Default
30 0x00000001e SeCreateGlobalPrivilege Attributes — Enabled Default
33 0×000000021 SeIncreaseWorkingSetPrivilege Attributes — Enabled Default
34 0×000000022 SeTimeZonePrivilege Attributes — Enabled Default
35 0×000000023 SeCreateSymbolicLinkPrivilege Attributes — Enabled Default
Authentication ID: (0,3e7)
Impersonation Level: Anonymous
TokenType: Primary
Source: Advapi TokenFlags: 0×2000 ( Token in use )
Token ID: 158ec1 ParentToken ID: 0
Modified ID: (0, 158ff6)
RestrictedSidCount: 0 RestrictedSids: 00000000
OriginatingLogonSession: 3e7

А теперь давайте подменим Token процесса FAR.exe на Token процесса TrustedInstaller.exe:

PROCESS 84c9e030 SessionId: 1 Cid: 08d0 Peb: 7ffda000 ParentCid: 07b0
DirBase: 3ef593c0 ObjectTable: 90fe1308 HandleCount: 264.
Image: Far.exe

kd> ed 84c9e030+f8 98e1abc8

После этих нехитрых манипуляций файловый менеджер FAR получает все необходимые права и может изменять и/или удалять защищаемые системные файлы без каких-либо изощрений с захватом прав пользования отдельного файла.

Читайте также:

Share

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">