Connection to Commonly Abused Web Services

Adversaries may implement command and control (C2) communications that use common web services to hide their activity. This attack technique is typically targeted at an organization and uses web services common to the victim network, which allows the adversary to blend into legitimate traffic activity. These popular services are typically targeted since they have most likely been used before compromise, which helps malicious traffic blend in.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/11/04"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2024/07/16"
  6
  7[transform]
  8[[transform.osquery]]
  9label = "Osquery - Retrieve DNS Cache"
 10query = "SELECT * FROM dns_cache"
 11
 12[[transform.osquery]]
 13label = "Osquery - Retrieve All Services"
 14query = "SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services"
 15
 16[[transform.osquery]]
 17label = "Osquery - Retrieve Services Running on User Accounts"
 18query = """
 19SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services WHERE
 20NOT (user_account LIKE '%LocalSystem' OR user_account LIKE '%LocalService' OR user_account LIKE '%NetworkService' OR
 21user_account == null)
 22"""
 23
 24[[transform.osquery]]
 25label = "Osquery - Retrieve Service Unsigned Executables with Virustotal Link"
 26query = """
 27SELECT concat('https://www.virustotal.com/gui/file/', sha1) AS VtLink, name, description, start_type, status, pid,
 28services.path FROM services JOIN authenticode ON services.path = authenticode.path OR services.module_path =
 29authenticode.path JOIN hash ON services.path = hash.path WHERE authenticode.result != 'trusted'
 30"""
 31
 32[[transform.investigate]]
 33label = "Alerts associated with the user in the last 48h"
 34relativeFrom = "now-48h/h"
 35relativeTo = "now"
 36providers = [
 37  [
 38    {field = "event.kind", excluded = false, queryType = "phrase", value = "signal", valueType = "string"},
 39    {field = "user.id", excluded = false, queryType = "phrase", value = "{{user.id}}", valueType = "string"}
 40  ]
 41]
 42
 43
 44[[transform.investigate]]
 45label = "Alerts associated with the host in the last 48h"
 46relativeFrom = "now-48h/h"
 47relativeTo = "now"
 48providers = [
 49  [
 50    {field = "event.kind", excluded = false, queryType = "phrase", value = "signal", valueType = "string"},
 51    {field = "host.name", excluded = false, queryType = "phrase", value = "{{host.name}}", valueType = "string"}
 52  ]
 53]
 54
 55[[transform.investigate]]
 56label = "Investigate the Subject Process Network Events"
 57providers = [
 58  [
 59    {field = "process.entity_id", excluded = false, queryType = "phrase", value = "{{process.entity_id}}", valueType = "string"},
 60    {field = "event.category", excluded = false, queryType = "phrase", value = "network", valueType = "string"}
 61  ]
 62]
 63
 64
 65[rule]
 66author = ["Elastic"]
 67description = """
 68Adversaries may implement command and control (C2) communications that use common web services to hide their activity.
 69This attack technique is typically targeted at an organization and uses web services common to the victim network, which
 70allows the adversary to blend into legitimate traffic activity. These popular services are typically targeted since they
 71have most likely been used before compromise, which helps malicious traffic blend in.
 72"""
 73from = "now-9m"
 74index = ["logs-endpoint.events.network-*"]
 75language = "eql"
 76license = "Elastic License v2"
 77name = "Connection to Commonly Abused Web Services"
 78note = """## Triage and analysis
 79
 80### Investigating Connection to Commonly Abused Web Services
 81
 82Adversaries may use an existing, legitimate external Web service as a means for relaying data to/from a compromised system. Popular websites and social media acting as a mechanism for C2 may give a significant amount of cover due to the likelihood that hosts within a network are already communicating with them prior to a compromise.
 83
 84This rule looks for processes outside known legitimate program locations communicating with a list of services that can be abused for exfiltration or command and control.
 85
 86> **Note**:
 87> This investigation guide uses the [Osquery Markdown Plugin](https://www.elastic.co/guide/en/security/master/invest-guide-run-osquery.html) introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
 88> This investigation guide uses the [Investigate Markdown Plugin](https://www.elastic.co/guide/en/security/master/interactive-investigation-guides.html) introduced in Elastic Stack version 8.8.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
 89
 90#### Possible investigation steps
 91
 92- Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
 93- Investigate other alerts associated with the user/host during the past 48 hours.
 94  - $investigate_0
 95  - $investigate_1
 96- Verify whether the digital signature exists in the executable.
 97- Identify the operation type (upload, download, tunneling, etc.).
 98- Examine the host for derived artifacts that indicate suspicious activities:
 99  - Analyze the process executable using a private sandboxed analysis system.
100  - Observe and collect information about the following activities in both the sandbox and the alert subject host:
101    - Attempts to contact external domains and addresses.
102      - Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' `process.entity_id`.
103        - $investigate_2
104      - Examine the DNS cache for suspicious or anomalous entries.
105        - $osquery_0
106    - Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
107    - Examine the host services for suspicious or anomalous entries.
108      - $osquery_1
109      - $osquery_2
110      - $osquery_3
111  - Retrieve the files' SHA-256 hash values using the PowerShell `Get-FileHash` cmdlet and search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
112
113### False positive analysis
114
115- This rule has a high chance to produce false positives because it detects communication with legitimate services. Noisy false positives can be added as exceptions.
116
117### Response and remediation
118
119- Initiate the incident response process based on the outcome of the triage.
120- Isolate the involved host to prevent further post-compromise behavior.
121- If the triage identified malware, search the environment for additional compromised hosts.
122  - Implement temporary network rules, procedures, and segmentation to contain the malware.
123  - Stop suspicious processes.
124  - Immediately block the identified indicators of compromise (IoCs).
125  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
126- Remove and block malicious artifacts identified during triage.
127- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
128- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
129- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
130"""
131risk_score = 21
132rule_id = "66883649-f908-4a5b-a1e0-54090a1d3a32"
133severity = "low"
134tags = ["Domain: Endpoint", "OS: Windows", "Use Case: Threat Detection", "Tactic: Command and Control", "Resources: Investigation Guide", "Data Source: Elastic Defend"]
135timestamp_override = "event.ingested"
136type = "eql"
137
138query = '''
139network where host.os.type == "windows" and network.protocol == "dns" and
140    process.name != null and user.id not in ("S-1-5-18", "S-1-5-19", "S-1-5-20") and
141    /* Add new WebSvc domains here */
142    dns.question.name :
143       (
144        "raw.githubusercontent.*",
145        "pastebin.*",
146        "paste4btc.com",
147        "paste.ee",
148        "ghostbin.com",
149        "drive.google.com",
150        "?.docs.live.net",
151        "api.dropboxapi.*",
152        "content.dropboxapi.*",
153        "dl.dropboxusercontent.*",
154        "api.onedrive.com",
155        "*.onedrive.org",
156        "onedrive.live.com",
157        "filebin.net",
158        "*.ngrok.io",
159        "ngrok.com",
160        "*.portmap.*",
161        "*serveo.net",
162        "*localtunnel.me",
163        "*pagekite.me",
164        "*localxpose.io",
165        "*notabug.org",
166        "rawcdn.githack.*",
167        "paste.nrecom.net",
168        "zerobin.net",
169        "controlc.com",
170        "requestbin.net",
171        "slack.com",
172        "api.slack.com",
173        "slack-redir.net",
174        "slack-files.com",
175        "cdn.discordapp.com",
176        "discordapp.com",
177        "discord.com",
178        "apis.azureedge.net",
179        "cdn.sql.gg",
180        "?.top4top.io",
181        "top4top.io",
182        "www.uplooder.net",
183        "*.cdnmegafiles.com",
184        "transfer.sh",
185        "gofile.io",
186        "updates.peer2profit.com",
187        "api.telegram.org",
188        "t.me",
189        "meacz.gq",
190        "rwrd.org",
191        "*.publicvm.com",
192        "*.blogspot.com",
193        "api.mylnikov.org",
194        "file.io",
195        "stackoverflow.com",
196        "*files.1drv.com",
197        "api.anonfile.com",
198        "*hosting-profi.de",
199        "ipbase.com",
200        "ipfs.io",
201        "*up.freeo*.space",
202        "api.mylnikov.org",
203        "script.google.com",
204        "script.googleusercontent.com",
205        "api.notion.com",
206        "graph.microsoft.com",
207        "*.sharepoint.com",
208        "mbasic.facebook.com",
209        "login.live.com",
210        "api.gofile.io",
211        "api.anonfiles.com",
212        "api.notion.com",
213        "api.trello.com",
214        "gist.githubusercontent.com",
215        "files.pythonhosted.org",
216        "g.live.com",
217        "*.zulipchat.com",
218        "webhook.site",
219        "run.mocky.io",
220        "mockbin.org", 
221        "www.googleapis.com", 
222        "googleapis.com") and
223        
224    /* Insert noisy false positives here */
225    not (
226      (
227        process.executable : (
228          "?:\\Program Files\\*.exe",
229          "?:\\Program Files (x86)\\*.exe",
230          "?:\\Windows\\System32\\WWAHost.exe",
231          "?:\\Windows\\System32\\smartscreen.exe",
232          "?:\\Windows\\System32\\MicrosoftEdgeCP.exe",
233          "?:\\ProgramData\\Microsoft\\Windows Defender\\Platform\\*\\MsMpEng.exe",
234          "?:\\Users\\*\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe",
235          "?:\\Users\\*\\AppData\\Local\\BraveSoftware\\*\\Application\\brave.exe",
236          "?:\\Users\\*\\AppData\\Local\\Vivaldi\\Application\\vivaldi.exe",
237          "?:\\Users\\*\\AppData\\Local\\Programs\\Opera*\\opera.exe",
238          "?:\\Users\\*\\AppData\\Local\\Programs\\Fiddler\\Fiddler.exe",
239          "?:\\Users\\*\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe",
240          "?:\\Users\\*\\AppData\\Local\\Microsoft\\OneDrive\\OneDrive.exe",
241          "?:\\Windows\\system32\\mobsync.exe",
242          "?:\\Windows\\SysWOW64\\mobsync.exe"
243        )
244      ) or
245    
246      /* Discord App */
247      (process.name : "Discord.exe" and (process.code_signature.subject_name : "Discord Inc." and
248       process.code_signature.trusted == true) and dns.question.name : ("discord.com", "cdn.discordapp.com", "discordapp.com")
249      ) or 
250
251      /* MS Sharepoint */
252      (process.name : "Microsoft.SharePoint.exe" and (process.code_signature.subject_name : "Microsoft Corporation" and
253       process.code_signature.trusted == true) and dns.question.name : "onedrive.live.com"
254      ) or 
255
256      /* Firefox */
257      (process.name : "firefox.exe" and (process.code_signature.subject_name : "Mozilla Corporation" and
258       process.code_signature.trusted == true)
259      ) or 
260
261      /* Dropbox */
262      (process.name : "Dropbox.exe" and (process.code_signature.subject_name : "Dropbox, Inc" and
263       process.code_signature.trusted == true) and dns.question.name : ("api.dropboxapi.com", "*.dropboxusercontent.com")
264      ) or 
265
266      /* Obsidian - Plugins are stored on raw.githubusercontent.com */
267      (process.name : "Obsidian.exe" and (process.code_signature.subject_name : "Dynalist Inc" and
268       process.code_signature.trusted == true) and dns.question.name : "raw.githubusercontent.com"
269      ) or 
270
271      /* WebExperienceHostApp */
272      (process.name : "WebExperienceHostApp.exe" and (process.code_signature.subject_name : "Microsoft Windows" and
273       process.code_signature.trusted == true) and dns.question.name : ("onedrive.live.com", "skyapi.onedrive.live.com")
274      ) or
275
276      (process.code_signature.subject_name : "Microsoft *" and process.code_signature.trusted == true and
277       dns.question.name : ("*.sharepoint.com", "graph.microsoft.com", "g.live.com", "login.live.com", "login.live.com")) or
278
279      (process.code_signature.trusted == true and
280       process.code_signature.subject_name :
281                             ("Johannes Schindelin",
282                              "Redis Inc.",
283                              "Slack Technologies, LLC",
284                              "Cisco Systems, Inc.",
285                              "Dropbox, Inc",
286                              "Amazon.com Services LLC"))
287    ) 
288'''
289
290
291[[rule.threat]]
292framework = "MITRE ATT&CK"
293[[rule.threat.technique]]
294id = "T1102"
295name = "Web Service"
296reference = "https://attack.mitre.org/techniques/T1102/"
297
298[[rule.threat.technique]]
299id = "T1568"
300name = "Dynamic Resolution"
301reference = "https://attack.mitre.org/techniques/T1568/"
302
303  [[rule.threat.technique.subtechnique]]
304  id = "T1568.002"
305  name = "Domain Generation Algorithms"
306  reference = "https://attack.mitre.org/techniques/T1568/002/"
307
308[rule.threat.tactic]
309id = "TA0011"
310name = "Command and Control"
311reference = "https://attack.mitre.org/tactics/TA0011/"
312[[rule.threat]]
313framework = "MITRE ATT&CK"
314[[rule.threat.technique]]
315id = "T1567"
316name = "Exfiltration Over Web Service"
317reference = "https://attack.mitre.org/techniques/T1567/"
318[[rule.threat.technique.subtechnique]]
319id = "T1567.001"
320name = "Exfiltration to Code Repository"
321reference = "https://attack.mitre.org/techniques/T1567/001/"
322
323[[rule.threat.technique.subtechnique]]
324id = "T1567.002"
325name = "Exfiltration to Cloud Storage"
326reference = "https://attack.mitre.org/techniques/T1567/002/"
327
328
329
330[rule.threat.tactic]
331id = "TA0010"
332name = "Exfiltration"
333reference = "https://attack.mitre.org/tactics/TA0010/"

