<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>PyTorch - CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/products/pytorch/</link><description>Trending threats, MITRE ATT&amp;CK coverage, and detection metadata. Fed continuously.</description><generator>Hugo</generator><language>en</language><managingEditor>hello@craftedsignal.io</managingEditor><webMaster>hello@craftedsignal.io</webMaster><lastBuildDate>Wed, 03 Jul 2024 14:27:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/products/pytorch/feed.xml" rel="self" type="application/rss+xml"/><item><title>First Time Python Created a LaunchAgent or LaunchDaemon</title><link>https://feed.craftedsignal.io/briefs/2024-07-macos-python-launchagent/</link><pubDate>Wed, 03 Jul 2024 14:27:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-07-macos-python-launchagent/</guid><description>Detection of the first-time a Python process creates or modifies a LaunchAgent or LaunchDaemon plist file on a given macOS host, which is indicative of persistence attempts via malicious scripts, compromised dependencies, or model file deserialization.</description><content:encoded><![CDATA[<p>This alert focuses on detecting suspicious persistence mechanisms on macOS systems where a Python process is observed creating or modifying LaunchAgent or LaunchDaemon plist files for the first time. Attackers achieving Python code execution, whether through malicious scripts, compromised dependencies, or model file deserialization vulnerabilities such as pickle or PyTorch <code>__reduce__</code>, may drop plist files to establish persistence. These LaunchAgents and LaunchDaemons are designed to configure programs to run automatically at login or boot, ensuring the attacker's payload survives reboots and user logouts. This activity is often a strong indicator of compromise because legitimate Python processes rarely need to create persistence mechanisms.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>Initial Access: The attacker gains initial access to the macOS system through various means, such as exploiting a vulnerability in an application, social engineering, or phishing.</li>
<li>Code Execution: Once inside, the attacker achieves code execution, often leveraging Python through malicious scripts, compromised dependencies (e.g., via pip), or model file deserialization.</li>
<li>Persistence Preparation: The attacker crafts a malicious LaunchAgent or LaunchDaemon plist file.  This file contains configurations to automatically run a specified program at login or boot.</li>
<li>File Creation/Modification: The malicious Python script creates or modifies a plist file in either <code>/Library/LaunchAgents/</code>, <code>~/Library/LaunchAgents/</code>, or <code>/Library/LaunchDaemons/</code>.</li>
<li>Persistence Installation: The system recognizes the new or modified plist file and schedules the specified program to run automatically.</li>
<li>Payload Execution:  At the next login or boot, the system executes the program specified in the plist file, initiating the attacker's payload.</li>
<li>Command and Control: The executed payload establishes a connection to a command-and-control server, allowing the attacker to remotely control the compromised system.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation could lead to persistent access to the compromised macOS system, enabling attackers to maintain their foothold even after reboots or user logouts. This can lead to data theft, installation of malware, or further lateral movement within the network. The impact extends to potential data breaches, system compromise, and reputational damage. While the specific number of victims is unknown, the threat affects any macOS system susceptible to malicious Python scripts or compromised dependencies.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Enable Sysmon process-creation and file-creation logging to capture the events required for the rules below (references &quot;process_creation&quot; and &quot;file_event&quot; log sources).</li>
<li>Deploy the Sigma rule &quot;macOS Suspicious LaunchAgent/Daemon Creation by Python&quot; to your SIEM and tune for your environment to detect the behavior (references the Sigma rule).</li>
<li>Investigate any persistence events involving Python creating LaunchDaemons by reviewing persistence event fields such as <code>Persistence.runatload</code>, <code>Persistence.keepalive</code>, <code>Persistence.args</code>, <code>Persistence.path</code> to understand the plist configuration.</li>
</ul>
]]></content:encoded><category domain="severity">medium</category><category domain="type">advisory</category><category>persistence</category><category>macos</category><category>python</category><category>launchagent</category><category>launchdaemon</category></item><item><title>First Time Python Accessed Sensitive Credential Files on macOS</title><link>https://feed.craftedsignal.io/briefs/2024-07-python-credential-access/</link><pubDate>Wed, 03 Jul 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-07-python-credential-access/</guid><description>This alert triggers on the first instance of a Python process accessing sensitive credential files on macOS, potentially indicating post-exploitation credential theft.</description><content:encoded><![CDATA[<p>This detection rule identifies instances where a Python process accesses sensitive credential files on macOS for the first time. This activity is often indicative of post-exploitation credential theft, where attackers leverage Python code execution (through malicious scripts, compromised dependencies, or model file deserialization) to target sensitive data. Since legitimate Python processes rarely interact with files containing SSH keys, cloud provider credentials, browser session cookies, Kerberos tickets, or keychain databases, such access is considered a high-confidence indicator of compromise. The rule specifically focuses on &quot;first occurrence&quot; events within a 7-day window to minimize noise from legitimate but infrequent access patterns. This alert is designed to detect malicious activity related to Python-based attacks targeting credential stores on macOS systems.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>Initial Access: Attacker gains initial access to the macOS system through a software vulnerability or social engineering.</li>
<li>Code Execution: The attacker executes malicious Python code on the compromised system. This could be through a malicious script, a compromised dependency, or exploitation of unsafe deserialization practices like pickle/PyTorch <code>__reduce__</code>.</li>
<li>Discovery: The Python script enumerates potential credential file locations on the system.</li>
<li>Credential Access: The Python script attempts to open and read sensitive files such as SSH keys (<code>~/.ssh/id_rsa</code>), AWS credentials (<code>~/.aws/credentials</code>), browser cookies, Kerberos tickets (<code>/tmp/krb5cc_*</code>), or macOS keychain databases (<code>~/Library/Keychains/login.keychain-db</code>).</li>
<li>Data Collection: The stolen credentials are saved to a temporary file or memory.</li>
<li>Exfiltration: The attacker establishes a network connection to an external server and exfiltrates the collected credential data.</li>
<li>Lateral Movement/Privilege Escalation: The attacker uses the stolen credentials to move laterally to other systems or escalate privileges within the network.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>A successful attack can lead to unauthorized access to sensitive data, lateral movement within the network, and potential privilege escalation. If SSH keys are compromised, attackers can gain access to other systems without authentication. Compromised AWS credentials can lead to unauthorized access to cloud resources, potentially resulting in data breaches and financial losses. Browser cookie theft allows attackers to hijack user sessions, gaining access to web applications and services.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Deploy the Sigma rule <code>macOS Python Credential File Access</code> to your SIEM and tune for your environment, ensuring it is enabled and actively monitoring file access events.</li>
<li>Enable Elastic Defend endpoint file monitoring to capture <code>open</code> events for sensitive credential files, as required by the rule <code>macOS Python Credential File Access</code>.</li>
<li>Implement <code>weights_only=True</code> enforcement for PyTorch model loading to mitigate risks associated with malicious model files, as mentioned in the overview.</li>
<li>Investigate and quarantine any Python processes flagged by the Sigma rule <code>macOS Python Credential File Access</code> to prevent further data exfiltration or lateral movement.</li>
<li>Rotate any compromised credentials (SSH keys, AWS access keys, cloud tokens) identified during incident response, as described in the Triage section.</li>
<li>Monitor process command lines for suspicious arguments or script execution related to credential access using the Sigma rule <code>Suspicious Python Script Execution</code>.</li>
</ul>
]]></content:encoded><category domain="severity">medium</category><category domain="type">advisory</category><category>credential-access</category><category>python</category><category>macos</category><category>endpoint</category></item><item><title>First Time Python Spawned a Shell on macOS Host</title><link>https://feed.craftedsignal.io/briefs/2024-07-python-shell-macos/</link><pubDate>Tue, 02 Jul 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-07-python-shell-macos/</guid><description>This rule detects the first time a Python process spawns a shell on a given macOS host using the `-c` flag, indicating potential malicious activity stemming from compromised Python environments.</description><content:encoded><![CDATA[<p>This detection identifies the initial instance of a Python process spawning a shell on a macOS host. Attackers often leverage Python code execution, gained through malicious scripts, compromised dependencies, or insecure model file deserialization (e.g., pickle/PyTorch <code>__reduce__</code>), to spawn shell processes. These shell processes are then used for reconnaissance, credential theft, persistence, or establishing reverse shells. The rule specifically looks for shell invocations using the <code>-c</code> flag, which is often used to execute commands directly within the shell. Given that legitimate Python workflows typically avoid using <code>-c</code> to execute shell commands, the first appearance of such behavior on a host is a significant indicator of a potential compromise. The rule leverages a 7-day window to establish the first occurrence baseline.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>Attacker gains initial access to a macOS system via methods such as phishing or exploiting a vulnerable service.</li>
<li>Attacker uploads or introduces a malicious Python script or compromises an existing Python dependency.</li>
<li>The malicious Python script is executed. This could occur via a user executing the script, a cron job, or a compromised application loading the script.</li>
<li>The Python script uses the <code>subprocess</code> module or a similar function to spawn a shell process (e.g., bash, sh, zsh) with the <code>-c</code> flag.</li>
<li>The shell executes a command provided by the Python script, such as system reconnaissance (<code>whoami</code>, <code>ifconfig</code>), credential access (<code>security dump-keychain</code>), or persistence mechanisms.</li>
<li>The attacker may establish a reverse shell to maintain access to the compromised system.</li>
<li>The attacker performs lateral movement or exfiltrates sensitive data.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation can lead to a wide range of consequences, including unauthorized access to sensitive data, system compromise, and lateral movement within the network. While specific victim counts or sectors targeted are not provided, the attack could impact any macOS environment where Python is used, particularly those handling sensitive information or running custom Python scripts.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Deploy the Sigma rule <code>Python Shell Spawned with -c</code> to your SIEM to detect the behavior described in this brief and tune for your environment.</li>
<li>Enable Sysmon process creation logging to ensure the <code>process_creation</code> log category is populated, allowing for accurate detection using the provided Sigma rules.</li>
<li>Investigate any alerts generated by the Sigma rule, focusing on the parent Python process and the executed shell command to understand the context of the activity.</li>
<li>Implement <code>weights_only=True</code> enforcement for PyTorch model loading across the environment, as referenced in the &quot;https://blog.trailofbits.com/2024/06/11/exploiting-ml-models-with-pickle-file-attacks-part-1/&quot; reference.</li>
</ul>
]]></content:encoded><category domain="severity">medium</category><category domain="type">advisory</category><category>execution</category><category>macos</category><category>python</category></item></channel></rss>