Interactive Terminal Spawned via Python

Identifies when a terminal (tty) is spawned via Python. Attackers may upgrade a simple reverse shell to a fully interactive tty after obtaining initial access to a host.

Elastic rule (View on GitHub)

 1[metadata]
 2creation_date = "2020/04/15"
 3integration = ["endpoint"]
 4maturity = "production"
 5updated_date = "2023/02/22"
 6min_stack_comments = "New fields added: required_fields, related_integrations, setup"
 7min_stack_version = "8.3.0"
 8
 9[rule]
10author = ["Elastic"]
11description = """
12Identifies when a terminal (tty) is spawned via Python. Attackers may upgrade a simple reverse shell to a fully
13interactive tty after obtaining initial access to a host.
14"""
15from = "now-9m"
16index = ["auditbeat-*", "logs-endpoint.events.*", "endgame-*"]
17language = "kuery"
18license = "Elastic License v2"
19name = "Interactive Terminal Spawned via Python"
20risk_score = 73
21rule_id = "d76b02ef-fc95-4001-9297-01cb7412232f"
22severity = "high"
23tags = ["Elastic", "Host", "Linux", "Threat Detection", "Execution", "Elastic Endgame"]
24timeline_id = "e70679c2-6cde-4510-9764-4823df18f7db"
25timeline_title = "Comprehensive Process Timeline"
26timestamp_override = "event.ingested"
27type = "query"
28
29query = '''
30event.category:process and host.os.type:linux and event.type:(start or process_started) and
31  process.name:python* and
32  process.args:("import pty; pty.spawn(\"/bin/sh\")" or
33                "import pty; pty.spawn(\"/bin/dash\")" or
34                "import pty; pty.spawn(\"/bin/bash\")")
35'''
36
37
38[[rule.threat]]
39framework = "MITRE ATT&CK"
40[[rule.threat.technique]]
41id = "T1059"
42name = "Command and Scripting Interpreter"
43reference = "https://attack.mitre.org/techniques/T1059/"
44
45
46[rule.threat.tactic]
47id = "TA0002"
48name = "Execution"
49reference = "https://attack.mitre.org/tactics/TA0002/"

to-top