SMBEXEC
%COMSPEC%
SERVICE
TEMP .BAT
DetectionBlue TeamSOCOctober 12, 2026•9 min read

Detecting smbexec and Impacket Service Execution

smbexec never drops a service binary. It abuses the service itself, so the command line sitting in the ImagePath is the detection.

Scroll

Where PsExec uploads an executable, smbexec avoids touching disk with a payload: it creates a service whose binary path is a cmd.exe command line, runs it, then deletes the service. Each command repeats the cycle, which makes the pattern noisy in the very logs defenders already collect.

Signals at a Glance

SignalWhereATT&CK
Service ImagePath containing %COMSPEC%, cmd.exe /Q /c or echo redirected into a fileEvent 7045 / 4697T1569.002
Repeated service create and delete cycles from one source in minutesSystem log, Sysmon 13T1543.003
Temporary .bat file created and executed then removedSysmon 11/23T1059.003
Output file written to a share such as C$ or ADMIN$ and read backEvent 5145, Zeek smbT1021.002
cmd.exe launched by services.exe with /Q /cSysmon 1, Event 4688T1059.003

The ImagePath Is the Payload

The default smbexec flow builds a service binary path along the lines of %COMSPEC% /Q /c echo <command> ^> \\127.0.0.1\C$\__output 2^>^&1 > %TEMP%\execute.bat & %COMSPEC% /Q /c %TEMP%\execute.bat & del %TEMP%\execute.bat. Older builds also used a fixed service name; newer ones and forks randomise it, so match on the command-line shape:

title: Service ImagePath Executes Command Interpreter With Redirection
logsource:
  product: windows
  service: system
detection:
  selection:
    Provider_Name: 'Service Control Manager'
    EventID: 7045
  interpreter:
    ImagePath|contains:
      - '%COMSPEC%'
      - 'cmd.exe /Q /c'
      - 'cmd /c echo'
      - 'powershell'
  redirect:
    ImagePath|contains:
      - '\\127.0.0.1\'
      - '__output'
      - '.bat'
  condition: selection and interpreter and redirect
level: high
# tune/validate: legitimate services almost never point ImagePath at a shell; confirm in your estate.

Because every command creates and removes a service, volume is itself a signal. Count 7045 and 7036 events per host and source:

// Sentinel (KQL) - bursts of service creation on one host (smbexec per-command cycle)
SecurityEvent
| where EventID == 4697
| where ServiceFileName has_any ("%COMSPEC%", "cmd.exe", "powershell")
| summarize installs=count(), names=dcount(ServiceName), first=min(TimeGenerated), last=max(TimeGenerated)
          by Computer, SubjectUserName, bin(TimeGenerated, 10m)
| where installs >= 3
// tune/validate: the per-command cycle means one interactive session produces many events.

Batch Files, Output and Cleanup

Vetted sources

SigmaHQ includes rules for suspicious service ImagePaths and Impacket smbexec patterns, and Elastic and Splunk ESCU carry equivalent service-creation content. MITRE CAR documents remote service analytics, and Atomic Red Team lets you replay the behaviour. Baseline your own environment, and note that Zeek smb logs help where host auditing is incomplete.

Build Detections That Fire

Mjolnir Security helps blue teams turn threat intelligence into high-fidelity detections across endpoint, network, identity and cloud telemetry.

Detection EngineeringManaged Detection & ResponseThreat HuntingIncident ResponsePurple Teaming
  • Detection Engineering We build and tune detections mapped to ATT&CK from your own telemetry.
  • Threat Hunting as a Service Hypothesis-driven hunts for the behaviours on this page.
  • 24/7 Incident Response Containment when a detection fires. Call +1 833 403 5875.
Written by: Mjolnir Threat Research (MTAC)  |  Published: October 12, 2026  |  Last reviewed: October 12, 2026