Skip to content

Commit 2df3a74

Browse files
committed
Installer: Grant access to system and services (fix #391)
1 parent 560c5a7 commit 2df3a74

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

src-installer/RDPWInst.dpr

+56-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
Copyright 2017 Stas'M Corp.
2+
Copyright 2018 Stas'M Corp.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -26,7 +26,9 @@ uses
2626
Classes,
2727
WinSvc,
2828
Registry,
29-
WinInet;
29+
WinInet,
30+
AccCtrl,
31+
AclAPI;
3032

3133
function EnumServicesStatusEx(
3234
hSCManager: SC_HANDLE;
@@ -41,6 +43,11 @@ function EnumServicesStatusEx(
4143
pszGroupName: PWideChar): BOOL; stdcall;
4244
external advapi32 name 'EnumServicesStatusExW';
4345

46+
function ConvertStringSidToSid(
47+
StringSid: PWideChar;
48+
var Sid: PSID): BOOL; stdcall;
49+
external advapi32 name 'ConvertStringSidToSidW';
50+
4451
type
4552
FILE_VERSION = record
4653
Version: record case Boolean of
@@ -639,14 +646,57 @@ begin
639646
Result := True;
640647
end;
641648

649+
procedure GrantSidFullAccess(Path, SID: String);
650+
var
651+
p_SID: PSID;
652+
pDACL: PACL;
653+
EA: EXPLICIT_ACCESS;
654+
Code, Result: DWORD;
655+
begin
656+
p_SID := nil;
657+
if not ConvertStringSidToSid(PChar(SID), p_SID) then
658+
begin
659+
Code := GetLastError;
660+
Writeln('[-] ConvertStringSidToSid error (code ', Code, ').');
661+
Exit;
662+
end;
663+
EA.grfAccessPermissions := GENERIC_ALL;
664+
EA.grfAccessMode := GRANT_ACCESS;
665+
EA.grfInheritance := SUB_CONTAINERS_AND_OBJECTS_INHERIT;
666+
EA.Trustee.pMultipleTrustee := nil;
667+
EA.Trustee.MultipleTrusteeOperation := NO_MULTIPLE_TRUSTEE;
668+
EA.Trustee.TrusteeForm := TRUSTEE_IS_SID;
669+
EA.Trustee.TrusteeType := TRUSTEE_IS_WELL_KNOWN_GROUP;
670+
EA.Trustee.ptstrName := p_SID;
671+
672+
Result := SetEntriesInAcl(1, @EA, nil, pDACL);
673+
if Result = ERROR_SUCCESS then
674+
begin
675+
if SetNamedSecurityInfo(pchar(Path), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, nil, nil, pDACL, nil) <> ERROR_SUCCESS then
676+
begin
677+
Code := GetLastError;
678+
Writeln('[-] SetNamedSecurityInfo error (code ', Code, ').');
679+
end;
680+
LocalFree(Cardinal(pDACL));
681+
end
682+
else begin
683+
Code := GetLastError;
684+
Writeln('[-] SetEntriesInAcl error (code ', Code, ').');
685+
end;
686+
end;
687+
642688
procedure ExtractFiles;
643689
var
644690
RDPClipRes, RfxvmtRes, S: String;
645691
OnlineINI: TStringList;
646692
begin
647693
if not DirectoryExists(ExtractFilePath(ExpandPath(WrapPath))) then
648-
if ForceDirectories(ExtractFilePath(ExpandPath(WrapPath))) then
649-
Writeln('[+] Folder created: ', ExtractFilePath(ExpandPath(WrapPath)))
694+
if ForceDirectories(ExtractFilePath(ExpandPath(WrapPath))) then begin
695+
S := ExtractFilePath(ExpandPath(WrapPath));
696+
Writeln('[+] Folder created: ', S);
697+
GrantSidFullAccess(S, 'S-1-5-18'); // Local System account
698+
GrantSidFullAccess(S, 'S-1-5-6'); // Service group
699+
end
650700
else begin
651701
Writeln('[-] ForceDirectories error.');
652702
Writeln('[*] Path: ', ExtractFilePath(ExpandPath(WrapPath)));
@@ -1080,8 +1130,8 @@ var
10801130
I: Integer;
10811131
begin
10821132
Writeln('RDP Wrapper Library v1.6.2');
1083-
Writeln('Installer v2.5');
1084-
Writeln('Copyright (C) Stas''M Corp. 2017');
1133+
Writeln('Installer v2.6');
1134+
Writeln('Copyright (C) Stas''M Corp. 2018');
10851135
Writeln('');
10861136

10871137
if (ParamCount < 1)

src-installer/resource.res

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)