Detecting Active Services

Created the Monday 11 March 2019. Updated 3 years, 8 months ago.

VMwareService.exe runs the VMware Tools Service as a child of services.exe. It can be identified by listing services.


Technique Identifier

U1337


Code Snippets

Jean-Pierre LESUEUR

Description

Two methods are demonstrated in this example (Windows Registry and Windows Service Manager API).

program AntiSandboxScanService;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  WinAPI.Windows,
  WinAPI.WinSvc;


const ANTI_LIST : array[0..4-1] of String = (
      // VMWare
      'VGAuthService',
      'vmvss',
      'vm3dservice',
      'VMTools' 
      // ...
);

{
  Using Service Manager WinAPI + OpenService()

  * https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-openscmanagerw
  * https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-openservicew
}
function CheckService_WinSvc() : Boolean;
var AServiceManager : SC_HANDLE;
    I               : Cardinal;
begin
  result := False;
  ///

  AServiceManager := OpenSCManagerW(nil, nil, SC_MANAGER_ENUMERATE_SERVICE);
  if AServiceManager = 0 then
  raise Exception.Create(
      Format('Could not open service manager with error=[%s]', [GetLastError()])
  );
  try
    for I := 0 to Length(ANTI_LIST) -1 do begin
      if (OpenServiceW(AServiceManager, PWideChar(ANTI_LIST[I]), READ_CONTROL) <> 0) then begin
        WriteLn(Format('[*] "%s" service found.', [ANTI_LIST[I]]));

        ///
        result := true;
      end;
    end;
  finally
    CloseServiceHandle(AServiceManager);
  end;
end;

{
  Using Microsoft Windows Registry + RegOpenKeyExW

  * https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw
}
function CheckService_Registry() : Boolean;
const HIVE : HKEY = HKEY_LOCAL_MACHINE;
      PATH = 'SYSTEM\CurrentControlSet\Services\%s';
var AStatus : Longint;
    AKey    : HKEY;
    I       : Cardinal;
    APath   : String;
begin
  for I := 0 to Length(ANTI_LIST) -1 do begin
    APath := Format(PATH, [ANTI_LIST[i]]);
    if RegOpenKeyExW(HIVE, PWideChar(APath), 0, KEY_READ, AKey) <> ERROR_SUCCESS then
      continue;
    try
        WriteLn(Format('[*] "%s" service found.', [ANTI_LIST[I]]));

        ///
        result := true;
    finally
      RegCloseKey(AKey);
    end;
  end;
end;

procedure Header(ACaption : String);
begin
  WriteLn(StringOfChar('-', 50));
  WriteLn(ACaption);
  WriteLn(StringOfChar('-', 50));
end;

begin
  try
    Header('Check Service (WinSvc):');
    if not CheckService_WinSvc() then
      WriteLn('Nothing found so far...');

    WriteLn;

    Header('Check Service (Registry):');
    if not CheckService_Registry() then
      WriteLn('Nothing found so far...');

    readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Additional Resources

External Links

Subscribe to our Newsletter


The information entered into this form is mandatory. It will be subjected to computer processing. It is processed by computer in order to support our users and readers. The recipients of the data will be : contact@unprotect.it.

According to the Data Protection Act of January 6th, 1978, you have at any time, a right of access to and rectification of all of your personal data. If you wish to exercise this right and gain access to your personal data, please write to Thomas Roccia at contact@unprotect.it.

You may also oppose, for legitimate reasons, the processing of your personal data.