Latest alertCVE-2018-11776 in Apache Struts Confirmed Exploited in the WildRead
Search all news in the platform

Detection rule

Metasploit Or Impacket Service Installation Via SMB PsExec

HighTest-data validatedSigmaHQ (community)T1021.002T1569.002T1570

Overview

Detects usage of Metasploit SMB PsExec (exploit/windows/smb/psexec) and Impacket psexec.py by triggering on specific service installation

Rule id
6fb63b40-e02a-403e-9ffd-3bcc1d749442
ATT&CK techniques
T1021.002 Remote Services: SMB/Windows Admin Shares, T1569.002 System Services: Service Execution, T1570 Lateral Tool Transfer
Severity
High
Confidence
Low
Origin
SigmaHQ (community)
SigmaHQ status
test
Used in defense packs
The Gentlemen, qilin, INC Ransom, Akira, safepay, Play, everest, nightspire

Validation

  1. ExperimentalSyntax checked only. Not yet tested on events.
  2. Test-data validatedMatched positive test events and ignored near-miss events. Not yet run in a production SIEM.
  3. SIEM-validatedRun in a real SIEM, with a recorded result.

1 of 1 positive test events matched; 2 of 2 near-miss events were correctly ignored. Community rule reused unmodified from SigmaHQ. OffSet7 converted it and tested it on synthetic events.

Detection logic and queries

Queries are shown exactly as generated. Test them in your environment before you deploy them.

Sigma

Sigma (YAML) · 6fb63b40-e02a-403e-9ffd-3bcc1d749442

Download
title: Metasploit Or Impacket Service Installation Via SMB PsExec
id: 6fb63b40-e02a-403e-9ffd-3bcc1d749442
related:
    - id: 1a17ce75-ff0d-4f02-9709-2b7bb5618cf0
      type: derived
status: test
description: Detects usage of Metasploit SMB PsExec (exploit/windows/smb/psexec) and Impacket psexec.py by triggering on specific service installation
references:
    - https://bczyz1.github.io/2021/01/30/psexec.html
author: Bartlomiej Czyz, Relativity
date: 2021-01-21
modified: 2022-10-05
tags:
    - attack.lateral-movement
    - attack.t1021.002
    - attack.t1570
    - attack.execution
    - attack.t1569.002
logsource:
    product: windows
    service: security
    definition: The 'System Security Extension' audit subcategory need to be enabled to log the EID 4697
detection:
    selection:
        EventID: 4697
        ServiceFileName|re: '^%systemroot%\\[a-zA-Z]{8}\.exe$'
        ServiceName|re: '(^[a-zA-Z]{4}$)|(^[a-zA-Z]{8}$)|(^[a-zA-Z]{16}$)'
        ServiceStartType: 3  # on-demand start, see https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventID=4697
        ServiceType: '0x10'
    filter:
        ServiceName: 'PSEXESVC'
    condition: selection and not filter
falsepositives:
    - Possible, different agents with a 8 character binary and a 4, 8 or 16 character service name
level: high

QRadar CRE

Design for the QRadar Rule Wizard. It is not importable and has not been tested in QRadar.

Rule name
OffSet7: Metasploit Or Impacket Service Installation Via SMB PsExec
Rule type
Event rule (Local)
Log source types
Microsoft Windows Security Event Log DSM (Security channel)

Building blocks

  • BB:OffSet7:Metasploit Or Impacket Service Installation Via :selection (match)
    All test lines must match (AND).
    • Event ID is equal to (case-insensitive): 4697
    • Service Filename matches the regular expression: ^%systemroot%\\[a-zA-Z]{8}\.exe$
    • Service Name matches the regular expression: (^[a-zA-Z]{4}$)|(^[a-zA-Z]{8}$)|(^[a-zA-Z]{16}$)
    • custom property needed: ServiceStartType is equal to (case-insensitive): 3
      No QRadar property mapped for "ServiceStartType": create a custom event property (regex or JSON) on the DSM first.
    • custom property needed: ServiceType is equal to (case-insensitive): 0x10
      No QRadar property mapped for "ServiceType": create a custom event property (regex or JSON) on the DSM first.
  • BB:OffSet7:Metasploit Or Impacket Service Installation Via :filter (exclusion)
    All test lines must match (AND).
    • Service Name is equal to (case-insensitive): PSEXESVC

Main rule, option A (building blocks)

  1. when the event(s) were detected by one or more of these log source types: Microsoft Windows Security Event Log DSM (Security channel)
  2. when an event matches the condition built from these building blocks: BB:OffSet7:Metasploit Or Impacket Service Installation Via :selection AND NOT BB:OffSet7:Metasploit Or Impacket Service Installation Via :filter

Main rule, option B (AQL filter test)

Not available: the AQL conversion failed for this rule.

Rule response

  • Severity 7, credibility 6, relevance 7
  • Ensure the detected event is part of an offense; index offense on Log Source (host) and annotate with the rule title and OffSet7 rule id
  • Respond no more than once per 30 minutes per Log Source (tune per environment)

Limitations

  • AQL conversion failed (field 'ServiceStartType' is not supported); only the building-block design is available.
  • QRadar AQL LIKE / CRE string tests are case-sensitive unless the property is lower-cased; the AQL option uses LOWER() where the backend applied it.
  • Regular expressions (|re) use Java regex in QRadar; verify syntax in the Rule Wizard.