Triage and analysis

Investigating Connection to Commonly Abused Web Services

Adversaries may use an existing, legitimate external Web service as a means for relaying data to/from a compromised system. Popular websites and social media acting as a mechanism for C2 may give a significant amount of cover due to the likelihood that hosts within a network are already communicating with them prior to a compromise.

This rule looks for processes outside known legitimate program locations communicating with a list of services that can be abused for exfiltration or command and control.

Note: This investigation guide uses the Osquery Markdown Plugin introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide. This investigation guide uses the Investigate Markdown Plugin introduced in Elastic Stack version 8.8.0. Older Elastic Stack versions will display unrendered Markdown in this guide.

Possible investigation steps

  • Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
  • Investigate other alerts associated with the user/host during the past 48 hours.
    • $investigate_0
    • $investigate_1
  • Verify whether the digital signature exists in the executable.
  • Identify the operation type (upload, download, tunneling, etc.).
  • Examine the host for derived artifacts that indicate suspicious activities:
    • Analyze the process executable using a private sandboxed analysis system.
    • Observe and collect information about the following activities in both the sandbox and the alert subject host:
      • Attempts to contact external domains and addresses.
        • Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' process.entity_id.
          • $investigate_2
        • Examine the DNS cache for suspicious or anomalous entries.
          • $osquery_0
      • Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
      • Examine the host services for suspicious or anomalous entries.
        • $osquery_1
        • $osquery_2
        • $osquery_3
    • Retrieve the files' SHA-256 hash values using the PowerShell Get-FileHash cmdlet and search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.

False positive analysis

  • This rule has a high chance to produce false positives because it detects communication with legitimate services. Noisy false positives can be added as exceptions.

Response and remediation

  • Initiate the incident response process based on the outcome of the triage.
  • Isolate the involved host to prevent further post-compromise behavior.
  • If the triage identified malware, search the environment for additional compromised hosts.
    • Implement temporary network rules, procedures, and segmentation to contain the malware.
    • Stop suspicious processes.
    • Immediately block the identified indicators of compromise (IoCs).
    • Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
  • Remove and block malicious artifacts identified during triage.
  • Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
  • Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
  • Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).

Related rules

to-top