00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#include <stdio.h>
00025
#include <string.h>
00026
00027
#include <nt.h>
00028
#include <ntrtl.h>
00029
00030
#include "sep.h"
00031
#include "ttoken.c"
00032
00033
VOID
00034
RtlDumpAcl(
00035 IN PACL Acl
00036 );
00037
00038
00039 main(
00040
int argc,
00041
char *argv[],
00042
char *envp[]
00043 )
00044 {
00045 HANDLE CurrentProcessHandle;
00046
NTSTATUS Status;
00047 ULONG i;
00048
VOID SeMain();
00049
00050 CurrentProcessHandle = NtCurrentProcess();
00051
Status = STATUS_SUCCESS;
00052
00053
DbgPrint(
"Entering User Mode Test Program\n" );
00054
00055
DbgPrint(
"argc: %ld\n", argc );
00056
if (argv !=
NULL) {
00057
for (i=0; i<argc; i++) {
00058
DbgPrint(
"argv[ %ld ]: %s\n", i, argv[ i ] );
00059 }
00060 }
00061
00062
if (envp !=
NULL) {
00063 i = 0;
00064
while (*envp) {
00065
DbgPrint(
"envp[ %02ld ]: %s\n", i++, *envp++ );
00066 }
00067 }
00068
00069
SeMain();
00070
00071
DbgPrint(
"Exiting User Mode Test Program with Status = %lx\n",
Status );
00072
00073
NtTerminateProcess( CurrentProcessHandle,
Status );
00074 }
00075
00076
00077
VOID
00078 SeMain(
00079 )
00080 {
00081 BOOLEAN
TestCreateAcl();
00082 BOOLEAN
TestQueryInformationAcl();
00083 BOOLEAN
TestSetInformationAcl();
00084 BOOLEAN
TestAddAce();
00085 BOOLEAN
TestDeleteAce();
00086 BOOLEAN
TestGetAce();
00087
00088 BOOLEAN
TestAccessCheck();
00089 BOOLEAN
TestGenerateMessage();
00090
00091
DbgPrint(
"Starting User Mode Security Test\n");
00092
00093
if (!
TestCreateAcl()) {
00094
DbgPrint(
"TestCreateAcl Error\n");
00095
return;
00096 }
00097
if (!
TestQueryInformationAcl()) {
00098
DbgPrint(
"TestCreateAcl Error\n");
00099
return;
00100 }
00101
if (!
TestSetInformationAcl()) {
00102
DbgPrint(
"TestCreateAcl Error\n");
00103
return;
00104 }
00105
if (!
TestAddAce()) {
00106
DbgPrint(
"TestCreateAcl Error\n");
00107
return;
00108 }
00109
if (!
TestDeleteAce()) {
00110
DbgPrint(
"TestCreateAcl Error\n");
00111
return;
00112 }
00113
if (!
TestGetAce()) {
00114
DbgPrint(
"TestCreateAcl Error\n");
00115
return;
00116 }
00117
00118
if (!
TestAccessCheck()) {
00119
DbgPrint(
"TestCreateAcl Error\n");
00120
return;
00121 }
00122
if (!
TestGenerateMessage()) {
00123
DbgPrint(
"TestCreateAcl Error\n");
00124
return;
00125 }
00126
00127
DbgPrint(
"Ending User Mode Security Test\n");
00128
00129
return;
00130 }
00131
00132
00133 BOOLEAN
00134 TestCreateAcl()
00135 {
00136 UCHAR
Buffer[512];
00137 PACL Acl;
00138
00139
NTSTATUS Status;
00140
00141 Acl = (PACL)
Buffer;
00142
00143
00144
00145
00146
00147
if (!
NT_SUCCESS(
Status =
RtlCreateAcl( Acl, 512, 1))) {
00148
DbgPrint(
"RtlCreateAcl Error large Acl : %8lx\n",
Status);
00149
return FALSE;
00150 }
00151
00152
00153
00154
00155
00156
if (!
NT_SUCCESS(
Status =
RtlCreateAcl( Acl,
sizeof(ACL), 1))) {
00157
DbgPrint(
"RtlCreateAcl Error small Acl : %8lx\n",
Status);
00158
return FALSE;
00159 }
00160
00161
00162
00163
00164
00165
if (
NT_SUCCESS(
Status =
RtlCreateAcl( Acl,
sizeof(ACL) - 1, 1))) {
00166
DbgPrint(
"RtlCreateAcl Error too small Acl : %8lx\n",
Status);
00167
return FALSE;
00168 }
00169
00170
00171
00172
00173
00174
if (
NT_SUCCESS(
Status =
RtlCreateAcl( Acl, 512, 2))) {
00175
DbgPrint(
"RtlCreateAcl Error bad version : %8lx\n",
Status);
00176
return FALSE;
00177 }
00178
00179
return TRUE;
00180 }
00181
00182
00183 BOOLEAN
00184 TestQueryInformationAcl()
00185 {
00186 UCHAR
Buffer[512];
00187 PACL Acl;
00188 ACL_REVISION_INFORMATION AclRevisionInfo;
00189 ACL_SIZE_INFORMATION AclSizeInfo;
00190
00191
NTSTATUS Status;
00192
00193 Acl = (PACL)
Buffer;
00194
00195 BuildAcl(
Fred, Acl, 512 );
00196
00197
00198
00199
00200
00201
if (!
NT_SUCCESS(
Status =
RtlQueryInformationAcl( Acl,
00202 (PVOID)&AclRevisionInfo,
00203
sizeof(ACL_REVISION_INFORMATION),
00204 AclRevisionInformation))) {
00205
DbgPrint(
"RtlQueryInformationAcl revision info error : %8lx\n",
Status);
00206
return FALSE;
00207 }
00208
if (AclRevisionInfo.AclRevision != ACL_REVISION) {
00209
DbgPrint(
"RtlAclRevision Error\n");
00210
return FALSE;
00211 }
00212
00213
00214
00215
00216
00217
if (!
NT_SUCCESS(
Status =
RtlQueryInformationAcl( Acl,
00218 (PVOID)&AclSizeInfo,
00219
sizeof(ACL_SIZE_INFORMATION),
00220 AclSizeInformation))) {
00221
DbgPrint(
"RtlQueryInformationAcl size info Error : %8lx\n",
Status);
00222
return FALSE;
00223 }
00224
if ((AclSizeInfo.AceCount != 6) ||
00225 (AclSizeInfo.AclBytesInUse != (
sizeof(ACL)+6*
sizeof(
STANDARD_ACE))) ||
00226 (AclSizeInfo.AclBytesFree != 512 - AclSizeInfo.AclBytesInUse)) {
00227
DbgPrint(
"RtlAclSize Error\n");
00228
DbgPrint(
"AclSizeInfo.AceCount = %8lx\n", AclSizeInfo.AceCount);
00229
DbgPrint(
"AclSizeInfo.AclBytesInUse = %8lx\n", AclSizeInfo.AclBytesInUse);
00230
DbgPrint(
"AclSizeInfo.AclBytesFree = %8lx\n", AclSizeInfo.AclBytesFree);
00231
return FALSE;
00232 }
00233
00234
return TRUE;
00235 }
00236
00237
00238 BOOLEAN
00239 TestSetInformationAcl()
00240 {
00241 UCHAR
Buffer[512];
00242 PACL Acl;
00243 ACL_REVISION_INFORMATION AclRevisionInfo;
00244
00245
NTSTATUS Status;
00246
00247 Acl = (PACL)
Buffer;
00248
00249 BuildAcl(
Fred, Acl, 512 );
00250
00251
00252
00253
00254
00255 AclRevisionInfo.AclRevision = ACL_REVISION;
00256
if (!
NT_SUCCESS(
Status =
RtlSetInformationAcl( Acl,
00257 (PVOID)&AclRevisionInfo,
00258
sizeof(ACL_REVISION_INFORMATION),
00259 AclRevisionInformation))) {
00260
DbgPrint(
"RtlSetInformationAcl revision info error : %8lx\n",
Status);
00261
return FALSE;
00262 }
00263
00264
00265
00266
00267
00268 AclRevisionInfo.AclRevision = ACL_REVISION+1;
00269
if (
NT_SUCCESS(
Status =
RtlSetInformationAcl( Acl,
00270 (PVOID)&AclRevisionInfo,
00271
sizeof(ACL_REVISION_INFORMATION),
00272 AclRevisionInformation))) {
00273
DbgPrint(
"RtlSetInformationAcl revision to wrong info error : %8lx\n",
Status);
00274
return FALSE;
00275 }
00276
00277
return TRUE;
00278 }
00279
00280
00281 BOOLEAN
00282 TestAddAce()
00283 {
00284 UCHAR AclBuffer[512];
00285 PACL Acl;
00286
00287
STANDARD_ACE AceList[2];
00288
00289
NTSTATUS Status;
00290
00291 Acl = (PACL)AclBuffer;
00292
00293
00294
00295
00296
00297
if (!
NT_SUCCESS(
Status =
RtlCreateAcl( Acl, 512, 1))) {
00298
DbgPrint(
"RtlCreateAcl Error large Acl : %8lx\n",
Status);
00299
return FALSE;
00300 }
00301
00302
00303
00304
00305
00306 AceList[0].
Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
00307 AceList[0].
Header.AceSize =
sizeof(
STANDARD_ACE);
00308 AceList[0].
Header.InheritFlags = 0;
00309 AceList[0].
Header.AceFlags = 0;
00310 AceList[0].
Mask = 0x22222222;
00311 CopyGuid(&AceList[0].Guid, &FredGuid);
00312
00313 AceList[1].
Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
00314 AceList[1].
Header.AceSize =
sizeof(
STANDARD_ACE);
00315 AceList[1].
Header.InheritFlags = 0;
00316 AceList[1].
Header.AceFlags = 0;
00317 AceList[1].
Mask = 0x44444444;
00318 CopyGuid(&AceList[1].Guid, &WilmaGuid);
00319
00320
if (!
NT_SUCCESS(
Status =
RtlAddAce( Acl,
00321 1,
00322 0,
00323 AceList,
00324 2*
sizeof(
STANDARD_ACE)))) {
00325
DbgPrint(
"RtlAddAce to empty acl Error : %8lx\n",
Status);
00326
return FALSE;
00327 }
00328
00329
00330
00331
00332
00333
00334
00335 AceList[0].
Header.AceType = SYSTEM_AUDIT_ACE_TYPE;
00336 AceList[0].
Header.AceSize =
sizeof(
STANDARD_ACE);
00337 AceList[0].
Header.InheritFlags = 0;
00338 AceList[0].
Header.AceFlags = 0;
00339 AceList[0].
Mask = 0x11111111;
00340 CopyGuid(&AceList[0].Guid, &PebblesGuid);
00341
00342
if (!
NT_SUCCESS(
Status =
RtlAddAce( Acl,
00343 1,
00344 0,
00345 AceList,
00346
sizeof(
STANDARD_ACE)))) {
00347
DbgPrint(
"RtlAddAce to beginning of acl Error : %8lx\n",
Status);
00348
return FALSE;
00349 }
00350
00351
00352
00353
00354
00355
00356
00357 AceList[0].
Header.AceType = ACCESS_DENIED_ACE_TYPE;
00358 AceList[0].
Header.AceSize =
sizeof(
STANDARD_ACE);
00359 AceList[0].
Header.InheritFlags = 0;
00360 AceList[0].
Header.AceFlags = 0;
00361 AceList[0].
Mask = 0x33333333;
00362 CopyGuid(&AceList[0].Guid, &DinoGuid);
00363
00364
if (!
NT_SUCCESS(
Status =
RtlAddAce( Acl,
00365 1,
00366 2,
00367 AceList,
00368
sizeof(
STANDARD_ACE)))) {
00369
DbgPrint(
"RtlAddAce to middle of acl Error : %8lx\n",
Status);
00370
return FALSE;
00371 }
00372
00373
00374
00375
00376
00377
00378
00379 AceList[0].
Header.AceType = ACCESS_DENIED_ACE_TYPE;
00380 AceList[0].
Header.AceSize =
sizeof(
STANDARD_ACE);
00381 AceList[0].
Header.InheritFlags = 0;
00382 AceList[0].
Header.AceFlags = 0;
00383 AceList[0].
Mask = 0x55555555;
00384 CopyGuid(&AceList[0].Guid, &FlintstoneGuid);
00385
00386
if (!
NT_SUCCESS(
Status =
RtlAddAce( Acl,
00387 1,
00388 MAXULONG,
00389 AceList,
00390
sizeof(
STANDARD_ACE)))) {
00391
DbgPrint(
"RtlAddAce to end of an acl Error : %8lx\n",
Status);
00392
return FALSE;
00393 }
00394
00395
00396
00397
return TRUE;
00398 }
00399
00400
00401 BOOLEAN
00402 TestDeleteAce()
00403 {
00404 UCHAR
Buffer[512];
00405 PACL Acl;
00406
00407
NTSTATUS Status;
00408
00409 Acl = (PACL)
Buffer;
00410
00411 BuildAcl(
Fred, Acl, 512 );
00412
00413
00414
00415
00416
00417
if (!
NT_SUCCESS(
Status =
RtlDeleteAce(Acl, 0))) {
00418
DbgPrint(
"RtlDeleteAce first ace Error : %8lx\n",
Status);
00419
return FALSE;
00420 }
00421
00422
00423
00424
00425
00426
00427
00428
if (!
NT_SUCCESS(
Status =
RtlDeleteAce(Acl, 2))) {
00429
DbgPrint(
"RtlDeleteAce middle ace Error : %8lx\n",
Status);
00430
return FALSE;
00431 }
00432
00433
00434
00435
00436
00437
00438
00439
if (!
NT_SUCCESS(
Status =
RtlDeleteAce(Acl, 3))) {
00440
DbgPrint(
"RtlDeleteAce last ace Error : %8lx\n",
Status);
00441
return FALSE;
00442 }
00443
00444
00445
00446
return TRUE;
00447 }
00448
00449
00450 BOOLEAN
00451 TestGetAce()
00452 {
00453 UCHAR
Buffer[512];
00454 PACL Acl;
00455
00456
STANDARD_ACE Ace;
00457
00458
NTSTATUS Status;
00459
00460 Acl = (PACL)
Buffer;
00461
00462 BuildAcl(
Fred, Acl, 512 );
00463
00464
00465
00466
00467
00468
if (!
NT_SUCCESS(
Status =
RtlGetAce(Acl, 0, (PVOID)&Ace))) {
00469
DbgPrint(
"RtlGetAce first ace error : %8lx\n",
Status);
00470
return FALSE;
00471 }
00472
00473
00474
00475
00476
00477
00478
00479
if (!
NT_SUCCESS(
Status =
RtlGetAce(Acl, 3, (PVOID)&Ace))) {
00480
DbgPrint(
"RtlGetAce middle ace error : %8lx\n",
Status);
00481
return FALSE;
00482 }
00483
00484
00485
00486
00487
00488
00489
00490
if (!
NT_SUCCESS(
Status =
RtlGetAce(Acl, 5, (PVOID)&Ace))) {
00491
DbgPrint(
"RtlGetAce last ace error : %8lx\n",
Status);
00492
return FALSE;
00493 }
00494
00495
00496
00497
return TRUE;
00498 }
00499
00500
00501 BOOLEAN
00502 TestAccessCheck()
00503 {
00504 UCHAR AclBuffer[1024];
00505 SECURITY_DESCRIPTOR SecurityDescriptor;
00506 PACL Acl;
00507
00508 UCHAR TokenBuffer[512];
00509 PACCESS_TOKEN
Token;
00510
00511
NTSTATUS Status;
00512
00513 Acl = (PACL)AclBuffer;
00514 BuildAcl(
Fred, Acl, 1024 );
00515
00516
Token = (PACCESS_TOKEN)TokenBuffer;
00517 BuildToken(
Fred,
Token );
00518
00519 DiscretionarySecurityDescriptor( &SecurityDescriptor, Acl );
00520
00521
00522
00523
00524
00525
if (!
NT_SUCCESS(
Status =
NtAccessCheck( &SecurityDescriptor,
00526
Token,
00527 0x00000001,
00528
NULL ))) {
00529
DbgPrint(
"NtAccessCheck Error should allow access : %8lx\n",
Status);
00530
return FALSE;
00531 }
00532
00533
00534
00535
00536
00537
if (!
NT_SUCCESS(
Status =
NtAccessCheck( &SecurityDescriptor,
00538
Token,
00539 READ_CONTROL,
00540 &FredGuid ))) {
00541
DbgPrint(
"NtAccessCheck Error should allow owner : %8lx\n",
Status);
00542
return FALSE;
00543 }
00544
00545
00546
00547
00548
00549
if (
NT_SUCCESS(
Status =
NtAccessCheck( &SecurityDescriptor,
00550
Token,
00551 0x0000000f,
00552 &FredGuid ))) {
00553
DbgPrint(
"NtAccessCheck Error shouldn't allow access : %8lx\n",
Status);
00554
return FALSE;
00555 }
00556
00557
00558
00559
00560
00561
if (
NT_SUCCESS(
Status =
NtAccessCheck( &SecurityDescriptor,
00562
Token,
00563 READ_CONTROL,
00564 &BarneyGuid ))) {
00565
DbgPrint(
"NtAccessCheck Error shouldn't allow non owner access : %8lx\n",
Status);
00566
return FALSE;
00567 }
00568
00569
return TRUE;
00570 }
00571
00572
00573 BOOLEAN
00574 TestGenerateMessage()
00575 {
00576
return TRUE;
00577 }
00578