Splunk

Splunk SPLSearch

Search for Splunk with Windows/Sysmon field names. A scheduled search or ES correlation search also needs a schedule, time range, throttling and an adaptive response, set in your environment.

source="WinEventLog:Security" EventCode=4697 ServiceStartType=3 ServiceType="0x10" NOT ServiceName="PSEXESVC"
| regex ServiceFileName="^%systemroot%\\\\[a-zA-Z]{8}\\.exe$"
| regex ServiceName="(^[a-zA-Z]{4}$)|(^[a-zA-Z]{8}$)|(^[a-zA-Z]{16}$)"

Splunk savedsearches.conf stanzaScheduled search template

Template stanza. Review schedule, alert actions and index/sourcetype for your environment before enabling.

[default]
dispatch.earliest_time = -30d
dispatch.latest_time = now

[Metasploit Or Impacket Service Installation Via SMB PsExec]
description = Detects usage of Metasploit SMB PsExec (exploit/windows/smb/psexec) and Impacket psexec.py by triggering on specific service installation
search = source="WinEventLog:Security" EventCode=4697 ServiceStartType=3 ServiceType="0x10" NOT ServiceName="PSEXESVC" \
| regex ServiceFileName="^%systemroot%\\\\[a-zA-Z]{8}\\.exe$" \
| regex ServiceName="(^[a-zA-Z]{4}$)|(^[a-zA-Z]{8}$)|(^[a-zA-Z]{16}$)"

Microsoft Sentinel

Microsoft Sentinel KQL (ASIM)Hunting query

Hunting query over ASIM-normalized tables. An analytics rule also needs a schedule, entity mapping and alert grouping.

SecurityEvent
| where (EventID == 4697 and ServiceFileName matches regex "^%systemroot%\\\\[a-zA-Z]{8}\\.exe$" and ServiceName matches regex "(^[a-zA-Z]{4}$)|(^[a-zA-Z]{8}$)|(^[a-zA-Z]{16}$)" and ServiceStartType == 3 and ServiceType =~ "0x10") and (not(ServiceName =~ "PSEXESVC"))

Elastic

Elastic Lucene (ECS)Hunting query

Lucene query over ECS fields (Winlogbeat/Elastic Agent Windows mappings). A detection rule also needs an index pattern, schedule and actions.

winlog.channel:Security AND ((event.code:4697 AND winlog.event_data.ServiceFileName:/(%systemroot%\\[a-zA-Z]{8}\.exe)/ AND service.name:/(([a-zA-Z]{4}))|(([a-zA-Z]{8}))|(([a-zA-Z]{16}))/ AND winlog.event_data.ServiceStartType:3 AND winlog.event_data.ServiceType:0x10) AND (NOT service.name:PSEXESVC))

Elastic EQL (ECS)Hunting query

EQL query over ECS fields. Usable in an Elastic Security EQL rule after review; index pattern and schedule are set per environment.

any where winlog.channel:"Security" and ((event.code:"4697" and winlog.event_data.ServiceFileName regex "(%systemroot%\\\\[a-zA-Z]{8}\\.exe)" and service.name regex "(([a-zA-Z]{4}))|(([a-zA-Z]{8}))|(([a-zA-Z]{16}))" and winlog.event_data.ServiceStartType:"3" and winlog.event_data.ServiceType:"0x10") and (not service.name:"PSEXESVC"))

Elastic ES|QL (ECS)Hunting query

ES|QL query over ECS fields; the FROM clause uses * and must be narrowed to your indices.

from * metadata _id, _index, _version | where winlog.channel=="Security" and event.code=="4697" and winlog.event_data.ServiceFileName rlike "(%systemroot%\\\\[a-zA-Z]{8}\\.exe)" and service.name rlike "(([a-zA-Z]{4}))|(([a-zA-Z]{8}))|(([a-zA-Z]{16}))" and winlog.event_data.ServiceStartType=="3" and winlog.event_data.ServiceType=="0x10" and not service.name=="PSEXESVC"

No working conversion: Microsoft Defender XDR KQL (Defender XDR advanced hunting has no Windows event-log channel tables (Security/System/Application).); IBM QRadar AQL (hunting query) (QRadar AQL backend has no property mapping for field "ServiceStartType")

Required telemetry

Log source
product: windows · service: security · definition: The 'System Security Extension' audit subcategory need to be enabled to log the EID 4697
Fields used
EventID ServiceFileName ServiceName ServiceStartType ServiceType

False positives

  • Possible, different agents with a 8 character binary and a 4, 8 or 16 character service name

Investigation and response

No OffSet7 investigation guidance has been written for this rule yet. Start from the false positives above and the ATT&CK technique pages.

References

Author and attribution

Author
Bartlomiej Czyz, Relativity
Source
SigmaHQ · rules/windows/builtin/security/win_security_metasploit_or_impacket_smb_psexec_service_install.yml
Upstream commit
9688134317a2
Licence
Detection Rule License (DRL) 1.1

Version history

  1. Version 1Imported from SigmaHQ
  2. OffSet7 build · SigmaHQ 9688134317a2

Related rules